Hyperlink: add Hyperlink widget
authorjihye424.kim <jihye424.kim@samsung.com>
Mon, 31 Aug 2015 08:10:43 +0000 (17:10 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 1 Sep 2015 04:58:40 +0000 (13:58 +0900)
- that widget draws underlined text

Change-Id: Ia0de7a202cc6179f2f6dd3f800aca6657c386abe
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/renewal/resources/ColorResources.java
src/org/tizen/emulator/manager/renewal/resources/FontResources.java
src/org/tizen/emulator/manager/ui/renewal/tableviewer/AbstractTableViewer.java
src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTableViewer.java
src/org/tizen/emulator/manager/ui/renewal/widgets/Hyperlink.java [new file with mode: 0644]

index ca62f0b..9df5b80 100644 (file)
@@ -45,6 +45,7 @@ public enum ColorResources {
        GRAY_BTN_DISABLE(208, 208, 208),
 
        TABLE_VIEWER_BG(240, 240, 240),
+       LINK_MENU_FONT(255, 255, 255),
        MESSAGE_BOX_TITLE_BG(111, 125, 149),
        MESSAGE_BOX_TITLE_FONT(255, 255, 255),
        MESSAGE_BOX_CONTENTS_BG(255, 255, 255),
index 238d6fb..80f745e 100644 (file)
@@ -42,6 +42,7 @@ public enum FontResources {
        // * Nomal button
        BUTTON_FONT("button_font", resizeDefaultFont(9)), //$NON-NLS-1$
 
+       TABLE_VIEWER_LINK_MENU("link_menu_font", resizeDefaultFont(9)),
        MESSAGE_BOX_TITLE("msg_box_title", resizeDefaultFont(10)),
        MESSAGE_BOX_CONTENTS("msg_box_contents", resizeDefaultFont(9));
 
index 19ff24d..c5f5c2d 100644 (file)
@@ -42,13 +42,13 @@ 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.Label;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.emulator.manager.renewal.resources.ColorResources;
+import org.tizen.emulator.manager.renewal.resources.FontResources;
 import org.tizen.emulator.manager.renewal.resources.ImageResources;
 import org.tizen.emulator.manager.ui.dialog.AboutDialog;
+import org.tizen.emulator.manager.ui.renewal.widgets.Hyperlink;
 import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton;
-import org.tizen.emulator.manager.ui.table.FontResources;
 
 public abstract class AbstractTableViewer {
        private static final int BUTTON_MENU_WIDTH = 20;
@@ -64,7 +64,7 @@ public abstract class AbstractTableViewer {
        private static ImageButton infoButton;
        private List<ImageButton> buttonMenuList = new ArrayList<ImageButton>();
 
-       private List<Label> linkMenuList = new ArrayList<Label>();
+       private List<Hyperlink> linkMenuList = new ArrayList<Hyperlink>();
 
        public AbstractTableViewer(Shell shell, String key) {
                this.key = key;
@@ -161,7 +161,7 @@ public abstract class AbstractTableViewer {
                }
        }
 
-       public void addLinkMenu(Label menu) {
+       public void addLinkMenu(Hyperlink menu) {
                linkMenuList.add(menu);
        }
 
@@ -176,13 +176,14 @@ public abstract class AbstractTableViewer {
                                if (i == 0) {
                                        data.top = new FormAttachment (0, 5);
                                } else {
-                                       data.top = new FormAttachment(linkMenuList.get(i-1), 5);
+                                       data.top = new FormAttachment(linkMenuList.get(i - 1), 5);
                                }
                                data.right = new FormAttachment(100, -8);
-                               linkMenuList.get(i).setLayoutData(data);
-                               linkMenuList.get(i).setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND));
-                               linkMenuList.get(i).setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
-                               linkMenuList.get(i).setFont(FontResources.setSizeDefaultFont(10));
+                               Hyperlink menu = linkMenuList.get(i);
+                               menu.setLayoutData(data);
+                               menu.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND));
+                               menu.setForeground(ColorResources.LINK_MENU_FONT.getColor());
+                               menu.setFont(FontResources.TABLE_VIEWER_LINK_MENU.getFont());
                        }
                }
 
index 8274781..77c2e9e 100644 (file)
@@ -33,14 +33,17 @@ package org.tizen.emulator.manager.ui.renewal.tableviewer;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.emulator.manager.renewal.resources.ImageResources;
+import org.tizen.emulator.manager.ui.renewal.MainDialog;
+import org.tizen.emulator.manager.ui.renewal.widgets.Hyperlink;
 import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton;
 
 public class VMListTableViewer extends AbstractTableViewer {
-       Label templateList;
-       Label baseImageList;
+       Hyperlink templateList;
+       Hyperlink baseImageList;
        ImageButton refreshButton;
 
        VMListTable table;
@@ -69,22 +72,34 @@ public class VMListTableViewer extends AbstractTableViewer {
        @Override
        void setLinkerMenu() {
                // add linker
-               templateList = new Label(getTopComp(), SWT.None);
+               templateList = new Hyperlink(getTopComp(), SWT.None);
                templateList.setText("Templates");
-               //              templateList.addSelectionListener(new SelectionListener(){
-               //
-               //                      @Override
-               //                      public void widgetDefaultSelected(SelectionEvent arg0) {
-               //                              // TODO Auto-generated method stub
-               //                      }
-               //
-               //                      @Override
-               //                      public void widgetSelected(SelectionEvent arg0) {
-               //                              // TODO Auto-generated method stub
-               //                      }
-               //              });
-               baseImageList = new Label(getTopComp(), SWT.None);
+               templateList.addListener(SWT.Selection, new Listener() {
+                       @Override
+                       public void handleEvent(Event event) {
+                               if (event.type == SWT.Selection) {
+                                       MessageBox dialog = new MessageBox(MainDialog.getShell());
+                                       dialog.setMessage("Click Templates menu");
+                                       dialog.open();
+                               }
+                       }
+
+               });
+
+               baseImageList = new Hyperlink(getTopComp(), SWT.None);
                baseImageList.setText("Base Images");
+               baseImageList.addListener(SWT.Selection, new Listener() {
+                       @Override
+                       public void handleEvent(Event event) {
+                               if (event.type == SWT.Selection) {
+                                       if (event.type == SWT.Selection) {
+                                               MessageBox dialog = new MessageBox(MainDialog.getShell());
+                                               dialog.setMessage("Click BaseImages menu");
+                                               dialog.open();
+                                       }
+                               }
+                       }
+               });
 
                addLinkMenu(templateList);
                addLinkMenu(baseImageList);
diff --git a/src/org/tizen/emulator/manager/ui/renewal/widgets/Hyperlink.java b/src/org/tizen/emulator/manager/ui/renewal/widgets/Hyperlink.java
new file mode 100644 (file)
index 0000000..72c1b55
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.renewal.widgets;
+
+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.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+
+public class Hyperlink extends Canvas {
+       private String text = "";
+       private boolean underlined = true;
+       private Color focusBoxColor;
+
+       public Hyperlink(Composite parent, int style) {
+               super(parent, checkStyle(style));
+               this.addPaintListener(paintListener);
+               this.addMouseListener(mouseListener);
+               this.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+               focusBoxColor = Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
+       }
+
+       private static int checkStyle(int style) {
+               return style | SWT.NO_BACKGROUND;
+       }
+
+       public String getText() {
+               checkWidget();
+               return text;
+       }
+
+       public void setText(String text) {
+               checkWidget();
+               if (text == null) {
+                       SWT.error(SWT.ERROR_NULL_ARGUMENT);
+               }
+               this.text = text;
+       }
+
+       public boolean isUnderlined() {
+               checkWidget();
+               return underlined;
+       }
+
+       public void setUnderlined(boolean underlined) {
+               checkWidget();
+               this.underlined = underlined;
+       }
+
+       @Override
+       public Point computeSize(int wHint, int hHint, boolean changes) {
+               checkWidget();
+
+               if (wHint != SWT.DEFAULT && wHint < 0) {
+                       wHint = 0;
+               }
+
+               if (hHint != SWT.DEFAULT && hHint < 0) {
+                       hHint = 0;
+               }
+
+               Point size = new Point(0, 0);
+               Point textSize = getTextSize();
+               size.x = Math.max(wHint, textSize.x + 2);
+               if (underlined) {
+                       textSize.y += 1;
+               }
+               size.y = Math.max(hHint, textSize.y);
+
+               return size;
+       }
+
+       private Point getTextSize() {
+               Point size = new Point(0, 0);
+               GC gc = new GC(this);
+               if (text != null && text.length() > 0) {
+                       Point p = gc.textExtent(text, SWT.DRAW_MNEMONIC);
+                       size.x += p.x;
+                       size.y = Math.max(size.y, p.y);
+               } else {
+                       size.y = Math.max(size.y, gc.getFontMetrics().getHeight());
+               }
+
+               gc.dispose();
+               return size;
+       }
+
+       private PaintListener paintListener = new PaintListener() {
+
+               @Override
+               public void paintControl(PaintEvent e) {
+                       Point extent = getTextSize();
+
+                       GC gc = e.gc;
+
+                       if ((getStyle() & SWT.NO_BACKGROUND) != 0) {
+                               Rectangle rect = ((Hyperlink)e.widget).getClientArea();
+                               gc.setBackground(getBackground());
+                               gc.fillRectangle(rect);
+                       }
+
+                       gc.setForeground(focusBoxColor);
+                       if (isMouseDown) {
+                               gc.setLineStyle(SWT.LINE_DOT);
+                               gc.drawRectangle(0, 0, extent.x, extent.y - 2);
+                       }
+
+                       gc.setForeground(getForeground());
+                       gc.drawText(text, 0, 0, true);
+
+                       if (underlined) {
+                               gc.setLineStyle(SWT.LINE_SOLID);
+                               gc.drawLine(0, extent.y - 2, extent.x, extent.y - 2);
+                       }
+               }
+       };
+
+       private boolean isMouseDown = false;
+       private MouseListener mouseListener = new MouseListener() {
+
+               @Override
+               public void mouseDoubleClick(MouseEvent e) {
+                       isMouseDown = false;
+               }
+
+               @Override
+               public void mouseDown(MouseEvent e) {
+                       isMouseDown = true;
+                       redraw();
+               }
+
+               @Override
+               public void mouseUp(MouseEvent e) {
+                       if (isMouseDown) {
+                               isMouseDown = false;
+                               Event event = new Event();
+                               event.widget = e.widget;
+                               event.type = SWT.Selection;
+                               e.widget.notifyListeners(SWT.Selection, event);
+                       }
+               }
+       };
+}