Java Code Examples for javax.swing.event.CaretEvent

The following are top voted examples for showing how to use javax.swing.event.CaretEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: CaretMarkProvider.java   View source code 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 2
Project: incubator-netbeans   File: SubmitPanel.java   View source code 6 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
    int offset = text.getCaretPosition();
    
    Node[] arr = getExplorerManager().getRootContext().getChildren().getNodes(true);
    int index = Arrays.binarySearch(arr, offset, this);
    if (index < -1) {
        index = -index - 2;
    }
    if (index >= 0 && index < arr.length) {
        try {
            getExplorerManager().removePropertyChangeListener(this);
            getExplorerManager().setSelectedNodes(new Node[]{arr[index]});
        } catch (PropertyVetoException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            getExplorerManager().addPropertyChangeListener(this);
        }
    }
}
 
Example 3
Project: incubator-netbeans   File: WikiEditPanel.java   View source code 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
Project: BEAST   File: TextLineNumber.java   View source code 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 5
Project: BEAST   File: OpenCloseCharHighlighter.java   View source code 6 votes vote down vote up
@Override
public void caretUpdate(CaretEvent ce) {
    removeAllHighlights();
    char surroundingChars[] = {' ', ' '};
    try {            
        surroundingChars[0] = JTextPaneToolbox.getCharToTheLeftOfCaret(pane).charAt(0);
        surroundingChars[1] = JTextPaneToolbox.getCharToTheRightOfCaret(pane).charAt(0);
    } catch (StringIndexOutOfBoundsException ex) {            
    }
    for (int i = 0; i < surroundingChars.length; i++) {
        char c = surroundingChars[i];
        if(c == ' ') continue;
        if(charList.isOpenChar(c)) {
            highlightChar(ce.getDot() + i);
            highlightCorrespondingCloseChar(ce.getDot() + i, charList.getOpenCloseChar(c));
            return;
        } else if(charList.isCloseChar(c)) {
            highlightChar(ce.getDot() + i);
            highlightCorrespondingOpenChar(ce.getDot() + i, charList.getOpenCloseChar(c));
            return;
        }
    }
}
 
Example 6
Project: scratch-bench   File: MainMenu.java   View source code 6 votes vote down vote up
/**
     * Creates new form MainMenu
     */
public void caretUpdate(CaretEvent ce) {
           
         SyntaxDocument sDoc = ActionUtils.getSyntaxDocument(editorPanes.get(tabbedPane.getSelectedIndex()));
         if (sDoc != null) {
             Token t = sDoc.getTokenAt(ce.getDot());
             if (t != null) {
                 CharSequence tData = t.getText(sDoc);
                 if (t.length > 40) {
                     tData = tData.subSequence(0, 40);
                 }
                 caretPosLabel.setText(t.toString() + ": " + tData);
             } else {
                 // null token, remove the status
//				lblToken.setText(java.util.ResourceBundle.getBundle("jsyntaxpane/Bundle").getString("NO_TOKEN_AT_CURSOR"));
             }
         }
              }
 
Example 7
Project: powertext   File: AutoCompletePopupWindow.java   View source code 6 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
	if (isVisible()) { // Should always be true
		int line = ac.getLineOfCaret();
		if (line!=lastLine) {
			lastLine = -1;
			setVisible(false);
		}
		else {
			doAutocomplete();
		}
	}
	else if (AutoCompletion.getDebug()) {
		Thread.dumpStack();
	}
}
 
Example 8
Project: powertext   File: ParameterizedCompletionContext.java   View source code 6 votes vote down vote up
/**
 * Called when the text component's caret moves.
 *
 * @param e The event.
 */
@Override
public void caretUpdate(CaretEvent e) {
	if (maxPos==null) { // Sanity check
		deactivate();
		return;
	}
	int dot = e.getDot();
	if (dot<minPos || dot>maxPos.getOffset()) {
		deactivate();
		return;
	}
	paramPrefix = updateToolTipText();
	if (active) {
		prepareParamChoicesWindow();
	}
}
 
Example 9
Project: powertext   File: RTextArea.java   View source code 6 votes vote down vote up
/**
 * Notifies all listeners that a caret change has occurred.
 *
 * @param e The caret event.
 */
@Override
protected void fireCaretUpdate(CaretEvent e) {

	// Decide whether we need to repaint the current line background.
	possiblyUpdateCurrentLineHighlightLocation();

	// Now, if there is a highlighted region of text, allow them to cut
	// and copy.
	if (e!=null && e.getDot()!=e.getMark()) {// && !cutAction.isEnabled()) {
		cutAction.setEnabled(true);
		copyAction.setEnabled(true);
	}

	// Otherwise, if there is no highlighted region, don't let them cut
	// or copy.  The condition here should speed things up, because this
	// way, we will only enable the actions the first time the selection
	// becomes nothing.
	else if (cutAction.isEnabled()) {
		cutAction.setEnabled(false);
		copyAction.setEnabled(false);
	}

	super.fireCaretUpdate(e);

}
 
Example 10
Project: openjdk-jdk10   File: TableViewLayoutTest.java   View source code 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 11
Project: Mujeed-Arabic-Prolog   File: TextLineNumber.java   View source code 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 12
Project: incubator-netbeans   File: ComponentPeer.java   View source code 5 votes vote down vote up
public void caretUpdate(CaretEvent e) {
    synchronized (this) {
        lastCaretPosition = e.getDot();
    }
    
    LOG.fine("scheduling hints computation");
    
    computeHint.schedule(100);
}
 
Example 13
Project: incubator-netbeans   File: MarkOccurrencesSupport.java   View source code 5 votes vote down vote up
public void caretUpdate (final CaretEvent e) {
    if (parsingTask != null) {
        parsingTask.cancel ();
    }
    parsingTask = PROC.post (new Runnable () {
        public void run () {
            refresh (e.getDot ());
        }
    }, 1000);
}
 
Example 14
Project: incubator-netbeans   File: TokensBrowserTopComponent.java   View source code 5 votes vote down vote up
public void caretUpdate (CaretEvent e) {
    int position = e.getDot ();
    try {
        selectPath (position);
    } catch (ConcurrentModificationException ex) {
    }
}
 
Example 15
Project: incubator-netbeans   File: SearchBar.java   View source code 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 16
Project: incubator-netbeans   File: SelectCodeElementAction.java   View source code 5 votes vote down vote up
public @Override void caretUpdate(CaretEvent e) {
    if (!ignoreNextCaretUpdate) {
        synchronized (this) {
            selectionInfos = null;
            selIndex = -1;
        }
    }
    ignoreNextCaretUpdate = false;
}
 
Example 17
Project: incubator-netbeans   File: TaskPanel.java   View source code 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();
}
 
Example 18
Project: incubator-netbeans   File: SelectCodeElementAction.java   View source code 5 votes vote down vote up
public void caretUpdate(CaretEvent e) {
    assert SwingUtilities.isEventDispatchThread();
    if (!ignoreNextCaretUpdate) {
        synchronized (this) {
            selectionInfos = null;
            selIndex = -1;
        }
    }
}
 
Example 19
Project: incubator-netbeans   File: SelectionAwareJavaSourceTaskFactory.java   View source code 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 20
Project: incubator-netbeans   File: CaretAwareJavaSourceTaskFactory.java   View source code 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 21
Project: incubator-netbeans   File: AbbrevDetection.java   View source code 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 22
Project: BEAST   File: StoppedTypingContinuouslyMessager.java   View source code 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent ce) {
    if (ce.getDot() != currentCaretPos + 1
            && ce.getDot() != currentCaretPos) {
        msgAllListener(ce.getDot());
    }
    currentCaretPos = ce.getDot();
}
 
Example 23
Project: Equella   File: ExpertScriptingTab.java   View source code 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent event)
{
	if( focus != null )
	{
		itemEditor
			.getStatusBar()
			.setMessage(
				CurrentLocale
					.get(
						"com.tle.admin.scripting.editor.lineandcolumn", focus.getCaretLineNumber() + 1, focus.getCaretOffsetFromLineStart())); //$NON-NLS-1$
	}
}
 
Example 24
Project: Equella   File: ScriptTab.java   View source code 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent event)
{
	statusbar.setMessage(
		CurrentLocale.get("com.tle.admin.scripting.editor.lineandcolumn", script.getCaretLineNumber() + 1,
			script.getCaretOffsetFromLineStart()));
}
 
Example 25
Project: Equella   File: AdvancedScriptControlEditor.java   View source code 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent event)
{
	if( focus != null )
	{
		getEntityEditor().getStatusBar().setMessage(
			getString("lineandcolumn", focus.getCaretLineNumber() + 1, focus.getCaretOffsetFromLineStart())); //$NON-NLS-1$
	}
}
 
Example 26
Project: Equella   File: ScriptPanel.java   View source code 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent event)
{
	statusHolder
		.getStatusBar()
		.setMessage(
			CurrentLocale
				.get(
					"com.tle.admin.scripting.editor.lineandcolumn", advanced.getCaretLineNumber() + 1, advanced.getCaretOffsetFromLineStart())); //$NON-NLS-1$
}
 
Example 27
Project: powertext   File: Caretlistener.java   View source code 5 votes vote down vote up
@Override        
    public void caretUpdate(CaretEvent evt) {
       JTextArea textPane1 =(JTextArea)evt.getSource();
        int row = getRow(evt.getDot(), textPane1); //row += 1;
        int col = getColumn(evt.getDot(), textPane1);
        
cal.setText("Line: " + row + " Column: " + col);
cln = row;
                
        //Get the location in the text
int dot = evt.getDot();
int mark = evt.getMark();
int totalsel = mark - dot ;
int totalsele = dot - mark ;
if (dot == mark) {  
    //Rectangle caretCoords = textPane.modelToView(dot);
    
    Totalsel.setText("Caret Position: " + dot ); doti = dot;
    //jLabel17.setText("Caret Position : " + dot);
    //jLabel18.setText("Current Line : " + row);
    jLabel500.setText(""+row);   jLabel501.setText(""+col);
    //jLabel19.setText("Current Column : " + col);
    mark +=1 ;
 } else if (dot < mark) {
    statusLabel.setText("Selection : " + totalsel + "\t | \t" + row);
    jLabel26.setText("Selection : " + totalsel + "\t | \t" + row);
    
 } else {
    jLabel26.setText("Selection : " + totalsele + "\t | " + row);
    statusLabel.setText("Selection : " + totalsele + "\t | \t" + row);
 }
    }
 
Example 28
Project: powertext   File: Caretlistener.java   View source code 5 votes vote down vote up
@Override        
    public void caretUpdate(CaretEvent evt) {
       JTextArea textPane1 =(JTextArea)evt.getSource();
        int row = getRow(evt.getDot(), textPane1); //row += 1;
        int col = getColumn(evt.getDot(), textPane1);
        
cal.setText("Line: " + row + " Column: " + col);
cln = row;
                
        //Get the location in the text
int dot = evt.getDot();
int mark = evt.getMark();
int totalsel = mark - dot ;
int totalsele = dot - mark ;
if (dot == mark) {  
    //Rectangle caretCoords = textPane.modelToView(dot);
    
    Totalsel.setText("Caret Position: " + dot ); doti = dot;
    //jLabel17.setText("Caret Position : " + dot);
    //jLabel18.setText("Current Line : " + row);
    jLabel500.setText(""+row);   jLabel501.setText(""+col);
    //jLabel19.setText("Current Column : " + col);
    mark +=1 ;
 } else if (dot < mark) {
    statusLabel.setText("Selection : " + totalsel + "\t | \t" + row);
    jLabel26.setText("Selection : " + totalsel + "\t | \t" + row);
    
 } else {
    jLabel26.setText("Selection : " + totalsele + "\t | " + row);
    statusLabel.setText("Selection : " + totalsele + "\t | \t" + row);
 }
    }
 
Example 29
Project: powertext   File: LineNumberList.java   View source code 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {

	int dot = textArea.getCaretPosition();

	// We separate the line wrap/no line wrap cases because word wrap
	// can make a single line from the model (document) be on multiple
	// lines on the screen (in the view); thus, we have to enhance the
	// logic for that case a bit - we check the actual y-coordinate of
	// the caret when line wrap is enabled.  For the no-line-wrap case,
	// getting the line number of the caret suffices.  This increases
	// efficiency in the no-line-wrap case.

	if (!textArea.getLineWrap()) {
		int line = textArea.getDocument().getDefaultRootElement().
								getElementIndex(dot);
		if (currentLine!=line) {
			repaintLine(line);
			repaintLine(currentLine);
			currentLine = line;
		}
	}
	else { // lineWrap enabled; must check actual y position of caret
		try {
			int y = textArea.yForLineContaining(dot);
			if (y!=lastY) {
				lastY = y;
				currentLine = textArea.getDocument().
						getDefaultRootElement().getElementIndex(dot);
				repaint(); // *Could* be optimized...
			}
		} catch (BadLocationException ble) {
			ble.printStackTrace();
		}
	}

}
 
Example 30
Project: powertext   File: RSyntaxTextArea.java   View source code 5 votes vote down vote up
/**
 * Notifies all listeners that a caret change has occurred.
 *
 * @param e The caret event.
 */
@Override
protected void fireCaretUpdate(CaretEvent e) {
	super.fireCaretUpdate(e);
	if (isBracketMatchingEnabled()) {
		doBracketMatching();
	}
}
 
Example 31
Project: powertext   File: RSyntaxTextArea.java   View source code 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
	int dot = e.getDot();
	if (dot != origDot) {
		stop();
		removeCaretListener(this);
		if (popup != null) {
			popup.dispose();
		}
	}
}
 
Example 32
Project: powertext   File: ErrorStrip.java   View source code 5 votes vote down vote up
@Override
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 33
Project: GravSupport   File: CreateThemeDialog.java   View source code 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
    if (e.getSource() == textField1) {
        themeData.setName(textField1.getText());
    }
    if (e.getSource() == textField2) {
        themeData.setDescription(textField2.getText());
    }
    if (e.getSource() == textField3) {
        themeData.setDeveloper(textField3.getText());
    }
    if (e.getSource() == textField4) {
        themeData.setEmail(textField4.getText());
    }
}
 
Example 34
Project: enigma-vk   File: CodeReader.java   View source code 5 votes vote down vote up
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;
}
 
Example 35
Project: JuggleMasterPro   File: BallsColorsJTextPane.java   View source code 5 votes vote down vote up
@Override final public void caretUpdate(CaretEvent objPcaretEvent) {
	try {
		// TODO : c'est bon, mais �a ne d�place rien... Peut-�tre un scroll � rajouter ?
		this.scrollRectToVisible(this.modelToView(this.getCaretPosition()));
	} catch (final Throwable objPthrowable) {
		Tools.err("Error while scrolling ball color field visible part");
	}
}
 
Example 36
Project: Neukoelln_SER316   File: AddResourceDialog.java   View source code 4 votes vote down vote up
/**
* disable the ok button if pathField is empty
*/

  void pathField_caretUpdate(CaretEvent e) {
      checkOkEnabled();
  }
 
Example 37
Project: Neukoelln_SER316   File: AddResourceDialog.java   View source code 4 votes vote down vote up
/**
* disable the ok button if urlField is empty
*/
	
  void urlField_caretUpdate(CaretEvent e) {        
      checkOkEnabled();
  }
 
Example 38
Project: Reinickendorf_SER316   File: AddResourceDialog.java   View source code 4 votes vote down vote up
/**
* disable the ok button if urlField is empty
*/
	
  void urlField_caretUpdate(CaretEvent e) {        
      checkOkEnabled();
  }
 
Example 39
Project: Neukoelln_SER316   File: SearchPanel.java   View source code 4 votes vote down vote up
void searchField_caretUpdate(CaretEvent e) {
    searchB.setEnabled(searchField.getText().length() > 0);
}
 
Example 40
Project: Neukoelln_SER316   File: SetAppDialog.java   View source code 4 votes vote down vote up
void applicationField_caretUpdate(CaretEvent e) {
  checkOkEnabled();
}