use of org.eclipse.swt.widgets.Dialog in project eclipse.platform.swt by eclipse.
the class FormLayoutTab method createChildWidgets.
/**
* Creates the widgets in the "child" group.
*/
@Override
void createChildWidgets() {
/* Add common controls */
super.createChildWidgets();
/* Resize the columns */
table.getColumn(LEFT_COL).setWidth(90);
table.getColumn(RIGHT_COL).setWidth(90);
table.getColumn(TOP_COL).setWidth(90);
table.getColumn(BOTTOM_COL).setWidth(90);
/* Add TableEditors */
nameEditor = new TableEditor(table);
comboEditor = new TableEditor(table);
widthEditor = new TableEditor(table);
heightEditor = new TableEditor(table);
leftEditor = new TableEditor(table);
rightEditor = new TableEditor(table);
topEditor = new TableEditor(table);
bottomEditor = new TableEditor(table);
table.addMouseListener(MouseListener.mouseDownAdapter(e -> {
resetEditors();
index = table.getSelectionIndex();
Point pt = new Point(e.x, e.y);
newItem = table.getItem(pt);
if (newItem == null)
return;
TableItem oldItem = comboEditor.getItem();
if (newItem == oldItem || newItem != lastSelected) {
lastSelected = newItem;
return;
}
table.showSelection();
combo = new CCombo(table, SWT.READ_ONLY);
createComboEditor(combo, comboEditor);
nameText = new Text(table, SWT.SINGLE);
nameText.setText(data.get(index)[NAME_COL]);
createTextEditor(nameText, nameEditor, NAME_COL);
widthText = new Text(table, SWT.SINGLE);
widthText.setText(data.get(index)[WIDTH_COL]);
createTextEditor(widthText, widthEditor, WIDTH_COL);
heightText = new Text(table, SWT.SINGLE);
heightText.setText(data.get(index)[HEIGHT_COL]);
createTextEditor(heightText, heightEditor, HEIGHT_COL);
leftAttach = new Button(table, SWT.PUSH);
leftAttach.setText(LayoutExample.getResourceString("Attach_Edit"));
leftEditor.horizontalAlignment = SWT.LEFT;
leftEditor.grabHorizontal = true;
leftEditor.minimumWidth = leftAttach.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
leftEditor.setEditor(leftAttach, newItem, LEFT_COL);
leftAttach.addSelectionListener(SelectionListener.widgetSelectedAdapter(e1 -> {
Shell shell = tabFolderPage.getShell();
AttachDialog dialog = new AttachDialog(shell);
dialog.setText(LayoutExample.getResourceString("Left_Attachment"));
dialog.setColumn(LEFT_COL);
String attach = dialog.open();
newItem.setText(LEFT_COL, attach);
resetEditors();
}));
rightAttach = new Button(table, SWT.PUSH);
rightAttach.setText(LayoutExample.getResourceString("Attach_Edit"));
rightEditor.horizontalAlignment = SWT.LEFT;
rightEditor.grabHorizontal = true;
rightEditor.minimumWidth = rightAttach.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
rightEditor.setEditor(rightAttach, newItem, RIGHT_COL);
rightAttach.addSelectionListener(SelectionListener.widgetSelectedAdapter(e1 -> {
Shell shell = tabFolderPage.getShell();
AttachDialog dialog = new AttachDialog(shell);
dialog.setText(LayoutExample.getResourceString("Right_Attachment"));
dialog.setColumn(RIGHT_COL);
String attach = dialog.open();
newItem.setText(RIGHT_COL, attach);
if (newItem.getText(LEFT_COL).endsWith(")"))
newItem.setText(LEFT_COL, "");
resetEditors();
}));
topAttach = new Button(table, SWT.PUSH);
topAttach.setText(LayoutExample.getResourceString("Attach_Edit"));
topEditor.horizontalAlignment = SWT.LEFT;
topEditor.grabHorizontal = true;
topEditor.minimumWidth = topAttach.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
topEditor.setEditor(topAttach, newItem, TOP_COL);
topAttach.addSelectionListener(SelectionListener.widgetSelectedAdapter(e1 -> {
Shell shell = tabFolderPage.getShell();
AttachDialog dialog = new AttachDialog(shell);
dialog.setText(LayoutExample.getResourceString("Top_Attachment"));
dialog.setColumn(TOP_COL);
String attach = dialog.open();
newItem.setText(TOP_COL, attach);
resetEditors();
}));
bottomAttach = new Button(table, SWT.PUSH);
bottomAttach.setText(LayoutExample.getResourceString("Attach_Edit"));
bottomEditor.horizontalAlignment = SWT.LEFT;
bottomEditor.grabHorizontal = true;
bottomEditor.minimumWidth = bottomAttach.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
bottomEditor.setEditor(bottomAttach, newItem, BOTTOM_COL);
bottomAttach.addSelectionListener(SelectionListener.widgetSelectedAdapter(e1 -> {
Shell shell = tabFolderPage.getShell();
AttachDialog dialog = new AttachDialog(shell);
dialog.setText(LayoutExample.getResourceString("Bottom_Attachment"));
dialog.setColumn(BOTTOM_COL);
String attach = dialog.open();
newItem.setText(BOTTOM_COL, attach);
if (newItem.getText(TOP_COL).endsWith(")"))
newItem.setText(TOP_COL, "");
resetEditors();
}));
for (int i = 0; i < table.getColumnCount(); i++) {
Rectangle rect = newItem.getBounds(i);
if (rect.contains(pt)) {
switch(i) {
case 0:
resetEditors();
break;
case COMBO_COL:
combo.setFocus();
break;
case WIDTH_COL:
widthText.setFocus();
break;
case HEIGHT_COL:
heightText.setFocus();
break;
default:
break;
}
}
}
}));
}
use of org.eclipse.swt.widgets.Dialog in project eclipse.platform.swt by eclipse.
the class GradientDialog method createDialogControls.
/**
* Creates the controls of the dialog.
*/
public void createDialogControls(final Shell parent) {
final Display display = parent.getDisplay();
// message
Label message = new Label(parent, SWT.NONE);
message.setText(GraphicsExample.getResourceString("GradientDlgMsg"));
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gridData.horizontalSpan = 2;
message.setLayoutData(gridData);
// default colors are white and black
if (rgb1 == null || rgb2 == null) {
rgb1 = display.getSystemColor(SWT.COLOR_WHITE).getRGB();
rgb2 = display.getSystemColor(SWT.COLOR_BLACK).getRGB();
}
// canvas
canvas = new Canvas(parent, SWT.NONE);
gridData = new GridData(GridData.FILL_BOTH);
gridData.widthHint = 200;
gridData.heightHint = 100;
canvas.setLayoutData(gridData);
canvas.addListener(SWT.Paint, e -> {
Image preview = null;
Point size = canvas.getSize();
Color color1 = new Color(display, rgb1);
Color color2 = new Color(display, rgb2);
preview = GraphicsExample.createImage(display, color1, color2, size.x, size.y);
if (preview != null) {
e.gc.drawImage(preview, 0, 0);
}
preview.dispose();
color1.dispose();
color2.dispose();
});
// composite used for both color buttons
Composite colorButtonComp = new Composite(parent, SWT.NONE);
// layout buttons
RowLayout layout = new RowLayout();
layout.type = SWT.VERTICAL;
layout.pack = false;
colorButtonComp.setLayout(layout);
// position composite
gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
colorButtonComp.setLayoutData(gridData);
ColorMenu colorMenu = new ColorMenu();
// color controls: first color
colorButton1 = new Button(colorButtonComp, SWT.PUSH);
colorButton1.setText(GraphicsExample.getResourceString("GradientDlgButton1"));
Color color1 = new Color(display, rgb1);
Image img1 = GraphicsExample.createImage(display, color1);
color1.dispose();
colorButton1.setImage(img1);
resources.add(img1);
menu1 = colorMenu.createMenu(parent.getParent(), gb -> {
rgb1 = gb.getBgColor1().getRGB();
colorButton1.setImage(gb.getThumbNail());
if (canvas != null)
canvas.redraw();
});
colorButton1.addListener(SWT.Selection, event -> {
final Button button = (Button) event.widget;
final Composite parent1 = button.getParent();
Rectangle bounds = button.getBounds();
Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
menu1.setLocation(point.x, point.y + bounds.height);
menu1.setVisible(true);
});
// color controls: second color
colorButton2 = new Button(colorButtonComp, SWT.PUSH);
colorButton2.setText(GraphicsExample.getResourceString("GradientDlgButton2"));
Color color2 = new Color(display, rgb2);
Image img2 = GraphicsExample.createImage(display, color2);
color2.dispose();
colorButton2.setImage(img2);
resources.add(img2);
menu2 = colorMenu.createMenu(parent.getParent(), gb -> {
rgb2 = gb.getBgColor1().getRGB();
colorButton2.setImage(gb.getThumbNail());
if (canvas != null)
canvas.redraw();
});
colorButton2.addListener(SWT.Selection, event -> {
final Button button = (Button) event.widget;
final Composite parent1 = button.getParent();
Rectangle bounds = button.getBounds();
Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
menu2.setLocation(point.x, point.y + bounds.height);
menu2.setVisible(true);
});
// composite used for ok and cancel buttons
Composite okCancelComp = new Composite(parent, SWT.NONE);
// layout buttons
RowLayout rowLayout = new RowLayout();
rowLayout.pack = false;
rowLayout.marginTop = 5;
okCancelComp.setLayout(rowLayout);
// position composite
gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
gridData.horizontalSpan = 2;
okCancelComp.setLayoutData(gridData);
// OK button
okButton = new Button(okCancelComp, SWT.PUSH);
okButton.setText("&OK");
okButton.addListener(SWT.Selection, event -> {
returnVal = SWT.OK;
parent.close();
});
// cancel button
cancelButton = new Button(okCancelComp, SWT.PUSH);
cancelButton.setText("&Cancel");
cancelButton.addListener(SWT.Selection, event -> parent.close());
}
use of org.eclipse.swt.widgets.Dialog in project eclipse.platform.swt by eclipse.
the class ImageAnalyzer method showBMPDialog.
/*
* Open a dialog asking the user for more information on the type of BMP file to save.
*/
int showBMPDialog() {
final int[] bmpType = new int[1];
bmpType[0] = SWT.IMAGE_BMP;
SelectionListener radioSelected = widgetSelectedAdapter(event -> {
Button radio = (Button) event.widget;
if (radio.getSelection())
bmpType[0] = ((Integer) radio.getData()).intValue();
});
// need to externalize strings
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
dialog.setText(bundle.getString("Save_as_type"));
dialog.setLayout(new GridLayout());
Label label = new Label(dialog, SWT.NONE);
label.setText(bundle.getString("Save_as_type_label"));
Button radio = new Button(dialog, SWT.RADIO);
radio.setText(bundle.getString("Save_as_type_no_compress"));
radio.setSelection(true);
radio.setData(Integer.valueOf(SWT.IMAGE_BMP));
radio.addSelectionListener(radioSelected);
radio = new Button(dialog, SWT.RADIO);
radio.setText(bundle.getString("Save_as_type_rle_compress"));
radio.setData(Integer.valueOf(SWT.IMAGE_BMP_RLE));
radio.addSelectionListener(radioSelected);
radio = new Button(dialog, SWT.RADIO);
radio.setText(bundle.getString("Save_as_type_os2"));
radio.setData(Integer.valueOf(SWT.IMAGE_OS2_BMP));
radio.addSelectionListener(radioSelected);
label = new Label(dialog, SWT.SEPARATOR | SWT.HORIZONTAL);
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button ok = new Button(dialog, SWT.PUSH);
ok.setText(bundle.getString("OK"));
GridData data = new GridData();
data.horizontalAlignment = SWT.CENTER;
data.widthHint = 75;
ok.setLayoutData(data);
ok.addSelectionListener(widgetSelectedAdapter(e -> dialog.close()));
dialog.pack();
dialog.open();
while (!dialog.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
return bmpType[0];
}
Aggregations