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;
|
|
|
|
|
|
|
|
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;
|
2016-07-29 12:28:11 +00:00
|
|
|
private boolean retina;
|
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;
|
|
|
|
repaint ();
|
|
|
|
}
|
|
|
|
|
2016-07-29 12:28:11 +00:00
|
|
|
public void setRetina (boolean value)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-07-29 12:28:11 +00:00
|
|
|
retina = value;
|
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;
|
|
|
|
|
|
|
|
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-29 12:28:11 +00:00
|
|
|
if (retina)
|
2015-06-02 01:35:49 +00:00
|
|
|
g.fillRect (x + 1, y + 1, layoutDetails.block.width - 2,
|
|
|
|
layoutDetails.block.height - 2);
|
2016-07-29 12:28:11 +00:00
|
|
|
else
|
|
|
|
g.fillRect (x + 2, y + 2, layoutDetails.block.width - 3,
|
|
|
|
layoutDetails.block.height - 3);
|
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)
|
|
|
|
{
|
2015-06-02 01:35:49 +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",
|
|
|
|
10, y);
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
}
|