summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Prus2013-12-13 05:37:23 (EST)
committerMarc Khouzam2013-12-13 05:44:21 (EST)
commit99b34b33524e01e19f71cd809c02f7d7122aeb26 (patch)
tree8bdbff26773ed0d93c8e4efc3facc3b4773e7ad2
parent7bbbbcf7a849682578052093a494806a4bfdf6fa (diff)
downloadorg.eclipse.cdt-99b34b33524e01e19f71cd809c02f7d7122aeb26.zip
org.eclipse.cdt-99b34b33524e01e19f71cd809c02f7d7122aeb26.tar.gz
org.eclipse.cdt-99b34b33524e01e19f71cd809c02f7d7122aeb26.tar.bz2
Bug 390827 - Trace View enhancement
Create necessary button. Signed-off-by: Vladimir Prus <vladimir@codesourcery.com>
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/tracepoints/FlatButton.java126
1 files changed, 126 insertions, 0 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/tracepoints/FlatButton.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/tracepoints/FlatButton.java
new file mode 100644
index 0000000..76de2be
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/tracepoints/FlatButton.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Mentor Graphics and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vladimir Prus (Mentor Graphics) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.gdb.internal.ui.tracepoints;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.TypedListener;
+
+public class FlatButton extends Canvas {
+
+ private String fText;
+ private int fMargin = 4;
+ private Cursor fHandCursor;
+
+ public FlatButton(Composite parent, int flags) {
+ super(parent, flags);
+
+ fHandCursor = getDisplay().getSystemCursor(SWT.CURSOR_HAND);
+ setCursor(fHandCursor);
+
+ addPaintListener(new PaintListener() {
+ @Override
+ public void paintControl(PaintEvent e) {
+ onPaint(e);
+ }
+ });
+
+ addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseDown(MouseEvent e) {
+ if (isEnabled()) {
+ notifyListeners(SWT.Selection, null);
+ }
+ }
+ });
+ }
+
+ public void addSelectionListener (SelectionListener listener) {
+ checkWidget ();
+ if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Selection,typedListener);
+ addListener (SWT.DefaultSelection,typedListener);
+ }
+
+ public void setText(String text) {
+ fText = text;
+ }
+
+ public String getText() {
+ return fText;
+ }
+
+ public void setMargin(int margin) {
+ fMargin = margin;
+ }
+
+ @Override
+ public Point computeSize(int wHint, int hHint, boolean changed) {
+ return computeSize(wHint, hHint);
+ }
+
+ @Override
+ public Point computeSize(int wHint, int hHint) {
+
+ GC gc = new GC(this);
+ if (fText == null || fText.isEmpty()) {
+ Point e = gc.textExtent("A"); //$NON-NLS-1$
+ return new Point(0, e.y + fMargin*2);
+ }
+
+
+ Point e = gc.textExtent(fText);
+ return new Point(e.x + fMargin*2, e.y + fMargin*2);
+ }
+
+ private void onPaint(PaintEvent event) {
+ GC gc = event.gc;
+ Rectangle ca = getClientArea();
+
+ Color mainColor = gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION);
+ gc.setBackground(mainColor);
+ float[] mainHSB = mainColor.getRGB().getHSB();
+ float h = mainHSB[0];
+ float s = mainHSB[1];
+ float b = mainHSB[2];
+
+
+ Color borderColor = new Color(gc.getDevice(), new RGB(h, s, (float)(b*0.7)));
+ Color shadowColor = new Color(gc.getDevice(), new RGB(h, s, (float)(b*0.5)));
+
+ gc.setForeground(borderColor);
+ gc.drawRectangle(0, 0, ca.width-1, ca.height-1);
+
+ gc.setForeground(shadowColor);
+ gc.drawLine(0, ca.height-1, ca.width-1, ca.height-1);
+
+ gc.fillRectangle(1, 1, ca.width-2, ca.height-2);
+
+ gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
+ gc.drawText(fText, fMargin, fMargin, true);
+
+ borderColor.dispose();
+ shadowColor.dispose();
+ }
+}