The switchLayout method in the SearchResultsFrame class is currently tightly coupled to specific Look and Feel (LaF) implementations, such as SeaGlass and Mac. This approach makes it difficult to manage and update the layout constraints for different LaFs and reduces the flexibility of the code.
Tasks:
Define Layout Constraints:
Create a LayoutConstraints class that holds the border configurations for different LaFs.
Define a mapping from LaF names to their respective border configurations.
Update Borders Declaratively:
Use the LayoutConstraints class to get the appropriate border configurations based on the current LaF.
Apply these configurations in the switchLayout method.
Refactor switchLayout Method:
Remove direct checks for specific LaFs within the method.
Use the declarative constraints from LayoutConstraints to set the borders and other properties.
Ensure that the method still updates the JSplitPane orientation and handles additional styling for Mac if needed.
Example Implementation:
LayoutConstraints.java
public class LayoutConstraints {
private Map<String, BorderConfig> lafBorders;
public LayoutConstraints() {
lafBorders = new HashMap<>();
// Example configurations for different LaFs
lafBorders.put("SeaGlass", new BorderConfig(
BorderFactory.createMatteBorder(0, 0, 1, 0, ColorUtil.getBorderGray(settingsObj)),
BorderFactory.createMatteBorder(1, 1, 0, 0, ColorUtil.getBorderGray(settingsObj)),
BorderFactory.createMatteBorder(0, 0, 0, 1, ColorUtil.getBorderGray(settingsObj)),
BorderFactory.createMatteBorder(0, 1, 0, 0, ColorUtil.getBorderGray(settingsObj))
));
// Add other LaF configurations here
}
public BorderConfig getBorderConfig(String laf) {
return lafBorders.getOrDefault(laf, new BorderConfig());
}
public static class BorderConfig {
private Border verticalSplitBorder1;
private Border verticalSplitBorder2;
private Border horizontalSplitBorder1;
private Border horizontalSplitBorder2;
public BorderConfig() {
// Default borders
this(BorderFactory.createEmptyBorder(), BorderFactory.createEmptyBorder(), BorderFactory.createEmptyBorder(), BorderFactory.createEmptyBorder());
}
public BorderConfig(Border vSplitBorder1, Border vSplitBorder2, Border hSplitBorder1, Border hSplitBorder2) {
this.verticalSplitBorder1 = vSplitBorder1;
this.verticalSplitBorder2 = vSplitBorder2;
this.horizontalSplitBorder1 = hSplitBorder1;
this.horizontalSplitBorder2 = hSplitBorder2;
}
public Border getVerticalSplitBorder1() { return verticalSplitBorder1; }
public Border getVerticalSplitBorder2() { return verticalSplitBorder2; }
public Border getHorizontalSplitBorder1() { return horizontalSplitBorder1; }
public Border getHorizontalSplitBorder2() { return horizontalSplitBorder2; }
}
}
SearchResultsFrame.java
@Action
public void switchLayout() {
int currentlayout = settingsObj.getSearchFrameSplitLayout();
String currentLaf = settingsObj.getCurrentLookAndFeel(); // Assuming there's a method to get the current LaF
LayoutConstraints layoutConstraints = new LayoutConstraints();
LayoutConstraints.BorderConfig borderConfig = layoutConstraints.getBorderConfig(currentLaf);
if (JSplitPane.HORIZONTAL_SPLIT == currentlayout) {
currentlayout = JSplitPane.VERTICAL_SPLIT;
jPanel1.setBorder(borderConfig.getVerticalSplitBorder1());
jPanel2.setBorder(borderConfig.getVerticalSplitBorder2());
} else {
currentlayout = JSplitPane.HORIZONTAL_SPLIT;
jPanel1.setBorder(borderConfig.getHorizontalSplitBorder1());
jPanel2.setBorder(borderConfig.getHorizontalSplitBorder2());
}
settingsObj.setSearchFrameSplitLayout(currentlayout);
jSplitPaneSearch1.setOrientation(currentlayout);
// Apply additional styling if necessary (can be generalized or removed if no longer needed)
if (settingsObj.isMacStyle()) {
ZknMacWidgetFactory.updateSplitPane(jSplitPaneSearch1);
}
}
Expected Outcome:
The switchLayout method will be decoupled from specific LaF implementations.
Layout constraints will be defined declaratively, improving maintainability and flexibility.
It will be easier to add new LaF configurations without modifying the core logic.
The
switchLayout
method in theSearchResultsFrame
class is currently tightly coupled to specific Look and Feel (LaF) implementations, such as SeaGlass and Mac. This approach makes it difficult to manage and update the layout constraints for different LaFs and reduces the flexibility of the code.Tasks:
Define Layout Constraints:
LayoutConstraints
class that holds the border configurations for different LaFs.Update Borders Declaratively:
LayoutConstraints
class to get the appropriate border configurations based on the current LaF.switchLayout
method.Refactor
switchLayout
Method:LayoutConstraints
to set the borders and other properties.JSplitPane
orientation and handles additional styling for Mac if needed.Example Implementation:
LayoutConstraints.java
SearchResultsFrame.java
Expected Outcome:
switchLayout
method will be decoupled from specific LaF implementations.Labels:
Assignees:
Milestone: