UI : apply a drag image on DATabcomposite 69/23469/1
authorhyeran74.kim <hyeran74.kim@samsung.com>
Thu, 26 Jun 2014 07:19:15 +0000 (16:19 +0900)
committerhyeran74.kim <hyeran74.kim@samsung.com>
Thu, 26 Jun 2014 07:19:15 +0000 (16:19 +0900)
Change-Id: I386a02416870ea786b13a6864f247ed5b588c05c
Signed-off-by: hyeran74.kim <hyeran74.kim@samsung.com>
org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/resources/ImageResources.java
org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/widgets/da/view/DATabComposite.java
org.tizen.dynamicanalyzer.appearance/theme/white/img/drag_tab_32.png [new file with mode: 0644]

index e8544b3..92ec9d9 100644 (file)
@@ -128,6 +128,7 @@ public class ImageResources {
        public static final Image TAB_HOVER = getPngImage("tab_hover"); //$NON-NLS-1$\r
        public static final Image TAB_SELECTED = getPngImage("tab_selected"); //$NON-NLS-1$\r
        public static final Image TAB_DRAG = getPngImage("tab_dag"); //$NON-NLS-1$\r
+       public static final Image DRAG_TAB_32 = getPngImage("drag_tab_32"); //$NON-NLS-1$\r
 \r
        // Trim\r
        public static final Image WINDOW_TOP = getPngImage("window_top_pattern_01"); //$NON-NLS-1$\r
@@ -424,7 +425,7 @@ public class ImageResources {
        public static final Image SCREEN_SHOT_PUSH = getPngImage("toolbar_screen_shot_push"); //$NON-NLS-1$\r
        public static final Image SCREEN_SHOT_HOVER = getPngImage("toolbar_screen_shot_hover"); //$NON-NLS-1$\r
        public static final Image SCREEN_SHOT_DISABLE = getPngImage("toolbar_screen_shot_disable"); //$NON-NLS-1$\r
-\r
+       \r
        private static Image getImage(String pluginId, String folderName,\r
                        String imageName, String extension) {\r
                if (null == imageRegistry.get(imageName)\r
index f8c5d51..b3887f6 100644 (file)
@@ -37,6 +37,7 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.StackLayout;
 import org.eclipse.swt.events.PaintEvent;
 import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Cursor;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.layout.FormAttachment;
@@ -47,9 +48,11 @@ import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
 import org.tizen.dynamicanalyzer.appearance.DesignConstants;
 import org.tizen.dynamicanalyzer.resources.ColorResources;
 import org.tizen.dynamicanalyzer.resources.FontResources;
+import org.tizen.dynamicanalyzer.resources.ImageResources;
 import org.tizen.dynamicanalyzer.util.DALogger;
 import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
 import org.tizen.dynamicanalyzer.widgets.da.base.DAButton;
@@ -75,6 +78,10 @@ public class DATabComposite extends DABaseComposite {
        private int targetButtonIndex = -1;
        private int sourceButtonIndex = -1;
        private boolean drag = false;
+       private Shell shell = null;
+       private Display display = null;
+       private Cursor dragCursor = null;
+       private Cursor basicCursor = null;
        
        private boolean isImageTab = false;
        private int tabWidth = LONG_TAB_WIDTH;
@@ -84,16 +91,23 @@ public class DATabComposite extends DABaseComposite {
 
        public DATabComposite(Composite parent, int style) {
                super(parent, style);
+               this.shell = parent.getShell();
+               this.display = parent.getDisplay();
                construct();
        }
 
        public DATabComposite(Composite parent, int style, boolean istoplevel) {
                super(parent, style);
                this.isToplevel = istoplevel;
+               this.shell = parent.getShell();
+               this.display = parent.getDisplay();
                construct();
        }
 
        private void construct() {
+               dragCursor = new Cursor(display, ImageResources.DRAG_TAB_32.getImageData(), 0, 0);
+               basicCursor = new Cursor(display, SWT.CURSOR_ARROW);
+               
                buttons = new ArrayList<DATabButton>();
                children = new ArrayList<DABaseComposite>();
 
@@ -205,13 +219,14 @@ public class DATabComposite extends DABaseComposite {
                tabButton.setLayoutData(data);
 
                final DABaseComposite finalChild = child;
-
+               
                Listener tabMoveEvent = new Listener() {
 
                        @Override
                        public void handleEvent(Event event) {
-                               Point cursorLocation = Display.getCurrent().getCursorLocation();
+                               Point cursorLocation = tabComposite.getDisplay().getCurrent().getCursorLocation();
                                Point curPosition = tabComposite.toControl(cursorLocation);
+                               targetButtonIndex = curPosition.x / tabWidth;
 
                                switch (event.type) {
                                case SWT.MouseDown:
@@ -221,32 +236,13 @@ public class DATabComposite extends DABaseComposite {
 
                                        break;
                                case SWT.MouseUp:
+                                       // change the cursor icon
+                                       shell.setCursor(basicCursor);
                                        drag = false;
-                                       if (curPosition.y < tabComposite.getBounds().y
-                                                       || curPosition.y > tabComposite.getBounds().height
-                                                       || sourceButtonIndex == buttons.size()) {
-                                               return;
-                                       }
-
-                                       // find the tab button index the mouse pointer is dragged
-                                       // and dropped
-                                       // sourceButton : the tab button you want to move
-                                       // targetButton : the tab button of position that has moved
-                                       // the sourceButton
-                                       if (curPosition.x <= 0) {
-                                               targetButtonIndex = 0;
-                                       } else if (curPosition.x > tabWidth * buttons.size()) {
-                                               targetButtonIndex = buttons.size() - 1;
-                                       } else {
-                                               targetButtonIndex = curPosition.x / tabWidth;
-                                       }
-                                       // check whether the tab button has clicked or moved
+                                       
+                                       //click the tab button
                                        if (targetButtonIndex == sourceButtonIndex) {
-                                               // click
                                                changeButtonState(tabButton);
-                                       } else {
-                                               // move
-                                               reArrangeTabs();
                                        }
 
                                        lasttab = contentsStackLayout.topControl;
@@ -259,36 +255,36 @@ public class DATabComposite extends DABaseComposite {
                                        break;
                                case SWT.MouseMove:
                                        if (drag) {
-                                               DATabButton selectedBtn = (DATabButton) event.widget;
-                                               for (int i = 0; i < buttons.size(); i++) {
-                                                       Rectangle r = buttons.get(i).getBounds();
-                                                       DATabButton btn = (DATabButton) buttons.get(i);
-
-                                                       if (selectedBtn.equals(btn)) {
-                                                               btn.setGradationColor(
-                                                                               DACustomButton.STATE_DISABLE,
-                                                                               ColorResources.TAB_SELECTED_COLOR_START,
-                                                                               ColorResources.TAB_SELECTED_COLOR_END);
-                                                               btn.setButtonEnabled(false);
-                                                               lasttab = contentsStackLayout.topControl;
-                                                               contentsStackLayout.topControl = finalChild; // TODO
-                                                                                                                                                               // :
-                                                                                                                                                               // greatim:
-                                                                                                                                                               // is
-                                                                                                                                                               // this
-                                                                                                                                                               // right?
-                                                               tabComposite.layout();
-                                                               contentsComposite.layout();
-                                                       } else {
-                                                               if (r.contains(curPosition.x, 0)
-                                                                                && (event.y > r.y && event.y < r.y
-                                                                                               + r.height)) {
-                                                                       btn.changeButtonState(DACustomButton.STATE_HOVER);
-                                                               } else {
-                                                                       btn.changeButtonState(DACustomButton.STATE_NORMAL);
-                                                               }
-                                                       }
+                                               // change the cursor icon
+                                               shell.setCursor(dragCursor);
+                                               
+                                               // if the mouse pointer is out of tab area, break
+                                               if(curPosition.y < tabComposite.getBounds().y 
+                                                               || curPosition.y > tabComposite.getBounds().height
+                                                               || sourceButtonIndex == buttons.size()) {
+                                                       break;
+                                               }
+                                               
+                                               // search a tab button index of a position that the mouse pointer is dropped 
+                                               if(curPosition.x <=0){
+                                                       targetButtonIndex = 0;
+                                               }else if(curPosition.x > tabWidth * buttons.size()){
+                                                       targetButtonIndex = buttons.size() - 1;
                                                }
+                                               
+                                               // check whether the tab button has been clicked or moved
+                                               if (targetButtonIndex == sourceButtonIndex) {
+                                                       // if the tab button has been clicked, change the tab button state
+                                                       changeButtonState(tabButton);
+                                               } else {
+                                                       // if the tab button has been moved, rearrange the tab buttons
+                                                       reArrangeTabs();
+                                                       sourceButtonIndex = targetButtonIndex;
+                                               }
+                                               lasttab = contentsStackLayout.topControl;
+                                               contentsStackLayout.topControl = finalChild;
+                                               tabComposite.layout();
+                                               contentsComposite.layout();
                                        }
                                        break;
                                }
@@ -339,58 +335,72 @@ public class DATabComposite extends DABaseComposite {
                }
        }
 
+       /**
+        * rearrange tabs
+        */
        private void reArrangeTabs() {
-               if (sourceButtonIndex < targetButtonIndex) { // move forward
-                       // source
-                       setLayoutTabs(targetButtonIndex, sourceButtonIndex);
-                       if (sourceButtonIndex == 0) { // source == first tab
-                               // source+1
+               // sourceButtonIndex(index of the source tab): the index of the tab user
+               // want to move
+               // targetButtonIndex(index of the target tab): the index of the position
+               // user want to move the source tab button to
+               
+               // moving forward the tab
+               if (sourceButtonIndex < targetButtonIndex) { 
+                       // set the position of the tab of source index
+                       setLayoutTabs(targetButtonIndex, sourceButtonIndex);            
+                       // check whether the source tab is a first tab or not,
+                       // set the position of the tab button of source+1 index
+                       if (sourceButtonIndex == 0) {
                                setLayoutTabs(-1, (sourceButtonIndex + 1));
                        } else {
-                               // source+1
                                setLayoutTabs((sourceButtonIndex - 1), (sourceButtonIndex + 1));
                        }
-                       // target+1
-                       if (targetButtonIndex != buttons.size() - 1) {
+                       // set the position of the tab button of target+1 index
+                       if (targetButtonIndex != buttons.size()-1) {
                                setLayoutTabs(sourceButtonIndex, (targetButtonIndex + 1));
-                       }
-                       Collections.rotate(
-                                       buttons.subList(sourceButtonIndex, targetButtonIndex + 1),
-                                       -1);
-                       Collections.rotate(
-                                       children.subList(sourceButtonIndex, targetButtonIndex + 1),
-                                       -1);
-               } else { // move backward
-                       // source
-                       if (targetButtonIndex == 0) { // target == first tab
-                               setLayoutTabs(-1, sourceButtonIndex);
+                       } // else, no need to change the position
+                       
+                       Collections.rotate(buttons.subList(sourceButtonIndex, targetButtonIndex + 1), -1);
+                       Collections.rotate(children.subList(sourceButtonIndex, targetButtonIndex + 1), -1);
+               
+               // moving backward the tab
+               } else {  
+                       // check whether the target tab is a first tab or not
+                       // set the position of the tab of source index
+                       if (targetButtonIndex == 0) { 
+                               setLayoutTabs(-1, sourceButtonIndex);                           
                        } else {
                                setLayoutTabs((targetButtonIndex - 1), sourceButtonIndex);
                        }
-                       if (sourceButtonIndex != buttons.size() - 1) {
-                               // source+1
+                       // if the source tab is not a last tab,
+                       // set the position of the tab button of source+1 index
+                       if (sourceButtonIndex != buttons.size() - 1) {                                                                                                                                          
                                setLayoutTabs((sourceButtonIndex - 1), (sourceButtonIndex + 1));
-                       }
-                       // target
+                       }// else,  no need to change the position
+                       
+                       // set the position of the tab button of target index
                        setLayoutTabs(sourceButtonIndex, targetButtonIndex);
-                       Collections.rotate(
-                                       buttons.subList(targetButtonIndex, sourceButtonIndex + 1),
-                                       1);
-                       Collections.rotate(
-                                       children.subList(targetButtonIndex, sourceButtonIndex + 1),
-                                       1);
+                       
+                       Collections.rotate(buttons.subList(targetButtonIndex, sourceButtonIndex + 1), 1);
+                       Collections.rotate(children.subList(targetButtonIndex, sourceButtonIndex + 1), 1);
                }
        }
 
-       // positioning of the tab button
+       /**
+        * positioning of the tab button
+        * @param leftTabIndex
+        * @param tabIndex
+        */
        private void setLayoutTabs(int leftTabIndex, int tabIndex) {
                FormData data = new FormData();
                data.top = new FormAttachment(0, 1);
                data.bottom = new FormAttachment(100, 0);
                data.width = tabWidth;
                if (leftTabIndex != -1) {
+                       // if the tabIndex is not a first tab
                        data.left = new FormAttachment(buttons.get(leftTabIndex));
                } else {
+                       // if the tabIndex is a first tab
                        data.left = new FormAttachment(0, 0);
                }
                buttons.get(tabIndex).setLayoutData(data);
@@ -512,6 +522,8 @@ public class DATabComposite extends DABaseComposite {
        
        @Override
        public void clear() {
+               dragCursor.dispose();
+               basicCursor.dispose();
                int size = children.size();
                for (int i = 0; i < size; i++) {
                        children.get(i).clear();
diff --git a/org.tizen.dynamicanalyzer.appearance/theme/white/img/drag_tab_32.png b/org.tizen.dynamicanalyzer.appearance/theme/white/img/drag_tab_32.png
new file mode 100644 (file)
index 0000000..e65947d
Binary files /dev/null and b/org.tizen.dynamicanalyzer.appearance/theme/white/img/drag_tab_32.png differ