mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
Demo: added combo box above themes list to show only light or dark themes
This commit is contained in:
@@ -25,6 +25,7 @@ class IJThemeInfo
|
||||
{
|
||||
final String name;
|
||||
final String resourceName;
|
||||
final boolean dark;
|
||||
final String license;
|
||||
final String licenseFile;
|
||||
final String sourceCodeUrl;
|
||||
@@ -32,13 +33,14 @@ class IJThemeInfo
|
||||
final File themeFile;
|
||||
final String lafClassName;
|
||||
|
||||
IJThemeInfo( String name, String resourceName,
|
||||
IJThemeInfo( String name, String resourceName, boolean dark,
|
||||
String license, String licenseFile,
|
||||
String sourceCodeUrl, String sourceCodePath,
|
||||
File themeFile, String lafClassName )
|
||||
{
|
||||
this.name = name;
|
||||
this.resourceName = resourceName;
|
||||
this.dark = dark;
|
||||
this.license = license;
|
||||
this.licenseFile = licenseFile;
|
||||
this.sourceCodeUrl = sourceCodeUrl;
|
||||
|
||||
@@ -55,12 +55,13 @@ class IJThemesManager
|
||||
String resourceName = e.getKey();
|
||||
Map<String, String> value = (Map<String, String>) e.getValue();
|
||||
String name = value.get( "name" );
|
||||
boolean dark = Boolean.parseBoolean( value.get( "dark" ) );
|
||||
String license = value.get( "license" );
|
||||
String licenseFile = value.get( "licenseFile" );
|
||||
String sourceCodeUrl = value.get( "sourceCodeUrl" );
|
||||
String sourceCodePath = value.get( "sourceCodePath" );
|
||||
|
||||
bundledThemes.add( new IJThemeInfo( name, resourceName, license, licenseFile, sourceCodeUrl, sourceCodePath, null, null ) );
|
||||
bundledThemes.add( new IJThemeInfo( name, resourceName, dark, license, licenseFile, sourceCodeUrl, sourceCodePath, null, null ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ class IJThemesManager
|
||||
String name = fname.endsWith( ".properties" )
|
||||
? StringUtils.removeTrailing( fname, ".properties" )
|
||||
: StringUtils.removeTrailing( fname, ".theme.json" );
|
||||
moreThemes.add( new IJThemeInfo( name, null, null, null, null, null, f, null ) );
|
||||
moreThemes.add( new IJThemeInfo( name, null, false, null, null, null, null, f, null ) );
|
||||
lastModifiedMap.put( f, f.lastModified() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.formdev.flatlaf.demo.intellijthemes;
|
||||
import java.awt.Component;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
@@ -120,6 +121,10 @@ public class IJThemesPanel
|
||||
}
|
||||
|
||||
private void updateThemesList() {
|
||||
int filterLightDark = filterComboBox.getSelectedIndex();
|
||||
boolean showLight = (filterLightDark != 2);
|
||||
boolean showDark = (filterLightDark != 1);
|
||||
|
||||
// load theme infos
|
||||
themesManager.loadBundledThemes();
|
||||
themesManager.loadThemesFromDirectory();
|
||||
@@ -129,15 +134,22 @@ public class IJThemesPanel
|
||||
themesManager.bundledThemes.sort( comparator );
|
||||
themesManager.moreThemes.sort( comparator );
|
||||
|
||||
// remember selection (must be invoked before clearing themes field)
|
||||
IJThemeInfo oldSel = themesList.getSelectedValue();
|
||||
|
||||
themes.clear();
|
||||
categories.clear();
|
||||
|
||||
// add core themes at beginning
|
||||
categories.put( themes.size(), "Core Themes" );
|
||||
themes.add( new IJThemeInfo( "Flat Light", null, null, null, null, null, null, FlatLightLaf.class.getName() ) );
|
||||
themes.add( new IJThemeInfo( "Flat Dark", null, null, null, null, null, null, FlatDarkLaf.class.getName() ) );
|
||||
themes.add( new IJThemeInfo( "Flat IntelliJ", null, null, null, null, null, null, FlatIntelliJLaf.class.getName() ) );
|
||||
themes.add( new IJThemeInfo( "Flat Darcula", null, null, null, null, null, null, FlatDarculaLaf.class.getName() ) );
|
||||
if( showLight )
|
||||
themes.add( new IJThemeInfo( "Flat Light", null, false, null, null, null, null, null, FlatLightLaf.class.getName() ) );
|
||||
if( showDark )
|
||||
themes.add( new IJThemeInfo( "Flat Dark", null, true, null, null, null, null, null, FlatDarkLaf.class.getName() ) );
|
||||
if( showLight )
|
||||
themes.add( new IJThemeInfo( "Flat IntelliJ", null, false, null, null, null, null, null, FlatIntelliJLaf.class.getName() ) );
|
||||
if( showDark )
|
||||
themes.add( new IJThemeInfo( "Flat Darcula", null, true, null, null, null, null, null, FlatDarculaLaf.class.getName() ) );
|
||||
|
||||
// add themes from directory
|
||||
categories.put( themes.size(), "Current Directory" );
|
||||
@@ -146,15 +158,17 @@ public class IJThemesPanel
|
||||
// add uncategorized bundled themes
|
||||
categories.put( themes.size(), "IntelliJ Themes" );
|
||||
for( IJThemeInfo ti : themesManager.bundledThemes ) {
|
||||
if( !ti.name.contains( "/" ) )
|
||||
boolean show = (showLight && !ti.dark) || (showDark && ti.dark);
|
||||
if( show && !ti.name.contains( "/" ) )
|
||||
themes.add( ti );
|
||||
}
|
||||
|
||||
// add categorized bundled themes
|
||||
String lastCategory = null;
|
||||
for( IJThemeInfo ti : themesManager.bundledThemes ) {
|
||||
boolean show = (showLight && !ti.dark) || (showDark && ti.dark);
|
||||
int sep = ti.name.indexOf( '/' );
|
||||
if( sep < 0 )
|
||||
if( !show || sep < 0 )
|
||||
continue;
|
||||
|
||||
String category = ti.name.substring( 0, sep ).trim();
|
||||
@@ -166,9 +180,6 @@ public class IJThemesPanel
|
||||
themes.add( ti );
|
||||
}
|
||||
|
||||
// remember selection
|
||||
IJThemeInfo oldSel = themesList.getSelectedValue();
|
||||
|
||||
// fill themes list
|
||||
themesList.setModel( new AbstractListModel<IJThemeInfo>() {
|
||||
@Override
|
||||
@@ -195,6 +206,18 @@ public class IJThemesPanel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// select first theme if none selected
|
||||
if( themesList.getSelectedIndex() < 0 )
|
||||
themesList.setSelectedIndex( 0 );
|
||||
|
||||
// scroll selection into visible area
|
||||
int sel = themesList.getSelectedIndex();
|
||||
if( sel >= 0 ) {
|
||||
Rectangle bounds = themesList.getCellBounds( sel, sel );
|
||||
if( bounds != null )
|
||||
themesList.scrollRectToVisible( bounds );
|
||||
}
|
||||
}
|
||||
|
||||
private void themesListValueChanged( ListSelectionEvent e ) {
|
||||
@@ -381,12 +404,17 @@ public class IJThemesPanel
|
||||
isAdjustingThemesList = false;
|
||||
}
|
||||
|
||||
private void filterChanged() {
|
||||
updateThemesList();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||
JLabel themesLabel = new JLabel();
|
||||
toolBar = new JToolBar();
|
||||
saveButton = new JButton();
|
||||
sourceCodeButton = new JButton();
|
||||
filterComboBox = new JComboBox<>();
|
||||
themesScrollPane = new JScrollPane();
|
||||
themesList = new JList<>();
|
||||
|
||||
@@ -419,6 +447,17 @@ public class IJThemesPanel
|
||||
}
|
||||
add(toolBar, "cell 0 0,alignx right,growx 0");
|
||||
|
||||
//---- filterComboBox ----
|
||||
filterComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
|
||||
"all",
|
||||
"light",
|
||||
"dark"
|
||||
}));
|
||||
filterComboBox.putClientProperty("JComponent.minimumWidth", 0);
|
||||
filterComboBox.setFocusable(false);
|
||||
filterComboBox.addActionListener(e -> filterChanged());
|
||||
add(filterComboBox, "cell 0 0,alignx right,growx 0");
|
||||
|
||||
//======== themesScrollPane ========
|
||||
{
|
||||
|
||||
@@ -435,6 +474,7 @@ public class IJThemesPanel
|
||||
private JToolBar toolBar;
|
||||
private JButton saveButton;
|
||||
private JButton sourceCodeButton;
|
||||
private JComboBox<String> filterComboBox;
|
||||
private JScrollPane themesScrollPane;
|
||||
private JList<IJThemeInfo> themesList;
|
||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
JFDML JFormDesigner: "7.0.0.0.194" Java: "11.0.2" encoding: "UTF-8"
|
||||
JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
@@ -34,6 +34,20 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 0,alignx right,growx 0"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JComboBox" ) {
|
||||
name: "filterComboBox"
|
||||
"model": new javax.swing.DefaultComboBoxModel {
|
||||
selectedItem: "all"
|
||||
addElement( "all" )
|
||||
addElement( "light" )
|
||||
addElement( "dark" )
|
||||
}
|
||||
"$client.JComponent.minimumWidth": 0
|
||||
"focusable": false
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "filterChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 0,alignx right,growx 0"
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
|
||||
name: "themesScrollPane"
|
||||
add( new FormComponent( "javax.swing.JList" ) {
|
||||
|
||||
Reference in New Issue
Block a user