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

Last change on this file since 183 was 183, checked in by bjn8, 16 years ago

Gave popups an option to have autohide on or off

File size: 3.1 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 private boolean _autoHide = true;
35
36 /**
37 * Creates a new popup.
38 * Autohide is set to true.
39 *
40 */
41 public Popup() {
42 super();
43 setVisible(false);
44 }
45
46 /**
47 * Creates a new popup.
48 *
49 * @param layout the LayoutManager to use
50 */
51 public Popup(LayoutManager layout) {
52 super(layout);
53 setVisible(false);
54 }
55
56 @Override
57 public void paint(Graphics g) {
58 super.paint(g);
59 // Draw iwidget-like border for consistancy
60 ((Graphics2D)g).setStroke(_lineStroke);
61 g.drawRect(0, 0, getWidth(), getHeight());
62 }
63
64 private void ignoreAWTPainting(Component c) {
65
66 if (c instanceof JComponent) {
67 ((JComponent)c).setDoubleBuffered(false);
68 }
69
70 c.setIgnoreRepaint(true);
71
72 if (c instanceof Container) {
73 for (Component child : ((Container) c).getComponents()) {
74
75 if (child instanceof Container) {
76 ignoreAWTPainting(child);
77 } else {
78 if (child instanceof JComponent) {
79 ((JComponent)child).setDoubleBuffered(false);
80 }
81
82 child.setIgnoreRepaint(true);
83 }
84 }
85 }
86
87 }
88
89 /**
90 * Ensures that AWT painting turned off
91 */
92 void prepareToPaint() {
93 if (!_isReadyToPaint) {
94 _isReadyToPaint = true;
95 ignoreAWTPainting(this);
96 }
97 }
98
99 /**
100 * Invoked when the popup becomes hidden, or when the popup is animating to show but cancelled.
101 */
102 public void onHide() {}
103
104 /**
105 * Invoked when the popup shows. Note this might not eventuate for animated popups.
106 */
107 public void onShow() {}
108
109 /**
110 * Invoked when popups is going to show.
111 * This always is invoked first.
112 */
113 public void onShowing() {}
114
115 public boolean shouldConsumeBackClick() {
116 return _consumeBackClick;
117 }
118
119 /**
120 * @param consumeBackClick
121 * Set to True for whenever the user clicks empty space
122 * to go back a frame that if this popup is visible should
123 * consume the back-click event.
124 */
125 protected void setConsumeBackClick(boolean consumeBackClick) {
126 _consumeBackClick = consumeBackClick;
127 }
128
129 /**
130 * @param autoHideOn
131 * Set to True if this popup should auto hide. (The default).
132 * Set to false if this popup should be manually hidden.
133 */
134 protected void setAudoHide(boolean autoHideOn) {
135 _autoHide = autoHideOn;
136 }
137
138 /**
139 * @return
140 * True if this popup auto hides.
141 */
142 public boolean doesAutoHide() {
143 return _autoHide;
144 }
145
146
147
148
149
150}
Note: See TracBrowser for help on using the repository browser.