From 3d9e44d3f17d9a67f38b412170b6f2a03395cd7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Wed, 7 May 2025 09:42:40 +0200 Subject: [PATCH] Added: Configure grid and guides color --- .../flash/configuration/Configuration.java | 20 ++++ .../ConfigurationDefaultColor.java | 34 +++++++ .../flash/gui/AdvancedSettingsDialog.java | 16 ++++ .../gui/ConfigurationColorSelection.java | 94 +++++++++++++++++++ .../decompiler/flash/gui/ImagePanel.java | 12 +-- .../locales/AdvancedSettingsDialog.properties | 5 + 6 files changed, 174 insertions(+), 7 deletions(-) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationDefaultColor.java create mode 100644 src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 501d45e7f..c2c4dc421 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.helpers.FontHelper; import com.jpexs.decompiler.flash.importers.TextImportResizeTextBoundsMode; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; +import java.awt.Color; import java.awt.Font; import java.io.BufferedOutputStream; import java.io.File; @@ -1101,6 +1102,14 @@ public final class Configuration { @ConfigurationCategory("display") public static ConfigurationItem gridOverObjects = null; + @ConfigurationDefaultColor("#949494") + @ConfigurationCategory("display") + public static ConfigurationItem gridColor = null; + + @ConfigurationDefaultColor("#00FF00") + @ConfigurationCategory("display") + public static ConfigurationItem guidesColor = null; + private enum OSId { WINDOWS, OSX, UNIX } @@ -1484,6 +1493,17 @@ public final class Configuration { mingc.setTime(new Date(aCalendar.value())); defaultValue = mingc; } + + ConfigurationDefaultColor aColor = field.getAnnotation(ConfigurationDefaultColor.class); + if (aColor != null) { + Pattern p = Pattern.compile("#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$"); + Matcher m = p.matcher(aColor.value()); + if (m.matches()) { + defaultValue = new Color(Integer.parseInt(m.group(1), 16), Integer.parseInt(m.group(2), 16), Integer.parseInt(m.group(3), 16)); + } else { + defaultValue = Color.black; + } + } return defaultValue; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationDefaultColor.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationDefaultColor.java new file mode 100644 index 000000000..ca709f524 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationDefaultColor.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010-2024 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.configuration; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Configuration default Color annotation. + * + * @author JPEXS + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigurationDefaultColor { + + String value(); +} diff --git a/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java b/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java index 2164a8962..eb9bdd4f1 100644 --- a/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java @@ -35,6 +35,8 @@ import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.ParameterizedType; @@ -55,6 +57,7 @@ import java.util.ResourceBundle; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; +import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -68,6 +71,8 @@ import javax.swing.JTextField; import javax.swing.SpringLayout; import javax.swing.UIManager; import javax.swing.WindowConstants; +import javax.swing.border.BevelBorder; +import javax.swing.border.Border; import javax.swing.table.DefaultTableModel; import org.pushingpixels.substance.api.ColorSchemeAssociationKind; import org.pushingpixels.substance.api.ComponentState; @@ -409,6 +414,9 @@ public class AdvancedSettingsDialog extends AppDialog { Logger.getLogger(AdvancedSettingsDialog.class.getName()).log(Level.SEVERE, null, ex); } } + if (itemType == Color.class) { + defaultValue = ConfigurationColorSelection.colorToHex((Color) defaultValue); + } String locNameHtml = locName; if (!filter.trim().equals("")) { locNameHtml = Pattern.compile(Pattern.quote(filter), Pattern.UNICODE_CASE + Pattern.CASE_INSENSITIVE).matcher(locNameHtml).replaceAll("{bold}$0{/bold}"); @@ -464,6 +472,11 @@ public class AdvancedSettingsDialog extends AppDialog { cb.setSelected((Boolean) item.get()); cb.setToolTipText(description); c = cb; + } else if (itemType == Color.class) { + ConfigurationColorSelection cb = new ConfigurationColorSelection(item, (Color) item.get(), description); + + cb.setMaximumSize(new Dimension(Integer.MAX_VALUE, cb.getPreferredSize().height)); + c = cb; } else if (itemType.isEnum()) { JComboBox cb = new JComboBox<>(); @SuppressWarnings("unchecked") @@ -575,6 +588,9 @@ public class AdvancedSettingsDialog extends AppDialog { if (itemType == Boolean.class) { value = ((JCheckBox) c).isSelected(); } + if (itemType == Color.class) { + value = ((ConfigurationColorSelection) c).getValue(); + } if (itemType == Calendar.class) { Calendar cal = Calendar.getInstance(); diff --git a/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java b/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java new file mode 100644 index 000000000..ef4808370 --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2025 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui; + +import com.jpexs.decompiler.flash.configuration.ConfigurationItem; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.BevelBorder; + +/** + * + * @author JPEXS + */ +public class ConfigurationColorSelection extends JPanel { + private JPanel colorPanel; + + public ConfigurationColorSelection(ConfigurationItem item, Color value, String description) { + setLayout(new FlowLayout(FlowLayout.LEFT)); + colorPanel = new JPanel(); + colorPanel.setToolTipText(description); + colorPanel.setSize(16, 16); + colorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); + JLabel colorLabel = new JLabel(); + colorPanel.setBackground(value); + + colorPanel.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + colorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); + } + + @Override + public void mouseReleased(MouseEvent e) { + colorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); + } + + @Override + public void mouseClicked(MouseEvent e) { + Color newColor = ViewMessages.showColorDialog(colorPanel, colorPanel.getBackground(), false); + if (newColor != null) { + colorPanel.setBackground(newColor); + + } + } + + }); + colorLabel.setText(colorToHex(value)); + colorLabel.setToolTipText(description); + + + add(colorPanel); + 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 Color getValue() { + return colorPanel.getBackground(); + } + +} diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index e93070ec9..c6bb9ef55 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -385,8 +385,6 @@ public final class ImagePanel extends JPanel implements MediaDisplay { private List guidesY = new ArrayList<>(); - private static final Color GUIDES_COLOR = Color.green; - private static final int GUIDE_THICKNESS = 20; private static final int GUIDE_FONT_HEIGHT = 11; @@ -912,7 +910,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } private static void drawGridSwf(Graphics2D g, Rectangle realRect, double zoom) { - g.setColor(new Color(0x94, 0x94, 0x94)); + g.setColor(Configuration.gridColor.get()); double x; double y; int ix; @@ -1011,7 +1009,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { private void drawGridNoSwf(Graphics2D g2, int x, int y) { double zoomDouble = getRealZoom(); - g2.setColor(new Color(0x94, 0x94, 0x94)); + g2.setColor(Configuration.gridColor.get()); double gx; double gy; int ix = 0; @@ -3298,7 +3296,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } } - g2d.setColor(GUIDES_COLOR); + g2d.setColor(Configuration.guidesColor.get()); if (draggingGuideX && lastMouseEvent != null) { g2d.drawLine(guideDragX, 0, guideDragX, getHeight()); } @@ -3737,7 +3735,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { g2.fillRect(0, 0, GUIDE_THICKNESS, GUIDE_THICKNESS); if (guideDragX > -1) { - g2.setColor(GUIDES_COLOR); + g2.setColor(Configuration.guidesColor.get()); g2.drawLine(GUIDE_THICKNESS + guideDragX, 0, GUIDE_THICKNESS + guideDragX, GUIDE_THICKNESS); } @@ -3811,7 +3809,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { g2.draw(gp); if (guideDragY > -1) { - g2.setColor(GUIDES_COLOR); + g2.setColor(Configuration.guidesColor.get()); g2.drawLine(0, guideDragY, GUIDE_THICKNESS, guideDragY); } } diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index 81b78c621..572152034 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -593,3 +593,8 @@ config.description.snapToGrid = Enables snapping cursor to grid while moving obj config.name.gridOverObjects = Show grid over objects config.description.gridOverObjects = When the grid is displayed, it is shown over objects on stage. +config.name.gridColor = Grid color +config.description.gridColor = Color of the drawn grid. + +config.name.guidesColor = Guides color +config.description.guidesColor = Color of the drawn guides.