KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > awt > Toaster


1 package com.sshtools.ui.awt;
2
3 import java.awt.BorderLayout JavaDoc;
4 import java.awt.Canvas JavaDoc;
5 import java.awt.Color JavaDoc;
6 import java.awt.Dimension JavaDoc;
7 import java.awt.Font JavaDoc;
8 import java.awt.Frame JavaDoc;
9 import java.awt.GridBagConstraints JavaDoc;
10 import java.awt.GridBagLayout JavaDoc;
11 import java.awt.Image JavaDoc;
12 import java.awt.Insets JavaDoc;
13 import java.awt.Label JavaDoc;
14 import java.awt.Panel JavaDoc;
15 import java.awt.Window JavaDoc;
16 import java.awt.event.ActionEvent JavaDoc;
17 import java.awt.event.ActionListener JavaDoc;
18 import java.awt.event.MouseEvent JavaDoc;
19 import java.awt.event.MouseListener JavaDoc;
20 import java.lang.reflect.Method JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 /**
25  *
26  * UI component that display <i>toaster</i> style messages. When a request to
27  * display a message is made, the message will appear at a specified location on
28  * the users desktop. It will stay visible for a specified amount of time. If
29  * more messages are sent in the meantime, they will appear in a new window
30  * either just above or just below the last messages.
31  *
32  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
33  */

34 public class Toaster {
35
36     /**
37      * Default timeout
38      */

39     public final static int DEFAULT_TIMEOUT = 10000;
40
41     /**
42      * Toaster appears at the bottom right of the screen with messages flowing
43      * up from bottom to top
44      */

45     public final static int BOTTOM_RIGHT = 0;
46
47     /**
48      * Toaster appears at the bottom left of the screen with messages flowing up
49      * from bottom to top
50      */

51     public final static int BOTTOM_LEFT = 1;
52
53     /**
54      * Toaster appears at the top left of the screen with messages flowing down
55      * from top to bottom
56      */

57     public final static int TOP_LEFT = 2;
58
59     /**
60      * Toaster appears at the top right of the screen with messages flowing down
61      * from top to bottom
62      */

63     public final static int TOP_RIGHT = 3;
64
65     /*
66      * Configurable statics
67      */

68
69     /**
70      * Default background color for new toasters
71      */

72     public static Color JavaDoc BACKGROUND_COLOR = null;
73
74     /**
75      * Default foreground color for new toasters
76      */

77     public static Color JavaDoc FOREGROUND_COLOR = null;
78
79     /**
80      * Default border color for new toasters
81      */

82     public static Color JavaDoc BORDER_COLOR = null;
83
84     /**
85      * Default text font for new toasters
86      */

87     public static Font JavaDoc TEXT_FONT = null;
88
89     /**
90      * Default title font for new toasters
91      */

92     public static Font JavaDoc TITLE_FONT = null;
93
94     /*
95      * Intialise depending on environment
96      */

97     static {
98         try {
99             if ("false".equals(System.getProperty("toaster.loadStyleFromUIManager", "false"))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
100
throw new Exception JavaDoc(Messages.getString("Toaster.disabled")); //$NON-NLS-1$
101
}
102             Class JavaDoc clazz = Class.forName("javax.swing.UIManager"); //$NON-NLS-1$
103
Method JavaDoc colorMethod = clazz.getMethod("getColor", new Class JavaDoc[] { Object JavaDoc.class }); //$NON-NLS-1$
104
Method JavaDoc fontMethod = clazz.getMethod("getFont", new Class JavaDoc[] { Object JavaDoc.class }); //$NON-NLS-1$
105
BACKGROUND_COLOR = (Color JavaDoc) colorMethod.invoke(null, new Object JavaDoc[] { "ToolTip.background" }); //$NON-NLS-1$
106
FOREGROUND_COLOR = (Color JavaDoc) colorMethod.invoke(null, new Object JavaDoc[] { "ToolTip.foreground" }); //$NON-NLS-1$
107
BORDER_COLOR = (Color JavaDoc) colorMethod.invoke(null, new Object JavaDoc[] { "ToolTip.foreground" }); //$NON-NLS-1$
108
TEXT_FONT = (Font JavaDoc) fontMethod.invoke(null, new Object JavaDoc[] { "ToolTip.font" }); //$NON-NLS-1$
109
TITLE_FONT = ((Font JavaDoc) fontMethod.invoke(null, new Object JavaDoc[] { "Label.font" })); //$NON-NLS-1$
110
TITLE_FONT = new Font JavaDoc(TITLE_FONT.getName(), Font.BOLD, TITLE_FONT.getSize());
111         } catch (Exception JavaDoc e) {
112             BACKGROUND_COLOR = Color.white;
113             FOREGROUND_COLOR = Color.black;
114             BORDER_COLOR = Color.black;
115             TEXT_FONT = new Font JavaDoc("Arial", Font.PLAIN, 10); //$NON-NLS-1$
116
TITLE_FONT = new Font JavaDoc("Arial", Font.BOLD, 11); //$NON-NLS-1$
117
}
118     }
119
120     // Private instance variables
121

122     private Vector JavaDoc messages;
123     private Color JavaDoc backgroundColor;
124     private Color JavaDoc foregroundColor;
125     private Color JavaDoc borderColor;
126     private Font JavaDoc textFont;
127     private Font JavaDoc titleFont;
128     private int position;
129     private float textAlign;
130     private Dimension JavaDoc popupSize;
131     private MagicThread magicThread;
132
133     // Private static variables
134
private static Frame JavaDoc sharedFrame;
135
136     /**
137      * Constructor.
138      *
139      * @param position
140      * @param popupSize popup size
141      * @see #setPosition(int)
142      */

143     public Toaster(int position, Dimension JavaDoc popupSize) {
144         messages = new Vector JavaDoc();
145         backgroundColor = BACKGROUND_COLOR;
146         foregroundColor = FOREGROUND_COLOR;
147         borderColor = BORDER_COLOR;
148         textFont = TEXT_FONT;
149         titleFont = TITLE_FONT;
150         this.popupSize = popupSize;
151         this.position = position;
152         textAlign = Canvas.CENTER_ALIGNMENT;
153     }
154
155     /**
156      * Set the text alignment. May be one of
157      * {@link java.awt.Component#LEFT_ALIGNMENT},
158      * {@link java.awt.Component#CENTER_ALIGNMENT} or
159      * {@link java.awt.Component#RIGHT_ALIGNMENT}.
160      *
161      * @param textAlign text alignment
162      */

163     public void setTextAlign(float textAlign) {
164         this.textAlign = textAlign;
165     }
166
167     /**
168      * Set the size of the popups. This will only take affect on new messages.
169      *
170      * @param popupSize popup size
171      */

172     public void setPopupSize(Dimension JavaDoc popupSize) {
173         this.popupSize = popupSize;
174     }
175
176     /**
177      * Get the size of the popups.
178      *
179      * @return popup size
180      */

181     public Dimension JavaDoc getPopupSize() {
182         return popupSize;
183     }
184
185     /**
186      * Set the position of messages. Can be one of {@link #TOP_LEFT},
187      * {@link #TOP_RIGHT}, {@link #BOTTOM_LEFT} or {@link #BOTTOM_RIGHT}.
188      *
189      * @param position position
190      */

191     public void setPosition(int position) {
192         this.position = position;
193     }
194
195     /**
196      * Get the position of messages. Can be one of {@link #TOP_LEFT},
197      * {@link #TOP_RIGHT}, {@link #BOTTOM_LEFT} or {@link #BOTTOM_RIGHT}.
198      *
199      * @return position
200      */

201     public int getPosition() {
202         return position;
203     }
204
205     /**
206      * Get the background color
207      *
208      * @return background color
209      */

210     public Color JavaDoc getBackgroundColor() {
211         return backgroundColor;
212     }
213
214     /**
215      * Set the background color. This will only take affect on new messages.
216      *
217      * @param backgroundColor background color
218      */

219     public void setBackgroundColor(Color JavaDoc backgroundColor) {
220         this.backgroundColor = backgroundColor;
221     }
222
223     /**
224      * Get the border color
225      *
226      * @return border color
227      */

228     public Color JavaDoc getBorderColor() {
229         return borderColor;
230     }
231
232     /**
233      * Set the border color. This will only take affect on new messages.
234      *
235      * @param borderColor border color
236      */

237     public void setBorderColor(Color JavaDoc borderColor) {
238         this.borderColor = borderColor;
239     }
240
241     /**
242      * Get the foreground color
243      *
244      * @return foreground color
245      */

246     public Color JavaDoc getForegroundColor() {
247         return foregroundColor;
248     }
249
250     /**
251      * Set the foreground color. This will only take affect on new messages.
252      *
253      * @param foregroundColor
254      */

255     public void setForegroundColor(Color JavaDoc foregroundColor) {
256         this.foregroundColor = foregroundColor;
257     }
258
259     /**
260      * Get the text text
261      *
262      * @return text font
263      */

264     public Font JavaDoc getTextFont() {
265         return textFont;
266     }
267
268     /**
269      * Set the text font. This will only take affect on new messages.
270      *
271      * @param textFont text font
272      */

273     public void setTextFont(Font JavaDoc textFont) {
274         this.textFont = textFont;
275     }
276
277     /**
278      * Get the title font. This will only take affect on new messages.
279      *
280      * @return title font
281      */

282     public Font JavaDoc getTitleFont() {
283         return titleFont;
284     }
285
286     /**
287      * Set the title font. This will only take affect on new messages.
288      *
289      * @param titleFont title font
290      */

291     public void setTitleFont(Font JavaDoc titleFont) {
292         this.titleFont = titleFont;
293     }
294
295     /**
296      * Popup a new message for 10 seconds.
297      *
298      * @param callback invoked when message is clicked
299      * @param message message to display
300      * @param title title of message
301      */

302     public synchronized void popup(ActionListener JavaDoc callback, String JavaDoc message, String JavaDoc title) {
303         popup(callback, message, title, null);
304     }
305
306     /**
307      * Popup a new message for 10 seconds with an option image.
308      *
309      * @param callback invoked when message is clicked
310      * @param message message to display
311      * @param title title of message
312      * @param image image or <code>null</code>
313      */

314     public synchronized void popup(ActionListener JavaDoc callback, String JavaDoc message, String JavaDoc title, Image JavaDoc image) {
315         popup(callback, message, title, image, -1);
316     }
317
318     /**
319      * Popup a new message.
320      *
321      * @param callback invoked when message is clicked
322      * @param message message to display
323      * @param title title of message
324      * @param timeout time to display message for
325      * @param image image or <code>null</code>
326      */

327     public void popup(ActionListener JavaDoc callback, String JavaDoc message, String JavaDoc title, Image JavaDoc image, int timeout) {
328         if (timeout == -1) {
329             timeout = DEFAULT_TIMEOUT;
330         }
331
332         // Create the new message window and add it to our Vector
333
MessageWindow window = new MessageWindow(popupSize, callback, message, title, image, timeout);
334         window.pack();
335
336         messages.addElement(window);
337
338         // Stop the magic thread
339
if (magicThread != null) {
340             magicThread.stopMagic();
341             magicThread = null;
342         }
343
344         // Reposition and show the messages windows
345
repositionPopups();
346     }
347
348     void repositionPopups() {
349
350         synchronized (messages) {
351             // Get the screeb suze
352
Dimension JavaDoc d = null;
353             try {
354                 Object JavaDoc genv = Class.forName("java.awt.GraphicsEnvironment") //$NON-NLS-1$
355
.getMethod("getLocalGraphicsEnvironment", new Class JavaDoc[] {}).invoke(null, new Object JavaDoc[] {}); //$NON-NLS-1$
356
Object JavaDoc[] devices = (Object JavaDoc[]) genv.getClass().getMethod("getScreenDevices", new Class JavaDoc[] {}).invoke(genv, //$NON-NLS-1$
357
new Object JavaDoc[] {});
358                 Object JavaDoc mode = devices[0].getClass().getMethod("getDisplayMode", new Class JavaDoc[] {}).invoke(devices[0], new Object JavaDoc[] {}); //$NON-NLS-1$
359
d = new Dimension JavaDoc(((Integer JavaDoc) mode.getClass().getMethod("getWidth", new Class JavaDoc[] {}).invoke(mode, new Object JavaDoc[] {})) //$NON-NLS-1$
360
.intValue(), ((Integer JavaDoc) mode.getClass().getMethod("getHeight", new Class JavaDoc[] {}).invoke(mode, //$NON-NLS-1$
361
new Object JavaDoc[] {})).intValue());
362             } catch (Exception JavaDoc e) {
363                 d = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
364             }
365
366             // Calculate the starting position
367
int wy = 0;
368             switch (position) {
369                 case TOP_LEFT:
370                 case TOP_RIGHT:
371                     wy = 16;
372                     break;
373                 case BOTTOM_LEFT:
374                 case BOTTOM_RIGHT:
375                     wy = d.height - 48;
376             }
377
378             // Set the target positions on all of the windows
379
for (Enumeration JavaDoc e = messages.elements(); e.hasMoreElements();) {
380                 MessageWindow w = (MessageWindow) e.nextElement();
381
382                 // Calculate the x (and y where appropriate) position
383
int wx = 0;
384                 switch (position) {
385                     case TOP_LEFT:
386                         wx = 16;
387                         break;
388                     case BOTTOM_LEFT:
389                         wy = wy - w.getPreferredSize().height;
390                         wx = 16;
391                         break;
392                     case TOP_RIGHT:
393                         wx = d.width - popupSize.width - 16;
394                         break;
395                     case BOTTOM_RIGHT:
396                         wy = wy - w.getPreferredSize().height;
397                         wx = d.width - popupSize.width - 16;
398                         break;
399                 }
400                 int owy = wy;
401
402                 // Increment the y position
403
switch (position) {
404                     case TOP_LEFT:
405                     case TOP_RIGHT:
406                         wy += 16;
407                         break;
408                     case BOTTOM_LEFT:
409                     case BOTTOM_RIGHT:
410                         wy -= 16;
411                         break;
412                 }
413
414                 // Show the window if it is not visible
415
if (!w.isVisible()) {
416                     w.setLocation(wx, owy);
417                     w.setTargetY(owy);
418                     w.setVisible(true);
419                 } else {
420                     w.setTargetY(owy);
421                 }
422             }
423         }
424
425     }
426
427     /*
428      * Hide a popup, remove it from the list and move other popups to their new
429      * position
430      */

431     void hideAndRemove(MessageWindow messageWindow) {
432         synchronized (messages) {
433             messageWindow.setVisible(false);
434             messages.removeElement(messageWindow);
435             repositionPopups();
436
437             // Start the magic thread if its not running
438
if (messages.size() != 0 && (magicThread == null || !magicThread.isAlive())) {
439                 magicThread = new MagicThread();
440             }
441         }
442     }
443
444     /*
445      * Get a shared parent frame
446      */

447     static Frame JavaDoc getSharedFrame() {
448         if (sharedFrame == null) {
449             sharedFrame = new Frame JavaDoc();
450         }
451         return sharedFrame;
452     }
453
454     /**
455      * Test.
456      *
457      * @param args
458      * @throws Exception
459      */

460     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
461         // #ifdef JAVA2
462
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
463         // #endif
464
Toaster.BACKGROUND_COLOR = Color.white;
465         Toaster.FOREGROUND_COLOR = Color.black;
466         Toaster.BORDER_COLOR = Color.black;
467         // Toaster t = new Toaster(BOTTOM_RIGHT, new Dimension(160, 160));
468
// t.popup(null, "This is a test message blah blah blah blah", "Brett
469
// says",
470
// UIUtil.loadImage(Toaster.class, "/images/error-48x48.png"));
471
// t.popup(null, "This is a test message 2", "Pete says");
472
// t.popup(null, "This is a test message 3", "Ash says");
473
// t.popup(null, "This is a multi\nline test message 3", "Lee Says");
474
final Toaster t = new Toaster(BOTTOM_RIGHT, new Dimension JavaDoc(260, 60));
475         t.setTextAlign(Canvas.LEFT_ALIGNMENT);
476         t.popup(new ActionListener JavaDoc() {
477             public void actionPerformed(ActionEvent JavaDoc evt) {
478                 System.exit(0);
479             }
480         }, "This is a test message blah blah blah blah", "Brett says", UIUtil.loadImage(Toaster.class, "/images/error-48x48.png")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
481
ActionListener JavaDoc a = new ActionListener JavaDoc() {
482             public void actionPerformed(ActionEvent JavaDoc evt) {
483                 t.popup(null, "This is a test message blah blah blah blah", "JB says", UIUtil.loadImage(Toaster.class, //$NON-NLS-1$ //$NON-NLS-2$
484
"/home/brett/Desktop/Modules/vpn-client/client/images/idle.gif")); //$NON-NLS-1$
485
// System.exit(0);
486
}
487         };
488         t.popup(a, "This is a test message blah blah blah blah", "JB says", UIUtil.loadImage(Toaster.class, //$NON-NLS-1$ //$NON-NLS-2$
489
"/home/brett/Desktop/Modules/vpn-client/client/images/idle.gif"), 2000); //$NON-NLS-1$
490
t.popup(a, "This is a test message 2", "Pete says", null, 7000); //$NON-NLS-1$ //$NON-NLS-2$
491
// t.popup(null, "This is a test message 3", "Ash says");
492
Thread.sleep(1000);
493         t.popup(a, "This is a multi\nline test message 3", "Lee Says"); //$NON-NLS-1$ //$NON-NLS-2$
494
t.popup(a,
495             "This is a test message blah blah blah blah that should push the size of the text box over the fixed dimensions provided. If it does not something has gone horibbly horibbly wrong. arrrrrrrrggggggggggh!!!!!!!!!!!!!", //$NON-NLS-1$
496
"JB says", UIUtil.loadImage(Toaster.class, //$NON-NLS-1$
497
"/home/brett/Desktop/Modules/vpn-client/client/images/idle.gif"), 5000); //$NON-NLS-1$
498
t.popup(a,
499             "This is a multiline test message blah\nblah blah blah that\nshould push the size of the text\nbox over the fixed dimensions\nprovided. If it does not something\nhas gone horibbly horibbly wrong. arrrrrrrrggggggggggh!!!!!!!!!!!!!", //$NON-NLS-1$
500
"JB says", UIUtil.loadImage(Toaster.class, //$NON-NLS-1$
501
"/home/brett/Desktop/Modules/vpn-client/client/images/idle.gif"), 8000); //$NON-NLS-1$
502
}
503
504     class MagicThread extends Thread JavaDoc {
505
506         boolean run = true;
507         int moved;
508
509         MagicThread() {
510             super("MagicThread"); //$NON-NLS-1$
511
start();
512         }
513
514         public void run() {
515             moved = 1;
516             while (run && moved > 0) {
517                 try {
518                     Method JavaDoc invokeAndWaitMethod = Class.forName("java.awt.EventQueue").getMethod("invokeAndWait", new Class JavaDoc[] { Runnable JavaDoc.class }); //$NON-NLS-1$ //$NON-NLS-2$
519
Runnable JavaDoc r = new Runnable JavaDoc() {
520                         public void run() {
521                             moved = doMove();
522                         }
523                     };
524                     invokeAndWaitMethod.invoke(null, new Object JavaDoc[] { r });
525                 } catch (Exception JavaDoc e) {
526                     moved = doMove();
527                 }
528                 yield();
529                 try {
530                     sleep(5);
531                 } catch (InterruptedException JavaDoc e1) {
532                 }
533             }
534         }
535
536         public void stopMagic() {
537             run = false;
538             interrupt();
539         }
540
541         int doMove() {
542
543             synchronized (messages) {
544                 int moved = 0;
545                 int ly, lx, wy;
546                 MessageWindow w;
547                 Enumeration JavaDoc e;
548                 for (e = messages.elements(); e.hasMoreElements();) {
549                     w = (MessageWindow) e.nextElement();
550                     ly = w.getLocation().y;
551                     lx = w.getLocation().x;
552                     wy = w.getTargetY();
553                     if (ly > wy) {
554                         ly = Math.max(ly - 4, wy);
555                         w.setLocation(lx, ly);
556                         moved++;
557                     } else if (ly < wy) {
558                         ly = Math.min(ly + 4, wy);
559                         w.setLocation(lx, ly);
560                         moved++;
561                     }
562                 }
563                 return moved;
564             }
565         }
566     }
567
568     class MessageWindow extends Window JavaDoc implements MouseListener JavaDoc {
569
570         ActionListener JavaDoc callback;
571         Dimension JavaDoc preferredSize;
572         int targetY;
573
574         MessageWindow(Dimension JavaDoc preferredSize, ActionListener JavaDoc callback, String JavaDoc message, String JavaDoc title, Image JavaDoc image, final int timeout) {
575             this(preferredSize, callback, message, title, image, timeout, null);
576         }
577
578         MessageWindow(Dimension JavaDoc preferredSize, ActionListener JavaDoc callback, String JavaDoc message, String JavaDoc title, Image JavaDoc image, final int timeout, String JavaDoc actionText) {
579             super(Toaster.getSharedFrame());
580             this.preferredSize = preferredSize;
581             this.callback = callback;
582             // #ifdef JAVA2
583
try {
584                 Method JavaDoc m = getClass().getMethod("setAlwaysOnTop", new Class JavaDoc[] { boolean.class }); //$NON-NLS-1$
585
m.invoke(this, new Object JavaDoc[] { Boolean.TRUE });
586             } catch (Exception JavaDoc e) {
587             }
588             // #endif
589
BorderPanel p = new BorderPanel(new GridBagLayout JavaDoc());
590             p.insets = new Insets JavaDoc(4, 4, 4, 4);
591             p.setBorderColor(borderColor);
592             p.setBackground(backgroundColor);
593             p.setForeground(foregroundColor);
594             GridBagConstraints JavaDoc gbc = new GridBagConstraints JavaDoc();
595             gbc.anchor = GridBagConstraints.CENTER;
596
597             Label JavaDoc tl = new Label JavaDoc(title);
598             tl.setFont(titleFont);
599             UIUtil.gridBagAdd(p, tl, gbc, GridBagConstraints.REMAINDER);
600
601             WrappingLabel l = new WrappingLabel();
602             l.setText(message);
603             l.setVAlignStyle(Canvas.TOP_ALIGNMENT);
604             l.setBackground(backgroundColor);
605             l.setForeground(foregroundColor);
606             gbc.fill = GridBagConstraints.BOTH;
607             gbc.weighty = 1.0;
608             l.setFont(textFont);
609             l.setHAlignStyle(textAlign);
610             gbc.weightx = 1.0;
611             if (image != null) {
612                 Panel JavaDoc pi = new Panel JavaDoc(new BorderLayout JavaDoc(4, 0));
613                 pi.setBackground(backgroundColor);
614                 pi.setForeground(foregroundColor);
615                 UIUtil.waitFor(image, this);
616                 ImageCanvas c = new ImageCanvas(image);
617                 c.setValign(Canvas.TOP_ALIGNMENT);
618                 pi.add(c, BorderLayout.WEST);
619                 pi.add(l, BorderLayout.CENTER);
620                 UIUtil.gridBagAdd(p, pi, gbc, GridBagConstraints.REMAINDER);
621             } else {
622                 UIUtil.gridBagAdd(p, l, gbc, GridBagConstraints.REMAINDER);
623             }
624
625             p.addMouseListener(this);
626             l.addMouseListener(this);
627             tl.addMouseListener(this);
628
629             add(p);
630
631             if (timeout > 0) {
632                 Thread JavaDoc t = new Thread JavaDoc() {
633                     public void run() {
634                         try {
635                             Thread.sleep(timeout);
636                         } catch (InterruptedException JavaDoc ie) {
637                         }
638                         hideAndRemove(MessageWindow.this);
639                     }
640                 };
641                 t.start();
642             }
643             
644             if(actionText != null) {
645                 Label JavaDoc l2 = new Label JavaDoc(actionText);
646                 l2.setAlignment(Label.CENTER);
647                 l2.setFont(new Font JavaDoc(titleFont.getName(), Font.PLAIN, 10));
648                 gbc.anchor = GridBagConstraints.CENTER;
649                 gbc.weightx = 1.0;
650                 UIUtil.gridBagAdd(p, l2, gbc, GridBagConstraints.REMAINDER);
651             }
652         }
653
654         public void setTargetY(int targetY) {
655             this.targetY = targetY;
656         }
657
658         public int getTargetY() {
659             return targetY;
660         }
661
662         public Dimension JavaDoc getPreferredSize() {
663             Dimension JavaDoc s = super.getPreferredSize();
664             if (s.height > preferredSize.height) {
665                 return new Dimension JavaDoc(preferredSize.width, s.height);
666             }
667             return preferredSize;
668         }
669
670         public void mouseClicked(MouseEvent JavaDoc e) {
671             if (callback != null) {
672                 callback.actionPerformed(new ActionEvent JavaDoc(this, ActionEvent.ACTION_PERFORMED, "clicked")); //$NON-NLS-1$
673
}
674             hideAndRemove(this);
675         }
676
677         public void mousePressed(MouseEvent JavaDoc e) {
678         }
679
680         public void mouseReleased(MouseEvent JavaDoc e) {
681         }
682
683         public void mouseEntered(MouseEvent JavaDoc e) {
684         }
685
686         public void mouseExited(MouseEvent JavaDoc e) {
687         }
688     }
689
690 }
691
Popular Tags