Theme Editor: preview: added "editable" check box for text components

This commit is contained in:
Karl Tauber
2021-09-08 00:22:02 +02:00
parent b5f2f77944
commit bddef38a7c
2 changed files with 81 additions and 9 deletions

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.themeeditor;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.beans.Beans;
import java.beans.PropertyVetoException; import java.beans.PropertyVetoException;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
@@ -40,6 +41,7 @@ class FlatThemePreviewAll
extends JPanel extends JPanel
{ {
private static final String KEY_ENABLED = "preview.enabled"; private static final String KEY_ENABLED = "preview.enabled";
private static final String KEY_EDITABLE = "preview.editable";
private static final String KEY_FOCUSED = "preview.focused"; private static final String KEY_FOCUSED = "preview.focused";
private static final String KEY_MENU_UNDERLINE_SELECTION = "preview.menuUnderlineSelection"; private static final String KEY_MENU_UNDERLINE_SELECTION = "preview.menuUnderlineSelection";
@@ -84,6 +86,7 @@ class FlatThemePreviewAll
void activated() { void activated() {
boolean enabled = preview.state.getBoolean( KEY_ENABLED, true ); boolean enabled = preview.state.getBoolean( KEY_ENABLED, true );
boolean editable = preview.state.getBoolean( KEY_EDITABLE, true );
boolean focused = preview.state.getBoolean( KEY_FOCUSED, false ); boolean focused = preview.state.getBoolean( KEY_FOCUSED, false );
boolean menuUnderlineSelection = preview.state.getBoolean( KEY_MENU_UNDERLINE_SELECTION, false ); boolean menuUnderlineSelection = preview.state.getBoolean( KEY_MENU_UNDERLINE_SELECTION, false );
@@ -92,6 +95,11 @@ class FlatThemePreviewAll
enabledChanged(); enabledChanged();
} }
if( editable != editableCheckBox.isSelected() ) {
editableCheckBox.setSelected( editable );
editableChanged();
}
if( focused != focusedCheckBox.isSelected() ) { if( focused != focusedCheckBox.isSelected() ) {
focusedCheckBox.setSelected( focused ); focusedCheckBox.setSelected( focused );
focusedChanged(); focusedChanged();
@@ -146,6 +154,24 @@ class FlatThemePreviewAll
} }
} }
private void editableChanged() {
boolean editable = editableCheckBox.isSelected();
preview.runWithUIDefaultsGetter( () -> {
textField1.setEditable( editable );
formattedTextField1.setEditable( editable );
passwordField1.setEditable( editable );
textArea1.setEditable( editable );
editorPane1.setEditable( editable );
textPane1.setEditable( editable );
editorPane1.updateUI();
textPane1.updateUI();
} );
FlatThemeFileEditor.putPrefsBoolean( preview.state, KEY_EDITABLE, editable, true );
}
private void focusedChanged() { private void focusedChanged() {
boolean focused = focusedCheckBox.isSelected(); boolean focused = focusedCheckBox.isSelected();
@@ -175,6 +201,7 @@ class FlatThemePreviewAll
private boolean isControlComponent( Component c ) { private boolean isControlComponent( Component c ) {
return c == enabledCheckBox || return c == enabledCheckBox ||
c == editableCheckBox ||
c == focusedCheckBox || c == focusedCheckBox ||
c == menuUnderlineSelectionButton || c == menuUnderlineSelectionButton ||
c == menu2; c == menu2;
@@ -212,6 +239,7 @@ class FlatThemePreviewAll
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JPanel hSpacer1 = new JPanel(null); JPanel hSpacer1 = new JPanel(null);
enabledCheckBox = new JCheckBox(); enabledCheckBox = new JCheckBox();
editableCheckBox = new JCheckBox();
focusedCheckBox = new JCheckBox(); focusedCheckBox = new JCheckBox();
JLabel labelLabel = new JLabel(); JLabel labelLabel = new JLabel();
JLabel label1 = new JLabel(); JLabel label1 = new JLabel();
@@ -235,15 +263,15 @@ class FlatThemePreviewAll
JSpinner spinner1 = new JSpinner(); JSpinner spinner1 = new JSpinner();
JLabel textFieldLabel = new JLabel(); JLabel textFieldLabel = new JLabel();
textField1 = new FlatTextField(); textField1 = new FlatTextField();
FlatFormattedTextField formattedTextField1 = new FlatFormattedTextField(); formattedTextField1 = new FlatFormattedTextField();
FlatPasswordField passwordField1 = new FlatPasswordField(); passwordField1 = new FlatPasswordField();
JLabel textAreaLabel = new JLabel(); JLabel textAreaLabel = new JLabel();
JScrollPane scrollPane1 = new JScrollPane(); JScrollPane scrollPane1 = new JScrollPane();
JTextArea textArea1 = new JTextArea(); textArea1 = new JTextArea();
JScrollPane scrollPane5 = new JScrollPane(); JScrollPane scrollPane5 = new JScrollPane();
JEditorPane editorPane1 = new JEditorPane(); editorPane1 = new JEditorPane();
JScrollPane scrollPane9 = new JScrollPane(); JScrollPane scrollPane9 = new JScrollPane();
JTextPane textPane1 = new JTextPane(); textPane1 = new JTextPane();
JLabel menuBarLabel = new JLabel(); JLabel menuBarLabel = new JLabel();
menuUnderlineSelectionButton = new FlatToggleButton(); menuUnderlineSelectionButton = new FlatToggleButton();
JMenuBar menuBar1 = new JMenuBar(); JMenuBar menuBar1 = new JMenuBar();
@@ -340,6 +368,12 @@ class FlatThemePreviewAll
enabledCheckBox.addActionListener(e -> enabledChanged()); enabledCheckBox.addActionListener(e -> enabledChanged());
add(enabledCheckBox, "cell 0 0 3 1"); add(enabledCheckBox, "cell 0 0 3 1");
//---- editableCheckBox ----
editableCheckBox.setText("Editable");
editableCheckBox.setSelected(true);
editableCheckBox.addActionListener(e -> editableChanged());
add(editableCheckBox, "cell 0 0 3 1");
//---- focusedCheckBox ---- //---- focusedCheckBox ----
focusedCheckBox.setText("Focused"); focusedCheckBox.setText("Focused");
focusedCheckBox.addActionListener(e -> focusedChanged()); focusedCheckBox.addActionListener(e -> focusedChanged());
@@ -817,8 +851,14 @@ class FlatThemePreviewAll
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private JCheckBox enabledCheckBox; private JCheckBox enabledCheckBox;
private JCheckBox editableCheckBox;
private JCheckBox focusedCheckBox; private JCheckBox focusedCheckBox;
private FlatTextField textField1; private FlatTextField textField1;
private FlatFormattedTextField formattedTextField1;
private FlatPasswordField passwordField1;
private JTextArea textArea1;
private JEditorPane editorPane1;
private JTextPane textPane1;
private FlatToggleButton menuUnderlineSelectionButton; private FlatToggleButton menuUnderlineSelectionButton;
private JMenu menu2; private JMenu menu2;
private JSlider slider1; private JSlider slider1;
@@ -855,7 +895,10 @@ class FlatThemePreviewAll
@Override @Override
public void updateUI() { public void updateUI() {
setUI( new PreviewFlatTabbedPaneUI( uiDefaultsGetter ) ); if( !Beans.isDesignTime() )
setUI( new PreviewFlatTabbedPaneUI( uiDefaultsGetter ) );
else
super.updateUI();
} }
} }
@@ -899,10 +942,13 @@ class FlatThemePreviewAll
@Override @Override
public void paint( Graphics g ) { public void paint( Graphics g ) {
// needed for DefaultTableCellRenderer if( !Beans.isDesignTime() ) {
FlatLaf.runWithUIDefaultsGetter( uiDefaultsGetter, () -> { // needed for DefaultTableCellRenderer
FlatLaf.runWithUIDefaultsGetter( uiDefaultsGetter, () -> {
super.paint( g );
} );
} else
super.paint( g ); super.paint( g );
} );
} }
} }
} }

View File

@@ -28,6 +28,17 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0 3 1" "value": "cell 0 0 3 1"
} ) } )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "editableCheckBox"
"text": "Editable"
"selected": true
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "editableChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0 3 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) { add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "focusedCheckBox" name: "focusedCheckBox"
"text": "Focused" "text": "Focused"
@@ -219,6 +230,9 @@ new FormModel {
name: "formattedTextField1" name: "formattedTextField1"
"text": "Some Text" "text": "Some Text"
"placeholderText": "placeholder text" "placeholderText": "placeholder text"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 9" "value": "cell 1 9"
} ) } )
@@ -226,6 +240,9 @@ new FormModel {
name: "passwordField1" name: "passwordField1"
"text": "Some Text" "text": "Some Text"
"placeholderText": "placeholder text" "placeholderText": "placeholder text"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 9" "value": "cell 2 9"
} ) } )
@@ -243,6 +260,9 @@ new FormModel {
name: "textArea1" name: "textArea1"
"text": "Text" "text": "Text"
"rows": 2 "rows": 2
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
} ) } )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 10 2 1,width 40" "value": "cell 1 10 2 1,width 40"
@@ -254,6 +274,9 @@ new FormModel {
add( new FormComponent( "javax.swing.JEditorPane" ) { add( new FormComponent( "javax.swing.JEditorPane" ) {
name: "editorPane1" name: "editorPane1"
"text": "Text" "text": "Text"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
} ) } )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 10 2 1,width 40" "value": "cell 1 10 2 1,width 40"
@@ -265,6 +288,9 @@ new FormModel {
add( new FormComponent( "javax.swing.JTextPane" ) { add( new FormComponent( "javax.swing.JTextPane" ) {
name: "textPane1" name: "textPane1"
"text": "Text" "text": "Text"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
} ) } )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 10 2 1,width 40" "value": "cell 1 10 2 1,width 40"