2015-06-01 09:35:51 +00:00
|
|
|
package com.bytezone.diskbrowser.gui;
|
|
|
|
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Font;
|
|
|
|
import java.awt.Graphics;
|
2016-07-30 03:04:55 +00:00
|
|
|
import java.awt.Graphics2D;
|
|
|
|
import java.awt.geom.AffineTransform;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
|
|
import com.bytezone.common.Platform;
|
|
|
|
import com.bytezone.common.Platform.FontSize;
|
|
|
|
import com.bytezone.common.Platform.FontType;
|
|
|
|
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
|
|
|
import com.bytezone.diskbrowser.disk.SectorType;
|
|
|
|
import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails;
|
|
|
|
|
|
|
|
class DiskLegendPanel extends JPanel
|
|
|
|
{
|
2016-07-29 22:06:41 +00:00
|
|
|
private static final int LEFT = 10;
|
|
|
|
private static final int TOP = 10;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-07-29 22:06:41 +00:00
|
|
|
private FormattedDisk disk;
|
|
|
|
private LayoutDetails layoutDetails;
|
|
|
|
private final Font font;
|
2017-01-20 05:20:00 +00:00
|
|
|
private boolean isRetina;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
public DiskLegendPanel ()
|
|
|
|
{
|
|
|
|
font = Platform.getFont (FontType.SANS_SERIF, FontSize.BASE);
|
|
|
|
setBackground (Color.WHITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDisk (FormattedDisk disk, LayoutDetails details)
|
|
|
|
{
|
|
|
|
this.disk = disk;
|
|
|
|
layoutDetails = details;
|
|
|
|
|
2016-07-30 03:04:55 +00:00
|
|
|
Graphics2D g = (Graphics2D) this.getGraphics ();
|
2017-01-20 05:20:00 +00:00
|
|
|
if (g != null) // panel might not be showing
|
|
|
|
isRetina = g.getFontRenderContext ().getTransform ()
|
|
|
|
.equals (AffineTransform.getScaleInstance (2.0, 2.0));
|
2016-07-30 03:04:55 +00:00
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
repaint ();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Dimension getPreferredSize ()
|
|
|
|
{
|
|
|
|
return new Dimension (0, 160); // width/height
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void paintComponent (Graphics g)
|
|
|
|
{
|
|
|
|
super.paintComponent (g);
|
|
|
|
|
|
|
|
if (disk == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g.setFont (font);
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
int lineHeight = 20;
|
2017-01-20 05:20:00 +00:00
|
|
|
int width = layoutDetails.block.width - (isRetina ? 2 : 3);
|
|
|
|
int height = layoutDetails.block.height - (isRetina ? 2 : 3);
|
|
|
|
int offset = isRetina ? 1 : 2;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
for (SectorType type : disk.getSectorTypeList ())
|
|
|
|
{
|
|
|
|
int x = LEFT + (count % 2 == 0 ? 0 : 145);
|
|
|
|
int y = TOP + count++ / 2 * lineHeight;
|
|
|
|
|
|
|
|
// draw border
|
|
|
|
g.setColor (Color.GRAY);
|
|
|
|
g.drawRect (x, y, layoutDetails.block.width, layoutDetails.block.height);
|
|
|
|
|
|
|
|
// draw the colour
|
|
|
|
g.setColor (type.colour);
|
2016-07-30 06:12:01 +00:00
|
|
|
g.fillRect (x + offset, y + offset, width, height);
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
// draw the text
|
|
|
|
g.setColor (Color.BLACK);
|
|
|
|
g.drawString (type.name, x + layoutDetails.block.width + 4, y + 12);
|
|
|
|
}
|
|
|
|
|
|
|
|
int y = ++count / 2 * lineHeight + TOP * 2 + 5;
|
|
|
|
int val = disk.falseNegativeBlocks ();
|
|
|
|
if (val > 0)
|
|
|
|
{
|
2017-01-20 05:20:00 +00:00
|
|
|
g.drawString (
|
|
|
|
val + " empty sector" + (val == 1 ? "" : "s") + " marked as unavailable", 10,
|
|
|
|
y);
|
2015-06-01 09:35:51 +00:00
|
|
|
y += lineHeight;
|
|
|
|
}
|
|
|
|
val = disk.falsePositiveBlocks ();
|
|
|
|
if (val > 0)
|
2015-06-02 01:35:49 +00:00
|
|
|
g.drawString (val + " used sector" + (val == 1 ? "" : "s") + " marked as available",
|
2017-01-20 05:20:00 +00:00
|
|
|
10, y);
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
}
|