mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 23:37:13 -06:00
Theme Editor: "replace" and "replace all" added; focus editor with F12 key
This commit is contained in:
@@ -48,13 +48,15 @@ class FlatFindReplaceBar
|
|||||||
|
|
||||||
findField.getDocument().addDocumentListener( new MarkAllUpdater() );
|
findField.getDocument().addDocumentListener( new MarkAllUpdater() );
|
||||||
|
|
||||||
// find previous/next with UP/DOWN keys
|
// find previous/next with UP/DOWN keys; focus editor with F12 key
|
||||||
InputMap inputMap = findField.getInputMap();
|
InputMap inputMap = getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
|
||||||
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_UP, 0 ), "findPrevious" );
|
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_UP, 0 ), "findPrevious" );
|
||||||
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_DOWN, 0 ), "findNext" );
|
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_DOWN, 0 ), "findNext" );
|
||||||
ActionMap actionMap = findField.getActionMap();
|
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_F12, 0 ), "focusEditor" );
|
||||||
|
ActionMap actionMap = getActionMap();
|
||||||
actionMap.put( "findPrevious", new ConsumerAction( e -> findPrevious() ) );
|
actionMap.put( "findPrevious", new ConsumerAction( e -> findPrevious() ) );
|
||||||
actionMap.put( "findNext", new ConsumerAction( e -> findNext() ) );
|
actionMap.put( "findNext", new ConsumerAction( e -> findNext() ) );
|
||||||
|
actionMap.put( "focusEditor", new ConsumerAction( e -> textArea.requestFocusInWindow() ) );
|
||||||
|
|
||||||
findPreviousButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/themeeditor/icons/findAndShowPrevMatches.svg" ) );
|
findPreviousButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/themeeditor/icons/findAndShowPrevMatches.svg" ) );
|
||||||
findNextButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/themeeditor/icons/findAndShowNextMatches.svg" ) );
|
findNextButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/themeeditor/icons/findAndShowNextMatches.svg" ) );
|
||||||
@@ -76,6 +78,7 @@ class FlatFindReplaceBar
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
findField.setText( context.getSearchFor() );
|
findField.setText( context.getSearchFor() );
|
||||||
|
replaceField.setText( context.getReplaceWith() );
|
||||||
matchCaseToggleButton.setSelected( context.getMatchCase() );
|
matchCaseToggleButton.setSelected( context.getMatchCase() );
|
||||||
matchWholeWordToggleButton.setSelected( context.getWholeWord() );
|
matchWholeWordToggleButton.setSelected( context.getWholeWord() );
|
||||||
regexToggleButton.setSelected( context.isRegularExpression() );
|
regexToggleButton.setSelected( context.isRegularExpression() );
|
||||||
@@ -130,7 +133,7 @@ class FlatFindReplaceBar
|
|||||||
: SearchEngine.markAll( textArea, context );
|
: SearchEngine.markAll( textArea, context );
|
||||||
|
|
||||||
// update matches info label
|
// update matches info label
|
||||||
matchesLabel.setText( result.getMarkedCount() + " matches" );
|
updateMatchesLabel( result, false );
|
||||||
|
|
||||||
// enabled/disable
|
// enabled/disable
|
||||||
boolean findEnabled = (searchFor != null && !searchFor.isEmpty());
|
boolean findEnabled = (searchFor != null && !searchFor.isEmpty());
|
||||||
@@ -153,6 +156,33 @@ class FlatFindReplaceBar
|
|||||||
markAll();
|
markAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void replace() {
|
||||||
|
// update search context
|
||||||
|
context.setReplaceWith( replaceField.getText() );
|
||||||
|
|
||||||
|
// replace
|
||||||
|
SearchResult result = SearchEngine.replace( textArea, context );
|
||||||
|
|
||||||
|
// update matches info labels
|
||||||
|
updateMatchesLabel( result, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void replaceAll() {
|
||||||
|
// update search context
|
||||||
|
context.setReplaceWith( replaceField.getText() );
|
||||||
|
|
||||||
|
// replace all
|
||||||
|
SearchResult result = SearchEngine.replaceAll( textArea, context );
|
||||||
|
|
||||||
|
// update matches info labels
|
||||||
|
updateMatchesLabel( result, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateMatchesLabel( SearchResult result, boolean replace ) {
|
||||||
|
matchesLabel.setText( result.getMarkedCount() + " matches" );
|
||||||
|
replaceMatchesLabel.setText( replace ? result.getCount() + " matches replaced" : null );
|
||||||
|
}
|
||||||
|
|
||||||
private void close() {
|
private void close() {
|
||||||
Container parent = getParent();
|
Container parent = getParent();
|
||||||
if( parent instanceof CollapsibleSectionPanel )
|
if( parent instanceof CollapsibleSectionPanel )
|
||||||
@@ -172,18 +202,27 @@ class FlatFindReplaceBar
|
|||||||
matchWholeWordToggleButton = new JToggleButton();
|
matchWholeWordToggleButton = new JToggleButton();
|
||||||
regexToggleButton = new JToggleButton();
|
regexToggleButton = new JToggleButton();
|
||||||
matchesLabel = new JLabel();
|
matchesLabel = new JLabel();
|
||||||
hSpacer1 = new JPanel(null);
|
closeToolBar = new JToolBar();
|
||||||
closeButton = new JButton();
|
closeButton = new JButton();
|
||||||
|
replaceLabel = new JLabel();
|
||||||
|
replaceField = new JTextField();
|
||||||
|
toolBar1 = new JToolBar();
|
||||||
|
replaceButton = new JButton();
|
||||||
|
replaceAllButton = new JButton();
|
||||||
|
replaceMatchesLabel = new JLabel();
|
||||||
|
|
||||||
//======== this ========
|
//======== this ========
|
||||||
setFocusCycleRoot(true);
|
setFocusCycleRoot(true);
|
||||||
setLayout(new MigLayout(
|
setLayout(new MigLayout(
|
||||||
"insets 3,hidemode 3",
|
"insets 3 6 3 3,hidemode 3",
|
||||||
// columns
|
// columns
|
||||||
"[fill]" +
|
"[fill]" +
|
||||||
"[fill]0" +
|
"[fill]0" +
|
||||||
"[grow,fill]",
|
"[fill]" +
|
||||||
|
"[grow,fill]" +
|
||||||
|
"[fill]",
|
||||||
// rows
|
// rows
|
||||||
|
"[]3" +
|
||||||
"[]"));
|
"[]"));
|
||||||
|
|
||||||
//---- findLabel ----
|
//---- findLabel ----
|
||||||
@@ -227,19 +266,57 @@ class FlatFindReplaceBar
|
|||||||
regexToggleButton.setToolTipText("Regex");
|
regexToggleButton.setToolTipText("Regex");
|
||||||
regexToggleButton.addActionListener(e -> regexChanged());
|
regexToggleButton.addActionListener(e -> regexChanged());
|
||||||
findToolBar.add(regexToggleButton);
|
findToolBar.add(regexToggleButton);
|
||||||
findToolBar.addSeparator();
|
}
|
||||||
|
add(findToolBar, "cell 2 0");
|
||||||
|
|
||||||
//---- matchesLabel ----
|
//---- matchesLabel ----
|
||||||
matchesLabel.setEnabled(false);
|
matchesLabel.setEnabled(false);
|
||||||
findToolBar.add(matchesLabel);
|
add(matchesLabel, "cell 3 0");
|
||||||
findToolBar.add(hSpacer1);
|
|
||||||
|
//======== closeToolBar ========
|
||||||
|
{
|
||||||
|
closeToolBar.setFloatable(false);
|
||||||
|
closeToolBar.setBorder(null);
|
||||||
|
|
||||||
//---- closeButton ----
|
//---- closeButton ----
|
||||||
closeButton.setToolTipText("Close");
|
closeButton.setToolTipText("Close");
|
||||||
closeButton.addActionListener(e -> close());
|
closeButton.addActionListener(e -> close());
|
||||||
findToolBar.add(closeButton);
|
closeToolBar.add(closeButton);
|
||||||
}
|
}
|
||||||
add(findToolBar, "cell 2 0");
|
add(closeToolBar, "cell 4 0");
|
||||||
|
|
||||||
|
//---- replaceLabel ----
|
||||||
|
replaceLabel.setText("Replace:");
|
||||||
|
replaceLabel.setDisplayedMnemonic('R');
|
||||||
|
replaceLabel.setLabelFor(replaceField);
|
||||||
|
add(replaceLabel, "cell 0 1");
|
||||||
|
|
||||||
|
//---- replaceField ----
|
||||||
|
replaceField.setColumns(16);
|
||||||
|
add(replaceField, "cell 1 1");
|
||||||
|
|
||||||
|
//======== toolBar1 ========
|
||||||
|
{
|
||||||
|
toolBar1.setFloatable(false);
|
||||||
|
toolBar1.setBorder(null);
|
||||||
|
|
||||||
|
//---- replaceButton ----
|
||||||
|
replaceButton.setText("Replace");
|
||||||
|
replaceButton.setMnemonic('E');
|
||||||
|
replaceButton.addActionListener(e -> replace());
|
||||||
|
toolBar1.add(replaceButton);
|
||||||
|
|
||||||
|
//---- replaceAllButton ----
|
||||||
|
replaceAllButton.setText("Replace All");
|
||||||
|
replaceAllButton.setMnemonic('A');
|
||||||
|
replaceAllButton.addActionListener(e -> replaceAll());
|
||||||
|
toolBar1.add(replaceAllButton);
|
||||||
|
}
|
||||||
|
add(toolBar1, "cell 2 1");
|
||||||
|
|
||||||
|
//---- replaceMatchesLabel ----
|
||||||
|
replaceMatchesLabel.setEnabled(false);
|
||||||
|
add(replaceMatchesLabel, "cell 3 1");
|
||||||
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,8 +330,14 @@ class FlatFindReplaceBar
|
|||||||
private JToggleButton matchWholeWordToggleButton;
|
private JToggleButton matchWholeWordToggleButton;
|
||||||
private JToggleButton regexToggleButton;
|
private JToggleButton regexToggleButton;
|
||||||
private JLabel matchesLabel;
|
private JLabel matchesLabel;
|
||||||
private JPanel hSpacer1;
|
private JToolBar closeToolBar;
|
||||||
private JButton closeButton;
|
private JButton closeButton;
|
||||||
|
private JLabel replaceLabel;
|
||||||
|
private JTextField replaceField;
|
||||||
|
private JToolBar toolBar1;
|
||||||
|
private JButton replaceButton;
|
||||||
|
private JButton replaceAllButton;
|
||||||
|
private JLabel replaceMatchesLabel;
|
||||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||||
|
|
||||||
//---- class MarkAllUpdater -----------------------------------------------
|
//---- class MarkAllUpdater -----------------------------------------------
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ new FormModel {
|
|||||||
contentType: "form/swing"
|
contentType: "form/swing"
|
||||||
root: new FormRoot {
|
root: new FormRoot {
|
||||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||||
"$layoutConstraints": "insets 3,hidemode 3"
|
"$layoutConstraints": "insets 3 6 3 3,hidemode 3"
|
||||||
"$columnConstraints": "[fill][fill]0[grow,fill]"
|
"$columnConstraints": "[fill][fill]0[fill][grow,fill][fill]"
|
||||||
"$rowConstraints": "[]"
|
"$rowConstraints": "[]3[]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "this"
|
name: "this"
|
||||||
"focusCycleRoot": true
|
"focusCycleRoot": true
|
||||||
@@ -57,27 +57,69 @@ new FormModel {
|
|||||||
"toolTipText": "Regex"
|
"toolTipText": "Regex"
|
||||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "regexChanged", false ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "regexChanged", false ) )
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JToolBar$Separator" ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
name: "separator2"
|
"value": "cell 2 0"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "matchesLabel"
|
name: "matchesLabel"
|
||||||
"enabled": false
|
"enabled": false
|
||||||
} )
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
add( new FormComponent( "com.jformdesigner.designer.wrapper.HSpacer" ) {
|
"value": "cell 3 0"
|
||||||
name: "hSpacer1"
|
} )
|
||||||
} )
|
add( new FormContainer( "javax.swing.JToolBar", new FormLayoutManager( class javax.swing.JToolBar ) ) {
|
||||||
|
name: "closeToolBar"
|
||||||
|
"floatable": false
|
||||||
|
"border": sfield com.jformdesigner.model.FormObject NULL_VALUE
|
||||||
add( new FormComponent( "javax.swing.JButton" ) {
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
name: "closeButton"
|
name: "closeButton"
|
||||||
"toolTipText": "Close"
|
"toolTipText": "Close"
|
||||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "close", false ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "close", false ) )
|
||||||
} )
|
} )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 2 0"
|
"value": "cell 4 0"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "replaceLabel"
|
||||||
|
"text": "Replace:"
|
||||||
|
"displayedMnemonic": 82
|
||||||
|
"labelFor": new FormReference( "replaceField" )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 0 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JTextField" ) {
|
||||||
|
name: "replaceField"
|
||||||
|
"columns": 16
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 1"
|
||||||
|
} )
|
||||||
|
add( new FormContainer( "javax.swing.JToolBar", new FormLayoutManager( class javax.swing.JToolBar ) ) {
|
||||||
|
name: "toolBar1"
|
||||||
|
"floatable": false
|
||||||
|
"border": sfield com.jformdesigner.model.FormObject NULL_VALUE
|
||||||
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
|
name: "replaceButton"
|
||||||
|
"text": "Replace"
|
||||||
|
"mnemonic": 69
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "replace", false ) )
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
|
name: "replaceAllButton"
|
||||||
|
"text": "Replace All"
|
||||||
|
"mnemonic": 65
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "replaceAll", false ) )
|
||||||
|
} )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 2 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "replaceMatchesLabel"
|
||||||
|
"enabled": false
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 3 1"
|
||||||
} )
|
} )
|
||||||
}, new FormLayoutConstraints( null ) {
|
}, new FormLayoutConstraints( null ) {
|
||||||
"location": new java.awt.Point( 0, 0 )
|
"location": new java.awt.Point( 0, 0 )
|
||||||
"size": new java.awt.Dimension( 400, 300 )
|
"size": new java.awt.Dimension( 465, 125 )
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ public class FlatThemeFileEditor
|
|||||||
editMenu.setMnemonic('E');
|
editMenu.setMnemonic('E');
|
||||||
|
|
||||||
//---- findMenuItem ----
|
//---- findMenuItem ----
|
||||||
findMenuItem.setText("Find...");
|
findMenuItem.setText("Find/Replace...");
|
||||||
findMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
|
findMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
|
||||||
findMenuItem.setMnemonic('F');
|
findMenuItem.setMnemonic('F');
|
||||||
findMenuItem.addActionListener(e -> find());
|
findMenuItem.addActionListener(e -> find());
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ new FormModel {
|
|||||||
"mnemonic": 69
|
"mnemonic": 69
|
||||||
add( new FormComponent( "javax.swing.JMenuItem" ) {
|
add( new FormComponent( "javax.swing.JMenuItem" ) {
|
||||||
name: "findMenuItem"
|
name: "findMenuItem"
|
||||||
"text": "Find..."
|
"text": "Find/Replace..."
|
||||||
"accelerator": static javax.swing.KeyStroke getKeyStroke( 70, 4226, false )
|
"accelerator": static javax.swing.KeyStroke getKeyStroke( 70, 4226, false )
|
||||||
"mnemonic": 70
|
"mnemonic": 70
|
||||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "find", false ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "find", false ) )
|
||||||
|
|||||||
Reference in New Issue
Block a user