Merge PR #341: Styling individual components

This commit is contained in:
Karl Tauber
2021-09-15 20:00:06 +02:00
120 changed files with 7300 additions and 561 deletions

View File

@@ -27,7 +27,7 @@ import javax.swing.JButton;
*/
public class FlatButton
extends JButton
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
// NOTE: enum names must be equal to allowed strings
public enum ButtonType { none, square, roundRect, tab, help, toolBarButton, borderless }

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JCheckBox;
/**
* Subclass of {@link JCheckBox} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatCheckBox
extends JCheckBox
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JCheckBoxMenuItem;
/**
* Subclass of {@link JCheckBoxMenuItem} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatCheckBoxMenuItem
extends JCheckBoxMenuItem
implements FlatStyleableComponent
{
}

View File

@@ -27,7 +27,7 @@ import javax.swing.JComboBox;
*/
public class FlatComboBox<E>
extends JComboBox<E>
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns the placeholder text that is only painted if the editable combo box is empty.

View File

@@ -26,7 +26,7 @@ import javax.swing.JEditorPane;
*/
public class FlatEditorPane
extends JEditorPane
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns minimum width of a component.

View File

@@ -29,7 +29,7 @@ import com.formdev.flatlaf.extras.components.FlatTextField.SelectAllOnFocusPolic
*/
public class FlatFormattedTextField
extends JFormattedTextField
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns the placeholder text that is only painted if the text field is empty.

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JInternalFrame;
/**
* Subclass of {@link JInternalFrame} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatInternalFrame
extends JInternalFrame
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JLabel;
/**
* Subclass of {@link JLabel} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatLabel
extends JLabel
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JList;
/**
* Subclass of {@link JList} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatList<E>
extends JList<E>
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JMenu;
/**
* Subclass of {@link JMenu} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatMenu
extends JMenu
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JMenuBar;
/**
* Subclass of {@link JMenuBar} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatMenuBar
extends JMenuBar
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JMenuItem;
/**
* Subclass of {@link JMenuItem} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatMenuItem
extends JMenuItem
implements FlatStyleableComponent
{
}

View File

@@ -29,7 +29,7 @@ import com.formdev.flatlaf.extras.components.FlatTextField.SelectAllOnFocusPolic
*/
public class FlatPasswordField
extends JPasswordField
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns the placeholder text that is only painted if the text field is empty.

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JPopupMenu;
/**
* Subclass of {@link JPopupMenu} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatPopupMenu
extends JPopupMenu
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JPopupMenu;
/**
* Subclass of {@link JPopupMenu.Separator} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatPopupMenuSeparator
extends JPopupMenu.Separator
implements FlatStyleableComponent
{
}

View File

@@ -26,7 +26,7 @@ import javax.swing.JProgressBar;
*/
public class FlatProgressBar
extends JProgressBar
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns whether the progress bar has always the larger height even if no string is painted.

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JRadioButton;
/**
* Subclass of {@link JRadioButton} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatRadioButton
extends JRadioButton
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JRadioButtonMenuItem;
/**
* Subclass of {@link JRadioButtonMenuItem} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatRadioButtonMenuItem
extends JRadioButtonMenuItem
implements FlatStyleableComponent
{
}

View File

@@ -26,7 +26,7 @@ import javax.swing.JScrollBar;
*/
public class FlatScrollBar
extends JScrollBar
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns whether the decrease/increase arrow buttons of a scrollbar are shown.

View File

@@ -27,7 +27,7 @@ import javax.swing.JScrollPane;
*/
public class FlatScrollPane
extends JScrollPane
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns whether the decrease/increase arrow buttons of a scrollbar are shown.

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JSeparator;
/**
* Subclass of {@link JSeparator} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatSeparator
extends JSeparator
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JSlider;
/**
* Subclass of {@link JSlider} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatSlider
extends JSlider
implements FlatStyleableComponent
{
}

View File

@@ -27,7 +27,7 @@ import javax.swing.JSpinner;
*/
public class FlatSpinner
extends JSpinner
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns minimum width of a component.

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JSplitPane;
/**
* Subclass of {@link JSplitPane} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatSplitPane
extends JSplitPane
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright 2021 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.extras.components;
import java.util.Map;
import javax.swing.JComponent;
import com.formdev.flatlaf.FlatClientProperties;
/**
* Interface for all styleable FlatLaf components.
* <p>
* If you already have custom subclasses of Swing components, you can add this interface
* to your components to add styling getter and setter methods to them.
*
* @author Karl Tauber
* @since 2
*/
public interface FlatStyleableComponent
{
/**
* Returns the style of a component as String in CSS syntax ("key1: value1; key2: value2; ...")
* or {@code null} if no style has been assigned.
*/
default String getStyle() {
return (String) getClientProperty( FlatClientProperties.STYLE );
}
/**
* Specifies the style of a component as String in CSS syntax ("key1: value1; key2: value2; ...").
* <p>
* The keys are the same as used in UI defaults, but without component type prefix.
* E.g. for UI default {@code Slider.thumbSize} use key {@code thumbSize}.
* <p>
* The syntax of the CSS values is the same as used in FlatLaf properties files
* (<a href="https://www.formdev.com/flatlaf/properties-files/">https://www.formdev.com/flatlaf/properties-files/</a>),
* but some features are not supported (e.g. variables).
*/
default void setStyle( String style ) {
putClientProperty( FlatClientProperties.STYLE, style );
}
/**
* Returns the style of a component as {@link java.util.Map}&lt;String, Object&gt;
* or {@code null} if no style has been assigned.
*/
@SuppressWarnings( "unchecked" )
default Map<String, Object> getStyleMap() {
return (Map<String, Object>) getClientProperty( FlatClientProperties.STYLE );
}
/**
* Specifies the style of a component as {@link java.util.Map}&lt;String, Object&gt; with binary values.
* <p>
* The keys are the same as used in UI defaults, but without component type prefix.
* E.g. for UI default {@code Slider.thumbSize} use key {@code thumbSize}.
* <p>
* The values are not parsed from a string. They must be binary.
*/
default void setStyleMap( Map<String, Object> styleMap ) {
putClientProperty( FlatClientProperties.STYLE, styleMap );
}
/**
* Overrides {@link JComponent#getClientProperty(Object)}.
*/
Object getClientProperty( Object key );
/**
* Overrides {@link JComponent#putClientProperty(Object, Object)}.
*/
void putClientProperty( Object key, Object value );
}

View File

@@ -31,7 +31,7 @@ import javax.swing.SwingConstants;
*/
public class FlatTabbedPane
extends JTabbedPane
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns whether separators are shown between tabs.

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JTable;
/**
* Subclass of {@link JTable} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatTable
extends JTable
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.table.JTableHeader;
/**
* Subclass of {@link JTableHeader} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatTableHeader
extends JTableHeader
implements FlatStyleableComponent
{
}

View File

@@ -26,7 +26,7 @@ import javax.swing.JTextArea;
*/
public class FlatTextArea
extends JTextArea
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns minimum width of a component.

View File

@@ -28,7 +28,7 @@ import javax.swing.JTextField;
*/
public class FlatTextField
extends JTextField
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns the placeholder text that is only painted if the text field is empty.

View File

@@ -26,7 +26,7 @@ import javax.swing.JTextPane;
*/
public class FlatTextPane
extends JTextPane
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns minimum width of a component.

View File

@@ -28,7 +28,7 @@ import com.formdev.flatlaf.extras.components.FlatButton.ButtonType;
*/
public class FlatToggleButton
extends JToggleButton
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns type of a button.

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JToolBar;
/**
* Subclass of {@link JToolBar} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatToolBar
extends JToolBar
implements FlatStyleableComponent
{
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.extras.components;
import javax.swing.JToolBar;
/**
* Subclass of {@link JToolBar.Separator} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
* @since 2
*/
public class FlatToolBarSeparator
extends JToolBar.Separator
implements FlatStyleableComponent
{
}

View File

@@ -22,10 +22,11 @@ import javax.swing.JTree;
/**
* Subclass of {@link JTree} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
*/
public class FlatTree
extends JTree
implements FlatComponentExtension
implements FlatComponentExtension, FlatStyleableComponent
{
/**
* Returns if the tree shows a wide selection