📄 tab.java
字号:
public void handleEvent (Event event) { eventConsole.copy (); } }); MenuItem paste = new MenuItem (popup, SWT.PUSH); paste.setText (ControlExample.getResourceString("MenuItem_Paste")); paste.addListener (SWT.Selection, new Listener () { public void handleEvent (Event event) { eventConsole.paste (); } }); new MenuItem (popup, SWT.SEPARATOR); MenuItem selectAll = new MenuItem (popup, SWT.PUSH); selectAll.setText(ControlExample.getResourceString("MenuItem_SelectAll")); selectAll.addListener (SWT.Selection, new Listener () { public void handleEvent (Event event) { eventConsole.selectAll (); } }); } /** * Creates the "Example" group. The "Example" group * is typically the left hand column in the tab. */ void createExampleGroup () { exampleGroup = new Group (tabFolderPage, SWT.NONE); GridLayout gridLayout = new GridLayout (); exampleGroup.setLayout (gridLayout); exampleGroup.setLayoutData (new GridData (GridData.FILL_BOTH)); } /** * Creates the "Example" widget children of the "Example" group. * Subclasses override this method to create the particular * example control. */ void createExampleWidgets () { /* Do nothing */ } /** * Creates and opens the "Listener selection" dialog. */ void createListenerSelectionDialog () { final Shell dialog = new Shell (tabFolderPage.getShell (), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setSize(400, 300); dialog.setText (ControlExample.getResourceString ("Select_Listeners")); dialog.setLayout (new GridLayout (2, false)); final Table table = new Table (dialog, SWT.BORDER | SWT.V_SCROLL | SWT.CHECK); GridData data = new GridData(GridData.FILL_BOTH); data.verticalSpan = 2; table.setLayoutData(data); for (int i = 0; i < EVENT_NAMES.length; i++) { TableItem item = new TableItem (table, SWT.NONE); item.setText (EVENT_NAMES[i]); item.setChecked (eventsFilter[i]); } final String [] customNames = getCustomEventNames (); for (int i = 0; i < customNames.length; i++) { TableItem item = new TableItem (table, SWT.NONE); item.setText (customNames[i]); item.setChecked (eventsFilter[EVENT_NAMES.length + i]); } Button selectAll = new Button (dialog, SWT.PUSH); selectAll.setText(ControlExample.getResourceString ("Select_All")); selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); selectAll.addSelectionListener (new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem [] items = table.getItems(); for (int i = 0; i < EVENT_NAMES.length; i++) { items[i].setChecked(true); } for (int i = 0; i < customNames.length; i++) { items[EVENT_NAMES.length + i].setChecked(true); } } }); Button deselectAll = new Button (dialog, SWT.PUSH); deselectAll.setText(ControlExample.getResourceString ("Deselect_All")); deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING)); deselectAll.addSelectionListener (new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem [] items = table.getItems(); for (int i = 0; i < EVENT_NAMES.length; i++) { items[i].setChecked(false); } for (int i = 0; i < customNames.length; i++) { items[EVENT_NAMES.length + i].setChecked(false); } } }); Label filler = new Label(dialog, SWT.NONE); Button ok = new Button (dialog, SWT.PUSH); ok.setText(ControlExample.getResourceString ("OK")); dialog.setDefaultButton(ok); ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); ok.addSelectionListener (new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem [] items = table.getItems(); for (int i = 0; i < EVENT_NAMES.length; i++) { eventsFilter[i] = items[i].getChecked(); } for (int i = 0; i < customNames.length; i++) { eventsFilter[EVENT_NAMES.length + i] = items[EVENT_NAMES.length + i].getChecked(); } dialog.dispose(); } }); dialog.pack (); dialog.open (); while (! dialog.isDisposed()) { if (! dialog.getDisplay().readAndDispatch()) dialog.getDisplay().sleep(); } } /** * Creates the "Listeners" group. The "Listeners" group * goes below the "Example" and "Control" groups. */ void createListenersGroup () { listenersGroup = new Group (tabFolderPage, SWT.NONE); listenersGroup.setLayout (new GridLayout (3, false)); GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); gridData.horizontalSpan = 2; listenersGroup.setLayoutData (gridData); listenersGroup.setText (ControlExample.getResourceString ("Listeners")); /* * Create the button to access the 'Listeners' dialog. */ Button listenersButton = new Button (listenersGroup, SWT.PUSH); listenersButton.setText (ControlExample.getResourceString ("Select_Listeners")); listenersButton.addSelectionListener (new SelectionAdapter() { public void widgetSelected (SelectionEvent e) { createListenerSelectionDialog (); recreateExampleWidgets (); } }); /* * Create the checkbox to add/remove listeners to/from the example widgets. */ final Button listenCheckbox = new Button (listenersGroup, SWT.CHECK); listenCheckbox.setText (ControlExample.getResourceString ("Listen")); listenCheckbox.addSelectionListener (new SelectionAdapter () { public void widgetSelected(SelectionEvent e) { logging = listenCheckbox.getSelection (); recreateExampleWidgets (); } }); /* * Create the button to clear the text. */ Button clearButton = new Button (listenersGroup, SWT.PUSH); clearButton.setText (ControlExample.getResourceString ("Clear")); clearButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); clearButton.addSelectionListener (new SelectionAdapter() { public void widgetSelected (SelectionEvent e) { eventConsole.setText (""); } }); /* Initialize the eventsFilter to log all events. */ int customEventCount = getCustomEventNames ().length; eventsFilter = new boolean [EVENT_NAMES.length + customEventCount]; for (int i = 0; i < EVENT_NAMES.length + customEventCount; i++) { eventsFilter [i] = true; } /* Create the event console Text. */ eventConsole = new Text (listenersGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); GridData data = new GridData (GridData.FILL_BOTH); data.horizontalSpan = 3; data.heightHint = 80; eventConsole.setLayoutData (data); createEventConsolePopup (); eventConsole.addKeyListener (new KeyAdapter () { public void keyPressed (KeyEvent e) { if ((e.keyCode == 'A' || e.keyCode == 'a') && (e.stateMask & SWT.MOD1) != 0) { eventConsole.selectAll (); e.doit = false; } } }); } void createOrientationGroup () { /* Create Orientation group*/ orientationGroup = new Group (controlGroup, SWT.NONE); orientationGroup.setLayout (new GridLayout()); orientationGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); orientationGroup.setText (ControlExample.getResourceString("Orientation")); defaultOrietationButton = new Button (orientationGroup, SWT.RADIO); defaultOrietationButton.setText (ControlExample.getResourceString("Default")); defaultOrietationButton.setSelection (true); ltrButton = new Button (orientationGroup, SWT.RADIO); ltrButton.setText ("SWT.LEFT_TO_RIGHT"); rtlButton = new Button (orientationGroup, SWT.RADIO); rtlButton.setText ("SWT.RIGHT_TO_LEFT"); } /** * Creates the "Size" group. The "Size" group contains * controls that allow the user to change the size of * the example widgets. */ void createSizeGroup () { /* Create the group */ sizeGroup = new Group (controlGroup, SWT.NONE); sizeGroup.setLayout (new GridLayout()); sizeGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); sizeGroup.setText (ControlExample.getResourceString("Size")); /* Create the controls */ /* * The preferred size of a widget is the size returned * by widget.computeSize (SWT.DEFAULT, SWT.DEFAULT). * This size is defined on a widget by widget basis. * Many widgets will attempt to display their contents. */ preferredButton = new Button (sizeGroup, SWT.RADIO); preferredButton.setText (ControlExample.getResourceString("Preferred")); tooSmallButton = new Button (sizeGroup, SWT.RADIO); tooSmallButton.setText (TOO_SMALL_SIZE + " X " + TOO_SMALL_SIZE); smallButton = new Button(sizeGroup, SWT.RADIO); smallButton.setText (SMALL_SIZE + " X " + SMALL_SIZE); largeButton = new Button (sizeGroup, SWT.RADIO); largeButton.setText (LARGE_SIZE + " X " + LARGE_SIZE); fillButton = new Button (sizeGroup, SWT.RADIO); fillButton.setText (ControlExample.getResourceString("Fill")); /* Add the listeners */ SelectionAdapter selectionListener = new SelectionAdapter () { public void widgetSelected (SelectionEvent event) { if (!((Button) event.widget).getSelection ()) return; setExampleWidgetSize (); }; }; 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -