From: hyeran74.kim Date: Thu, 13 Mar 2014 02:21:52 +0000 (+0900) Subject: [Title] Page tab: simplify the logic of dynamic moving of tab X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7685690fa7c8994efa07d0b3ccf274bbf8bd3d8d;p=sdk%2Ftools%2Fdynamic-analyzer.git [Title] Page tab: simplify the logic of dynamic moving of tab [Desc.] [Issue] Change-Id: If26c54ebcac3cdb0eb6815100a1383cdb906db9d Signed-off-by: hyeran74.kim --- diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/DATabComposite.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/DATabComposite.java index 0dbced8..5e57d74 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/DATabComposite.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/DATabComposite.java @@ -4,7 +4,7 @@ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: - * Jooyoul Lee + * Hyeran Kim * Juyoung Kim * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -198,156 +198,37 @@ public class DATabComposite extends DAView { break; case SWT.MouseUp: drag = false; - for (int i = 0; i < getButtons().size(); i++) { - Rectangle rec = getButtons().get(i).getBounds(); - if (rec.contains(curPosition.x, 0) - && (event.y > rec.y && event.y < rec.y+ rec.height)) { - targetButtonIndex = i; - break; - } else { - targetButtonIndex = -1; - } + if(curPosition.y < tabComposite.getBounds().y + || curPosition.y > tabComposite.getBounds().height) { + 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 * getButtons().size()){ + targetButtonIndex = getButtons().size() - 1; + }else{ + targetButtonIndex = curPosition.x / tabWidth; } + // check whether the tab button has clicked or moved if (targetButtonIndex == sourceButtonIndex) { - stackLayout.topControl = tempChild; + //click changeButtonState(tabButton); - tabComposite.layout(); - contentsComposite.layout(); - tempChild.update(); - ((ViewAction) tempChild).updateView(); - - return; + } else { + //move + reArrangeTabs(); } - - if (targetButtonIndex != -1) { - if (sourceButtonIndex == 0) { // source == first tab - // source - FormData data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - data.left = new FormAttachment(getButtons().get(targetButtonIndex)); - data.width = tabWidth; - sourceButton.setLayoutData(data); - - // source+1 - data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - data.left = new FormAttachment(0, 0); - data.width = tabWidth; - getButtons().get(sourceButtonIndex + 1).setLayoutData(data); - - // target+1 - if (targetButtonIndex != getButtons().size()-1) { - data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - data.left = new FormAttachment(getButtons().get(sourceButtonIndex)); - data.width = tabWidth; - getButtons().get(targetButtonIndex+1).setLayoutData(data); - } - - Collections.rotate(getButtons().subList(sourceButtonIndex, targetButtonIndex + 1), -1); - Collections.rotate(getTabChildren().subList(sourceButtonIndex, targetButtonIndex + 1), -1); - - } else if (sourceButtonIndex == getButtons().size() - 1) { // source == last tab - // source - FormData data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - if (targetButtonIndex != 0) { - data.left = new FormAttachment(getButtons().get(targetButtonIndex - 1)); - } else { - data.left = new FormAttachment(0, 0); - } - data.width = tabWidth; - sourceButton.setLayoutData(data); - - // target - data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - data.left = new FormAttachment(getButtons().get(sourceButtonIndex)); - data.width = tabWidth; - ((DATabButton) getButtons().get(targetButtonIndex)).setLayoutData(data); - - Collections.rotate(getButtons().subList(targetButtonIndex, sourceButtonIndex + 1), 1); - Collections.rotate(getTabChildren().subList(targetButtonIndex, sourceButtonIndex + 1), 1); - - } else { // first tab < source < last tab - // source - FormData data = new FormData(); - - if (sourceButtonIndex < targetButtonIndex) { //forward - // source - data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - data.left = new FormAttachment(getButtons().get(targetButtonIndex)); - data.width = tabWidth; - sourceButton.setLayoutData(data); - - // source +1 - data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - data.left = new FormAttachment(getButtons().get(sourceButtonIndex - 1)); - data.width = tabWidth; - getButtons().get(sourceButtonIndex + 1).setLayoutData(data); - - // target+1 - if (targetButtonIndex != getButtons().size()-1) { - data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - data.left = new FormAttachment(getButtons().get(sourceButtonIndex)); - data.width = tabWidth; - getButtons().get(targetButtonIndex + 1).setLayoutData(data); - } - - Collections.rotate(getButtons().subList(sourceButtonIndex, targetButtonIndex + 1), -1); - Collections.rotate(getTabChildren().subList(sourceButtonIndex, targetButtonIndex + 1), -1); - - } else { //backward - // source - data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - if (targetButtonIndex == 0) { - data.left = new FormAttachment(0,0); - } else { - data.left = new FormAttachment(getButtons().get(targetButtonIndex - 1)); - } - data.width = tabWidth; - sourceButton.setLayoutData(data); - - // source +1 - data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - data.left = new FormAttachment(getButtons().get(sourceButtonIndex - 1)); - data.width = tabWidth; - getButtons().get(sourceButtonIndex + 1).setLayoutData(data); - - // tartget - data = new FormData(); - data.top = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - data.left = new FormAttachment(getButtons().get(sourceButtonIndex)); - data.width = tabWidth; - getButtons().get(targetButtonIndex).setLayoutData(data); - - Collections.rotate(getButtons().subList(targetButtonIndex, sourceButtonIndex + 1), 1); - Collections.rotate(getTabChildren().subList(targetButtonIndex, sourceButtonIndex + 1), 1); - } - } - } stackLayout.topControl = tempChild; tabComposite.layout(); contentsComposite.layout(); - + tempChild.update(); + ((ViewAction) tempChild).updateView(); + break; case SWT.MouseMove: if(drag){ @@ -364,7 +245,6 @@ public class DATabComposite extends DAView { stackLayout.topControl = tempChild; tabComposite.layout(); contentsComposite.layout(); - } else { if (r.contains(curPosition.x, 0) && (event.y > r.y && event.y < r.y+ r.height)) { @@ -408,6 +288,73 @@ public class DATabComposite extends DAView { return tabButton; } + private void setLayoutTabs(int leftTabIndex, int tabIndex) { + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.bottom = new FormAttachment(100, 0); + data.width = tabWidth; + if(leftTabIndex != -1){ + data.left = new FormAttachment(getButtons().get(leftTabIndex)); + }else{ + data.left = new FormAttachment(0, 0); + } + getButtons().get(tabIndex).setLayoutData(data); + } + + private void reArrangeTabs() { + if (sourceButtonIndex < targetButtonIndex) { // move forward + if (sourceButtonIndex == 0) { // source == first tab + // source + setLayoutTabs(targetButtonIndex, sourceButtonIndex); + // source+1 + setLayoutTabs(-1, (sourceButtonIndex + 1)); + // target+1 + if (targetButtonIndex != getButtons().size()-1) { + setLayoutTabs(sourceButtonIndex, (targetButtonIndex+1)); + } + Collections.rotate(getButtons().subList(sourceButtonIndex, targetButtonIndex + 1), -1); + Collections.rotate(getTabChildren().subList(sourceButtonIndex, targetButtonIndex + 1), -1); + } else { + // source + setLayoutTabs(targetButtonIndex, sourceButtonIndex); + // source+1 + setLayoutTabs((sourceButtonIndex - 1), (sourceButtonIndex + 1)); + // target+1 + if (targetButtonIndex != getButtons().size()-1) { + setLayoutTabs(sourceButtonIndex, (targetButtonIndex + 1)); + } + Collections.rotate(getButtons().subList(sourceButtonIndex, targetButtonIndex + 1), -1); + Collections.rotate(getTabChildren().subList(sourceButtonIndex, targetButtonIndex + 1), -1); + } + } else { // move backward + if (sourceButtonIndex == getButtons().size() - 1) { // source == last tab + // source + if (targetButtonIndex != 0) { + setLayoutTabs((targetButtonIndex - 1), sourceButtonIndex); + } else { + setLayoutTabs(-1, sourceButtonIndex); + } + // target + setLayoutTabs(sourceButtonIndex, targetButtonIndex); + Collections.rotate(getButtons().subList(targetButtonIndex, sourceButtonIndex + 1), 1); + Collections.rotate(getTabChildren().subList(targetButtonIndex, sourceButtonIndex + 1), 1); + } else { + // source + if (targetButtonIndex == 0) { + setLayoutTabs(-1, sourceButtonIndex); + } else { + setLayoutTabs((targetButtonIndex - 1), sourceButtonIndex); + } + // source+1 + setLayoutTabs((sourceButtonIndex - 1), (sourceButtonIndex + 1)); + // target + setLayoutTabs(sourceButtonIndex, targetButtonIndex); + Collections.rotate(getButtons().subList(targetButtonIndex, sourceButtonIndex + 1), 1); + Collections.rotate(getTabChildren().subList(targetButtonIndex, sourceButtonIndex + 1), 1); + } + } + } + public void removeView(final String ID, boolean usingAnimation) { Composite child = childrenMap.get(ID); getTabChildren().remove(child);