/** * Create a line number component for a text component. * * @param component the related text component * @param minimumDisplayDigits the number of digits used to calculate * the minimum width of the component */ public TextLineNumber(JTextComponent component, int minimumDisplayDigits) { this.component = component; setFont(component.getFont()); setBorderGap(5); setCurrentLineForeground(Color.RED); setDigitAlignment(RIGHT); setMinimumDisplayDigits(minimumDisplayDigits); component.getDocument().addDocumentListener(this); component.addCaretListener(this); component.addPropertyChangeListener("font", this); }
@Override public void install(JEditorPane editor) { pane = editor; pane.addCaretListener(this); status = Status.INSTALLING; }
@Override public void install(JEditorPane editor) { pane = editor; pane.addCaretListener(this); status = Status.INSTALLING; }
public void addTo(JTextComponent tc) { tc.addFocusListener(this); tc.getDocument().addDocumentListener(this); tc.addCaretListener(this); }
public void establishUndoableEditListener( JTextComponent editor ) { editor.getDocument().addUndoableEditListener( this ); editor.addCaretListener( this ); _editor = editor; }
public void establishUndoableEditListener( JTextComponent editor ) { editor.getDocument().addUndoableEditListener( this ); editor.addCaretListener( this ); _editor = editor; }
public CaretMonitor(JTextComponent text, JLabel label) { this.label = label; this.text = text; text.addCaretListener(this); updateLabel(text.getCaretPosition()); }
/** Creates a new instance of ComponentPeer */ private ComponentPeer(JTextComponent pane) { this.pane = pane; // reschedule(); pane.addPropertyChangeListener(this); pane.addCaretListener(this); pane.addAncestorListener(this); document = pane.getDocument(); document.addDocumentListener(this); ancestorAdded(null); }
@Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("document")) { pane.removeCaretListener(this); if (status.equals(Status.INSTALLING)) { pane.addCaretListener(this); removeMarkers(); } } } }
public CaretMonitor(JTextComponent text, JLabel label) { this.label = label; this.text = text; text.addCaretListener(this); updateLabel(text.getCaretPosition()); }
@Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("document")) { pane.removeCaretListener(this); if (status.equals(Status.INSTALLING)) { pane.addCaretListener(this); removeMarkers(); } } } }
public void stateChanged(ChangeEvent e) { List<JTextComponent> added = new ArrayList<JTextComponent>(OpenedEditors.getDefault().getVisibleEditors()); List<JTextComponent> removed = new ArrayList<JTextComponent>(component2Listener.keySet()); added.removeAll(component2Listener.keySet()); removed.removeAll(OpenedEditors.getDefault().getVisibleEditors()); for (JTextComponent c : removed) { c.removeCaretListener(component2Listener.remove(c)); } for (JTextComponent c : added) { ComponentListener l = new ComponentListener(c); c.addCaretListener(l); component2Listener.put(c, l); //TODO: are we in AWT Thread?: setLastSelection(OpenedEditors.getFileObject(c), c.getSelectionStart(), c.getSelectionEnd()); } fileObjectsChanged(); }
public void stateChanged(ChangeEvent e) { List<JTextComponent> added = new ArrayList<JTextComponent>(OpenedEditors.getDefault().getVisibleEditors()); List<JTextComponent> removed = new ArrayList<JTextComponent>(component2Listener.keySet()); added.removeAll(component2Listener.keySet()); removed.removeAll(OpenedEditors.getDefault().getVisibleEditors()); for (JTextComponent c : removed) { c.removeCaretListener(component2Listener.remove(c)); } for (JTextComponent c : added) { ComponentListener l = new ComponentListener(c); c.addCaretListener(l); component2Listener.put(c, l); //TODO: are we in AWT Thread?: setLastPosition(OpenedEditors.getFileObject(c), c.getCaretPosition()); } fileObjectsChanged(); }
/** * Creates new form FindDialog * @param text * @param dsd DocumentSerachData */ public ReplaceDialog(JTextComponent text, DocumentSearchData dsd) { super(SwingUtilities.getWindowAncestor(text), ModalityType.MODELESS.MODELESS); initComponents(); textComponent = text; this.dsd = dsd; textComponent.addCaretListener(this); setLocationRelativeTo(text.getRootPane()); getRootPane().setDefaultButton(jBtnNext); SwingUtils.addEscapeListener(this); jBtnReplaceAll.setEnabled(text.isEditable() && text.isEnabled()); }
public static void createCaretListeners(ActionContext actionContext){ Thing self = (Thing) actionContext.get("self"); JTextComponent parent = (JTextComponent) actionContext.get("parent"); for(Thing child : self.getChilds()){ CaretListener l = (CaretListener) child.doAction("create", actionContext); if(l != null){ parent.addCaretListener(l); } } }
/** * Creates new form FindDialog * @param text * @param dsd DocumentSerachData */ public ReplaceDialog(JTextComponent text, DocumentSearchData dsd) { super(SwingUtilities.getWindowAncestor(text), ModalityType.MODELESS.MODELESS); initComponents(); textComponent = text; this.dsd = dsd; textComponent.addCaretListener(this); setLocationRelativeTo(text.getRootPane()); getRootPane().setDefaultButton(jBtnNext); SwingUtils.addEscapeListener(this); jBtnReplaceAll.setEnabled(text.isEditable() && text.isEnabled()); }
public TextLineNumbersPanel(JTextComponent component, int minimumDisplayDigits, Border border, int borderGap, ALIGNMENT alignment) { this.component = component; setBackground(Color.LIGHT_GRAY); setForeground(Color.black); setCurrentLineForeground(new Color(0,0,255)); setDigitAlignment(alignment); setBorder(border, borderGap); setMinimumDisplayDigits( minimumDisplayDigits); setFont(component.getFont()); component.getDocument().addDocumentListener(this); component.addPropertyChangeListener("font", this); component.addCaretListener(this); }
public LinePainter(JTextComponent component, Color color) { this.component = component; setColor(color); // Add listeners so we know when to change highlighting component.addCaretListener(this); component.addMouseListener(this); component.addMouseMotionListener(this); // Turn highlighting on by adding a dummy highlight try { component.getHighlighter().addHighlight(0, 0, this); } catch (BadLocationException ble) { } }
/** * Installs CurrentLineHilighter for the given JTextComponent. * @param c is the text component */ public static void install(JTextComponent c) { try { Object obj = c.getHighlighter().addHighlight(0, 0, painter); c.putClientProperty(LINE_HIGHLIGHT, obj); c.putClientProperty(PREVIOUS_CARET, new Integer(c.getCaretPosition())); c.addCaretListener(caretListener); c.addMouseListener(mouseListener); c.addMouseMotionListener(mouseMotionListener); color = EditorThemePropertiesManager.getCurrentEditorThemeProperties().getHighlightedLineColor(); EditorThemePropertiesManager.addListener(editorThemePropertyChangeListener); } catch (BadLocationException ex) {} }
void updateFocusOwner(JComponent oldOwner, JComponent newOwner) { if (oldOwner instanceof JTextComponent) { JTextComponent text = (JTextComponent) oldOwner; text.removeCaretListener(textComponentCaretListener); text.removePropertyChangeListener(textComponentPCL); } if (newOwner instanceof JTextComponent) { JTextComponent text = (JTextComponent) newOwner; maybeInstallTextActions(text); updateTextActions(text); text.addCaretListener(textComponentCaretListener); text.addPropertyChangeListener(textComponentPCL); } else if (newOwner == null) { setCopyEnabled(false); setCutEnabled(false); setPasteEnabled(false); setDeleteEnabled(false); setSelectAllEnabled(false); } }