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

Last change on this file since 189 was 189, checked in by ra33, 16 years ago
File size: 3.0 KB
Line 
1package org.expeditee.gui;
2
3import java.awt.Component;
4import java.awt.Container;
5import java.awt.Graphics;
6import java.awt.LayoutManager;
7
8import javax.swing.JComponent;
9import javax.swing.JPanel;
10
11/**
12 *
13 * A Custom swing popup in Expeditee.
14 *
15 * Expeditee popus can be re-used. Popups are always heavyweight (i.e. uses invalidation).
16 *
17 * @see {@link PopupManager}
18 *
19 * @author Brook Novak
20 *
21 */
22public abstract class Popup extends JPanel {
23
24 //Mike says: Can we get the border for the IW to which this popup corresponds?
25 public static final float BORDER_THICKNESS = 1.0F;
26// private static final Stroke _lineStroke = new BasicStroke(BORDER_THICKNESS);
27
28 private boolean _isReadyToPaint = false;
29 private boolean _consumeBackClick = false;
30 private boolean _autoHide = true;
31
32 /**
33 * Creates a new popup.
34 * Autohide is set to true.
35 *
36 */
37 public Popup() {
38 super();
39 setVisible(false);
40 }
41
42 /**
43 * Creates a new popup.
44 *
45 * @param layout the LayoutManager to use
46 */
47 public Popup(LayoutManager layout) {
48 super(layout);
49 setVisible(false);
50 }
51
52 @Override
53 public void paint(Graphics g) {
54 super.paint(g);
55 // Draw iwidget-like border for consistancy
56// ((Graphics2D)g).setStroke(_lineStroke);
57// g.drawRect(0, 0, getWidth(), getHeight());
58 }
59
60 private void ignoreAWTPainting(Component c) {
61
62 if (c instanceof JComponent) {
63 ((JComponent)c).setDoubleBuffered(false);
64 }
65
66 c.setIgnoreRepaint(true);
67
68 if (c instanceof Container) {
69 for (Component child : ((Container) c).getComponents()) {
70
71 if (child instanceof Container) {
72 ignoreAWTPainting(child);
73 } else {
74 if (child instanceof JComponent) {
75 ((JComponent)child).setDoubleBuffered(false);
76 }
77
78 child.setIgnoreRepaint(true);
79 }
80 }
81 }
82
83 }
84
85 /**
86 * Ensures that AWT painting turned off
87 */
88 void prepareToPaint() {
89 if (!_isReadyToPaint) {
90 _isReadyToPaint = true;
91 ignoreAWTPainting(this);
92 }
93 }
94
95 /**
96 * Invoked when the popup becomes hidden, or when the popup is animating to show but cancelled.
97 */
98 public void onHide() {}
99
100 /**
101 * Invoked when the popup shows. Note this might not eventuate for animated popups.
102 */
103 public void onShow() {}
104
105 /**
106 * Invoked when popups is going to show.
107 * This always is invoked first.
108 */
109 public void onShowing() {}
110
111 public boolean shouldConsumeBackClick() {
112 return _consumeBackClick;
113 }
114
115 /**
116 * @param consumeBackClick
117 * Set to True for whenever the user clicks empty space
118 * to go back a frame that if this popup is visible should
119 * consume the back-click event.
120 */
121 protected void setConsumeBackClick(boolean consumeBackClick) {
122 _consumeBackClick = consumeBackClick;
123 }
124
125 /**
126 * @param autoHideOn
127 * Set to True if this popup should auto hide. (The default).
128 * Set to false if this popup should be manually hidden.
129 */
130 protected void setAudoHide(boolean autoHideOn) {
131 _autoHide = autoHideOn;
132 }
133
134 /**
135 * @return
136 * True if this popup auto hides.
137 */
138 public boolean doesAutoHide() {
139 return _autoHide;
140 }
141
142
143
144
145
146}
Note: See TracBrowser for help on using the repository browser.