From 7860992d92e62dd8280b528cf340e2a41b3c626a Mon Sep 17 00:00:00 2001 From: Argent77 <4519923+Argent77@users.noreply.github.com> Date: Sun, 30 Aug 2020 17:17:04 +0200 Subject: [PATCH] Add "Properties" feature to TTF resource viewer --- .../resource/graphics/MosResource.java | 2 +- .../infinity/resource/other/TtfResource.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/org/infinity/resource/graphics/MosResource.java b/src/org/infinity/resource/graphics/MosResource.java index 868e19412..e49d9477b 100644 --- a/src/org/infinity/resource/graphics/MosResource.java +++ b/src/org/infinity/resource/graphics/MosResource.java @@ -394,7 +394,7 @@ private void showProperties() sb.append(br).append("Referenced PVRZ pages:").append(br); sb.append(pageList.toString()).append(br); } - sb.append(""); + sb.append(""); JOptionPane.showMessageDialog(panel, sb.toString(), "Properties of " + resName, JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { diff --git a/src/org/infinity/resource/other/TtfResource.java b/src/org/infinity/resource/other/TtfResource.java index ca014e84a..b9fc1c7dc 100644 --- a/src/org/infinity/resource/other/TtfResource.java +++ b/src/org/infinity/resource/other/TtfResource.java @@ -13,11 +13,13 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.InputStream; +import java.util.Locale; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; @@ -32,6 +34,7 @@ import org.infinity.gui.ButtonPanel; import org.infinity.gui.ViewerUtil; +import org.infinity.icon.Icons; import org.infinity.resource.Resource; import org.infinity.resource.ResourceFactory; import org.infinity.resource.ViewableContainer; @@ -39,6 +42,8 @@ public class TtfResource implements Resource, DocumentListener, ActionListener { + private static final ButtonPanel.Control Properties = ButtonPanel.Control.CUSTOM_1; + private static final String DEFAULT_STRING = "The quick brown fox jumps over the lazy dog. 1234567890"; private static final int[] FONT_SIZE = { 12, 18, 24, 36, 48, 60, 72, 96, 128, 192 }; @@ -113,6 +118,9 @@ public JComponent makeViewer(ViewableContainer container) scroll.setBorder(BorderFactory.createLoweredBevelBorder()); ((JButton)buttonPanel.addControl(ButtonPanel.Control.EXPORT_BUTTON)).addActionListener(this); + JButton bProperties = new JButton("Properties...", Icons.getIcon(Icons.ICON_EDIT_16)); + bProperties.addActionListener(this); + buttonPanel.addControl(bProperties, Properties); panel = new JPanel(new BorderLayout()); panel.add(pInput, BorderLayout.NORTH); @@ -131,6 +139,8 @@ public void actionPerformed(ActionEvent event) { if (buttonPanel.getControlByType(ButtonPanel.Control.EXPORT_BUTTON) == event.getSource()) { ResourceFactory.exportResource(entry, panel.getTopLevelAncestor()); + } else if (buttonPanel.getControlByType(Properties) == event.getSource()) { + showProperties(); } } @@ -215,4 +225,19 @@ private void updateText(String text) tpDisplay.setCaretPosition(0); } } + + // Shows message box about basic resource properties + private void showProperties() + { + String resName = entry.getResourceName().toUpperCase(Locale.ENGLISH); + String fontName = font.getFontName(); + String fontFamily = font.getFamily(); + + StringBuilder sb = new StringBuilder(""); + sb.append(""); + sb.append(""); + sb.append("
Font name:").append(fontName).append("
Font family:").append(fontFamily).append("
"); + JOptionPane.showMessageDialog(panel, sb.toString(), "Properties of " + resName, + JOptionPane.INFORMATION_MESSAGE); + } }