1 | package org.expeditee.gui;
|
---|
2 |
|
---|
3 | import java.awt.BasicStroke;
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.awt.Container;
|
---|
6 | import java.awt.Graphics;
|
---|
7 | import java.awt.Graphics2D;
|
---|
8 | import java.awt.Stroke;
|
---|
9 |
|
---|
10 | import javax.swing.JComponent;
|
---|
11 | import javax.swing.JPanel;
|
---|
12 |
|
---|
13 | import org.expeditee.items.WidgetCorner;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | *
|
---|
17 | * A Custom swing popup in Expeditee.
|
---|
18 | *
|
---|
19 | * @author Brook Novak
|
---|
20 | *
|
---|
21 | */
|
---|
22 | public abstract class Popup extends JPanel {
|
---|
23 |
|
---|
24 | public static final float BORDER_THICKNESS = WidgetCorner.BORDER_THICKNESS;
|
---|
25 | private static final Stroke _lineStroke = new BasicStroke(BORDER_THICKNESS);
|
---|
26 |
|
---|
27 | private boolean _isReadyToPaint = false;
|
---|
28 |
|
---|
29 | @Override
|
---|
30 | public void paint(Graphics g) {
|
---|
31 | super.paint(g);
|
---|
32 | // Draw iwidget-like border for consistancy
|
---|
33 | ((Graphics2D)g).setStroke(_lineStroke);
|
---|
34 | g.drawRect(0, 0, getWidth(), getHeight());
|
---|
35 | }
|
---|
36 |
|
---|
37 | private void ignoreAWTPainting(Component c) {
|
---|
38 |
|
---|
39 | if (c instanceof JComponent) {
|
---|
40 | ((JComponent)c).setDoubleBuffered(false);
|
---|
41 | }
|
---|
42 |
|
---|
43 | c.setIgnoreRepaint(true);
|
---|
44 |
|
---|
45 | if (c instanceof Container) {
|
---|
46 | for (Component child : ((Container) c).getComponents()) {
|
---|
47 |
|
---|
48 | if (child instanceof Container) {
|
---|
49 | ignoreAWTPainting(child);
|
---|
50 | } else {
|
---|
51 | if (child instanceof JComponent) {
|
---|
52 | ((JComponent)child).setDoubleBuffered(false);
|
---|
53 | }
|
---|
54 |
|
---|
55 | child.setIgnoreRepaint(true);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Ensures that AWT painting turned off
|
---|
64 | */
|
---|
65 | void prepareToPaint() {
|
---|
66 | if (!_isReadyToPaint) {
|
---|
67 | _isReadyToPaint = true;
|
---|
68 | ignoreAWTPainting(this);
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | }
|
---|