📄 tab.java
字号:
preferredButton.addSelectionListener(selectionListener); tooSmallButton.addSelectionListener(selectionListener); smallButton.addSelectionListener(selectionListener); largeButton.addSelectionListener(selectionListener); fillButton.addSelectionListener(selectionListener); /* Set the default state */ preferredButton.setSelection (true); } /** * Creates the "Style" group. The "Style" group contains * controls that allow the user to change the style of * the example widgets. Changing a widget "Style" causes * the widget to be destroyed and recreated. */ void createStyleGroup () { styleGroup = new Group (controlGroup, SWT.NONE); styleGroup.setLayout (new GridLayout ()); styleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); styleGroup.setText (ControlExample.getResourceString("Styles")); } /** * Creates the tab folder page. * * @param tabFolder org.eclipse.swt.widgets.TabFolder * @return the new page for the tab folder */ Composite createTabFolderPage (TabFolder tabFolder) { /* * Create a two column page. */ tabFolderPage = new Composite (tabFolder, SWT.NONE); tabFolderPage.setLayout (new GridLayout (2, false)); /* Create the "Example" and "Control" groups. */ createExampleGroup (); createControlGroup (); /* Create the "Listeners" group under the "Control" group. */ createListenersGroup (); /* Create and initialize the example and control widgets. */ createExampleWidgets (); hookExampleWidgetListeners (); createControlWidgets (); setExampleWidgetState (); return tabFolderPage; } /** * Disposes the "Example" widgets. */ void disposeExampleWidgets () { Control [] controls = getExampleWidgets (); for (int i=0; i<controls.length; i++) { controls [i].dispose (); } } void drawImage (Image image, Color color) { GC gc = new GC(image); gc.setBackground(color); Rectangle bounds = image.getBounds(); gc.fillRectangle(0, 0, bounds.width, bounds.height); gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1); gc.dispose(); } /** * Gets the list of custom event names. * * @return an array containing custom event names */ String [] getCustomEventNames () { return new String [0]; } /** * Gets the default style for a widget * * @return the default style bit */ int getDefaultStyle () { if (ltrButton != null && ltrButton.getSelection()) { return SWT.LEFT_TO_RIGHT; } if (rtlButton != null && rtlButton.getSelection()) { return SWT.RIGHT_TO_LEFT; } return SWT.NONE; } /** * Gets the "Example" widget children. * * @return an array containing the example widget children */ Control [] getExampleWidgets () { return new Control [0]; } /** * Gets the "Example" widget children's items, if any. * * @return an array containing the example widget children's items */ Item [] getExampleWidgetItems () { return new Item [0]; } /** * 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) { Control[] exampleControls = getExampleWidgets (); for (int i = 0; i < exampleControls.length; i++) { hookListeners (exampleControls [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 (i, listener); } } } /** * Logs an untyped event to the event console. */ void log(Event event) { String toString = EVENT_NAMES[event.type] + " ["+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: 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. */ void setExampleWidgetBackground () { if (backgroundButton == null) return; // no background button on this tab Control [] controls = getExampleWidgets (); for (int i = 0; i < controls.length; i++) { controls[i].setBackground (backgroundColor); } // Set the background button's color to match the color just set. Color color = backgroundColor; if (controls.length == 0) return; if (color == null) color = controls [0].getBackground (); drawImage (backgroundImage, color); backgroundButton.setImage (backgroundImage); } /** * Sets the enabled state of the "Example" widgets. */ void setExampleWidgetEnabled () { Control [] controls = getExampleWidgets (); for (int i=0; i<controls.length; i++) { controls [i].setEnabled (enabledButton.getSelection ()); } } /** * Sets the font of the "Example" widgets. */ void setExampleWidgetFont () { if (instance.startup) return; if (fontButton == null) return; // no font button on this tab Control [] controls = getExampleWidgets (); for (int i = 0; i < controls.length; i++) { Control control = controls[i]; control.setFont(font); } } /** * Sets the foreground color of the "Example" widgets. */ void setExampleWidgetForeground () { if (foregroundButton == null) return; // no foreground button on this tab Control [] controls = getExampleWidgets (); for (int i = 0; i < controls.length; i++) { controls[i].setForeground (foregroundColor); } // Set the foreground button's color to match the color just set. Color color = foregroundColor; if (controls.length == 0) return; if (color == null) color = controls [0].getForeground (); drawImage (foregroundImage, color); foregroundButton.setImage (foregroundImage); } /** * 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 = getExampleWidgets (); for (int i=0; i<controls.length; i++) { GridData gridData; if (fillButton.getSelection()) { gridData = new GridData (GridData.FILL_BOTH); } else { gridData = new GridData (); gridData.widthHint = size; gridData.heightHint = size; } 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 () { setExampleWidgetEnabled (); setExampleWidgetVisibility (); setExampleWidgetBackground (); setExampleWidgetForeground (); setExampleWidgetFont (); setExampleWidgetSize (); //TEMPORARY CODE// Control [] controls = getExampleWidgets ();// 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 = getExampleWidgets (); for (int i=0; i<controls.length; i++) { controls [i].setVisible (visibleButton.getSelection ()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -