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;
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;
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;
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>();
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:
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;
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;
}
}
}
+ /**
+ * 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);
@Override
public void clear() {
+ dragCursor.dispose();
+ basicCursor.dispose();
int size = children.size();
for (int i = 0; i < size; i++) {
children.get(i).clear();