ColorChooser implementation

This commit is contained in:
Karl Tauber
2019-09-07 11:12:41 +02:00
parent 41c4df87ba
commit 90f020cae7
4 changed files with 156 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
/*
* 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.ui;
import java.awt.Dimension;
import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicColorChooserUI;
import com.formdev.flatlaf.util.UIScale;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JColorChooser}.
*
* @uiDefault ColorChooser.showPreviewPanelText boolean
* @uiDefault ColorChooser.swatchesSwatchSize Dimension
* @uiDefault ColorChooser.swatchesRecentSwatchSize Dimension
*
* @author Karl Tauber
*/
public class FlatColorChooserUI
extends BasicColorChooserUI
{
public static ComponentUI createUI( JComponent c ) {
return new FlatColorChooserUI();
}
@Override
public void installUI( JComponent c ) {
if( UIScale.getUserScaleFactor() != 1f ) {
// temporary scale swatch sizes
Dimension swatchSize = UIManager.getDimension( "ColorChooser.swatchesSwatchSize" );
Dimension swatchSize2 = UIManager.getDimension( "ColorChooser.swatchesRecentSwatchSize" );
UIManager.put( "ColorChooser.swatchesSwatchSize", UIScale.scale( swatchSize ) );
UIManager.put( "ColorChooser.swatchesRecentSwatchSize", UIScale.scale( swatchSize2 ) );
super.installUI( c );
UIManager.put( "ColorChooser.swatchesSwatchSize", null );
UIManager.put( "ColorChooser.swatchesRecentSwatchSize", null );
} else
super.installUI( c );
}
}

View File

@@ -19,6 +19,7 @@
ButtonUI=com.formdev.flatlaf.ui.FlatButtonUI
CheckBoxUI=com.formdev.flatlaf.ui.FlatCheckBoxUI
CheckBoxMenuItemUI=com.formdev.flatlaf.ui.FlatCheckBoxMenuItemUI
ColorChooserUI=com.formdev.flatlaf.ui.FlatColorChooserUI
ComboBoxUI=com.formdev.flatlaf.ui.FlatComboBoxUI
EditorPaneUI=com.formdev.flatlaf.ui.FlatEditorPaneUI
FormattedTextFieldUI=com.formdev.flatlaf.ui.FlatFormattedTextFieldUI
@@ -78,6 +79,12 @@ CheckBoxMenuItem.checkIcon=com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon
CheckBoxMenuItem.arrowIcon=com.formdev.flatlaf.icons.FlatMenuItemArrowIcon
#---- ColorChooser ----
ColorChooser.swatchesSwatchSize=16,16
ColorChooser.swatchesRecentSwatchSize=16,16
#---- ComboBox ----
ComboBox.border=com.formdev.flatlaf.ui.FlatRoundBorder

View File

@@ -0,0 +1,60 @@
/*
* 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;
import javax.swing.*;
import net.miginfocom.swing.*;
/**
* @author Karl Tauber
*/
public class FlatChooserTest
extends JPanel
{
public static void main( String[] args ) {
FlatTestFrame frame = FlatTestFrame.create( args, "FlatChooserTest" );
frame.showFrame( new FlatChooserTest() );
}
FlatChooserTest() {
initComponents();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JLabel colorChooserLabel = new JLabel();
JColorChooser colorChooser1 = new JColorChooser();
//======== this ========
setLayout(new MigLayout(
"insets 0,hidemode 3,gap 5 5,ltr",
// columns
"[]" +
"[]",
// rows
"[top]"));
//---- colorChooserLabel ----
colorChooserLabel.setText("JColorChooser:");
add(colorChooserLabel, "cell 0 0");
add(colorChooser1, "cell 1 0");
// JFormDesigner - End of component initialization //GEN-END:initComponents
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
// JFormDesigner - End of variables declaration //GEN-END:variables
}

View File

@@ -0,0 +1,31 @@
JFDML JFormDesigner: "7.0.0.0.194" Java: "11.0.2" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
root: new FormRoot {
auxiliary() {
"JavaCodeGenerator.defaultVariableLocal": true
}
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets 0,hidemode 3,gap 5 5,ltr"
"$columnConstraints": "[][]"
"$rowConstraints": "[top]"
} ) {
name: "this"
add( new FormComponent( "javax.swing.JLabel" ) {
name: "colorChooserLabel"
"text": "JColorChooser:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0"
} )
add( new FormComponent( "javax.swing.JColorChooser" ) {
name: "colorChooser1"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 0"
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 790, 715 )
} )
}
}