mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Better component value render in explorer
This commit is contained in:
@@ -46,7 +46,7 @@ import org.diylc.swing.gui.SearchTextField;
|
|||||||
public class ExplorerPane extends JPanel {
|
public class ExplorerPane extends JPanel {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private static final String REORDERING_NOT_POSSIBLE = LangUtil.translate(
|
private static final String REORDERING_NOT_POSSIBLE = LangUtil.translate(
|
||||||
"Component reordering is possible only when Project Explorer is sorted by z-index.");
|
"Component reordering is possible only when Project Explorer is sorted by z-index.");
|
||||||
|
|
||||||
@@ -74,13 +74,13 @@ public class ExplorerPane extends JPanel {
|
|||||||
GridBagConstraints gbc = new GridBagConstraints();
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
gbc.gridx = 0;
|
gbc.gridx = 0;
|
||||||
gbc.gridy = 0;
|
gbc.gridy = 0;
|
||||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc.weighty = 0;
|
gbc.weighty = 0;
|
||||||
gbc.gridwidth = 1;
|
gbc.gridwidth = 1;
|
||||||
|
|
||||||
// add(getTitleLabel(), gbc);
|
// add(getTitleLabel(), gbc);
|
||||||
//
|
//
|
||||||
// gbc.gridy++;
|
// gbc.gridy++;
|
||||||
|
|
||||||
add(getSearchField(), gbc);
|
add(getSearchField(), gbc);
|
||||||
|
|
||||||
@@ -102,12 +102,12 @@ public class ExplorerPane extends JPanel {
|
|||||||
|
|
||||||
setPreferredSize(new Dimension(240, 200));
|
setPreferredSize(new Dimension(240, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
public JLabel getTitleLabel() {
|
public JLabel getTitleLabel() {
|
||||||
if (titleLabel == null) {
|
if (titleLabel == null) {
|
||||||
titleLabel = new JLabel(getName());
|
titleLabel = new JLabel(getName());
|
||||||
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
// titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD));
|
// titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD));
|
||||||
}
|
}
|
||||||
return titleLabel;
|
return titleLabel;
|
||||||
}
|
}
|
||||||
@@ -342,36 +342,52 @@ public class ExplorerPane extends JPanel {
|
|||||||
return this.components.get(index);
|
return this.components.get(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ComponentListCellRenderer implements ListCellRenderer<IDIYComponent<?>> {
|
private static class ComponentListCellRenderer implements ListCellRenderer<IDIYComponent<?>> {
|
||||||
|
|
||||||
// private static Color[] layerColors = new Color[] { Color.gray, Color.decode("#ff6363"), Color.decode("#293462"), Color.decode("#138588"),
|
// private static Color[] layerColors = new Color[] { Color.gray, Color.decode("#ff6363"),
|
||||||
// Color.decode("#c0ca03"), Color.decode("#990000") };
|
// Color.decode("#293462"), Color.decode("#138588"),
|
||||||
|
// Color.decode("#c0ca03"), Color.decode("#990000") };
|
||||||
|
|
||||||
protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
|
protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
|
||||||
|
|
||||||
private Map<String, ComponentType> componentTypes;
|
private Map<String, ComponentType> componentTypes;
|
||||||
|
|
||||||
public ComponentListCellRenderer(Map<String, List<ComponentType>> componentTypeMap) {
|
public ComponentListCellRenderer(Map<String, List<ComponentType>> componentTypeMap) {
|
||||||
this.componentTypes = componentTypeMap.values().stream()
|
this.componentTypes = componentTypeMap.values().stream().flatMap(x -> x.stream())
|
||||||
.flatMap(x -> x.stream())
|
|
||||||
.collect(Collectors.toMap(x -> x.getInstanceClass().getCanonicalName(), x -> x));
|
.collect(Collectors.toMap(x -> x.getInstanceClass().getCanonicalName(), x -> x));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getListCellRendererComponent(JList<? extends IDIYComponent<?>> list,
|
public Component getListCellRendererComponent(JList<? extends IDIYComponent<?>> list,
|
||||||
IDIYComponent<?> value, int index, boolean isSelected, boolean cellHasFocus) {
|
IDIYComponent<?> value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
|
|
||||||
ComponentType componentType = componentTypes.get(value.getClass().getCanonicalName());
|
ComponentType componentType = componentTypes.get(value.getClass().getCanonicalName());
|
||||||
|
|
||||||
JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,
|
JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,
|
||||||
isSelected, cellHasFocus);
|
isSelected, cellHasFocus);
|
||||||
|
|
||||||
int layerId = (int)Math.round(componentType.getZOrder());
|
int layerId = (int) Math.round(componentType.getZOrder());
|
||||||
|
|
||||||
|
String valueForDisplay = value.getValueForDisplay();
|
||||||
renderer.setText(String.format("<html><font color='#c0c0c0'>[L%s]</font> %s (<font color='#666666'>%s</font>)</html>", layerId, value.getName(), value.getValueForDisplay()));
|
if (isSelected) {
|
||||||
|
if (valueForDisplay == null || valueForDisplay.trim().isEmpty()) {
|
||||||
|
renderer.setText(String.format("[L%s] %s", layerId, value.getName()));
|
||||||
|
} else {
|
||||||
|
renderer
|
||||||
|
.setText(String.format("[L%s] %s (%s)", layerId, value.getName(), valueForDisplay));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (valueForDisplay == null || valueForDisplay.trim().isEmpty()) {
|
||||||
|
renderer.setText(String.format("<html><font color='#c0c0c0'>[L%s]</font> %s</html>",
|
||||||
|
layerId, value.getName()));
|
||||||
|
} else {
|
||||||
|
renderer.setText(String.format(
|
||||||
|
"<html><font color='#c0c0c0'>[L%s]</font> %s (<font color='#666666'>%s</font>)</html>",
|
||||||
|
layerId, value.getName(), valueForDisplay));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return renderer;
|
return renderer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user