Theme Editor: Preview:

- reworked disabling to avoid disabling internal components
- do not disable labels
- removed special code for JTextPane and JEditorPane, which seems to be no longer needed
This commit is contained in:
Karl Tauber
2021-12-26 20:30:36 +01:00
parent b56215e5e3
commit 01170b669b
2 changed files with 36 additions and 33 deletions

View File

@@ -128,26 +128,25 @@ class FlatThemePreviewAll
} }
private void enableDisable( Component comp, boolean enabled ) { private void enableDisable( Component comp, boolean enabled ) {
if( !isControlComponent( comp ) ) if( comp instanceof JScrollPane )
comp.setEnabled( enabled ); comp = ((JScrollPane)comp).getViewport().getView();
if( !(comp instanceof Container) || comp instanceof JInternalFrame ) if( comp == null || (comp instanceof JLabel && comp != label1) )
return; return;
for( Component c : ((Container)comp).getComponents() ) { // enable/disable component
if( c instanceof JScrollPane ) if( !isControlComponent( comp ) && comp != menu2 )
c = ((JScrollPane)c).getViewport().getView(); comp.setEnabled( enabled );
// make sure that background is updated correctly in BasicTextUI.updateBackground() // enable/disable children
if( c instanceof JTextPane ) if( comp instanceof JPanel || comp instanceof JToolBar || comp instanceof JMenuBar ) {
c.setBackground( UIManager.getColor( "TextPane.background" ) ); for( Component c : ((Container)comp).getComponents() )
else if( c instanceof JEditorPane ) enableDisable( c, enabled );
c.setBackground( UIManager.getColor( "EditorPane.background" ) ); } else if( comp instanceof JSplitPane ) {
JSplitPane splitPane = (JSplitPane) comp;
enableDisable( c, enabled ); enableDisable( splitPane.getLeftComponent(), enabled );
} enableDisable( splitPane.getRightComponent(), enabled );
} else if( comp instanceof JMenu ) {
if( comp instanceof JMenu ) {
JMenu menu = (JMenu) comp; JMenu menu = (JMenu) comp;
int count = menu.getMenuComponentCount(); int count = menu.getMenuComponentCount();
for( int i = 0; i < count; i++ ) for( int i = 0; i < count; i++ )
@@ -165,9 +164,6 @@ class FlatThemePreviewAll
textArea1.setEditable( editable ); textArea1.setEditable( editable );
editorPane1.setEditable( editable ); editorPane1.setEditable( editable );
textPane1.setEditable( editable ); textPane1.setEditable( editable );
editorPane1.updateUI();
textPane1.updateUI();
} ); } );
FlatThemeFileEditor.putPrefsBoolean( preview.state, KEY_EDITABLE, editable, true ); FlatThemeFileEditor.putPrefsBoolean( preview.state, KEY_EDITABLE, editable, true );
@@ -186,20 +182,24 @@ class FlatThemePreviewAll
} }
private void focusComponent( Component comp, Object value ) { private void focusComponent( Component comp, Object value ) {
if( comp instanceof JScrollPane )
comp = ((JScrollPane)comp).getViewport().getView();
if( comp == null )
return;
// focus component
if( !isControlComponent( comp ) && comp instanceof JComponent ) if( !isControlComponent( comp ) && comp instanceof JComponent )
((JComponent)comp).putClientProperty( FlatClientProperties.COMPONENT_FOCUS_OWNER, value ); ((JComponent)comp).putClientProperty( FlatClientProperties.COMPONENT_FOCUS_OWNER, value );
if( !(comp instanceof Container) || // focus children
comp instanceof JComboBox || if( comp instanceof JPanel || comp instanceof JToolBar ) {
comp instanceof JSpinner || for( Component c : ((Container)comp).getComponents() )
comp instanceof JInternalFrame ) focusComponent( c, value );
return; } else if( comp instanceof JSplitPane ) {
JSplitPane splitPane = (JSplitPane) comp;
for( Component c : ((Container)comp).getComponents() ) { focusComponent( splitPane.getLeftComponent(), value );
if( c instanceof JScrollPane ) focusComponent( splitPane.getRightComponent(), value );
c = ((JScrollPane)c).getViewport().getView();
focusComponent( c, value );
} }
} }
@@ -207,8 +207,7 @@ class FlatThemePreviewAll
return c == enabledCheckBox || return c == enabledCheckBox ||
c == editableCheckBox || c == editableCheckBox ||
c == focusedCheckBox || c == focusedCheckBox ||
c == menuUnderlineSelectionButton || c == menuUnderlineSelectionButton;
c == menu2;
} }
private void menuUnderlineSelectionChanged() { private void menuUnderlineSelectionChanged() {
@@ -246,7 +245,7 @@ class FlatThemePreviewAll
editableCheckBox = new JCheckBox(); editableCheckBox = new JCheckBox();
focusedCheckBox = new JCheckBox(); focusedCheckBox = new JCheckBox();
JLabel labelLabel = new JLabel(); JLabel labelLabel = new JLabel();
JLabel label1 = new JLabel(); label1 = new JLabel();
FlatButton flatButton1 = new FlatButton(); FlatButton flatButton1 = new FlatButton();
JLabel buttonLabel = new JLabel(); JLabel buttonLabel = new JLabel();
JButton button1 = new JButton(); JButton button1 = new JButton();
@@ -861,6 +860,7 @@ class FlatThemePreviewAll
private JCheckBox enabledCheckBox; private JCheckBox enabledCheckBox;
private JCheckBox editableCheckBox; private JCheckBox editableCheckBox;
private JCheckBox focusedCheckBox; private JCheckBox focusedCheckBox;
private JLabel label1;
private FlatTextField textField1; private FlatTextField textField1;
private FlatFormattedTextField formattedTextField1; private FlatFormattedTextField formattedTextField1;
private FlatPasswordField passwordField1; private FlatPasswordField passwordField1;

View File

@@ -58,6 +58,9 @@ new FormModel {
add( new FormComponent( "javax.swing.JLabel" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "label1" name: "label1"
"text": "Some Text" "text": "Some Text"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1 2 1" "value": "cell 1 1 2 1"
} ) } )