Bug 133268 - How to create a dialog shell with upper left corner at cursor position
Summary: How to create a dialog shell with upper left corner at cursor position
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Carolyn MacLeod CLA
QA Contact:
URL:
Whiteboard:
Keywords: example
Depends on:
Blocks:
 
Reported: 2006-03-25 10:11 EST by andrea del bene CLA
Modified: 2006-04-04 07:22 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description andrea del bene CLA 2006-03-25 10:11:42 EST
Eclipse build id or SWT version: swt version 3.1.2

Platform(s) tested on: windows xp

Snippet title: create a dialog shell with upper left corner at cursor position

Snippet code: 

/*******************************************************************************
 * 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
 *******************************************************************************/
package org.eclipse.swt.snippets;

/* 
 * Shell example snippet: create a dialog shell with upper left corner 
 * at cursor position
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class Snippet1{

public static void main (String [] args) {
	final Display display = new Display ();
	final Shell shell = new Shell (display);
	
	shell.setText ("Shell");
	shell.setSize (400, 400);
	shell.setText("Parent form");
	shell.open ();
	
	shell.addMouseListener(new org.eclipse.swt.events.MouseAdapter() {
			public void mouseDown(org.eclipse.swt.events.MouseEvent           e) {
					Shell dialog = new Shell (shell,    SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
					   dialog.setLocation(display.getCursorLocation().x, 
									        display.getCursorLocation().y);
					
					dialog.setText ("Dialog form");
					dialog.setSize (100, 100);
					dialog.open ();		
                }});
	
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}
Comment 1 andrea del bene CLA 2006-03-25 10:14:19 EST
sorry for my bad English :-)!!!
Comment 2 Steve Northover CLA 2006-03-27 14:25:28 EST
CAR, please evaluate this snippet, fix as necessary (get rid of multiple calls to getCursorLocation()) and post it.  Should this snippet just be "position a shell"?
Comment 3 Carolyn MacLeod CLA 2006-04-04 07:22:50 EDT
Done. Check out Snippet233.