mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Extras: added extension interfaces and classes for JComboBox, JFormattedTextField, JPasswordField, JScrollBar, JScrollPane and JTextField (issue #117)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.extras.components;
|
||||
|
||||
import javax.swing.JComboBox;
|
||||
import com.formdev.flatlaf.extras.components.extensions.FlatComboBoxExtension;
|
||||
|
||||
/**
|
||||
* Subclass of {@link JComboBox} that implements {@link FlatComboBoxExtension}
|
||||
* to provide easy access to FlatLaf specific client properties.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatComboBox<E>
|
||||
extends JComboBox<E>
|
||||
implements FlatComboBoxExtension
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.extras.components;
|
||||
|
||||
import javax.swing.JFormattedTextField;
|
||||
import com.formdev.flatlaf.extras.components.extensions.FlatTextFieldExtension;
|
||||
|
||||
/**
|
||||
* Subclass of {@link JFormattedTextField} that implements {@link FlatTextFieldExtension}
|
||||
* to provide easy access to FlatLaf specific client properties.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatFormattedTextField
|
||||
extends JFormattedTextField
|
||||
implements FlatTextFieldExtension
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.extras.components;
|
||||
|
||||
import javax.swing.JPasswordField;
|
||||
import com.formdev.flatlaf.extras.components.extensions.FlatTextFieldExtension;
|
||||
|
||||
/**
|
||||
* Subclass of {@link JPasswordField} that implements {@link FlatTextFieldExtension}
|
||||
* to provide easy access to FlatLaf specific client properties.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatPasswordField
|
||||
extends JPasswordField
|
||||
implements FlatTextFieldExtension
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.extras.components;
|
||||
|
||||
import javax.swing.JScrollBar;
|
||||
import com.formdev.flatlaf.extras.components.extensions.FlatScrollBarExtension;
|
||||
|
||||
/**
|
||||
* Subclass of {@link JScrollBar} that implements {@link FlatScrollBarExtension}
|
||||
* to provide easy access to FlatLaf specific client properties.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatScrollBar
|
||||
extends JScrollBar
|
||||
implements FlatScrollBarExtension
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.extras.components;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import com.formdev.flatlaf.extras.components.extensions.FlatScrollPaneExtension;
|
||||
|
||||
/**
|
||||
* Subclass of {@link JScrollPane} that implements {@link FlatScrollPaneExtension}
|
||||
* to provide easy access to FlatLaf specific client properties.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatScrollPane
|
||||
extends JScrollPane
|
||||
implements FlatScrollPaneExtension
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.extras.components;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
import com.formdev.flatlaf.extras.components.extensions.FlatTextFieldExtension;
|
||||
|
||||
/**
|
||||
* Subclass of {@link JTextField} that implements {@link FlatTextFieldExtension}
|
||||
* to provide easy access to FlatLaf specific client properties.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatTextField
|
||||
extends JTextField
|
||||
implements FlatTextFieldExtension
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.extras.components.extensions;
|
||||
|
||||
import static com.formdev.flatlaf.FlatClientProperties.*;
|
||||
import javax.swing.JComboBox;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link JComboBox} that provides
|
||||
* easy access to FlatLaf specific client properties.
|
||||
* <p>
|
||||
* Use this interface if you already have a subclass of {@link JComboBox}
|
||||
* in your project and want add access to FlatLaf features to your class.
|
||||
* Otherwise use {@link FlatComboBox}.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public interface FlatComboBoxExtension
|
||||
extends FlatComponentExtension
|
||||
{
|
||||
/**
|
||||
* Returns the placeholder text that is only painted if the editable combo box is empty.
|
||||
*/
|
||||
default String getPlaceholderText() {
|
||||
return (String) getClientProperty( PLACEHOLDER_TEXT );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the placeholder text that is only painted if the editable combo box is empty.
|
||||
*/
|
||||
default void setPlaceholderText( String placeholderText ) {
|
||||
putClientProperty( PLACEHOLDER_TEXT, placeholderText );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.extras.components.extensions;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
/**
|
||||
* Base interface for all FlatLaf component extensions.
|
||||
* Extensions use client properties to store property values in components.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public interface FlatComponentExtension
|
||||
{
|
||||
/**
|
||||
* Overrides {@link JComponent#getClientProperty(Object)}.
|
||||
*/
|
||||
Object getClientProperty( Object key );
|
||||
|
||||
/**
|
||||
* Overrides {@link JComponent#putClientProperty(Object, Object)}.
|
||||
*/
|
||||
void putClientProperty( Object key, Object value );
|
||||
|
||||
|
||||
default boolean getClientPropertyBoolean( Object key, String defaultValueKey ) {
|
||||
Object value = getClientProperty( key );
|
||||
return (value instanceof Boolean) ? (boolean) value : UIManager.getBoolean( defaultValueKey );
|
||||
}
|
||||
|
||||
default <T extends Enum<T>> T getClientPropertyEnumString( Object key, Class<T> enumType,
|
||||
String defaultValueKey, T defaultValue )
|
||||
{
|
||||
Object value = getClientProperty( key );
|
||||
if( !(value instanceof String) && defaultValueKey != null )
|
||||
value = UIManager.getString( defaultValueKey );
|
||||
if( value instanceof String ) {
|
||||
try {
|
||||
return Enum.valueOf( enumType, (String) value );
|
||||
} catch( IllegalArgumentException ex ) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
default <T extends Enum<T>> void putClientPropertyEnumString( Object key, Enum<T> value ) {
|
||||
putClientProperty( key, (value != null) ? value.toString() : null );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.extras.components.extensions;
|
||||
|
||||
import static com.formdev.flatlaf.FlatClientProperties.*;
|
||||
import javax.swing.JScrollBar;
|
||||
import com.formdev.flatlaf.extras.components.FlatScrollBar;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link JScrollBar} that provides
|
||||
* easy access to FlatLaf specific client properties.
|
||||
* <p>
|
||||
* Use this interface if you already have a subclass of {@link JScrollBar}
|
||||
* in your project and want add access to FlatLaf features to your class.
|
||||
* Otherwise use {@link FlatScrollBar}.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public interface FlatScrollBarExtension
|
||||
extends FlatComponentExtension
|
||||
{
|
||||
/**
|
||||
* Returns whether the decrease/increase arrow buttons of a scrollbar are shown.
|
||||
*/
|
||||
default boolean isShowButtons() {
|
||||
return getClientPropertyBoolean( SCROLL_BAR_SHOW_BUTTONS, "ScrollBar.showButtons" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies whether the decrease/increase arrow buttons of a scrollbar are shown.
|
||||
*/
|
||||
default void setShowButtons( boolean showButtons ) {
|
||||
putClientProperty( SCROLL_BAR_SHOW_BUTTONS, showButtons );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.extras.components.extensions;
|
||||
|
||||
import static com.formdev.flatlaf.FlatClientProperties.*;
|
||||
import javax.swing.JScrollPane;
|
||||
import com.formdev.flatlaf.extras.components.FlatScrollPane;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link JScrollPane} that provides
|
||||
* easy access to FlatLaf specific client properties.
|
||||
* <p>
|
||||
* Use this interface if you already have a subclass of {@link JScrollPane}
|
||||
* in your project and want add access to FlatLaf features to your class.
|
||||
* Otherwise use {@link FlatScrollPane}.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public interface FlatScrollPaneExtension
|
||||
extends FlatComponentExtension
|
||||
{
|
||||
/**
|
||||
* Returns whether the decrease/increase arrow buttons of a scrollbar are shown.
|
||||
*/
|
||||
default boolean isShowButtons() {
|
||||
return getClientPropertyBoolean( SCROLL_BAR_SHOW_BUTTONS, "ScrollBar.showButtons" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies whether the decrease/increase arrow buttons of a scrollbar are shown.
|
||||
*/
|
||||
default void setShowButtons( boolean showButtons ) {
|
||||
putClientProperty( SCROLL_BAR_SHOW_BUTTONS, showButtons );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the scroll pane uses smooth scrolling.
|
||||
*/
|
||||
default boolean isSmoothScrolling() {
|
||||
return getClientPropertyBoolean( SCROLL_PANE_SMOOTH_SCROLLING, "ScrollPane.smoothScrolling" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies whether the scroll pane uses smooth scrolling.
|
||||
*/
|
||||
default void setSmoothScrolling( boolean smoothScrolling ) {
|
||||
putClientProperty( SCROLL_PANE_SMOOTH_SCROLLING, smoothScrolling );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.extras.components.extensions;
|
||||
|
||||
import static com.formdev.flatlaf.FlatClientProperties.*;
|
||||
import javax.swing.JFormattedTextField;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
import com.formdev.flatlaf.extras.components.FlatFormattedTextField;
|
||||
import com.formdev.flatlaf.extras.components.FlatPasswordField;
|
||||
import com.formdev.flatlaf.extras.components.FlatTextField;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link JTextField} (and subclasses) that provides
|
||||
* easy access to FlatLaf specific client properties.
|
||||
* <p>
|
||||
* Use this interface if you already have a subclass of {@link JTextField},
|
||||
* {@link JFormattedTextField} or {@link JPasswordField}
|
||||
* in your project and want add access to FlatLaf features to your class.
|
||||
* Otherwise use {@link FlatTextField}, {@link FlatFormattedTextField} or {@link FlatPasswordField}.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public interface FlatTextFieldExtension
|
||||
extends FlatComponentExtension
|
||||
{
|
||||
/**
|
||||
* Returns the placeholder text that is only painted if the text field is empty.
|
||||
*/
|
||||
default String getPlaceholderText() {
|
||||
return (String) getClientProperty( PLACEHOLDER_TEXT );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the placeholder text that is only painted if the text field is empty.
|
||||
*/
|
||||
default void setPlaceholderText( String placeholderText ) {
|
||||
putClientProperty( PLACEHOLDER_TEXT, placeholderText );
|
||||
}
|
||||
|
||||
|
||||
// NOTE: enum names must be equal to allowed strings
|
||||
enum SelectAllOnFocusPolicy { never, once, always };
|
||||
|
||||
/**
|
||||
* Returns whether all text is selected when the text component gains focus.
|
||||
*/
|
||||
default SelectAllOnFocusPolicy getSelectAllOnFocusPolicy() {
|
||||
return getClientPropertyEnumString( SELECT_ALL_ON_FOCUS_POLICY, SelectAllOnFocusPolicy.class,
|
||||
"TextComponent.selectAllOnFocusPolicy", SelectAllOnFocusPolicy.once );
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies whether all text is selected when the text component gains focus.
|
||||
*/
|
||||
default void setSelectAllOnFocusPolicy( SelectAllOnFocusPolicy selectAllOnFocusPolicy ) {
|
||||
putClientPropertyEnumString( SELECT_ALL_ON_FOCUS_POLICY, selectAllOnFocusPolicy );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user