KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > widgets > Tray


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation 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.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.swt.widgets;
12
13
14 import org.eclipse.swt.*;
15
16 /**
17  * Instances of this class represent the system tray that is part
18  * of the task bar status area on some operating systems.
19  *
20  * <dl>
21  * <dt><b>Styles:</b></dt>
22  * <dd>(none)</dd>
23  * <dt><b>Events:</b></dt>
24  * <dd>(none)</dd>
25  * </dl>
26  * <p>
27  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
28  * </p>
29  *
30  * @see Display#getSystemTray
31  *
32  * @since 3.0
33  */

34 public class Tray extends Widget {
35     int itemCount;
36     TrayItem [] items = new TrayItem [4];
37
38 Tray (Display display, int style) {
39     if (display == null) display = Display.getCurrent ();
40     if (display == null) display = Display.getDefault ();
41     if (!display.isValidThread ()) {
42         error (SWT.ERROR_THREAD_INVALID_ACCESS);
43     }
44     this.display = display;
45 }
46     
47 void createItem (TrayItem item, int index) {
48     if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
49     if (itemCount == items.length) {
50         TrayItem [] newItems = new TrayItem [items.length + 4];
51         System.arraycopy (items, 0, newItems, 0, items.length);
52         items = newItems;
53     }
54     System.arraycopy (items, index, items, index + 1, itemCount++ - index);
55     items [index] = item;
56 }
57
58 void destroyItem (TrayItem item) {
59     int index = 0;
60     while (index < itemCount) {
61         if (items [index] == item) break;
62         index++;
63     }
64     if (index == itemCount) return;
65     System.arraycopy (items, index + 1, items, index, --itemCount - index);
66     items [itemCount] = null;
67 }
68
69 /**
70  * Returns the item at the given, zero-relative index in the
71  * receiver. Throws an exception if the index is out of range.
72  *
73  * @param index the index of the item to return
74  * @return the item at the given index
75  *
76  * @exception IllegalArgumentException <ul>
77  * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
78  * </ul>
79  * @exception SWTException <ul>
80  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
81  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
82  * </ul>
83  */

84 public TrayItem getItem (int index) {
85     checkWidget ();
86     if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
87     return items [index];
88 }
89
90 /**
91  * Returns the number of items contained in the receiver.
92  *
93  * @return the number of items
94  *
95  * @exception SWTException <ul>
96  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
97  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
98  * </ul>
99  */

100 public int getItemCount () {
101     checkWidget ();
102     return itemCount;
103 }
104
105 /**
106  * Returns an array of <code>TrayItem</code>s which are the items
107  * in the receiver.
108  * <p>
109  * Note: This is not the actual structure used by the receiver
110  * to maintain its list of items, so modifying the array will
111  * not affect the receiver.
112  * </p>
113  *
114  * @return the items in the receiver
115  *
116  * @exception SWTException <ul>
117  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
118  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
119  * </ul>
120  */

121 public TrayItem [] getItems () {
122     checkWidget ();
123     TrayItem [] result = new TrayItem [itemCount];
124     System.arraycopy (items, 0, result, 0, result.length);
125     return result;
126 }
127
128 void releaseChildren (boolean destroy) {
129     if (items != null) {
130         for (int i=0; i<items.length; i++) {
131             TrayItem item = items [i];
132             if (item != null && !item.isDisposed ()) {
133                 item.release (false);
134             }
135         }
136         items = null;
137     }
138     super.releaseChildren (destroy);
139 }
140
141 void releaseParent () {
142     super.releaseParent ();
143     if (display.tray == this) display.tray = null;
144 }
145
146 }
147
Popular Tags