use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class ShellTab method createControlWidgets.
/**
* Creates the "Control" widget children.
*/
@Override
void createControlWidgets() {
/* Create the parent style buttons */
noParentButton = new Button(parentStyleGroup, SWT.RADIO);
noParentButton.setText(ControlExample.getResourceString("No_Parent"));
parentButton = new Button(parentStyleGroup, SWT.RADIO);
parentButton.setText(ControlExample.getResourceString("Parent"));
/* Create the decoration style buttons */
noTrimButton = new Button(styleGroup, SWT.CHECK);
noTrimButton.setText("SWT.NO_TRIM");
noMoveButton = new Button(styleGroup, SWT.CHECK);
noMoveButton.setText("SWT.NO_MOVE");
closeButton = new Button(styleGroup, SWT.CHECK);
closeButton.setText("SWT.CLOSE");
titleButton = new Button(styleGroup, SWT.CHECK);
titleButton.setText("SWT.TITLE");
minButton = new Button(styleGroup, SWT.CHECK);
minButton.setText("SWT.MIN");
maxButton = new Button(styleGroup, SWT.CHECK);
maxButton.setText("SWT.MAX");
borderButton = new Button(styleGroup, SWT.CHECK);
borderButton.setText("SWT.BORDER");
resizeButton = new Button(styleGroup, SWT.CHECK);
resizeButton.setText("SWT.RESIZE");
onTopButton = new Button(styleGroup, SWT.CHECK);
onTopButton.setText("SWT.ON_TOP");
toolButton = new Button(styleGroup, SWT.CHECK);
toolButton.setText("SWT.TOOL");
sheetButton = new Button(styleGroup, SWT.CHECK);
sheetButton.setText("SWT.SHEET");
Label separator = new Label(styleGroup, SWT.SEPARATOR | SWT.HORIZONTAL);
separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
shellTrimButton = new Button(styleGroup, SWT.CHECK);
shellTrimButton.setText("SWT.SHELL_TRIM");
dialogTrimButton = new Button(styleGroup, SWT.CHECK);
dialogTrimButton.setText("SWT.DIALOG_TRIM");
/* Create the modal style buttons */
modelessButton = new Button(modalStyleGroup, SWT.RADIO);
modelessButton.setText("SWT.MODELESS");
primaryModalButton = new Button(modalStyleGroup, SWT.RADIO);
primaryModalButton.setText("SWT.PRIMARY_MODAL");
applicationModalButton = new Button(modalStyleGroup, SWT.RADIO);
applicationModalButton.setText("SWT.APPLICATION_MODAL");
systemModalButton = new Button(modalStyleGroup, SWT.RADIO);
systemModalButton.setText("SWT.SYSTEM_MODAL");
/* Create the 'other' buttons */
imageButton = new Button(otherGroup, SWT.CHECK);
imageButton.setText(ControlExample.getResourceString("Image"));
backgroundImageButton = new Button(otherGroup, SWT.CHECK);
backgroundImageButton.setText(ControlExample.getResourceString("BackgroundImage"));
createSetGetGroup();
/* Create the "create" and "closeAll" buttons */
createButton = new Button(controlGroup, SWT.NONE);
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
createButton.setLayoutData(gridData);
createButton.setText(ControlExample.getResourceString("Create_Shell"));
closeAllButton = new Button(controlGroup, SWT.NONE);
gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
closeAllButton.setText(ControlExample.getResourceString("Close_All_Shells"));
closeAllButton.setLayoutData(gridData);
/* Add the listeners */
createButton.addSelectionListener(widgetSelectedAdapter(e -> createButtonSelected(e)));
closeAllButton.addSelectionListener(widgetSelectedAdapter(e -> closeAllShells()));
SelectionListener decorationButtonListener = widgetSelectedAdapter(event -> decorationButtonSelected(event));
noTrimButton.addSelectionListener(decorationButtonListener);
noMoveButton.addSelectionListener(decorationButtonListener);
closeButton.addSelectionListener(decorationButtonListener);
titleButton.addSelectionListener(decorationButtonListener);
minButton.addSelectionListener(decorationButtonListener);
maxButton.addSelectionListener(decorationButtonListener);
borderButton.addSelectionListener(decorationButtonListener);
resizeButton.addSelectionListener(decorationButtonListener);
dialogTrimButton.addSelectionListener(decorationButtonListener);
shellTrimButton.addSelectionListener(decorationButtonListener);
applicationModalButton.addSelectionListener(decorationButtonListener);
systemModalButton.addSelectionListener(decorationButtonListener);
/* Set the default state */
noParentButton.setSelection(true);
modelessButton.setSelection(true);
}
use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class Tab method createControlGroup.
/**
* Creates the "Control" group. The "Control" group
* is typically the right hand column in the tab.
*/
void createControlGroup() {
/*
* Create the "Control" group. This is the group on the
* right half of each example tab. It consists of the
* "Style" group, the "Other" group and the "Size" group.
*/
controlGroup = new Group(tabFolderPage, SWT.NONE);
controlGroup.setLayout(new GridLayout(2, true));
controlGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
controlGroup.setText(ControlExample.getResourceString("Parameters"));
/* Create individual groups inside the "Control" group */
createStyleGroup();
createOtherGroup();
createSetGetGroup();
createSizeGroup();
createColorAndFontGroup();
if (rtlSupport()) {
createOrientationGroup();
createDirectionGroup();
}
createBackgroundModeGroup();
/*
* For each Button child in the style group, add a selection
* listener that will recreate the example controls. If the
* style group button is a RADIO button, ensure that the radio
* button is selected before recreating the example controls.
* When the user selects a RADIO button, the current RADIO
* button in the group is deselected and the new RADIO button
* is selected automatically. The listeners are notified for
* both these operations but typically only do work when a RADIO
* button is selected.
*/
SelectionListener selectionListener = widgetSelectedAdapter(event -> {
if ((event.widget.getStyle() & SWT.RADIO) != 0) {
if (!((Button) event.widget).getSelection())
return;
}
if (!handleTextDirection(event.widget)) {
recreateExampleWidgets();
if (rtlSupport()) {
/* Reflect the base direction falls back to the default (i.e. orientation). */
ltrDirectionButton.setSelection(false);
rtlDirectionButton.setSelection(false);
autoDirectionButton.setSelection(false);
defaultDirectionButton.setSelection(true);
}
}
});
Control[] children = styleGroup.getChildren();
for (Control child : children) {
if (child instanceof Button) {
Button button = (Button) child;
button.addSelectionListener(selectionListener);
} else {
if (child instanceof Composite) {
/* Look down one more level of children in the style group. */
Composite composite = (Composite) child;
Control[] grandchildren = composite.getChildren();
for (Control grandchild : grandchildren) {
if (grandchild instanceof Button) {
Button button = (Button) grandchild;
button.addSelectionListener(selectionListener);
}
}
}
}
}
if (rtlSupport()) {
rtlButton.addSelectionListener(selectionListener);
ltrButton.addSelectionListener(selectionListener);
defaultOrietationButton.addSelectionListener(selectionListener);
rtlDirectionButton.addSelectionListener(selectionListener);
ltrDirectionButton.addSelectionListener(selectionListener);
autoDirectionButton.addSelectionListener(selectionListener);
defaultDirectionButton.addSelectionListener(selectionListener);
}
}
use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class Tab method createSizeGroup.
/**
* 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(SWT.FILL, SWT.FILL, false, false));
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);
rectangleButton = new Button(sizeGroup, SWT.RADIO);
rectangleButton.setText(RETANGLE_SIZE_WIDTH + " X " + RETANGLE_SIZE_HEIGHT);
fillHButton = new Button(sizeGroup, SWT.CHECK);
fillHButton.setText(ControlExample.getResourceString("Fill_X"));
fillVButton = new Button(sizeGroup, SWT.CHECK);
fillVButton.setText(ControlExample.getResourceString("Fill_Y"));
/* Add the listeners */
SelectionListener selectionListener = widgetSelectedAdapter(event -> setExampleWidgetSize());
preferredButton.addSelectionListener(selectionListener);
tooSmallButton.addSelectionListener(selectionListener);
smallButton.addSelectionListener(selectionListener);
largeButton.addSelectionListener(selectionListener);
rectangleButton.addSelectionListener(selectionListener);
fillHButton.addSelectionListener(selectionListener);
fillVButton.addSelectionListener(selectionListener);
/* Set the default state */
preferredButton.setSelection(true);
}
use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_TreeColumn method test_addSelectionListenerWidgetSelectedAdapterLorg_eclipse_swt_events_SelectionListener.
@Test
public void test_addSelectionListenerWidgetSelectedAdapterLorg_eclipse_swt_events_SelectionListener() {
listenerCalled = false;
SelectionListener listener = SelectionListener.widgetSelectedAdapter(e -> listenerCalled = true);
treeColumn.addSelectionListener(listener);
treeColumn.notifyListeners(SWT.Selection, new Event());
assertTrue(listenerCalled);
listenerCalled = false;
treeColumn.removeSelectionListener(listener);
treeColumn.notifyListeners(SWT.Selection, new Event());
assertFalse(listenerCalled);
}
use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_DateTime method test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener.
@Test
public void test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener() {
listenerCalled = false;
SelectionListener listener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
listenerCalled = true;
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
};
try {
datetime.addSelectionListener(null);
fail("No exception thrown for addSelectionListener with null argument");
} catch (IllegalArgumentException e) {
}
datetime.addSelectionListener(listener);
datetime.notifyListeners(SWT.Selection, new Event());
assertTrue(listenerCalled);
try {
datetime.removeSelectionListener(null);
fail("No exception thrown for removeSelectionListener with null argument");
} catch (IllegalArgumentException e) {
}
listenerCalled = false;
datetime.removeSelectionListener(listener);
datetime.notifyListeners(SWT.Selection, new Event());
assertFalse(listenerCalled);
}
Aggregations