/** * Add the provided text with the provided color to the GUI document * * @param text The text that will be added * @param color The color used to show the text */ public void print(String text, Color color) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color); int len = logPane.getDocument().getLength(); try { logPane.setCaretPosition(len); logPane.getDocument().insertString(len, text + "\n", aset); } catch (BadLocationException e) { LoggerFactory.getLogger(ProcessUIPanel.class).error("Cannot show the log message", e); } logPane.setCaretPosition(logPane.getDocument().getLength()); }
@Override public synchronized void run() { try { for (int i = 0; i < NUM_PIPES; i++) { while (Thread.currentThread() == reader[i]) { try { this.wait(100); } catch (InterruptedException ie) { } if (pin[i].available() != 0) { String input = this.readLine(pin[i]); appendMsg(htmlize(input)); if (textArea.getDocument().getLength() > 0) { textArea.setCaretPosition(textArea.getDocument().getLength() - 1); } } if (quit) { return; } } } } catch (Exception e) { Debug.error(me + "Console reports an internal error:\n%s", e.getMessage()); } }
public void toChatScreen(String toScreen, boolean selfSeen) throws IOException, BadLocationException { // Timestamp ts = new Timestamp(); String toScreenFinal = ""; Date now = Calendar.getInstance().getTime(); SimpleDateFormat format = new SimpleDateFormat("hh:mm"); String ts = format.format(now); // chatScreen.append(ts + " " + toScreen + "\n"); toScreenFinal = "<font color=gray>" + ts + "</font> "; if (selfSeen) toScreenFinal = toScreenFinal + "<font color=red>" + toScreen + "</font>"; else toScreenFinal = toScreenFinal + toScreen; // chatter.addTo(toScreen); // if(standardWindow) { // chatScreen.setCaretPosition(chatScreen.getDocument().getLength()); // } // else { JScrollBar vBar = scrollChat.getVerticalScrollBar(); int vSize = vBar.getVisibleAmount(); int maxVBar = vBar.getMaximum(); int currVBar = vBar.getValue() + vSize; kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null); if (maxVBar == currVBar) { chatScreen.setCaretPosition(chatScreen.getDocument().getLength()); } // } // kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null); }
void editorPane_keyPressed(KeyEvent e) { StyledDocument doc = editorPane.getStyledDocument(); int pos = editorPane.getCaretPosition(); int code = e.getKeyCode(); Element el; switch (code) { case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_DELETE: case KeyEvent.VK_LEFT: case KeyEvent.VK_KP_LEFT: if (pos == 0) return; // we want to get the element to the left of position. el = doc.getCharacterElement(pos - 1); break; case KeyEvent.VK_RIGHT: case KeyEvent.VK_KP_RIGHT: // we want to get the element to the right of position. el = doc.getCharacterElement(pos + 1); break; default: return; // bail we don't handle it. } AttributeSet attr = el.getAttributes(); String el_name = (String) attr.getAttribute(StyleConstants.NameAttribute); int el_range = el.getEndOffset() - el.getStartOffset() - 1; if (el_name.startsWith("Parameter") && StyleConstants.getComponent(attr) != null) { try { switch (code) { case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_DELETE: doc.remove(el.getStartOffset(), el_range); break; case KeyEvent.VK_LEFT: case KeyEvent.VK_KP_LEFT: editorPane.setCaretPosition(pos - el_range); break; case KeyEvent.VK_RIGHT: case KeyEvent.VK_KP_RIGHT: editorPane.setCaretPosition(pos + (el_range)); break; } } catch (BadLocationException ex) { } } }
public void appendToPane(String msg, Color c) { if (inputText.isEnabled()) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); textArea.setCharacterAttributes(aset, false); textArea.replaceSelection(msg); textArea.setCaretPosition(textArea.getDocument().getLength()); } }
public static void appendToPane(JTextPane tp, String msg, Color c) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED); int len = tp.getDocument().getLength(); tp.setCaretPosition(len); tp.setCharacterAttributes(aset, false); tp.replaceSelection(msg); }
private void displayMessage(String text, AttributeSet as) { try { if (!text.endsWith("\n")) { text += "\n"; } jTextPaneDisplayMessages .getDocument() .insertString(jTextPaneDisplayMessages.getDocument().getLength(), text, as); jTextPaneDisplayMessages.setCaretPosition(jTextPaneDisplayMessages.getDocument().getLength()); } catch (BadLocationException ex) { } }
// Update the box that shows current actions. public void updateGUI(String message) { StyledDocument text = updateBox.getStyledDocument(); SimpleAttributeSet currentWords = new SimpleAttributeSet(); StyleConstants.setBold(currentWords, true); SimpleAttributeSet pastWords = new SimpleAttributeSet(); StyleConstants.setBold(pastWords, false); try { text.setCharacterAttributes(0, text.getLength(), pastWords, true); text.insertString(0, message + "\n", currentWords); } catch (BadLocationException e) { // TODO Auto-generated catch block System.err.println("Bad location exception while styling updateBox."); e.printStackTrace(); } updateBox.setCaretPosition(0); }
private void decompile(Map params) { try { ClazzSourceView csv = ClazzSourceViewFactory.getClazzSourceView(clazz); csv.setDecompileParameters(params); source = csv.getSource(); String sourceText = source; sourceText = sourceText.replaceAll(" ", " "); sourceText = sourceText.replaceAll("<", "<"); sourceText = sourceText.replaceAll(">", ">"); sourceText = sourceText.replaceAll("\n", "<BR>"); sourcePane.setText(sourceText); sourcePane.setCaretPosition(0); } catch (Throwable ex) { if (Utils.hasDebug()) { ex.printStackTrace(); } sourcePane.setText("Exception occured while decompiling"); String link = "http://sourceforge.net/tracker/?group_id=226227&atid=1066690"; String exception = unpackException(ex); JTextPane text = new JTextPane(); text.setContentType("text/html"); text.setText( "<html>Error occured while decompiling!<BR>Please submit bug at <b>" + link + "</b><BR>" + exception + "</html>"); text.setEditable(false); text.setBackground(this.getBackground()); JOptionPane.showMessageDialog(this, text, "Error", JOptionPane.ERROR_MESSAGE); throw new IllegalArgumentException("Error decompiling"); } }
/** * Build the UI of the given process according to the given data. * * @param processExecutionData Process data. * @return The UI for the configuration of the process. */ public JComponent buildUIExec(ProcessExecutionData processExecutionData) { JPanel panel = new JPanel(new MigLayout("fill")); JPanel executorPanel = new JPanel(new MigLayout()); executorPanel.setBorder(BorderFactory.createTitledBorder("Executor :")); executorPanel.add(new JLabel("localhost")); JPanel statusPanel = new JPanel(new MigLayout()); statusPanel.setBorder(BorderFactory.createTitledBorder("Status :")); stateLabel = new JLabel(processExecutionData.getState().getValue()); statusPanel.add(stateLabel); JPanel resultPanel = new JPanel(new MigLayout()); resultPanel.setBorder(BorderFactory.createTitledBorder("Result :")); for (Output o : processExecutionData.getProcess().getOutput()) { JLabel title = new JLabel(o.getTitle() + " : "); JLabel result = new JLabel(); result.putClientProperty("URI", o.getIdentifier()); outputJLabelList.add(result); resultPanel.add(title); resultPanel.add(result, "wrap"); } JPanel logPanel = new JPanel(new BorderLayout()); logPanel.setBorder(BorderFactory.createTitledBorder("Log :")); logPane = new JTextPane(); logPane.setCaretPosition(0); JScrollPane scrollPane = new JScrollPane(logPane); logPanel.add(scrollPane, BorderLayout.CENTER); panel.add(executorPanel, "growx, wrap"); panel.add(statusPanel, "growx, wrap"); panel.add(resultPanel, "growx, wrap"); panel.add(logPanel, "growx, growy, wrap"); return panel; }