From 251e1c1d8c9bbff4793c9b10814657344cfce77b Mon Sep 17 00:00:00 2001 From: "hyeran74.kim" Date: Thu, 26 Jun 2014 16:19:15 +0900 Subject: [PATCH] UI : apply a drag image on DATabcomposite Change-Id: I386a02416870ea786b13a6864f247ed5b588c05c Signed-off-by: hyeran74.kim --- .../dynamicanalyzer/resources/ImageResources.java | 3 +- .../widgets/da/view/DATabComposite.java | 180 +++++++++++---------- .../theme/white/img/drag_tab_32.png | Bin 0 -> 3269 bytes 3 files changed, 98 insertions(+), 85 deletions(-) create mode 100644 org.tizen.dynamicanalyzer.appearance/theme/white/img/drag_tab_32.png diff --git a/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/resources/ImageResources.java b/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/resources/ImageResources.java index e8544b3..92ec9d9 100644 --- a/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/resources/ImageResources.java +++ b/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/resources/ImageResources.java @@ -128,6 +128,7 @@ public class ImageResources { public static final Image TAB_HOVER = getPngImage("tab_hover"); //$NON-NLS-1$ public static final Image TAB_SELECTED = getPngImage("tab_selected"); //$NON-NLS-1$ public static final Image TAB_DRAG = getPngImage("tab_dag"); //$NON-NLS-1$ + public static final Image DRAG_TAB_32 = getPngImage("drag_tab_32"); //$NON-NLS-1$ // Trim public static final Image WINDOW_TOP = getPngImage("window_top_pattern_01"); //$NON-NLS-1$ @@ -424,7 +425,7 @@ public class ImageResources { public static final Image SCREEN_SHOT_PUSH = getPngImage("toolbar_screen_shot_push"); //$NON-NLS-1$ public static final Image SCREEN_SHOT_HOVER = getPngImage("toolbar_screen_shot_hover"); //$NON-NLS-1$ public static final Image SCREEN_SHOT_DISABLE = getPngImage("toolbar_screen_shot_disable"); //$NON-NLS-1$ - + private static Image getImage(String pluginId, String folderName, String imageName, String extension) { if (null == imageRegistry.get(imageName) diff --git a/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/widgets/da/view/DATabComposite.java b/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/widgets/da/view/DATabComposite.java index f8c5d51..b3887f6 100644 --- a/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/widgets/da/view/DATabComposite.java +++ b/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/widgets/da/view/DATabComposite.java @@ -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(); children = new ArrayList(); @@ -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 index 0000000000000000000000000000000000000000..e65947dd43c84e26d0b6ac36c107590cfea6a8bc GIT binary patch literal 3269 zcmV;$3_A0PP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT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