Java Code Examples for org.eclipse.swt.widgets.Display#readAndDispatch()

The following examples show how to use org.eclipse.swt.widgets.Display#readAndDispatch() . 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: LEDSnippet.java    From nebula with Eclipse Public License 2.0 6 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("LED Snippet");
	shell.setLayout(new GridLayout(1, true));
	shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

	createTopPart();
	createBottomPart();

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

	display.dispose();

}
 
Example 2
Source File: RichTextEditorExample.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	Display display = new Display();

	final Shell shell = new Shell(display);
	shell.setText("SWT Rich Text Editor example");
	shell.setSize(800, 600);

	shell.setLayout(new GridLayout(1, true));

	RichTextEditorExample example = new RichTextEditorExample();
	example.createControls(shell);

	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 3
Source File: SWTTimeSeriesDemo.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Starting point for the demonstration application.
 *
 * @param args  ignored.
 */
public static void main(String[] args) {
    final JFreeChart chart = createChart(createDataset());
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(600, 300);
    shell.setLayout(new FillLayout());
    shell.setText("Time series demo for jfreechart running with SWT");
    ChartComposite frame = new ChartComposite(shell, SWT.NONE, chart, true);
    frame.setDisplayToolTips(true);
    frame.setHorizontalAxisTrace(false);
    frame.setVerticalAxisTrace(false);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
 
Example 4
Source File: AbstractStyleEditorDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initialize and display the SWT shell. This is a blocking call.
 */
public void open() {
	Shell shell = new Shell(getParent(), getStyle());
	shell.setImage(GUIHelper.getImage("preferences"));
	shell.setText(getText());

	initComponents(shell);
	createButtons(shell);

	shell.pack();
	shell.open();
	Display display = shell.getDisplay();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
}
 
Example 5
Source File: DateFormatterSnippet1.java    From nebula 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 GridLayout());

   Locale.setDefault(Locale.US);
   FormattedText text = new FormattedText(shell, SWT.BORDER);
   text.setFormatter(new DateFormatter());
   GridData data = new GridData();
   data.widthHint = 70;
   text.getControl().setLayoutData(data);

   shell.open();
   while ( ! shell.isDisposed() ) {
   	if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
}
 
Example 6
Source File: IPAddressFormatterSnippet.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new GridLayout());

	final FormattedText text = new FormattedText(shell, SWT.BORDER);
	text.setFormatter(new IPAddressFormatter());
	text.setValue("192.192.92.192");
	GridData data = new GridData();
	data.widthHint = 100;
	text.getControl().setLayoutData(data);

	Button btn = new Button(shell, SWT.PUSH);
	btn.setText("ok");
	btn.addListener(SWT.Selection, new Listener() {
		public void handleEvent(Event e) {
			System.out.println(text.getValue());
		}
	});

	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 7
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 8
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 9
Source File: CDPSnippet01.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("CDatePanel");
	shell.setLayout(new GridLayout());

	final CDatePanel cdp = new CDatePanel(shell, SWT.BORDER);
	cdp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	cdp.setMonthCount(2);
       
	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: 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 11
Source File: ApkInstaller.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Open the dialog.
 * @return the result
 */
public String open() {
	createContents();
	shlApkInstaller.open();
	shlApkInstaller.layout();
	Display display = getParent().getDisplay();
	while (!shlApkInstaller.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	return result;
}
 
Example 12
Source File: BundleCreator.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Open the dialog.
 * @return the result
 */
public Object open() {
	createContents();
	
	shlBundler.open();
	shlBundler.layout();
	Display display = getParent().getDisplay();
	while (!shlBundler.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	return result;
}
 
Example 13
Source File: MultiScope_ScopeWithDataAndProgression2Channels_1.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Launch the application.
 *
 * @param args
 */
public static void main(String[] args) {

	Display display = Display.getDefault();
	createContents();
	shell.open();
	shell.layout();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
}
 
Example 14
Source File: FastbootToolbox.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Open the dialog.
 * @return the result
 */
public Object open() {
	createContents();
	shlFastbootToolbox.open();
	shlFastbootToolbox.layout();
	Display display = getParent().getDisplay();
	while (!shlFastbootToolbox.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	return result;
}
 
Example 15
Source File: CDTSnippet04.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 cdt = new CDateTime(shell, CDT.BORDER | CDT.COMPACT | CDT.SIMPLE);
	cdt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
	cdt.addListener(SWT.DefaultSelection, event -> {
		System.out.println(cdt.getSelection());
	});

	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 16
Source File: SWTURLRedirectViewer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * main() method for constructing the layout.
 * 
 * @param args
 */
public static void main( String[] args )
{
	Display display = Display.getDefault( );
	Shell shell = new Shell( display );
	shell.setSize( 600, 400 );
	shell.setLayout( new GridLayout( ) );

	SWTURLRedirectViewer siv = new SWTURLRedirectViewer(
			shell,
			SWT.NO_BACKGROUND );
	siv.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	siv.addPaintListener( siv );

	Composite cBottom = new Composite( shell, SWT.NONE );
	cBottom.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
	cBottom.setLayout( new RowLayout( ) );

	Label la = new Label( cBottom, SWT.NONE );

	la.setText( "Choose: " );//$NON-NLS-1$
	cbType = new Combo( cBottom, SWT.DROP_DOWN | SWT.READ_ONLY );
	cbType.add( "Area Chart" );
	cbType.add( "Bar Chart" );
	cbType.add( "Line Chart" );
	cbType.add( "Meter Chart" );
	cbType.add( "Pie Chart" );
	cbType.add( "Scatter Chart" );
	cbType.add( "Stock Chart" );
	cbType.select( 0 );

	btn = new Button( cBottom, SWT.NONE );
	btn.setText( "Update" );//$NON-NLS-1$
	btn.addSelectionListener( siv );

	shell.open( );
	while ( !shell.isDisposed( ) )
	{
		if ( !display.readAndDispatch( ) )
			display.sleep( );
	}
	display.dispose( );
}
 
Example 17
Source File: SnippetSimpleOverlay.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(106);
	gr.setItemWidth(82);
	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("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 18
Source File: ProgressBarExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	final Shell shell = new Shell();
	shell.setSize(300, 120);
    shell.open();
    
    //use LightweightSystem to create the bridge between SWT and draw2D
	final LightweightSystem lws = new LightweightSystem(shell);		
	
	//Create Gauge
	final ProgressBarFigure progressBarFigure = new ProgressBarFigure();
	
	//Init gauge
	progressBarFigure.setFillColor(
			XYGraphMediaFactory.getInstance().getColor(0, 255, 0));
			
	progressBarFigure.setRange(-100, 100);
	progressBarFigure.setLoLevel(-50);
	progressBarFigure.setLoloLevel(-80);
	progressBarFigure.setHiLevel(60);
	progressBarFigure.setHihiLevel(80);
	progressBarFigure.setMajorTickMarkStepHint(50);
	progressBarFigure.setHorizontal(true);
	progressBarFigure.setOriginIgnored(true);
	
	lws.setContents(progressBarFigure);		
	
	//Update the gauge in another thread.
	ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
	ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(new Runnable() {
		
		@Override
		public void run() {
			Display.getDefault().asyncExec(new Runnable() {					
				@Override
				public void run() {
					progressBarFigure.setValue(Math.sin(counter++/10.0)*100);						
				}
			});
		}
	}, 100, 100, TimeUnit.MILLISECONDS);		
	
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    future.cancel(true);
    scheduler.shutdown();
   
}
 
Example 19
Source File: GanttTester.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public GanttTester() {
    final Display display = Display.getDefault(); //new Display();
    final Monitor m = display.getMonitors()[0];
    final Shell shell = new Shell(display);
    shell.setText("GanttChart Test Application");
    shell.setLayout(new FillLayout());

    final SashForm sfVSplit = new SashForm(shell, SWT.VERTICAL);
    final SashForm sfHSplit = new SashForm(sfVSplit, SWT.HORIZONTAL);

    final ViewForm vfBottom = new ViewForm(sfVSplit, SWT.NONE);
    _vfChart = new ViewForm(sfHSplit, SWT.NONE);
    final ViewForm rightForm = new ViewForm(sfHSplit, SWT.NONE);

    final ScrolledComposite sc = new ScrolledComposite(rightForm, SWT.V_SCROLL | SWT.H_SCROLL);
    rightForm.setContent(sc);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    sc.getVerticalBar().setPageIncrement(150);

    final Composite rightComposite = new Composite(sc, SWT.NONE);
    final GridLayout gl = new GridLayout();
    gl.marginLeft = 0;
    gl.marginTop = 0;
    gl.horizontalSpacing = 0;
    gl.verticalSpacing = 0;
    gl.marginBottom = 0;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    rightComposite.setLayout(gl);

    sc.setContent(rightComposite);

    rightComposite.addListener(SWT.Resize, new Listener() {

        public void handleEvent(final Event event) {
            sc.setMinSize(rightComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        }

    });

    sfVSplit.setWeights(new int[] { 91, 9 });
    sfHSplit.setWeights(new int[] { 70, 30 });

    // top left side
    _ganttChart = new GanttChart(_vfChart, SWT.MULTI);
    _vfChart.setContent(_ganttChart);
    _ganttComposite = _ganttChart.getGanttComposite();

    final TabFolder tfRight = new TabFolder(rightComposite, SWT.BORDER);
    final TabItem tiGeneral = new TabItem(tfRight, SWT.NONE);
    tiGeneral.setText("Creation");

    final TabItem tiAdvanced = new TabItem(tfRight, SWT.NONE);
    tiAdvanced.setText("Advanced");

    final TabItem tiEventLog = new TabItem(tfRight, SWT.NONE);
    tiEventLog.setText("Event Log");

    final Composite bottom = new Composite(rightComposite, SWT.NONE);
    bottom.setLayout(new GridLayout());
    createCreateButtons(bottom);

    vfBottom.setContent(createBottom(vfBottom));
    tiGeneral.setControl(createCreationTab(tfRight)); // NOPMD
    tiAdvanced.setControl(createAdvancedTab(tfRight));
    tiEventLog.setControl(createEventLogTab(tfRight));

    shell.setMaximized(true);
    // uncomment to put on right-hand-side monitor
    shell.setLocation(new Point(m.getClientArea().x, 0));

    sc.setMinSize(rightComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.removeListener(SWT.KeyDown, _undoRedoListener);

    shell.dispose();
}
 
Example 20
Source File: IngresVectorwiseLoaderDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see org.pentaho.di.trans.step.StepDialogInterface#open()
 */
public String open() {
  shell = new Shell( getParent(), SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX );
  props.setLook( shell );

  setShellImage( shell, input );

  changed = input.hasChanged();

  FormLayout formLayout = new FormLayout();
  formLayout.marginWidth = Const.FORM_MARGIN;
  formLayout.marginHeight = Const.FORM_MARGIN;

  shell.setLayout( formLayout );
  shell.setText( BaseMessages.getString( PKG, "IngresVectorwiseLoaderDialog.Shell.Title" ));

  middle = props.getMiddlePct();
  margin = Const.MARGIN;

  /************************************** Step name line ***************************/
  // label
  wlStepname = new Label( shell, SWT.RIGHT );
  wlStepname.setText( "Step Name" );
  wlStepname.setLayoutData( standardLabelSpacing( null, null ) );
  props.setLook( wlStepname );

  // text entry
  wStepname = new Text( shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER );
  wStepname.setText( stepname );
  wStepname.addModifyListener( lsMod );
  wStepname.setLayoutData( standardInputSpacing( null, wlStepname ) );
  props.setLook( wStepname );

  Control lastControl = addDbConnectionInputs();
  lastControl = addCustomInputs( lastControl );

  addVerticalPadding( 2 * margin );

  /********************************** OK and Cancel buttons **************************/
  addDefaultButtons( margin, lastControl );

  lastControl = addFieldSelection( lastControl );

  getData();
  input.setChanged( changed );

  // Add listeners
  // Listener lsVisualize = new Listener() { public void handleEvent(Event e) { quickVisualize(); } };

  // wVisualize.addListener(SWT.Selection, lsVisualize );

  shell.open();
  while ( !shell.isDisposed() ) {
    Display display = getParent().getDisplay();

    if ( !display.readAndDispatch() ) {
      display.sleep();
    }
  }
  return stepname;
}