source: trunk/src/org/expeditee/gui/Popup.java@ 168

Last change on this file since 168 was 168, checked in by bjn8, 16 years ago
File size: 2.3 KB
Line 
1package org.expeditee.gui;
2
3import java.awt.BasicStroke;
4import java.awt.Component;
5import java.awt.Container;
6import java.awt.Graphics;
7import java.awt.Graphics2D;
8import java.awt.LayoutManager;
9import java.awt.Stroke;
10
11import javax.swing.JComponent;
12import javax.swing.JPanel;
13
14import org.expeditee.items.WidgetCorner;
15
16/**
17 *
18 * A Custom swing popup in Expeditee.
19 *
20 * Expeditee popus can be re-used. Popups are always heavyweight (i.e. uses invalidation).
21 *
22 * @see {@link PopupManager}
23 *
24 * @author Brook Novak
25 *
26 */
27public abstract class Popup extends JPanel {
28
29 public static final float BORDER_THICKNESS = WidgetCorner.BORDER_THICKNESS;
30 private static final Stroke _lineStroke = new BasicStroke(BORDER_THICKNESS);
31
32 private boolean _isReadyToPaint = false;
33 private boolean _consumeBackClick = false;
34
35 /**
36 * Creates a new popup.
37 */
38 public Popup() {
39 super();
40 setVisible(false);
41 }
42
43 /**
44 * Creates a new popup.
45 *
46 * @param layout the LayoutManager to use
47 */
48 public Popup(LayoutManager layout) {
49 super(layout);
50 setVisible(false);
51 }
52
53 @Override
54 public void paint(Graphics g) {
55 super.paint(g);
56 // Draw iwidget-like border for consistancy
57 ((Graphics2D)g).setStroke(_lineStroke);
58 g.drawRect(0, 0, getWidth(), getHeight());
59 }
60
61 private void ignoreAWTPainting(Component c) {
62
63 if (c instanceof JComponent) {
64 ((JComponent)c).setDoubleBuffered(false);
65 }
66
67 c.setIgnoreRepaint(true);
68
69 if (c instanceof Container) {
70 for (Component child : ((Container) c).getComponents()) {
71
72 if (child instanceof Container) {
73 ignoreAWTPainting(child);
74 } else {
75 if (child instanceof JComponent) {
76 ((JComponent)child).setDoubleBuffered(false);
77 }
78
79 child.setIgnoreRepaint(true);
80 }
81 }
82 }
83
84 }
85
86 /**
87 * Ensures that AWT painting turned off
88 */
89 void prepareToPaint() {
90 if (!_isReadyToPaint) {
91 _isReadyToPaint = true;
92 ignoreAWTPainting(this);
93 }
94 }
95
96 public void onHide() {}
97 public void onShow() {}
98
99 public boolean shouldConsumeBackClick() {
100 return _consumeBackClick;
101 }
102
103 /**
104 * @param consumeBackClick
105 * Set to True for whenever the user clicks empty space
106 * to go back a frame that if this popup is visible should
107 * consume the back-click event.
108 */
109 public void setConsumeBackClick(boolean consumeBackClick) {
110 _consumeBackClick = consumeBackClick;
111 }
112
113
114
115}
Note: See TracBrowser for help on using the repository browser.