-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#537 documentation and a few minor updates.
- Loading branch information
Showing
22 changed files
with
316 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
.../src/main/java/com/thecoderscorner/embedcontrol/core/controlmgr/ComponentPositioning.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
.../main/java/com/thecoderscorner/embedcontrol/core/controlmgr/ComponentSettingsBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.thecoderscorner.embedcontrol.core.controlmgr; | ||
|
||
import com.thecoderscorner.embedcontrol.core.controlmgr.color.ConditionalColoring; | ||
import com.thecoderscorner.embedcontrol.customization.FontInformation; | ||
import com.thecoderscorner.embedcontrol.customization.customdraw.CustomDrawingConfiguration; | ||
import com.thecoderscorner.menu.domain.*; | ||
|
||
import java.util.Set; | ||
|
||
import static com.thecoderscorner.embedcontrol.core.controlmgr.EditorComponent.PortableAlignment; | ||
import static com.thecoderscorner.embedcontrol.customization.MenuFormItem.FONT_100_PERCENT; | ||
|
||
/** | ||
* ComponentSettingsBuilder is a builder class for creating instances of ComponentSettings. | ||
* It provides various methods to customize the settings of a component, such as font, colors, | ||
* justification, position, control type, drawing mode, and custom drawing configuration. | ||
*/ | ||
public class ComponentSettingsBuilder { | ||
private final static Set<EditItemType> POSSIBLE_TIME_TYPES = Set.of( | ||
EditItemType.TIME_12H, | ||
EditItemType.TIME_24_HUNDREDS, | ||
EditItemType.TIME_24H, | ||
EditItemType.TIME_12H_HHMM, | ||
EditItemType.TIME_24H_HHMM); | ||
|
||
private MenuItem item; | ||
private FontInformation fontInfo = FONT_100_PERCENT; | ||
private ConditionalColoring colors; | ||
private PortableAlignment justification = PortableAlignment.LEFT_VAL_RIGHT; | ||
private ComponentPositioning position = new ComponentPositioning(0, 0); | ||
private ControlType controlType = ControlType.TEXT_CONTROL; | ||
private RedrawingMode drawMode = RedrawingMode.SHOW_NAME_VALUE; | ||
private CustomDrawingConfiguration customDrawing = CustomDrawingConfiguration.NO_CUSTOM_DRAWING; | ||
|
||
/// Create component settings builder object from a menu item. It defaults the fields to reasonable values as | ||
/// much as possible by setting the font to 100% size, setting the control type to the default, and setting the | ||
/// justification to the default too. | ||
/// @param item the menu item to build for | ||
/// @param color the colors to use for the control | ||
public static ComponentSettingsBuilder forMenuItem(MenuItem item, ConditionalColoring color) { | ||
var b = new ComponentSettingsBuilder(); | ||
b.colors = color; | ||
b.item = item; | ||
b.withControlType(defaultControlForType(item)); | ||
b.withJustification(defaultJustificationForType(b.controlType)); | ||
return b; | ||
} | ||
|
||
private static PortableAlignment defaultJustificationForType(ControlType controlType) { | ||
return switch(controlType) { | ||
case HORIZONTAL_SLIDER, UP_DOWN_CONTROL -> PortableAlignment.LEFT_VAL_RIGHT; | ||
case BUTTON_CONTROL, VU_METER, ROTARY_METER -> PortableAlignment.CENTER; | ||
default -> PortableAlignment.LEFT; | ||
}; | ||
} | ||
|
||
public static ControlType defaultControlForType(MenuItem item) { | ||
return switch(item) { | ||
case SubMenuItem _, BooleanMenuItem _, ActionMenuItem _ -> ControlType.BUTTON_CONTROL; | ||
case AnalogMenuItem _ -> ControlType.HORIZONTAL_SLIDER; | ||
case EnumMenuItem _, ScrollChoiceMenuItem _ -> ControlType.UP_DOWN_CONTROL; | ||
case Rgb32MenuItem _ -> ControlType.RGB_CONTROL; | ||
case RuntimeListMenuItem _ -> ControlType.LIST_CONTROL; | ||
case CustomBuilderMenuItem _ -> ControlType.AUTH_IOT_CONTROL; | ||
case EditableTextMenuItem txt when txt.getItemType() == EditItemType.GREGORIAN_DATE -> ControlType.DATE_CONTROL; | ||
case EditableTextMenuItem txt when POSSIBLE_TIME_TYPES.contains(txt.getItemType()) -> ControlType.TIME_CONTROL; | ||
default -> ControlType.TEXT_CONTROL; | ||
}; | ||
} | ||
|
||
/// Override the font from the default 100% size to another value | ||
/// @param fontInfo the font to override with. | ||
public ComponentSettingsBuilder withFont(FontInformation fontInfo) { | ||
this.fontInfo = fontInfo; | ||
return this; | ||
} | ||
|
||
/// Change the conditional coloring from the default one chosen. | ||
/// @param colors the conditional colors | ||
public ComponentSettingsBuilder withColors(ConditionalColoring colors) { | ||
this.colors = colors; | ||
return this; | ||
} | ||
|
||
/// Change the justification from the default value which is guessed during `forMenuItem` based on the control. | ||
/// @param justification the justification to use | ||
public ComponentSettingsBuilder withJustification(PortableAlignment justification) { | ||
this.justification = justification; | ||
return this; | ||
} | ||
|
||
/// Set the position of the control in the grid. Pretty much must always be set | ||
/// @param position the position and span in the grid to create with | ||
public ComponentSettingsBuilder withPosition(ComponentPositioning position) { | ||
this.position = position; | ||
return this; | ||
} | ||
|
||
/// Override the control type that was guessed during `forMenuItem`. You should be careful that the control type | ||
/// you choose is compatible with the menu item type. | ||
/// @param controlType the control type to use | ||
/// @throws IllegalArgumentException if the control type is invalid for the menu item | ||
public ComponentSettingsBuilder withControlType(ControlType controlType) { | ||
if(!controlType.isSupportedFor(item)) { | ||
throw new IllegalArgumentException("Control type %s cannot render %s".formatted(controlType, item.getClass().getSimpleName())); | ||
} | ||
this.controlType = controlType; | ||
return this; | ||
} | ||
|
||
/// Sets the drawing mode for the item, defaults to show name and item. | ||
/// @param drawMode the drawing mode | ||
public ComponentSettingsBuilder withDrawMode(RedrawingMode drawMode) { | ||
this.drawMode = drawMode; | ||
return this; | ||
} | ||
|
||
/// Configure a custom drawing for the item, again make sure it is compatible with the menu type your using. | ||
/// @param customDrawing the custom drawing to be used, must be compatible with the menu item type. | ||
/// @throws IllegalArgumentException if the custom drawing is incompatible with the menu item type | ||
public ComponentSettingsBuilder withCustomDrawing(CustomDrawingConfiguration customDrawing) { | ||
if(!customDrawing.isSupportedFor(item)) { | ||
throw new IllegalArgumentException("Custom drawing %s cannot render %s".formatted(customDrawing, item.getClass().getSimpleName())); | ||
} | ||
this.customDrawing = customDrawing; | ||
return this; | ||
} | ||
|
||
/// Get the menuitem for this builder | ||
/// @return menu item | ||
public MenuItem getItem() { | ||
return item; | ||
} | ||
|
||
/// Creates the component settings | ||
/// @return the built object | ||
public ComponentSettings build() { | ||
return new ComponentSettings(colors, fontInfo, justification, position, drawMode, controlType, customDrawing, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 15 additions & 6 deletions
21
...Core/src/main/java/com/thecoderscorner/embedcontrol/core/controlmgr/PanelPresentable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.