java.lang.Object
com.marginallyclever.ro3.PanelHelper
PanelHelper
is a collection of static methods to help build panels.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addColorChooser
(JPanel parent, String title, Supplier<Color> startColor, Consumer<Color> consumer, GridBagConstraints gbc) A convenience method to add a color chooser to a panel.static void
addLabelAndComponent
(JPanel pane, String labelText, JComponent component) A convenience method to add a label and component to a panel that is built withGridLayout
.static void
addLabelAndComponent
(JPanel pane, String labelText, JComponent component, GridBagConstraints gbc) A convenience method to add a label and component to a panel that is built withGridBagLayout
.static void
addLimit
(JPanel pane, GridBagConstraints gbc, String label, double value, Consumer<Double> consumer, double infinite) A convenience method to add an angle limit to a panel (in degrees).static <T extends Node>
NodeSelector<T> addNodeSelector
(JPanel pane, String label, NodePath<T> nodePath, GridBagConstraints gbc) A convenience method to add a label and component to a panel that is expected to be built with GridBagConstraint.static JFormattedTextField
addNumberField
(String toolTip, double value, NumberFormatter formatter) A convenience method to add a number field to a panel.static JFormattedTextField
addNumberFieldDouble
(String toolTip, double value) A convenience method to add a number field to a panel.static JFormattedTextField
addNumberFieldInt
(String toolTip, int value) A convenience method to add a number field to a panel.static void
addSelector
(JPanel pane, GridBagConstraints gbc, String label, NodePath<ODEBody> originalValue, Consumer<ODEBody> consumer) A convenience method to add aNodeSelector
to a panel.static JComponent
createRange
(double max, double min, double value, Consumer<Double> consumer) Create a range slider with two decimal places that displays the value on the right.static void
enableLimit
(boolean isSelected, JSpinner spinner, Consumer<Double> consumer, double infinite)
-
Constructor Details
-
PanelHelper
public PanelHelper()
-
-
Method Details
-
addLabelAndComponent
A convenience method to add a label and component to a panel that is built with
GridLayout
.- Parameters:
pane
- the panel to add tolabelText
- the text for the labelcomponent
- the component to add
-
addLabelAndComponent
public static void addLabelAndComponent(JPanel pane, String labelText, JComponent component, GridBagConstraints gbc) A convenience method to add a label and component to a panel that is built with
GridBagLayout
.- Parameters:
pane
- the panel to add tolabelText
- the text for the labelcomponent
- the component to addgbc
- the GridBagConstraints to use
-
addNodeSelector
public static <T extends Node> NodeSelector<T> addNodeSelector(JPanel pane, String label, NodePath<T> nodePath, GridBagConstraints gbc) A convenience method to add a label and component to a panel that is expected to be built with GridBagConstraint.- Type Parameters:
T
- the type filter for theNodeSelector
.- Parameters:
pane
- the panel to add tolabel
- the text for the labelnodePath
- the NodePath to usegbc
- theGridBagConstraints
to use- Returns:
- the NodeSelector
-
addColorChooser
public static void addColorChooser(JPanel parent, String title, Supplier<Color> startColor, Consumer<Color> consumer, GridBagConstraints gbc) A convenience method to add a color chooser to a panel.
- Parameters:
parent
- the parent paneltitle
- the title for the color chooserstartColor
- the initial colorconsumer
- the consumer to accept the colorgbc
- theGridBagConstraints
to use
-
addNumberFieldDouble
A convenience method to add a number field to a panel.
- Parameters:
toolTip
- the tooltip for the fieldvalue
- the initial value- Returns:
- the
JFormattedTextField
-
addNumberFieldInt
A convenience method to add a number field to a panel.
- Parameters:
toolTip
- the tooltip for the fieldvalue
- the initial value- Returns:
- the
JFormattedTextField
-
addNumberField
public static JFormattedTextField addNumberField(String toolTip, double value, NumberFormatter formatter) A convenience method to add a number field to a panel.
- Parameters:
toolTip
- the tooltip for the fieldvalue
- the initial valueformatter
- theNumberFormatter
to use- Returns:
- the
JFormattedTextField
-
addLimit
public static void addLimit(JPanel pane, GridBagConstraints gbc, String label, double value, Consumer<Double> consumer, double infinite) A convenience method to add an angle limit to a panel (in degrees).
- Parameters:
pane
- the panel to add togbc
- theGridBagConstraints
to uselabel
- the label for the limitvalue
- the initial valueconsumer
- the consumer to accept the valueinfinite
- the value to use for infinite (no limit)
-
enableLimit
-
addSelector
public static void addSelector(JPanel pane, GridBagConstraints gbc, String label, NodePath<ODEBody> originalValue, Consumer<ODEBody> consumer) A convenience method to add a
NodeSelector
to a panel.- Parameters:
pane
- the panel to add togbc
- theGridBagConstraints
to uselabel
- the label for the selectororiginalValue
- the original valueconsumer
- the consumer to accept the value
-
createRange
public static JComponent createRange(double max, double min, double value, Consumer<Double> consumer) Create a range slider with two decimal places that displays the value on the right.- Parameters:
max
- the maximum valuemin
- the minimum valuevalue
- the initial valueconsumer
- the consumer to accept the value- Returns:
- the
JComponent
-