📄 tab.java
字号:
Item [] getExampleWidgetItems () { return new Item [0]; } /** * Gets the short text for the tab folder item. * * @return the short text for the tab item */ String getShortTabText() { return getTabText(); } /** * Gets the text for the tab folder item. * * @return the text for the tab item */ String getTabText () { return ""; } /** * Hooks all listeners to all example controls * and example control items. */ void hookExampleWidgetListeners () { if (logging) { Widget[] widgets = getExampleWidgets (); for (int i = 0; i < widgets.length; i++) { hookListeners (widgets [i]); } Item[] exampleItems = getExampleWidgetItems (); for (int i = 0; i < exampleItems.length; i++) { hookListeners (exampleItems [i]); } String [] customNames = getCustomEventNames (); for (int i = 0; i < customNames.length; i++) { if (eventsFilter [EVENT_NAMES.length + i]) hookCustomListener (customNames[i]); } } } /** * Hooks the custom listener specified by eventName. */ void hookCustomListener (String eventName) { } /** * Hooks all listeners to the specified widget. */ void hookListeners (Widget widget) { if (logging) { Listener listener = new Listener() { public void handleEvent (Event event) { log (event); } }; for (int i = 0; i < EVENT_NAMES.length; i++) { if (eventsFilter [i]) widget.addListener (((Integer)EVENT_NAMES[i][1]).intValue(), listener); } } } /** * Logs an untyped event to the event console. */ void log(Event event) { int i = 0; while (i < EVENT_NAMES.length) { if (((Integer)EVENT_NAMES[i][1]).intValue() == event.type) break; i++; } String toString = (String)EVENT_NAMES[i][0] + " ["+event.type+"]: "; switch (event.type) { case SWT.KeyDown: case SWT.KeyUp: toString += new KeyEvent (event).toString (); break; case SWT.MouseDown: case SWT.MouseUp: case SWT.MouseMove: case SWT.MouseEnter: case SWT.MouseExit: case SWT.MouseDoubleClick: case SWT.MouseWheel: case SWT.MouseHover: toString += new MouseEvent (event).toString (); break; case SWT.Paint: toString += new PaintEvent (event).toString (); break; case SWT.Move: case SWT.Resize: toString += new ControlEvent (event).toString (); break; case SWT.Dispose: toString += new DisposeEvent (event).toString (); break; case SWT.Selection: case SWT.DefaultSelection: toString += new SelectionEvent (event).toString (); break; case SWT.FocusIn: case SWT.FocusOut: toString += new FocusEvent (event).toString (); break; case SWT.Expand: case SWT.Collapse: toString += new TreeEvent (event).toString (); break; case SWT.Iconify: case SWT.Deiconify: case SWT.Close: case SWT.Activate: case SWT.Deactivate: toString += new ShellEvent (event).toString (); break; case SWT.Show: case SWT.Hide: toString += (event.widget instanceof Menu) ? new MenuEvent (event).toString () : event.toString(); break; case SWT.Modify: toString += new ModifyEvent (event).toString (); break; case SWT.Verify: toString += new VerifyEvent (event).toString (); break; case SWT.Help: toString += new HelpEvent (event).toString (); break; case SWT.Arm: toString += new ArmEvent (event).toString (); break; case SWT.Traverse: toString += new TraverseEvent (event).toString (); break; case SWT.HardKeyDown: case SWT.HardKeyUp: case SWT.DragDetect: case SWT.MenuDetect: case SWT.SetData: default: toString += event.toString (); } eventConsole.append (toString); eventConsole.append ("\n"); } /** * Logs a string to the event console. */ void log (String string) { eventConsole.append (string); eventConsole.append ("\n"); } /** * Logs a typed event to the event console. */ void log (String eventName, TypedEvent event) { eventConsole.append (eventName + ": "); eventConsole.append (event.toString ()); eventConsole.append ("\n"); } /** * Recreates the "Example" widgets. */ void recreateExampleWidgets () { disposeExampleWidgets (); createExampleWidgets (); hookExampleWidgetListeners (); setExampleWidgetState (); } /** * Sets the foreground color, background color, and font * of the "Example" widgets to their default settings. * Subclasses may extend in order to reset other colors * and fonts to default settings as well. */ void resetColorsAndFonts () { Color oldColor = foregroundColor; foregroundColor = null; setExampleWidgetForeground (); if (oldColor != null) oldColor.dispose(); oldColor = backgroundColor; backgroundColor = null; setExampleWidgetBackground (); if (oldColor != null) oldColor.dispose(); Font oldFont = font; font = null; setExampleWidgetFont (); setExampleWidgetSize (); if (oldFont != null) oldFont.dispose(); } /** * Sets the background color of the "Example" widgets' parent. */ void setExampleGroupBackgroundColor () { if (backgroundModeGroup == null) return; exampleGroup.setBackground (backgroundModeColorButton.getSelection () ? display.getSystemColor(SWT.COLOR_BLUE) : null); } /** * Sets the background image of the "Example" widgets' parent. */ void setExampleGroupBackgroundImage () { if (backgroundModeGroup == null) return; exampleGroup.setBackgroundImage (backgroundModeImageButton.getSelection () ? instance.images[ControlExample.ciParentBackground] : null); } /** * Sets the background mode of the "Example" widgets' parent. */ void setExampleGroupBackgroundMode () { if (backgroundModeGroup == null) return; String modeString = backgroundModeCombo.getText (); int mode = SWT.INHERIT_NONE; if (modeString.equals("SWT.INHERIT_DEFAULT")) mode = SWT.INHERIT_DEFAULT; if (modeString.equals("SWT.INHERIT_FORCE")) mode = SWT.INHERIT_FORCE; exampleGroup.setBackgroundMode (mode); } /** * Sets the background color of the "Example" widgets. */ void setExampleWidgetBackground () { if (colorAndFontTable == null) return; // user cannot change color/font on this tab Control [] controls = getExampleControls (); if (!instance.startup) { for (int i = 0; i < controls.length; i++) { controls[i].setBackground (backgroundColor); } } // Set the background color item's image to match the background color of the example widget(s). Color color = backgroundColor; if (controls.length == 0) return; if (color == null) color = controls [0].getBackground (); TableItem item = colorAndFontTable.getItem(BACKGROUND_COLOR); Image oldImage = item.getImage(); if (oldImage != null) oldImage.dispose(); item.setImage (colorImage (color)); } /** * Sets the enabled state of the "Example" widgets. */ void setExampleWidgetEnabled () { Control [] controls = getExampleControls (); for (int i=0; i<controls.length; i++) { controls [i].setEnabled (enabledButton.getSelection ()); } } /** * Sets the font of the "Example" widgets. */ void setExampleWidgetFont () { if (colorAndFontTable == null) return; // user cannot change color/font on this tab Control [] controls = getExampleControls (); if (!instance.startup) { for (int i = 0; i < controls.length; i++) { controls[i].setFont(font); } } /* Set the font item's image and font to match the font of the example widget(s). */ Font ft = font; if (controls.length == 0) return; if (ft == null) ft = controls [0].getFont (); TableItem item = colorAndFontTable.getItem(FONT); Image oldImage = item.getImage(); if (oldImage != null) oldImage.dispose(); item.setImage (fontImage (ft)); item.setFont(ft); colorAndFontTable.layout (); } /** * Sets the foreground color of the "Example" widgets. */ void setExampleWidgetForeground () { if (colorAndFontTable == null) return; // user cannot change color/font on this tab Control [] controls = getExampleControls (); if (!instance.startup) { for (int i = 0; i < controls.length; i++) { controls[i].setForeground (foregroundColor); } } /* Set the foreground color item's image to match the foreground color of the example widget(s). */ Color color = foregroundColor; if (controls.length == 0) return; if (color == null) color = controls [0].getForeground (); TableItem item = colorAndFontTable.getItem(FOREGROUND_COLOR); Image oldImage = item.getImage(); if (oldImage != null) oldImage.dispose(); item.setImage (colorImage(color)); } /** * Sets the size of the "Example" widgets. */ void setExampleWidgetSize () { int size = SWT.DEFAULT; if (preferredButton == null) return; if (preferredButton.getSelection()) size = SWT.DEFAULT; if (tooSmallButton.getSelection()) size = TOO_SMALL_SIZE; if (smallButton.getSelection()) size = SMALL_SIZE; if (largeButton.getSelection()) size = LARGE_SIZE; Control [] controls = getExampleControls (); for (int i=0; i<controls.length; i++) { GridData gridData = new GridData(size, size); gridData.grabExcessHorizontalSpace = fillHButton.getSelection(); gridData.grabExcessVerticalSpace = fillVButton.getSelection(); gridData.horizontalAlignment = fillHButton.getSelection() ? SWT.FILL : SWT.LEFT; gridData.verticalAlignment = fillVButton.getSelection() ? SWT.FILL : SWT.TOP; controls [i].setLayoutData (gridData); } tabFolderPage.layout (controls); } /** * Sets the state of the "Example" widgets. Subclasses * reimplement this method to set "Example" widget state * that is specific to the widget. */ void setExampleWidgetState () { setExampleWidgetBackground (); setExampleWidgetForeground (); setExampleWidgetFont (); if (!instance.startup) { setExampleWidgetEnabled (); setExampleWidgetVisibility (); setExampleGroupBackgroundMode (); setExampleGroupBackgroundColor (); setExampleGroupBackgroundImage (); setExampleWidgetBackgroundImage (); setExampleWidgetPopupMenu (); setExampleWidgetSize (); } //TEMPORARY CODE// Control [] controls = getExampleControls ();// for (int i=0; i<controls.length; i++) {// log ("Control=" + controls [i] + ", border width=" + controls [i].getBorderWidth ());// } } /** * Sets the visibility of the "Example" widgets. */ void setExampleWidgetVisibility () { Control [] controls = getExampleControls (); for (int i=0; i<controls.length; i++) { controls [i].setVisible (visibleButton.getSelection ()); } } /** * Sets the background image of the "Example" widgets. */ void setExampleWidgetBackgroundImage () { Control [] controls = getExampleControls (); for (int i=0; i<controls.length; i++) { controls [i].setBackgroundImage (backgroundImageButton.getSelection () ? instance.images[ControlExample.ciBackground] : null); } } /** * Splits the given string around matches of the given character. * * This subset of java.lang.String.split(String regex) * uses only code that can be run on CLDC platforms. */ String [] split (String string, char ch) { String [] result = new String[0]; int start = 0; int length = string.length(); while (start < length) { int end = string.indexOf(ch, start); if (end == -1) end = length; String substr = string.substring(start, end); String [] newResult = new String[result.length + 1]; System.arraycopy(result, 0, newResult, 0, result.length); newResult [result.length] = substr; result = newResult; start = end + 1; } return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -