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

The following examples show how to use org.eclipse.swt.widgets.Display#getDefault() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
public static void aquireAndRun(Identifiable identifiable, ILockHandler handler){
	Display display = Display.getDefault();
	display.syncExec(new Runnable() {
		
		@Override
		public void run(){
			ProgressMonitorDialog progress =
				new ProgressMonitorDialog(display.getActiveShell());
			try {
				progress.run(true, true, new AcquireLockRunnable(identifiable, handler));
			} catch (InvocationTargetException | InterruptedException e) {
				logger.warn("Exception during acquire lock.", e);
			}
		}
	});
}
 
Example 2
public Image getImage(Object element) {		
	if (element instanceof Language) {
		Language lang = (Language) element;
		String code = lang.getCode();
		String imagePath = lang.getImagePath();
		if (imagePath != null && !imagePath.equals("")) {				
			ImageDescriptor imageDesc = Activator.getImageDescriptor(imagePath);
			if (imageDesc != null) {
				ImageData data = imageDesc.getImageData().scaledTo(16, 12);
				Image image = new Image(Display.getDefault(), data);
				
				// 销毁原来的图片
				Image im = imageCache.put(code, image);
				if (im != null && !im.isDisposed()) {
					im.dispose();
				}
				return image;
			}
		}
	}
	return null;
}
 
Example 3
public static void aquireAndRun(Identifiable identifiable, ILockHandler lockhandler){
	Display display = Display.getDefault();
	LockResponse result = LocalLockServiceHolder.get().acquireLock(identifiable);
	if (result.isOk()) {
		
		display.syncExec(new Runnable() {
			@Override
			public void run(){
				lockhandler.lockAcquired();
			}
		});
		LocalLockServiceHolder.get().releaseLock(identifiable);
	} else {
		
		display.syncExec(new Runnable() {
			@Override
			public void run(){
				lockhandler.lockFailed();
				LockResponseHelper.showInfo(result, identifiable, logger);
			}
		});
	}
}
 
Example 4
Source Project: http4e   File: ExportJavaViewer.java    License: Apache License 2.0 6 votes vote down vote up
void initializeColors(){
   Display display = Display.getDefault();
   colors = new Color[] { new Color(display, new RGB(0, 0, 0)), // black
         new Color(display, new RGB(0, 153, 0)), // comment
         new Color(display, new RGB(153, 0, 0)), // string
         new Color(display, new RGB(0, 51, 255)) // reserved words
   };
   tokenColors = new int[MAXIMUM_TOKEN];
   tokenColors[WORD] = 0;
   tokenColors[WHITE] = 0;
   tokenColors[KEY_WORD] = 3;
   tokenColors[COMMENT] = 1;
   tokenColors[STRING] = 2;
   tokenColors[OTHER] = 0;
   tokenColors[NUMBER] = 0;
}
 
Example 5
/**
 * Returns the standard display to be used. The method first checks, if
 * the thread calling this method has an associated display. If so, this
 * display is returned. Otherwise the method returns the default display.
 */
public static Display getStandardDisplay() {
	Display display= Display.getCurrent();
	if (display == null) {
		display= Display.getDefault();
	}
	return display;		
}
 
Example 6
Source Project: nebula   File: SWTGraphicUtil.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param text
 * @return the width of text
 */
public static int computeWidth(final String text) {
	final GC gc = new GC(Display.getDefault());
	final int width = gc.textExtent(text).x;
	gc.dispose();
	return width;
}
 
Example 7
public static void main(String[] args) {
	final Display display = Display.getDefault();
	Realm.runWithDefault(SWTObservables.getRealm(display), 
		new Runnable() {
			public void run() {
				NumberFormatterDataBindingSnippet snippet = new NumberFormatterDataBindingSnippet();
				Shell shell = snippet.createShell();
		    shell.open();
		    while ( ! shell.isDisposed() ) {
		    	if (!display.readAndDispatch()) display.sleep();
		    }
			}
	});
}
 
Example 8
/**
 * Returns the standard display to be used. The method first checks, if the thread calling this method has an
 * associated disaply. If so, this display is returned. Otherwise the method returns the default display.
 */
public static Display getStandardDisplay()
{
	Display display = UIUtils.getDisplay();
	if (display == null)
	{
		display = Display.getCurrent();
	}
	if (display == null)
	{
		display = Display.getDefault();
	}
	return display;
}
 
Example 9
/**
 * 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( ) );

	Regression_78699_swt siv = new Regression_78699_swt(
			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( "Bar 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 10
Source Project: nebula   File: ListItemRenderer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void createColors() {
	if (dropShadowsSize > 0) {
		int step = 125 / dropShadowsSize;
		// Create new colors
		for (int i = dropShadowsSize - 1; i >= 0; i--) {
			int value = 255 - i * step;
			Color c = new Color(Display.getDefault(), value, value, value);
			dropShadowsColors.add(c);
		}
	}
}
 
Example 11
private TextStyle createResultsStyle() {
	background = new Color(Display.getCurrent(), 0x19, 0x19, 0x70);
	foreground = new Color(Display.getCurrent(), 0xff, 0xff, 0xff);
	FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
	fontData.setStyle(fontData.getStyle());
	rsFont = new Font(Display.getDefault(), fontData);
	TextStyle style = new TextStyle(rsFont, foreground, background);
	return style;
}
 
Example 12
protected static Clipboard getClipboard()
{
	Display display = Display.getCurrent();
	if (display == null)
	{
		display = Display.getDefault();
	}
	return new Clipboard(display);
}
 
Example 13
Source Project: statecharts   File: Clock.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public Clock(Composite parent) {
	super(parent, SWT.NONE);
	font = new Font(Display.getDefault(), new FontData(FONT, FONT_SIZE, SWT.NORMAL));
	createContents();
	updateTimestamp(0);
}
 
Example 14
private static Font getTagFont() {
	return new Font(Display.getDefault(), "Arial", 8, SWT.BOLD);
}
 
Example 15
public void testCreateLaunchAndDebugGoogleAppProject() throws Exception {

        final Display display = Display.getDefault();
        final Boolean[] executed = new Boolean[] { false };
        display.syncExec(new Runnable() {

            @Override
            public void run() {
                final Shell shell = new Shell(display);
                shell.setLayout(new FillLayout());
                Composite pageContainer = new Composite(shell, 0);
                AppEngineWizard appEngineWizard = new AppEngineWizard();
                appEngineWizard.setContainer(new IWizardContainer() {

                    @Override
                    public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                            throws InvocationTargetException, InterruptedException {
                        runnable.run(new NullProgressMonitor());
                    }

                    @Override
                    public void updateWindowTitle() {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public void updateTitleBar() {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public void updateMessage() {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public void updateButtons() {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public void showPage(IWizardPage page) {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public Shell getShell() {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public IWizardPage getCurrentPage() {
                        return null;
                    }
                });

                appEngineWizard.init(PlatformUI.getWorkbench(), new StructuredSelection());
                appEngineWizard.addPages();
                appEngineWizard.createPageControls(pageContainer);

                IWizardPage[] pages = appEngineWizard.getPages();
                NewProjectNameAndLocationWizardPage nameAndLocation = (NewProjectNameAndLocationWizardPage) pages[0];
                AppEngineConfigWizardPage appEnginePage = (AppEngineConfigWizardPage) pages[1];

                assertFalse(nameAndLocation.isPageComplete());
                nameAndLocation.setProjectName("AppEngineTest");
                assertTrue(nameAndLocation.isPageComplete());

                assertFalse(appEnginePage.isPageComplete());
                appEnginePage.setAppEngineLocationFieldValue(TestDependent.GOOGLE_APP_ENGINE_LOCATION
                        + "invalid_path_xxx");
                assertFalse(appEnginePage.isPageComplete());
                appEnginePage.setAppEngineLocationFieldValue(TestDependent.GOOGLE_APP_ENGINE_LOCATION);
                assertTrue(appEnginePage.isPageComplete());

                assertTrue(appEngineWizard.performFinish());

                IProject createdProject = appEngineWizard.getCreatedProject();
                PythonNature nature = PythonNature.getPythonNature(createdProject);
                Map<String, String> expected = new HashMap<String, String>();
                expected.put(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE, new File(
                        TestDependent.GOOGLE_APP_ENGINE_LOCATION).getAbsolutePath());
                IPythonPathNature pythonPathNature = nature.getPythonPathNature();
                try {
                    assertEquals(expected, pythonPathNature.getVariableSubstitution());

                    String projectExternalSourcePath = pythonPathNature.getProjectExternalSourcePath(false);
                    assertTrue(projectExternalSourcePath.indexOf(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE) != -1);
                    projectExternalSourcePath = pythonPathNature.getProjectExternalSourcePath(true);
                    assertTrue(projectExternalSourcePath.indexOf(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE) == -1);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }

                //                goToManual();

                executed[0] = true;
            }
        });
        assertTrue(executed[0]);
    }
 
Example 16
public static void main( String args[] )
{
	display = Display.getDefault( );
	Shell shell = new Shell( display );
	shell.setLocation( display.getClientArea( ).width / 2 - 110, display
			.getClientArea( ).height / 2 - 40 );
	shell.setSize( 620, 450 );
	shell.setLayout( new GridLayout( ) );

	Regression_132620_svg siv = new Regression_132620_svg( shell, SWT.NONE );
	GridData gd = new GridData( GridData.BEGINNING );
	gd.widthHint = 1;
	gd.heightHint = 1;
	siv.setLayoutData( gd );

	try
	{
		RunTimeContext rtc = new RunTimeContext( );
		rtc.setULocale( ULocale.getDefault( ) );

		IDeviceRenderer idr = null;
		Chart cm = toggleVisibility_BarChart( );

		idr = PluginSettings.instance( ).getDevice( "dv.SVG" ); //$NON-NLS-1$
		Generator gr = Generator.instance( );
		GeneratedChartState gcs = null;
		Bounds bo = BoundsImpl.create( 0, 0, 450, 300 );
		gcs = gr.build( idr.getDisplayServer( ), cm, bo, null, rtc, null );

		idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, "c:/test.svg" ); //$NON-NLS-1$
		idr.setProperty(
				IDeviceRenderer.UPDATE_NOTIFIER,
				new EmptyUpdateNotifier( cm, gcs.getChartModel( ) ) );

		gr.render( idr, gcs );
	}

	catch ( ChartException ce )
	{
		ce.printStackTrace( );
	}

	Browser br = new Browser( shell, SWT.NONE );
	br.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	br.setUrl( "c:/test.svg" );//$NON-NLS-1$		
	br.setVisible( true );

	shell.open( );
	while ( !shell.isDisposed( ) )
	{
		if ( !display.readAndDispatch( ) )
			display.sleep( );
	}
	display.dispose( );
}
 
Example 17
Source Project: tracecompass   File: NGC.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public IColor createColor(int r, int g, int b) {
    return new ColorImpl(Display.getDefault(), r, g, b);
}
 
Example 18
/**
 * Restores the code assist pop-up's size.
 * 
 * @return the stored size
 * @since 3.0
 */
protected Point restoreCompletionProposalPopupSize()
{
	if (fDialogSettings == null)
	{
		return null;
	}

	Point size = new Point(-1, -1);

	try
	{
		size.x = fDialogSettings.getInt(STORE_SIZE_X);
		size.y = fDialogSettings.getInt(STORE_SIZE_Y);
	}
	catch (NumberFormatException ex)
	{
		size.x = -1;
		size.y = -1;
	}

	// sanity check
	if (size.x == -1 && size.y == -1)
	{
		return null;
	}

	Rectangle maxBounds = null;
	if (fContentAssistSubjectControl != null && !fContentAssistSubjectControl.getControl().isDisposed())
	{
		maxBounds = fContentAssistSubjectControl.getControl().getDisplay().getBounds();
	}
	else
	{
		// fallback
		Display display = Display.getCurrent();
		if (display == null)
		{
			display = Display.getDefault();
		}
		if (display != null && !display.isDisposed())
		{
			maxBounds = display.getBounds();
		}
	}

	if (size.x > -1 && size.y > -1)
	{
		if (maxBounds != null)
		{
			size.x = Math.min(size.x, maxBounds.width);
			size.y = Math.min(size.y, maxBounds.height);
		}

		// Enforce an absolute minimal size
		size.x = Math.max(size.x, 30);
		size.y = Math.max(size.y, 30);
	}

	return size;
}
 
Example 19
public TerminologyViewPart() {
	JFaceResources.getFontRegistry().addListener(fontChangeListener);
	selectedBgColor = new Color(Display.getDefault(), 210, 210, 240);
	tipLabelImage = Activator.getImageDescriptor("images/status/Loading.png").createImage();
}
 
Example 20
Source Project: birt   File: SWTHighlightViewer.java    License: 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( ) );

	SWTHighlightViewer siv = new SWTHighlightViewer(
			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" ); //$NON-NLS-1$
	cbType.add( "Bar Chart" ); //$NON-NLS-1$
	cbType.add( "Line Chart" );//$NON-NLS-1$
	cbType.add( "Meter Chart" );//$NON-NLS-1$
	cbType.add( "Pie Chart" );//$NON-NLS-1$
	cbType.add( "Scatter Chart" );//$NON-NLS-1$
	cbType.add( "Stock Chart" );//$NON-NLS-1$
	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( );
}