Skip to content

Commit

Permalink
Fixed font size and differences in rendering previews on high def dis…
Browse files Browse the repository at this point in the history
…plays
  • Loading branch information
KodeMunkie committed Apr 29, 2022
1 parent 5bbc00a commit ba87c1c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
55 changes: 43 additions & 12 deletions src/main/java/uk/co/silentsoftware/ui/ImageToZxSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Set;

import static uk.co.silentsoftware.config.LanguageSupport.getCaption;

Expand All @@ -54,7 +55,9 @@ public class ImageToZxSpec {
private static final ImageIcon SETTINGS_ICON = new ImageIcon(ImageToZxSpec.class.getResource("/icons/Gear.png"));
private static final ImageIcon PREVIEW_ICON = new ImageIcon(ImageToZxSpec.class.getResource("/icons/Coherence.png"));
private static final String SINCLAIR_IMAGE_PATH = "/icons/sinclair.png";


private static final int DEFAULT_FONT_SIZE = 14;

/**
* The message to show when idle
*/
Expand Down Expand Up @@ -105,12 +108,12 @@ public class ImageToZxSpec {
/**
* The options dialog
*/
private static PreferencesDialog preferences = new PreferencesDialog();
private static PreferencesDialog preferences;

/**
* The preview window
*/
private final PopupPreviewFrame preview = new PopupPreviewFrame(new UiCallback());
private PopupPreviewFrame preview;

/**
* Main dialog preview panel showing progress
Expand Down Expand Up @@ -145,7 +148,10 @@ private void createUserInterface() {

// Initialises this app's look and feel settings
initLookAndFeel();


preferences = new PreferencesDialog();
preview = new PopupPreviewFrame(new UiCallback());

// Drag and drop support and the icon image
frame.setDropTarget(new DropTarget(frame, new CustomDropTargetListener(new UiCallback())));

Expand All @@ -162,7 +168,7 @@ private void createUserInterface() {
frame.getContentPane().add(createToolbar(), BorderLayout.PAGE_START);

// Add the panel for rendering the original + result
frame.getContentPane().add(createRenderPanel(), BorderLayout.CENTER);
frame.getContentPane().add(createRenderPanel(), BorderLayout.CENTER);

// Add the status message box at the bottom of the pane
frame.getContentPane().add(createStatusBox(), BorderLayout.PAGE_END);
Expand Down Expand Up @@ -192,12 +198,32 @@ private void createUserInterface() {
private void initLookAndFeel() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
setDefaultFontSize(DEFAULT_FONT_SIZE);
} catch(Exception e) {
log.debug("Unable to set the platform lnf",e);
// Pah just ignore this error, we'll just have a naff looking UI
}
}



/**
* Sets the a sensible font size suitable for hidef displays
* @param size
*/
public void setDefaultFontSize(int size) {
Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet();
Object[] keys = keySet.toArray(new Object[keySet.size()]);
for (Object key : keys) {
if (key != null && key.toString().toLowerCase().contains("font")) {
Font font = UIManager.getDefaults().getFont(key);
if (font != null) {
font = font.deriveFont((float)size);
UIManager.put(key, font);
}
}
}
}

/**
* Creates a window listener that shuts down the app gracefully
*
Expand Down Expand Up @@ -233,6 +259,7 @@ private void prepareFrameForLogoImage() {
Dimension dim = new Dimension(specLogo.getWidth(),
specLogo.getHeight()+toolBar.getHeight()+statusBox.getHeight()+frame.getInsets().top+frame.getInsets().bottom+menubar.getHeight());
frame.setSize(dim);
frame.setMinimumSize(dim);
frame.setPreferredSize(dim);
frame.repaint();
frame.setLocationRelativeTo(null);
Expand Down Expand Up @@ -321,14 +348,15 @@ private Component createStatusBox() {

/**
* Creates the main dialog's main panel for rendering the preview
*
* Nb. Needs to be a Swing Jpanel inside an AWT panel since image
* rendering differs from the popup preview frame otherwise!
*
* @return the render panel
*/
private JPanel createRenderPanel() {
/*
The panel for rendering the images
*/
return new JPanel() {
private Panel createRenderPanel() {

Panel outer = new Panel();
JPanel inner = new JPanel() {
static final long serialVersionUID = 0;

@Override
Expand All @@ -346,6 +374,9 @@ public void paint(Graphics g) {
}
}
};
outer.add(inner);
outer.setLayout(new GridLayout(1,1));
return outer;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/uk/co/silentsoftware/ui/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PreferencesDialog extends JFrame {
private final Logger log = LoggerFactory.getLogger(this.getClass());

private static final long serialVersionUID = 1L;

private final List<DitherChangedListener> ditherChangedListeners = new ArrayList<>();

private final JFrame currentInstance;
Expand All @@ -80,7 +80,7 @@ class PreferencesDialog extends JFrame {
// The frame defaults
setIconImage(ImageToZxSpec.IMAGE_ICON.getImage());
setTitle(getCaption("tab_item_control_panel"));
setSize(600,480);
setSize(820,480);
setLocationRelativeTo(null);
setResizable(false);

Expand Down

0 comments on commit ba87c1c

Please sign in to comment.