Extras: removed extension interfaces and moved methods to components classes because:

- Javadoc for components that implement extension interfaces are useless because they do not include default methods from the extension interface
- GUI builders do not recognize default methods from the extension interface and it is not possible to edit extension properties in GUI builder
- the idea of adding the extension interface to own components can be also achieved by changing superclass of own component

(issue #117)
This commit is contained in:
Karl Tauber
2020-12-11 13:00:20 +01:00
parent 923d58519f
commit 3a8b30ca8e
12 changed files with 170 additions and 259 deletions

View File

@@ -40,6 +40,7 @@ tasks {
this as StandardJavadocDocletOptions
use( true )
tags = listOf( "uiDefault", "clientProperty" )
addStringOption( "Xdoclint:all,-missing", "-Xdoclint:all,-missing" )
}
isFailOnError = false
}

View File

@@ -16,17 +16,29 @@
package com.formdev.flatlaf.extras.components;
import static com.formdev.flatlaf.FlatClientProperties.*;
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.
* Subclass of {@link JComboBox} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
*/
public class FlatComboBox<E>
extends JComboBox<E>
implements FlatComboBoxExtension
implements FlatComponentExtension
{
/**
* Returns the placeholder text that is only painted if the editable combo box is empty.
*/
public String getPlaceholderText() {
return (String) getClientProperty( PLACEHOLDER_TEXT );
}
/**
* Sets the placeholder text that is only painted if the editable combo box is empty.
*/
public void setPlaceholderText( String placeholderText ) {
putClientProperty( PLACEHOLDER_TEXT, placeholderText );
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.formdev.flatlaf.extras.components.extensions;
package com.formdev.flatlaf.extras.components;
import javax.swing.JComponent;
import javax.swing.UIManager;

View File

@@ -16,17 +16,48 @@
package com.formdev.flatlaf.extras.components;
import static com.formdev.flatlaf.FlatClientProperties.*;
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.
* Subclass of {@link JFormattedTextField} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
*/
public class FlatFormattedTextField
extends JFormattedTextField
implements FlatTextFieldExtension
implements FlatComponentExtension
{
/**
* Returns the placeholder text that is only painted if the text field is empty.
*/
public String getPlaceholderText() {
return (String) getClientProperty( PLACEHOLDER_TEXT );
}
/**
* Sets the placeholder text that is only painted if the text field is empty.
*/
public 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.
*/
public 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.
*/
public void setSelectAllOnFocusPolicy( SelectAllOnFocusPolicy selectAllOnFocusPolicy ) {
putClientPropertyEnumString( SELECT_ALL_ON_FOCUS_POLICY, selectAllOnFocusPolicy );
}
}

View File

@@ -16,17 +16,48 @@
package com.formdev.flatlaf.extras.components;
import static com.formdev.flatlaf.FlatClientProperties.*;
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.
* Subclass of {@link JPasswordField} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
*/
public class FlatPasswordField
extends JPasswordField
implements FlatTextFieldExtension
implements FlatComponentExtension
{
/**
* Returns the placeholder text that is only painted if the text field is empty.
*/
public String getPlaceholderText() {
return (String) getClientProperty( PLACEHOLDER_TEXT );
}
/**
* Sets the placeholder text that is only painted if the text field is empty.
*/
public 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.
*/
public 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.
*/
public void setSelectAllOnFocusPolicy( SelectAllOnFocusPolicy selectAllOnFocusPolicy ) {
putClientPropertyEnumString( SELECT_ALL_ON_FOCUS_POLICY, selectAllOnFocusPolicy );
}
}

View File

@@ -16,17 +16,29 @@
package com.formdev.flatlaf.extras.components;
import static com.formdev.flatlaf.FlatClientProperties.*;
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.
* Subclass of {@link JScrollBar} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
*/
public class FlatScrollBar
extends JScrollBar
implements FlatScrollBarExtension
implements FlatComponentExtension
{
/**
* Returns whether the decrease/increase arrow buttons of a scrollbar are shown.
*/
public boolean isShowButtons() {
return getClientPropertyBoolean( SCROLL_BAR_SHOW_BUTTONS, "ScrollBar.showButtons" );
}
/**
* Specifies whether the decrease/increase arrow buttons of a scrollbar are shown.
*/
public void setShowButtons( boolean showButtons ) {
putClientProperty( SCROLL_BAR_SHOW_BUTTONS, showButtons );
}
}

View File

@@ -16,17 +16,44 @@
package com.formdev.flatlaf.extras.components;
import static com.formdev.flatlaf.FlatClientProperties.*;
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.
* Subclass of {@link JScrollPane} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
*/
public class FlatScrollPane
extends JScrollPane
implements FlatScrollPaneExtension
implements FlatComponentExtension
{
/**
* Returns whether the decrease/increase arrow buttons of a scrollbar are shown.
*/
public boolean isShowButtons() {
return getClientPropertyBoolean( SCROLL_BAR_SHOW_BUTTONS, "ScrollBar.showButtons" );
}
/**
* Specifies whether the decrease/increase arrow buttons of a scrollbar are shown.
*/
public void setShowButtons( boolean showButtons ) {
putClientProperty( SCROLL_BAR_SHOW_BUTTONS, showButtons );
}
/**
* Returns whether the scroll pane uses smooth scrolling.
*/
public boolean isSmoothScrolling() {
return getClientPropertyBoolean( SCROLL_PANE_SMOOTH_SCROLLING, "ScrollPane.smoothScrolling" );
}
/**
* Specifies whether the scroll pane uses smooth scrolling.
*/
public void setSmoothScrolling( boolean smoothScrolling ) {
putClientProperty( SCROLL_PANE_SMOOTH_SCROLLING, smoothScrolling );
}
}

View File

@@ -16,17 +16,48 @@
package com.formdev.flatlaf.extras.components;
import static com.formdev.flatlaf.FlatClientProperties.*;
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.
* Subclass of {@link JTextField} that provides easy access to FlatLaf specific client properties.
*
* @author Karl Tauber
*/
public class FlatTextField
extends JTextField
implements FlatTextFieldExtension
implements FlatComponentExtension
{
/**
* Returns the placeholder text that is only painted if the text field is empty.
*/
public String getPlaceholderText() {
return (String) getClientProperty( PLACEHOLDER_TEXT );
}
/**
* Sets the placeholder text that is only painted if the text field is empty.
*/
public 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.
*/
public 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.
*/
public void setSelectAllOnFocusPolicy( SelectAllOnFocusPolicy selectAllOnFocusPolicy ) {
putClientPropertyEnumString( SELECT_ALL_ON_FOCUS_POLICY, selectAllOnFocusPolicy );
}
}

View File

@@ -1,48 +0,0 @@
/*
* 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 );
}
}

View File

@@ -1,49 +0,0 @@
/*
* 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 );
}
}

View File

@@ -1,64 +0,0 @@
/*
* 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 );
}
}

View File

@@ -1,73 +0,0 @@
/*
* 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 );
}
}