[Desc.] when the button is clicked, a context menu appears.
[Issue] -
Change-Id: I2ad2fe3535bcdb9f4faa7ee59624365a5fe3ac1d
Signed-off-by: heeyoung <heeyoung1008.hwang@samsung.com>
org.tizen.dynamicanalyzer.widgets.button,
org.tizen.dynamicanalyzer.widgets.button.checkbox,
org.tizen.dynamicanalyzer.widgets.button.radio,
+ org.tizen.dynamicanalyzer.widgets.button.splitButton,
org.tizen.dynamicanalyzer.widgets.button.toggle,
org.tizen.dynamicanalyzer.widgets.chart,
org.tizen.dynamicanalyzer.widgets.chartBoard,
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
+ * Heeyoung Hwang <heeyoung1008.hwang@samsung.com>
* Jooyoul Lee <jy.exe.lee@samsung.com>
* Juyoung Kim <j0.kim@samsung.com>
*
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
+import org.tizen.dynamicanalyzer.widgets.button.splitButton.DACustomSplitButton;
public class DACustomButtonAttribute {
private static final int MAX_SIZE = 12;
private List<Color> outlineColors = new ArrayList<Color>();
private List<Color> outlineInColors = new ArrayList<Color>();
+ // style : draw or position
+ private int splitButtonType = DACustomSplitButton.TYPE_POLYGON;
+
+ // split line
+ private boolean isPolygonSeparator = false;
+ private List<Point> polygonSeparatorPoints = new ArrayList<Point>();
+ private List<Color> polygonSeparatorColors = new ArrayList<Color>();
+
+ // polygon
+ private List<Point> polygonPoints = new ArrayList<Point>();
+ private List<Color> polygonColors = new ArrayList<Color>();
+
+ // split area
+ private List<Point> polygonAreaPoints = new ArrayList<Point>();
+
public DACustomButtonAttribute() {
for (int i = 0; i < MAX_SIZE; i++) {
images.add(null);
fontColors.add(null);
outlineColors.add(null);
outlineInColors.add(null);
+ polygonSeparatorPoints.add(null);
+ polygonSeparatorColors.add(null);
+ polygonColors.add(null);
+ polygonAreaPoints.add(null);
}
+ polygonPoints.clear();
}
public String getText() {
public int getAlign() {
return this.align;
}
+
+ public boolean isPolygonSeparator() {
+ return isPolygonSeparator;
+ }
+
+ public void setPolygonSeparator(boolean isPolygonSeparator) {
+ this.isPolygonSeparator = isPolygonSeparator;
+ }
+
+ public Point getPolygonSeparatorPoint(int position) {
+ return polygonSeparatorPoints.get(position);
+ }
+
+ public void setPolygonSeparatorPoint(int position, Point polygonSeparatorPoint) {
+ polygonSeparatorPoints.set(position, polygonSeparatorPoint);
+ }
+
+ public Point getPolygonPoint(int index) {
+ return polygonPoints.get(index);
+ }
+
+ public List<Point> getPolygonPoints() {
+ return polygonPoints;
+ }
+
+ public void setPolygonPoint(Point polygonPoint) {
+ polygonPoints.add(polygonPoint);
+ }
+
+ public Color getPolygonSeparatorColor(int state) {
+ return polygonSeparatorColors.get(state);
+ }
+
+ public void setPolygonSeparatorColor(int state, Color color) {
+ polygonSeparatorColors.set(state, color);
+ }
+
+ public Color getPolygonColor(int state) {
+ return polygonColors.get(state);
+ }
+
+ public void setPolygonColor(int state, Color color) {
+ polygonColors.set(state, color);
+ }
+
+ public Point getPolygonAreaPoint(int position) {
+ return polygonAreaPoints.get(position);
+ }
+
+ public void setPolygonAreaPoint(int position, Point polygonAreaPoint) {
+ polygonAreaPoints.set(position, polygonAreaPoint);
+ }
+
+ public int getSplitButtonType() {
+ return splitButtonType;
+ }
+
+ public void setSplitButtonType(int splitButtonType) {
+ this.splitButtonType = splitButtonType;
+ }
+
+
}
--- /dev/null
+/*
+ * Dynamic Analyzer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Heeyoung Hwang <heeyoung1008.hwang@samsung.com>
+ * Juyoung Kim <j0.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+package org.tizen.dynamicanalyzer.widgets.button.splitButton;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
+import org.tizen.dynamicanalyzer.widgets.popupMenu.DAPopupMenu;
+
+public class DACustomSplitButton extends DACustomButton {
+
+ // style
+ public static final int TYPE_AREA = 0;
+ public static final int TYPE_POLYGON = 1;
+
+ // position
+ public static final int AREA_START = 0;
+ public static final int AREA_END = 1;
+
+ private DAPopupMenu popupMenu = null;
+
+ public DACustomSplitButton(Composite parent, int style) {
+ super(parent, style);
+ initSplitButton();
+ }
+
+ public DACustomSplitButton(Composite parent, Image normal, Image mouseDown,
+ Image hover, Image disable) {
+ super(parent, normal, mouseDown, hover, disable);
+ initSplitButton();
+ }
+
+ public DACustomSplitButton(Composite parent, Color normalStart, Color normalEnd,
+ Color pushStart, Color pushEnd, Color hoverStart, Color hoverEnd,
+ Color disableStart, Color disableEnd) {
+ super(parent, normalStart, normalEnd, pushStart, pushEnd,
+ hoverStart, hoverEnd, disableStart, disableEnd);
+ initSplitButton();
+ }
+
+ public void initSplitButton() {
+ buttonRenderer = new DACustomSplitButtonRenderer();
+// addListeners();
+ }
+
+ public DAPopupMenu getPopupMenu() {
+ return popupMenu;
+ }
+
+ public void setPopupMenu(DAPopupMenu popupMenu) {
+ this.popupMenu = popupMenu;
+ }
+
+ public void setPolygonSeparatorColors(Color normal, Color push, Color hover,
+ Color disable) {
+ attr.setPolygonSeparatorColor(STATE_NORMAL, normal);
+ attr.setPolygonSeparatorColor(STATE_PUSH, push);
+ attr.setPolygonSeparatorColor(STATE_HOVER, hover);
+ attr.setPolygonSeparatorColor(STATE_DISABLE, disable);
+ }
+
+ public void setPolygonSeparatorColor(int state, Color color) {
+ attr.setPolygonSeparatorColor(state, color);
+ }
+
+ public void setPolygonColors(Color normal, Color push, Color hover,
+ Color disable) {
+ attr.setPolygonColor(STATE_NORMAL, normal);
+ attr.setPolygonColor(STATE_PUSH, push);
+ attr.setPolygonColor(STATE_HOVER, hover);
+ attr.setPolygonColor(STATE_DISABLE, disable);
+ }
+
+ public void setPolygonColor(int state, Color color) {
+ attr.setPolygonColor(state, color);
+ }
+
+ public void setPolygonSeparatorPoint(int position, Point point) {
+ attr.setPolygonSeparatorPoint(position, point);
+ }
+
+ public void setPolygonAreaPoint(int position, Point point) {
+ attr.setPolygonAreaPoint(position, point);
+ }
+
+ public Point getPolygonAreaPoint(int position) {
+ return attr.getPolygonAreaPoint(position);
+ }
+
+ public void setPolygonPoint(Point point) {
+ attr.setPolygonPoint(point);
+ }
+
+ public void setPolygonSeparator(boolean isPolygonSeparator) {
+ attr.setPolygonSeparator(isPolygonSeparator);
+ }
+
+ public void setSplitButtonType(int splitButtonType) {
+ attr.setSplitButtonType(splitButtonType);
+ }
+
+
+// protected Listener splitButtonMouseListener = new Listener() {
+//
+// @Override
+// public void handleEvent(Event event) {
+// if (state == STATE_DISABLE) {
+// return;
+// }
+//
+// if (event.type == SWT.MouseEnter) {
+//
+// }
+//
+// if (event.type == SWT.MouseExit) {
+// }
+//
+// if (event.type == SWT.MouseDown) {
+// }
+//
+// if (event.type == SWT.MouseUp) {
+// }
+// }
+// };
+//
+//
+// @Override
+// protected void addListeners() {
+// if (null != splitButtonMouseListener) {
+// this.addListener(SWT.MouseEnter, splitButtonMouseListener);
+// this.addListener(SWT.MouseExit, splitButtonMouseListener);
+// this.addListener(SWT.MouseDown, splitButtonMouseListener);
+// this.addListener(SWT.MouseUp, splitButtonMouseListener);
+// }
+// }
+}
--- /dev/null
+/*
+ * Dynamic Analyzer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Heeyoung Hwang <heeyoung1008.hwang@samsung.com>
+ * Juyoung Kim <j0.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+package org.tizen.dynamicanalyzer.widgets.button.splitButton;
+
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Event;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonClickEventListener;
+import org.tizen.dynamicanalyzer.widgets.popupMenu.DAPopupMenu;
+
+public abstract class DACustomSplitButtonClickEventListener extends
+ DACustomButtonClickEventListener {
+
+ @Override
+ public void handleEvent(Event event) {
+ DACustomButton button = (DACustomButton) event.widget;
+ if (null != button && button.getState() != DACustomSplitButton.STATE_DISABLE) {
+ Rectangle rectangle = button.getBounds();
+ int x = event.x;
+ int y = event.y;
+
+ if (x < 0 || x > rectangle.width || y < 0 || y > rectangle.height) {
+ return;
+ }
+ } else {
+ return;
+ }
+
+ String tooltip = button.getToolTipText();
+ button.setToolTipText(null);
+
+ DACustomSplitButton splitButton = (DACustomSplitButton)button;
+ if (isShowMenu(splitButton, event.x, event.y)) {
+ // click menu
+ //System.out.println("click menu");
+ handleMenuEvent(splitButton);
+ } else {
+ // click button
+ //System.out.println("click button");
+ handleClickEvent(button);
+ }
+
+ if (!button.isDisposed()) {
+ button.setToolTipText(tooltip);
+ }
+ }
+
+ private void handleMenuEvent(DACustomSplitButton button) {
+ Point p = button.toDisplay(0, 0);
+ DAPopupMenu popupMenu = button.getPopupMenu();
+ popupMenu.open(popupMenu.getTopShell(),
+ p.x, p.y+button.getBounds().height);
+ }
+
+ private boolean isShowMenu(DACustomSplitButton button, int x, int y) {
+ Point startArea = button.getPolygonAreaPoint(DACustomSplitButton.AREA_START);
+ Point endArea = button.getPolygonAreaPoint(DACustomSplitButton.AREA_END);
+ return x>=startArea.x && y>startArea.y && x<=endArea.x && y<=endArea.y;
+ }
+
+}
--- /dev/null
+/*
+ * Dynamic Analyzer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Heeyoung Hwang <heeyoung1008.hwang@samsung.com>
+ * Juyoung Kim <j0.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+package org.tizen.dynamicanalyzer.widgets.button.splitButton;
+
+import java.util.List;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonAttribute;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonRenderer;
+
+public class DACustomSplitButtonRenderer extends DACustomButtonRenderer {
+
+ @Override
+ public void draw(GC gc, Canvas canvas, int state,
+ DACustomButtonAttribute attr) {
+ Rectangle rect = canvas.getClientArea();
+
+ if (attr.getDrawType() == DACustomButton.TYPE_IMAGE) {
+ drawImageButton(gc, rect, state, attr);
+ } else if (attr.getDrawType() == DACustomButton.TYPE_COLOR
+ || attr.getDrawType() == DACustomButton.TYPE_GRADATION) {
+ drawButton(gc, rect, state, attr);
+ }
+
+ if (attr.getSplitButtonType() == DACustomSplitButton.TYPE_POLYGON) {
+ drawButtonPolygon(gc, rect, attr, state);
+ }
+ }
+
+ protected void drawButtonPolygon(GC gc, Rectangle rect,
+ DACustomButtonAttribute attr, int state) {
+ Color color = null;
+
+ // draw split line
+ Point startSeparator = attr.getPolygonSeparatorPoint(DACustomSplitButton.AREA_START);
+ Point endSeparator = attr.getPolygonSeparatorPoint(DACustomSplitButton.AREA_END);
+ if (attr.isPolygonSeparator()) {
+ color = attr.getPolygonSeparatorColor(state); // Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ gc.setForeground(color);
+ gc.setBackground(color);
+ gc.drawLine(startSeparator.x, startSeparator.y, endSeparator.x, endSeparator.y);
+
+// color = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
+// gc.setForeground(color);
+// gc.setBackground(color);
+// gc.drawLine(startSeparator.x-1, startSeparator.y, endSeparator.x-1, endSeparator.y);
+ }
+
+ // set polygon area
+ attr.setPolygonAreaPoint(DACustomSplitButton.AREA_START, new Point(startSeparator.x, 0));
+ attr.setPolygonAreaPoint(DACustomSplitButton.AREA_END, new Point(rect.width, rect.height));
+
+ // draw polygon
+ color = attr.getPolygonColor(state);
+ gc.setForeground(color);
+ gc.setBackground(color);
+ gc.fillPolygon(convertArray(attr.getPolygonPoints()));
+ }
+
+ private int[] convertArray(List<Point> list) {
+ int[] array = new int[list.size() * 2];
+ int arrayIndex = 0;
+ for (int i = 0; i < list.size(); i++) {
+ array[arrayIndex++] = list.get(i).x;
+ array[arrayIndex++] = list.get(i).y;
+ }
+ return array;
+ }
+}
* Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
+ * Heeyoung Hwang <heeyoung1008.hwang@samsung.com>
* yeongtaik byeon <yeongtaik.byeon@samsung.com>
* Juyoung Kim <j0.kim@samsung.com>
*
this.parent = parent;
setMouseListener();
}
+
+ public DAPopupMenu() {
+ // mouse listener is not registered
+ }
+ public void setParent(Composite parent) {
+ this.parent = parent;
+ }
+
public void setMouseListener(){
parent.getShell().addShellListener(new ShellListener() {