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

The following examples show how to use org.eclipse.swt.widgets.Shell#setBackground() . 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: GridToolTip.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
   * Creates an inplace tooltip.
   *
   * @param parent parent control.
   */
  public GridToolTip(final Control parent)
  {
      super(parent, SWT.NONE);

      shell = new Shell(parent.getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
      shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
      shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));

      parent.addListener(SWT.Dispose, new Listener()
      {
	public void handleEvent(Event arg0)
	{
		shell.dispose();
		dispose();
	}
});

      shell.addListener(SWT.Paint, new Listener()
      {
          public void handleEvent(Event e)
          {
              onPaint(e.gc);
          }
      });
  }
 
Example 2
Source File: AbstractContainmentExample.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 *
 */
public AbstractContainmentExample(String title) {
	Display display = new Display();
	shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
	shell.setText(title);
	shell.setBounds(0, 0, 640, 480);
	shell.setBackground(
			Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

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

	controllableShape1 = createControllableShape1(shell);
	controllableShape2 = createControllableShape2(shell);

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

	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
}
 
Example 3
Source File: ToolTipHandler.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new tooltip handler
 *
 * @param parent the parent Shell
 */
public ToolTipHandler(Shell parent) {
    final Display display = parent.getDisplay();
    this.parentShell = parent;

    tipShell = new Shell(parent, SWT.ON_TOP | SWT.TOOL);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    gridLayout.marginWidth = 2;
    gridLayout.marginHeight = 2;
    tipShell.setLayout(gridLayout);

    tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));

    tipLabelImage = new Label(tipShell, SWT.NONE);
    tipLabelImage.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    tipLabelImage.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    tipLabelImage.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));

    tipLabelText = new Label(tipShell, SWT.NONE);
    tipLabelText.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    tipLabelText.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    tipLabelText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
}
 
Example 4
Source File: ProgressCircleSnippet.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setLayout(new GridLayout(3, true));
	final Color white = display.getSystemColor(SWT.COLOR_WHITE);
	shell.setBackground(white);

	new PercentagePanel(shell);
	new AbsolutePanel(shell);
	new TimePanel(shell);

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

	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	display.dispose();
}
 
Example 5
Source File: BadgedLabelSnippet.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("BadgedLabel Snippet");
	shell.setLayout(new GridLayout(5, false));
	shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

	icon = new Image(display, BadgedLabelSnippet.class.getClassLoader()
			.getResourceAsStream("org/eclipse/nebula/widgets/badgedlabel/user.png"));

	createButtons("Blue :", SWT.COLOR_BLUE, SWT.TOP | SWT.LEFT);
	createButtons("Grey:", SWT.COLOR_GRAY, SWT.TOP | SWT.RIGHT);
	createButtons("Green:", SWT.COLOR_GREEN, SWT.BOTTOM | SWT.LEFT);
	createButtons("Red:", SWT.COLOR_RED, SWT.BOTTOM | SWT.RIGHT);
	createButtons("Yellow:", SWT.COLOR_YELLOW, SWT.TOP | SWT.RIGHT);
	createButtons("Cyan:", SWT.COLOR_CYAN, SWT.TOP | SWT.LEFT);
	createButtons("Black:", SWT.COLOR_BLACK, SWT.BOTTOM | SWT.RIGHT);

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

	icon.dispose();
	display.dispose();

}
 
Example 6
Source File: AbstractIntersectionExample.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 *
 */
public AbstractIntersectionExample(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());
	shell.setBackground(
			Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

	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.open();

	controllableShape1 = createControllableShape1(shell);
	controllableShape2 = createControllableShape2(shell);

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

	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
}
 
Example 7
Source File: SimpleMessageDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Overridden to make the shell background white.
 *
 * @param shell
 */
@Override
protected void configureShell( Shell shell ) {
  super.configureShell( shell );
  shell.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_WHITE ) );
  shell.setBackgroundMode( SWT.INHERIT_FORCE );
}
 
Example 8
Source File: TexInformationControl.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
public TexInformationControl(TexEditor editor, Shell container) {
    this.editor = editor;
    document = editor.getTexDocument();
    refMana = editor.getDocumentModel().getRefMana();
    shell = new Shell(container, SWT.NO_FOCUS | SWT.ON_TOP | SWT.MODELESS);
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 3;
    layout.marginWidth = 3;
    shell.setLayout(layout);
    display = shell.getDisplay();
    shell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
}
 
Example 9
Source File: WorkaroundForIssue1353.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private static void createShell() {
	DEBUG.OUT("Shell created");
	shell = new Shell(WorkbenchHelper.getShell(), SWT.APPLICATION_MODAL);
	shell.setSize(5, 5);
	shell.setAlpha(0);
	shell.setBackground(IGamaColors.BLACK.color());
}
 
Example 10
Source File: DisplayOverlay.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
protected void createPopupControl() {
	// overall panel
	final Shell top = getPopup();
	final GridLayout layout = new GridLayout(3, true);
	layout.horizontalSpacing = 0;
	layout.verticalSpacing = 0;
	layout.marginWidth = 5;
	layout.marginHeight = 5;
	top.setLayout(layout);
	top.setBackground(IGamaColors.BLACK.color());
	if (createExtraInfo) {
		// left overlay info
		left = label(top, SWT.LEFT);
		// center overlay info
		center = label(top, SWT.CENTER);
		// right overlay info
		right = label(top, SWT.RIGHT);
	}
	// coordinates overlay info
	coord = label(top, SWT.LEFT);
	// zoom overlay info
	zoom = label(top, SWT.CENTER);
	// scalebar overlay info
	scalebar = new Canvas(top, SWT.None);
	scalebar.setVisible(true);
	final GridData scaleData = new GridData(SWT.RIGHT, SWT.CENTER, true, false);
	scaleData.minimumWidth = 140;
	scaleData.widthHint = 140;
	scaleData.minimumHeight = 24;
	scaleData.heightHint = 24;
	scalebar.setLayoutData(scaleData);
	scalebar.setBackground(IGamaColors.BLACK.color());
	scalebar.addPaintListener(e -> paintScale(e.gc));
	top.addMouseListener(toggleListener);
	scalebar.addMouseListener(toggleListener);
	top.layout();
}
 
Example 11
Source File: SimpleMessageDialog.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Overridden to make the shell background white.
 *
 * @param shell
 */
@Override
protected void configureShell( Shell shell ) {
  super.configureShell( shell );
  shell.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_WHITE ) );
  shell.setBackgroundMode( SWT.INHERIT_FORCE );
}
 
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: 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 14
Source File: DisplayOverlay.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public DisplayOverlay(final LayeredDisplayView view, final Composite c,
		final IOverlayProvider<OverlayInfo> provider) {
	this.createExtraInfo = provider != null;
	this.view = view;
	final IPartService ps = ((IWorkbenchPart) view).getSite().getService(IPartService.class);
	ps.addPartListener(pl2);
	referenceComposite = c;
	// parentShell = c.getShell();
	popup = new Shell(c.getShell(), SWT.NO_TRIM | SWT.NO_FOCUS);
	popup.setAlpha(140);
	final FillLayout layout = new FillLayout();
	layout.type = SWT.VERTICAL;
	layout.spacing = 10;
	popup.setLayout(layout);
	popup.setBackground(IGamaColors.BLACK.color());
	createPopupControl();
	popup.setAlpha(140);
	popup.layout();
	c.getShell().addShellListener(listener);
	// parentShell.addControlListener(listener);
	c.addControlListener(listener);
	if (provider != null) {
		provider.setTarget(new ThreadedOverlayUpdater(this), view.getDisplaySurface());
	}
	// if (GamaPreferences.Displays.CORE_SHOW_FPS.getValue()) {
	timer.schedule(new FPSTask(), 0, 1000);
	// }
}
 
Example 15
Source File: SetToolTipImage.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
/**
 * Create contents of the window.
 */
protected void createContents() {
	shell = new Shell(SWT.NO_TRIM | SWT.ON_TOP);
	shell.setSize(width, height);
	shell.setBackground(display.getSystemColor(SWT.COLOR_DARK_MAGENTA));
	shell.setLayoutData(new GridData(GridData.FILL_BOTH));
	shell.setLayout(new GridLayout(1, true));
	
	//shell.setText("SWT Application");
	picture = new Label(shell,SWT.NULL);
	picture.setLayoutData(new GridData(GridData.FILL_BOTH));
	setImage();

}
 
Example 16
Source File: SnippetGalleryViewerTester.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public SnippetGalleryViewerTester() {
	// Initialize the containing Shell
	Display display = new Display();
	shell = new Shell(display);
	shell.setSize(WIDTH, HEIGHT);
	shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
	GridLayoutFactory.fillDefaults().applyTo(shell);

	GalleryTreeViewer viewer = new GalleryTreeViewer(shell);
	GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getGallery());
	viewer.setContentProvider(new GalleryTestContentProvider());
	viewer.setLabelProvider(new GalleryTestLabelProvider());
	viewer.setComparator(new ViewerComparator());
	// viewer.addFilter(new OddNumbersFilter());
	viewer.setInput(new Object());

	// Show the Shell
	shell.open();
	shell.layout();

	// Run the event loop
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 17
Source File: DiagramToolTip.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create a new tooltip for the given parent control
 *
 * @param parent the parent control.
 */
public DiagramToolTip(Control parent) {
    fParent = parent;
    fToolTipShell = new Shell(fParent.getShell(), SWT.MULTI);
    fToolTipShell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    fTextBox = new Text(fToolTipShell, SWT.WRAP | SWT.MULTI);
    fTextBox.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
}
 
Example 18
Source File: PasswordRevealerSnippet.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
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 Color white = display.getSystemColor(SWT.COLOR_WHITE);
	shell.setBackground(white);
	shell.setText("Password Revealer Snippet");

	final Image image = new Image(display, PasswordRevealerSnippet.class.getResourceAsStream("eye.png"));
	final Image clickImage = new Image(display, PasswordRevealerSnippet.class.getResourceAsStream("eye-slash.png"));
	shell.addListener(SWT.Dispose, e -> {
		image.dispose();
		clickImage.dispose();
	});

	final Label lbl1 = new Label(shell, SWT.NONE);
	lbl1.setText("Password Revealer:");
	final GridData gdLabel1 = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
	gdLabel1.widthHint = 150;
	lbl1.setBackground(white);
	lbl1.setLayoutData(gdLabel1);

	final PasswordRevealer revealer = new PasswordRevealer(shell, SWT.NONE);
	final GridData gd = new GridData(GridData.FILL, GridData.CENTER, true, false);
	gd.widthHint = 250;
	revealer.setLayoutData(gd);
	revealer.setBackground(white);

	new Label(shell, SWT.NONE);

	final Label lbl2 = new Label(shell, SWT.NONE);
	lbl2.setText("Password Revealer with other icon:");
	final GridData gdLabel2 = new GridData(GridData.FILL, GridData.CENTER, true, false);
	gdLabel2.widthHint = 150;
	lbl2.setBackground(white);
	lbl2.setLayoutData(gdLabel2);

	final PasswordRevealer revealer2 = new PasswordRevealer(shell, SWT.NONE);
	final GridData gd2 = new GridData(GridData.FILL, GridData.CENTER, true, false);
	gd2.widthHint = 250;
	revealer2.setLayoutData(gd2);
	revealer2.setBackground(white);
	revealer2.setImage(image);
	revealer2.setClickImage(clickImage);

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

	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	display.dispose();
}
 
Example 19
Source File: AnnotationExpansionControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
	 * Creates a new control.
	 *
	 * @param parent parent shell
	 * @param shellStyle additional style flags
	 * @param access the annotation access
	 */
	public AnnotationExpansionControl(Shell parent, int shellStyle, IAnnotationAccess access) {
		fPaintListener= new MyPaintListener();
		fMouseTrackListener= new MyMouseTrackListener();
		fMouseListener= new MyMouseListener();
		fMenuDetectListener= new MyMenuDetectListener();
		fDisposeListener= new MyDisposeListener();
		fViewportListener= new IViewportListener() {

			public void viewportChanged(int verticalOffset) {
				dispose();
			}

		};
		fLayouter= new LinearLayouter();

		if (access instanceof IAnnotationAccessExtension)
			fAnnotationAccessExtension= (IAnnotationAccessExtension) access;

		fShell= new Shell(parent, shellStyle | SWT.NO_FOCUS | SWT.ON_TOP);
		Display display= fShell.getDisplay();
		fShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
		fComposite= new Composite(fShell, SWT.NO_FOCUS | SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM);
//		fComposite= new Composite(fShell, SWT.NO_FOCUS | SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM | SWT.V_SCROLL);

		GridLayout layout= new GridLayout(1, true);
		layout.marginHeight= 0;
		layout.marginWidth= 0;
		fShell.setLayout(layout);

		GridData data= new GridData(GridData.FILL_BOTH);
		data.heightHint= fLayouter.getAnnotationSize() + 2 * fLayouter.getBorderWidth() + 4;
		fComposite.setLayoutData(data);
		fComposite.addMouseTrackListener(new MouseTrackAdapter() {

			@Override
			public void mouseExit(MouseEvent e) {
				if (fComposite == null)
						return;
				Control[] children= fComposite.getChildren();
				Rectangle bounds= null;
				for (int i= 0; i < children.length; i++) {
					if (bounds == null)
						bounds= children[i].getBounds();
					else
						bounds.add(children[i].getBounds());
					if (bounds.contains(e.x, e.y))
						return;
				}

				// if none of the children contains the event, we leave the popup
				dispose();
			}

		});

//		fComposite.getVerticalBar().addListener(SWT.Selection, new Listener() {
//
//			public void handleEvent(Event event) {
//				Rectangle bounds= fShell.getBounds();
//				int x= bounds.x - fLayouter.getAnnotationSize() - fLayouter.getBorderWidth();
//				int y= bounds.y;
//				fShell.setBounds(x, y, bounds.width, bounds.height);
//			}
//
//		});

		Cursor handCursor= getHandCursor(display);
		fShell.setCursor(handCursor);
		fComposite.setCursor(handCursor);

		setInfoSystemColor();
	}
 
Example 20
Source File: Bug385585.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {

		// get display.
		Display display = new Display();

		// create a new visible shell.
		final Shell shell = new Shell(display);
		shell.setText("Test");
		shell.setSize(600, 400);
		GridLayoutFactory.swtDefaults().numColumns(2).applyTo(shell);

		Button button = new Button(shell, SWT.PUSH);
		button.setText("Click me");
		GridDataFactory.fillDefaults().grab(false, false).applyTo(button);

		final Label label = new Label(shell, SWT.NONE);
		label.setText("Combo will appear here");
		GridDataFactory.fillDefaults().grab(true, false).applyTo(label);

		// create a new "background" shell
		Shell limbo = new Shell(display, SWT.NONE);
		limbo.setLocation(0, 10000);
		limbo.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
		limbo.setBackgroundMode(SWT.INHERIT_FORCE);
		GridLayoutFactory.swtDefaults().numColumns(2).applyTo(limbo);

		final TableComboViewer comboViewer = new TableComboViewer(limbo);
		GridDataFactory.fillDefaults().grab(true, false).applyTo(comboViewer.getControl());
		comboViewer.getTableCombo().defineColumns(1);
		comboViewer.setContentProvider(ArrayContentProvider.getInstance());
		comboViewer.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				return (String) element;
			}
		});
		comboViewer.setInput(Arrays.asList("One", "Two", "Three"));

		// move combo
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				label.dispose();
				comboViewer.getTableCombo().setParent(shell);
				shell.layout(true);
			}
		});

		// open the shell.
		shell.open();

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

		// dispose display
		display.dispose();
	}