* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
- * Jooyoul Lee <jy.exe.lee@samsung.com>
+ * Hyeran Kim <hyeran74.kim@samsung.com>
* Juyoung Kim <j0.kim@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
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){
stackLayout.topControl = tempChild;
tabComposite.layout();
contentsComposite.layout();
-
} else {
if (r.contains(curPosition.x, 0)
&& (event.y > r.y && event.y < r.y+ r.height)) {
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);