From ceed806703e7536668dc60923ea90cd9f9bceadb Mon Sep 17 00:00:00 2001 From: funa-tk <1781263+funa-tk@users.noreply.github.com> Date: Wed, 2 Oct 2019 16:06:55 +0900 Subject: [PATCH] [Fix] use "MS Gothic" rather than "Arial" on Win (#30) --- .../core/packetproxy/gui/BinaryTextPane.java | 12 +++++-- .../packetproxy/gui/ExtendedTextPane.java | 6 +++- .../packetproxy/gui/GUIHistoryBinary.java | 31 ++++++++++++++++--- .../java/core/packetproxy/gui/GUIMain.java | 10 ++++-- .../java/core/packetproxy/gui/GUIOption.java | 7 ++++- .../core/packetproxy/gui/HintTextField.java | 14 ++++++--- .../core/packetproxy/gui/RawTextPane.java | 13 ++++++-- .../java/core/packetproxy/util/SearchBox.java | 9 +++++- 8 files changed, 84 insertions(+), 18 deletions(-) diff --git a/src/main/java/core/packetproxy/gui/BinaryTextPane.java b/src/main/java/core/packetproxy/gui/BinaryTextPane.java index c45d82a..5b91179 100644 --- a/src/main/java/core/packetproxy/gui/BinaryTextPane.java +++ b/src/main/java/core/packetproxy/gui/BinaryTextPane.java @@ -42,12 +42,20 @@ public class BinaryTextPane extends ExtendedTextPane public BinaryTextPane() { setEditorKit(editor); - setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); + if (Utils.isWindows()) { + setFont(new Font("MS ゴシック", Font.PLAIN, 13)); + } else { + setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); + } JPopupMenu menu = new JPopupMenu(); JMenuItem title_encoders = new JMenuItem("エンコーダ"); - title_encoders.setFont(new Font("Arial", Font.BOLD, 12)); + if (Utils.isWindows()) { + title_encoders.setFont(new Font("MS ゴシック", Font.PLAIN, 13)); + } else { + title_encoders.setFont(new Font("Arial", Font.BOLD, 12)); + } title_encoders.setEnabled(false); menu.add(title_encoders); diff --git a/src/main/java/core/packetproxy/gui/ExtendedTextPane.java b/src/main/java/core/packetproxy/gui/ExtendedTextPane.java index 1085ee8..933d5e6 100644 --- a/src/main/java/core/packetproxy/gui/ExtendedTextPane.java +++ b/src/main/java/core/packetproxy/gui/ExtendedTextPane.java @@ -56,7 +56,11 @@ abstract class ExtendedTextPane extends JTextPane public ExtendedTextPane() { setEditorKit(editor); - setFont(new Font(Font.MONOSPACED, Font.PLAIN, FONT_SIZE)); + if (Utils.isWindows()) { + setFont(new Font("MS ゴシック", Font.PLAIN, 13)); + } else { + setFont(new Font(Font.MONOSPACED, Font.PLAIN, FONT_SIZE)); + } getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { diff --git a/src/main/java/core/packetproxy/gui/GUIHistoryBinary.java b/src/main/java/core/packetproxy/gui/GUIHistoryBinary.java index 1c45cac..c47625e 100644 --- a/src/main/java/core/packetproxy/gui/GUIHistoryBinary.java +++ b/src/main/java/core/packetproxy/gui/GUIHistoryBinary.java @@ -22,11 +22,20 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Arrays; + +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; import javax.swing.JTextPane; -import javax.swing.*; + +import org.apache.commons.lang3.ArrayUtils; + import packetproxy.common.Binary; import packetproxy.common.StringUtils; -import org.apache.commons.lang3.ArrayUtils; +import packetproxy.common.Utils; public class GUIHistoryBinary extends GUIHistoryPanel implements BinaryTextPane.DataChangedListener { @@ -52,7 +61,11 @@ public GUIHistoryBinary() hex_text.setParentHistory(this); hex_text.addDataChangedListener(this); //hex_text.setLineWrap(true); - hex_text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); + if (Utils.isWindows()) { + hex_text.setFont(new Font("MS ゴシック", Font.PLAIN, 13)); + } else { + hex_text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); + } hex_text.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { @@ -103,7 +116,11 @@ public void keyTyped(KeyEvent arg0) { ascii_text = new JTextPane(); //ascii_text.setLineWrap(true); - ascii_text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); + if (Utils.isWindows()) { + ascii_text.setFont(new Font("MS ゴシック", Font.PLAIN, 13)); + } else { + ascii_text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); + } ascii_text.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { @@ -128,7 +145,11 @@ public void mouseReleased(MouseEvent e) { scrollpane4.getVerticalScrollBar().setModel(scrollpane3.getVerticalScrollBar().getModel()); // 縦方向のスクロールをhex側と同期させる search_text = new JTextField(); - search_text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); + if (Utils.isWindows()) { + search_text.setFont(new Font("MS ゴシック", Font.PLAIN, 13)); + } else { + search_text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); + } search_text.addKeyListener(new KeyListener() { @Override public void keyReleased(KeyEvent arg0) { diff --git a/src/main/java/core/packetproxy/gui/GUIMain.java b/src/main/java/core/packetproxy/gui/GUIMain.java index 17d5091..0a3d359 100644 --- a/src/main/java/core/packetproxy/gui/GUIMain.java +++ b/src/main/java/core/packetproxy/gui/GUIMain.java @@ -43,6 +43,9 @@ import javax.swing.text.DefaultEditorKit; import javax.swing.text.JTextComponent; import javax.swing.text.Keymap; + +import com.sun.javafx.util.Utils; + import packetproxy.model.InterceptModel; import packetproxy.model.Packets; import packetproxy.util.PacketProxyUtility; @@ -175,8 +178,11 @@ private void setLookandFeel() throws Exception { } //Windowsだと日本語フォントを指定しないと文字化けする //TODO FONT指定は一か所に集める - UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("MS ゴシック", Font.PLAIN, 12)); - //UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("Arial", Font.PLAIN, 12)); + if (Utils.isWindows()) { + UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("MS ゴシック", Font.PLAIN, 13)); + } else { + UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("Arial", Font.PLAIN, 12)); + } setIconForWindows(); addShortcutForMac(); addDockIconForMac(); diff --git a/src/main/java/core/packetproxy/gui/GUIOption.java b/src/main/java/core/packetproxy/gui/GUIOption.java index 30f0347..bdd02ce 100644 --- a/src/main/java/core/packetproxy/gui/GUIOption.java +++ b/src/main/java/core/packetproxy/gui/GUIOption.java @@ -38,6 +38,7 @@ import org.apache.commons.io.FileUtils; +import packetproxy.common.Utils; import packetproxy.model.CAFactory; import packetproxy.model.CAs.CA; @@ -52,7 +53,11 @@ private JComponent createTitle(String title) { JLabel label = new JLabel(title); label.setForeground(Color.ORANGE); label.setBackground(Color.WHITE); - label.setFont(new Font("Arial", Font.BOLD, 14)); + if (Utils.isWindows()) { + label.setFont(new Font("Arial", Font.BOLD, 15)); + } else { + label.setFont(new Font("Arial", Font.BOLD, 14)); + } int label_height = label.getMaximumSize().height; label.setMaximumSize(new Dimension(Short.MAX_VALUE, label_height)); return label; diff --git a/src/main/java/core/packetproxy/gui/HintTextField.java b/src/main/java/core/packetproxy/gui/HintTextField.java index bef7291..c14e26e 100644 --- a/src/main/java/core/packetproxy/gui/HintTextField.java +++ b/src/main/java/core/packetproxy/gui/HintTextField.java @@ -25,6 +25,8 @@ import java.awt.event.FocusListener; import javax.swing.JTextField; +import packetproxy.common.Utils; + public class HintTextField extends JTextField { private static final long serialVersionUID = 1L; @@ -74,12 +76,16 @@ protected void paintComponent(Graphics g) { Font oldFont=g2.getFont(); Color oldColor=g2.getColor(); { - g2.setFont(getFont().deriveFont(Font.ITALIC)); - g2.setColor(Color.GRAY); - Insets insets=getBorder().getBorderInsets(this); int h=g2.getFontMetrics().getAscent(); - g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + if (Utils.isWindows()) { + g2.setColor(Color.LIGHT_GRAY); + } else { + g2.setFont(getFont().deriveFont(Font.ITALIC)); + g2.setColor(Color.GRAY); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + } g2.drawString(getHint(),insets.left,insets.top+h); } g2.setFont(oldFont); diff --git a/src/main/java/core/packetproxy/gui/RawTextPane.java b/src/main/java/core/packetproxy/gui/RawTextPane.java index 4e5bb83..395a667 100644 --- a/src/main/java/core/packetproxy/gui/RawTextPane.java +++ b/src/main/java/core/packetproxy/gui/RawTextPane.java @@ -125,8 +125,13 @@ public void keyPressed(KeyEvent e) { } }); + menu.addSeparator(); JMenuItem title_decoders = new JMenuItem("デコーダ"); - title_decoders.setFont(new Font("Arial", Font.BOLD, 12)); + if (Utils.isWindows()) { + title_decoders.setFont(new Font("MS ゴシック", Font.BOLD, 13)); + } else { + title_decoders.setFont(new Font("Arial", Font.BOLD, 12)); + } title_decoders.setEnabled(false); menu.add(title_decoders); @@ -210,7 +215,11 @@ public void actionPerformed(ActionEvent actionEvent) { menu.addSeparator(); JMenuItem title_encoders = new JMenuItem("エンコーダ"); - title_encoders.setFont(new Font("Arial", Font.BOLD, 12)); + if (Utils.isWindows()) { + title_encoders.setFont(new Font("MS ゴシック", Font.BOLD, 13)); + } else { + title_encoders.setFont(new Font("Arial", Font.BOLD, 12)); + } title_encoders.setEnabled(false); menu.add(title_encoders); diff --git a/src/main/java/core/packetproxy/util/SearchBox.java b/src/main/java/core/packetproxy/util/SearchBox.java index c466a22..ecbc220 100644 --- a/src/main/java/core/packetproxy/util/SearchBox.java +++ b/src/main/java/core/packetproxy/util/SearchBox.java @@ -22,6 +22,9 @@ import java.awt.event.KeyListener; import javax.swing.JTextField; import javax.swing.JTextPane; + +import packetproxy.common.Utils; + import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.BoxLayout; @@ -45,7 +48,11 @@ public String getText() { public SearchBox() { search_text = new JTextField(); - search_text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); + if (Utils.isWindows()) { + search_text.setFont(new Font("MS ゴシック", Font.PLAIN, 13)); + } else { + search_text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); + } search_text.addKeyListener(new KeyListener() { private String prev_word = null; private int cur_pos = 0;