+++ /dev/null
-/*
- * Dynamic Analyzer
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * HyunJong Park <phjwithyou.park@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.contextMenu;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.widgets.Composite;
-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.widgets.helper.ColorResources;
-
-/**
- * Newly implemented contextMenuItem class
- *
- * @author ParkHyunJong
- *
- */
-public class ContextMenu {
-
- public static final int STATE_NORMAL = 0;
- public static final int STATE_PUSH = 1;
- public static final int STATE_HOVER = 2;
- public static final int STATE_DISABLE = 3;
-
- private static final int DEFAULT_HEIGHT = 24;
- private static final int CHARACTER_WIDTH_PIXEL = 8;
- private static final int STORKE_PIXEL = 2;
- private static final int STAUES_ITEMS_CHECK_TIME = 500;
- private static final int ADJUSTED_CONTEXT_MENU_POINT = 5;
-
- private int menuShellWidth = 25;
- private int titleHeight = 0;
- private String title = null;
- private Font titleFont = null;
- private Color titleFontColor = null;
- private Color titleBacgroundColor = null;
-
- public static final int MOUSE_LEFT = 1;
- public static final int MOUSE_RIGHT = 3;
- private static Shell lastMenuShell = null;
- private Shell menuShell = null;
- private Shell parentShell = null;
- private Composite menuComp = null;
- private Composite menuTitleComp = null;
- private Composite parentComp = null;
- private Rectangle parentArea = null;
- private Timer checkEableTimer = null;
- private List<DAContextMenuItem> itemList = null;
- private Font itemFont = null;
-
- /**
- * create contextMenu Shell and Composite, add mouse listeners - mouse down.<br>
- */
- private void setDefaultSetting() {
- if (null != menuShell) {
- return;
- }
- menuShell = new Shell(parentShell, SWT.NO_TRIM);
- menuShell.setLayout(new FillLayout());
- menuComp = new Composite(menuShell, SWT.NONE);
- menuComp.addPaintListener(new PaintListener() {
-
- @Override
- public void paintControl(PaintEvent e) {
- // TODO Auto-generated method stub
- e.gc.setForeground(ColorResources.CONTEXT_MENU_STORKE_IN);
- e.gc.drawRectangle(menuComp.getBounds().x + STORKE_PIXEL - 1,
- menuComp.getBounds().y + STORKE_PIXEL - 1,
- menuComp.getBounds().width - 3,
- menuComp.getBounds().height - 3);
- }
- });
-
- menuComp.setLayout(new FormLayout());
- menuComp.setBackground(ColorResources.CONTEXT_MENU_STORKE_OUT);
- parentComp.addMouseListener(new MouseListener() {
- @Override
- public void mouseUp(MouseEvent e) {
- // TODO Auto-generated method stub
- }
-
- @Override
- public void mouseDown(MouseEvent event) {
- // TODO Auto-generated method stub
- switch (event.button) {
- case MOUSE_LEFT: {
- disappearContextMenu();
- break;
- }
- case MOUSE_RIGHT: {
- if (null != parentArea) {
- if (event.x > parentArea.x && event.y > parentArea.y
- && event.x < parentArea.x + parentArea.width
- && event.y < parentArea.y + parentArea.height) {
- open();
- }
- } else {
- open();
- }
- break;
- }
- default: {
- break;
- }
- }
- }
-
- @Override
- public void mouseDoubleClick(MouseEvent e) {
- // TODO Auto-generated method stub
- }
- });
-
- }
-
- /**
- * generated Title area of context menu
- */
- public void setTitleComposite() {
- if (getTitle().length() > 0) {
- menuTitleComp = new Composite(menuComp, SWT.NONE);
- menuTitleComp.addPaintListener(new PaintListener() {
- @Override
- public void paintControl(PaintEvent e) {
- // TODO Auto-generated method stub
- e.gc.setForeground(getTitleFontColor());
- if (null != getTitleFont()) {
- e.gc.setFont(getTitleFont());
- }
- e.gc.drawString(getTitle(), 5, getTitleHeight() / 6);
- }
- });
-
- menuTitleComp.setLayout(new FormLayout());
- menuTitleComp.setBackground(getTitleBacgroundColor());
- FormData compData = new FormData();
- compData.top = new FormAttachment(STORKE_PIXEL + 1, 0);
- compData.left = new FormAttachment(STORKE_PIXEL + 1, 0);
- compData.right = new FormAttachment(100, -STORKE_PIXEL - 1);
- compData.bottom = new FormAttachment(menuShellWidth - 4, 0);
- menuTitleComp.setLayoutData(compData);
- }
- }
-
- /**
- * Construct a new instance of this class.<br>
- *
- * @param parent
- * a composite control which will be the parent of the new
- * instance (cannot be bull)
- */
- public ContextMenu(Composite parent) {
- parentComp = parent;
- parentShell = parent.getShell();
- setDefaultSetting();
- }
-
- /**
- * Get contextMenu Shell.<br>
- *
- * @return contextMenu Shell
- */
- public Shell getShell() {
- return menuShell;
- }
-
- /**
- * Get contextMenu composite.<br>
- *
- * @return contextMenu composite
- */
- public Composite getComposite() {
- return this.menuComp;
- }
-
- /**
- * implementation item mouse listeners event.<br>
- */
- protected Listener itemMouseListener = new Listener() {
- @Override
- public void handleEvent(Event event) {
-
- DAContextMenuItem itme = (DAContextMenuItem) event.widget;
- if (event.type == SWT.MouseUp) {
- switch (event.button) {
- case MOUSE_LEFT: {
- if (itme.getState() != STATE_DISABLE) {
- disappearContextMenu();
- }
- break;
- }
- default: {
- break;
- }
- }
- }
- }
- };
-
- /**
- * disappear contextMenu
- */
- public void disappearContextMenu() {
- if(!menuShell.isDisposed()) {
- menuShell.setVisible(false);
- }
- }
-
- /**
- * Appear contextMenu when click mouse leftButton.<br>
- *
- * @param x
- * The value of x of the right mouse button to click
- * @param y
- * The value of y of the right mouse button to click
- */
- public void open(int x, int y) {
- if (null == lastMenuShell) {
- lastMenuShell = menuShell;
- } else {
- lastMenuShell.setVisible(false);
- lastMenuShell = menuShell;
- }
-
- if (null == menuShell) {
- setDefaultSetting();
- lastMenuShell = menuShell;
-
- }
-
- setTitleComposite();
-
- if (getItems() == null) {
- menuShell.setSize(CHARACTER_WIDTH_PIXEL, DEFAULT_HEIGHT
- + (getTitleHeight()));
- } else {
- int shellHeight = (DEFAULT_HEIGHT * getItems().size())
- + (STORKE_PIXEL * 2) + (getTitleHeight());
- if (getTitle().length() >= itemLongestTextLenght()) {
- menuShellWidth = getTitle().length() * CHARACTER_WIDTH_PIXEL;
- } else {
- menuShellWidth = itemLongestTextLenght()
- * CHARACTER_WIDTH_PIXEL;
- }
- menuShell.setSize(menuShellWidth, shellHeight);
- }
-
- menuShell.setLocation(x, y);
- menuShell.setVisible(true);
-
- if (checkEableTimer != null) {
- checkEableTimer.cancel();
- checkEableTimer = null;
- }
- disposeContextMenu(STAUES_ITEMS_CHECK_TIME);
- }
-
- /**
- * Get the coordinates of the mouse click.<br>
- *
- * @return Point object of coordinates of the mouse click
- */
- private Point computeContextMenuLocation() {
- Display display = Display.getCurrent();
- if (null == display) {
- display = Display.getDefault();
- }
- Point pt = display.getCursorLocation();
- return pt;
- }
-
- /**
- * Show the ContextMenu when click the right button.<br>
- */
- public void open() {
- Point pt = computeContextMenuLocation();
- pt.x = pt.x - ADJUSTED_CONTEXT_MENU_POINT;
- pt.y = pt.y - ADJUSTED_CONTEXT_MENU_POINT;
- open(pt.x, pt.y);
- }
-
- /**
- * Periodically check the focus has been on the context Menu.<br>
- *
- * @param milliseconds
- * Set the time to check regularly.
- */
- public void disposeContextMenu(int milliseconds) {
- this.checkEableTimer = new Timer();
- this.checkEableTimer.schedule(new TimerTask() {
- public void run() {
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- Rectangle rt = menuShell.getBounds();
- Point pt = Display.getCurrent().getCursorLocation();
- if (false == rt.contains(pt)) {
- if (checkEableTimer != null) {
- checkEableTimer.cancel();
- checkEableTimer = null;
- }
- disappearContextMenu();
- }
- }
- });
- }
- }, milliseconds, milliseconds);
- }
-
- /**
- * Register the DAContextMenuItem to the contextMenu.<br>
- *
- * @param item
- * contextMenu item object
- */
- public void addItem(DAContextMenuItem item) {
- if (itemList == null) {
- itemList = new ArrayList<DAContextMenuItem>();
- }
-
- FormData compData = new FormData();
- if (getItems() == null) {
- compData.top = new FormAttachment(0, STORKE_PIXEL
- + getTitleHeight());
- } else {
- compData.top = new FormAttachment(0, DEFAULT_HEIGHT
- * getItems().size() + STORKE_PIXEL + getTitleHeight());
- }
- compData.left = new FormAttachment(0, STORKE_PIXEL);
- compData.right = new FormAttachment(100, -STORKE_PIXEL);
- compData.height = DEFAULT_HEIGHT;
- item.setLayoutData(compData);
- if (itemFont != null) {
- item.setFont(this.itemFont);
- }
- itemList.add(item);
- item.addListener(SWT.MouseUp, itemMouseListener);
- }
-
- /**
- * Get the DAContextMenuItem.<br>
- *
- * @return contextMenu items list
- */
- public List<DAContextMenuItem> getItems() {
- if (itemList == null) {
- itemList = new ArrayList<DAContextMenuItem>();
- }
- return itemList;
- }
-
- /**
- * get The text length of the longest item
- *
- * @return text length
- */
- public int itemLongestTextLenght() {
- int lenght = 0;
- if (getItems() == null) {
- return lenght;
- }
- for (DAContextMenuItem item : getItems()) {
- if (lenght < item.getText().length()) {
- lenght = item.getText().length();
- }
- }
- return lenght;
- }
-
- /**
- * set parent area
- *
- * @param area
- * parent area
- */
- public void setParentArea(Rectangle area) {
- parentArea = area;
- }
-
- /**
- * Sets the font of the contxtImtes text.
- *
- * @param font
- * The font of the contextItem text.
- */
- public void setFont(Font font) {
- this.itemFont = font;
- for (DAContextMenuItem item : getItems()) {
- item.setFont(font);
- }
- }
-
- /**
- * get the height of the title area
- *
- * @return height
- */
- public int getTitleHeight() {
- return titleHeight;
- }
-
- /**
- * set the height of the title area
- *
- * @param contextMenuTitleHeight
- * height
- */
- public void setTitleHeight(int contextMenuTitleHeight) {
- this.titleHeight = contextMenuTitleHeight;
- }
-
- /**
- * get the title name
- *
- * @return the title name
- */
- public String getTitle() {
- if (title == null) {
- return "";//$NON-NLS-1$
- }
- return title;
- }
-
- /**
- * set the title name
- *
- * @param title
- * the title name
- */
- public void setTitle(String title) {
- this.title = title;
- setTitleHeight(15);
- }
-
- /**
- * get the title font
- *
- * @return the title font
- */
- public Font getTitleFont() {
- return titleFont;
- }
-
- /**
- * set the title font
- *
- * @param titleFont
- * the title font
- */
- public void setTitleFont(Font titleFont) {
- this.titleFont = titleFont;
- }
-
- /**
- * get color of the title font
- *
- * @return color
- */
- public Color getTitleFontColor() {
- if (titleFontColor == null) {
- titleFontColor = ColorResources.CONTEXT_MENU_TITLE_FONT_COLOR;
- }
- return titleFontColor;
- }
-
- /**
- * set color of the title font
- *
- * @param titleFontColor
- * color
- */
- public void setTitleFontColor(Color titleFontColor) {
- this.titleFontColor = titleFontColor;
- }
-
- /**
- * get The background color of the title
- *
- * @return The background color
- */
- public Color getTitleBacgroundColor() {
- if (titleBacgroundColor == null) {
- titleBacgroundColor = ColorResources.CONTEXT_MENU_TITLE_BACKGROUND_COLOR;
- }
- return titleBacgroundColor;
- }
-
- /**
- * set The background color of the title
- *
- * @param titleBacgroundColor
- * The background color
- */
- public void setTitleBacgroundColor(Color titleBacgroundColor) {
- this.titleBacgroundColor = titleBacgroundColor;
- }
-}
+++ /dev/null
-/*
- * Dynamic Analyzer
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * HyunJong Park <phjwithyou.park@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.contextMenu;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
-import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonRenderer;
-import org.tizen.dynamicanalyzer.widgets.helper.ColorResources;
-import org.tizen.dynamicanalyzer.widgets.helper.FontResources;
-
-/**
- * Newly implemented contextMenuItem class
- *
- * @author ParkHyunJong
- *
- */
-public class DAContextMenuItem extends DACustomButton {
- private double doubleData;
-
- /**
- * Constructs a new instance of this class given its menu and style value
- * describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in class SWT
- * which is applicable to instances of this class, or must be built by
- * bitwise OR'ing together (that is, using the int "|" operator) two or more
- * of those SWT style constants. The class description lists the style
- * constants that are applicable to the class. Style bits are also inherited
- * from superclasses.
- * </p>
- *
- * @param menu
- * a DAContextMenu which will be the parent of the new instance
- * (cannot be bull)
- * @param style
- * the style of control to construct
- */
- public DAContextMenuItem(ContextMenu menu) {
- super(menu.getComposite(), SWT.NONE);
- setDefaultSetting();
- menu.addItem(this);
- }
-
- /**
- * Sets Menu Item default state
- */
- private void setDefaultSetting() {
- attr.setColor(STATE_NORMAL,
- ColorResources.CONTEXT_MENU_STATUS_NORMAL_COLOR);
- attr.setColor(STATE_HOVER,
- ColorResources.CONTEXT_MENU_STATUS_HOVER_COLOR);
- attr.setColor(STATE_PUSH, ColorResources.CONTEXT_MENU_STATUS_PUSH_COLOR);
- attr.setColor(STATE_DISABLE,
- ColorResources.CONTEXT_MENU_STATUSE_DISABLE_COLOR);
- setOutlineColors(ColorResources.CONTEXT_MENU_OUTLINE_NORMAL_COLOR,
- ColorResources.CONTEXT_MENU_OUTLINE_PUSH_COLOR,
- ColorResources.CONTEXT_MENU_OUTLINE_HOVER_COLOR,
- ColorResources.CONTEXT_MENU_OUTLINE_DISABLE_COLOR);
- setFont(FontResources.CONTEXT_MENU_ITEM_FONT);
- this.setRenderer(new DACustomButtonRenderer());
- }
-
- /**
- *
- * adds button click listener
- *
- * @param listener
- * user implemented contextMenu item action listener
- */
- public void addClickListener(DAContextMenuListener listener) {
- addListener(SWT.MouseUp, listener);
- }
-
- /**
- * Sets the text of item <br>
- */
- public void setText(String newTitle) {
- attr.setText(newTitle);
- setFontPoint(new Point(5, 4));
- }
-
- /**
- * gets the text of item <br>
- *
- * @return the text of item
- */
- public String getText() {
- return attr.getText();
- }
-
- public double getDoubleData() {
- return doubleData;
- }
-
- public void setDoubleData(double data) {
- doubleData = data;
- }
-}