menu: skin dialog code clean up 41/12241/1
authorGiWoong Kim <giwoong.kim@samsung.com>
Tue, 12 Nov 2013 10:43:04 +0000 (19:43 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Wed, 13 Nov 2013 02:35:13 +0000 (11:35 +0900)
1. allow to create a button composite optionally in SkinDialog
2. added boilerplate title (SkinDialog, LicenceDialog,
RamdumpDialog)
3. define static string
4. modified indenting & etc

Change-Id: I040276e597a8cebfc61e1a15aa0cec13af7cb95d
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/AboutDialog.java
tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/DetailInfoDialog.java
tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/LicenseDialog.java
tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/RamdumpDialog.java
tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/SkinDialog.java

index a65f79d920a0069c74a284d6f1389e00632709f9..674b2212a996fcc5bea008df1af4c742c6d53f8b 100644 (file)
@@ -59,6 +59,7 @@ import org.tizen.emulator.skin.util.StringUtil;
 import org.tizen.emulator.skin.util.SwtUtil;
 
 public class AboutDialog extends SkinDialog {
+       public static final String ABOUT_DIALOG_TITLE = "About Tizen Emulator";
        public static final String ABOUT_PROP_FILENAME = "about.properties";
 
        public static final String PROP_KEY_VERSION = "version";
@@ -79,14 +80,14 @@ public class AboutDialog extends SkinDialog {
         */
        public AboutDialog(Shell parent,
                        EmulatorConfig config, ImageRegistry imageRegistry) {
-               super(parent, "About Tizen Emulator",
-                               SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+               super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL, ABOUT_DIALOG_TITLE);
 
                this.config = config;
                this.imageRegistry = imageRegistry;
        }
 
-       private GridLayout getNopaddedGridLayout(int numColumns, boolean makeColumnEqualWidth) {
+       private GridLayout getNopaddedGridLayout(
+                       int numColumns, boolean makeColumnEqualWidth) {
                GridLayout layout = new GridLayout(numColumns, makeColumnEqualWidth);
                layout.marginLeft = layout.marginRight = 0;
                layout.marginTop = layout.marginBottom = 0;
@@ -224,7 +225,6 @@ public class AboutDialog extends SkinDialog {
                        String property = properties.getProperty(key);
 
                        if (!StringUtil.isEmpty(property)) {
-
                                if (!property.contains(key)) {
                                        return property;
                                } else {
index f57d39d78e3f76050baba865562651199fd0f83e..e7ffc1ffbf5f37ca463d90151191531e40509b53 100644 (file)
@@ -30,6 +30,7 @@
 package org.tizen.emulator.skin.dialog;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -64,6 +65,8 @@ import org.tizen.emulator.skin.util.SwtUtil;
  *
  */
 public class DetailInfoDialog extends SkinDialog {
+       public final static String DETAIL_INFO_DIALOG_TITLE = "Detail Info";
+
        public final static String TABLE_COLUMN_NAME_0 = "Feature";
        public final static String TABLE_COLUMN_NAME_1 = "Value";
 
@@ -107,8 +110,8 @@ public class DetailInfoDialog extends SkinDialog {
         */
        public DetailInfoDialog(Shell parent, SocketCommunicator communicator,
                        EmulatorConfig config, SkinInformation skinInfo) {
-               super(parent, "Detail Info" + " - " + SkinUtil.makeEmulatorName(config),
-                               SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE | SWT.MAX);
+               super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE | SWT.MAX,
+                               DETAIL_INFO_DIALOG_TITLE + " - " + SkinUtil.makeEmulatorName(config));
 
                this.communicator = communicator;
                this.config = config;
@@ -237,7 +240,12 @@ public class DetailInfoDialog extends SkinDialog {
                byte[] receivedData = communicator.getReceivedData(dataTranfer);
 
                if (null != receivedData) {
-                       infoData = new String(receivedData);
+                       try {
+                               infoData = new String(receivedData, "UTF-8");
+                       } catch (UnsupportedEncodingException e) {
+                               logger.warning("unsupported encoding exception");
+                               infoData = new String(receivedData);
+                       }
                } else {
                        logger.severe("Fail to get detail info");
                        SkinUtil.openMessage(shell, null,
index f6a6b2c5799cf7c6e7d5d80d2ff70af31e1ce0b0..9baa0511cec8fee139d03e173ac08c7eeeda720d 100644 (file)
@@ -1,7 +1,7 @@
 /**
- * 
+ * License Dialog
  *
- * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact:
  * GiWoong Kim <giwoong.kim@samsung.com>
@@ -53,88 +53,86 @@ import org.tizen.emulator.skin.util.StringUtil;
  *
  */
 public class LicenseDialog extends SkinDialog {
-
        public static final String LICENSE_FILE_PATH = "../license/Open_Source_Announcement.txt";
 
-       private Logger logger = SkinLogger.getSkinLogger( LicenseDialog.class ).getLogger();
+       private Logger logger =
+                       SkinLogger.getSkinLogger(LicenseDialog.class).getLogger();
 
-       public LicenseDialog( Shell parent, String title ) {
-               super( parent, title, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE | SWT.MAX );
+       /**
+        *  Constructor
+        */
+       public LicenseDialog(Shell parent, String title) {
+               super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE | SWT.MAX, title);
        }
 
        @Override
-       protected Composite createArea( Composite parent ) {
-
-               Composite composite = new Composite( parent, SWT.NONE );
-               composite.setLayout( new GridLayout() );
+       protected Composite createArea(Composite parent) {
+               Composite composite = new Composite(parent, SWT.NONE);
+               composite.setLayout(new GridLayout());
 
-               final Text text = new Text( composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI );
-               GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true );
-               text.setLayoutData( gridData );
+               final Text text = new Text(composite,
+                               SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
+               GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+               text.setLayoutData(gridData);
 
-               text.setEditable( false );
-               text.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_WHITE ) );
-               String license = StringUtil.nvl( getLicense() );
-               text.setText( license );
+               text.setEditable(false);
+               text.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
+               String license = StringUtil.nvl(getLicense());
+               text.setText(license);
 
                return composite;
-
        }
 
        @Override
        protected void setShellSize() {
-               shell.setSize( (int) ( 400 * 1.618 ), 400 );
+               shell.setSize((int) (400 * 1.618/* golden ratio */), 400);
        }
 
        @Override
-       protected void createButtons( Composite parent ) {
-               super.createButtons( parent );
+       protected void createButtons(Composite parent) {
+               super.createButtons(parent);
 
-               Button okButton = createButton( parent, OK );
+               Button okButton = createButton(parent, OK);
 
                GridData gd = new GridData();
                gd.grabExcessHorizontalSpace = true;
                gd.horizontalAlignment = SWT.RIGHT;
-               okButton.setLayoutData( gd );
+               okButton.setLayoutData(gd);
 
                okButton.setFocus();
 
-               okButton.addSelectionListener( new SelectionAdapter() {
+               okButton.addSelectionListener(new SelectionAdapter() {
                        @Override
-                       public void widgetSelected( SelectionEvent e ) {
-                               LicenseDialog.this.shell.close();
+                       public void widgetSelected(SelectionEvent e) {
+                               shell.close();
                        }
-               } );
-
+               });
        }
 
        private String getLicense() {
-
                FileInputStream fis = null;
                String string = "";
 
                try {
-
-                       fis = new FileInputStream( LICENSE_FILE_PATH );
+                       fis = new FileInputStream(LICENSE_FILE_PATH);
 
                        try {
-                               byte[] bytes = IOUtil.getBytes( fis );
-                               string = new String( bytes, "UTF-8" );
-                       } catch ( IOException e ) {
-                               logger.log( Level.SEVERE, e.getMessage(), e );
+                               byte[] bytes = IOUtil.getBytes(fis);
+                               string = new String(bytes, "UTF-8");
+                       } catch (IOException e) {
+                               logger.log(Level.SEVERE, e.getMessage(), e);
                                string = "File control error.";
                        }
-
-               } catch ( FileNotFoundException e ) {
+               } catch (FileNotFoundException e) {
                        string = "There is no license info.";
                } finally {
-                       IOUtil.close( fis );
+                       IOUtil.close(fis);
                }
 
                return string;
-
        }
 
+       @Override
        protected void close() {
                logger.info("close the license dialog");
        }
index f8acd4b5f59fa08b235edfb7f0c565c1e708fd74..35271423733ceaf4398e3acb86d782547e39dfab 100644 (file)
@@ -1,5 +1,5 @@
 /**
- *
+ * Ramdump Dialog
  *
  * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
@@ -51,17 +51,24 @@ import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.util.SkinUtil;
 
 public class RamdumpDialog extends SkinDialog {
-       private SocketCommunicator communicator;
-       private Composite compositeBase;
-       private ImageData[] frames;
+       public static final String RAMDUMP_DIALOG_TITLE = "Ram Dump";
+       public static final String INDICATOR_IMAGE_PATH = "images/process.gif";
 
        private Logger logger =
                        SkinLogger.getSkinLogger(RamdumpDialog.class).getLogger();
 
+       private SocketCommunicator communicator;
+       private Composite compositeBase;
+       private ImageData[] frames;
+
+       /**
+        *  Constructor
+        */
        public RamdumpDialog(Shell parent,
                        SocketCommunicator communicator, EmulatorConfig config) throws IOException {
-               super(parent, SkinUtil.makeEmulatorName(config),
-                               SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+               super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL,
+                               RAMDUMP_DIALOG_TITLE + " - " + SkinUtil.makeEmulatorName(config), false);
+
                this.communicator = communicator;
        }
 
@@ -76,7 +83,7 @@ public class RamdumpDialog extends SkinDialog {
                        return null;
                }
 
-               RamdumpDialog.this.shell.addListener(SWT.Close, new Listener() {
+               shell.addListener(SWT.Close, new Listener() {
                        @Override
                        public void handleEvent(Event event) {
                                if (communicator.getRamdumpFlag() == true) {
@@ -86,7 +93,7 @@ public class RamdumpDialog extends SkinDialog {
                                        event.doit = false;
                                }
                        }
-               } );
+               });
 
                return composite;
        }
@@ -102,9 +109,8 @@ public class RamdumpDialog extends SkinDialog {
 
                try {
                        frames = loader.load(
-                                       classLoader.getResourceAsStream("images/process.gif"));
+                                       classLoader.getResourceAsStream(INDICATOR_IMAGE_PATH));
                } catch (Exception e) {
-                       // TODO: register a indicator file
                        frames = null;
                }
 
@@ -164,13 +170,13 @@ public class RamdumpDialog extends SkinDialog {
                                display.syncExec(new Runnable() {
                                        @Override
                                        public void run() {
-                                               logger.info("close the Ramdump dialog");
+                                               logger.info("ramdump complete");
 
                                                if (labelImage.getImage() != null) {
                                                        labelImage.getImage().dispose();
                                                }
                                                shell.setCursor(null);
-                                               RamdumpDialog.this.shell.close();
+                                               shell.close();
                                        }
                                });
                        }
@@ -184,7 +190,7 @@ public class RamdumpDialog extends SkinDialog {
 
        @Override
        protected void setShellSize() {
-               shell.setSize(280, 150);
+               shell.setSize(280, 140);
 
                /* align */
                Rectangle boundsClient = shell.getClientArea();
index a74b47d00ea4382e1191f484aee84c03ba928e69..9d5ab417ff793158c553852c018381e85f2b42d0 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * 
+ * Skin Dialog
  *
  * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
@@ -60,14 +60,29 @@ public abstract class SkinDialog extends Dialog {
        protected Shell shell;
        protected Composite buttonComposite;
        private Shell parent;
-       private String title;
        private int style;
-       
-       public SkinDialog(Shell parent, String title, int style) {
+       private String title;
+       private boolean hasButton;
+
+       /**
+        *  Constructor
+        */
+       public SkinDialog(Shell parent, int style, String title) {
                super(parent, style);
+
                this.parent = parent;
+               this.style = style;
                this.title = title;
+               this.hasButton = true;
+       }
+
+       public SkinDialog(Shell parent, int style, String title, boolean hasButton) {
+               super(parent, style);
+
+               this.parent = parent;
                this.style = style;
+               this.title = title;
+               this.hasButton = hasButton;
        }
 
        protected void createComposite() {
@@ -86,12 +101,14 @@ public abstract class SkinDialog extends Dialog {
                        return;
                }
 
+               if (hasButton == true) {
                /* bottom side */
-               buttonComposite = new Composite(parent, SWT.NONE);
-               buttonComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, true));
-               buttonComposite.setLayout(new GridLayout(1, false));
+                       buttonComposite = new Composite(parent, SWT.NONE);
+                       buttonComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, true));
+                       buttonComposite.setLayout(new GridLayout(1, false));
 
-               createButtons(buttonComposite);
+                       createButtons(buttonComposite);
+               }
        }
 
        public void open() {
@@ -146,6 +163,8 @@ public abstract class SkinDialog extends Dialog {
        }
 
        protected void close() {
+               logger.info("closed");
+
                /* do nothing */
        }
 
@@ -157,14 +176,13 @@ public abstract class SkinDialog extends Dialog {
 
        protected void createButtons(Composite parent) {
                if (null == parent) {
-                       throw new IllegalArgumentException("Buttons parent is null");
+                       throw new IllegalArgumentException("button composite is null");
                }
        }
 
        protected Button createButton(Composite parent, String text) {
-
                if (null == parent) {
-                       throw new IllegalArgumentException("Button parent is null");
+                       throw new IllegalArgumentException("button composite is null");
                }
 
                Composite composite = new Composite(parent, SWT.NONE);
@@ -198,7 +216,5 @@ public abstract class SkinDialog extends Dialog {
                }
 
                return okButton;
-
        }
-
 }