當前位置: 首頁>>代碼示例>>Java>>正文


Java Utilities.getWordEnd方法代碼示例

本文整理匯總了Java中javax.swing.text.Utilities.getWordEnd方法的典型用法代碼示例。如果您正苦於以下問題:Java Utilities.getWordEnd方法的具體用法?Java Utilities.getWordEnd怎麽用?Java Utilities.getWordEnd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.text.Utilities的用法示例。


在下文中一共展示了Utilities.getWordEnd方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getWordEnd

import javax.swing.text.Utilities; //導入方法依賴的package包/類
protected int getWordEnd(JTextComponent c, int pos)
{
	try
	{
		return Utilities.getWordEnd(c, pos);
	}
	catch(Exception e)
	{ }
	return -1;
}
 
開發者ID:andy-goryachev,項目名稱:PasswordSafe,代碼行數:11,代碼來源:CEditorAction.java

示例2: actionPerformed

import javax.swing.text.Utilities; //導入方法依賴的package包/類
/**
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
public void actionPerformed(ActionEvent e) {
    JTextComponent target = getTextComponent(e);
    boolean        beep   = true;

    if ((target != null) && (target.isEditable())) {

        try {

            // select the next word
            int    offs    = target.getCaretPosition();
            int    endOffs;
            String s       = target.getDocument().getText(offs, 1);

            if (Character.isWhitespace(s.charAt(0))) {
                endOffs = Utilities.getNextWord(target, offs);
                endOffs = Utilities.getWordEnd(target, endOffs);
            } else {
                endOffs = Utilities.getWordEnd(target, offs);
            }

            target.moveCaretPosition(endOffs);

            // and then delete it
            target.replaceSelection("");
            beep = false;
        } catch (BadLocationException exc) {
            // nothing to do, because we set beep to true already
        }
    }

    if (beep) {
        provideErrorFeedback(target);
    }
}
 
開發者ID:khuxtable,項目名稱:seaglass,代碼行數:38,代碼來源:MacEditorKit.java

示例3: setClickText

import javax.swing.text.Utilities; //導入方法依賴的package包/類
private void setClickText(MouseEvent evt) {
    try {
        int clickIndex = getHyperCardTextPane().viewToModel(evt.getPoint());
        int startWordIndex = Utilities.getWordStart(getHyperCardTextPane(), clickIndex);
        int endWordIndex = Utilities.getWordEnd(getHyperCardTextPane(), clickIndex);

        String clickText = getHyperCardTextPane().getStyledDocument().getText(startWordIndex, endWordIndex - startWordIndex);
        ExecutionContext.getContext().getGlobalProperties().defineProperty(HyperCardProperties.PROP_CLICKTEXT, new Value(clickText), true);

    } catch (BadLocationException e) {
        // Nothing to do
    }
}
 
開發者ID:defano,項目名稱:hypertalk-java,代碼行數:14,代碼來源:FieldPart.java

示例4: getCurrentWord

import javax.swing.text.Utilities; //導入方法依賴的package包/類
public String getCurrentWord() throws BadLocationException {
    int start = Utilities.getWordStart(this, getSelectionStart());
    int end = Utilities.getWordEnd(this, getSelectionStart());
    String word = getDocument().getText(start, end - start);
    if (word.indexOf(".") != -1) {
        word = word.substring(0, word.lastIndexOf("."));
    }
    //System.out.println( "Selected word: " + word );
    return word;
}
 
開發者ID:silverslade,項目名稱:jif,代碼行數:11,代碼來源:JifTextPane.java

示例5: actionPerformed

import javax.swing.text.Utilities; //導入方法依賴的package包/類
/**
 * At first the same code as in {@link
 * EmacsKeyBindings.DowncaseWordAction} is performed, to ensure the
 * word is in lower case, then the first letter is capialized.
 */
@Override
public void actionPerformed(ActionEvent event) {
    JTextComponent jtc = getTextComponent(event);

    if (jtc != null) {
        try {
            /* downcase code */
            int start = jtc.getCaretPosition();
            int end = EmacsKeyBindings.getWordEnd(jtc, start);
            jtc.setSelectionStart(start);
            jtc.setSelectionEnd(end);
            String word = jtc.getText(start, end - start);
            jtc.replaceSelection(word.toLowerCase(Locale.ROOT));

            /* actual capitalize code */
            int offs = Utilities.getWordStart(jtc, start);
            // get first letter
            String c = jtc.getText(offs, 1);
            // we're at the end of the previous word
            if (" ".equals(c)) {
                /* ugly java workaround to get the beginning of the
                   word.  */
                offs = Utilities.getWordStart(jtc, ++offs);
                c = jtc.getText(offs, 1);
            }
            if (Character.isLetter(c.charAt(0))) {
                jtc.setSelectionStart(offs);
                jtc.setSelectionEnd(offs + 1);
                jtc.replaceSelection(c.toUpperCase(Locale.ROOT));
            }
            end = Utilities.getWordEnd(jtc, offs);
            jtc.setCaretPosition(end);
        } catch (BadLocationException ble) {
            jtc.getToolkit().beep();
        }
    }
}
 
開發者ID:JabRef,項目名稱:jabref,代碼行數:43,代碼來源:EmacsKeyBindings.java

示例6: actionPerformed

import javax.swing.text.Utilities; //導入方法依賴的package包/類
/***
 * At first the same code as in
 * {@link EmacsKeyBindings.DowncaseWordAction} is performed, to ensure
 * the word is in lower case, then the first letter is capialized.
 */
public void actionPerformed(ActionEvent event) {
	JTextComponent jtc = getTextComponent(event);

	if (jtc != null) {
		try {
			/* downcase code */
			int start = jtc.getCaretPosition();
			int end = getWordEnd(jtc, start);
			jtc.setSelectionStart(start);
			jtc.setSelectionEnd(end);
			String word = jtc.getText(start, end - start);
			jtc.replaceSelection(word.toLowerCase());

			/* actual capitalize code */
			int offs = Utilities.getWordStart(jtc, start);
			// get first letter
			String c = jtc.getText(offs, 1);
			// we're at the end of the previous word
			if (c.equals(" ")) {
				/*
				 * ugly java workaround to get the beginning of the
				 * word.
				 */
				offs = Utilities.getWordStart(jtc, ++offs);
				c = jtc.getText(offs, 1);
			}
			if (Character.isLetter(c.charAt(0))) {
				jtc.setSelectionStart(offs);
				jtc.setSelectionEnd(offs + 1);
				jtc.replaceSelection(c.toUpperCase());
			}
			end = Utilities.getWordEnd(jtc, offs);
			jtc.setCaretPosition(end);
		} catch (BadLocationException ble) {
			jtc.getToolkit().beep();
		}
	}
}
 
開發者ID:jpverkamp,項目名稱:wombat-ide,代碼行數:44,代碼來源:EmacsKeyBindings.java

示例7: getWordEnd

import javax.swing.text.Utilities; //導入方法依賴的package包/類
protected int getWordEnd(RTextArea textArea, int offs)
		throws BadLocationException {
	return Utilities.getWordEnd(textArea, offs);
}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:5,代碼來源:RTextAreaEditorKit.java

示例8: popupMenuWillBecomeVisible

import javax.swing.text.Utilities; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
public void popupMenuWillBecomeVisible( PopupMenuEvent ev ) {
    if( dictionary == null) {
        menu.setEnabled( false );
        return;
    }

    JPopupMenu popup = (JPopupMenu)ev.getSource();

    Component invoker = popup.getInvoker();
    if( invoker instanceof JTextComponent ) {
        final JTextComponent jText = (JTextComponent)invoker;
        if( !jText.isEditable() ) {
            // Suggestions only for editable text components
            menu.setEnabled( false );
            return;
        }
        try {
            int offs = getCursorPosition( jText );
            if( offs < 0 ) {
                // occur if there nothing under the mouse pointer
                menu.setEnabled( false );
                return;
            }
            
            // get the word from current position
            final int begOffs = Utilities.getWordStart( jText, offs );
            final int endOffs = Utilities.getWordEnd( jText, offs );
            final String word = jText.getText( begOffs, endOffs - begOffs );

            //find the first invalid word from current position, use the Tokenizer that it is ever compatible with the red zigzag line
            Tokenizer tokenizer = new Tokenizer( jText, dictionary, locale, offs, options );
            String invalidWord;
            do {
                invalidWord = tokenizer.nextInvalidWord();
            } while( tokenizer.getWordOffset() < begOffs );
            menu.removeAll();

            if( !word.equals( invalidWord ) ) {
                // the current word is not invalid
                menu.setEnabled( false );
                return;
            }

            List<Suggestion> list = dictionary.searchSuggestions( word );

            //Disable then menu item if there are no suggestions
            menu.setEnabled( list.size() > 0 );

            boolean needCapitalization = tokenizer.isFirstWordInSentence() && Utils.isFirstCapitalized( word );

            addSuggestionMenuItem( jText, begOffs, endOffs, list, needCapitalization );
            addMenuItemAddToDictionary( jText, word, list.size() > 0 );
        } catch( BadLocationException ex ) {
        	SpellChecker.getMessageHandler().handleException( ex );
        }
    }
}
 
開發者ID:kolchagov,項目名稱:jlokalize,代碼行數:61,代碼來源:CheckerListener.java

示例9: popupMenuWillBecomeVisible

import javax.swing.text.Utilities; //導入方法依賴的package包/類
public void popupMenuWillBecomeVisible( PopupMenuEvent ev ) {
    JPopupMenu popup = (JPopupMenu)ev.getSource();

    Component invoker = popup.getInvoker();
    if( invoker instanceof JTextComponent ) {
        final JTextComponent jText = (JTextComponent)invoker;
        if( !jText.isEditable() ) {
            // Suggestions only for editable text components
            menu.setEnabled( false );
            return;
        }
        Caret caret = jText.getCaret();
        int offs = Math.min( caret.getDot(), caret.getMark() );
        Point p = jText.getMousePosition();
        if( p != null ) {
            // use position from mouse click and not from editor cursor position 
            offs = jText.viewToModel( p );
        }
        try {
            Document doc = jText.getDocument();
            if( offs > 0 && (offs >= doc.getLength() || Character.isWhitespace( doc.getText( offs, 1 ).charAt( 0 ) )) ) {
                // if the next character is a white space then use the word on the left site
                offs--;
            }
            // get the word from current position
            final int begOffs = Utilities.getWordStart( jText, offs );
            final int endOffs = Utilities.getWordEnd( jText, offs );
            String word = jText.getText( begOffs, endOffs - begOffs );

            //find the first invalid word from current position
            Tokenizer tokenizer = new Tokenizer( jText, dictionary, locale, offs, options );
            String invalidWord;
            do {
                invalidWord = tokenizer.nextInvalidWord();
            } while( tokenizer.getWordOffset() < begOffs );
            menu.removeAll();

            if( !word.equals( invalidWord ) ) {
                // the current word is not invalid
                menu.setEnabled( false );
                return;
            }

            if( dictionary == null ) {
                // without dictionary it is disabled
                menu.setEnabled( false );
                return;
            }

            List<Suggestion> list = dictionary.searchSuggestions( word );

            //Disable then menu item if there are no suggestions
            menu.setEnabled( list.size() > 0 );

            boolean needCapitalization = tokenizer.isFirstWordInSentence() && Utils.isCapitalized( word );

            for( int i = 0; i < list.size() && i < options.getSuggestionsLimitMenu(); i++ ) {
                Suggestion sugestion = list.get( i );
                String sugestionWord = sugestion.getWord();
                if( needCapitalization ) {
                    sugestionWord = Utils.getCapitalized( sugestionWord );
                }
                JMenuItem item = new JMenuItem( sugestionWord );
                menu.add( item );
                final String newWord = sugestionWord;
                item.addActionListener( new ActionListener() {

                    public void actionPerformed( ActionEvent e ) {
                        jText.setSelectionStart( begOffs );
                        jText.setSelectionEnd( endOffs );
                        jText.replaceSelection( newWord );
                    }

                } );
            }
        } catch( BadLocationException ex ) {
            ex.printStackTrace();
        }
    }
}
 
開發者ID:dasatti,項目名稱:urduhtmlmaster,代碼行數:81,代碼來源:CheckerListener.java


注:本文中的javax.swing.text.Utilities.getWordEnd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。