[Title] refactoring widget - splitButton
authorheeyoung <heeyoung1008.hwang@samsung.com>
Thu, 27 Mar 2014 08:18:17 +0000 (17:18 +0900)
committerheeyoung <heeyoung1008.hwang@samsung.com>
Thu, 27 Mar 2014 08:18:17 +0000 (17:18 +0900)
[Desc.] add comment and DACustomSplitButtonAttribute class
[Issue] -

Change-Id: I8b9893ea65261e0f967d20e3c0e892187f0f0b66
Signed-off-by: heeyoung <heeyoung1008.hwang@samsung.com>
org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/DACustomButtonAttribute.java
org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/splitButton/DACustomSplitButton.java
org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/splitButton/DACustomSplitButtonAttribute.java [new file with mode: 0644]
org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/splitButton/DACustomSplitButtonClickEventListener.java
org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/splitButton/DACustomSplitButtonRenderer.java

index 9ec99d5..e9fee67 100644 (file)
@@ -35,10 +35,9 @@ import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.Point;
-import org.tizen.dynamicanalyzer.widgets.button.splitButton.DACustomSplitButton;
 
 public class DACustomButtonAttribute {
-       private static final int MAX_SIZE = 12;
+       public static final int MAX_SIZE = 12;
        private String text;
        private Image buttonImage = null;
        private Font font;
@@ -54,21 +53,6 @@ public class DACustomButtonAttribute {
        private List<Color> outlineColors = new ArrayList<Color>();
        private List<Color> outlineInColors = new ArrayList<Color>();
 
-       // style : draw or position
-       private int splitButtonType = DACustomSplitButton.TYPE_POLYGON;
-       
-       // split line
-       private boolean isPolygonSeparator = false;
-       private List<Point> polygonSeparatorPoints = new ArrayList<Point>();
-       private List<Color> polygonSeparatorColors = new ArrayList<Color>();
-               
-       // polygon
-       private List<Point> polygonPoints = new ArrayList<Point>();
-       private List<Color> polygonColors = new ArrayList<Color>();
-
-       // split area
-       private List<Point> polygonAreaPoints = new ArrayList<Point>();
-
        public DACustomButtonAttribute() {
                for (int i = 0; i < MAX_SIZE; i++) {
                        images.add(null);
@@ -76,12 +60,7 @@ public class DACustomButtonAttribute {
                        fontColors.add(null);
                        outlineColors.add(null);
                        outlineInColors.add(null);
-                       polygonSeparatorPoints.add(null);
-                       polygonSeparatorColors.add(null);
-                       polygonColors.add(null);
-                       polygonAreaPoints.add(null);
                }
-               polygonPoints.clear();
        }
 
        public String getText() {
@@ -185,66 +164,5 @@ public class DACustomButtonAttribute {
        public int getAlign() {
                return this.align;
        }
-       
-       public boolean isPolygonSeparator() {
-               return isPolygonSeparator;
-       }
-
-       public void setPolygonSeparator(boolean isPolygonSeparator) {
-               this.isPolygonSeparator = isPolygonSeparator;
-       }
-
-       public Point getPolygonSeparatorPoint(int position) {
-               return polygonSeparatorPoints.get(position);
-       }
-
-       public void setPolygonSeparatorPoint(int position, Point polygonSeparatorPoint) {
-               polygonSeparatorPoints.set(position, polygonSeparatorPoint);
-       }       
-       
-       public Point getPolygonPoint(int index) {
-               return polygonPoints.get(index);
-       }
-
-       public List<Point> getPolygonPoints() {
-               return polygonPoints;
-       }
-
-       public void setPolygonPoint(Point polygonPoint) {
-               polygonPoints.add(polygonPoint);
-       }
-
-       public Color getPolygonSeparatorColor(int state) {
-               return polygonSeparatorColors.get(state);
-       }
-
-       public void setPolygonSeparatorColor(int state, Color color) {
-               polygonSeparatorColors.set(state, color);
-       }
-
-       public Color getPolygonColor(int state) {
-               return polygonColors.get(state);
-       }
-
-       public void setPolygonColor(int state, Color color) {
-               polygonColors.set(state, color);
-       }
-       
-       public Point getPolygonAreaPoint(int position) {
-               return polygonAreaPoints.get(position);
-       }
-
-       public void setPolygonAreaPoint(int position, Point polygonAreaPoint) {
-               polygonAreaPoints.set(position, polygonAreaPoint);
-       }
-
-       public int getSplitButtonType() {
-               return splitButtonType;
-       }
-
-       public void setSplitButtonType(int splitButtonType) {
-               this.splitButtonType = splitButtonType;
-       }       
-       
-       
+               
 }
index dc676e2..481b034 100644 (file)
  */
 package org.tizen.dynamicanalyzer.widgets.button.splitButton;
 
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.widgets.Composite;
 import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
 import org.tizen.dynamicanalyzer.widgets.popupMenu.DAPopupMenu;
 
+/**
+ * This class represents the context button.
+ * if you click the arrow of the button, context menu is display.
+ */
 public class DACustomSplitButton extends DACustomButton {
        
        // style
@@ -42,6 +46,7 @@ public class DACustomSplitButton extends DACustomButton {
        public static final int AREA_START = 0;
        public static final int AREA_END = 1;
        
+       // context menu
        private DAPopupMenu popupMenu = null; 
        
        public DACustomSplitButton(Composite parent, int style) {
@@ -50,21 +55,32 @@ public class DACustomSplitButton extends DACustomButton {
        }
                        
        public DACustomSplitButton(Composite parent, Image normal, Image mouseDown,
-                       Image hover, Image disable) {
-               super(parent, normal, mouseDown, hover, disable);
+                       Image hover, Image disable) {           
+               super(parent, SWT.TRANSPARENT);
                initSplitButton();
+               setImages(normal, mouseDown, hover, disable);
+               attr.setDrawType(TYPE_IMAGE);
        }
 
        public DACustomSplitButton(Composite parent, Color normalStart, Color normalEnd,
                        Color pushStart, Color pushEnd, Color hoverStart, Color hoverEnd,
                        Color disableStart, Color disableEnd) {
-               super(parent, normalStart, normalEnd, pushStart, pushEnd,
-                               hoverStart, hoverEnd, disableStart, disableEnd);
+               super(parent, SWT.NONE);
                initSplitButton();
+               attr.setColor(0, normalStart);
+               attr.setColor(1, normalEnd);
+               attr.setColor(2, pushStart);
+               attr.setColor(3, pushEnd);
+               attr.setColor(4, hoverStart);
+               attr.setColor(5, hoverEnd);
+               attr.setColor(6, disableStart);
+               attr.setColor(7, disableEnd);
+               attr.setDrawType(TYPE_GRADATION);
        }
        
        public void initSplitButton() {
                buttonRenderer = new DACustomSplitButtonRenderer();
+               attr = new DACustomSplitButtonAttribute();
 //             addListeners();
        }
        
@@ -76,55 +92,11 @@ public class DACustomSplitButton extends DACustomButton {
                this.popupMenu = popupMenu;
        }
 
-       public void setPolygonSeparatorColors(Color normal, Color push, Color hover,
-                       Color disable) {                
-               attr.setPolygonSeparatorColor(STATE_NORMAL, normal);
-               attr.setPolygonSeparatorColor(STATE_PUSH, push);
-               attr.setPolygonSeparatorColor(STATE_HOVER, hover);
-               attr.setPolygonSeparatorColor(STATE_DISABLE, disable);                  
-       }
-
-       public void setPolygonSeparatorColor(int state, Color color) {
-               attr.setPolygonSeparatorColor(state, color);
-       }
-       
-       public void setPolygonColors(Color normal, Color push, Color hover,
-                       Color disable) {                
-               attr.setPolygonColor(STATE_NORMAL, normal);
-               attr.setPolygonColor(STATE_PUSH, push);
-               attr.setPolygonColor(STATE_HOVER, hover);
-               attr.setPolygonColor(STATE_DISABLE, disable);                   
-       }
-
-       public void setPolygonColor(int state, Color color) {
-               attr.setPolygonColor(state, color);
+       public DACustomSplitButtonAttribute getAttr() {
+               return (DACustomSplitButtonAttribute)attr;
        }
        
-       public void setPolygonSeparatorPoint(int position, Point point) {
-               attr.setPolygonSeparatorPoint(position, point);
-       }
-       
-       public void setPolygonAreaPoint(int position, Point point) {
-               attr.setPolygonAreaPoint(position, point);
-       }
-       
-       public Point getPolygonAreaPoint(int position) {
-               return attr.getPolygonAreaPoint(position);
-       }
-       
-       public void setPolygonPoint(Point point) {
-               attr.setPolygonPoint(point);
-       }
-       
-       public void setPolygonSeparator(boolean isPolygonSeparator) {
-               attr.setPolygonSeparator(isPolygonSeparator);
-       }
-       
-       public void setSplitButtonType(int splitButtonType) {
-               attr.setSplitButtonType(splitButtonType);
-       }       
-       
-       
+// TODO : change depending on the image transfer of the design team.   
 //             protected Listener splitButtonMouseListener = new Listener() {
 //
 //                     @Override
diff --git a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/splitButton/DACustomSplitButtonAttribute.java b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/splitButton/DACustomSplitButtonAttribute.java
new file mode 100644 (file)
index 0000000..b83a68f
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ *  Dynamic Analyzer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * Heeyoung Hwang <heeyoung1008.hwang@samsung.com>
+ * Juyoung Kim <j0.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ * 
+ */
+package org.tizen.dynamicanalyzer.widgets.button.splitButton;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonAttribute;
+
+/**
+ * This class represents a property that is used to draw the split button.
+ */
+public class DACustomSplitButtonAttribute extends DACustomButtonAttribute {
+       
+       // style : draw or position
+       private int splitButtonType = DACustomSplitButton.TYPE_POLYGON;
+       
+       // split line
+       private boolean isPolygonSeparator = false;
+       private List<Point> polygonSeparatorPoints = new ArrayList<Point>();
+       private List<Color> polygonSeparatorColors = new ArrayList<Color>();
+               
+       // polygon
+       private List<Point> polygonPoints = new ArrayList<Point>();
+       private List<Color> polygonColors = new ArrayList<Color>();
+
+       // split area
+       private List<Point> polygonAreaPoints = new ArrayList<Point>();
+       
+       public DACustomSplitButtonAttribute() {
+               super();
+               for (int i = 0; i < MAX_SIZE; i++) {
+                       polygonSeparatorPoints.add(null);
+                       polygonSeparatorColors.add(null);
+                       polygonColors.add(null);
+                       polygonAreaPoints.add(null);
+               }
+               polygonPoints.clear();
+       }
+       
+       public boolean isPolygonSeparator() {
+               return isPolygonSeparator;
+       }
+
+       public void setPolygonSeparator(boolean isPolygonSeparator) {
+               this.isPolygonSeparator = isPolygonSeparator;
+       }
+
+       public Point getPolygonSeparatorPoint(int position) {
+               return polygonSeparatorPoints.get(position);
+       }
+
+       public void setPolygonSeparatorPoint(int position, Point polygonSeparatorPoint) {
+               polygonSeparatorPoints.set(position, polygonSeparatorPoint);
+       }       
+       
+       public Point getPolygonPoint(int index) {
+               return polygonPoints.get(index);
+       }
+
+       public List<Point> getPolygonPoints() {
+               return polygonPoints;
+       }
+
+       public void setPolygonPoint(Point polygonPoint) {
+               polygonPoints.add(polygonPoint);
+       }
+
+       public Color getPolygonSeparatorColor(int state) {
+               return polygonSeparatorColors.get(state);
+       }
+
+       public void setPolygonSeparatorColor(int state, Color color) {
+               polygonSeparatorColors.set(state, color);
+       }
+
+       public Color getPolygonColor(int state) {
+               return polygonColors.get(state);
+       }
+
+       public void setPolygonColor(int state, Color color) {
+               polygonColors.set(state, color);
+       }
+       
+       public Point getPolygonAreaPoint(int position) {
+               return polygonAreaPoints.get(position);
+       }
+
+       public void setPolygonAreaPoint(int position, Point polygonAreaPoint) {
+               polygonAreaPoints.set(position, polygonAreaPoint);
+       }
+
+       public int getSplitButtonType() {
+               return splitButtonType;
+       }
+
+       public void setSplitButtonType(int splitButtonType) {
+               this.splitButtonType = splitButtonType;
+       }       
+       
+       public void setPolygonSeparatorColors(Color normal, Color push, Color hover,
+                       Color disable) {                
+               polygonSeparatorColors.set(DACustomButton.STATE_NORMAL, normal);
+               polygonSeparatorColors.set(DACustomButton.STATE_PUSH, push);
+               polygonSeparatorColors.set(DACustomButton.STATE_HOVER, hover);
+               polygonSeparatorColors.set(DACustomButton.STATE_DISABLE, disable);      
+       }
+       
+       public void setPolygonColors(Color normal, Color push, Color hover,
+                       Color disable) {                
+               polygonColors.set(DACustomButton.STATE_NORMAL, normal);
+               polygonColors.set(DACustomButton.STATE_PUSH, normal);
+               polygonColors.set(DACustomButton.STATE_HOVER, normal);
+               polygonColors.set(DACustomButton.STATE_DISABLE, disable);               
+       }
+       
+}
index 969b7b3..09da61f 100644 (file)
@@ -32,6 +32,9 @@ import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
 import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonClickEventListener;
 import org.tizen.dynamicanalyzer.widgets.popupMenu.DAPopupMenu;
 
+/**
+ * This class is responsible for the operation when the user clicks on the split button.
+ */
 public abstract class DACustomSplitButtonClickEventListener extends
                DACustomButtonClickEventListener {
 
@@ -44,6 +47,7 @@ public abstract class DACustomSplitButtonClickEventListener extends
                        int y = event.y;
 
                        if (x < 0 || x > rectangle.width || y < 0 || y > rectangle.height) {
+                               // return if it is not button area
                                return;
                        }                       
                } else {
@@ -65,6 +69,7 @@ public abstract class DACustomSplitButtonClickEventListener extends
                }
                
                if (!button.isDisposed()) {
+                       // if the button does not dispose, applied to tooltip
                        button.setToolTipText(tooltip);
                }
        }
@@ -77,8 +82,9 @@ public abstract class DACustomSplitButtonClickEventListener extends
        }
 
        private boolean isShowMenu(DACustomSplitButton button, int x, int y) {
-               Point startArea = button.getPolygonAreaPoint(DACustomSplitButton.AREA_START);
-               Point endArea = button.getPolygonAreaPoint(DACustomSplitButton.AREA_END);
+               DACustomSplitButtonAttribute attr = button.getAttr();
+               Point startArea = attr.getPolygonAreaPoint(DACustomSplitButton.AREA_START);
+               Point endArea = attr.getPolygonAreaPoint(DACustomSplitButton.AREA_END);
                return x>=startArea.x && y>startArea.y && x<=endArea.x && y<=endArea.y;
        }
        
index 514c2c1..4f25340 100644 (file)
@@ -36,6 +36,9 @@ import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
 import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonAttribute;
 import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonRenderer;
 
+/**
+ * This class is responsible for drawing the split button.
+ */
 public class DACustomSplitButtonRenderer extends DACustomButtonRenderer {
 
        @Override
@@ -50,13 +53,14 @@ public class DACustomSplitButtonRenderer extends DACustomButtonRenderer {
                        drawButton(gc, rect, state, attr);
                }
                
-               if (attr.getSplitButtonType() == DACustomSplitButton.TYPE_POLYGON) {
-                       drawButtonPolygon(gc, rect, attr, state);
+               DACustomSplitButtonAttribute splitAttr = (DACustomSplitButtonAttribute)attr;
+               if (splitAttr.getSplitButtonType() == DACustomSplitButton.TYPE_POLYGON) {
+                       drawButtonPolygon(gc, rect, splitAttr, state);
                }
        }       
        
        protected void drawButtonPolygon(GC gc, Rectangle rect,
-                       DACustomButtonAttribute attr, int state) {
+                       DACustomSplitButtonAttribute attr, int state) {
                Color color = null;
                
                // draw split line