diff --git a/flatlaf-theme-editor/build.gradle.kts b/flatlaf-theme-editor/build.gradle.kts new file mode 100644 index 00000000..e40fb7bc --- /dev/null +++ b/flatlaf-theme-editor/build.gradle.kts @@ -0,0 +1,25 @@ +/* + * Copyright 2020 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 + * + * https://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. + */ + +plugins { + `java-library` +} + +dependencies { + implementation( project( ":flatlaf-core" ) ) + + implementation( "com.fifesoft:rsyntaxtextarea:3.1.0" ) +} diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatSyntaxTextArea.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatSyntaxTextArea.java new file mode 100644 index 00000000..755edbd5 --- /dev/null +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatSyntaxTextArea.java @@ -0,0 +1,31 @@ +/* + * Copyright 2020 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 + * + * https://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.themeeditor; + +import org.fife.ui.rsyntaxtextarea.TextEditorPane; + +/** + * A text area that supports editing FlatLaf themes. + * + * @author Karl Tauber + */ +class FlatSyntaxTextArea + extends TextEditorPane +{ + FlatSyntaxTextArea() { + } +} 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 new file mode 100644 index 00000000..8aa40543 --- /dev/null +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java @@ -0,0 +1,66 @@ +/* + * Copyright 2020 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 + * + * https://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.themeeditor; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import javax.swing.JPanel; +import org.fife.ui.rsyntaxtextarea.FileLocation; +import org.fife.ui.rtextarea.RTextScrollPane; +import com.formdev.flatlaf.util.UIScale; + +/** + * A pane that supports editing FlatLaf themes. + * + * @author Karl Tauber + */ +class FlatThemeEditorPane + extends JPanel +{ + private final RTextScrollPane scrollPane; + private final FlatSyntaxTextArea textArea; + + FlatThemeEditorPane() { + super( new BorderLayout() ); + + // create text area + textArea = new FlatSyntaxTextArea(); + + // create scroll pane + scrollPane = new RTextScrollPane( textArea ); + scrollPane.setLineNumbersEnabled( true ); + + // scale fonts + if( UIScale.getUserScaleFactor() != 1 ) { + textArea.setFont( scaleFont( textArea.getFont() ) ); + scrollPane.getGutter().setLineNumberFont( scaleFont( scrollPane.getGutter().getLineNumberFont() ) ); + } + + add( scrollPane, BorderLayout.CENTER ); + } + + private static Font scaleFont( Font font ) { + int newFontSize = UIScale.scale( font.getSize() ); + return font.deriveFont( (float) newFontSize ); + } + + public void load( FileLocation loc ) throws IOException { + textArea.load( loc, StandardCharsets.ISO_8859_1 ); + } +} 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 new file mode 100644 index 00000000..71f1e2b7 --- /dev/null +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java @@ -0,0 +1,87 @@ +/* + * Copyright 2020 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 + * + * https://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.themeeditor; + +import java.awt.*; +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.util.UIScale; + +/** + * TODO + * + * @author Karl Tauber + */ +public class FlatThemeFileEditor + extends JFrame +{ + public static void main( String[] args ) { + File file = new File( args.length > 0 + ? args[0] + : "../flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties" ); // TODO + + SwingUtilities.invokeLater( () -> { + FlatLightLaf.install(); + + FlatThemeFileEditor frame = new FlatThemeFileEditor(); + + try { + frame.themeEditorArea.load( FileLocation.create( file ) ); + } catch( IOException ex ) { + ex.printStackTrace(); + } + + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + frame.setSize( Math.min( UIScale.scale( 800 ), screenSize.width ), + screenSize.height - UIScale.scale( 100 ) ); + frame.setLocationRelativeTo( null ); + frame.setVisible( true ); + } ); + } + + public FlatThemeFileEditor() { + initComponents(); + } + + private void initComponents() { + // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents + dialogPane = new JPanel(); + themeEditorArea = new FlatThemeEditorPane(); + + //======== this ======== + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + setTitle("FlatLaf Theme Editor"); + Container contentPane = getContentPane(); + contentPane.setLayout(new BorderLayout()); + + //======== dialogPane ======== + { + dialogPane.setLayout(new BorderLayout()); + dialogPane.add(themeEditorArea, BorderLayout.CENTER); + } + contentPane.add(dialogPane, BorderLayout.CENTER); + // JFormDesigner - End of component initialization //GEN-END:initComponents + } + + // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables + private JPanel dialogPane; + private FlatThemeEditorPane themeEditorArea; + // JFormDesigner - End of variables declaration //GEN-END:variables +} diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.jfd b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.jfd new file mode 100644 index 00000000..be2a9cdd --- /dev/null +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.jfd @@ -0,0 +1,27 @@ +JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.1" encoding: "UTF-8" + +new FormModel { + contentType: "form/swing" + root: new FormRoot { + add( new FormWindow( "javax.swing.JFrame", new FormLayoutManager( class java.awt.BorderLayout ) ) { + name: "this" + "$locationPolicy": 2 + "$sizePolicy": 2 + "defaultCloseOperation": 2 + "title": "FlatLaf Theme Editor" + add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) { + name: "dialogPane" + add( new FormComponent( "com.formdev.flatlaf.themeeditor.FlatThemeEditorPane" ) { + name: "themeEditorArea" + }, new FormLayoutConstraints( class java.lang.String ) { + "value": "Center" + } ) + }, new FormLayoutConstraints( class java.lang.String ) { + "value": "Center" + } ) + }, new FormLayoutConstraints( null ) { + "location": new java.awt.Point( 0, 0 ) + "size": new java.awt.Dimension( 535, 300 ) + } ) + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 1dfc5794..c325a9d7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,6 +22,7 @@ include( "flatlaf-swingx" ) include( "flatlaf-jide-oss" ) include( "flatlaf-demo" ) include( "flatlaf-testing" ) +include( "flatlaf-theme-editor" ) pluginManagement { plugins {