1 /*******************************************************************************
2 * Copyright (c) 2000, 2009 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.widgets;
17 import org.eclipse.swt.*;
20 * Instances of this class represent the system tray that is part
21 * of the task bar status area on some operating systems.
24 * <dt><b>Styles:</b></dt>
26 * <dt><b>Events:</b></dt>
30 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
33 * @see Display#getSystemTray
34 * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a>
35 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
38 * @noextend This class is not intended to be subclassed by clients.
40 public class Tray extends Widget {
42 TrayItem [] items = new TrayItem [4];
44 Tray (Display display, int style) {
45 this.display = display;
49 void createItem (TrayItem item, int index) {
50 if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
51 if (itemCount == items.length) {
52 TrayItem [] newItems = new TrayItem [items.length + 4];
53 System.arraycopy (items, 0, newItems, 0, items.length);
56 System.arraycopy (items, index, items, index + 1, itemCount++ - index);
60 void destroyItem (TrayItem item) {
62 while (index < itemCount) {
63 if (items [index] == item) break;
66 if (index == itemCount) return;
67 System.arraycopy (items, index + 1, items, index, --itemCount - index);
68 items [itemCount] = null;
72 * Returns the item at the given, zero-relative index in the
73 * receiver. Throws an exception if the index is out of range.
75 * @param index the index of the item to return
76 * @return the item at the given index
78 * @exception IllegalArgumentException <ul>
79 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
81 * @exception SWTException <ul>
82 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
83 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
86 public TrayItem getItem (int index) {
88 if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
93 * Returns the number of items contained in the receiver.
95 * @return the number of items
97 * @exception SWTException <ul>
98 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
99 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
102 public int getItemCount () {
108 * Returns an array of <code>TrayItem</code>s which are the items
111 * Note: This is not the actual structure used by the receiver
112 * to maintain its list of items, so modifying the array will
113 * not affect the receiver.
116 * @return the items in the receiver
118 * @exception SWTException <ul>
119 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
120 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
123 public TrayItem [] getItems () {
125 TrayItem [] result = new TrayItem [itemCount];
126 System.arraycopy (items, 0, result, 0, result.length);
131 void releaseChildren (boolean destroy) {
133 for (int i=0; i<items.length; i++) {
134 TrayItem item = items [i];
135 if (item != null && !item.isDisposed ()) {
136 item.release (false);
141 super.releaseChildren (destroy);
145 void releaseParent () {
146 super.releaseParent ();
147 if (display.tray == this) display.tray = null;
151 void reskinChildren (int flags) {
153 for (int i=0; i<items.length; i++) {
154 TrayItem item = items [i];
155 if (item != null) item.reskin (flags);
158 super.reskinChildren (flags);