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

The following examples show how to use org.eclipse.swt.widgets.Display#sleep() . 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: TableExample.java    From translationstudio8 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 2
Source File: JFaceViewerIntegrationExample.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("Rich Text Editor JFace viewer integration example");
	shell.setSize(800, 600);

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

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

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

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

	display.dispose();

}
 
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: MultiLineListExample.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public MultiLineListExample(IJaretTableModel tableModel) {
    _tableModel = tableModel;
    _shell = new Shell(Display.getCurrent());
    _shell.setText("jaret table multilinelist");
    createControls();
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(280, 400);

    /*
     * 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: ResultMessage.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Launch the application.
 * @param args
 */
public static void main(String args[]) {
	try {
		Display display = Display.getDefault();
		ResultMessage shell = new ResultMessage(display, "");
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 7
Source File: SWTTimeSeriesDemo.java    From openstock with GNU General Public License v3.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 8
Source File: BrowserEnvironmentWarningDialog.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * showWarningDialog
 * <p>
 * Shows a SWT dialog warning the user that something is wrong with the browser environment.
 *
 * @param title        the title on the top of the window.
 * @param message      the message at the center of the screen.
 * @param helpLink     a string that contains a hyperlink to a help web page.
 * @param maxTextWidth the width for the text inside the dialog.
 */
private void showWarningDialog( String title, String message, String helpLink, EnvironmentCase environment,
                                int maxTextWidth ) {
  if ( this.getParent().isDisposed() ) {
    return;
  }

  this.props = PropsUi.getInstance();
  Display display = this.getParent().getDisplay();
  shell = new Shell( this.getParent(), SWT.TITLE | SWT.APPLICATION_MODAL );
  props.setLook( shell );

  FormLayout formLayout = new FormLayout();
  formLayout.marginWidth = margin;
  formLayout.marginHeight = margin;
  shell.setLayout( formLayout ); // setting layout

  shell.setText( title ); //setting title of the window
  setWarningIcon( display ); //adding icon
  setWarningText( message, maxTextWidth ); //adding text
  setHelpLink( display, helpLink, maxTextWidth, environment ); //adding link
  setCloseButton(); //adding button

  shell.setSize( shell.computeSize( SWT.DEFAULT, SWT.DEFAULT, true ) );
  Rectangle screenSize = display.getPrimaryMonitor().getBounds();
  shell.setLocation( ( screenSize.width - shell.getBounds().width ) / 2, ( screenSize.height - shell.getBounds().height ) / 2 );
  closeButton.setFocus();
  shell.open();
  while ( !shell.isDisposed() ) {
    if ( !display.readAndDispatch() ) {
      display.sleep();
    }
  }
}
 
Example 9
Source File: MonthCalendarSnippet.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
    Display display = Display.getDefault();
    MonthCalendarSnippet thisClass = new MonthCalendarSnippet();
    thisClass.createSShell();
    thisClass.sShell.open();

    while (!thisClass.sShell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
 
Example 10
Source File: AboutDialog.java    From Rel with Apache License 2.0 5 votes vote down vote up
/**
 * Open the dialog.
 */
public void open() {
	createContents();
	shell.open();
	shell.layout();
	Display display = getParent().getDisplay();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
}
 
Example 11
Source File: ActionCopyFilesDialog.java    From hop with Apache License 2.0 5 votes vote down vote up
@Override
public IAction open() {
  initUI();
  BaseTransformDialog.setSize( shell );
  shell.open();
  Display display = getParent().getDisplay();
  while ( !shell.isDisposed() ) {
    if ( !display.readAndDispatch() ) {
      display.sleep();
    }
  }
  return action;
}
 
Example 12
Source File: Snippet7.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) {
	final Display display = Display.getDefault();

	Shell shell = new UI(display).createShell();
	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	display.dispose();
}
 
Example 13
Source File: SimpleChatUI.java    From jReto with MIT License 5 votes vote down vote up
/**
 * Open the window.
 */
public void open() {
	Display display = Display.getDefault();
	createContents();
	chatPeer = new LocalChatPeer(SimpleChatUI.this, swtExecutor);

	shlSimpleChatExample.open();
	shlSimpleChatExample.layout();
	while (!shlSimpleChatExample.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
}
 
Example 14
Source File: RootPackageSelector.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();
	shell.open();
	shell.layout();
	Display display = getParent().getDisplay();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	return result;
}
 
Example 15
Source File: SWTToggleVisibilityViewer.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( ) );

	SWTToggleVisibilityViewer siv = new SWTToggleVisibilityViewer(
			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 16
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 17
Source File: InfobrightLoaderDialog.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, (StepMetaInterface) 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, "InfobrightLoaderDialog.Shell.Title" ) );

  middle = props.getMiddlePct();

  int margin = Const.MARGIN;

  /************************************** Step name line ***************************/
  // label
  wlStepname = new Label( shell, SWT.RIGHT );
  wlStepname.setText( BaseMessages.getString( PKG, "InfobrightLoaderDialog.Stepname.Label" ) );
  wlStepname.setLayoutData( standardLabelSpacing( 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 ) );
  props.setLook( wStepname );

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

  addVerticalPadding( 2 * margin );

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

  getData();
  input.setChanged( changed );

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

    if ( !display.readAndDispatch() ) {
      display.sleep();
    }
  }
  return stepname;
}
 
Example 18
Source File: GridPrintCellClippingAllowClipFirstRow.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	final Display display = new Display();

	final Shell shell = new Shell(display, SWT.SHELL_TRIM);
	shell.setLayout(new GridLayout());
	shell.setSize(600, 600);

	final PrintJob job = new PrintJob(
			"GridPrintCellClippingAllowClipFirstRow", createPrint());

	Composite buttons = new Composite(shell, SWT.NONE);
	buttons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
	buttons.setLayout(new RowLayout(SWT.HORIZONTAL));

	final Button prev = new Button(buttons, SWT.PUSH);
	prev.setText("<< Prev");
	prev.setEnabled(false);

	final Button next = new Button(buttons, SWT.PUSH);
	next.setText("Next >>");

	final Button print = new Button(buttons, SWT.PUSH);
	print.setText("Print..");

	final PrintPreview preview = new PrintPreview(shell, SWT.BORDER);
	preview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	preview.setPrintJob(job);
	next.setEnabled(preview.getPageCount() > 1);

	Listener listener = event -> {
		int newIndex = preview.getPageIndex();
		if (event.widget == prev)
			newIndex--;
		else
			newIndex++;
		preview.setPageIndex(newIndex);
		prev.setEnabled(newIndex > 0);
		next.setEnabled(newIndex < preview.getPageCount() - 1);
	};
	prev.addListener(SWT.Selection, listener);
	next.addListener(SWT.Selection, listener);

	print.addListener(SWT.Selection, event -> {
		PrinterData printerData = new PrintDialog(shell).open();
		if (printerData != null) {
			PaperClips.print(job, printerData);
		}
	});

	shell.open();

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();
}
 
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: MeterExample.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, 150);
    shell.open();
    
    //use LightweightSystem to create the bridge between SWT and draw2D
	final LightweightSystem lws = new LightweightSystem(shell);		
	
	//Create Gauge
	final MeterFigure meterFigure = new MeterFigure();
	
	//Init gauge
	meterFigure.setBackgroundColor(
			XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
	
	meterFigure.setBorder(new SchemeBorder(SchemeBorder.SCHEMES.ETCHED));
	
	meterFigure.setRange(-100, 100);
	meterFigure.setLoLevel(-50);
	meterFigure.setLoloLevel(-80);
	meterFigure.setHiLevel(60);
	meterFigure.setHihiLevel(80);
	meterFigure.setMajorTickMarkStepHint(50);
	
	lws.setContents(meterFigure);		
	
	//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() {
					meterFigure.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();
   
}