dmolony-DiskBrowser/src/com/bytezone/diskbrowser/gui/DiskLegendPanel.java

97 lines
3.1 KiB
Java
Raw Permalink Normal View History

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 com.bytezone.diskbrowser.disk.FormattedDisk;
import com.bytezone.diskbrowser.disk.SectorType;
import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails;
2020-06-29 02:29:26 +00:00
import com.bytezone.diskbrowser.utilities.FontUtility;
import com.bytezone.diskbrowser.utilities.FontUtility.FontSize;
import com.bytezone.diskbrowser.utilities.FontUtility.FontType;
2015-06-01 09:35:51 +00:00
2020-02-08 22:20:08 +00:00
// -----------------------------------------------------------------------------------//
2018-07-18 05:14:17 +00:00
class DiskLegendPanel extends DiskPanel
2020-02-08 22:20:08 +00:00
// -----------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
2017-06-12 09:09:19 +00:00
private static final int LEFT = 3;
2016-07-29 22:06:41 +00:00
private static final int TOP = 10;
2015-06-01 09:35:51 +00:00
2016-07-29 22:06:41 +00:00
private final Font font;
2015-06-01 09:35:51 +00:00
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
public DiskLegendPanel ()
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
2020-06-29 02:29:26 +00:00
font = FontUtility.getFont (FontType.SANS_SERIF, FontSize.BASE);
2015-06-01 09:35:51 +00:00
setBackground (Color.WHITE);
}
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
2018-07-18 05:14:17 +00:00
@Override
2015-06-01 09:35:51 +00:00
public void setDisk (FormattedDisk disk, LayoutDetails details)
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
2018-07-18 05:14:17 +00:00
super.setDisk (disk, details);
2015-06-01 09:35:51 +00:00
repaint ();
}
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
@Override
public Dimension getPreferredSize ()
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
2018-07-18 05:14:17 +00:00
return new Dimension (0, 160); // width/height
2015-06-01 09:35:51 +00:00
}
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
@Override
protected void paintComponent (Graphics g)
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
super.paintComponent (g);
2018-07-18 05:14:17 +00:00
if (formattedDisk == null)
2015-06-01 09:35:51 +00:00
return;
g.setFont (font);
int count = 0;
int lineHeight = 20;
2018-07-18 05:14:17 +00:00
for (SectorType type : formattedDisk.getSectorTypeList ())
2015-06-01 09:35:51 +00:00
{
2017-06-12 09:09:19 +00:00
int x = LEFT + (count % 2 == 0 ? 0 : 155);
2018-07-18 05:14:17 +00:00
int y = TOP + count / 2 * lineHeight;
++count;
2015-06-01 09:35:51 +00:00
// draw border
2018-07-18 05:14:17 +00:00
g.setColor (backgroundColor);
g.drawRect (x + 1, y + 1, blockWidth - 1, blockHeight - 1);
2015-06-01 09:35:51 +00:00
2018-07-18 05:14:17 +00:00
// draw block
2015-06-01 09:35:51 +00:00
g.setColor (type.colour);
2018-08-16 00:09:26 +00:00
g.fillRect (x + 1, y + 1, blockWidth - 1, blockHeight - 1);
2015-06-01 09:35:51 +00:00
2018-07-18 05:14:17 +00:00
// draw text
2015-06-01 09:35:51 +00:00
g.setColor (Color.BLACK);
2018-07-18 05:14:17 +00:00
g.drawString (type.name, x + blockWidth + 4, y + 12);
2015-06-01 09:35:51 +00:00
}
int y = ++count / 2 * lineHeight + TOP * 2 + 5;
2018-07-18 05:14:17 +00:00
int val = formattedDisk.falseNegativeBlocks ();
2015-06-01 09:35:51 +00:00
if (val > 0)
{
2021-06-04 06:53:04 +00:00
g.drawString (val + " unused sector" + (val == 1 ? "" : "s") //
+ " marked as unavailable", 10, y);
2015-06-01 09:35:51 +00:00
y += lineHeight;
}
2018-07-18 05:14:17 +00:00
val = formattedDisk.falsePositiveBlocks ();
2015-06-01 09:35:51 +00:00
if (val > 0)
2021-06-04 06:53:04 +00:00
g.drawString (val + " used sector" + (val == 1 ? "" : "s") //
+ " marked as available", 10, y);
2015-06-01 09:35:51 +00:00
}
}