Skip to content

Commit

Permalink
Add "Properties" feature to TTF resource viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Aug 30, 2020
1 parent 8fcf47d commit 7860992
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/org/infinity/resource/graphics/MosResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private void showProperties()
sb.append(br).append("Referenced PVRZ pages:").append(br);
sb.append(pageList.toString()).append(br);
}
sb.append("</code></html>");
sb.append("</div></html>");
JOptionPane.showMessageDialog(panel, sb.toString(), "Properties of " + resName,
JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
Expand Down
25 changes: 25 additions & 0 deletions src/org/infinity/resource/other/TtfResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,13 +34,16 @@

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;
import org.infinity.resource.key.ResourceEntry;

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 };

Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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("<html><table align=\"left\" border=\"0\">");
sb.append("<tr><td>Font name:</td><td>").append(fontName).append("</td></tr>");
sb.append("<tr><td>Font family:</td><td>").append(fontFamily).append("</td></tr>");
sb.append("</table></html>");
JOptionPane.showMessageDialog(panel, sb.toString(), "Properties of " + resName,
JOptionPane.INFORMATION_MESSAGE);
}
}

0 comments on commit 7860992

Please sign in to comment.