/** * Creates new form WikiEditPanel */ public WikiEditPanel(String wikiLanguage, boolean editing, boolean switchable) { this.wikiLanguage = wikiLanguage; this.switchable = switchable; this.wikiFormatText = ""; this.htmlFormatText = ""; initComponents(); pnlButtons.setVisible(switchable); textCode.getDocument().addDocumentListener(new RevalidatingListener()); textPreview.getDocument().addDocumentListener(new RevalidatingListener()); textCode.addCaretListener(new CaretListener() { @Override public void caretUpdate(CaretEvent e) { makeCaretVisible(textCode); } }); textCode.getDocument().addDocumentListener(new EnablingListener()); // A11Y - Issues 163597 and 163598 UIUtils.fixFocusTraversalKeys(textCode); UIUtils.issue163946Hack(scrollCode); Spellchecker.register(textCode); textPreview.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); setEditing(editing); }
private void updateActiveEditor() { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(this); return; } JTextComponent c = findActivePane(); if (c == null) { editorReleased(); return; } if (activeEditor != null && activeEditor.get() == c) { return; } editorReleased(); activeEditor = new WeakReference<>(c); wCaretL = WeakListeners.create(CaretListener.class, this, c); c.addCaretListener(this); selectCurrentNode(); }
public TableViewLayoutTest() { super("Code example for a TableView bug"); setUndecorated(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); edit.setEditorKit(new CodeBugEditorKit()); initCodeBug(); this.getContentPane().add(new JScrollPane(edit)); this.pack(); this.setLocationRelativeTo(null); edit.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { JTextComponent textComp = (JTextComponent) e.getSource(); try { Rectangle rect = textComp.getUI().modelToView(textComp, e.getDot()); yCaret = rect.getY(); xCaret = rect.getX(); } catch (BadLocationException ex) { throw new RuntimeException("Failed to get pixel position of caret", ex); } } }); }
RowColumnLabel(ISQLEntryPanel sqlEntryPanel) { super(" ", JLabel.CENTER); _sqlEntryPanel = sqlEntryPanel; sqlEntryPanel.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { onCaretUpdate(e); } }); writePosition(0,0, 0); setToolTipText(s_stringMgr.getString("RowColumnLabel.tooltip")); }
/** * Feature Request [1707462] * Set VFormat * @param strMask mask * @author fer_luck */ public void setVFormat (String strMask) { m_VFormat = strMask; //Get the actual caret from the field, if there's no //caret then just catch the exception and continue //creating the new caret. try{ CaretListener [] cl = this.getCaretListeners(); this.removeCaretListener(cl[0]); } catch(ClassCastException ex ){ log.debug("VString.setVFormat - No caret Listeners"); } //hengsin: [ adempiere-Bugs-1891037 ], preserve current data before change of format String s = getText(); setDocument(new MDocString(m_VFormat, m_fieldLength, this)); setText(s); }
public SlotConstTraitDetailPanel(final DecompiledEditorPane editor) { slotConstEditor = new LineMarkedEditorPane(); setLayout(new BorderLayout()); add(new JScrollPane(slotConstEditor), BorderLayout.CENTER); slotConstEditor.setFont(Configuration.getSourceFont()); slotConstEditor.changeContentType("text/flasm3"); slotConstEditor.addCaretListener(new CaretListener() { @Override public void caretUpdate(CaretEvent e) { if (ignoreCaret) { return; } Highlighting spec = Highlighting.searchPos(specialHilights, slotConstEditor.getCaretPosition()); if (spec != null) { editor.hilightSpecial(spec.getProperties().subtype, (int) spec.getProperties().index); slotConstEditor.getCaret().setVisible(true); } } }); }
protected void addTextOption(TextPropertyConfigurationOption option, Component control) { String defaultValue = this.model.getProperty(option.getName()); if (defaultValue == null) { defaultValue = option.getDefaultValue(); } final String requiredField = option.getName(); final JTextField valueField = new JTextField(defaultValue); if (option.isRequired()) { boolean isSet = defaultValue != null && defaultValue.trim().length() > 0; this.requiredFields.put(option.getName(), isSet); valueField.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent evt) { if (PropertyConfigurationStep.this.requiredFields.containsKey(requiredField)) { boolean selected = valueField.getText() != null && valueField.getText().trim().length() > 0; PropertyConfigurationStep.this.requiredFields.put(requiredField, selected); PropertyConfigurationStep.this.checkComplete(); } } }); } addOption(option.getName(), option.getDescription(), valueField, control); }
protected void addPasswordOption(PasswordPropertyConfigurationOption option) { String defaultValue = this.model.getProperty(option.getName()); if (defaultValue == null) { defaultValue = option.getDefaultValue(); } final String requiredField = option.getName(); final JPasswordField valueField = new JPasswordField(defaultValue); if (option.isRequired()) { boolean isSet = defaultValue != null && defaultValue.trim().length() > 0; this.requiredFields.put(option.getName(), isSet); valueField.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent evt) { if (PropertyConfigurationStep.this.requiredFields.containsKey(requiredField)) { boolean selected = valueField.getPassword() != null && String.valueOf(valueField.getPassword()).trim().length() > 0; PropertyConfigurationStep.this.requiredFields.put(requiredField, selected); PropertyConfigurationStep.this.checkComplete(); } } }); } addOption(option.getName(), option.getDescription(), valueField); }
/** * constructor * * @param textArea the textArea-instance */ public SourceMenuPanel(JTextArea textArea) { super(new FlowLayout(FlowLayout.LEFT,5,2)); _textArea = textArea; Document doc = _textArea.getDocument(); doc.addUndoableEditListener(new MyUndoableEditListener()); createActionTable(); _textArea.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { boolean select = e.getDot() != e.getMark(); _btnCut.setEnabled(select); _btnCopy.setEnabled(select); } }); initLayout(); }
/** * updates the inputPane-area, if references were imported from a file * * @param bibTexStrng * a string containing the raw bibtext references */ public static void setInput(String bibTexString) { if (clearInput) { final CaretListener[] clis = inputPane.getCaretListeners(); final CaretListener cli = clis[0]; inputPane = new JTextArea(); inputPane.setText(bibTexString); inputPane.addCaretListener(cli); } else { inputPane.setText(bibTexString); } inputPane.validate(); }
private CaretListener createCaretListenerForComponent() { return new CaretListener() { @Override public void caretUpdate(CaretEvent e) { if (SearchBar.getInstance().isVisible()) { int num = SearchBar.getInstance().getNumOfMatches(); SearchBar.getInstance().showNumberOfMatches(null, num); } } }; }
/** * Creates new form TaskPanel */ public TaskPanel (LocalTask task) { this.task = task; initComponents(); updateReadOnlyField(headerField); Font font = new JLabel().getFont(); headerField.setFont(font.deriveFont((float) (font.getSize() * 1.7))); mainScrollPane.getVerticalScrollBar().setUnitIncrement(10); privateNotesField.addCaretListener(new CaretListener() { @Override public void caretUpdate (CaretEvent e) { makeCaretVisible(privateNotesField); } }); // A11Y - Issues 163597 and 163598 UIUtils.fixFocusTraversalKeys(privateNotesField); initSpellChecker(); attachmentsPanel = new AttachmentsPanel(this); attachmentsSection.setContent(attachmentsPanel); GroupLayout layout = (GroupLayout) attributesPanel.getLayout(); dueDatePicker = UIUtils.createDatePickerComponent(); scheduleDatePicker = new SchedulePicker(); layout.replace(dummyDueDateField, dueDatePicker.getComponent()); dueDateLabel.setLabelFor(dueDatePicker.getComponent()); layout.replace(dummyScheduleDateField, scheduleDatePicker.getComponent()); scheduleDateLabel.setLabelFor(scheduleDatePicker.getComponent()); attachListeners(); }
protected void fireCaretEvent() { Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i--) { if (listeners[i] == CaretListener.class) { ((CaretListener) listeners[i + 1]).caretUpdate(caretEvent); } } }
public CodeReader() { setEditable(false); setContentType("text/java"); // turn off token highlighting (it's wrong most of the time anyway...) DefaultSyntaxKit kit = (DefaultSyntaxKit)getEditorKit(); kit.toggleComponent(this, "de.sciss.syntaxpane.components.TokenMarker"); // hook events addCaretListener(new CaretListener() { @Override public void caretUpdate(CaretEvent event) { if (m_selectionListener != null && m_sourceIndex != null) { Token token = m_sourceIndex.getReferenceToken(event.getDot()); if (token != null) { m_selectionListener.onSelect(m_sourceIndex.getDeobfReference(token)); } else { m_selectionListener.onSelect(null); } } } }); m_selectionHighlightPainter = new SelectionHighlightPainter(); m_sourceIndex = null; m_selectionListener = null; }
/** * Maps {@code JTextComponent.addCaretListener(CaretListener)} through queue */ public void addCaretListener(final CaretListener caretListener) { runMapping(new MapVoidAction("addCaretListener") { @Override public void map() { ((JTextComponent) getSource()).addCaretListener(caretListener); } }); }
/** * Maps {@code JTextComponent.removeCaretListener(CaretListener)} * through queue */ public void removeCaretListener(final CaretListener caretListener) { runMapping(new MapVoidAction("removeCaretListener") { @Override public void map() { ((JTextComponent) getSource()).removeCaretListener(caretListener); } }); }
@Override public void addCaretListener(CaretListener listener) { if (this.ipFields != null) { for (JIPV4Field field : this.ipFields) { field.addCaretListener(listener); } } }
@Override public void removeCaretListener(CaretListener listener) { if (this.ipFields != null) { for (JIPV4Field field : this.ipFields) { field.removeCaretListener(listener); } } }
public Comment(Listener listener) { m_listener = listener; m_textPane = new JTextPane(); setFocusTraversalKeys(m_textPane); GuiUtil.addStyle(m_textPane, "marked", Color.white, Color.decode("#38d878"), false); setPreferredSize(); m_textPane.getDocument().addDocumentListener(this); CaretListener caretListener = new CaretListener() { public void caretUpdate(CaretEvent event) { if (m_listener == null) return; m_listener.textSelected(m_textPane.getSelectedText()); } }; m_textPane.addCaretListener(caretListener); setViewportView(m_textPane); setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); if (Platform.isMac()) m_normalFont = new Font("Lucida Grande", Font.PLAIN, 11); else m_normalFont = UIManager.getFont("TextPane.font"); setMonoFont(false); }
/** * @param ce if the source inside the event is not null, that component will be excluded from * the list of components to be notified about the caret event. */ public void fireValueChanged(CaretEvent ce) { for (int loop=size()-1; loop>=0; loop--) { CaretListener cl = (CaretListener) get(loop); if (ce==null || cl!=ce.getSource()) { // System.out.println("fireValueChanged: tsl: "+tsl); // System.out.println("fireValueChanged: tse.getSource(): "+tse.getSource()); cl.caretUpdate(ce); } } }
public HostConnectionParameter() { super(); defaultName = true; JPanel namePane = new JPanel(new GridLayout(0, 2)); namePane.add(new JLabel("Name")); name = new JTextField(20); name.addCaretListener(new CaretListener() { @Override public void caretUpdate(CaretEvent e) { defaultName = false; } }); namePane.add(name); hostParametersPane = new JPanel(new GridLayout(0, 2)); hostParametersPane.add(new JLabel("Host")); host = new JTextField(20); host.addCaretListener(this); hostParametersPane.add(host); hostParametersPane.add(new JLabel("Port")); port = new JTextField(5); port.addCaretListener(this); hostParametersPane.add(port); hostParametersPane.add(new JLabel("Username")); username = new JTextField(20); hostParametersPane.add(username); hostParametersPane.add(new JLabel("Password")); password = new JTextField(20); hostParametersPane.add(password); host.requestFocusInWindow(); }
/** * Bind a CaretListener. * <p> * This method propagates caret events to wizard panel change events. * * @param source an object implementing addCaretListener. */ public boolean bindCaretListener( Object source ) { boolean bound = false; try { final CaretListener caretListener = getCaretListener(); final CaretListener weakCaretListener = (CaretListener) WeakListeners.create( CaretListener.class, caretListener, source ); final Method m = source.getClass().getMethod( "addCaretListener", CaretListener.class ); m.invoke( source, weakCaretListener ); bound = true; } catch (Exception ex) { ErrorManager.getDefault().notify( ex ); } return bound; }
public void open(JTextArea ta, GUILog logPlugin) { this.logPlugin = logPlugin; textArea = ta; textArea.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { if (GUIWindowLog.this.logPlugin != null) GUIWindowLog.this.logPlugin.getSelectionChangeHandler().notifyListeners(new GUIEvent(1)); } }); updater = new GUIWindowLogUpdater(this, textArea); updater.start(); }
protected void fireCaretUpdate(CaretEvent e) { CaretListener[] carets = JTextComponent.this.getCaretListeners(); if(carets != null){ for (int i = 0; i < carets.length; i++) { carets[i].caretUpdate(e); } } }
/** * Notifies all registered <code>CaretListener</code> objects that the caret * was updated. * * @param event the event to send */ protected void fireCaretUpdate(CaretEvent event) { CaretListener[] listeners = getCaretListeners(); for (int index = 0; index < listeners.length; ++index) listeners[index].caretUpdate(event); }
public CodeReader() { setEditable(false); setContentType("text/java"); // turn off token highlighting (it's wrong most of the time anyway...) DefaultSyntaxKit kit = (DefaultSyntaxKit)getEditorKit(); kit.toggleComponent(this, "de.sciss.syntaxpane.components.TokenMarker"); // hook events addCaretListener(new CaretListener() { @Override public void caretUpdate(CaretEvent event) { if(m_selectionListener != null && m_sourceIndex != null) { Token token = m_sourceIndex.getReferenceToken(event.getDot()); if(token != null) m_selectionListener.onSelect(m_sourceIndex .getDeobfReference(token)); else m_selectionListener.onSelect(null); } } }); m_selectionHighlightPainter = new SelectionHighlightPainter(); m_sourceIndex = null; m_selectionListener = null; }
/** * Creates new form ErrorReportFrame */ public ErrorReportFrame() { initComponents(); errorText.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent ce) { String sel = errorText.getSelectedText(); copyButton.setEnabled(sel != null); } }); }
protected void fireCaretEvent() { Object[] listeners = listenerList.getListenerList(); for(int i = listeners.length - 2; i >= 0; i--) { if(listeners[i] == CaretListener.class) { ((CaretListener)listeners[i+1]).caretUpdate(caretEvent); } } }
public LineEnabledTextPanel(final JTextComponent component) { this.setLayout(new BorderLayout()); textComponent = component; updateDocument(); JScrollPane scrollPane = new JScrollPane(textComponent ); scrollPane.setPreferredSize(textComponent.getPreferredSize() ); this.add(scrollPane, BorderLayout.CENTER);; final JLabel caretLabel = new JLabel("Line: 1 Column: 0"); setCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { int caretPosition = getCaretPosition(); Element root = document.getRootElements()[0]; int elementIndex = root.getElementIndex(caretPosition); int relativeOffset = caretPosition - root.getElement(elementIndex).getStartOffset(); caretLabel.setText("Line: " + (elementIndex + 1) + " Column: " + relativeOffset); }}); this.add(caretLabel, BorderLayout.SOUTH); KeyStroke gotoLineKeystroke = KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.META_MASK); gotoLineAction = new GotoLineAction(); textComponent.getInputMap().put(gotoLineKeystroke, "gotoLineKeystroke"); textComponent.getActionMap().put("gotoLineKeystroke", gotoLineAction); }
/** * Immer wenn der Cursor mit der Maus in einen Bereich innerhalb eines Tags gesetzt * wird, sorgt der hier registrierte caret Listener dafür, dass der Bereich auf das * gesamte Tag ausgedehnt wird. * * @author Christoph Lutz (D-III-ITD-5.1) */ private void changeCaretHandling() { compo.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { extraHighlightOff(); int dot = compo.getCaret().getDot(); int mark = compo.getCaret().getMark(); for (Iterator<TagPos> iter = getTagPosIterator(); iter.hasNext();) { TextComponentTags.TagPos fp = iter.next(); if (dot > fp.start && dot < fp.end) { if (dot < mark) { caretMoveDot(fp.start); } else if (dot > mark) { caretMoveDot(fp.end); } else { caretSetDot(fp.end); extraHighlight(fp.start, fp.end); } } } } }); }
@Override public void validateValue() { Amf3Importer importer = new Amf3Importer(); String textVal = editor.getText(); try { if (!textVal.trim().isEmpty()) { importer.stringToAmf(textVal); } } catch (IOException | Amf3ParseException ex) { if (ex instanceof Amf3ParseException) { Amf3ParseException ape = (Amf3ParseException) ex; if (ape.line > 0) { editor.gotoLine((int) ape.line); } } final CaretListener cl = new CaretListener() { @Override public void caretUpdate(CaretEvent e) { errorLabel.setVisible(false); editor.removeCaretListener(this); } }; editor.addCaretListener(cl); errorLabel.setText("<html>" + AppStrings.translate("error") + ":" + ex.getMessage() + "</html>"); errorLabel.setVisible(true); throw new IllegalArgumentException("Invalid AMF value", ex); } }
protected void fireCaretUpdate(final CaretEvent ce) { CaretListener[] listeners = getCaretListeners(); for (int i = 0; i < listeners.length; i++) { listeners[i].caretUpdate(ce); } if (ce != null) { handleComposedText(ce.getDot()); } }
public void testGetListeners() { ns.addChangeListener(this); EventListener[] listeners = ns.getListeners(ChangeListener.class); assertEquals(1, listeners.length); assertSame(this, listeners[0]); listeners = ns.getListeners(CaretListener.class); assertEquals(0, listeners.length); ns.removeChangeListener(this); listeners = ns.getListeners(ChangeListener.class); assertEquals(0, listeners.length); }
public void assertEquals(final Vector<SimpleCaretListener> listeners1, final CaretListener[] listeners2) { assertNotNull(listeners1); assertNotNull(listeners2); assertEquals(listeners1.size(), listeners2.length); for (int i = 0; i < listeners1.size(); i++) { assertEquals(listeners1.get(i), listeners2[i]); } }
/** * コンストラクタ */ public LineHighlightTextPaneUI() { CodePane.this.addCaretListener(new CaretListener() { @Override public void caretUpdate(CaretEvent e) { CodePane.this.repaint(); } }); }