package org.tizen.emulator.manager.ui;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.tool.StringResource;
public class MessageDialog
{
}
}
- public int openInfoDialog(final String message) {
- return openInfoDialog("Info", message);
- }
-
- public int openInfoDialog(final String title, final String message) {
- return openMessageDialog(title, message, SWT.OK | SWT.MODELESS | SWT.ICON_INFORMATION);
- }
-
- public int openWarningDialog(final String message) {
- return openWarningDialog("Warning", message);
- }
-
- public int openWarningDialog(final String title, final String message) {
- return openMessageDialog(title, message, SWT.OK | SWT.MODELESS | SWT.ICON_WARNING);
- }
-
- public int openSelectionDialog(final String message) {
- return openSelectionDialog("Warning", message);
- }
-
- public int openSelectionDialog(final String title, final String message) {
- return openMessageDialog(title, message, SWT.OK | SWT.CANCEL | SWT.MODELESS | SWT.ICON_WARNING);
- }
-
- int msgResponse = 0;
- public int openMessageDialog(final String title, final String message, final int style) {
- MessageBox dialog = new MessageBox(shell, style);
- dialog.setText(title);
- dialog.setMessage(message);
- msgResponse = dialog.open();
- return msgResponse;
- }
-
- public void dispose() {
- shell.dispose();
- }
+ public int openInfoDialog(final String message) {
+ return openInfoDialog("Info", message);
+ }
+
+ public int openInfoDialog(final String title, final String message) {
+ return openMessageDialog(title, message, SWT.ICON_INFORMATION, SWT.OK );
+ }
+
+ public int openWarningDialog(final String message) {
+ return openWarningDialog("Warning", message);
+ }
+
+ public int openWarningDialog(final String title, final String message) {
+ return openMessageDialog(title, message, SWT.ICON_WARNING, SWT.OK);
+ }
+
+ public int openSelectionDialog(final String message) {
+ return openSelectionDialog("Warning", message);
+ }
+
+ public int openSelectionDialog(final String title, final String message) {
+ return openMessageDialog(title, message, SWT.ICON_WARNING, SWT.OK | SWT.CANCEL);
+ }
+
+ int msgResponse = 0;
+ private Shell dialog = null;
+ public int openMessageDialog(final String title, final String message, final int icon_style, final int style) {
+ dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+ dialog.setText(title);
+ dialog.setLayout(new GridLayout(2, false));
+ dialog.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+
+ Label icon = new Label(dialog, SWT.NONE);
+ icon.setImage(Display.getCurrent().getSystemImage(icon_style));
+ icon.pack();
+
+ Label text = new Label(dialog, SWT.NONE);
+ text.setText(message);
+ text.pack();
+
+ int x = icon.getSize().x + text.getSize().x;
+ int y = 0;
+ if (icon.getSize().y > text.getSize().y ) {
+ y = icon.getSize().y;
+ } else {
+ y = text.getSize().y;
+ }
+
+ dialog.setSize(x + 25, y + 100);
+
+ if (EmulatorManager.getInstance() != null
+ && EmulatorManager.getInstance().getMainDialog() != null) {
+ Point p = EmulatorManager.getInstance().getMainDialog().getShell().getLocation();
+ Point s = EmulatorManager.getInstance().getMainDialog().getShell().getSize();
+ dialog.setLocation(p.x + (s.x>>2), p.y + (s.y>>2));
+ }
+
+ //TODO : dummy label
+ new Label(dialog, SWT.NONE);
+ new Label(dialog, SWT.NONE);
+ new Label(dialog, SWT.NONE);
+
+ makeButtonComposite(style);
+
+ dialog.open();
+ while(!dialog.isDisposed()) {
+ if(!Display.getCurrent().readAndDispatch()) {
+ Display.getCurrent().sleep();
+ }
+ }
+
+ return msgResponse;
+ }
+
+ private void makeButtonComposite(int style) {
+ // button
+ Composite buttonComposite = new Composite(dialog, SWT.NONE);
+ GridLayout layout = new GridLayout(2, false);
+ layout.horizontalSpacing = 5;
+ layout.verticalSpacing = 0;
+ layout.marginBottom = 0;
+ layout.marginHeight = 0;
+ layout.marginLeft = 0;
+ layout.marginRight = 0;
+ layout.marginTop = 0;
+ layout.marginWidth = 0;
+ buttonComposite.setLayout(layout);
+ buttonComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));
+ //buttonComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+
+ if ((style & SWT.CANCEL) != 0 ) {
+ Button cancleButton = new Button(buttonComposite, SWT.PUSH);
+ cancleButton.setLayoutData(new GridData(90, SWT.DEFAULT));
+ cancleButton.setText(StringResource.CANCEL);
+ cancleButton.setFocus();
+ cancleButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ dialog.close();
+ msgResponse = SWT.CANCEL;
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ cancleButton.setFocus();
+ } else {
+ new Label(dialog, SWT.NONE);
+ }
+
+ Button okButton = new Button(buttonComposite, SWT.PUSH);
+ okButton.setLayoutData(new GridData(100, SWT.DEFAULT));
+ okButton.setText(StringResource.OK);
+ okButton.setFocus();
+ okButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ dialog.close();
+ msgResponse = SWT.OK;
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ if ((style & SWT.CANCEL) == 0 ) {
+ okButton.setFocus();
+ }
+ }
+
+ public void dispose() {
+ shell.dispose();
+ }
}