package org.safehaus.penrose.studio.partition.dialog; import org.eclipse.swt.widgets.*; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.graphics.Point; import org.safehaus.penrose.studio.PenroseImage; import org.safehaus.penrose.studio.PenroseStudio; /** * @author Endi S. Dewata */ public class PartitionDialog extends Dialog { public final static int CANCEL = 0; public final static int OK = 1; Shell shell; Text nameText; String name; int action = CANCEL; public PartitionDialog(Shell parent, int style) { super(parent, style); shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE); createControl(shell); } public void open () { Point size = new Point(400, 200); shell.setSize(size); Point l = getParent().getLocation(); Point s = getParent().getSize(); shell.setLocation(l.x + (s.x - size.x)/2, l.y + (s.y - size.y)/2); shell.setText(getText()); shell.setImage(PenroseStudio.getImage(PenroseImage.LOGO)); reset(); shell.open(); Display display = getParent().getDisplay(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } public void createControl(final Shell parent) { parent.setLayout(new GridLayout()); Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new GridLayout(2, false)); Label nameLabel = new Label(composite, SWT.NONE); nameLabel.setText("Name:"); GridData gd = new GridData(GridData.FILL); gd.widthHint = 100; nameLabel.setLayoutData(gd); nameText = new Text(composite, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); nameText.setLayoutData(gd); Composite buttons = new Composite(parent, SWT.NONE); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.END; buttons.setLayoutData(gd); buttons.setLayout(new RowLayout()); Button saveButton = new Button(buttons, SWT.PUSH); saveButton.setText("Save"); saveButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { name = "".equals(nameText.getText()) ? null : nameText.getText(); action = OK; shell.close(); } }); Button cancelButton = new Button(buttons, SWT.PUSH); cancelButton.setText("Cancel"); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.close(); } }); } public void reset() { nameText.setText(name == null ? "" : name); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAction() { return action; } public void setAction(int action) { this.action = action; } }