当前位置: 首页>>代码示例>>Java>>正文


Java JTextComponent.getSelectionEnd方法代码示例

本文整理汇总了Java中javax.swing.text.JTextComponent.getSelectionEnd方法的典型用法代码示例。如果您正苦于以下问题:Java JTextComponent.getSelectionEnd方法的具体用法?Java JTextComponent.getSelectionEnd怎么用?Java JTextComponent.getSelectionEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.JTextComponent的用法示例。


在下文中一共展示了JTextComponent.getSelectionEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        int selectionStartOffset = target.getSelectionStart();
        int selectionEndOffset = target.getSelectionEnd();
        if (selectionEndOffset > selectionStartOffset || selectNext) {
            SelectionHandler handler = (SelectionHandler)target.getClientProperty(SelectionHandler.class);
            if (handler == null) {
                handler = new SelectionHandler(target, getShortDescription());
                target.addCaretListener(handler);
                // No need to remove the listener above as the handler
                // is stored is the client-property of the component itself
                target.putClientProperty(SelectionHandler.class, handler);
            }

            if (selectNext) { // select next element
                handler.selectNext();
            } else { // select previous
                handler.selectPrevious();
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:SelectCodeElementAction.java

示例2: processKeyEvent

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void processKeyEvent(KeyEvent evt) {
    if (evt.getID() == KeyEvent.KEY_TYPED) {
        if(evt.getKeyChar() == '.') { // NOI18N
            Completion.get().hideDocumentation();
            JTextComponent component = (JTextComponent)evt.getSource();
            int caretOffset = component.getSelectionEnd();
            int len = caretOffset - substitutionOffset;
            if (len >= 0) {
                substituteText(component, substitutionOffset, len, Character.toString(evt.getKeyChar()));
                Completion.get().showCompletion();
                evt.consume();
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:SpringXMLConfigCompletionItem.java

示例3: paint

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void paint(Graphics g, Shape a) {
    ((Graphics2D) g).addRenderingHints(getHints());

    Container container = getContainer();
    if (container instanceof JTextComponent) {
        final JTextComponent textComp = (JTextComponent) container;
        selStart = textComp.getSelectionStart();
        selEnd = textComp.getSelectionEnd();
        unselectedFg = textComp.isEnabled()
                ? textComp.getForeground()
                : textComp.getDisabledTextColor();
        selectedFg = textComp.getCaret().isSelectionVisible()
                ? textComp.getSelectedTextColor()
                : unselectedFg;
    }
    super.paint(g, a);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:OutputView.java

示例4: instantSubstitution

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public boolean instantSubstitution(JTextComponent component) {
    if (component != null) {
        try {
            int caretOffset = component.getSelectionEnd();
            if (caretOffset > substitutionOffset) {
                String currentText = component.getDocument().getText(substitutionOffset, caretOffset - substitutionOffset);
                if (!getSubstituteText().toString().startsWith(currentText)) {
                    return false;
                }
            }
        } catch (BadLocationException ble) {
        }
    }
    defaultAction(component);
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:HtmlCompletionItem.java

示例5: updateTemplateEnding

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void updateTemplateEnding() {
    String text = request.getParametrizedText();
    if (text.endsWith("\n")) { //NOI18N
        JTextComponent component = request.getComponent();
        int offset = component.getSelectionEnd();
        Document doc = component.getDocument();
        if (doc.getLength() > offset) {
            try {
                if ("\n".equals(doc.getText(offset, 1))) {
                    request.setParametrizedText(text.substring(0, text.length() - 1));
                }
            } catch (BadLocationException ble) {
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:JavaCodeTemplateProcessor.java

示例6: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
	JTextComponent target = getTextComponent(e);
	boolean beep = true;
	if ((target != null) && (target.isEditable())) {
		try {
			Document doc = target.getDocument();
			int ss = target.getSelectionStart();
			int se = target.getSelectionEnd();

			if (ss != se) {
				doc.remove(ss, se - ss);
				beep = false;
			}
		} catch (BadLocationException bl) {
		}
	}
	if (beep) {
		UIManager.getLookAndFeel().provideErrorFeedback(target);
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:22,代码来源:TextActions.java

示例7: instantSubstitution

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public boolean instantSubstitution(JTextComponent component) {
    if (component != null) {
        try {
            int caretOffset = component.getSelectionEnd();
            if (caretOffset > substitutionOffset) {
                String text = component.getDocument().getText(substitutionOffset, caretOffset - substitutionOffset);
                if (!getInsertPrefix().toString().startsWith(text)) {
                    return false;
                }
            }
        }
        catch (BadLocationException ble) {}
    }
    defaultAction(component);
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JavaCompletionItem.java

示例8: getSelectionOrIdentifierBlock

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/** Get the selection if there's any or get the identifier around
* the position if there's no selection.
* @param c component to work with
* @param offset position in document - usually the caret.getDot()
* @return the block (starting and ending position) enclosing the identifier
*   or null if no identifier was found
*/
public static int[] getSelectionOrIdentifierBlock(JTextComponent c, int offset)
throws BadLocationException {
    Document doc = c.getDocument();
    Caret caret = c.getCaret();
    int[] ret;
    if (Utilities.isSelectionShowing(caret)) {
        ret = new int[] { c.getSelectionStart(), c.getSelectionEnd() }; 
    } else if (doc instanceof BaseDocument){
        ret = getIdentifierBlock((BaseDocument)doc, offset);
    } else {
        ret = getIdentifierBlock(c, offset);
    }
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:Utilities.java

示例9: defaultAction

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void defaultAction(JTextComponent component) {
    if (component != null) {
        Completion.get().hideDocumentation();
        Completion.get().hideCompletion();
        int caretOffset = component.getSelectionEnd();
        substituteText(component, substitutionOffset, caretOffset - substitutionOffset, null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:SpringXMLConfigCompletionItem.java

示例10: updateToolTipText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Updates the text in the tool tip to have the current parameter
 * displayed in bold.  The "current parameter" is determined from the
 * current caret position.
 *
 * @return The "prefix" of text in the caret's parameter before the caret.
 */
private String updateToolTipText() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getSelectionStart();
	int mark = tc.getSelectionEnd();
	int index = -1;
	String paramPrefix = null;

	List<Highlight> paramHighlights = getParameterHighlights();
	for (int i=0; i<paramHighlights.size(); i++) {
		Highlight h = paramHighlights.get(i);
		// "+1" because of param hack - see OutlineHighlightPainter
		int start = h.getStartOffset()+1;
		if (dot>=start && dot<=h.getEndOffset()) {
			try {
				// All text selected => offer all suggestions, otherwise
				// use prefix before selection
				if (dot!=start || mark!=h.getEndOffset()) {
					paramPrefix = tc.getText(start, dot-start);
				}
			} catch (BadLocationException ble) {
				ble.printStackTrace();
			}
			index = i;
			break;
		}
	}

	updateToolTipText(index);
	return paramPrefix;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:40,代码来源:ParameterizedCompletionContext.java

示例11: processKeyEvent

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void processKeyEvent(KeyEvent evt) {
    if (evt.getID() == KeyEvent.KEY_TYPED) {
        if (evt.getKeyChar() == '.') { // NOI18N
            Completion.get().hideDocumentation();
            JTextComponent component = (JTextComponent) evt.getSource();
            int caretOffset = component.getSelectionEnd();
            substituteText(component, substitutionOffset, caretOffset - substitutionOffset, Character.toString(evt.getKeyChar()));
            Completion.get().showCompletion();
            evt.consume();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:HibernateCompletionItem.java

示例12: defaultAction

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void defaultAction(JTextComponent component) {
    if (component != null) {
        // Items with no insert prefix and no custom code template
        // are "read-only" (such as the method call items)
        if (getInsertPrefix().length() == 0) {
            return;
        }
        Completion.get().hideAll();
        int caretOffset = component.getSelectionEnd();
        if (caretOffset >= substitutionOffset) {
            substituteText(component, substitutionOffset, caretOffset - substitutionOffset, null);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:GsfCompletionItem.java

示例13: TextComponentTask

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public TextComponentTask(EditorCookie ec) {
    JTextComponent textC = ec.getOpenedPanes()[0];
    this.document = textC.getDocument();
    this.caretOffset = textC.getCaretPosition();
    this.selectionStart = textC.getSelectionStart();
    this.selectionEnd = textC.getSelectionEnd();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:CPActionsImplementationProvider.java

示例14: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt) {
    Caret c = caret;
    JTextComponent component = editorUI.getComponent();

    // Also check whether the component is last focused since when undocking an editor
    // all the components' carets fire this listener and so invalid component's
    // data would get displayed in the global status bar.
    if (component != null && component == EditorRegistry.lastFocusedComponent()) {
        if (c != null) {
            BaseDocument doc = Utilities.getDocument(component);
            if (doc != null && doc.getDefaultRootElement().getElementCount()>0) {
                int pos = c.getDot();
                String s = Utilities.debugPosition(doc, pos, ":");
                if (CARET_OFFSET_LOG.isLoggable(Level.FINE)) { // Possibly add caret offset info
                    s += " <" + pos + ">"; // NOI18N
                }
                int countOfSelectedChars = component.getSelectionEnd() - component.getSelectionStart();
                final boolean hasSelection = countOfSelectedChars > 0;
                if (hasSelection) {
                    try {
                        //count of selected lines
                        int lineEnd = Utilities.getLineOffset(doc, component.getSelectionEnd());
                        int lineStart = Utilities.getLineOffset(doc, component.getSelectionStart());
                        s += "/" + (lineEnd - lineStart + 1);
                    } catch (BadLocationException ex) {
                    }
                    //count of selected characters
                    s += ":" + countOfSelectedChars;
                }
                //rows:cols/countRows:countCols
                setText(CELL_POSITION, s);
            }
        }

        Boolean b = (Boolean)editorUI.getProperty(EditorUI.OVERWRITE_MODE_PROPERTY);
        boolean om = (b != null && b.booleanValue());
        if (om != overwriteModeDisplayed) {
            overwriteModeDisplayed = om;
            setText(CELL_TYPING_MODE, overwriteModeDisplayed ? ovrText : insText);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:StatusBar.java

示例15: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target == null) return;
    if (!target.isEditable() || !target.isEnabled()) {
        problem(null);
        return;
    }
    Caret caret = target.getCaret();
    BaseDocument doc = (BaseDocument)target.getDocument();
    try {
        if (caret.isSelectionVisible()) {
            int startPos = Utilities.getRowStart(doc, target.getSelectionStart());
            int endPos = target.getSelectionEnd();
            doc.atomicLock();
            try {

                if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) {
                    endPos--;
                }

                int pos = startPos;
                int lineCnt = Utilities.getRowCount(doc, startPos, endPos);                            

                for (;lineCnt > 0; lineCnt--) {
                    doc.insertString(pos, commentStartString, null); 
                    doc.insertString(Utilities.getRowEnd(doc,pos), commentEndString, null);
                    pos = Utilities.getRowStart(doc, pos, +1);
                }

            } finally {
                doc.atomicUnlock();
            }
        } else { // selection not visible
            doc.insertString(Utilities.getRowStart(doc, target.getSelectionStart()),
                commentStartString, null);
            doc.insertString(Utilities.getRowEnd(doc, target.getSelectionStart()),
                commentEndString, null);
        }
    } catch (BadLocationException e) {
        problem(null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:XMLKit.java


注:本文中的javax.swing.text.JTextComponent.getSelectionEnd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。