/** * This method initializes jTextPane * * @return javax.swing.JTextPane */ private JTextPane getJTextPane() { if (jTextPane == null) { jTextPane = new JTextPane(); jTextPane.setEditorKit(new HTMLEditorKit()); HTMLDocument doc = new HTMLDocument() { private static final long serialVersionUID = 1L; @Override public Font getFont(AttributeSet attr) { Object family = attr.getAttribute(StyleConstants.FontFamily); Object size = attr.getAttribute(StyleConstants.FontSize); if (family == null && size == null) { return new Font("SansSerif", Font.PLAIN, currentFontSize); } return super.getFont(attr); } }; doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE); doc.setPreservesUnknownTags(false); jTextPane.setStyledDocument(doc); jTextPane.setEditable(false); } return jTextPane; }
public MUStatusComponent(final MUPrefs prefs) { super(VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_NEVER); // Setup our new status pane statusPane = new JTextPane(); statusPane.setBackground(Color.black); statusPane.setEditable(false); statusPaneWriter = new JTextPaneWriter(statusPane); newPreferences(prefs); statusPane.setStyledDocument(new BulkStyledDocument(100, mFont)); setViewportView(statusPane); }
/** * Updates the screen to be consistent with the internal ClientDataModel representation. * * @param t String representing the title of the document. Is guaranteed not to be null. */ protected void updateGUI(Integer d) { if (currentDocID == d) { // document changed is document being worked on if (dm.hasDoc(d)) currentDoc = dm.getDoc(d); else { // current document has been deleted currentDoc = new DefaultStyledDocument(); } textPane.setStyledDocument(currentDoc); } else { // document changed is not being worked on if (docIDList.contains(d) && !dm.hasDoc(d)) { // remove deleted document from selector int positionOfDoc = docIDList.indexOf(d); docSelect.remove(positionOfDoc); docIDList.remove(positionOfDoc); } else if (!docIDList.contains(d) && dm.hasDoc(d)) { // put in new document into selector docIDList.add(d); docSelect.addItem(dm.getTitle(d)); } } }
public void setStyledDocument(StyledDocument doc) { sentence.setStyledDocument(doc); }
/** Prepares a new <code>TerminalPanel</code> object. */ public TerminalPanel(final Host host) { super(); this.host = host; host.setTerminalPanel(this); /* Sets terminal some of the output colors. This is in no way complete * or correct and probably doesn't have to be. */ terminalColor.put("0", Tools.getDefaultColor("TerminalPanel.TerminalWhite")); terminalColor.put("30", Tools.getDefaultColor("TerminalPanel.TerminalBlack")); terminalColor.put("31", Tools.getDefaultColor("TerminalPanel.TerminalRed")); terminalColor.put("32", Tools.getDefaultColor("TerminalPanel.TerminalGreen")); terminalColor.put("33", Tools.getDefaultColor("TerminalPanel.TerminalYellow")); terminalColor.put("34", Tools.getDefaultColor("TerminalPanel.TerminalBlue")); terminalColor.put("35", Tools.getDefaultColor("TerminalPanel.TerminalPurple")); terminalColor.put("36", Tools.getDefaultColor("TerminalPanel.TerminalCyan")); final Font f = new Font("Monospaced", Font.PLAIN, Tools.getConfigData().scaled(14)); terminalArea = new JTextPane(); terminalArea.setStyledDocument(new MyDocument()); final DefaultCaret caret = new DefaultCaret() { private static final long serialVersionUID = 1L; @Override protected synchronized void damage(final Rectangle r) { if (r != null) { x = r.x; y = r.y; width = 8; height = r.height; repaint(); } } @Override public void paint(final Graphics g) { /* painting cursor. If it is not visible it is out of focus, we * make it barely visible. */ try { TextUI mapper = getComponent().getUI(); Rectangle r = mapper.modelToView(getComponent(), getDot(), getDotBias()); if (r == null) { return; } g.setColor(getComponent().getCaretColor()); if (isVisible() && editEnabled) { g.fillRect(r.x, r.y, 8, r.height); } else { g.drawRect(r.x, r.y, 8, r.height); } } catch (BadLocationException e) { Tools.appError("Drawing of cursor failed", e); } } }; terminalArea.setCaret(caret); terminalArea.addCaretListener( new CaretListener() { @Override public void caretUpdate(final CaretEvent e) { /* don't do this if caret moved because of selection */ mPosLock.lock(); try { if (e != null && e.getDot() < commandOffset && e.getDot() == e.getMark()) { terminalArea.setCaretPosition(commandOffset); } } finally { mPosLock.unlock(); } } }); /* set font and colors */ terminalArea.setFont(f); terminalArea.setBackground(Tools.getDefaultColor("TerminalPanel.Background")); commandColor = new SimpleAttributeSet(); StyleConstants.setForeground(commandColor, Tools.getDefaultColor("TerminalPanel.Command")); errorColor = new SimpleAttributeSet(); StyleConstants.setForeground(errorColor, Tools.getDefaultColor("TerminalPanel.Error")); outputColor = new SimpleAttributeSet(); defaultOutputColor = Tools.getDefaultColor("TerminalPanel.Output"); StyleConstants.setForeground(outputColor, defaultOutputColor); promptColor = new SimpleAttributeSet(); StyleConstants.setForeground(promptColor, host.getPmColors()[0]); append(prompt(), promptColor); terminalArea.setEditable(true); getViewport().add(terminalArea, BorderLayout.PAGE_END); setPreferredSize( new Dimension(Short.MAX_VALUE, Tools.getDefaultInt("MainPanel.TerminalPanelHeight"))); setMinimumSize(getPreferredSize()); setMaximumSize(getPreferredSize()); }