1 11 package org.eclipse.swt.widgets; 12 13 14 import org.eclipse.swt.*; 15 16 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 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 100 public int getItemCount () { 101 checkWidget (); 102 return itemCount; 103 } 104 105 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 |