KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > gui > swt > SWTBalloonWindow


1 /*******************************************************************************
2  * Copyright (c) 2004 Stefan Zeiger and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.novocode.com/legal/epl-v10.html
7  *
8  * Contributors:
9  * Stefan Zeiger (szeiger@novocode.com) - initial API and implementation
10  *******************************************************************************/

11
12 package com.sslexplorer.agent.client.gui.swt;
13
14 import java.util.ArrayList JavaDoc;
15
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.graphics.Color;
18 import org.eclipse.swt.graphics.Font;
19 import org.eclipse.swt.graphics.FontData;
20 import org.eclipse.swt.graphics.GC;
21 import org.eclipse.swt.graphics.Image;
22 import org.eclipse.swt.graphics.Point;
23 import org.eclipse.swt.graphics.Rectangle;
24 import org.eclipse.swt.graphics.Region;
25 import org.eclipse.swt.widgets.Canvas;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Display;
29 import org.eclipse.swt.widgets.Event;
30 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.swt.widgets.Listener;
32 import org.eclipse.swt.widgets.Shell;
33 import org.eclipse.swt.widgets.ToolBar;
34 import org.eclipse.swt.widgets.ToolItem;
35 import org.eclipse.swt.widgets.Widget;
36
37 /**
38  * A Shell wrapper which creates balloon popup windows.
39  *
40  * <p>
41  * By default, a balloon window has no title bar or system controls. The
42  * following styles are supported:
43  * </p>
44  *
45  * <ul>
46  * <li>SWT.ON_TOP - Keep the window on top of other windows</li>
47  * <li>SWT.TOOL - Add a drop shadow to the window (on supported platforms)</li>
48  * <li>SWT.CLOSE - Show a "close" control on the title bar (implies SWT.TITLE)</li>
49  * <li>SWT.TITLE - Show a title bar</li>
50  * </ul>
51  *
52  * @author Stefan Zeiger (szeiger@novocode.com)
53  * @since Jul 2, 2004
54  * @version $Id: SWTBalloonWindow.java,v 1.1 2007/02/08 11:44:35 brett Exp $
55  */

56
57 public class SWTBalloonWindow {
58     private final Shell shell;
59     private final Composite contents;
60     private Label titleLabel;
61     private Canvas titleImageLabel;
62     private final int style;
63     private int preferredAnchor = SWT.BOTTOM | SWT.RIGHT;
64     private boolean autoAnchor = true;
65     private int autoLocation = SWT.NONE;
66     private int locX = Integer.MIN_VALUE, locY = Integer.MIN_VALUE;
67     private int marginLeft = 12, marginRight = 12, marginTop = 5, marginBottom = 10;
68     private int titleSpacing = 3, titleWidgetSpacing = 8;
69     private ToolBar systemControlsBar;
70     private ArrayList JavaDoc selectionControls = new ArrayList JavaDoc();
71     private boolean addedGlobalListener;
72     private ArrayList JavaDoc selectionListeners = new ArrayList JavaDoc();
73
74     public SWTBalloonWindow(Shell parent, int style) {
75         this(null, parent, style);
76     }
77
78     public SWTBalloonWindow(Display display, int style) {
79         this(display, null, style);
80     }
81
82     private SWTBalloonWindow(Display display, Shell parent, final int style) {
83         this.style = style;
84         int shellStyle = style & (SWT.ON_TOP | SWT.TOOL);
85         this.shell = (display != null) ? new Shell(display, SWT.NO_TRIM | shellStyle) : new Shell(parent, SWT.NO_TRIM | shellStyle);
86         this.contents = new Composite(shell, SWT.NONE);
87
88         final Color c = new Color(shell.getDisplay(), 255, 255, 225);
89         shell.setBackground(c);
90         shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
91         contents.setBackground(shell.getBackground());
92         contents.setForeground(shell.getForeground());
93
94         selectionControls.add(shell);
95         selectionControls.add(contents);
96
97         final Listener globalListener = new Listener() {
98             public void handleEvent(Event event) {
99                 Widget w = event.widget;
100                 for (int i = selectionControls.size() - 1; i >= 0; i--) {
101                     if (selectionControls.get(i) == w) {
102                         if ((style & SWT.CLOSE) != 0) {
103                             for (int j = selectionListeners.size() - 1; j >= 0; j--)
104                                 ((Listener) selectionListeners.get(j)).handleEvent(event);
105                         } else {
106                             shell.close();
107                         }
108                         event.doit = false;
109                     }
110                 }
111             }
112         };
113
114         shell.addListener(SWT.Show, new Listener() {
115             public void handleEvent(Event event) {
116                 if (!addedGlobalListener) {
117                     shell.getDisplay().addFilter(SWT.MouseDown, globalListener);
118                     addedGlobalListener = true;
119                 }
120             }
121         });
122
123         shell.addListener(SWT.Hide, new Listener() {
124             public void handleEvent(Event event) {
125                 if (addedGlobalListener) {
126                     shell.getDisplay().removeFilter(SWT.MouseDown, globalListener);
127                     addedGlobalListener = false;
128                 }
129             }
130         });
131
132         shell.addListener(SWT.Dispose, new Listener() {
133             public void handleEvent(Event event) {
134                 if (addedGlobalListener) {
135                     shell.getDisplay().removeFilter(SWT.MouseDown, globalListener);
136                     addedGlobalListener = false;
137                 }
138                 c.dispose();
139             }
140         });
141     }
142
143     /**
144      * Adds a control to the list of controls which close the balloon window.
145      * The background, title image and title text are included by default.
146      */

147
148     public void addSelectionControl(Control c) {
149         selectionControls.add(c);
150     }
151
152     public void addListener(int type, Listener l) {
153         if (type == SWT.Selection)
154             selectionListeners.add(l);
155     }
156
157     /**
158      * Set the location of the anchor. This must be one of the following values:
159      * SWT.NONE, SWT.LEFT|SWT.TOP, SWT.RIGHT|SWT.TOP, SWT.LEFT|SWT.BOTTOM,
160      * SWT.RIGHT|SWT.BOTTOM
161      */

162
163     public void setAnchor(int anchor) {
164         switch (anchor) {
165             case SWT.NONE:
166             case SWT.LEFT | SWT.TOP:
167             case SWT.RIGHT | SWT.TOP:
168             case SWT.LEFT | SWT.BOTTOM:
169             case SWT.RIGHT | SWT.BOTTOM:
170                 break;
171             default:
172                 throw new IllegalArgumentException JavaDoc("Illegal anchor value " + anchor);
173         }
174         this.preferredAnchor = anchor;
175     }
176
177     public void setAutoAnchor(boolean autoAnchor) {
178         this.autoAnchor = autoAnchor;
179     }
180
181     public void setAutoLocation(int autoLocation) {
182         this.autoLocation = autoLocation;
183     }
184
185     public void setLocation(int x, int y) {
186         this.locX = x;
187         this.locY = y;
188     }
189
190     public void setLocation(Point p) {
191         this.locX = p.x;
192         this.locY = p.y;
193     }
194
195     public void setText(String JavaDoc title) {
196         shell.setText(title);
197     }
198
199     public void setImage(Image image) {
200         shell.setImage(image);
201     }
202
203     public void setMargins(int marginLeft, int marginRight, int marginTop, int marginBottom) {
204         this.marginLeft = marginLeft;
205         this.marginRight = marginRight;
206         this.marginTop = marginTop;
207         this.marginBottom = marginBottom;
208     }
209
210     public void setMargins(int marginX, int marginY) {
211         setMargins(marginX, marginX, marginY, marginY);
212     }
213
214     public void setMargins(int margin) {
215         setMargins(margin, margin, margin, margin);
216     }
217
218     public void setTitleSpacing(int titleSpacing) {
219         this.titleSpacing = titleSpacing;
220     }
221
222     public void setTitleWidgetSpacing(int titleImageSpacing) {
223         this.titleWidgetSpacing = titleImageSpacing;
224     }
225
226     public Shell getShell() {
227         return shell;
228     }
229
230     public Composite getContents() {
231         return contents;
232     }
233
234     public void prepareForOpen() {
235         Point contentsSize = contents.getSize();
236         Point titleSize = new Point(0, 0);
237
238         boolean showTitle = ((style & (SWT.CLOSE | SWT.TITLE)) != 0);
239         if (showTitle) {
240             if (titleLabel == null) {
241                 titleLabel = new Label(shell, SWT.NONE);
242                 titleLabel.setBackground(shell.getBackground());
243                 titleLabel.setForeground(shell.getForeground());
244                 FontData[] fds = shell.getFont().getFontData();
245                 for (int i = 0; i < fds.length; i++) {
246                     fds[i].setStyle(fds[i].getStyle() | SWT.BOLD);
247                 }
248                 final Font font = new Font(shell.getDisplay(), fds);
249                 titleLabel.addListener(SWT.Dispose, new Listener() {
250                     public void handleEvent(Event event) {
251                         font.dispose();
252                     }
253                 });
254                 titleLabel.setFont(font);
255                 selectionControls.add(titleLabel);
256             }
257             String JavaDoc titleText = shell.getText();
258             titleLabel.setText(titleText == null ? "" : titleText);
259             titleLabel.pack();
260             titleSize = titleLabel.getSize();
261
262             final Image titleImage = shell.getImage();
263             if (titleImageLabel == null && shell.getImage() != null) {
264                 titleImageLabel = new Canvas(shell, SWT.NONE);
265                 titleImageLabel.setBackground(shell.getBackground());
266                 titleImageLabel.setBounds(titleImage.getBounds());
267                 titleImageLabel.addListener(SWT.Paint, new Listener() {
268                     public void handleEvent(Event event) {
269                         event.gc.drawImage(titleImage, 0, 0);
270                     }
271                 });
272                 Point tilSize = titleImageLabel.getSize();
273                 titleSize.x += tilSize.x + titleWidgetSpacing;
274                 if (tilSize.y > titleSize.y)
275                     titleSize.y = tilSize.y;
276                 selectionControls.add(titleImageLabel);
277             }
278
279             if (systemControlsBar == null && (style & SWT.CLOSE) != 0) {
280                 // Color closeFG = shell.getForeground(), closeBG =
281
// shell.getBackground();
282
// Color closeFG =
283
// shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY),
284
// closeBG = shell.getBackground();
285
Color closeFG = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND), closeBG = shell.getDisplay()
286                                 .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
287                 final Image closeImage = createCloseImage(shell.getDisplay(), closeBG, closeFG);
288                 shell.addListener(SWT.Dispose, new Listener() {
289                     public void handleEvent(Event event) {
290                         closeImage.dispose();
291                     }
292                 });
293                 systemControlsBar = new ToolBar(shell, SWT.FLAT);
294                 systemControlsBar.setBackground(closeBG);
295                 systemControlsBar.setForeground(closeFG);
296                 ToolItem closeItem = new ToolItem(systemControlsBar, SWT.PUSH);
297                 closeItem.setImage(closeImage);
298                 closeItem.addListener(SWT.Selection, new Listener() {
299                     public void handleEvent(Event event) {
300                         shell.close();
301                     }
302                 });
303                 systemControlsBar.pack();
304                 Point closeSize = systemControlsBar.getSize();
305                 titleSize.x += closeSize.x + titleWidgetSpacing;
306                 if (closeSize.y > titleSize.y)
307                     titleSize.y = closeSize.y;
308             }
309
310             titleSize.y += titleSpacing;
311             if (titleSize.x > contentsSize.x) {
312                 contentsSize.x = titleSize.x;
313                 contents.setSize(contentsSize.x, contentsSize.y);
314             }
315             contentsSize.y += titleSize.y;
316         }
317
318         Rectangle screen = shell.getDisplay().getClientArea();
319
320         int anchor = preferredAnchor;
321         if (anchor != SWT.NONE && autoAnchor && locX != Integer.MIN_VALUE) {
322             if ((anchor & SWT.LEFT) != 0) {
323                 if (locX + contentsSize.x + marginLeft + marginRight - 16 >= screen.x + screen.width)
324                     anchor = anchor - SWT.LEFT + SWT.RIGHT;
325             } else // RIGHT
326
{
327                 if (locX - contentsSize.x - marginLeft - marginRight + 16 < screen.x)
328                     anchor = anchor - SWT.RIGHT + SWT.LEFT;
329             }
330             if ((anchor & SWT.TOP) != 0) {
331                 if (locY + contentsSize.y + 20 + marginTop + marginBottom >= screen.y + screen.height)
332                     anchor = anchor - SWT.TOP + SWT.BOTTOM;
333             } else // BOTTOM
334
{
335                 if (locY - contentsSize.y - 20 - marginTop - marginBottom < screen.y)
336                     anchor = anchor - SWT.BOTTOM + SWT.TOP;
337             }
338         }
339
340         final Point shellSize = (anchor == SWT.NONE) ? new Point(contentsSize.x + marginLeft + marginRight,
341                         contentsSize.y + marginTop + marginBottom) : new Point(contentsSize.x + marginLeft + marginRight,
342                         contentsSize.y + marginTop + marginBottom + 20);
343
344         if (shellSize.x < 54 + marginLeft + marginRight)
345             shellSize.x = 54 + marginLeft + marginRight;
346         if (anchor == SWT.NONE) {
347             if (shellSize.y < 10 + marginTop + marginBottom)
348                 shellSize.y = 10 + marginTop + marginBottom;
349         } else {
350             if (shellSize.y < 30 + marginTop + marginBottom)
351                 shellSize.y = 30 + marginTop + marginBottom;
352         }
353
354         shell.setSize(shellSize);
355         int titleLocY = marginTop + (((anchor & SWT.TOP) != 0) ? 20 : 0);
356         contents.setLocation(marginLeft, titleSize.y + titleLocY);
357         if (showTitle) {
358             int realTitleHeight = titleSize.y - titleSpacing;
359             if (titleImageLabel != null) {
360                 titleImageLabel.setLocation(marginLeft, titleLocY + (realTitleHeight - titleImageLabel.getSize().y) / 2);
361                 titleLabel.setLocation(marginLeft + titleImageLabel.getSize().x + titleWidgetSpacing,
362                     titleLocY + (realTitleHeight - titleLabel.getSize().y) / 2);
363             } else
364                 titleLabel.setLocation(marginLeft, titleLocY + (realTitleHeight - titleLabel.getSize().y) / 2);
365             if (systemControlsBar != null)
366                 systemControlsBar.setLocation(shellSize.x - marginRight - systemControlsBar.getSize().x,
367                     titleLocY + (realTitleHeight - systemControlsBar.getSize().y) / 2);
368         }
369
370         final Region region = new Region();
371         region.add(createOutline(shellSize, anchor, true));
372
373         shell.setRegion(region);
374         shell.addListener(SWT.Dispose, new Listener() {
375             public void handleEvent(Event event) {
376                 region.dispose();
377             }
378         });
379
380         final int[] outline = createOutline(shellSize, anchor, false);
381         shell.addListener(SWT.Paint, new Listener() {
382             public void handleEvent(Event event) {
383                 event.gc.drawPolygon(outline);
384             }
385         });
386
387         if (autoLocation != SWT.NONE) {
388             Point shellLoc = new Point(locX == Integer.MIN_VALUE ? 0 : locX, locY == Integer.MIN_VALUE ? 0 : locY);
389             Rectangle screenBounds = shell.getDisplay().getPrimaryMonitor().getBounds();
390             if ((autoLocation & SWT.RIGHT) != 0) {
391                 shellLoc.x = screenBounds.width - shellSize.x - shellLoc.x;
392             }
393             if ((autoLocation & SWT.BOTTOM) != 0) {
394                 shellLoc.y = screenBounds.height - shellSize.y - shellLoc.y;
395             }
396             shell.setLocation(shellLoc);
397         }
398         else {
399             if (locX != Integer.MIN_VALUE) {
400                 Point shellLoc = new Point(locX, locY);
401                 if ((anchor & SWT.BOTTOM) != 0)
402                     shellLoc.y = shellLoc.y - shellSize.y + 1;
403                 if ((anchor & SWT.LEFT) != 0)
404                     shellLoc.x -= 15;
405                 else if ((anchor & SWT.RIGHT) != 0)
406                     shellLoc.x = shellLoc.x - shellSize.x + 16;
407
408                 if (autoAnchor) {
409                     if (shellLoc.x < screen.x)
410                         shellLoc.x = screen.x;
411                     else if (shellLoc.x > screen.x + screen.width - shellSize.x)
412                         shellLoc.x = screen.x + screen.width - shellSize.x;
413
414                     if (anchor == SWT.NONE) {
415                         if (shellLoc.y < screen.y)
416                             shellLoc.y = screen.y;
417                         else if (shellLoc.y > screen.y + screen.height - shellSize.y)
418                             shellLoc.y = screen.y + screen.height - shellSize.y;
419                     }
420                 }
421
422                 shell.setLocation(shellLoc);
423             }
424         }
425     }
426
427     public void open() {
428         prepareForOpen();
429         shell.open();
430     }
431
432     public void close() {
433         shell.close();
434     }
435
436     public void setVisible(boolean visible) {
437         if (visible)
438             prepareForOpen();
439         shell.setVisible(visible);
440     }
441
442     private static int[] createOutline(Point size, int anchor, boolean outer) {
443         int o = outer ? 1 : 0;
444         int w = size.x + o;
445         int h = size.y + o;
446
447         switch (anchor) {
448             case SWT.RIGHT | SWT.BOTTOM:
449                 return new int[] {
450                 // top and top right
451
5,
452                     0,
453                     w - 6,
454                     0,
455                     w - 6,
456                     1,
457                     w - 4,
458                     1,
459                     w - 4,
460                     2,
461                     w - 3,
462                     2,
463                     w - 3,
464                     3,
465                     w - 2,
466                     3,
467                     w - 2,
468                     5,
469                     w - 1,
470                     5,
471                     // right and bottom right
472
w - 1,
473                     h - 26,
474                     w - 2,
475                     h - 26,
476                     w - 2,
477                     h - 24,
478                     w - 3,
479                     h - 24,
480                     w - 3,
481                     h - 23,
482                     w - 4,
483                     h - 23,
484                     w - 4,
485                     h - 22,
486                     w - 6,
487                     h - 22,
488                     w - 6,
489                     h - 21,
490                     // bottom with anchor
491
w - 16,
492                     h - 21,
493                     w - 16,
494                     h - 1,
495                     w - 16 - o,
496                     h - 1,
497                     w - 16 - o,
498                     h - 2,
499                     w - 17 - o,
500                     h - 2,
501                     w - 17 - o,
502                     h - 3,
503                     w - 18 - o,
504                     h - 3,
505                     w - 18 - o,
506                     h - 4,
507                     w - 19 - o,
508                     h - 4,
509                     w - 19 - o,
510                     h - 5,
511                     w - 20 - o,
512                     h - 5,
513                     w - 20 - o,
514                     h - 6,
515                     w - 21 - o,
516                     h - 6,
517                     w - 21 - o,
518                     h - 7,
519                     w - 22 - o,
520                     h - 7,
521                     w - 22 - o,
522                     h - 8,
523                     w - 23 - o,
524                     h - 8,
525                     w - 23 - o,
526                     h - 9,
527                     w - 24 - o,
528                     h - 9,
529                     w - 24 - o,
530                     h - 10,
531                     w - 25 - o,
532                     h - 10,
533                     w - 25 - o,
534                     h - 11,
535                     w - 26 - o,
536                     h - 11,
537                     w - 26 - o,
538                     h - 12,
539                     w - 27 - o,
540                     h - 12,
541                     w - 27 - o,
542                     h - 13,
543                     w - 28 - o,
544                     h - 13,
545                     w - 28 - o,
546                     h - 14,
547                     w - 29 - o,
548                     h - 14,
549                     w - 29 - o,
550                     h - 15,
551                     w - 30 - o,
552                     h - 15,
553                     w - 30 - o,
554                     h - 16,
555                     w - 31 - o,
556                     h - 16,
557                     w - 31 - o,
558                     h - 17,
559                     w - 32 - o,
560                     h - 17,
561                     w - 32 - o,
562                     h - 18,
563                     w - 33 - o,
564                     h - 18,
565                     w - 33 - o,
566                     h - 19,
567                     w - 34 - o,
568                     h - 19,
569                     w - 34 - o,
570                     h - 20,
571                     w - 35 - o,
572                     h - 20,
573                     w - 35 - o,
574                     h - 21,
575                     // bottom left
576
5,
577                     h - 21,
578                     5,
579                     h - 22,
580                     3,
581                     h - 22,
582                     3,
583                     h - 23,
584                     2,
585                     h - 23,
586                     2,
587                     h - 24,
588                     1,
589                     h - 24,
590                     1,
591                     h - 26,
592                     0,
593                     h - 26,
594                     // left and top left
595
0,
596                     5,
597                     1,
598                     5,
599                     1,
600                     3,
601                     2,
602                     3,
603                     2,
604                     2,
605                     3,
606                     2,
607                     3,
608                     1,
609                     5,
610                     1 };
611             case SWT.LEFT | SWT.BOTTOM:
612                 return new int[] {
613                 // top and top right
614
5,
615                     0,
616                     w - 6,
617                     0,
618                     w - 6,
619                     1,
620                     w - 4,
621                     1,
622                     w - 4,
623                     2,
624                     w - 3,
625                     2,
626                     w - 3,
627                     3,
628                     w - 2,
629                     3,
630                     w - 2,
631                     5,
632                     w - 1,
633                     5,
634                     // right and bottom right
635
w - 1,
636                     h - 26,
637                     w - 2,
638                     h - 26,
639                     w - 2,
640                     h - 24,
641                     w - 3,
642                     h - 24,
643                     w - 3,
644                     h - 23,
645                     w - 4,
646                     h - 23,
647                     w - 4,
648                     h - 22,
649                     w - 6,
650                     h - 22,
651                     w - 6,
652                     h - 21,
653                     // bottom with anchor
654
34 + o,
655                     h - 21,
656                     34 + o,
657                     h - 20,
658                     33 + o,
659                     h - 20,
660                     33 + o,
661                     h - 19,
662                     32 + o,
663                     h - 19,
664                     32 + o,
665                     h - 18,
666                     31 + o,
667                     h - 18,
668                     31 + o,
669                     h - 17,
670                     30 + o,
671                     h - 17,
672                     30 + o,
673                     h - 16,
674                     29 + o,
675                     h - 16,
676                     29 + o,
677                     h - 15,
678                     28 + o,
679                     h - 15,
680                     28 + o,
681                     h - 14,
682                     27 + o,
683                     h - 14,
684                     27 + o,
685                     h - 13,
686                     26 + o,
687                     h - 13,
688                     26 + o,
689                     h - 12,
690                     25 + o,
691                     h - 12,
692                     25 + o,
693                     h - 11,
694                     24 + o,
695                     h - 11,
696                     24 + o,
697                     h - 10,
698                     23 + o,
699                     h - 10,
700                     23 + o,
701                     h - 9,
702                     22 + o,
703                     h - 9,
704                     22 + o,
705                     h - 8,
706                     21 + o,
707                     h - 8,
708                     21 + o,
709                     h - 7,
710                     20 + o,
711                     h - 7,
712                     20 + o,
713                     h - 6,
714                     19 + o,
715                     h - 6,
716                     19 + o,
717                     h - 5,
718                     18 + o,
719                     h - 5,
720                     18 + o,
721                     h - 4,
722                     17 + o,
723                     h - 4,
724                     17 + o,
725                     h - 3,
726                     16 + o,
727                     h - 3,
728                     16 + o,
729                     h - 2,
730                     15 + o,
731                     h - 2,
732                     15,
733                     h - 1,
734                     15,
735                     h - 21,
736                     // bottom left
737
5,
738                     h - 21,
739                     5,
740                     h - 22,
741                     3,
742                     h - 22,
743                     3,
744                     h - 23,
745                     2,
746                     h - 23,
747                     2,
748                     h - 24,
749                     1,
750                     h - 24,
751                     1,
752                     h - 26,
753                     0,
754                     h - 26,
755                     // left and top left
756
0,
757                     5,
758                     1,
759                     5,
760                     1,
761                     3,
762                     2,
763                     3,
764                     2,
765                     2,
766                     3,
767                     2,
768                     3,
769                     1,
770                     5,
771                     1 };
772             case SWT.RIGHT | SWT.TOP:
773                 return new int[] {
774                 // top with anchor
775
5,
776                     20,
777                     w - 35 - o,
778                     20,
779                     w - 35 - o,
780                     19,
781                     w - 34 - o,
782                     19,
783                     w - 34 - o,
784                     18,
785                     w - 33 - o,
786                     18,
787                     w - 33 - o,
788                     17,
789                     w - 32 - o,
790                     17,
791                     w - 32 - o,
792                     16,
793                     w - 31 - o,
794                     16,
795                     w - 31 - o,
796                     15,
797                     w - 30 - o,
798                     15,
799                     w - 30 - o,
800                     14,
801                     w - 29 - o,
802                     14,
803                     w - 29 - o,
804                     13,
805                     w - 28 - o,
806                     13,
807                     w - 28 - o,
808                     12,
809                     w - 27 - o,
810                     12,
811                     w - 27 - o,
812                     11,
813                     w - 26 - o,
814                     11,
815                     w - 26 - o,
816                     10,
817                     w - 25 - o,
818                     10,
819                     w - 25 - o,
820                     9,
821                     w - 24 - o,
822                     9,
823                     w - 24 - o,
824                     8,
825                     w - 23 - o,
826                     8,
827                     w - 23 - o,
828                     7,
829                     w - 22 - o,
830                     7,
831                     w - 22 - o,
832                     6,
833                     w - 21 - o,
834                     6,
835                     w - 21 - o,
836                     5,
837                     w - 20 - o,
838                     5,
839                     w - 20 - o,
840                     4,
841                     w - 19 - o,
842                     4,
843                     w - 19 - o,
844                     3,
845                     w - 18 - o,
846                     3,
847                     w - 18 - o,
848                     2,
849                     w - 17 - o,
850                     2,
851                     w - 17 - o,
852                     1,
853                     w - 16 - o,
854                     1,
855                     w - 16 - o,
856                     0,
857                     w - 16,
858                     0,
859                     w - 16,
860                     20,
861                     // top and top right
862
w - 6,
863                     20,
864                     w - 6,
865                     21,
866                     w - 4,
867                     21,
868                     w - 4,
869                     22,
870                     w - 3,
871                     22,
872                     w - 3,
873                     23,
874                     w - 2,
875                     23,
876                     w - 2,
877                     25,
878                     w - 1,
879                     25,
880                     // right and bottom right
881
w - 1,
882                     h - 6,
883                     w - 2,
884                     h - 6,
885                     w - 2,
886                     h - 4,
887                     w - 3,
888                     h - 4,
889                     w - 3,
890                     h - 3,
891                     w - 4,
892                     h - 3,
893                     w - 4,
894                     h - 2,
895                     w - 6,
896                     h - 2,
897                     w - 6,
898                     h - 1,
899                     // bottom and bottom left
900
5,
901                     h - 1,
902                     5,
903                     h - 2,
904                     3,
905                     h - 2,
906                     3,
907                     h - 3,
908                     2,
909                     h - 3,
910                     2,
911                     h - 4,
912                     1,
913                     h - 4,
914                     1,
915                     h - 6,
916                     0,
917                     h - 6,
918                     // left and top left
919
0,
920                     25,
921                     1,
922                     25,
923                     1,
924                     23,
925                     2,
926                     23,
927                     2,
928                     22,
929                     3,
930                     22,
931                     3,
932                     21,
933                     5,
934                     21 };
935             case SWT.LEFT | SWT.TOP:
936                 return new int[] {
937                 // top with anchor
938
5,
939                     20,
940                     15,
941                     20,
942                     15,
943                     0,
944                     15 + o,
945                     0,
946                     16 + o,
947                     1,
948                     16 + o,
949                     2,
950                     17 + o,
951                     2,
952                     17 + o,
953                     3,
954                     18 + o,
955                     3,
956                     18 + o,
957                     4,
958                     19 + o,
959                     4,
960                     19 + o,
961                     5,
962                     20 + o,
963                     5,
964                     20 + o,
965                     6,
966                     21 + o,
967                     6,
968                     21 + o,
969                     7,
970                     22 + o,
971                     7,
972                     22 + o,
973                     8,
974                     23 + o,
975                     8,
976                     23 + o,
977                     9,
978                     24 + o,
979                     9,
980                     24 + o,
981                     10,
982                     25 + o,
983                     10,
984                     25 + o,
985                     11,
986                     26 + o,
987                     11,
988                     26 + o,
989                     12,
990                     27 + o,
991                     12,
992                     27 + o,
993                     13,
994                     28 + o,
995                     13,
996                     28 + o,
997                     14,
998                     29 + o,
999                     14,
1000                    29 + o,
1001                    15,
1002                    30 + o,
1003                    15,
1004                    30 + o,
1005                    16,
1006                    31 + o,
1007                    16,
1008                    31 + o,
1009                    17,
1010                    32 + o,
1011                    17,
1012                    32 + o,
1013                    18,
1014                    33 + o,
1015                    18,
1016                    33 + o,
1017                    19,
1018                    34 + o,
1019                    19,
1020                    34 + o,
1021                    20,
1022                    // top and top right
1023
w - 6,
1024                    20,
1025                    w - 6,
1026                    21,
1027                    w - 4,
1028                    21,
1029                    w - 4,
1030                    22,
1031                    w - 3,
1032                    22,
1033                    w - 3,
1034                    23,
1035                    w - 2,
1036                    23,
1037                    w - 2,
1038                    25,
1039                    w - 1,
1040                    25,
1041                    // right and bottom right
1042
w - 1,
1043                    h - 6,
1044                    w - 2,
1045                    h - 6,
1046                    w - 2,
1047                    h - 4,
1048                    w - 3,
1049                    h - 4,
1050                    w - 3,
1051                    h - 3,
1052                    w - 4,
1053                    h - 3,
1054                    w - 4,
1055                    h - 2,
1056                    w - 6,
1057                    h - 2,
1058                    w - 6,
1059                    h - 1,
1060                    // bottom and bottom left
1061
5,
1062                    h - 1,
1063                    5,
1064                    h - 2,
1065                    3,
1066                    h - 2,
1067                    3,
1068                    h - 3,
1069                    2,
1070                    h - 3,
1071                    2,
1072                    h - 4,
1073                    1,
1074                    h - 4,
1075                    1,
1076                    h - 6,
1077                    0,
1078                    h - 6,
1079                    // left and top left
1080
0,
1081                    25,
1082                    1,
1083                    25,
1084                    1,
1085                    23,
1086                    2,
1087                    23,
1088                    2,
1089                    22,
1090                    3,
1091                    22,
1092                    3,
1093                    21,
1094                    5,
1095                    21 };
1096            default:
1097                return new int[] {
1098                // top and top right
1099
5,
1100                    0,
1101                    w - 6,
1102                    0,
1103                    w - 6,
1104                    1,
1105                    w - 4,
1106                    1,
1107                    w - 4,
1108                    2,
1109                    w - 3,
1110                    2,
1111                    w - 3,
1112                    3,
1113                    w - 2,
1114                    3,
1115                    w - 2,
1116                    5,
1117                    w - 1,
1118                    5,
1119                    // right and bottom right
1120
w - 1,
1121                    h - 6,
1122                    w - 2,
1123                    h - 6,
1124                    w - 2,
1125                    h - 4,
1126                    w - 3,
1127                    h - 4,
1128                    w - 3,
1129                    h - 3,
1130                    w - 4,
1131                    h - 3,
1132                    w - 4,
1133                    h - 2,
1134                    w - 6,
1135                    h - 2,
1136                    w - 6,
1137                    h - 1,
1138                    // bottom and bottom left
1139
5,
1140                    h - 1,
1141                    5,
1142                    h - 2,
1143                    3,
1144                    h - 2,
1145                    3,
1146                    h - 3,
1147                    2,
1148                    h - 3,
1149                    2,
1150                    h - 4,
1151                    1,
1152                    h - 4,
1153                    1,
1154                    h - 6,
1155                    0,
1156                    h - 6,
1157                    // left and top left
1158
0,
1159                    5,
1160                    1,
1161                    5,
1162                    1,
1163                    3,
1164                    2,
1165                    3,
1166                    2,
1167                    2,
1168                    3,
1169                    2,
1170                    3,
1171                    1,
1172                    5,
1173                    1 };
1174        }
1175    }
1176
1177    private static final Image createCloseImage(Display display, Color bg, Color fg) {
1178        int size = 11, off = 1;
1179        Image image = new Image(display, size, size);
1180        GC gc = new GC(image);
1181        gc.setBackground(bg);
1182        gc.fillRectangle(image.getBounds());
1183        gc.setForeground(fg);
1184        gc.drawLine(0 + off, 0 + off, size - 1 - off, size - 1 - off);
1185        gc.drawLine(1 + off, 0 + off, size - 1 - off, size - 2 - off);
1186        gc.drawLine(0 + off, 1 + off, size - 2 - off, size - 1 - off);
1187        gc.drawLine(size - 1 - off, 0 + off, 0 + off, size - 1 - off);
1188        gc.drawLine(size - 1 - off, 1 + off, 1 + off, size - 1 - off);
1189        gc.drawLine(size - 2 - off, 0 + off, 0 + off, size - 2 - off);
1190        /*
1191         * gc.drawLine(1, 0, size-2, 0); gc.drawLine(1, size-1, size-2, size-1);
1192         * gc.drawLine(0, 1, 0, size-2); gc.drawLine(size-1, 1, size-1, size-2);
1193         */

1194        gc.dispose();
1195        return image;
1196    }
1197}
1198
Popular Tags