/** * Creates an instance of a ControlExample embedded inside the supplied parent Composite. * * @param parent the container of the example */ public ControlExample(Composite parent) { initResources(); tabFolder = new TabFolder(parent, SWT.NONE); tabs = createTabs(); for (Tab tab : tabs) { TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText(tab.getTabText()); item.setControl(tab.createTabFolderPage(tabFolder)); item.setData(tab); } /* Workaround: if the tab folder is wider than the screen, * Mac platforms clip instead of somehow scrolling the tab items. * We try to recover some width by using shorter tab names. */ Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle monitorArea = parent.getMonitor().getClientArea(); boolean isMac = SWT.getPlatform().equals("cocoa"); if (size.x > monitorArea.width && isMac) { TabItem[] tabItems = tabFolder.getItems(); for (int i = 0; i < tabItems.length; i++) { tabItems[i].setText(tabs[i].getShortTabText()); } } startup = false; }
/** Creates the "Control" group. */ void createControlGroup() { super.createControlGroup(); /* Create the group */ alignmentGroup = new Group(controlGroup, SWT.NONE); alignmentGroup.setLayout(new GridLayout()); alignmentGroup.setLayoutData( new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); alignmentGroup.setText(ControlExample.getResourceString("Alignment")); /* Create the controls */ leftButton = new Button(alignmentGroup, SWT.RADIO); leftButton.setText(ControlExample.getResourceString("Left")); centerButton = new Button(alignmentGroup, SWT.RADIO); centerButton.setText(ControlExample.getResourceString("Center")); rightButton = new Button(alignmentGroup, SWT.RADIO); rightButton.setText(ControlExample.getResourceString("Right")); /* Add the listeners */ SelectionListener selectionListener = new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (!((Button) event.widget).getSelection()) return; setExampleWidgetAlignment(); } }; leftButton.addSelectionListener(selectionListener); centerButton.addSelectionListener(selectionListener); rightButton.addSelectionListener(selectionListener); }
/** Sets the state of the "Example" widgets. */ void setExampleWidgetState() { super.setExampleWidgetState(); Control[] controls = getExampleWidgets(); if (controls.length != 0) { leftButton.setSelection((controls[0].getStyle() & SWT.LEFT) != 0); centerButton.setSelection((controls[0].getStyle() & SWT.CENTER) != 0); rightButton.setSelection((controls[0].getStyle() & SWT.RIGHT) != 0); } }
/** Creates the "Example" group. */ void createExampleGroup() { super.createExampleGroup(); /* Create a group for the TabFolder */ tabFolderGroup = new Group(exampleGroup, SWT.NONE); tabFolderGroup.setLayout(new GridLayout()); tabFolderGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); tabFolderGroup.setText("TabFolder"); }
/** Sets the state of the "Example" widgets. */ void setExampleWidgetState() { super.setExampleWidgetState(); horizontalButton.setSelection((canvas.getStyle() & SWT.H_SCROLL) != 0); verticalButton.setSelection((canvas.getStyle() & SWT.V_SCROLL) != 0); borderButton.setSelection((canvas.getStyle() & SWT.BORDER) != 0); noBackgroundButton.setSelection((canvas.getStyle() & SWT.NO_BACKGROUND) != 0); noFocusButton.setSelection((canvas.getStyle() & SWT.NO_FOCUS) != 0); noMergePaintsButton.setSelection((canvas.getStyle() & SWT.NO_MERGE_PAINTS) != 0); noRedrawResizeButton.setSelection((canvas.getStyle() & SWT.NO_REDRAW_RESIZE) != 0); setCaret(); }
/** Creates the "Style" group. */ void createStyleGroup() { super.createStyleGroup(); /* Create the extra widgets */ topButton = new Button(styleGroup, SWT.RADIO); topButton.setText("SWT.TOP"); topButton.setSelection(true); bottomButton = new Button(styleGroup, SWT.RADIO); bottomButton.setText("SWT.BOTTOM"); borderButton = new Button(styleGroup, SWT.CHECK); borderButton.setText("SWT.BORDER"); }
/** Creates the "Example" group. */ void createExampleGroup() { super.createExampleGroup(); /* Create a group for the canvas widget */ canvasGroup = new Group(exampleGroup, SWT.NONE); canvasGroup.setLayout(new GridLayout()); canvasGroup.setLayoutData( new GridData( GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); canvasGroup.setText("Canvas"); }
/** Creates the "Example" group. */ void createExampleGroup() { super.createExampleGroup(); exampleGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); /* * Create a group for the text widget to display * the results returned by the example dialogs. */ resultGroup = new Group(exampleGroup, SWT.NONE); resultGroup.setLayout(new GridLayout()); resultGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); resultGroup.setText(ControlExample.getResourceString("Dialog_Result")); }
/** Creates the "Other" group. */ void createOtherGroup() { super.createOtherGroup(); /* Create display controls specific to this example */ caretButton = new Button(otherGroup, SWT.CHECK); caretButton.setText(ControlExample.getResourceString("Caret")); fillDamageButton = new Button(otherGroup, SWT.CHECK); fillDamageButton.setText(ControlExample.getResourceString("FillDamage")); /* Add the listeners */ caretButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { setCaret(); } }); }
/** * Creates the tab folder page. * * @param tabFolder org.eclipse.swt.widgets.TabFolder * @return the new page for the tab folder */ Composite createTabFolderPage(TabFolder tabFolder) { super.createTabFolderPage(tabFolder); /* * Add a resize listener to the tabFolderPage so that * if the user types into the example widget to change * its preferred size, and then resizes the shell, we * recalculate the preferred size correctly. */ tabFolderPage.addControlListener( new ControlAdapter() { public void controlResized(ControlEvent e) { setExampleWidgetSize(); } }); return tabFolderPage; }
/** Creates the "Style" group. */ void createStyleGroup() { super.createStyleGroup(); /* Create the extra widgets */ horizontalButton = new Button(styleGroup, SWT.CHECK); horizontalButton.setText("SWT.H_SCROLL"); horizontalButton.setSelection(true); verticalButton = new Button(styleGroup, SWT.CHECK); verticalButton.setText("SWT.V_SCROLL"); verticalButton.setSelection(true); borderButton = new Button(styleGroup, SWT.CHECK); borderButton.setText("SWT.BORDER"); noBackgroundButton = new Button(styleGroup, SWT.CHECK); noBackgroundButton.setText("SWT.NO_BACKGROUND"); noFocusButton = new Button(styleGroup, SWT.CHECK); noFocusButton.setText("SWT.NO_FOCUS"); noMergePaintsButton = new Button(styleGroup, SWT.CHECK); noMergePaintsButton.setText("SWT.NO_MERGE_PAINTS"); noRedrawResizeButton = new Button(styleGroup, SWT.CHECK); noRedrawResizeButton.setText("SWT.NO_REDRAW_RESIZE"); }
/** Recreates the "Example" widgets. */ void recreateExampleWidgets() { if (textWidget == null) { super.recreateExampleWidgets(); } }
/** Sets the state of the "Example" widgets. */ void setExampleWidgetState() { super.setExampleWidgetState(); topButton.setSelection((tabFolder1.getStyle() & SWT.TOP) != 0); bottomButton.setSelection((tabFolder1.getStyle() & SWT.BOTTOM) != 0); borderButton.setSelection((tabFolder1.getStyle() & SWT.BORDER) != 0); }