Theme Editor:

- support "themes" sub-directory
- added "generate Java class" checkbox to "New" dialog
This commit is contained in:
Karl Tauber
2022-05-10 11:01:45 +02:00
parent 1758c175ed
commit 37c375e2fa

View File

@@ -384,7 +384,17 @@ class FlatThemeFileEditor
String n2 = toSortName( f2.getName() ); String n2 = toSortName( f2.getName() );
return n1.compareToIgnoreCase( n2 ); return n1.compareToIgnoreCase( n2 );
} ); } );
return propertiesFiles;
File themesDir = new File( dir, "themes" );
if( !themesDir.isDirectory() )
return propertiesFiles;
// get files from "themes" sub-directory
File[] themesFiles = getPropertiesFiles( themesDir );
File[] allFiles = new File[propertiesFiles.length + themesFiles.length];
System.arraycopy( propertiesFiles, 0, allFiles, 0, propertiesFiles.length );
System.arraycopy( themesFiles, 0, allFiles, propertiesFiles.length, themesFiles.length );
return allFiles;
} }
private String toSortName( String name ) { private String toSortName( String name ) {
@@ -469,12 +479,21 @@ class FlatThemeFileEditor
FlatIntelliJLaf.NAME, FlatIntelliJLaf.NAME,
FlatDarculaLaf.NAME, FlatDarculaLaf.NAME,
} ); } );
JCheckBox genJavaClassCheckBox = new JCheckBox( "Generate Java class" );
genJavaClassCheckBox.setMnemonic( 'G' );
File themesDir = new File( dir, "themes" );
JCheckBox useThemesDirCheckBox = themesDir.isDirectory()
? new JCheckBox( "Create in 'themes' directory", true )
: null;
JOptionPane optionPane = new JOptionPane( new Object[] { JOptionPane optionPane = new JOptionPane( new Object[] {
new JLabel( "Theme name:" ), new JLabel( "Theme name:" ),
themeNameField, themeNameField,
new JLabel( "Base Theme:" ), new JLabel( "Base Theme:" ),
baseThemeField, baseThemeField,
genJavaClassCheckBox,
useThemesDirCheckBox,
}, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION ) { }, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION ) {
@Override @Override
public void selectInitialValue() { public void selectInitialValue() {
@@ -496,7 +515,8 @@ class FlatThemeFileEditor
return; return;
} }
File file = new File( dir, themeName + ".properties" ); File dir2 = (useThemesDirCheckBox != null && useThemesDirCheckBox.isSelected()) ? themesDir : dir;
File file = new File( dir2, themeName + ".properties" );
if( file.exists() ) { if( file.exists() ) {
JOptionPane.showMessageDialog( this, "Theme '" + themeName + "' already exists.", title, JOptionPane.INFORMATION_MESSAGE ); JOptionPane.showMessageDialog( this, "Theme '" + themeName + "' already exists.", title, JOptionPane.INFORMATION_MESSAGE );
return; return;
@@ -505,7 +525,8 @@ class FlatThemeFileEditor
try { try {
String baseTheme = (String) baseThemeField.getSelectedItem(); String baseTheme = (String) baseThemeField.getSelectedItem();
createTheme( file, baseTheme ); createTheme( file, baseTheme );
createThemeClass( dir, themeName, baseTheme ); if( genJavaClassCheckBox.isSelected() )
createThemeClass( dir2, themeName, baseTheme );
openFile( file, true ); openFile( file, true );
} catch( IOException ex ) { } catch( IOException ex ) {
ex.printStackTrace(); ex.printStackTrace();