mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
UIDefaultsDump: support dumping IntelliJ themes (disabled)
can be used to check changes to UI defaults when modifying the IntelliJ theme converter
This commit is contained in:
@@ -25,20 +25,21 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import com.formdev.flatlaf.json.Json;
|
import com.formdev.flatlaf.json.Json;
|
||||||
import com.formdev.flatlaf.util.StringUtils;
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
class IJThemesManager
|
public class IJThemesManager
|
||||||
{
|
{
|
||||||
final List<IJThemeInfo> bundledThemes = new ArrayList<>();
|
final List<IJThemeInfo> bundledThemes = new ArrayList<>();
|
||||||
final List<IJThemeInfo> moreThemes = new ArrayList<>();
|
final List<IJThemeInfo> moreThemes = new ArrayList<>();
|
||||||
private final Map<File,Long> lastModifiedMap = new HashMap<>();
|
private final Map<File,Long> lastModifiedMap = new HashMap<>();
|
||||||
|
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
void loadBundledThemes() {
|
public void loadBundledThemes() {
|
||||||
bundledThemes.clear();
|
bundledThemes.clear();
|
||||||
|
|
||||||
// load themes.json
|
// load themes.json
|
||||||
@@ -95,4 +96,10 @@ class IJThemesManager
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getBundledResourceNames() {
|
||||||
|
return bundledThemes.stream()
|
||||||
|
.map( themeInfo -> themeInfo.resourceName )
|
||||||
|
.collect( Collectors.toList() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ import javax.swing.plaf.BorderUIResource;
|
|||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicLookAndFeel;
|
import javax.swing.plaf.basic.BasicLookAndFeel;
|
||||||
import com.formdev.flatlaf.*;
|
import com.formdev.flatlaf.*;
|
||||||
|
import com.formdev.flatlaf.demo.intellijthemes.IJThemesManager;
|
||||||
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,6 +99,23 @@ public class UIDefaultsDump
|
|||||||
// // TODO Auto-generated catch block
|
// // TODO Auto-generated catch block
|
||||||
// ex.printStackTrace();
|
// ex.printStackTrace();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// dumpIntelliJThemes( dir );
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( "unused" )
|
||||||
|
private static void dumpIntelliJThemes( File dir ) {
|
||||||
|
dir = new File( dir, "intellijthemes" );
|
||||||
|
|
||||||
|
IJThemesManager themesManager = new IJThemesManager();
|
||||||
|
themesManager.loadBundledThemes();
|
||||||
|
|
||||||
|
for( String resourceName : themesManager.getBundledResourceNames() ) {
|
||||||
|
IntelliJTheme.install( UIDefaultsDump.class.getResourceAsStream(
|
||||||
|
"/com/formdev/flatlaf/demo/intellijthemes/" + resourceName ) );
|
||||||
|
dump( dir, StringUtils.removeTrailing( resourceName, ".theme.json" ) );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void dump( String lookAndFeelClassName, File dir ) {
|
private static void dump( String lookAndFeelClassName, File dir ) {
|
||||||
@@ -107,28 +126,37 @@ public class UIDefaultsDump
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dump( dir, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void dump( File dir, String name ) {
|
||||||
LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
|
LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
|
||||||
|
|
||||||
dump( dir, "", lookAndFeel, key -> !key.contains( "InputMap" ) );
|
dump( dir, name, "", lookAndFeel, key -> !key.contains( "InputMap" ) );
|
||||||
if( lookAndFeel.getClass() != FlatLightLaf.class )
|
if( lookAndFeel.getClass() != FlatLightLaf.class )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dump( dir, "_InputMap", lookAndFeel, key -> key.contains( "InputMap" ) );
|
dump( dir, name, "_InputMap", lookAndFeel, key -> key.contains( "InputMap" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void dump( File dir, String nameSuffix, LookAndFeel lookAndFeel, Predicate<String> keyFilter ) {
|
private static void dump( File dir, String name, String nameSuffix,
|
||||||
|
LookAndFeel lookAndFeel, Predicate<String> keyFilter )
|
||||||
|
{
|
||||||
// dump to string
|
// dump to string
|
||||||
StringWriter stringWriter = new StringWriter( 100000 );
|
StringWriter stringWriter = new StringWriter( 100000 );
|
||||||
new UIDefaultsDump( lookAndFeel ).dump( new PrintWriter( stringWriter ), keyFilter );
|
new UIDefaultsDump( lookAndFeel ).dump( new PrintWriter( stringWriter ), keyFilter );
|
||||||
|
|
||||||
Class<?> lookAndFeelClass = lookAndFeel instanceof MyBasicLookAndFeel
|
if( name == null ) {
|
||||||
? BasicLookAndFeel.class
|
name = lookAndFeel instanceof MyBasicLookAndFeel
|
||||||
: lookAndFeel.getClass();
|
? BasicLookAndFeel.class.getSimpleName()
|
||||||
|
: lookAndFeel.getClass().getSimpleName();
|
||||||
|
}
|
||||||
String osSuffix = (SystemInfo.IS_MAC && lookAndFeel instanceof FlatLaf) ? "-mac" : "";
|
String osSuffix = (SystemInfo.IS_MAC && lookAndFeel instanceof FlatLaf) ? "-mac" : "";
|
||||||
File file = new File( dir, lookAndFeelClass.getSimpleName() + nameSuffix + "_"
|
File file = new File( dir, name + nameSuffix + "_"
|
||||||
+ System.getProperty( "java.version" ) + osSuffix + ".txt" );
|
+ System.getProperty( "java.version" ) + osSuffix + ".txt" );
|
||||||
|
|
||||||
// write to file
|
// write to file
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
try( FileWriter fileWriter = new FileWriter( file ) ) {
|
try( FileWriter fileWriter = new FileWriter( file ) ) {
|
||||||
fileWriter.write( stringWriter.toString().replace( "\r", "" ) );
|
fileWriter.write( stringWriter.toString().replace( "\r", "" ) );
|
||||||
} catch( IOException ex ) {
|
} catch( IOException ex ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user