replaced retina test with one that works

This commit is contained in:
Denis Molony 2016-07-30 13:04:55 +10:00
parent 3a4db5fc31
commit 2bec5a83f6
7 changed files with 52 additions and 54 deletions

View File

@ -6,6 +6,7 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.util.List; import java.util.List;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -31,6 +32,7 @@ class DiskLayoutImage extends JPanel implements Scrollable, RedoListener
private boolean showFreeSectors; private boolean showFreeSectors;
private final DiskLayoutSelection selectionHandler = new DiskLayoutSelection (); private final DiskLayoutSelection selectionHandler = new DiskLayoutSelection ();
private boolean redo; private boolean redo;
private boolean retinaTest;
// set defaults (used until a real disk is set) // set defaults (used until a real disk is set)
private int bw = 30; private int bw = 30;
@ -38,7 +40,7 @@ class DiskLayoutImage extends JPanel implements Scrollable, RedoListener
private int gw = 8; private int gw = 8;
private int gh = 35; private int gh = 35;
private boolean retina; // private boolean retina;
public DiskLayoutImage () public DiskLayoutImage ()
{ {
@ -64,6 +66,10 @@ class DiskLayoutImage extends JPanel implements Scrollable, RedoListener
setPreferredSize (new Dimension (gw * bw + 1, gh * bh + 1)); setPreferredSize (new Dimension (gw * bw + 1, gh * bh + 1));
selectionHandler.setSelection (null); selectionHandler.setSelection (null);
Graphics2D g = (Graphics2D) this.getGraphics ();
retinaTest = g.getFontRenderContext ().getTransform ()
.equals (AffineTransform.getScaleInstance (2.0, 2.0));
repaint (); repaint ();
} }
@ -78,11 +84,11 @@ class DiskLayoutImage extends JPanel implements Scrollable, RedoListener
repaint (); repaint ();
} }
public void setRetina (boolean value) // public void setRetina (boolean value)
{ // {
retina = value; // retina = value;
repaint (); // repaint ();
} // }
void setSelection (List<DiskAddress> sectors) void setSelection (List<DiskAddress> sectors)
{ {
@ -155,7 +161,7 @@ class DiskLayoutImage extends JPanel implements Scrollable, RedoListener
g.setColor (type.colour); g.setColor (type.colour);
// this is weird, the retina OSX screen needs the second fillRect // this is weird, the retina OSX screen needs the second fillRect
// see also DiskLegendPanel.paint() // see also DiskLegendPanel.paint()
if (retina) if (retinaTest)
g.fillRect (rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2); g.fillRect (rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2);
else else
g.fillRect (rect.x + 2, rect.y + 2, rect.width - 3, rect.height - 3); g.fillRect (rect.x + 2, rect.y + 2, rect.width - 3, rect.height - 3);

View File

@ -31,7 +31,7 @@ class DiskLayoutPanel extends JPanel
//, FontChangeListener //, FontChangeListener
{ {
private static final int SIZE = 15; // basic unit of a display block private static final int SIZE = 15; // basic unit of a display block
private static final String PREFS_RETINA = "retina"; // private static final String PREFS_RETINA = "retina";
private final Preferences prefs; private final Preferences prefs;
private final MenuHandler mh; private final MenuHandler mh;
@ -73,7 +73,7 @@ class DiskLayoutPanel extends JPanel
add (sp, BorderLayout.CENTER); add (sp, BorderLayout.CENTER);
add (legendPanel, BorderLayout.SOUTH); add (legendPanel, BorderLayout.SOUTH);
mh.retinaItem.setAction (new RetinaAction (this)); // mh.retinaItem.setAction (new RetinaAction (this));
} }
// public DiskLayoutPanel (FormattedDisk disk) // public DiskLayoutPanel (FormattedDisk disk)
@ -122,11 +122,11 @@ class DiskLayoutPanel extends JPanel
repaint (); repaint ();
} }
public void setRetina (boolean value) // public void setRetina (boolean value)
{ // {
image.setRetina (value); // image.setRetina (value);
legendPanel.setRetina (value); // legendPanel.setRetina (value);
} // }
public void setHex (boolean hex) public void setHex (boolean hex)
{ {
@ -257,14 +257,14 @@ class DiskLayoutPanel extends JPanel
@Override @Override
public void quit (Preferences arg0) public void quit (Preferences arg0)
{ {
prefs.putBoolean (PREFS_RETINA, mh.retinaItem.isSelected ()); // prefs.putBoolean (PREFS_RETINA, mh.retinaItem.isSelected ());
} }
@Override @Override
public void restore (Preferences arg0) public void restore (Preferences arg0)
{ {
mh.retinaItem.setSelected (prefs.getBoolean (PREFS_RETINA, false)); // mh.retinaItem.setSelected (prefs.getBoolean (PREFS_RETINA, false));
setRetina (mh.retinaItem.isSelected ()); // setRetina (mh.retinaItem.isSelected ());
} }
// @Override // @Override

View File

@ -4,6 +4,8 @@ import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -13,6 +15,7 @@ import com.bytezone.common.Platform.FontType;
import com.bytezone.diskbrowser.disk.FormattedDisk; import com.bytezone.diskbrowser.disk.FormattedDisk;
import com.bytezone.diskbrowser.disk.SectorType; import com.bytezone.diskbrowser.disk.SectorType;
import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails; import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails;
import com.bytezone.diskbrowser.utilities.Utility;
class DiskLegendPanel extends JPanel class DiskLegendPanel extends JPanel
{ {
@ -22,7 +25,8 @@ class DiskLegendPanel extends JPanel
private FormattedDisk disk; private FormattedDisk disk;
private LayoutDetails layoutDetails; private LayoutDetails layoutDetails;
private final Font font; private final Font font;
private boolean retina; // private boolean retina;
private boolean retinaTest;
public DiskLegendPanel () public DiskLegendPanel ()
{ {
@ -34,14 +38,19 @@ class DiskLegendPanel extends JPanel
{ {
this.disk = disk; this.disk = disk;
layoutDetails = details; layoutDetails = details;
Graphics2D g = (Graphics2D) this.getGraphics ();
retinaTest = g.getFontRenderContext ().getTransform ()
.equals (AffineTransform.getScaleInstance (2.0, 2.0));
repaint (); repaint ();
} }
public void setRetina (boolean value) // public void setRetina (boolean value)
{ // {
retina = value; // retina = value;
repaint (); // repaint ();
} // }
@Override @Override
public Dimension getPreferredSize () public Dimension getPreferredSize ()
@ -61,6 +70,7 @@ class DiskLegendPanel extends JPanel
int count = 0; int count = 0;
int lineHeight = 20; int lineHeight = 20;
System.out.println (Utility.test ((Graphics2D) g));
for (SectorType type : disk.getSectorTypeList ()) for (SectorType type : disk.getSectorTypeList ())
{ {
@ -73,7 +83,7 @@ class DiskLegendPanel extends JPanel
// draw the colour // draw the colour
g.setColor (type.colour); g.setColor (type.colour);
if (retina) if (retinaTest)
g.fillRect (x + 1, y + 1, layoutDetails.block.width - 2, g.fillRect (x + 1, y + 1, layoutDetails.block.width - 2,
layoutDetails.block.height - 2); layoutDetails.block.height - 2);
else else

View File

@ -64,7 +64,7 @@ public class MenuHandler
JMenuItem colourQuirksItem = new JCheckBoxMenuItem ("Colour quirks"); JMenuItem colourQuirksItem = new JCheckBoxMenuItem ("Colour quirks");
JMenuItem monochromeItem = new JCheckBoxMenuItem ("Monochrome"); JMenuItem monochromeItem = new JCheckBoxMenuItem ("Monochrome");
JMenuItem debuggingItem = new JCheckBoxMenuItem ("Debugging"); JMenuItem debuggingItem = new JCheckBoxMenuItem ("Debugging");
JMenuItem retinaItem = new JCheckBoxMenuItem ("Retina display"); // JMenuItem retinaItem = new JCheckBoxMenuItem ("Retina display");
public MenuHandler (Preferences prefs) public MenuHandler (Preferences prefs)
{ {
@ -123,7 +123,7 @@ public class MenuHandler
formatMenu.add (colourQuirksItem); formatMenu.add (colourQuirksItem);
formatMenu.add (monochromeItem); formatMenu.add (monochromeItem);
formatMenu.add (debuggingItem); formatMenu.add (debuggingItem);
formatMenu.add (retinaItem); // formatMenu.add (retinaItem);
helpMenu.add (new JMenuItem (new EnvironmentAction ())); helpMenu.add (new JMenuItem (new EnvironmentAction ()));

View File

@ -1,27 +0,0 @@
package com.bytezone.diskbrowser.gui;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JMenuItem;
public class RetinaAction extends AbstractAction
{
private final DiskLayoutPanel owner;
public RetinaAction (DiskLayoutPanel owner)
{
super ("Retina display");
putValue (Action.SHORT_DESCRIPTION, "use hi resolution graphics");
// putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt G"));
// putValue (Action.MNEMONIC_KEY, KeyEvent.VK_G);
this.owner = owner;
}
@Override
public void actionPerformed (ActionEvent e)
{
owner.setRetina (((JMenuItem) e.getSource ()).isSelected ());
}
}

View File

@ -1,9 +1,12 @@
package com.bytezone.diskbrowser.utilities; package com.bytezone.diskbrowser.utilities;
import java.awt.Graphics2D;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
public class Utility public class Utility
{ {
// not used - it doesn't work with Oracle's JDK
public static boolean hasRetinaDisplay () public static boolean hasRetinaDisplay ()
{ {
Object obj = Object obj =
@ -16,4 +19,10 @@ public class Utility
} }
return false; return false;
} }
public static boolean test (Graphics2D g)
{
return g.getFontRenderContext ().getTransform ()
.equals (AffineTransform.getScaleInstance (2.0, 2.0));
}
} }

View File

@ -117,7 +117,7 @@ class Cell implements Comparable<Cell>, Value
switch (type) switch (type)
{ {
case LABEL: case LABEL:
return justify (label, colWidth, format); return justify (label, colWidth, cellFormat);
case REPEATING_CHARACTER: case REPEATING_CHARACTER:
return justify (repeat, colWidth, format); return justify (repeat, colWidth, format);