Example usage for javax.swing JEditorPane select

List of usage examples for javax.swing JEditorPane select

Introduction

In this page you can find the example usage for javax.swing JEditorPane select.

Prototype

public void select(int selectionStart, int selectionEnd) 

Source Link

Document

Selects the text between the specified start and end positions.

Usage

From source file:ja.lingo.application.gui.main.describer.DescriberGui.java

private void find(String searchText, boolean fromStart, boolean forwardDirection, boolean caseSensetive,
        boolean wholeWordsOnly) {
    JEditorPane editorPane = articlePanel.getEditorPane();

    String article;//w w w .j  a v  a 2  s  . c  om
    try {
        article = editorPane.getDocument().getText(0, editorPane.getDocument().getLength());
    } catch (BadLocationException e) {
        throw States.shouldNeverReachHere(e);
    }

    if (fromStart) {
        editorPane.select(0, 0);
    }

    // try search twice: after caret, before caret (the order depends on search direction)
    int attempt1 = forwardDirection ? editorPane.getSelectionEnd() : editorPane.getSelectionStart() - 1;
    int attempt2 = forwardDirection ? 0 : article.length();

    int index = TextSearcher.indexOf(forwardDirection, article, searchText, attempt1, caseSensetive,
            wholeWordsOnly);
    if (index == -1) {
        index = TextSearcher.indexOf(forwardDirection, article, searchText, attempt2, caseSensetive,
                wholeWordsOnly);

        if (index == -1) {
            // reset selction
            editorPane.select(0, 0);
            model.find_sendFeedback(false);
            return;
        }
    }

    // highlight on success
    editorPane.select(index, index + searchText.length());
    editorPane.getCaret().setSelectionVisible(true);
    model.find_sendFeedback(true);
}

From source file:org.docx4all.ui.main.WordMLEditor.java

public void createInternalFrame(FileObject f) {
    if (f == null) {
        return;/*  ww  w  .  j  av  a 2s .  c  o  m*/
    }

    log.info(VFSUtils.getFriendlyName(f.getName().getURI()));

    JInternalFrame iframe = _iframeMap.get(f.getName().getURI());
    if (iframe != null) {
        iframe.setVisible(true);

    } else {
        iframe = new JInternalFrame(f.getName().getBaseName(), true, true, true, true);
        iframe.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        iframe.addInternalFrameListener(_internalFrameListener);
        iframe.addInternalFrameListener(_toolbarStates);
        iframe.addPropertyChangeListener(WindowMenu.getInstance());

        if (iframe.getUI() instanceof BasicInternalFrameUI) {
            BasicInternalFrameUI ui = (BasicInternalFrameUI) iframe.getUI();
            javax.swing.JComponent northPane = ui.getNorthPane();
            if (northPane == null) {
                // Happens on Mac OSX: Google for "osx java getNorthPane"
                // Fix is from it.businesslogic.ireport.gui.JMDIFrame
                javax.swing.plaf.basic.BasicInternalFrameUI aUI = new javax.swing.plaf.basic.BasicInternalFrameUI(
                        iframe);
                iframe.setUI(aUI);

                // Try again
                ui = (BasicInternalFrameUI) iframe.getUI();
                northPane = ((javax.swing.plaf.basic.BasicInternalFrameUI) ui).getNorthPane();
            }
            northPane.addMouseMotionListener(_titleBarMouseListener);
        }

        JEditorPane editorView = createEditorView(f);
        JPanel panel = FxScriptUIHelper.getInstance().createEditorPanel(editorView);

        iframe.getContentPane().add(panel);
        iframe.pack();
        _desktop.add(iframe);

        editorView.requestFocusInWindow();
        editorView.select(0, 0);

        String filePath = f.getName().getURI();
        iframe.putClientProperty(WordMLDocument.FILE_PATH_PROPERTY, filePath);
        _iframeMap.put(filePath, iframe);

        iframe.show();
    }

    try {
        iframe.setSelected(true);
        iframe.setIcon(false);
        iframe.setMaximum(true);
    } catch (PropertyVetoException exc) {
        // do nothing
    }
}