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

The following examples show how to use org.eclipse.swt.widgets.Display#addFilter() . 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: SwtPlugin.java    From jframe with Apache License 2.0 6 votes vote down vote up
public void run() {
    try {
        Display display = Display.getCurrent();
        if (display == null)
            display = Display.getDefault();
        display.addFilter(SWT.Close, new Listener() {
            public void handleEvent(Event event) {
                event.doit = false;
            }
        });
        app = new JframeApp(display, SWT.SHELL_TRIM);
        Shell shell = app.getShell();
        shell.open();

        // shell.pack();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        if (!app.isDisposed())
            app.dispose();
        display.dispose();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e.fillInStackTrace());
    }
}
 
Example 2
Source File: SWTTestUtils.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
public static void runSWTEventLoopUntilBreak() {
	Display display = Display.getCurrent();
	
	final boolean[] breakLoopFlag = new boolean[1];
	
	display.addFilter(SWT.KeyDown, new Listener() {
		@Override
		public void handleEvent(Event event) {
			System.out.println("" + event.button + "--" + event.character  + " :: " + event.keyCode);
			if(event.keyCode == SWT.PAUSE) {
				breakLoopFlag[0] = true;
			}
		}
	});
	
	while(breakLoopFlag[0] == false) {
		if(!display.readAndDispatch())
			display.sleep();
	}
}
 
Example 3
Source File: MainView.java    From Universal-FE-Randomizer with MIT License 5 votes vote down vote up
public MainView(Display mainDisplay) {
	super();
	
	Shell shell = new Shell(mainDisplay, SWT.SHELL_TRIM & ~SWT.MAX); 
	 shell.setText("Yune: A Universal Fire Emblem Randomizer (v0.9.1)");
	 shell.setImage(new Image(mainDisplay, Main.class.getClassLoader().getResourceAsStream("YuneIcon.png")));
	 
	 screenHeight = mainDisplay.getBounds().height;
	 for (Monitor monitor : mainDisplay.getMonitors()) {
		 screenHeight = Math.max(screenHeight, monitor.getClientArea().height);
	 }
	 
	 screenHeight -= 20;
	 
	 mainShell = shell;
	 
	 setupMainShell();
	 
	 resize();
	 
	 /* Open shell window */
	  mainShell.open();
	  
	  mainDisplay.addFilter(SWT.KeyDown, new Listener() {
		@Override
		public void handleEvent(Event event) {
			if (((event.stateMask & SWT.CTRL) != 0) && ((event.stateMask & SWT.SHIFT) != 0) && (event.keyCode == 'c') && !consoleShellOpened) {
				openConsole();
			}
		}
	  });
}
 
Example 4
Source File: DateChooser.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handles the focus.
 *
 * @param mode SWT.FocusIn or SWT.FocusOut
 */
private void handleFocus(int mode) {
	switch (mode) {
		case SWT.FocusIn: {
			if (hasFocus) {
				return;
			}
			hasFocus = true;
			final Display display = getDisplay();
			display.removeFilter(SWT.KeyDown, filter);
			display.removeFilter(SWT.FocusIn, filter);
			if (focusIndex < 0) {
				setFocus(NOFOCUS);
			}
			notifyListeners(SWT.FocusIn, new Event());
			display.addFilter(SWT.FocusIn, filter);
			display.addFilter(SWT.KeyDown, filter);
			break;
		}

		case SWT.FocusOut: {
			if (!hasFocus) {
				return;
			}
			final Control focusControl = getDisplay().getFocusControl();
			if (focusControl == DateChooser.this || focusControl == nextMonth || focusControl == prevMonth) {
				return;
			}
			hasFocus = false;
			getDisplay().removeFilter(SWT.KeyDown, filter);
			getDisplay().removeFilter(SWT.FocusIn, filter);
			notifyListeners(SWT.FocusOut, new Event());
			break;
		}
	}
	gridRedraw();
}
 
Example 5
Source File: FormattedText.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets the Text widget value, preventing fire of Modify events.
 *
 * @param value The String value to display in the widget
 */
private void setText(String value) {
	Display display = text.getDisplay();
	try {
		display.addFilter(SWT.Modify, modifyFilter);
		text.setText(value);
	} finally {
		display.removeFilter(SWT.Modify, modifyFilter);
	}
}
 
Example 6
Source File: TLCErrorView.java    From tlaplus with MIT License 4 votes vote down vote up
public ShiftClickAction(final String text, final ImageDescriptor imageDescriptor, final Display display) {
	super(text, imageDescriptor);
	display.addFilter(SWT.KeyDown, this);
	display.addFilter(SWT.KeyUp, this);
}
 
Example 7
Source File: TLCErrorView.java    From tlaplus with MIT License 4 votes vote down vote up
public ShiftClickAction(final String text, final int style, final Display display) {
	super(text, style);
	display.addFilter(SWT.KeyDown, this);
	display.addFilter(SWT.KeyUp, this);
}
 
Example 8
Source File: KeybindingsManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void initBindings()
{
	WorkbenchJob workbenchJob = new WorkbenchJob("Installing KeybindingsManager") //$NON-NLS-1$
	{
		@Override
		public IStatus runInUIThread(IProgressMonitor monitor)
		{

			loadbindings();

			// Insert our key listener before the Eclipse's key listeners
			IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
			if (bindingService instanceof BindingService)
			{
				final BindingService theBindingService = (BindingService) bindingService;
				Display display = PlatformUI.getWorkbench().getDisplay();
				final WorkbenchKeyboard keyboard = theBindingService.getKeyboard();
				Listener keyDownFilter = keyboard.getKeyDownFilter();
				try
				{
					if (keyDownFilter != null)
					{
						display.removeFilter(SWT.KeyDown, keyDownFilter);
						display.removeFilter(SWT.Traverse, keyDownFilter);
					}
					display.addFilter(SWT.KeyDown, listener);
					display.addFilter(SWT.Traverse, listener);
				}
				finally
				{
					if (keyDownFilter != null)
					{
						display.addFilter(SWT.KeyDown, keyDownFilter);
						display.addFilter(SWT.Traverse, keyDownFilter);
					}
				}
			}

			// Set the initial enabled state of KeybindingsManager
			IContextService contextService = (IContextService) workbench.getService(IContextService.class);
			contextService.addContextManagerListener(contextManagerListener);
			setEnabled(contextService.getActiveContextIds().contains(ScriptingUIPlugin.SCRIPTING_CONTEXT_ID));

			return Status.OK_STATUS;
		}
	};
	workbenchJob.setRule(MUTEX_RULE);
	EclipseUtil.setSystemForJob(workbenchJob);
	workbenchJob.setPriority(Job.LONG);
	workbenchJob.schedule();
}
 
Example 9
Source File: ScannerEvents.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public static void addListenerToDisplay(Display display){
	display.addFilter(SWT.KeyDown, getInstance());
}