private void updateUIWithFindModel() { boolean needToResetSearchFocus = mySearchTextComponent.hasFocus(); boolean needToResetReplaceFocus = myReplaceTextComponent.hasFocus(); updateSearchComponent(); updateReplaceComponent(); if (myFindModel.isReplaceState()) { if (myReplaceFieldWrapper.getParent() == null) { myLeftPanel.add(myReplaceFieldWrapper, BorderLayout.CENTER); } if (myReplaceToolbarWrapper.getParent() == null) { myRightPanel.add(myReplaceToolbarWrapper, BorderLayout.CENTER); } if (needToResetReplaceFocus) { myReplaceTextComponent.requestFocusInWindow(); } } else { if (myReplaceFieldWrapper.getParent() != null) { myLeftPanel.remove(myReplaceFieldWrapper); } if (myReplaceToolbarWrapper.getParent() != null) { myRightPanel.remove(myReplaceToolbarWrapper); } } if (needToResetSearchFocus) mySearchTextComponent.requestFocusInWindow(); mySearchActionsToolbar1.updateActionsImmediately(); mySearchActionsToolbar2.updateActionsImmediately(); myReplaceActionsToolbar1.updateActionsImmediately(); myReplaceActionsToolbar2.updateActionsImmediately(); myReplaceToolbarWrapper.revalidate(); revalidate(); repaint(); myLivePreviewController.setTrackingSelection(!myFindModel.isGlobal()); }
/** * This applies quick fixes which require insertion in the editor panel. * * @param markThisPart */ void insertSentenceStub( IvanErrorInstance myerror, List<String> stubs, String defaultStub, String markThisPart) { String[] unlocatedNames = myerror.Reference; /* Create location sentences. * 1. find the insertion point. The insertion point is somewhere to the right of the last cue. * 2. set the caret to the insertion point * 3. for each Name without location, insert a sentence. (unlocatedNames) * a) build a sentence: Name + Stub. Then insert it. * b) if you run out of stubs, create Name + " is on the … side." and then select the three dots. **/ // focus is important, so the user can readily start typing after clicking txtEditor.requestFocusInWindow(); // get insertion point int insertionpoint = findInsertionPoint(myerror.Codepoints); // set the caret txtEditor.setCaretPosition(insertionpoint); String sentence; if (stubs.size() > 0) { // build a sentence from a stub sentence = "\n" + unlocatedNames[0] + stubs.get(0) + " "; stubs.remove(0); // finalise last sentence with a period, if not present try { String text = txtEditor.getText(insertionpoint - 1, 1); if (!text.equals(".")) { sentence = "." + sentence; } } catch (BadLocationException e1) { e1.printStackTrace(); } // insert the sentence txtEditor.replaceSelection(sentence); } else { sentence = "\n" + unlocatedNames[0] + defaultStub; // finalise last sentence with a period, if not present try { String text = txtEditor.getText(insertionpoint - 1, 1); if (!text.equals(".")) { sentence = "." + sentence; } } catch (BadLocationException e1) { e1.printStackTrace(); } // insert the sentence txtEditor.replaceSelection(sentence); // select the … int dotspoint = txtEditor.getText().indexOf(markThisPart, insertionpoint); if (dotspoint > 0) { txtEditor.setCaretPosition(dotspoint); txtEditor.moveCaretPosition(dotspoint + markThisPart.length()); } } }
@Override public void redo() throws CannotRedoException { restoreSelections(); if (canRedo()) { super.redo(); } else { die(); } editor.requestFocusInWindow(); }
/** DOCUMENT ME! */ private void doPopup() { if (findPopup != null) { JTextComponent c = getComponent(); findPopup.pack(); // The "-1" just snugs us up a bit under the text field. findPopup.show(c, 0, c.getHeight() - 1); // Set focus back to the text field. // TODO Fix caret positioning, selection, etc. c.requestFocusInWindow(); } }
public void undo() throws CannotUndoException { restoreSelections(); listener.finishCurrentEdit(); if (canUndo()) { super.undo(); } else { die(); } if (adapter != null) { adapter.updateModel(); } editor.requestFocusInWindow(); editor.selectAll(); }
@Override protected void initFocus(final JComponent focus) { input1.selectAll(); input1.requestFocusInWindow(); }
private void focusFullSelectionOnTextComponent(JTextComponent component) { component.setSelectionStart(0); component.setSelectionEnd(component.getText().length()); component.requestFocusInWindow(); }