1 package tim.prune.gui.map;
4 import java.awt.Component;
5 import java.awt.Graphics;
7 import javax.swing.JPanel;
10 * Semi-transparent panel to go on top of the map
11 * to contain a set of controls
13 public class OverlayPanel extends JPanel
15 // Previous dimensions to see if calculations necessary
16 private int _prevWidth = -1, _prevHeight = -1;
17 // Previously calculated border limits
18 private int _minX, _minY, _width, _height;
31 public void paint(Graphics g)
33 int panelWidth = getWidth();
34 int panelHeight = getHeight();
35 if (panelWidth != _prevWidth || panelHeight != _prevHeight)
38 _prevWidth = panelWidth;
39 _prevHeight = panelHeight;
41 // Draw white background
42 final Color BG = new Color(255, 255, 255, 200);
44 g.fillRect(_minX, _minY, _width, _height);
46 g.setColor(Color.BLACK);
47 g.drawRect(_minX, _minY, _width, _height);
48 // Paint everything else
53 * Calculate the boundaries to paint over
55 private void calculateBorder()
57 final int PADDING = 2;
58 // Calculate where the border should be drawn
59 final Component firstComp = getComponent(0);
60 final Component lastComp = getComponent(getComponentCount()-1);
61 _minX = Math.max(firstComp.getX() - PADDING, 0);
62 final int maxX = Math.min(lastComp.getX() + lastComp.getWidth() + PADDING, getWidth()-1);
63 _width = maxX - _minX;
64 _minY = Math.max(Math.min(firstComp.getY(), lastComp.getY()) - PADDING, 0);
65 final int maxY = Math.max(firstComp.getY()+firstComp.getHeight(), lastComp.getY()+lastComp.getHeight()) + PADDING;
66 _height = maxY - _minY;
67 //System.out.println("x from " + minx + " to " + maxx + ", y from " + miny + " to " + maxy);