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

The following examples show how to use org.eclipse.swt.widgets.Display#getDefault() . 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: AcquireLockBlockingUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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
Source File: LanguageLabelProvider.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: AcquireLockUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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 File: ExportJavaViewer.java    From http4e with 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
Source File: Utils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 File: SWTGraphicUtil.java    From nebula with 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
Source File: CommandExecutionUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected static Clipboard getClipboard()
{
	Display display = Display.getCurrent();
	if (display == null)
	{
		display = Display.getDefault();
	}
	return new Clipboard(display);
}
 
Example 8
Source File: NumberFormatterDataBindingSnippet.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
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 9
Source File: SWTUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 10
Source File: Regression_78699_swt.java    From birt with Eclipse Public License 1.0 5 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( ) );

	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 11
Source File: ListItemRenderer.java    From nebula with 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 12
Source File: ConcordanceSearchDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
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 13
Source File: SWTHighlightViewer.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( ) );

	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( );
}
 
Example 14
Source File: TerminologyViewPart.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public TerminologyViewPart() {
	JFaceResources.getFontRegistry().addListener(fontChangeListener);
	selectedBgColor = new Color(Display.getDefault(), 210, 210, 240);
	tipLabelImage = Activator.getImageDescriptor("images/status/Loading.png").createImage();
}
 
Example 15
Source File: ContentAssistant.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 16
Source File: NGC.java    From tracecompass with 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 17
Source File: Regression_132620_svg.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
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 18
Source File: AppEngineConfigWizardPageTestWorkbench.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
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 19
Source File: InnerTagUtil.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
private static Font getTagFont() {
	return new Font(Display.getDefault(), "Arial", 8, SWT.BOLD);
}
 
Example 20
Source File: Clock.java    From statecharts with 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);
}