DiskLayout problem drawing boxes

This commit is contained in:
Denis Molony 2015-06-02 11:35:49 +10:00
parent e502d2cfae
commit 12b8db6bdc
3 changed files with 42 additions and 26 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Mon Jun 01 19:29:14 AEST 2015 #Tue Jun 02 11:34:38 AEST 2015
build.number=627 build.number=629

View File

@ -1,12 +1,18 @@
package com.bytezone.diskbrowser.gui; package com.bytezone.diskbrowser.gui;
import java.awt.*; import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.InputEvent; import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.List; import java.util.List;
import javax.swing.JComponent; import javax.swing.JPanel;
import javax.swing.Scrollable; import javax.swing.Scrollable;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
@ -17,7 +23,7 @@ import com.bytezone.diskbrowser.disk.SectorType;
import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails; import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails;
import com.bytezone.diskbrowser.gui.RedoHandler.RedoEvent; import com.bytezone.diskbrowser.gui.RedoHandler.RedoEvent;
class DiskLayoutImage extends JComponent implements Scrollable class DiskLayoutImage extends JPanel implements Scrollable
{ {
static final Cursor crosshairCursor = new Cursor (Cursor.CROSSHAIR_CURSOR); static final Cursor crosshairCursor = new Cursor (Cursor.CROSSHAIR_CURSOR);
FormattedDisk disk; FormattedDisk disk;
@ -82,8 +88,8 @@ class DiskLayoutImage extends JComponent implements Scrollable
super.paintComponent (g); super.paintComponent (g);
// why doesn't linux do this? // why doesn't linux do this?
g.setColor (Color.WHITE); // g.setColor (Color.WHITE);
g.fillRect (0, 0, getWidth (), getHeight ()); // g.fillRect (0, 0, getWidth (), getHeight ());
if (disk == null) if (disk == null)
return; return;
@ -92,9 +98,9 @@ class DiskLayoutImage extends JComponent implements Scrollable
Point p1 = new Point (clipRect.x / bw * bw, clipRect.y / bh * bh); Point p1 = new Point (clipRect.x / bw * bw, clipRect.y / bh * bh);
Point p2 = Point p2 =
new Point ((clipRect.x + clipRect.width - 1) / bw * bw, (clipRect.y new Point ((clipRect.x + clipRect.width - 1) / bw * bw, (clipRect.y
+ clipRect.height - 1) + clipRect.height - 1)
/ bh * bh); / bh * bh);
// System.out.printf ("gw=%d, gh=%d, bw=%d, bh=%d%n", gw, gh, bw, bh); // System.out.printf ("gw=%d, gh=%d, bw=%d, bh=%d%n", gw, gh, bw, bh);
// int totalBlocks = 0; // int totalBlocks = 0;
@ -123,12 +129,11 @@ class DiskLayoutImage extends JComponent implements Scrollable
} }
private void drawBlock (Graphics2D g, int blockNo, int x, int y, boolean flagFree, private void drawBlock (Graphics2D g, int blockNo, int x, int y, boolean flagFree,
boolean selected) boolean selected)
{ {
SectorType type = disk.getSectorType (blockNo); SectorType type = disk.getSectorType (blockNo);
int offset = (bw - 4) / 2 + 1; int offset = (bw - 4) / 2 + 1;
// Rectangle rect = new Rectangle (x, y, bw, bh);
Rectangle rect = new Rectangle (x, y, bw, bh); Rectangle rect = new Rectangle (x, y, bw, bh);
// System.out.printf ("Rect: %4d %4d %4d %4d%n", x, y, bw, bh); // System.out.printf ("Rect: %4d %4d %4d %4d%n", x, y, bw, bh);
@ -144,7 +149,12 @@ class DiskLayoutImage extends JComponent implements Scrollable
if (type.colour != Color.WHITE) if (type.colour != Color.WHITE)
{ {
g.setColor (type.colour); g.setColor (type.colour);
g.fillRect (rect.x + 2, rect.y + 2, rect.width - 3, rect.height - 3); // this is weird, the retina OSX screen needs the second fillRect
// see also DiskLegendPanel.paint()
if (false)
g.fillRect (rect.x + 2, rect.y + 2, rect.width - 3, rect.height - 3);
else
g.fillRect (rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2);
} }
// draw an indicator in free blocks // draw an indicator in free blocks
@ -164,8 +174,9 @@ class DiskLayoutImage extends JComponent implements Scrollable
private Color getContrastColor (SectorType type) private Color getContrastColor (SectorType type)
{ {
if (type.colour == Color.WHITE || type.colour == Color.YELLOW || type.colour == Color.PINK if (type.colour == Color.WHITE || type.colour == Color.YELLOW
|| type.colour == Color.CYAN || type.colour == Color.ORANGE) || type.colour == Color.PINK || type.colour == Color.CYAN
|| type.colour == Color.ORANGE)
return Color.BLACK; return Color.BLACK;
return Color.WHITE; return Color.WHITE;
} }
@ -177,15 +188,15 @@ class DiskLayoutImage extends JComponent implements Scrollable
} }
@Override @Override
public int public int getScrollableUnitIncrement (Rectangle visibleRect, int orientation,
getScrollableUnitIncrement (Rectangle visibleRect, int orientation, int direction) int direction)
{ {
return orientation == SwingConstants.HORIZONTAL ? bw : bh; return orientation == SwingConstants.HORIZONTAL ? bw : bh;
} }
@Override @Override
public int public int getScrollableBlockIncrement (Rectangle visibleRect, int orientation,
getScrollableBlockIncrement (Rectangle visibleRect, int orientation, int direction) int direction)
{ {
return orientation == SwingConstants.HORIZONTAL ? bw * 4 : bh * 10; return orientation == SwingConstants.HORIZONTAL ? bw * 4 : bh * 10;
} }
@ -214,7 +225,7 @@ class DiskLayoutImage extends JComponent implements Scrollable
private void fireSectorSelectionEvent () private void fireSectorSelectionEvent ()
{ {
SectorSelectedEvent event = SectorSelectedEvent event =
new SectorSelectedEvent (this, selectionHandler.getHighlights (), disk); new SectorSelectedEvent (this, selectionHandler.getHighlights (), disk);
fireSectorSelectionEvent (event); fireSectorSelectionEvent (event);
} }
@ -222,7 +233,7 @@ class DiskLayoutImage extends JComponent implements Scrollable
{ {
event.redo = redo; event.redo = redo;
SectorSelectionListener[] listeners = SectorSelectionListener[] listeners =
(listenerList.getListeners (SectorSelectionListener.class)); (listenerList.getListeners (SectorSelectionListener.class));
for (SectorSelectionListener listener : listeners) for (SectorSelectionListener listener : listeners)
listener.sectorSelected (event); listener.sectorSelected (event);
} }

View File

@ -73,7 +73,12 @@ class DiskLegendPanel extends JPanel
// draw the colour // draw the colour
g.setColor (type.colour); g.setColor (type.colour);
g.fillRect (x + 2, y + 2, layoutDetails.block.width - 3, layoutDetails.block.height - 3); if (false)
g.fillRect (x + 2, y + 2, layoutDetails.block.width - 3,
layoutDetails.block.height - 3);
else
g.fillRect (x + 1, y + 1, layoutDetails.block.width - 2,
layoutDetails.block.height - 2);
// draw the text // draw the text
g.setColor (Color.BLACK); g.setColor (Color.BLACK);
@ -84,13 +89,13 @@ class DiskLegendPanel extends JPanel
int val = disk.falseNegativeBlocks (); int val = disk.falseNegativeBlocks ();
if (val > 0) if (val > 0)
{ {
g.drawString (val + " empty sector" + (val == 1 ? "" : "s") + " marked as unavailable", g.drawString (val + " empty sector" + (val == 1 ? "" : "s")
10, y); + " marked as unavailable", 10, y);
y += lineHeight; y += lineHeight;
} }
val = disk.falsePositiveBlocks (); val = disk.falsePositiveBlocks ();
if (val > 0) if (val > 0)
g.drawString (val + " used sector" + (val == 1 ? "" : "s") + " marked as available", 10, g.drawString (val + " used sector" + (val == 1 ? "" : "s") + " marked as available",
y); 10, y);
} }
} }