Search in sources :

Example 1 with Dialog

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;
                }
            }
        }
    }));
}
Also used : TableEditor(org.eclipse.swt.custom.TableEditor) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Rectangle(org.eclipse.swt.graphics.Rectangle) Spinner(org.eclipse.swt.widgets.Spinner) FormAttachment(org.eclipse.swt.layout.FormAttachment) Point(org.eclipse.swt.graphics.Point) Dialog(org.eclipse.swt.widgets.Dialog) Group(org.eclipse.swt.widgets.Group) MouseListener(org.eclipse.swt.events.MouseListener) SWT(org.eclipse.swt.SWT) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) CCombo(org.eclipse.swt.custom.CCombo) Control(org.eclipse.swt.widgets.Control) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Shell(org.eclipse.swt.widgets.Shell) CCombo(org.eclipse.swt.custom.CCombo) Button(org.eclipse.swt.widgets.Button) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) TableEditor(org.eclipse.swt.custom.TableEditor)

Example 2 with Dialog

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());
}
Also used : Resource(org.eclipse.swt.graphics.Resource) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Display(org.eclipse.swt.widgets.Display) Point(org.eclipse.swt.graphics.Point) Dialog(org.eclipse.swt.widgets.Dialog) ArrayList(java.util.ArrayList) List(java.util.List) RowLayout(org.eclipse.swt.layout.RowLayout) Color(org.eclipse.swt.graphics.Color) Composite(org.eclipse.swt.widgets.Composite) SWT(org.eclipse.swt.SWT) RGB(org.eclipse.swt.graphics.RGB) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) Menu(org.eclipse.swt.widgets.Menu) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Canvas(org.eclipse.swt.widgets.Canvas) Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) Display(org.eclipse.swt.widgets.Display)

Example 3 with Dialog

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];
}
Also used : ImageLoader(org.eclipse.swt.graphics.ImageLoader) StyledText(org.eclipse.swt.custom.StyledText) URL(java.net.URL) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Dialog(org.eclipse.swt.widgets.Dialog) SWTError(org.eclipse.swt.SWTError) PaintEvent(org.eclipse.swt.events.PaintEvent) PrintDialog(org.eclipse.swt.printing.PrintDialog) Composite(org.eclipse.swt.widgets.Composite) KeyEvent(org.eclipse.swt.events.KeyEvent) SWTException(org.eclipse.swt.SWTException) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Cursor(org.eclipse.swt.graphics.Cursor) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) Sash(org.eclipse.swt.widgets.Sash) Display(org.eclipse.swt.widgets.Display) List(java.util.List) MouseListener(org.eclipse.swt.events.MouseListener) MenuItem(org.eclipse.swt.widgets.MenuItem) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) Printer(org.eclipse.swt.printing.Printer) PrinterData(org.eclipse.swt.printing.PrinterData) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) ControlListener(org.eclipse.swt.events.ControlListener) ImageData(org.eclipse.swt.graphics.ImageData) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) ResourceBundle(java.util.ResourceBundle) RGB(org.eclipse.swt.graphics.RGB) Canvas(org.eclipse.swt.widgets.Canvas) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) FileDialog(org.eclipse.swt.widgets.FileDialog) StyleRange(org.eclipse.swt.custom.StyleRange) ImageLoaderEvent(org.eclipse.swt.graphics.ImageLoaderEvent) Group(org.eclipse.swt.widgets.Group) RowLayout(org.eclipse.swt.layout.RowLayout) ShellListener(org.eclipse.swt.events.ShellListener) Color(org.eclipse.swt.graphics.Color) MessageBox(org.eclipse.swt.widgets.MessageBox) Menu(org.eclipse.swt.widgets.Menu) ScrollBar(org.eclipse.swt.widgets.ScrollBar) InputStream(java.io.InputStream) GridLayout(org.eclipse.swt.layout.GridLayout) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

SWT (org.eclipse.swt.SWT)3 Point (org.eclipse.swt.graphics.Point)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Button (org.eclipse.swt.widgets.Button)3 Dialog (org.eclipse.swt.widgets.Dialog)3 Label (org.eclipse.swt.widgets.Label)3 Shell (org.eclipse.swt.widgets.Shell)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MouseListener (org.eclipse.swt.events.MouseListener)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 Color (org.eclipse.swt.graphics.Color)2 Image (org.eclipse.swt.graphics.Image)2 RGB (org.eclipse.swt.graphics.RGB)2 RowLayout (org.eclipse.swt.layout.RowLayout)2 Canvas (org.eclipse.swt.widgets.Canvas)2 Composite (org.eclipse.swt.widgets.Composite)2 Display (org.eclipse.swt.widgets.Display)2