Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Custom GUI builder in my RCP application
Custom GUI builder in my RCP application [message #519145] Sun, 07 March 2010 04:50 Go to next message
Eclipse UserFriend
Originally posted by: jedlicka.poll.cz

This is a multi-part message in MIME format.
--------------090506010105030703030505
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit

I created a small custom GUI builder in my RCP application to let user
to build own composite. By move composite with mouse I have followed
example Snippet46 (Composite example snippet: intercept mouse events
(drag a button with the mouse)). I used FormLayout. I would like to see
a cross when moving composite to see where will be the composite placed
and to see also a tooltip with grid line (please see attached picture).
Blue dash line shows a location where will be composite paste (at the
same time into grid). The same way work also other builders (e.g. SWT
Designer). On the background is Canvas and moving is Composite.

My question is how to implement tooltip and dash line cross?

Thanks for any advice or examples!

Martin

--------------090506010105030703030505
Content-Type: image/png;
name="DND_Widgets.png"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="DND_Widgets.png"

iVBORw0KGgoAAAANSUhEUgAAASAAAAEPCAIAAABtG440AAAACXBIWXMAAA7D AAAOwwHHb6hk
AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICE AAD6AAAAgOgA
AHUwAADqYAAAOpgAABdwnLpRPAAAD9pJREFUeF7tnTuO3EYURcf7cKgdOJto YkeKtYBZgAKl
6iUoFOBEq1AyUGDAgUMHzgQb8AIcCAoEAQbaxW8Xv10svkdeTp9Bw5B7WI/F y3vqvmK35R/+
/OP3O35QAAWcFAiA8UIBFHBS4M6pLmVRAAWK9hAVUAAF/BQAMDpkFHBUAMAc xfVbF6l8FAUA
DMBQwFEBAHMU9yirLPP0UwDAAAwFHBUAMEdx/dZFKh9FAQADMBRwVADAHMU9 yirLPP0UADAA
QwFHBQDMUVy/dZHKR1EAwAAMBRwVADBHcY+yyjJPPwUADMBQwFEBAHMU129d pPJRFAAwAEMB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Un
9wBTgA2uZaLCXvcy8bxJj+l7lzZYpEYTrNrdfX0dba7m6vQa0vHtbuJFyR4m ANhwk9a+M7/+
TR0WblwX0U7vcalZdZ7DffYEYMN9xfj28ix7s6uJTXzQXHVrzQOJQWRFrfvU HqzpEtsGpP+B
W93q10thT8/RbdtZXcyr99obsIQWccSmnV3QBY8p3qo9WPwVhBnA4gZmfA8w A1j0xaKRD4hq
614Vfd8DouC4bG6LjWW3aYz2ToW2UQs3B1i32y9ONV2nWgdbSce/RLKvVuvP 7g1Yqe+idj9e
9hYkWDJgE7EzYaBrT8bGnrutvyuuFdI+a1A5ylWKDYq7A5bwrZwre7C0BBt8 ra6merp430Jj
j5s7cZf6mdgGt23NKVTQSZvHmitVGOsPWL0jigHotvvNAVNPERMBu+wfEp8i Tu4B+i1i+/ik
+4WGuGvqmEXhvs7MIc3YKkeJi3l1epsAVtysuXa/+P3c52DNzZ7bg734+n7w +VhrkqnPwcb3
AJ2kqr9H13S58edgUx+SXhV93wNU0Embx75arT/7ZoClyZl31MS2Kq/Y+lHr 74prhfUXuGUF
Vyk2KA5g9m7Z4LZxiqMoAGAAdnN/acKWcD4LwOwZWVVxy/vHucQVALBVLI0O Fr/lTG9LBXwB
2/JKOBcKCCoAYOxAUMBRAQBzFFdwQWVKGysAYACGAo4KAJijuBsvlpxOUAEA AzAUcFQAwBzF
FVxQmdLGCgAYgKGAowIA5ijuxoslpxNUAMAADAUcFQAwR3EFF1SmtLECAAZg KOCoAIA5irvx
YsnpBBUAMABDAUcFAMxRXMEFlSltrACAARgKOCrwP9OZBDx2AKTGAAAAAElF TkSuQmCC
--------------090506010105030703030505--
Re: Custom GUI builder in my RCP application [message #519167 is a reply to message #519145] Sun, 07 March 2010 17:01 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
it was sunday so i thought...

try this...

/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

/*
 * Composite example snippet: intercept mouse events (drag a button with the mouse)
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import org.eclipse.swt.*;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;

public class Snippet46 {
	
	private static Color COLOR ;
	protected static int x;
	protected static int y;
	protected static boolean started;

	public static void main(String[] args) {
		Display display = new Display();
		COLOR = new Color(null,new RGB(255, 255, 222));
		final Shell shell = new Shell(display);
		final Composite composite = new Composite(shell, SWT.NONE);
		composite.setEnabled(false);
		composite.setLayout(new FillLayout());
		Button button = new Button(composite, SWT.PUSH);
		button.setText("Button");
		composite.pack();
		composite.setLocation(10, 10);
		final Point[] offset = new Point[1];
		Listener listener = new Listener() {
			public void handleEvent(Event event) {
				switch (event.type) {
				case SWT.MouseDown:
					started = true;
					Rectangle rect = composite.getBounds();
					if (rect.contains(event.x, event.y)) {
						Point pt1 = composite.toDisplay(0, 0);
						Point pt2 = shell.toDisplay(event.x, event.y);
						offset[0] = new Point(pt2.x - pt1.x, pt2.y - pt1.y);
					}
					break;
				case SWT.MouseMove:
					if (offset[0] != null) {
						Point pt = offset[0];
						x = event.x - pt.x;
						y = event.y - pt.y;
						composite.setLocation(event.x - pt.x, event.y - pt.y);
						shell.redraw();
					}
					break;
				case SWT.MouseUp:
					offset[0] = null;
					started = false;
					shell.redraw();
					break;
				}
			}
		};
		shell.addListener(SWT.MouseDown, listener);
		shell.addListener(SWT.MouseUp, listener);
		shell.addListener(SWT.MouseMove, listener);
		shell.addPaintListener(new PaintListener() {
			private int tooltipHieght = 10;
			private int tooltipWidth = 50;
			@Override
			public void paintControl(PaintEvent e) {
				if (started) {
					// e.gc.setLineWidth(5);
					e.gc.setLineStyle(SWT.LINE_DOT);
					e.gc.drawLine(x, 0, x, e.height);
					e.gc.drawLine(0, y + composite.getBounds().height, e.width,
							y + composite.getBounds().height);
					System.out.println(x + ":" + y);
					e.gc.setBackground(COLOR);
					int height = e.gc.getFontMetrics().getHeight();
					int cwidth = e.gc.getFontMetrics().getAverageCharWidth();
					String string = x+","+y;
					tooltipWidth = cwidth*string.length();
					tooltipHieght = height;
					//e.gc.drawRectangle(new Rectangle(x-tooltipWidth, y-tooltipHieght, tooltipWidth, tooltipHieght));
					e.gc.fillRectangle(new Rectangle(x-tooltipWidth-5, y-tooltipHieght, tooltipWidth, tooltipHieght));
					
					e.gc.drawString(string, x-tooltipWidth-5, y-tooltipHieght);
				}
			}
		});
		shell.setSize(300, 300);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}


modified the snippet for u r requirement...


instead of adding the paint listener to shell add it to canvas


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Custom GUI builder in my RCP application [message #519170 is a reply to message #519167] Sun, 07 March 2010 17:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jedlicka.poll.cz

Super!

Thank you very much!

Martin

vijay napsal(a):
> it was sunday so i thought...
>
> try this...
>
> /*********************************************************** ********************
>
> * Copyright (c) 2000, 2004 IBM Corporation 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:
> * IBM Corporation - initial API and implementation
> ************************************************************ *******************/
>
>
> /*
> * Composite example snippet: intercept mouse events (drag a button with
> the mouse)
> *
> * For a list of all SWT example snippets see
> * http://www.eclipse.org/swt/snippets/
> */
> import org.eclipse.swt.*;
> import org.eclipse.swt.events.PaintEvent;
> import org.eclipse.swt.events.PaintListener;
> import org.eclipse.swt.graphics.*;
> import org.eclipse.swt.widgets.*;
> import org.eclipse.swt.layout.*;
>
> public class Snippet46 {
>
> private static Color COLOR ;
> protected static int x;
> protected static int y;
> protected static boolean started;
>
> public static void main(String[] args) {
> Display display = new Display();
> COLOR = new Color(null,new RGB(255, 255, 222));
> final Shell shell = new Shell(display);
> final Composite composite = new Composite(shell, SWT.NONE);
> composite.setEnabled(false);
> composite.setLayout(new FillLayout());
> Button button = new Button(composite, SWT.PUSH);
> button.setText("Button");
> composite.pack();
> composite.setLocation(10, 10);
> final Point[] offset = new Point[1];
> Listener listener = new Listener() {
> public void handleEvent(Event event) {
> switch (event.type) {
> case SWT.MouseDown:
> started = true;
> Rectangle rect = composite.getBounds();
> if (rect.contains(event.x, event.y)) {
> Point pt1 = composite.toDisplay(0, 0);
> Point pt2 = shell.toDisplay(event.x, event.y);
> offset[0] = new Point(pt2.x - pt1.x, pt2.y -
> pt1.y);
> }
> break;
> case SWT.MouseMove:
> if (offset[0] != null) {
> Point pt = offset[0];
> x = event.x - pt.x;
> y = event.y - pt.y;
> composite.setLocation(event.x - pt.x, event.y -
> pt.y);
> shell.redraw();
> }
> break;
> case SWT.MouseUp:
> offset[0] = null;
> started = false;
> shell.redraw();
> break;
> }
> }
> };
> shell.addListener(SWT.MouseDown, listener);
> shell.addListener(SWT.MouseUp, listener);
> shell.addListener(SWT.MouseMove, listener);
> shell.addPaintListener(new PaintListener() {
> private int tooltipHieght = 10;
> private int tooltipWidth = 50;
> @Override
> public void paintControl(PaintEvent e) {
> if (started) {
> // e.gc.setLineWidth(5);
> e.gc.setLineStyle(SWT.LINE_DOT);
> e.gc.drawLine(x, 0, x, e.height);
> e.gc.drawLine(0, y + composite.getBounds().height,
> e.width,
> y + composite.getBounds().height);
> System.out.println(x + ":" + y);
> e.gc.setBackground(COLOR);
> int height = e.gc.getFontMetrics().getHeight();
> int cwidth =
> e.gc.getFontMetrics().getAverageCharWidth();
> String string = x+","+y;
> tooltipWidth = cwidth*string.length();
> tooltipHieght = height;
> //e.gc.drawRectangle(new Rectangle(x-tooltipWidth,
> y-tooltipHieght, tooltipWidth, tooltipHieght));
> e.gc.fillRectangle(new Rectangle(x-tooltipWidth-5,
> y-tooltipHieght, tooltipWidth, tooltipHieght));
>
> e.gc.drawString(string, x-tooltipWidth-5,
> y-tooltipHieght);
> }
> }
> });
> shell.setSize(300, 300);
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
>
>
> modified the snippet for u r requirement...
>
>
> instead of adding the paint listener to shell add it to canvas
Re: Custom GUI builder in my RCP application [message #519210 is a reply to message #519170] Mon, 08 March 2010 04:32 Go to previous message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
one thing tho....

re check the cordinates in the tool tip
> e.gc.drawString(string, x-tooltipWidth-5,
> y-tooltipHieght);


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Previous Topic:Re: Creating multiple Display objects
Next Topic:Click on empty row in a table
Goto Forum:
  


Current Time: Mon Sep 23 00:25:58 GMT 2019

Powered by FUDForum. Page generated in 0.03336 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top