Java Code Examples for org.eclipse.swt.widgets.Shell#setBounds()

The following examples show how to use org.eclipse.swt.widgets.Shell#setBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CDTSnippet05.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("CDateTime");
	shell.setLayout(new GridLayout());

	final CDateTime cdt = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN | CDT.TIME_SHORT | CDT.CLOCK_DISCRETE);
	cdt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
       
	shell.pack();
	Point size = shell.getSize();
	Rectangle screen = display.getMonitors()[0].getBounds();
	shell.setBounds(
			(screen.width-size.x)/2,
			(screen.height-size.y)/2,
			size.x,
			size.y
	);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 2
Source File: CDTSnippet01.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("CDateTime");
	shell.setLayout(new GridLayout(2, false));

	CDateTime cdt = new CDateTime(shell, CDT.BORDER | CDT.SPINNER);
	cdt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
       
	shell.pack();
	Point size = shell.getSize();
	Rectangle screen = display.getMonitors()[0].getBounds();
	shell.setBounds(
			(screen.width-size.x)/2,
			(screen.height-size.y)/2,
			size.x,
			size.y
	);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 3
Source File: DemoSelectableControlListViewer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static void main(String[] args) {
  Display display = new Display();
  COLOR_RED = getRegisteredColor("red", 255, 0, 0);
  COLOR_WHITE = getRegisteredColor("white", 255, 255, 255);

  Shell shell = new Shell(display);
  shell.setText("Demo ControlList");
  shell.setBounds(100, 100, 300, 400);
  FillLayout layout = new FillLayout();
  layout.type = SWT.VERTICAL;
  shell.setLayout(layout);
  createContents(shell);
  shell.open();
  while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
      display.sleep();
  }
  display.dispose();
}
 
Example 4
Source File: BlurredPanel.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Show the blurred panel
 */
public void show() {
	if (parent.isDisposed()) {
		SWT.error(SWT.ERROR_WIDGET_DISPOSED);
	}

	panel = new Shell(parent, SWT.APPLICATION_MODAL | SWT.NO_TRIM);
	panel.setLayout(new FillLayout());

	panel.addListener(SWT.KeyUp, event -> {
		event.doit = false;
	});

	canvas = new Canvas(panel, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
	canvas.addPaintListener(event -> {
		paintCanvas(event);
	});

	panel.setBounds(panel.getDisplay().map(parent, null, parent.getClientArea()));
	panel.open();

}
 
Example 5
Source File: DarkPanel.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Show the dark panel
 */
public void show() {
	if (parent.isDisposed()) {
		SWT.error(SWT.ERROR_WIDGET_DISPOSED);
	}

	panel = new Shell(parent, SWT.APPLICATION_MODAL | SWT.NO_TRIM);
	panel.setLayout(new FillLayout());
	panel.setAlpha(alpha);

	panel.addListener(SWT.KeyUp, event -> {
		event.doit = false;
	});

	canvas = new Canvas(panel, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
	canvas.addPaintListener(event -> {
		paintCanvas(event);
	});

	panel.setBounds(panel.getDisplay().map(parent, null, parent.getClientArea()));
	panel.open();
}
 
Example 6
Source File: Snippet8.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public Shell createShell() {
	printJob = new PrintJob("Snippet8.java", createPrint())
			.setMargins(108); // 1.5"

	shell = new Shell(display);
	shell.setText("Snippet8.java");
	shell.setBounds(100, 100, 800, 600);
	shell.setLayout(new GridLayout(1, false));

	createButtonPanel(shell).setLayoutData(
			new GridData(SWT.FILL, SWT.FILL, true, false));
	createScrollingPreview(shell).setLayoutData(
			new GridData(SWT.FILL, SWT.FILL, true, true));

	preview.setLazyPageLayout(true);
	preview.setPrintJob(printJob);
	updatePreviewSize();
	updatePageNumber();
	preview.startBackgroundLayout(() -> {
		updatePageNumber();
	});

	shell.setVisible(true);

	return shell;
}
 
Example 7
Source File: SimpleMessageDialog.java    From hop with Apache License 2.0 6 votes vote down vote up
/**
 * Overridden to auto-size the shell according to the selected width.
 */
@Override
protected void constrainShellSize() {
  super.constrainShellSize();
  try {
    // the shell property within the Windows class is private - need to access it via reflection
    final Field shellField = Window.class.getDeclaredField( "shell" );
    shellField.setAccessible( true );
    final Shell thisShell = (Shell) shellField.get( this );
    thisShell.pack();
    final int height = thisShell.computeSize( width, SWT.DEFAULT ).y;
    thisShell.setBounds( thisShell.getBounds().x, thisShell.getBounds().y, width + 4, height + 2 );
  } catch ( final Exception e ) {
    // nothing to do
  }
}
 
Example 8
Source File: SWTLayoutPositionTracker.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static void main(String[] args) {
	Display display = new Display();
	shell = new Shell(display);

	positiongLabel = new Label(shell, SWT.BORDER);
	
	int x= 60;
	int y=20;
	int width =400;
	int height=200;

	positiongLabel.setBounds(x, y, width, height);
	int toolbarSize = 30;

	shell.setBounds(200, 400, width+2*x , height + 2*y +toolbarSize);
	shell.open();
	
	
	
	shell.addMouseMoveListener(e -> showSize(e));
	positiongLabel.addMouseMoveListener(e -> showSize(e));
	
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 9
Source File: MetaXDialog.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
void showTip(String txt, ItemPkg tp, Table table)  {
	tip = new Shell((Shell) null, SWT.ON_TOP | SWT.TOOL);
	tip.setLayout(new FillLayout());
	tip.setBackground(table.getBackground());
	createCommandTip(tip, (Command) getSelectables().get(txt));
	Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	Rectangle rect = tp.getBounds();
	Point pt = table.toDisplay(rect.x + getSizeAdjustment(), rect.y
			- size.y);
	tip.setBounds(pt.x, pt.y, size.x, size.y);
	tip.setVisible(true);
}
 
Example 10
Source File: TmfAbstractToolTipHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static void setHoverLocation(Shell shell, Point position) {
    Rectangle displayBounds = shell.getDisplay().getBounds();
    Rectangle shellBounds = getBounds(shell);
    if (position.x + shellBounds.width + OFFSET > displayBounds.width && position.x - shellBounds.width - OFFSET >= 0) {
        shellBounds.x = position.x - shellBounds.width - OFFSET;
    } else {
        shellBounds.x = Math.max(Math.min(position.x + OFFSET, displayBounds.width - shellBounds.width), 0);
    }
    if (position.y + shellBounds.height + OFFSET > displayBounds.height && position.y - shellBounds.height - OFFSET >= 0) {
        shellBounds.y = position.y - shellBounds.height - OFFSET;
    } else {
        shellBounds.y = Math.max(Math.min(position.y + OFFSET, displayBounds.height - shellBounds.height), 0);
    }
    shell.setBounds(shellBounds);
}
 
Example 11
Source File: CDTSnippet07.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("CDateTime");
	shell.setLayout(new GridLayout());

	final CDateTime cdt1 = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
	cdt1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

	CDateTimeBuilder builder = CDateTimeBuilder.getStandard();
	builder.setFooter(Footer.Today().align(SWT.RIGHT), Footer.Clear().align(SWT.LEFT));
	
	final CDateTime cdt2 = new CDateTime(shell, CDT.BORDER | CDT.SIMPLE);
	cdt2.setBuilder(builder);
	cdt2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

	shell.pack();
	Point size = shell.getSize();
	Rectangle screen = display.getMonitors()[0].getBounds();
	shell.setBounds(
			(screen.width-size.x)/2,
			(screen.height-size.y)/2,
			size.x,
			size.y
	);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 12
Source File: DropTestSnippet.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("CDC");
	shell.setLayout(new GridLayout());

	GridLayout layout = new GridLayout(2, true);
	shell.setLayout(layout);

	final CDateTime cdc1 = new CDateTime(shell, CDT.BORDER);
	cdc1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

	final CDateTime cdc2 = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
	cdc2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));


	shell.pack();
	Point size = shell.getSize();
	Rectangle screen = display.getMonitors()[0].getBounds();
	shell.setBounds(
			(screen.width-size.x)/2,
			(screen.height-size.y)/2,
			size.x,
			size.y
	);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 13
Source File: CDTSnippet01.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("Nebula CDateTime");
	shell.setLayout(new GridLayout());

	GridLayout layout = new GridLayout();
	shell.setLayout(layout);

	final CDateTime cdt = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
	cdt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

	shell.pack();
	Point size = shell.getSize();
	Rectangle screen = display.getMonitors()[0].getBounds();
	shell.setBounds(
			(screen.width-size.x)/2,
			(screen.height-size.y)/2,
			size.x,
			size.y
	);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 14
Source File: CDateTimeSnippetBug527399.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("CDateTime");
	shell.setLayout(new GridLayout(2, false));

	CDateTime cdt = new CDateTime(shell, CDT.BORDER);
	String pattern = "dd.MM.yyyy HH:mm";
	cdt.setPattern(pattern);
	cdt.setSelection(new Date());
	cdt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	Label output = new Label(shell, SWT.NONE);
	output.setText("<press enter to see output value>");

	cdt.addSelectionListener(new SelectionAdapter() {
		SimpleDateFormat format = new SimpleDateFormat(pattern);

		@Override
		public void widgetSelected(SelectionEvent e) {
			String result = format.format(cdt.getSelection());
			output.setText(result);
			System.out.println(result);
		}
	});

	shell.pack();
	Point size = shell.getSize();
	Rectangle screen = display.getMonitors()[0].getBounds();
	shell.setBounds( (screen.width - size.x) / 2, (screen.height - size.y) / 2, size.x, size.y);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	display.dispose();
}
 
Example 15
Source File: NoWindowTest.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
private static void run(final Display display, final int x) {
    final Shell shell = new Shell(display);
    shell.setBounds(0, 0, 350, 350);

    shell.setLayout(new FillLayout(SWT.VERTICAL));

    // display.syncExec(new Runnable() {
    // public void run() {

    final ERDiagramEditPartFactory editPartFactory = new ERDiagramEditPartFactory();
    final GraphicalViewer viewer = new ScrollingGraphicalViewer();
    viewer.setControl(new FigureCanvas(shell));

    final ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(diagram);
    viewer.setRootEditPart(rootEditPart);

    viewer.setEditPartFactory(editPartFactory);
    viewer.setContents(diagram);

    viewer.getContents().refresh();

    // }
    // });

    shell.pack();
    shell.open();
    int count = 0;
    while (count < x) {
        if (!display.readAndDispatch()) {
            try {
                Thread.sleep(1000);
                count++;
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    viewer.getContents().deactivate();
    // display.dispose();
}
 
Example 16
Source File: AbstractExample.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
public AbstractExample(String title, String... infos) {
	Display display = new Display();

	shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
	shell.setText(title);
	shell.setBounds(0, 0, 640, 480);
	shell.setLayout(new FormLayout());

	if (infos.length > 0) {
		Label infoLabel = new Label(shell, SWT.NONE);
		FormData infoLabelFormData = new FormData();
		infoLabelFormData.right = new FormAttachment(100, -10);
		infoLabelFormData.bottom = new FormAttachment(100, -10);
		infoLabel.setLayoutData(infoLabelFormData);

		String infoText = "You can...";
		for (int i = 0; i < infos.length; i++) {
			infoText += "\n..." + infos[i];
		}
		infoLabel.setText(infoText);
	}

	// open the shell before creating the controllable shapes so that their
	// default coordinates are not changed due to the resize of their canvas
	shell.setBackground(
			Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
	shell.open();

	viewer = new ControllableShapeViewer(shell);
	for (ControllableShape cs : getControllableShapes()) {
		viewer.addShape(cs);
	}

	onInit();

	shell.addPaintListener(this);
	shell.redraw(); // triggers a PaintEvent platform independently

	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
}
 
Example 17
Source File: EmbeddedBrowser.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private static void setSafeBounds( Shell s, int x, int y, int width,
		int height )
{
	Rectangle clientArea = s.getDisplay( ).getClientArea( );

	width = Math.min( clientArea.width, width );

	height = Math.min( clientArea.height, height );

	x = Math.min( x + width, clientArea.x + clientArea.width ) - width;

	y = Math.min( y + height, clientArea.y + clientArea.height ) - height;

	x = Math.max( x, clientArea.x );

	y = Math.max( y, clientArea.y );

	s.setBounds( x, y, width, height );
}
 
Example 18
Source File: SWTDynamicLayoutChanges.java    From codeexamples-eclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static void main(String[] args) {
	
	Display display = new Display();
	Shell shell = new Shell(display);
	colorIndex = 0;
	colors = new ArrayList<>();
	colors.add(Display.getDefault().getSystemColor(SWT.COLOR_RED));
	colors.add(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));
	colors.add(Display.getDefault().getSystemColor(SWT.COLOR_YELLOW));
	colors.add(Display.getDefault().getSystemColor(SWT.COLOR_CYAN));
	colors.add(new Color (Display.getDefault(), 122, 122, 122));
	colors.add(new Color (Display.getDefault(), 255, 51, 227));
	colors.add(new Color (Display.getDefault(), 27, 82, 255));
	colors.add(new Color (Display.getDefault(), 240, 201, 27));
	colors.add(new Color (Display.getDefault(), 188, 188, 188));
	colors.add(Display.getDefault().getSystemColor(SWT.COLOR_DARK_MAGENTA));
	

	GridLayout gridLayout = new GridLayout(1, false);
	gridLayout.marginWidth = 0;
	gridLayout.marginHeight = 0;
	gridLayout.verticalSpacing = 0;
	gridLayout.horizontalSpacing = 0;
	shell.setLayout(gridLayout);
	
	Composite top = new Composite(shell, SWT.NONE);
	GridData d1 = new GridData(SWT.FILL, SWT.FILL, true, true);
	top.setLayoutData(d1);
	top.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));
	
	createLayer(shell);
	createLayer(shell);
	createLayer(shell);
	
	shell.setBounds(100, 100, 800, 600);
	shell.open();		
	
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 19
Source File: CDTSnippet10.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param args
 */
public static void main(final String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell( display );
	shell.setText( "CDateTime" );
	shell.setLayout( new GridLayout() );
	
	final String pattern = "EE, dd.MM.yyyy";
	
	final Label lbl1 = new Label( shell, SWT.NONE );
	lbl1.setText( "Date is rolling:" );
	lbl1.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
	
	final CDateTime cdt1 = new CDateTime( shell, CDT.BORDER );
	cdt1.setPattern( pattern );
	cdt1.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
	
	// CDateTimeBuilder builder = CDateTimeBuilder.getStandard();
	// builder.setFooter( Footer.Today().align( SWT.RIGHT ), Footer.Clear().align( SWT.LEFT ) );
	
	final Label lbl2 = new Label( shell, SWT.NONE );
	lbl2.setText( "Date is adding:" );
	lbl2.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
	
	final CDateTime cdt2 = new CDateTime( shell, CDT.BORDER | CDT.ADD_ON_ROLL );
	// cdt2.setBuilder( builder );
	cdt2.setPattern( pattern );
	cdt2.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
	
	final Label lbl3 = new Label( shell, SWT.NONE );
	lbl3.setText( "Select each 'DAY' and press 'UP_ARROW'!" );
	lbl3.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
	
	Calendar cal = new GregorianCalendar();
	cal.set( 2017, 0, 31 );
	cdt1.setSelection( cal.getTime() );
	cdt2.setSelection( cal.getTime() );
	
	shell.pack();
	Point size = shell.getSize();
	Rectangle screen = display.getMonitors()[0].getBounds();
	shell.setBounds(
			( screen.width - size.x ) / 2,
			( screen.height - size.y ) / 2,
			size.x,
			size.y );
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 20
Source File: CDTSnippet09.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("CDateTime");
	shell.setLayout(new FillLayout());

	// build list of allowed time zones -- since there are over 600 of them
	// we will add US time zones as an example of the developer
	// selectively allowing particular ones using political boundaries
	TimeZone[] timezones = new TimeZone[] {
			TimeZone.getTimeZone("US/Alaska"),
			TimeZone.getTimeZone("US/Hawaii"),
			TimeZone.getTimeZone("US/Pacific"),
			TimeZone.getTimeZone("US/Arizona"),
			TimeZone.getTimeZone("US/Mountain"),
			TimeZone.getTimeZone("US/Central"),
			TimeZone.getTimeZone("US/Eastern") };

	CDateTime dateTime = new CDateTime(shell, SWT.NONE);

	// This *requires* us to set a pattern that *must* include the Zone
	// Offset key (z)
	// otherwise the time zones functionality will be off
	dateTime.setPattern("MM/dd/yyyy HH:mm.ss z", timezones);

	// It is always a good idea to manually set the controls' initial time
	// zone
	// using one of the time zones from your list of allowed time zones.
	// When using the time zone functionality we do not alter the initial
	// time zone
	// in the setPattern( String, TimeZone[]) call
	dateTime.setTimeZone(timezones[0]);

	shell.pack();
	Point size = shell.getSize();
	Rectangle screen = display.getMonitors()[0].getBounds();
	shell.setBounds((screen.width - size.x) / 2,
			(screen.height - size.y) / 2, 180, 54);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}