- Timestamp:
- 06/22/13 21:51:33 (11 years ago)
- Location:
- java/main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main
-
Property
svn:ignore
set to
target
-
Property
svn:ignore
set to
-
java/main/src/main/java/com/framsticks/gui/windows/console/ConsoleFrame.java
r77 r84 3 3 import com.framsticks.communication.*; 4 4 import com.framsticks.gui.ImageProvider; 5 import com.framsticks.util. Pair;6 import com.framsticks.util. Strings;5 import com.framsticks.util.lang.Pair; 6 import com.framsticks.util.lang.Strings; 7 7 import org.apache.log4j.Logger; 8 8 … … 19 19 public class ConsoleFrame extends JFrame { 20 20 21 private static final Logger LOGGER= Logger.getLogger(ConsoleFrame.class.getName());22 23 /** 24 25 26 27 28 29 30 31 32 /** 33 34 35 21 private static final Logger log = Logger.getLogger(ConsoleFrame.class.getName()); 22 23 /** 24 * Painter coloring manager responses before display. 25 */ 26 private final ConsolePainter consolePainter; 27 28 /** 29 * Text field for typing commands. 30 */ 31 private final JTextField commandLine; 32 /** 33 * Reference to connection. 34 */ 35 protected final ClientConnection connection; 36 36 37 37 /** … … 52 52 53 53 /** 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 54 * Default constructor creates frame with console. 55 */ 56 @SuppressWarnings("unchecked") 57 public ConsoleFrame(ClientConnection connection) { 58 this.connection = connection; 59 this.setTitle("Console"); 60 this.setLayout(new BorderLayout()); 61 this.setSize(new Dimension(440, 400)); 62 this.setMinimumSize(new Dimension(440, 400)); 63 this.setIconImage(ImageProvider.loadImage(ImageProvider.LOGO).getImage()); 64 JFrame.setDefaultLookAndFeelDecorated(true); 65 66 JTextPane text = new JTextPane(); 67 consolePainter = new ConsolePainter(text); 68 69 text.setEditable(false); 70 final JScrollPane scrollText = new JScrollPane(text); 71 scrollText.setBorder(BorderFactory.createEtchedBorder()); 72 73 JPanel scrollPanel = new JPanel(); 74 scrollPanel.setLayout(new BorderLayout()); 75 scrollPanel.add(scrollText, BorderLayout.CENTER); 76 scrollPanel.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7)); 77 78 commandLine = new JTextField(); 79 80 commandLine.addKeyListener(new KeyListener() { 81 @Override 82 public void keyTyped(KeyEvent e) { 83 84 } 85 86 @Override 87 public void keyPressed(KeyEvent e) { 88 onKeyPressed(e.getKeyCode()); 89 } 90 91 @Override 92 public void keyReleased(KeyEvent e) { 93 } 94 }); 95 96 commandLine.setFocusTraversalKeys( 97 KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, 98 Collections.EMPTY_SET); 99 100 this.addWindowListener(new WindowAdapter() { 101 public void windowActivated(WindowEvent e) { 102 commandLine.requestFocusInWindow(); 103 } 104 }); 105 106 JButton sendButton = new JButton("Send"); 107 sendButton.addActionListener(new ActionListener() { 108 109 public void actionPerformed(final ActionEvent e) { 110 buttonSendAction(); 111 } 112 113 }); 114 115 final Box cmdBox = new Box(BoxLayout.LINE_AXIS); 116 cmdBox.add(commandLine); 117 cmdBox.add(Box.createHorizontalStrut(10)); 118 cmdBox.add(sendButton); 119 cmdBox.setBorder(BorderFactory.createEmptyBorder(0, 7, 7, 7)); 120 121 this.getContentPane().add(scrollPanel, BorderLayout.CENTER); 122 this.getContentPane().add(cmdBox, BorderLayout.PAGE_END); 123 this.setVisible(false); 124 125 } 126 126 127 127 public void setCommandLine(String command) { … … 130 130 131 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 LOGGER.warn("not a valid request: " + commandText);167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 132 /** 133 * Shows console frame, sets location relative to parent. 134 * 135 * @param parent Frame relative to which console window will be localized. 136 */ 137 public void show(JFrame parent) { 138 final Point parentLocation = parent.getLocation(); 139 final Point location = new Point(parentLocation.x + 20, parentLocation.y + 20); 140 this.setLocation(location); 141 this.setVisible(true); 142 } 143 144 /** 145 * Adds query to console window. 146 * 147 * @param line Line of string query. 148 */ 149 private void addQuery(String line) { 150 consolePainter.userMsg(line + "\n"); 151 } 152 153 154 /** 155 * Sends message to manager and adds message to console frame. 156 */ 157 public void buttonSendAction() { 158 if (!connection.isConnected()) { 159 JOptionPane.showMessageDialog(this, "missing connection to manager"); 160 return; 161 } 162 String commandText = commandLine.getText(); 163 Pair<String, String> command = Strings.splitIntoPair(commandText, ' ', "\n"); 164 Request request = Request.createRequestByTypeString(command.first); 165 if (request == null) { 166 log.warn("not a valid request: " + commandText); 167 return; 168 } 169 request.parseRest(command.second); 170 171 addQuery(commandText); 172 addSentMessage(commandText); 173 commandLine.setText(""); 174 connection.send(request, new ResponseCallback() { 175 @Override 176 public void process(Response response) { 177 for (File f : response.getFiles()) { 178 consolePainter.paintMessage(f); 179 } 180 } 181 }); 182 } 183 183 184 184 private void onKeyPressed(int keyCode) {
Note: See TracChangeset
for help on using the changeset viewer.