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

The following examples show how to use org.eclipse.swt.widgets.Shell#setVisible() . 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: 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 2
Source File: Snippet7.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public Shell createShell() {
	printJob = new PrintJob("Snippet7.java", createPrint())
			.setMargins(108); // 1.5"

	shell = new Shell(display);
	shell.setText("Snippet7.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.setPrintJob(printJob);
	updatePreviewSize();
	updatePageNumber();

	shell.setVisible(true);

	return shell;
}
 
Example 3
Source File: SWTUtil.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
 */
@Override
public void mouseDown(MouseEvent e) {
  Control theControl = (Control) e.widget;

  Display display = theControl.getDisplay();
  Shell tip = new Shell(theControl.getShell(), SWT.ON_TOP | SWT.TOOL);
  tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
  FillLayout layout = new FillLayout();
  layout.marginHeight = 1;
  layout.marginWidth = 2;
  tip.setLayout(layout);
  Label label = new Label(tip, SWT.NONE);
  label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
  label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));

  label.setText(theControl.getToolTipText());
  label.addMouseTrackListener(this);
  Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
  Rectangle rect = theControl.getBounds();
  Point pt = theControl.getParent().toDisplay(rect.x, rect.y);
  tip.setBounds(pt.x, pt.y, size.x, size.y);
  tip.setVisible(true);
}
 
Example 4
Source File: Snippet6.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Executes the snippet.
 *
 * @param args
 *            command-line args.
 */
public static void main(String[] args) {
	Display display = Display.getDefault();
	final Shell shell = new Shell(display);
	shell.setText("Snippet6.java");
	shell.setBounds(100, 100, 640, 480);
	shell.setLayout(new GridLayout());

	Button button = new Button(shell, SWT.PUSH);
	button.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
	button.setText("Print");

	PrintViewer viewer = new PrintViewer(shell, SWT.BORDER);
	viewer.getControl()
			.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	final Print print = createPrint();
	viewer.setPrint(print);

	button.addListener(SWT.Selection, event -> {
		PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
		PrinterData printerData = dialog.open();
		if (printerData != null)
			PaperClips.print(
					new PrintJob("Snippet6.java", print).setMargins(72),
					printerData);
	});

	shell.setVisible(true);

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	display.dispose();
}
 
Example 5
Source File: Snippet2.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Executes the snippet.
 *
 * @param args
 *            command-line args.
 */
public static void main(String[] args) {
	Display display = Display.getDefault();
	final Shell shell = new Shell(display);
	shell.setText("Snippet2.java");
	shell.setBounds(100, 100, 640, 480);
	shell.setLayout(new GridLayout());

	Button button = new Button(shell, SWT.PUSH);
	button.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
	button.setText("Print");

	PrintViewer viewer = new PrintViewer(shell, SWT.BORDER);
	viewer.getControl()
			.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	final Print print = createPrint();
	viewer.setPrint(print);

	button.addListener(SWT.Selection, event -> {
		PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
		PrinterData printerData = dialog.open();
		if (printerData != null)
			PaperClips.print(
					new PrintJob("Snippet2.java", print).setMargins(72),
					printerData);
	});

	shell.setVisible(true);

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	display.dispose();
}
 
Example 6
Source File: Snippet5.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Executes the snippet.
 *
 * @param args
 *            command-line args.
 */
public static void main(String[] args) {
	Display display = Display.getDefault();
	final Shell shell = new Shell(display);
	shell.setText("Snippet5.java");
	shell.setBounds(100, 100, 640, 480);
	shell.setLayout(new GridLayout());

	Button button = new Button(shell, SWT.PUSH);
	button.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
	button.setText("Print");

	PrintViewer viewer = new PrintViewer(shell, SWT.BORDER);
	viewer.getControl()
			.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	final Print print = createPrint();
	viewer.setPrint(print);

	button.addListener(SWT.Selection, event -> {
		PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
		PrinterData printerData = dialog.open();
		if (printerData != null)
			PaperClips.print(
					new PrintJob("Snippet5.java", print).setMargins(72),
					printerData);
	});

	shell.setVisible(true);

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	display.dispose();
}
 
Example 7
Source File: PopupDialog.java    From SWET with MIT License 5 votes vote down vote up
/**
 * Opens this window, creating it first if it has not yet been created.
 * <p>
 * This method is reimplemented for special configuration of PopupDialogs.
 * It never blocks on open, immediately returning <code>OK</code> if the
 * open is successful, or <code>CANCEL</code> if it is not. It provides
 * framework hooks that allow subclasses to set the focus and tab order, and
 * avoids the use of <code>shell.open()</code> in cases where the focus
 * should not be given to the shell initially.
 * 
 * @return the return code
 * 
 * @see org.eclipse.jface.window.Window#open()
 */
public int open() {

	Shell shell = getShell();
	if (shell == null || shell.isDisposed()) {
		shell = null;
		// create the window
		create();
		shell = getShell();
	}

	// provide a hook for adjusting the bounds. This is only
	// necessary when there is content driven sizing that must be
	// adjusted each time the dialog is opened.
	adjustBounds();

	// limit the shell size to the display size
	constrainShellSize();

	// set up the tab order for the dialog
	setTabOrder((Composite) getContents());

	// initialize flags for listening to deactivate
	listenToDeactivate = false;
	listenToParentDeactivate = false;

	// open the window
	if (takeFocusOnOpen) {
		shell.open();
		getFocusControl().setFocus();
	} else {
		shell.setVisible(true);
	}

	return OK;

}
 
Example 8
Source File: ShellFactory.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void open() {
	UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
	if (uiFunctions != null) {
		Boolean bringToFront = (Boolean)getData( "bringToFront" );
		if ( bringToFront == null || bringToFront ){
			Shell mainShell = uiFunctions.getMainShell();
			if (mainShell != null && mainShell.getMinimized()) {
				uiFunctions.bringToFront();
			}
		}
	}

	Shell firstShellWithStyle = Utils.findFirstShellWithStyle(SWT.APPLICATION_MODAL);
	if (firstShellWithStyle != null && firstShellWithStyle != this) {
		// ok, there's a window with application_modal set, which on OSX will mean
		// that if we open our window, it will be on top, but users won't be able
		// to interact with it.  So, wait until the modal window goes away..
		firstShellWithStyle.addDisposeListener(new DisposeListener() {
			@Override
			public void widgetDisposed(DisposeEvent e) {
				// wait for dispose to complete, then run open again to check for
				// any new application modal shells to wait for
				Utils.execSWTThreadLater(0, new AERunnable() {
					@Override
					public void runSupport() {
						AEShell.this.open();
					}
				});
			}
		});
		firstShellWithStyle.setVisible(true);
		firstShellWithStyle.forceActive();
	} else {
		if (!isDisposed()) {
			super.open();
		}
	}
}
 
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: BufferDialog.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());
	createBufferTip(tip, (IEditorReference)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 11
Source File: Snippet1.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Executes the snippet.
 *
 * @param args
 *            command-line args.
 */
public static void main(String[] args) {
	Display display = Display.getDefault();
	final Shell shell = new Shell(display);
	shell.setText("Snippet1.java");
	shell.setBounds(100, 100, 640, 480);
	shell.setLayout(new GridLayout());

	Button button = new Button(shell, SWT.PUSH);
	button.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
	button.setText("Print the table");

	final Table table = new Table(shell, SWT.BORDER);
	table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

	// Set up Table widget with dummy data.
	for (int i = 0; i < 5; i++)
		new TableColumn(table, SWT.LEFT).setText("Column " + i);

	for (int row = 0; row < 100; row++) {
		TableItem item = new TableItem(table, SWT.NONE);
		for (int col = 0; col < 5; col++)
			item.setText(col, "Cell [" + col + ", " + row + "]");
	}

	table.setHeaderVisible(true);
	TableColumn[] columns = table.getColumns();
	for (int i = 0; i < columns.length; i++)
		columns[i].pack();

	button.addListener(SWT.Selection, event -> {
		PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
		PrinterData printerData = dialog.open();
		if (printerData != null) {
			Print print = createPrint(table);
			PaperClips.print(
					new PrintJob("Snippet1.java", print).setMargins(72),
					printerData);
		}
	});

	shell.setVisible(true);

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	display.dispose();
}
 
Example 12
Source File: MinimizableWizardDialog.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * The Hide button has been pressed.
 */
public void hidePressed()
{
	if (hideOnFinish)
	{
		final Shell activeShell = getShell();
		toast = new GenericInfoPopupDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
				infoTitle, infoMessage, new Runnable()
				{
					public void run()
					{
						activeShell.setVisible(true);
					}
				});
		toast.open();
		activeShell.setVisible(false);

		activeShell.addListener(SWT.Show, new Listener()
		{
			public void handleEvent(Event event)
			{
				if (toast != null)
				{
					// Incase if the shell is opened through other source, close the toast
					toast.close();
				}
			}
		});

		activeShell.addShellListener(new ShellAdapter()
		{
			@Override
			public void shellClosed(ShellEvent e)
			{
				if (toast != null)
				{
					// In case the shell gets closed programatically, close the toast.
					toast.close();
				}
			}
		});
	}

}