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

The following examples show how to use org.eclipse.swt.widgets.Shell#pack() . 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: SWTHelloWorld.java    From http4e with Apache License 2.0 6 votes vote down vote up
public static void main( String[] args){
      Display display = new Display();
      Shell shell = new Shell(display);

//      Text helloWorldTest = new Text(shell, SWT.NONE);
//      helloWorldTest.setText("Hello World SWT");
//      helloWorldTest.pack();

      Ch5CompletionEditor ch5CompletionEditor = new Ch5CompletionEditor(shell);
      

      shell.pack();
      shell.open();
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch())
            display.sleep();
      }
      display.dispose();
   }
 
Example 2
Source File: PatternImageEditorDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void toggleDropDown( )
{
	if ( dropDown == null || dropDown.isDisposed( ) )
	{
		Point pt = UIHelper.getScreenLocation( host );
		int x = pt.x;
		int y = pt.y + host.getSize( ).y;

		Shell shell = new Shell( host.getShell( ), SWT.NONE );
		shell.setLayout( new GridLayout( ) );
		shell.setLocation( x, y );
		dropDown = createDropDown( shell );
		shell.layout( );
		shell.pack( );
		shell.open( );
	}
	else
	{
		dropDown.getShell( ).close( );
	}
}
 
Example 3
Source File: TableHierarchicalExample.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public TableHierarchicalExample(IHierarchicalJaretTableModel hierarchicalModel) {
    _shell = new Shell(Display.getCurrent());
    _shell.setText("jaret table hierarchical example");
    createControls(hierarchicalModel);
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(400, 700);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 4
Source File: TableHierarchicalExample.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public TableHierarchicalExample(IHierarchicalJaretTableModel hierarchicalModel) {
    _shell = new Shell(Display.getCurrent());
    _shell.setText("jaret table hierarchical example");
    createControls(hierarchicalModel);
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(400, 700);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 5
Source File: SimpleModelExample.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public SimpleModelExample(IJaretTableModel tableModel) {
    _tableModel = tableModel;
    _shell = new Shell(Display.getCurrent());
    _shell.setText("simple jaret table example");
    createControls();
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(1000, 700);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 6
Source File: TableExample.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public TableExample(IJaretTableModel tableModel) {
    _tableModel = tableModel;
    _shell = new Shell(Display.getCurrent());
    _shell.setText("jaret table example");
    createControls();
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(1000, 700);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 7
Source File: SWT2FXGestureConversionDemo.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	shell.setBackground(
			Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
	shell.setText("SWT to FX Gesture Conversion Demo");
	FXCanvasEx canvas = new FXCanvasEx(shell, SWT.NONE);
	Scene scene = createScene();
	canvas.setScene(scene);
	shell.open();
	shell.pack();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	display.dispose();
}
 
Example 8
Source File: PopOverShellIntegTest.java    From swt-bling with MIT License 6 votes vote down vote up
private static void initialize() {
  if (needsInitialization()) {
    display = Display.getDefault();
    shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayout(new GridLayout());

    button = new Button(composite, SWT.PUSH);
    button.setText("Testing Button");

    popOverShell = Bubble.createBubble(button, BUBBLE_TEXT);
    button.setLayoutData(new GridData(SWT.LEFT, SWT.LEFT, true, true));
    shell.pack();
    shell.layout();

    initialized = true;
  }
}
 
Example 9
Source File: CDTSnippet08.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(3, true));

	final CDateTime date = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
	date.setNullText("<day>");
	date.setPattern("dd");
	date.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

	final CDateTime month = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
	month.setNullText("<month>");
	month.setPattern("MMMM");
	month.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

	final CDateTime year = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
	year.setNullText("<year>");
	year.setPattern("yyyy");
	year.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 10
Source File: FocusTests.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void showSetup1() {
	Display display = new Display();
	Shell shell = new Shell(display);
	doSetUp1(shell);
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	display.dispose();
}
 
Example 11
Source File: InnerTagRender.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
	Display ds = Display.getDefault();
	Shell shell = new Shell(ds);
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!ds.readAndDispatch()) {
			ds.sleep();
		}
	}
}
 
Example 12
Source File: CarouselSnippet.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param args
 */
public static void main(final String[] args) {
	final Display display = new Display();
	shell = new Shell(display);
	shell.setText("Carousel Snippet");
	shell.setLayout(new FillLayout());
	shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

	final Carousel carousel = new Carousel(shell, SWT.NONE);
	carousel.addImage(loadImage("images/first.png"));
	carousel.addImage(loadImage("images/second.jpg"));
	carousel.addImage(loadImage("images/third.png"));

	final Listener listener = event -> {
		System.out.println("Click on " + carousel.getSelection());
	};
	carousel.addListener(SWT.Selection, listener);

	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}

	display.dispose();

}
 
Example 13
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 14
Source File: ExcelExportProgessBar.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void open(int minValue, int maxValue) {
	childShell = new Shell(shell.getDisplay(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
	childShell.setText("Exporting to Excel.. please wait");

	progressBar = new ProgressBar(childShell, SWT.SMOOTH);
	progressBar.setMinimum(minValue);
	progressBar.setMaximum(maxValue);
	progressBar.setBounds(0, 0, 400, 25);
	progressBar.setFocus();

	childShell.pack();
	childShell.open();
}
 
Example 15
Source File: SnippetVScroll.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	Display display = new Display();
	Image itemImage = new Image(display, Program.findProgram("jpg").getImageData()); //$NON-NLS-1$

	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	Gallery gallery = new Gallery(shell, SWT.V_SCROLL | SWT.MULTI);

	// Renderers
	DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
	gr.setMinMargin(10);
	gr.setItemHeight(56);
	gr.setItemWidth(72);
	gr.setAutoMargin(true);
	gallery.setGroupRenderer(gr);

	DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
	gallery.setItemRenderer(ir);

	for (int g = 0; g < 2; g++) {
		GalleryItem group = new GalleryItem(gallery, SWT.NONE);
		group.setText("Really Long Group Name " + g); //$NON-NLS-1$
		group.setExpanded(true);

		for (int i = 0; i < 10; i++) {
			GalleryItem item = new GalleryItem(group, SWT.NONE);
			if (itemImage != null) {
				item.setImage(itemImage);
			}
			item.setText("Item " + i); //$NON-NLS-1$
		}
	}

	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}

	if (itemImage != null)
		itemImage.dispose();
	display.dispose();
}
 
Example 16
Source File: SnippetSimpleListOverlay.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	Display display = new Display();
	Image[] itemImages = {
			new Image(display, Program.findProgram("jpg").getImageData()), //$NON-NLS-1$
			new Image(display, Program.findProgram("mov").getImageData()), //$NON-NLS-1$
			new Image(display, Program.findProgram("mp3").getImageData()), //$NON-NLS-1$
			new Image(display, Program.findProgram("txt").getImageData()) }; //$NON-NLS-1$

	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	Gallery gallery = new Gallery(shell, SWT.V_SCROLL | SWT.MULTI);

	// Renderers
	DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
	gr.setMinMargin(2);
	gr.setItemHeight(82);
	gr.setItemWidth(200);
	gr.setAutoMargin(true);
	gallery.setGroupRenderer(gr);

	ListItemRenderer ir = new ListItemRenderer();
	gallery.setItemRenderer(ir);

	for (int g = 0; g < 2; g++) {
		GalleryItem group = new GalleryItem(gallery, SWT.NONE);
		group.setText("Group " + g); //$NON-NLS-1$
		group.setExpanded(true);

		for (int i = 0; i < 50; i++) {
			GalleryItem item = new GalleryItem(group, SWT.NONE);
			if (itemImages[0] != null) {
				item.setImage(itemImages[0]);
			}
			item.setText("Item " + i); //$NON-NLS-1$
			Image[] over = { itemImages[0] };
			Image[] over2 = { itemImages[1], itemImages[2] };
			Image[] over3 = { itemImages[3] };
			item.setData(AbstractGalleryItemRenderer.OVERLAY_BOTTOM_RIGHT,
					over3);
			item.setData(AbstractGalleryItemRenderer.OVERLAY_BOTTOM_LEFT,
					over);
			item.setData(AbstractGalleryItemRenderer.OVERLAY_TOP_RIGHT,
					over);
			item.setData(AbstractGalleryItemRenderer.OVERLAY_TOP_LEFT,
					over2);

		}
	}

	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}

	for (int i = 0; i < itemImages.length; i++) {
		itemImages[i].dispose();
	}
	
	display.dispose();
}
 
Example 17
Source File: FontAwesomeSnippet2.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(final String[] args) throws IllegalArgumentException, IllegalAccessException {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("FontAwesome Snippet");
	shell.setSize(600, 600);
	shell.setLayout(new GridLayout(1, false));

	// Label
	new Label(shell, SWT.NONE).setText("In Label");
	Label text = new Label(shell, SWT.NONE);
	text.setFont(FontAwesome.getFont(22));
	text.setText(FontAwesome.code);

	// Button
	new Label(shell, SWT.NONE).setText("In Button");
	Composite comp1 = new Composite(shell, SWT.NONE);
	comp1.setLayout(new RowLayout());
	Button button1 = new Button(comp1, SWT.NONE);
	button1.setFont(FontAwesome.getFont(10));
	button1.setText(FontAwesome.plus + " plus");
	Button button2 = new Button(comp1, SWT.NONE);
	button2.setFont(FontAwesome.getFont(10));
	button2.setText(FontAwesome.minus + " minus");

	// Toolbar
	new Label(shell, SWT.NONE).setText("In ToolBar");
	ToolBar toolbar = new ToolBar(shell, SWT.NONE);
	toolbar.setFont(FontAwesome.getFont(15));
	ToolItem item1 = new ToolItem(toolbar, SWT.NONE);
	item1.setText(FontAwesome.align_left);
	ToolItem item2 = new ToolItem(toolbar, SWT.NONE);
	item2.setText(FontAwesome.align_center);
	ToolItem item3 = new ToolItem(toolbar, SWT.NONE);
	item3.setText(FontAwesome.align_right);
	new ToolItem(toolbar, SWT.SEPARATOR);
	ToolItem item4 = new ToolItem(toolbar, SWT.NONE);
	item4.setText(FontAwesome.quote_left);
	new ToolItem(toolbar, SWT.SEPARATOR);
	ToolItem item5 = new ToolItem(toolbar, SWT.NONE);
	item5.setText(FontAwesome.question);

	shell.pack();
	shell.open();

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

}
 
Example 18
Source File: SnippetHover.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	Display display = new Display();
	Image itemImage = new Image(display, Program
			.findProgram("jpg").getImageData()); //$NON-NLS-1$

	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	Gallery gallery = new Gallery(shell, SWT.V_SCROLL | SWT.MULTI);

	// Renderers
	NoGroupRenderer gr = new NoGroupRenderer();
	gr.setMinMargin(2);
	gr.setItemHeight(56);
	gr.setItemWidth(72);
	gr.setAutoMargin(true);
	gallery.setGroupRenderer(gr);

	DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
	gallery.setItemRenderer(ir);

	GalleryItem group = new GalleryItem(gallery, SWT.NONE);

	for (int i = 0; i < 100; i++) {
		GalleryItem item = new GalleryItem(group, SWT.NONE);
		if (itemImage != null) {
			item.setImage(itemImage);
		}
		item.setText("Item " + i); //$NON-NLS-1$
	}

	new HoverListener(gallery, Display.getCurrent().getSystemColor(
			SWT.COLOR_WHITE), Display.getCurrent().getSystemColor(
			SWT.COLOR_CYAN), 500, 5000);

	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}

	if (itemImage != null)
		itemImage.dispose();
	display.dispose();
}
 
Example 19
Source File: TitledSeparatorSnippet.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.setLayout(new GridLayout(1, false));

	final Image icon = new Image(display, TitledSeparatorSnippet.class.getResourceAsStream("user.png"));
	final Font font = new Font(display, "Courier New", 18, SWT.BOLD | SWT.ITALIC);

	// Default separator (no image, title aligned on the left)
	final TitledSeparator sep1 = new TitledSeparator(shell, SWT.NONE);
	sep1.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
	sep1.setText("Customer Info");

	// Separator with image
	final TitledSeparator sep2 = new TitledSeparator(shell, SWT.NONE);
	sep2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
	sep2.setText("Customer Info");
	sep2.setImage(icon);

	// Separator aligned on the right
	final TitledSeparator sep3 = new TitledSeparator(shell, SWT.NONE);
	sep3.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
	sep3.setText("Customer Info");
	sep3.setAlignment(SWT.RIGHT);

	// Custom font & text color
	final TitledSeparator sep4 = new TitledSeparator(shell, SWT.NONE);
	sep4.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
	sep4.setText("Customized Color and Font");
	sep4.setAlignment(SWT.CENTER);

	sep4.setForeground(display.getSystemColor(SWT.COLOR_DARK_RED));
	sep4.setFont(font);

	shell.setSize(640, 350);
	shell.pack();
	shell.open();
	SWTGraphicUtil.centerShell(shell);

	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	icon.dispose();
	font.dispose();

	display.dispose();
}
 
Example 20
Source File: PreferenceWindowSnippet.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param args
 */
public static void main(final String[] args) {

	Locale.setDefault(Locale.ENGLISH);

	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("PreferenceWindow snippet");
	shell.setLayout(new FillLayout(SWT.VERTICAL));

	final Button button1 = new Button(shell, SWT.PUSH);
	button1.setText("Open preference window");

	final Map<String, Object> data = fillData();

	button1.addListener(SWT.Selection, e -> {
		final PreferenceWindow window = PreferenceWindow.create(shell, data);

		createDocumentTab(window);
		createInfoTab(window);
		createTerminalTab(window);
		createPrinterTab(window);
		createSystemTab(window);

		window.setSelectedTab(2);

		window.open();
	});

	shell.pack();
	shell.open();
	SWTGraphicUtil.centerShell(shell);

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

	display.dispose();
}