IntelliJ Themes:

- added themes list to demo (and testing) apps
- added some popular open-source IntelliJ themes to demo
  (downloaded latest .theme.json from source repos;
  see themes.properties for source repo URLs)
This commit is contained in:
Karl Tauber
2019-11-12 19:23:20 +01:00
parent 3092fced3c
commit 0ebd43bc5f
47 changed files with 6410 additions and 17 deletions

View File

@@ -71,7 +71,6 @@ class ControlBar
}
lookAndFeelComboBox.setModel( lafModel );
lookAndFeelComboBox.selectedLookAndFeel( UIManager.getLookAndFeel() );
UIManager.addPropertyChangeListener( e -> {
if( "lookAndFeel".equals( e.getPropertyName() ) ) {

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.demo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.formdev.flatlaf.demo.intellijthemes.*;
import net.miginfocom.swing.*;
/**
@@ -87,6 +88,7 @@ class DemoFrame
TabsPanel tabsPanel = new TabsPanel();
OptionPanePanel optionPanePanel = new OptionPanePanel();
controlBar = new ControlBar();
IJThemesPanel themesPanel = new IJThemesPanel();
//======== this ========
setTitle("FlatLaf Demo");
@@ -262,6 +264,7 @@ class DemoFrame
}
contentPane.add(contentPanel, BorderLayout.CENTER);
contentPane.add(controlBar, BorderLayout.SOUTH);
contentPane.add(themesPanel, BorderLayout.EAST);
//---- buttonGroup1 ----
ButtonGroup buttonGroup1 = new ButtonGroup();

View File

@@ -107,6 +107,11 @@ new FormModel {
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "South"
} )
add( new FormComponent( "com.formdev.flatlaf.demo.intellijthemes.IJThemesPanel" ) {
name: "themesPanel"
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "East"
} )
menuBar: new FormContainer( "javax.swing.JMenuBar", new FormLayoutManager( class javax.swing.JMenuBar ) ) {
name: "menuBar1"
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
@@ -220,7 +225,7 @@ new FormModel {
}
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 800, 710 )
"size": new java.awt.Dimension( 935, 710 )
} )
add( new FormNonVisual( "javax.swing.ButtonGroup" ) {
name: "buttonGroup1"

View File

@@ -17,10 +17,11 @@
package com.formdev.flatlaf.demo;
import java.awt.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.LookAndFeel;
import javax.swing.MutableComboBoxModel;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
@@ -32,6 +33,8 @@ import javax.swing.plaf.basic.BasicComboBoxRenderer;
public class LookAndFeelsComboBox
extends JComboBox<UIManager.LookAndFeelInfo>
{
private final PropertyChangeListener lafListener = this::lafChanged;
@SuppressWarnings( "unchecked" )
public LookAndFeelsComboBox() {
setRenderer( new BasicComboBoxRenderer() {
@@ -40,7 +43,9 @@ public class LookAndFeelsComboBox
public Component getListCellRendererComponent( JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus )
{
value = ((LookAndFeelInfo)value).getName();
value = (value != null)
? ((LookAndFeelInfo)value).getName()
: UIManager.getLookAndFeel().getName();
return super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus );
}
} );
@@ -56,19 +61,11 @@ public class LookAndFeelsComboBox
}
public void setSelectedLookAndFeel( String className ) {
int index = getIndexOfLookAndFeel( className );
if( index >= 0 )
setSelectedIndex( index );
setSelectedIndex( getIndexOfLookAndFeel( className ) );
}
public void selectedLookAndFeel( LookAndFeel lookAndFeel ) {
String className = lookAndFeel.getClass().getName();
int index = getIndexOfLookAndFeel( className );
if( index < 0 ) {
addLookAndFeel( lookAndFeel.getName(), className );
index = getItemCount() - 1;
}
setSelectedIndex( index );
public void selectedCurrentLookAndFeel() {
setSelectedLookAndFeel( UIManager.getLookAndFeel().getClass().getName() );
}
public void removeLookAndFeel( String className ) {
@@ -90,4 +87,24 @@ public class LookAndFeelsComboBox
private MutableComboBoxModel<LookAndFeelInfo> getMutableModel() {
return (MutableComboBoxModel<LookAndFeelInfo>) getModel();
}
@Override
public void addNotify() {
super.addNotify();
selectedCurrentLookAndFeel();
UIManager.addPropertyChangeListener( lafListener );
}
@Override
public void removeNotify() {
super.removeNotify();
UIManager.removePropertyChangeListener( lafListener );
}
void lafChanged( PropertyChangeEvent e ) {
if( "lookAndFeel".equals( e.getPropertyName() ) )
selectedCurrentLookAndFeel();
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2019 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.demo.intellijthemes;
/**
* @author Karl Tauber
*/
class IJThemeInfo
{
String name;
String resourceName;
String sourceCodeUrl;
@Override
public String toString() {
return name;
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2019 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.demo.intellijthemes;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import com.formdev.flatlaf.util.StringUtils;
/**
* @author Karl Tauber
*/
class IJThemesManager
{
final List<IJThemeInfo> bundledThemes = new ArrayList<>();
void loadBundledThemes() {
// load themes.properties
Properties properties = new Properties();
try( InputStream in = getClass().getResourceAsStream( "themes.properties" ) ) {
if( in != null )
properties.load( in );
} catch( IOException ex ) {
ex.printStackTrace();
}
// add info about bundled themes
for( Map.Entry<Object, Object> e : properties.entrySet() ) {
String resourceName = (String) e.getKey();
List<String> strs = StringUtils.split( (String) e.getValue(), ',' );
IJThemeInfo themeInfo = new IJThemeInfo();
themeInfo.name = strs.get( 0 );
themeInfo.resourceName = resourceName;
themeInfo.sourceCodeUrl = strs.get( 1 );
bundledThemes.add( themeInfo );
}
}
}

View File

@@ -0,0 +1,145 @@
/*
* Copyright 2019 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.demo.intellijthemes;
import java.awt.EventQueue;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.IntelliJTheme;
import net.miginfocom.swing.*;
/**
* @author Karl Tauber
*/
public class IJThemesPanel
extends JPanel
{
private final IJThemesManager themesManager = new IJThemesManager();
private final PropertyChangeListener lafListener = this::lafChanged;
public IJThemesPanel() {
initComponents();
// load theme infos
themesManager.loadBundledThemes();
// sort themes by name
List<IJThemeInfo> themes = new ArrayList<>();
themes.addAll( themesManager.bundledThemes );
themes.sort( (t1, t2) -> t1.name.compareToIgnoreCase( t2.name ) );
// fill themes list
themesList.setModel( new AbstractListModel<IJThemeInfo>() {
@Override
public int getSize() {
return themes.size();
}
@Override
public IJThemeInfo getElementAt( int index ) {
return themes.get( index );
}
} );
}
private void themesListValueChanged( ListSelectionEvent e ) {
if( e.getValueIsAdjusting() )
return;
EventQueue.invokeLater( () -> {
setTheme( themesList.getSelectedValue() );
} );
}
private void setTheme( IJThemeInfo themeInfo ) {
if( themeInfo == null )
return;
// change look and feel
IntelliJTheme.install( getClass().getResourceAsStream( themeInfo.resourceName ) );
// update all components
FlatLaf.updateUI();
}
@Override
public void addNotify() {
super.addNotify();
selectedCurrentLookAndFeel();
UIManager.addPropertyChangeListener( lafListener );
}
@Override
public void removeNotify() {
super.removeNotify();
UIManager.removePropertyChangeListener( lafListener );
}
void lafChanged( PropertyChangeEvent e ) {
if( "lookAndFeel".equals( e.getPropertyName() ) )
selectedCurrentLookAndFeel();
}
private void selectedCurrentLookAndFeel() {
LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
if( !(lookAndFeel instanceof IntelliJTheme.ThemeLaf) )
themesList.clearSelection();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JLabel themesLabel = new JLabel();
themesScrollPane = new JScrollPane();
themesList = new JList<>();
//======== this ========
setLayout(new MigLayout(
"insets dialog,hidemode 3",
// columns
"[grow,fill]",
// rows
"[]" +
"[grow,fill]"));
//---- themesLabel ----
themesLabel.setText("Themes:");
add(themesLabel, "cell 0 0");
//======== themesScrollPane ========
{
//---- themesList ----
themesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
themesList.addListSelectionListener(e -> themesListValueChanged(e));
themesScrollPane.setViewportView(themesList);
}
add(themesScrollPane, "cell 0 1");
// JFormDesigner - End of component initialization //GEN-END:initComponents
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private JScrollPane themesScrollPane;
private JList<IJThemeInfo> themesList;
// JFormDesigner - End of variables declaration //GEN-END:variables
}

View File

@@ -0,0 +1,39 @@
JFDML JFormDesigner: "7.0.0.0.194" Java: "11.0.2" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
root: new FormRoot {
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets dialog,hidemode 3"
"$columnConstraints": "[grow,fill]"
"$rowConstraints": "[][grow,fill]"
} ) {
name: "this"
add( new FormComponent( "javax.swing.JLabel" ) {
name: "themesLabel"
"text": "Themes:"
auxiliary() {
"JavaCodeGenerator.variableLocal": true
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0"
} )
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
name: "themesScrollPane"
add( new FormComponent( "javax.swing.JList" ) {
name: "themesList"
"selectionMode": 0
auxiliary() {
"JavaCodeGenerator.typeParameters": "IJThemeInfo"
}
addEvent( new FormEvent( "javax.swing.event.ListSelectionListener", "valueChanged", "themesListValueChanged", true ) )
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 1"
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 400, 300 )
} )
}
}