From ac8225d8fb9a8c814a1d738640efb02aa7f4da79 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 7 Jul 2020 16:17:31 +0200 Subject: [PATCH] Theme Editor: support saving file; added inspector --- flatlaf-theme-editor/build.gradle.kts | 1 + .../flatlaf/themeeditor/FlatThemeEditorPane.java | 10 +++++++++- .../flatlaf/themeeditor/FlatThemeFileEditor.java | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/flatlaf-theme-editor/build.gradle.kts b/flatlaf-theme-editor/build.gradle.kts index 05f1ccc3..de5df384 100644 --- a/flatlaf-theme-editor/build.gradle.kts +++ b/flatlaf-theme-editor/build.gradle.kts @@ -20,6 +20,7 @@ plugins { dependencies { implementation( project( ":flatlaf-core" ) ) + implementation( project( ":flatlaf-extras" ) ) implementation( "com.fifesoft:rsyntaxtextarea:3.1.1" ) } diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java index d5e80354..485e53c5 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java @@ -94,7 +94,15 @@ class FlatThemeEditorPane return font.deriveFont( (float) newFontSize ); } - public void load( FileLocation loc ) throws IOException { + void load( FileLocation loc ) throws IOException { textArea.load( loc, StandardCharsets.ISO_8859_1 ); } + + void save() { + try { + textArea.save(); + } catch( IOException ex ) { + ex.printStackTrace(); // TODO + } + } } diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java index 18e453aa..65609b82 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java @@ -17,11 +17,13 @@ package com.formdev.flatlaf.themeeditor; import java.awt.*; +import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; import javax.swing.*; import org.fife.ui.rsyntaxtextarea.FileLocation; import com.formdev.flatlaf.FlatLightLaf; +import com.formdev.flatlaf.extras.FlatInspector; import com.formdev.flatlaf.util.UIScale; /** @@ -39,6 +41,7 @@ public class FlatThemeFileEditor SwingUtilities.invokeLater( () -> { FlatLightLaf.install(); + FlatInspector.install( "ctrl alt shift X" ); FlatThemeFileEditor frame = new FlatThemeFileEditor(); @@ -48,6 +51,12 @@ public class FlatThemeFileEditor ex.printStackTrace(); } + int menuShortcutKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); + ((JComponent)frame.getContentPane()).registerKeyboardAction( + e -> frame.themeEditorArea.save(), + KeyStroke.getKeyStroke( KeyEvent.VK_S, menuShortcutKeyMask ), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setSize( Math.min( UIScale.scale( 800 ), screenSize.width ), screenSize.height - UIScale.scale( 100 ) );