• R/O
  • HTTP
  • SSH
  • HTTPS

CharacterManaJ: Commit

キャラクターなんとかJの本体


Commit MetaInfo

Revision6fcc42f43b9998b544967214866213c21ceb7e6b (tree)
Time2019-01-13 12:51:25
Authorseraphy <seraphy@user...>
Commiterseraphy

Log Message

アイコンボタンまわりのHiDPI対応

Change Summary

Incremental Difference

--- a/src/main/java/charactermanaj/ui/ColorDialog.java
+++ b/src/main/java/charactermanaj/ui/ColorDialog.java
@@ -78,6 +78,7 @@ import charactermanaj.model.PartsCategory;
7878 import charactermanaj.model.PartsIdentifier;
7979 import charactermanaj.ui.model.ColorChangeEvent;
8080 import charactermanaj.ui.model.ColorChangeListener;
81+import charactermanaj.ui.util.ScaleSupport;
8182 import charactermanaj.ui.util.SpinnerWheelSupportListener;
8283 import charactermanaj.util.ErrorMessageHelper;
8384 import charactermanaj.util.LocalizedResourcePropertyLoader;
@@ -172,6 +173,8 @@ public class ColorDialog extends JDialog {
172173 captionBase = caption + name;
173174 setTitle(captionBase);
174175
176+ ScaleSupport scaleSupport = ScaleSupport.getInstance(this);
177+
175178 // ダイアログを非表示にする.
176179 final AbstractAction actHide = new AbstractAction() {
177180 private static final long serialVersionUID = 1L;
--- a/src/main/java/charactermanaj/ui/ImageSelectPanel.java
+++ b/src/main/java/charactermanaj/ui/ImageSelectPanel.java
@@ -461,10 +461,9 @@ public class ImageSelectPanel extends JPanel {
461461 btnPanelGrp.add(toolBar, BorderLayout.NORTH);
462462
463463 if (partsCategory.isMultipleSelectable()) {
464- UIHelper uiUty = UIHelper.getInstance();
465- JButton upBtn = uiUty.createTransparentButton("icons/arrow_up.png", "icons/arrow_up2.png");
466- JButton downBtn = uiUty.createTransparentButton("icons/arrow_down.png", "icons/arrow_down2.png");
467- JButton sortBtn = uiUty.createTransparentButton("icons/sort.png", "icons/sort2.png");
464+ JButton upBtn = uiUtl.createTransparentButton("icons/arrow_up.png", "icons/arrow_up2.png");
465+ JButton downBtn = uiUtl.createTransparentButton("icons/arrow_down.png", "icons/arrow_down2.png");
466+ JButton sortBtn = uiUtl.createTransparentButton("icons/sort.png", "icons/sort2.png");
468467
469468 upBtn.setToolTipText(strings.getProperty("tooltip.up"));
470469 downBtn.setToolTipText(strings.getProperty("tooltip.down"));
--- a/src/main/java/charactermanaj/ui/MainFrame.java
+++ b/src/main/java/charactermanaj/ui/MainFrame.java
@@ -422,8 +422,14 @@ public class MainFrame extends JFrame
422422 }
423423 });
424424
425+ // アイコンスケールの設定
426+ ScaleSupport scaleSupport = ScaleSupport.getInstance(this);
427+ UIHelper uiUtl = UIHelper.getInstance();
428+ uiUtl.setScaleX(scaleSupport.getManualScaleX());
429+ uiUtl.setScaleY(scaleSupport.getManualScaleY());
430+
425431 // アイコンの設定
426- icon = UIHelper.getInstance().getImage("icons/icon.png");
432+ icon = uiUtl.getImage("icons/icon.png");
427433 setIconImage(icon);
428434
429435 // 画面コンポーネント作成
@@ -695,7 +701,9 @@ public class MainFrame extends JFrame
695701 PartsImageDirectoryWatchAgentFactory agentFactory = PartsImageDirectoryWatchAgentFactory.getFactory();
696702 watchAgent = agentFactory.getAgent(characterData);
697703
698- previewPane = new PreviewPanel();
704+ ScaleSupport scaleSupport = ScaleSupport.getInstance(this);
705+
706+ previewPane = new PreviewPanel(scaleSupport);
699707 previewPane.setTitle(defaultPartsSetTitle);
700708 previewPane.addPreviewPanelListener(new PreviewPanelListener() {
701709 public void addFavorite(PreviewPanelEvent e) {
@@ -741,8 +749,6 @@ public class MainFrame extends JFrame
741749
742750 imageSelectPanels = new ImageSelectPanelList();
743751
744- ScaleSupport scaleSupport = ScaleSupport.getInstance(this);
745-
746752 JPanel imgSelectPanelsPanel = new JPanel();
747753 BoxLayout bl = new BoxLayout(imgSelectPanelsPanel, BoxLayout.PAGE_AXIS);
748754 imgSelectPanelsPanel.setLayout(bl);
--- a/src/main/java/charactermanaj/ui/PreviewPanel.java
+++ b/src/main/java/charactermanaj/ui/PreviewPanel.java
@@ -69,6 +69,7 @@ import charactermanaj.Main;
6969 import charactermanaj.graphics.filters.BackgroundColorFilter;
7070 import charactermanaj.graphics.filters.BackgroundColorFilter.BackgroundColorMode;
7171 import charactermanaj.model.AppConfig;
72+import charactermanaj.ui.util.ScaleSupport;
7273 import charactermanaj.ui.util.ScrollPaneDragScrollSupport;
7374 import charactermanaj.util.LocalizedResourcePropertyLoader;
7475 import charactermanaj.util.UIHelper;
@@ -221,7 +222,7 @@ public class PreviewPanel extends JPanel {
221222 private LinkedList<PreviewPanelListener> listeners = new LinkedList<PreviewPanelListener>();
222223
223224
224- public PreviewPanel() {
225+ public PreviewPanel(ScaleSupport scaleSupport) {
225226 setLayout(new BorderLayout());
226227
227228 final AppConfig appConfig = AppConfig.getInstance();
@@ -1836,7 +1837,7 @@ class PreviewControlPanel extends JPanel {
18361837 final Properties strings = LocalizedResourcePropertyLoader.getCachedInstance()
18371838 .getLocalizedProperties(STRINGS_RESOURCE);
18381839
1839- UIHelper uiHelper = UIHelper.getInstance();
1840+ final UIHelper uiHelper = UIHelper.getInstance();
18401841
18411842 // ピンアイコン
18421843 Icon pinIcon = uiHelper.createTwoStateIcon(
@@ -1849,10 +1850,10 @@ class PreviewControlPanel extends JPanel {
18491850 // 円ボタン型チェックボックス用アイコンの実装
18501851 final Icon stateIcon = new Icon() {
18511852 public int getIconHeight() {
1852- return 12;
1853+ return (int)(12 * uiHelper.getScaleX());
18531854 }
18541855 public int getIconWidth() {
1855- return 6;
1856+ return (int)(6 * uiHelper.getScaleY());
18561857 };
18571858 public void paintIcon(Component c, Graphics g, int x, int y) {
18581859 boolean sw = false;
--- a/src/main/java/charactermanaj/util/UIHelper.java
+++ b/src/main/java/charactermanaj/util/UIHelper.java
@@ -3,6 +3,7 @@ package charactermanaj.util;
33 import java.awt.Component;
44 import java.awt.Container;
55 import java.awt.Graphics;
6+import java.awt.Image;
67 import java.awt.image.BufferedImage;
78 import java.io.IOException;
89 import java.net.URL;
@@ -34,6 +35,26 @@ public final class UIHelper {
3435 return singleton;
3536 }
3637
38+ private double scaleX = 1;
39+
40+ private double scaleY = 1;
41+
42+ public void setScaleX(double scaleX) {
43+ this.scaleX = scaleX;
44+ }
45+
46+ public double getScaleX() {
47+ return scaleX;
48+ }
49+
50+ public void setScaleY(double scaleY) {
51+ this.scaleY = scaleY;
52+ }
53+
54+ public double getScaleY() {
55+ return scaleY;
56+ }
57+
3758 /**
3859 * 指定したコンテナに含まれる指定したコンポーネント型のすべてのコンポーネントを返す.<br>
3960 * 一つも該当するものがなければ空を返す
@@ -102,13 +123,14 @@ public final class UIHelper {
102123 }
103124 int w = iconImage.getWidth();
104125 int h = iconImage.getHeight();
105- g.drawImage(iconImage, x, y, w, h, 0, 0, w, h, null);
126+ g.drawImage(iconImage, x, y,
127+ (int)(w * scaleX), (int)(h * scaleY), 0, 0, w, h, null);
106128 }
107129 public int getIconHeight() {
108- return pinIcon1.getHeight();
130+ return (int)(pinIcon1.getHeight() * scaleY);
109131 }
110132 public int getIconWidth() {
111- return pinIcon1.getWidth();
133+ return (int)(pinIcon1.getWidth() * scaleX);
112134 }
113135 };
114136
@@ -126,7 +148,7 @@ public final class UIHelper {
126148 throw new IllegalArgumentException();
127149 }
128150 JButton btn = new JButton();
129- btn.setIcon(new ImageIcon(getImage(iconName)));
151+ btn.setIcon(createImageIcon(iconName));
130152
131153 return btn;
132154 }
@@ -152,11 +174,11 @@ public final class UIHelper {
152174 if (normal == null || normal.length() == 0) {
153175 throw new IllegalArgumentException();
154176 }
155- ImageIcon normIcon = new ImageIcon(getImage(normal));
177+ ImageIcon normIcon = createImageIcon(normal);
156178 JButton btn = new JButton(normIcon);
157179
158180 if (rollover != null && rollover.length() != 0) {
159- ImageIcon rolloverIcon = new ImageIcon(getImage(rollover));
181+ ImageIcon rolloverIcon = createImageIcon(rollover);
160182 btn.setRolloverEnabled(true);
161183 btn.setRolloverIcon(rolloverIcon);
162184 btn.setPressedIcon(rolloverIcon);
@@ -170,6 +192,26 @@ public final class UIHelper {
170192 }
171193
172194 /**
195+ * イメージアイコンを取得する。
196+ * 設定されているスケールに拡大されたイメージでアイコンが設定される。
197+ * @param name アイコンリソース名
198+ * @return スケール済みのイメージアイコン
199+ */
200+ public ImageIcon createImageIcon(String name) {
201+ Image img;
202+ if (scaleX != 1 || scaleY != 1) {
203+ BufferedImage bimg = getImage(name);
204+ img = bimg.getScaledInstance(
205+ (int)(bimg.getWidth() * scaleX),
206+ (int)(bimg.getHeight() * scaleY),
207+ Image.SCALE_DEFAULT);
208+ } else {
209+ img = getImage(name);
210+ }
211+ return new ImageIcon(img);
212+ }
213+
214+ /**
173215 * リソースから画像を取得する.<br>
174216 * 画像が取得できない場合は実行時例外を返す.<br>
175217 * @param name リソース
Show on old repository browser