javax.swing.event.CaretEvent Java Examples

The following examples show how to use javax.swing.event.CaretEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextLineNumberRowHeader.java    From mae-annotation with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e)
{
    //  Get the line the caret is positioned on

    int caretPosition = component.getCaretPosition();
    Element root = component.getDocument().getDefaultRootElement();
    int currentLine = root.getElementIndex( caretPosition );

    //  Need to repaint so the correct line number can be highlighted

    if (lastLine != currentLine)
    {
        repaint();
        lastLine = currentLine;
    }
}
 
Example #2
Source File: TableViewLayoutTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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);
                }
            }
        });
    }
 
Example #3
Source File: WikiEditPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: ASTBrowserTopComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void caretUpdate (CaretEvent e) {
    if (rootNode == null) return;
    ASTPath path = rootNode.findPath (e.getDot ());
    if (path == null) return;
    TreeNode tNode = (TreeNode) tree.getModel ().getRoot ();
    List<TreeNode> treePath = new ArrayList<TreeNode> ();
    Iterator it = path.listIterator ();
    if (!it.hasNext ()) return;
    it.next ();
    treePath.add (tNode);
    while (tNode instanceof TNode && it.hasNext ()) {
        tNode = ((TNode) tNode).getTreeNode (it.next ());
        if (tNode == null) throw new NullPointerException ();
        treePath.add (tNode);
    }
    TreePath treePath2 = new TreePath (treePath.toArray ());
    DefaultTreeModel model = new DefaultTreeModel ((TreeNode) tree.getModel ().getRoot ());
    tree.setModel (model);
    tree.setSelectionPath (treePath2);
    tree.scrollPathToVisible (treePath2);
}
 
Example #5
Source File: CaretMarkProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
    final List<Mark> old = getMarks();
    
    marks = createMarks();
    
    final List<Mark> nue = getMarks();
    
    //Do not fire this event under the document's write lock
    //may deadlock with other providers:
    RP.post(new Runnable() {
        @Override
        public void run() {
            firePropertyChange(PROP_MARKS, old, nue);
        }
    });
}
 
Example #6
Source File: JSpinField.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * After any user input, the value of the textfield is proofed. Depending on
 * being an integer, the value is colored green or red.
 * 
 * @param e
 *            the caret event
 */
public void caretUpdate(CaretEvent e) {
	try {
		int testValue = Integer.valueOf(textField.getText()).intValue();

		if ((testValue >= min) && (testValue <= max)) {
			textField.setForeground(darkGreen);
			setValue(testValue, false, true);
		} else {
			textField.setForeground(Color.red);
		}
	} catch (Exception ex) {
		if (ex instanceof NumberFormatException) {
			textField.setForeground(Color.red);
		}

		// Ignore all other exceptions, e.g. illegal state exception
	}

	textField.repaint();
}
 
Example #7
Source File: JTextFieldDateEditor.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * After any user input, the value of the textfield is proofed. Depending on
 * being a valid date, the value is colored green or red.
 * 
 * @param event
 *            the caret event
 */
public void caretUpdate(CaretEvent event) {
	String text = getText().trim();
	String emptyMask = maskPattern.replace('#', placeholder);

	if (text.length() == 0 || text.equals(emptyMask)) {
		setForeground(Color.BLACK);
		return;
	}

	try {
		Date date = dateFormatter.parse(getText());
		if (dateUtil.checkDate(date)) {
			setForeground(darkGreen);
		} else {
			setForeground(Color.RED);
		}
	} catch (Exception e) {
		setForeground(Color.RED);
	}
}
 
Example #8
Source File: RoundMarkErrorStrip.java    From jd-gui with GNU General Public License v3.0 5 votes vote down vote up
public void caretUpdate(CaretEvent e) {
    if (getFollowCaret()) {
        int line = textArea.getCaretLineNumber();
        float percent = line / (float)(textArea.getLineCount()-1);
        textArea.computeVisibleRect(visibleRect);
        caretLineY = (int)(visibleRect.height*percent);
        if (caretLineY!=lastLineY) {
            repaint(0,lastLineY, getWidth(), 2); // Erase old position
            repaint(0,caretLineY, getWidth(), 2);
            lastLineY = caretLineY;
        }
    }
}
 
Example #9
Source File: QrToolBuilder.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
	if (input.getText().length() == 0) {
		output.setContentString(empty);
	}
	else {
		output.setContentString(input.getText());
	}
}
 
Example #10
Source File: EventSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void caretUpdate(final CaretEvent event) {
    final JTextComponent lastEditor = lastEditorRef == null ? null : lastEditorRef.get();
    if (lastEditor != null) {
        Document doc = lastEditor.getDocument ();
        String mimeType = DocumentUtilities.getMimeType (doc);
        if (doc != null && mimeType != null) {
            Source source = Source.create(doc);
            if (source != null) {
                ((EventSupport)SourceEnvironment.forSource(source)).resetState(false, false, -1, -1, false);
            }
        }
    }
}
 
Example #11
Source File: FormulaEditorPanel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Called when the caret position is updated.
 *
 * @param e the caret event
 */
public void caretUpdate( final CaretEvent e ) {
  if ( ignoreTextEvents ) {
    return;
  }

  editorModel.setCaretPosition( functionTextArea.getCaretPosition() );
  refreshInformationPanel();
  revalidateParameters( true );
}
 
Example #12
Source File: SelectCodeElementAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void caretUpdate(CaretEvent e) {
    if (!ignoreNextCaretUpdate) {
        synchronized (this) {
            selectionInfos = null;
            selIndex = -1;
        }
    }
    ignoreNextCaretUpdate = false;
}
 
Example #13
Source File: SearchBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
            }
        }
    };
}
 
Example #14
Source File: SelectionAwareJavaSourceTaskFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void caretUpdate(CaretEvent e) {
    JTextComponent component = componentRef == null ? null : componentRef.get();
    if (component == null) {
        return;
    }
    FileObject file = OpenedEditors.getFileObject(component);
    
    if (file != null) {
        setLastSelection(OpenedEditors.getFileObject(component), component.getSelectionStart(), component.getSelectionEnd());
        rescheduleTask.schedule(timeout);
    }
}
 
Example #15
Source File: POMModelPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
    JTextComponent cc = currentComponent != null ? currentComponent.get() : null;
    if (e.getSource() != cc) {
        ((JTextComponent)e.getSource()).removeCaretListener(this);
        //just a double check we do't get a persistent leak here..
        return;
    }
    currentDot = e.getDot();
    caretTask.schedule(1000);
}
 
Example #16
Source File: RowColumnLabel.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
private void onCaretUpdate(CaretEvent e)
{
	int caretLineNumber = _sqlEntryPanel.getCaretLineNumber();
	int caretLinePosition = _sqlEntryPanel.getCaretLinePosition();
     int caretPosition = _sqlEntryPanel.getCaretPosition();

	writePosition(caretLineNumber, caretLinePosition, caretPosition);
}
 
Example #17
Source File: CaretAwareJavaSourceTaskFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void caretUpdate(CaretEvent e) {
    JTextComponent c = component.get();
    if (c == null) {
        return;
    }
    FileObject file = OpenedEditors.getFileObject(c);
    
    if (file != null) {
        setLastPosition(file, c.getCaretPosition());
        rescheduleTask.schedule(timeout);
    }
}
 
Example #18
Source File: SelectCodeElementAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void caretUpdate(CaretEvent e) {
    assert SwingUtilities.isEventDispatchThread();
    if (!ignoreNextCaretUpdate) {
        synchronized (this) {
            selectionInfos = null;
            selIndex = -1;
        }
    }
}
 
Example #19
Source File: AbbrevDetection.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void caretUpdate(CaretEvent evt) {
    if (evt.getDot() != evt.getMark()) {
        surroundsWithTimer.setInitialDelay(SURROUND_WITH_DELAY);
        surroundsWithTimer.restart();
    } else {
        surroundsWithTimer.stop();
        hideSurroundWithHint();
    }
}
 
Example #20
Source File: PlainTextEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void caretUpdate (final CaretEvent e) {
  final String text;
  if (this.lastEditor == null) {
    text = "...:...";
  }
  else {
    final int pos = this.lastEditor.getCaretPosition();
    final int col = getColumn(pos, this.lastEditor);
    final int row = getRow(pos, this.lastEditor);
    text = row + ":" + col;
  }
  this.labelCursorPos.setText(text);
}
 
Example #21
Source File: ToolsInternalFrame.java    From chipster with MIT License 5 votes vote down vote up
public void caretUpdate(CaretEvent e) {
	Object source = e.getSource();
	
	// Custom delimeter field
	if (source == customDelimField) {
		if (customDelimRadioButton.isSelected()) {
			String customDelim = customDelimField.getText();
			if (customDelim != null && customDelim.length() > 0) {
				this.setDelim(customDelim);
			} else {
				customDelimField.setForeground(Color.BLACK);
			}	
		}
	}
}
 
Example #22
Source File: JTagsDialog.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
	String name = jTextField.getText();
	if (unique.contains(name) && (editTag == null || !editTag.getName().equals(name))) {
		ColorSettings.config(jTextField, ColorEntry.GLOBAL_ENTRY_INVALID);
		jOK.setEnabled(false);
	} else {
		jOK.setEnabled(true);
		jTextField.setBackground(Color.WHITE);
	}
}
 
Example #23
Source File: EditorCurrentLineHighlighter.java    From SikuliX1 with MIT License 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent evt) {
  JTextComponent comp = (JTextComponent) evt.getSource();
  if (comp != null) {
    if (comp.getSelectionStart() != comp.getSelectionEnd()) {
      // cancel line highlighting if selection exists
      removeLineHighlight(comp);
      comp.repaint();
      return;
    }
    int pos = comp.getCaretPosition();
    Element elem = Utilities.getParagraphElement(comp, pos);
    int start = elem.getStartOffset();
    int end = elem.getEndOffset();
    Document doc = comp.getDocument();
    Element root = doc.getDefaultRootElement();
    int line = root.getElementIndex(pos);
    Debug.log(5, "LineHighlight: Caret at " + pos + " line " + line + " for " + start + "-" + end);
    if (SikulixIDE.getStatusbar() != null) {
      SikulixIDE.getStatusbar().setCaretPosition(line + 1, pos - start + 1);
    }
    removeLineHighlight(comp);
    try {
      highlight = comp.getHighlighter().addHighlight(start, end, painter);
      comp.repaint();
    } catch (BadLocationException ex) {
      Debug.error(me + "Problem while highlighting line %d\n%s", pos, ex.getMessage());
    }
  }
}
 
Example #24
Source File: ComponentController.java    From swingsane with Apache License 2.0 5 votes vote down vote up
private void batchNameCaretUpdateActionPerformed(CaretEvent e) {
  ScannerListItem currentScannerListItem = components.getScannerList().getSelectedValue();
  if (currentScannerListItem == null) {
    return;
  }
  Scanner scanner = currentScannerListItem.getScanner();
  if (scanner == null) {
    return;
  }
  scanner.setBatchPrefix(components.getBatchNameTextField().getText());
}
 
Example #25
Source File: TokenMarker.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
    int pos = e.getDot();
    SyntaxDocument doc = ActionUtils.getSyntaxDocument(pane);
    Token token = doc.getTokenAt(pos);
    removeMarkers();
    if (token != null && tokenTypes.contains(token.type)) {
        addMarkers(token);
    }
}
 
Example #26
Source File: PairsMarker.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
    removeMarkers();
    int pos = e.getDot();
    SyntaxDocument doc = ActionUtils.getSyntaxDocument(pane);
    Token token = doc.getTokenAt(pos);
    if (token != null && token.pairValue != 0) {
        Markers.markToken(pane, token, marker);
        Token other = doc.getPairFor(token);
        if (other != null) {
            Markers.markToken(pane, other, marker);
        }
    }
}
 
Example #27
Source File: TextLineNumber.java    From Digital with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
    //  Get the line the caret is positioned on

    int caretPosition = component.getCaretPosition();
    Element root = component.getDocument().getDefaultRootElement();
    int currentLine = root.getElementIndex(caretPosition);

    //  Need to repaint so the correct line number can be highlighted

    if (lastLine != currentLine) {
        repaint();
        lastLine = currentLine;
    }
}
 
Example #28
Source File: TextComponentHighlighter.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
	// see notes in the similar docListener
	synchronized (caretListener) {
		dirty = true;
		SwingUtilities.invokeLater(rehighlightRunnable);
	}
}
 
Example #29
Source File: PairsMarker.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
    removeMarkers();
    int pos = e.getDot();
    SyntaxDocument doc = ActionUtils.getSyntaxDocument(pane);
    Token token = doc.getTokenAt(pos);
    if (token != null && token.pairValue != 0) {
        Markers.markToken(pane, token, marker);
        Token other = doc.getPairFor(token);
        if (other != null) {
            Markers.markToken(pane, other, marker);
        }
    }
}
 
Example #30
Source File: TaskPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}