Java 类javax.swing.event.CaretEvent 实例源码

项目:incubator-netbeans    文件:CaretMarkProvider.java   
@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);
        }
    });
}
项目:incubator-netbeans    文件:SubmitPanel.java   
@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);
        }
    }
}
项目:incubator-netbeans    文件:WikiEditPanel.java   
/**
 * 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);
}
项目:BEAST    文件:TextLineNumber.java   
@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;
    }
}
项目:BEAST    文件:OpenCloseCharHighlighter.java   
@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;
        }
    }
}
项目:scratch-bench    文件:MainMenu.java   
/**
     * 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"));
             }
         }
              }
项目:powertext    文件:AutoCompletePopupWindow.java   
@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();
    }
}
项目:powertext    文件:ParameterizedCompletionContext.java   
/**
 * 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();
    }
}
项目:powertext    文件:RTextArea.java   
/**
 * 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);

}
项目:openjdk-jdk10    文件:TableViewLayoutTest.java   
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);
                }
            }
        });
    }
项目:Mujeed-Arabic-Prolog    文件:TextLineNumber.java   
@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;
    }
}
项目:incubator-netbeans    文件:ComponentPeer.java   
public void caretUpdate(CaretEvent e) {
    synchronized (this) {
        lastCaretPosition = e.getDot();
    }

    LOG.fine("scheduling hints computation");

    computeHint.schedule(100);
}
项目:incubator-netbeans    文件:MarkOccurrencesSupport.java   
public void caretUpdate (final CaretEvent e) {
    if (parsingTask != null) {
        parsingTask.cancel ();
    }
    parsingTask = PROC.post (new Runnable () {
        public void run () {
            refresh (e.getDot ());
        }
    }, 1000);
}
项目:incubator-netbeans    文件:TokensBrowserTopComponent.java   
public void caretUpdate (CaretEvent e) {
    int position = e.getDot ();
    try {
        selectPath (position);
    } catch (ConcurrentModificationException ex) {
    }
}
项目:incubator-netbeans    文件:SearchBar.java   
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);
            }
        }
    };
}
项目:incubator-netbeans    文件:SelectCodeElementAction.java   
public @Override void caretUpdate(CaretEvent e) {
    if (!ignoreNextCaretUpdate) {
        synchronized (this) {
            selectionInfos = null;
            selIndex = -1;
        }
    }
    ignoreNextCaretUpdate = false;
}
项目:incubator-netbeans    文件:TaskPanel.java   
/**
 * 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();
}
项目:incubator-netbeans    文件:SelectCodeElementAction.java   
public void caretUpdate(CaretEvent e) {
    assert SwingUtilities.isEventDispatchThread();
    if (!ignoreNextCaretUpdate) {
        synchronized (this) {
            selectionInfos = null;
            selIndex = -1;
        }
    }
}
项目:incubator-netbeans    文件:SelectionAwareJavaSourceTaskFactory.java   
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);
    }
}
项目:incubator-netbeans    文件:CaretAwareJavaSourceTaskFactory.java   
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);
    }
}
项目:incubator-netbeans    文件:AbbrevDetection.java   
public void caretUpdate(CaretEvent evt) {
    if (evt.getDot() != evt.getMark()) {
        surroundsWithTimer.setInitialDelay(SURROUND_WITH_DELAY);
        surroundsWithTimer.restart();
    } else {
        surroundsWithTimer.stop();
        hideSurroundWithHint();
    }
}
项目:BEAST    文件:StoppedTypingContinuouslyMessager.java   
@Override
public void caretUpdate(CaretEvent ce) {
    if (ce.getDot() != currentCaretPos + 1
            && ce.getDot() != currentCaretPos) {
        msgAllListener(ce.getDot());
    }
    currentCaretPos = ce.getDot();
}
项目:Equella    文件:ExpertScriptingTab.java   
@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$
    }
}
项目:Equella    文件:ScriptTab.java   
@Override
public void caretUpdate(CaretEvent event)
{
    statusbar.setMessage(
        CurrentLocale.get("com.tle.admin.scripting.editor.lineandcolumn", script.getCaretLineNumber() + 1,
            script.getCaretOffsetFromLineStart()));
}
项目:Equella    文件:AdvancedScriptControlEditor.java   
@Override
public void caretUpdate(CaretEvent event)
{
    if( focus != null )
    {
        getEntityEditor().getStatusBar().setMessage(
            getString("lineandcolumn", focus.getCaretLineNumber() + 1, focus.getCaretOffsetFromLineStart())); //$NON-NLS-1$
    }
}
项目:Equella    文件:ScriptPanel.java   
@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$
}
项目:powertext    文件:Caretlistener.java   
@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);
 }
    }
项目:powertext    文件:Caretlistener.java   
@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);
 }
    }
项目:powertext    文件:LineNumberList.java   
@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();
        }
    }

}
项目:powertext    文件:RSyntaxTextArea.java   
/**
 * 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();
    }
}
项目:powertext    文件:RSyntaxTextArea.java   
@Override
public void caretUpdate(CaretEvent e) {
    int dot = e.getDot();
    if (dot != origDot) {
        stop();
        removeCaretListener(this);
        if (popup != null) {
            popup.dispose();
        }
    }
}
项目:powertext    文件:ErrorStrip.java   
@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;
        }
    }
}
项目:GravSupport    文件:CreateThemeDialog.java   
@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());
    }
}
项目:enigma-vk    文件:CodeReader.java   
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;
}
项目:JuggleMasterPro    文件:BallsColorsJTextPane.java   
@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");
    }
}
项目:Neukoelln_SER316    文件:AddResourceDialog.java   
/**
* disable the ok button if pathField is empty
*/

  void pathField_caretUpdate(CaretEvent e) {
      checkOkEnabled();
  }
项目:Neukoelln_SER316    文件:AddResourceDialog.java   
/**
* disable the ok button if urlField is empty
*/

  void urlField_caretUpdate(CaretEvent e) {        
      checkOkEnabled();
  }
项目:Reinickendorf_SER316    文件:AddResourceDialog.java   
/**
* disable the ok button if urlField is empty
*/

  void urlField_caretUpdate(CaretEvent e) {        
      checkOkEnabled();
  }
项目:Neukoelln_SER316    文件:SearchPanel.java   
void searchField_caretUpdate(CaretEvent e) {
    searchB.setEnabled(searchField.getText().length() > 0);
}
项目:Neukoelln_SER316    文件:SetAppDialog.java   
void applicationField_caretUpdate(CaretEvent e) {
  checkOkEnabled();
}