Theme Editor: initial commit

This commit is contained in:
Karl Tauber
2020-04-04 14:13:20 +02:00
parent 152f235ca1
commit 204da2175b
6 changed files with 237 additions and 0 deletions

View File

@@ -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" )
}

View File

@@ -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() {
}
}

View File

@@ -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 );
}
}

View File

@@ -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
}

View File

@@ -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 )
} )
}
}

View File

@@ -22,6 +22,7 @@ include( "flatlaf-swingx" )
include( "flatlaf-jide-oss" )
include( "flatlaf-demo" )
include( "flatlaf-testing" )
include( "flatlaf-theme-editor" )
pluginManagement {
plugins {