?? ccombo.java
字號:
* @exception SWTError(ERROR_CANNOT_GET_COUNT)* when the operation fails*/public int getItemCount () { checkWidget(); return list.getItemCount ();}/*** Gets the height of one item.* <p>* This operation will fail if the height of* one item could not be queried from the OS.** @return the height of one item in the widget** @exception SWTError(ERROR_THREAD_INVALID_ACCESS)* when called from the wrong thread* @exception SWTError(ERROR_WIDGET_DISPOSED)* when the widget has been disposed* @exception SWTError(ERROR_CANNOT_GET_ITEM_HEIGHT)* when the operation fails*/public int getItemHeight () { checkWidget(); return list.getItemHeight ();}/*** Gets the items.* <p>* This operation will fail if the items cannot* be queried from the OS.** @return the items in the widget** @exception SWTError(ERROR_THREAD_INVALID_ACCESS)* when called from the wrong thread* @exception SWTError(ERROR_WIDGET_DISPOSED)* when the widget has been disposed* @exception SWTError(ERROR_CANNOT_GET_ITEM)* when the operation fails*/public String [] getItems () { checkWidget(); return list.getItems ();}char getMnemonic (String string) { int index = 0; int length = string.length (); do { while ((index < length) && (string.charAt (index) != '&')) index++; if (++index >= length) return '\0'; if (string.charAt (index) != '&') return string.charAt (index); index++; } while (index < length); return '\0';}/*** Gets the selection.* <p>* @return a point representing the selection start and end** @exception SWTError(ERROR_THREAD_INVALID_ACCESS)* when called from the wrong thread* @exception SWTError(ERROR_WIDGET_DISPOSED)* when the widget has been disposed*/public Point getSelection () { checkWidget(); return text.getSelection ();}/*** Gets the index of the selected item.* <p>* Indexing is zero based.* If no item is selected -1 is returned.** @return the index of the selected item.** @exception SWTError(ERROR_THREAD_INVALID_ACCESS)* when called from the wrong thread* @exception SWTError(ERROR_WIDGET_DISPOSED)* when the widget has been disposed*/public int getSelectionIndex () { checkWidget(); return list.getSelectionIndex ();}public int getStyle () { int style = super.getStyle(); style &= ~SWT.READ_ONLY; if (!text.getEditable()) style |= SWT.READ_ONLY; return style;}/*** Gets the widget text.* <p>* If the widget has no text, an empty string is returned.** @return the widget text** @exception SWTError(ERROR_THREAD_INVALID_ACCESS)* when called from the wrong thread* @exception SWTError(ERROR_WIDGET_DISPOSED)* when the widget has been disposed*/public String getText () { checkWidget(); return text.getText ();}/*** Gets the height of the combo's text field.* <p>* The operation will fail if the height cannot * be queried from the OS.* @return the height of the combo's text field.* * @exception SWTError(ERROR_THREAD_INVALID_ACCESS)* when called from the wrong thread* @exception SWTError(ERROR_WIDGET_DISPOSED)* when the widget has been disposed* @exception SWTError(ERROR_ERROR_CANNOT_GET_ITEM_HEIGHT)* when the operation fails*/public int getTextHeight () { checkWidget(); return text.getLineHeight();}/*** Gets the text limit.* <p>* @return the text limit* * @exception SWTError(ERROR_THREAD_INVALID_ACCESS)* when called from the wrong thread* @exception SWTError(ERROR_WIDGET_DISPOSED)* when the widget has been disposed*/public int getTextLimit () { checkWidget(); return text.getTextLimit ();}/** * Gets the number of items that are visible in the drop * down portion of the receiver's list. * * @return the number of items that are visible * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @since 3.0 */public int getVisibleItemCount () { checkWidget (); return visibleItemCount;}void handleFocus (int type) { if (isDisposed()) return; switch (type) { case SWT.FocusIn: { if (hasFocus) return; if (getEditable ()) text.selectAll (); hasFocus = true; Shell shell = getShell (); shell.removeListener(SWT.Deactivate, listener); shell.addListener(SWT.Deactivate, listener); Display display = getDisplay(); display.removeFilter(SWT.FocusIn, filter); display.addFilter(SWT.FocusIn, filter); Event e = new Event(); notifyListeners(SWT.FocusIn, e); break; } case SWT.FocusOut: { if (!hasFocus) return; Control focusControl = getDisplay().getFocusControl(); if (focusControl == arrow || focusControl == list || focusControl == text) return; hasFocus = false; Shell shell = getShell (); shell.removeListener(SWT.Deactivate, listener); Display display = getDisplay(); display.removeFilter(SWT.FocusIn, filter); Event e = new Event(); notifyListeners(SWT.FocusOut, e); break; } }}/*** Gets the index of an item.* <p>* The list is searched starting at 0 until an* item is found that is equal to the search item.* If no item is found, -1 is returned. Indexing* is zero based.** @param string the search item* @return the index of the item** @exception SWTError(ERROR_THREAD_INVALID_ACCESS)* when called from the wrong thread* @exception SWTError(ERROR_WIDGET_DISPOSED)* when the widget has been disposed* @exception SWTError(ERROR_NULL_ARGUMENT)* when string is null*/public int indexOf (String string) { checkWidget(); if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); return list.indexOf (string);}/*** Gets the index of an item.* <p>* The widget is searched starting at start including* the end position until an item is found that* is equal to the search itenm. If no item is* found, -1 is returned. Indexing is zero based.** @param string the search item* @param start the starting position* @return the index of the item** @exception SWTError(ERROR_THREAD_INVALID_ACCESS)* when called from the wrong thread* @exception SWTError(ERROR_WIDGET_DISPOSED)* when the widget has been disposed* @exception SWTError(ERROR_NULL_ARGUMENT)* when string is null*/public int indexOf (String string, int start) { checkWidget(); if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); return list.indexOf (string, start);}void initAccessible() { AccessibleAdapter accessibleAdapter = new AccessibleAdapter() { public void getName(AccessibleEvent e) { String name = null; Label label = getAssociatedLabel (); if (label != null) { name = stripMnemonic(label.getText()); } e.result = name; } public void getKeyboardShortcut(AccessibleEvent e) { String shortcut = null; Label label = getAssociatedLabel (); if (label != null) { String text = label.getText(); if (text != null) { char mnemonic = getMnemonic(text); if (mnemonic != '\0') { shortcut = "Alt+"+mnemonic; //$NON-NLS-1$ } } } e.result = shortcut; } public void getHelp(AccessibleEvent e) { e.result = getToolTipText(); } }; getAccessible().addAccessibleListener(accessibleAdapter); text.getAccessible().addAccessibleListener(accessibleAdapter); list.getAccessible().addAccessibleListener(accessibleAdapter); getAccessible().addAccessibleTextListener(new AccessibleTextAdapter() { public void getCaretOffset(AccessibleTextEvent e) { e.offset = text.getCaretPosition(); } }); getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() { public void getChildAtPoint(AccessibleControlEvent e) { Point testPoint = toControl(new Point(e.x, e.y)); if (getBounds().contains(testPoint)) { e.childID = ACC.CHILDID_SELF; } } public void getLocation(AccessibleControlEvent e) { Rectangle location = getBounds(); Point pt = toDisplay(new Point(location.x, location.y)); e.x = pt.x; e.y = pt.y; e.width = location.width; e.height = location.height; } public void getChildCount(AccessibleControlEvent e) { e.detail = 0; } public void getRole(AccessibleControlEvent e) { e.detail = ACC.ROLE_COMBOBOX; } public void getState(AccessibleControlEvent e) { e.detail = ACC.STATE_NORMAL; } public void getValue(AccessibleControlEvent e) { e.result = getText(); } });}boolean isDropped () { return popup.getVisible ();}public boolean isFocusControl () { checkWidget(); if (text.isFocusControl() || arrow.isFocusControl() || list.isFocusControl() || popup.isFocusControl()) { return true; } return super.isFocusControl();}void internalLayout () { if (isDropped ()) dropDown (false); Rectangle rect = getClientArea(); int width = rect.width; int height = rect.height; Point arrowSize = arrow.computeSize(SWT.DEFAULT, height); text.setBounds (0, 0, width - arrowSize.x, height); arrow.setBounds (width - arrowSize.x, 0, arrowSize.x, arrowSize.y);}void listEvent (Event event) { switch (event.type) { case SWT.Dispose: if (getShell() != popup.getParent()) { String[] items = list.getItems(); int selectionIndex = list.getSelectionIndex(); popup = null; list = null; createPopup(items, selectionIndex); } break; case SWT.FocusIn: { handleFocus (SWT.FocusIn); break; } case SWT.MouseUp: { if (event.button != 1) return; dropDown (false); break; } case SWT.Selection: { int index = list.getSelectionIndex (); if (index == -1) return; text.setText (list.getItem (index)); text.selectAll (); list.setSelection(index); Event e = new Event(); e.time = event.time; e.stateMask = event.stateMask; e.doit = event.doit; notifyListeners(SWT.Selection, e); event.doit = e.doit; break; } case SWT.Traverse: { switch (event.detail) { case SWT.TRAVERSE_RETURN: case SWT.TRAVERSE_ESCAPE: case SWT.TRAVERSE_ARROW_PREVIOUS: case SWT.TRAVERSE_ARROW_NEXT: event.doit = false; break; } Event e = new Event(); e.time = event.time; e.detail = event.detail; e.doit = event.doit; e.character = event.character; e.keyCode = event.keyCode; notifyListeners(SWT.Traverse, e); event.doit = e.doit; event.detail = e.detail; break; } case SWT.KeyUp: { Event e = new Event(); e.time = event.time; e.character = event.character; e.keyCode = event.keyCode; e.stateMask = event.stateMask; notifyListeners(SWT.KeyUp, e); break; } case SWT.KeyDown: { if (event.character == SWT.ESC) { // Escape key cancels popup list dropDown (false); } if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN)) { dropDown (false); } if (event.character == SWT.CR) { // Enter causes default selection dropDown (false); Event e = new Event(); e.time = event.time; e.stateMask = event.stateMask; notifyListeners(SWT.DefaultSelection, e); } // At this point the widget may have been disposed. // If so, do not continue. if (isDisposed()) break; Event e = new Event(); e.time = event.time; e.character = event.character; e.keyCode = event.keyCode; e.stateMask = event.stateMask; notifyListeners(SWT.KeyDown, e); break; } }}void popupEvent(Event event) { switch (event.type) { case SWT.Paint: // draw black rectangle around list Rectangle listRect = list.getBounds(); Color black = getDisplay().getSystemColor(SWT.COLOR_BLACK); event.gc.setForeground(black); event.gc.drawRectangle(0, 0, listRect.width + 1, listRect.height + 1); break; case SWT.Close: event.doit = false; dropDown (false); break; case SWT.Deactivate: dropDown (false); break; }}public void redraw () { super.redraw(); text.redraw(); arrow.redraw(); if (popup.isVisible()) list.redraw();}public void redraw (int x, int y, int width, int height, boolean all) { super.redraw(x, y, width, height, true);}/*** Removes an item at an index.* <p>* Indexing is zero based.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -