📄 jxfinddialog.java
字号:
*/ public void doClose() { JXFindDialog.this.dispose(); } private void setLastIndex(int i) { getPatternModel().setFoundIndex(i); } private int getLastIndex() { return getPatternModel().getFoundIndex(); } private Pattern getPattern() { return getPatternModel().getPattern(); } //-------------------------- initial private void initActions() { putAction(PatternModel.MATCH_CASE_ACTION_COMMAND, createMatchCaseAction()); putAction(MATCH_WRAP_ACTION_COMMAND, createWrapAction()); putAction(MATCH_BACKWARDS_ACTION_COMMAND, createBackwardsAction()); // PENDING: factor a common dialog containing the following putAction(EXECUTE_FIND_ACTION_COMMAND, createFindAction()); putAction(CLOSE_ACTION_COMMAND, createCloseAction()); } /** * * @return */ private AbstractActionExt createMatchCaseAction() { String actionName = getUIString(PatternModel.MATCH_CASE_ACTION_COMMAND); BoundAction action = new BoundAction(actionName, PatternModel.MATCH_CASE_ACTION_COMMAND); action.setStateAction(); action.registerCallback(getPatternModel(), "setCaseSensitive"); action.setSelected(getPatternModel().isCaseSensitive()); return action; } /** * * @return */ private AbstractActionExt createWrapAction() { String actionName = getUIString(MATCH_WRAP_ACTION_COMMAND); BoundAction action = new BoundAction(actionName, MATCH_WRAP_ACTION_COMMAND); action.setStateAction(); action.registerCallback(getPatternModel(), "setWrapping"); action.setSelected(getPatternModel().isWrapping()); return action; } /** * * @return */ private AbstractActionExt createBackwardsAction() { String actionName = getUIString(MATCH_BACKWARDS_ACTION_COMMAND); BoundAction action = new BoundAction(actionName, MATCH_BACKWARDS_ACTION_COMMAND); action.setStateAction(); action.registerCallback(getPatternModel(), "setBackwards"); action.setSelected(getPatternModel().isWrapping()); return action; } /** * * @return */ private AbstractActionExt createFindAction() { String actionName = getUIString(EXECUTE_FIND_ACTION_COMMAND); BoundAction action = new BoundAction(actionName, EXECUTE_FIND_ACTION_COMMAND); action.registerCallback(this, "doFind"); return action; } /** * * @return */ private AbstractActionExt createCloseAction() { String actionName = getUIString(CLOSE_ACTION_COMMAND); BoundAction action = new BoundAction(actionName, CLOSE_ACTION_COMMAND); action.registerCallback(this, "doClose"); return action; } /** * convenience wrapper to access rootPane's actionMap. * @param key * @param action */ private void putAction(Object key, Action action) { getRootPane().getActionMap().put(key, action); } /** * convenience wrapper to access rootPane's actionMap. * * @param key * @return */ private Action getAction(Object key) { return getRootPane().getActionMap().get(key); } /** * tries to find a String value from the UIManager, prefixing the * given key with the UIPREFIX. * * TODO: move to utilities? * * @param key * @return the String as returned by the UIManager or key if the returned * value was null. */ private String getUIString(String key) { String text = UIManager.getString(PatternModel.SEARCH_PREFIX + key); return text != null ? text : key; } //----------------------------- init ui /** create components. * */ private void initComponents() { searchField = new JTextField(30) { public Dimension getMaximumSize() { Dimension superMax = super.getMaximumSize(); superMax.height = getPreferredSize().height; return superMax; } }; matchCheck = new JCheckBox(); wrapCheck = new JCheckBox(); backCheck = new JCheckBox(); } private void build() { JComponent content = new Box(BoxLayout.PAGE_AXIS); //Box.createVerticalBox(); JComponent fieldPanel = createFieldPanel(); content.add(fieldPanel); JComponent buttonPanel = createButtonPanel(); content.add(buttonPanel); content.setBorder(BorderFactory.createEmptyBorder(14, 14, 14, 14));// content.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); // fieldPanel.setAlignmentX();// buttonPanel.setAlignmentX(Component.RIGHT_ALIGNMENT); add(content); } /** * TODO: Strings should be removed from the UI */ private JComponent createFieldPanel() { // Create components JLabel label = new JLabel(getUIString(SEARCH_FIELD_LABEL)); String mnemonic = getUIString(SEARCH_FIELD_MNEMONIC); if (mnemonic != SEARCH_FIELD_MNEMONIC) { label.setDisplayedMnemonic(mnemonic.charAt(0)); } label.setLabelFor(searchField); Box lBox = new Box(BoxLayout.LINE_AXIS); lBox.add(label); lBox.add(new JLabel(":")); lBox.add(new JLabel(" "));// lBox.add(Box.createGlue()); lBox.setAlignmentY(Component.TOP_ALIGNMENT); Box rBox = new Box(BoxLayout.PAGE_AXIS); rBox.add(searchField); rBox.add(matchCheck); rBox.add(wrapCheck); rBox.add(backCheck); rBox.setAlignmentY(Component.TOP_ALIGNMENT); Box box = new Box(BoxLayout.LINE_AXIS); box.add(lBox); box.add(rBox); return box; } /** * create the dialog button controls. * * PENDING: this should be factored to a common dialog support. * * @return */ private JComponent createButtonPanel() { JPanel panel = new JPanel(new BasicOptionPaneUI.ButtonAreaLayout(true, 6)) { public Dimension getMaximumSize() { return getPreferredSize(); } }; panel.setBorder(BorderFactory.createEmptyBorder(9, 0, 0, 0)); Action findAction = getAction(EXECUTE_FIND_ACTION_COMMAND); Action closeAction = getAction(CLOSE_ACTION_COMMAND); JButton findButton; panel.add(findButton = new JButton(findAction)); panel.add(new JButton(closeAction)); KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false); KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(enterKey, EXECUTE_FIND_ACTION_COMMAND); inputMap.put(escapeKey, CLOSE_ACTION_COMMAND); getRootPane().setDefaultButton(findButton); return panel; } //----------------------- obsolete actions - no longer use //----------------------- kept here to remember adding names etc to resources private abstract class CheckAction extends AbstractAction { public CheckAction(String name) { super(name); } public void actionPerformed(ActionEvent evt) { } } private class MatchAction extends CheckAction { public MatchAction() { super("Match upper/lower case"); putValue(Action.MNEMONIC_KEY, new Integer('M')); } } private class WrapAction extends CheckAction { public WrapAction() { super("Wrap around"); putValue(Action.MNEMONIC_KEY, new Integer('W')); } } private class BackwardAction extends CheckAction { public BackwardAction() { super("Search Backwards"); putValue(Action.MNEMONIC_KEY, new Integer('B')); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -