Added: Simple editor - change background color

This commit is contained in:
Jindra Petřík
2025-05-09 16:36:07 +02:00
parent 0965ec529f
commit 341bab395e
8 changed files with 108 additions and 43 deletions
@@ -415,7 +415,7 @@ public class AdvancedSettingsDialog extends AppDialog {
}
}
if (itemType == Color.class) {
defaultValue = ConfigurationColorSelection.colorToHex((Color) defaultValue);
defaultValue = ColorSelectionButton.colorToHex((Color) defaultValue);
}
String locNameHtml = locName;
if (!filter.trim().equals("")) {
@@ -492,7 +492,7 @@ public class AdvancedSettingsDialog extends AppDialog {
cb.setToolTipText(description);
c = cb;
} else if (itemType == Color.class) {
ConfigurationColorSelection cb = new ConfigurationColorSelection(item, (Color) item.get(), description);
ColorSelectionButton cb = new ColorSelectionButton((Color) item.get(), description);
cb.setMaximumSize(new Dimension(Integer.MAX_VALUE, cb.getPreferredSize().height));
c = cb;
@@ -618,7 +618,7 @@ public class AdvancedSettingsDialog extends AppDialog {
value = ((JCheckBox) c).isSelected();
}
if (itemType == Color.class) {
value = ((ConfigurationColorSelection) c).getValue();
value = ((ColorSelectionButton) c).getValue();
}
if (itemType == Calendar.class) {
@@ -32,16 +32,17 @@ import javax.swing.border.BevelBorder;
*
* @author JPEXS
*/
public class ConfigurationColorSelection extends FocusablePanel {
public class ColorSelectionButton extends FocusablePanel {
private JPanel colorPanel;
private JLabel colorLabel;
public ConfigurationColorSelection(ConfigurationItem item, Color value, String description) {
public ColorSelectionButton(Color value, String description) {
setLayout(new FlowLayout(FlowLayout.LEFT));
colorPanel = new JPanel();
setToolTipText(description);
colorPanel.setSize(16, 16);
colorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
JLabel colorLabel = new JLabel();
colorLabel = new JLabel();
colorPanel.setBackground(value);
addMouseListener(new MouseAdapter() {
@@ -75,24 +76,17 @@ public class ConfigurationColorSelection extends FocusablePanel {
add(colorLabel);
}
public static String colorToHex(Color value) {
String rh = Integer.toHexString(value.getRed());
if (rh.length() < 2) {
rh = "0" + rh;
}
String gh = Integer.toHexString(value.getGreen());
if (gh.length() < 2) {
gh = "0" + gh;
}
String bh = Integer.toHexString(value.getBlue());
if (bh.length() < 2) {
bh = "0" + bh;
}
return "#" + rh + gh + bh;
public static String colorToHex(Color color) {
return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
}
public Color getValue() {
return colorPanel.getBackground();
}
public void setValue(Color color) {
colorLabel.setText(colorToHex(color));
colorPanel.setBackground(color);
}
}
@@ -42,7 +42,7 @@ import javax.swing.JTextField;
* @author JPEXS
*/
public class GridDialog extends AppDialog {
private final ConfigurationColorSelection colorSelection;
private final ColorSelectionButton colorSelection;
private final JCheckBox showGridCheckBox;
private final JCheckBox snapToGridCheckBox;
private final JCheckBox showOverObjectsCheckBox;
@@ -68,7 +68,7 @@ public class GridDialog extends AppDialog {
centralPanel.add(colorLabel, c);
colorSelection = new ConfigurationColorSelection(Configuration.gridColor, Configuration.gridColor.get(), null);
colorSelection = new ColorSelectionButton(Configuration.gridColor.get(), null);
colorLabel.setLabelFor(colorSelection);
c.gridx = 1;
c.anchor = GridBagConstraints.LINE_START;
@@ -42,7 +42,7 @@ import javax.swing.JPanel;
*/
public class GuidesDialog extends AppDialog {
private final ConfigurationColorSelection colorSelection;
private final ColorSelectionButton colorSelection;
private final JCheckBox showGuidesCheckBox;
private final JCheckBox snapToGuidesCheckBox;
private final JCheckBox lockGuidesCheckBox;
@@ -68,7 +68,7 @@ public class GuidesDialog extends AppDialog {
centralPanel.add(colorLabel, c);
colorSelection = new ConfigurationColorSelection(Configuration.guidesColor, Configuration.guidesColor.get(), null);
colorSelection = new ColorSelectionButton(Configuration.guidesColor.get(), null);
colorLabel.setLabelFor(colorSelection);
c.gridx = 1;
c.anchor = GridBagConstraints.LINE_START;
@@ -115,3 +115,6 @@ property.instance.display.blending.hardlight = Hardlight
property.instance.display.cacheAsBitmap = Cache as bitmap
property.instance.display.cacheAsBitmap.transparent = Transparent
property.instance.display.cacheAsBitmap.opaque = Opaque
#after 22.0.2
property.document.backgroundColor = Background color
@@ -115,3 +115,6 @@ property.instance.display.blending.hardlight = Hardlight
property.instance.display.cacheAsBitmap = Ke\u0161ovat jako bitmapu
property.instance.display.cacheAsBitmap.transparent = Pr\u016fhledn\u00e1
property.instance.display.cacheAsBitmap.opaque = S barvou
#after 22.0.2
property.document.backgroundColor = Barva pozad\u00ed