List of usage examples for org.eclipse.jface.util Util getWS
public static String getWS()
From source file:com.patrikdufresne.switchbutton.SwitchButton.java
License:Open Source License
/** * Paint the widget/*from ww w . j av a2s .com*/ * * @param event * paint event */ private void paint(final PaintEvent event) { final Rectangle rect = this.getClientArea(); if (rect.width == 0 || rect.height == 0) { return; } // For ease of use declare width and height. final int x = rect.x; final int y = rect.y; final int width = rect.width; final int height = rect.height; GC gc = event.gc; gc.setAntialias(SWT.ON); /* * Draw background */ // Draw back color gc.setForeground(!this.selection ? this.unselectedBackgroundColor : this.selectedBackgroundColor); gc.setBackground(!this.selection ? this.unselectedBackgroundColor : this.selectedBackgroundColor); if (!getEnabled()) { gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); } gc.fillRoundRectangle(x, y, width - 1, height - 1, this.round, this.round); // Draw back border gc.setForeground(!this.selection ? getUnselectedBorderColor() : getSelectedBorderColor()); if (!getEnabled()) { gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); } gc.drawRoundRectangle(x, y, width - 1, height - 1, this.round, this.round); // Draw Left text gc.setForeground(this.selectedForegroundColor); if (!getEnabled()) { gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); } final Point onSize = gc.textExtent(this.textOn, SWT.DRAW_MNEMONIC); gc.drawText(this.textOn, x + width / 4 - onSize.x / 2, y + height / 2 - onSize.y / 2, SWT.DRAW_MNEMONIC); // Draw Right text gc.setForeground(this.unselectedForegroundColor); if (!getEnabled()) { gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); } final Point offSize = gc.textExtent(this.textOff, SWT.DRAW_MNEMONIC); gc.drawText(this.textOff, x + 3 * width / 4 - offSize.x / 2, y + height / 2 - offSize.y / 2, SWT.DRAW_MNEMONIC); // Draw toggle button. Rectangle b; gc.setBackground(this.buttonBackgroundColor); if (!this.selection) { b = new Rectangle(x, y, width / 2, height); } else { b = new Rectangle(x + width - (width / 2), y, width / 2, height); } gc.fillRoundRectangle(b.x, b.y, b.width, b.height, this.round, this.round); gc.setForeground(!this.selection ? this.unselectedBorderColor : this.selectedBorderColor); if (!getEnabled()) { gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); } gc.drawRoundRectangle(b.x, b.y, b.width - 1, b.height - 1, this.round, this.round); // Draw hover line inside the button. if (this.focusColor != null && this.mouseInside) { gc.setForeground(this.focusColor); gc.setLineWidth(1); gc.drawRoundRectangle(b.x + 1, b.y + 1, b.width - 3, b.height - 3, this.round, this.round); gc.setLineWidth(1); } // Draw focus line in button if (paintFocus && hasFocus) { gc.setForeground(getForeground()); if (Util.getWS().equals(Util.WS_GTK)) { gc.drawFocus(b.x + 3, b.y + 3, b.width - 7, b.height - 7); } else { gc.drawFocus(b.x + 3, b.y + 3, b.width - 6, b.height - 6); } } }
From source file:org.csstudio.opibuilder.util.MediaService.java
License:Open Source License
private String getOSName() { String osname = System.getProperty("os.name").trim(); //$NON-NLS-1$ String wsname = Util.getWS().trim(); osname = StringConverter.removeWhiteSpaces(osname).toLowerCase(); if (wsname != null && wsname.length() > 0) { wsname = StringConverter.removeWhiteSpaces(wsname).toLowerCase(); osname = osname + "_" + wsname; }/*from w w w .ja v a2 s . com*/ return osname; }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java
License:Open Source License
/** * <p>//from www . j av a2 s. c o m * Tests a common case for binding deletion. The binding is defined on all * platforms, then deleted on a specific platform, and defined again as * something else. * </p> * * @throws NotDefinedException * If the scheme we try to activate is not defined. */ public void testDeletedBindingPlatform() throws NotDefinedException { final String na = "na"; final Context context = contextManager.getContext(na); context.define("name", "description", null); final Scheme scheme = bindingManager.getScheme(na); scheme.define("name", "description", null); bindingManager.setActiveScheme(scheme); final Set activeContextIds = new HashSet(); activeContextIds.add("na"); contextManager.setActiveContextIds(activeContextIds); final Binding allPlatforms = new TestBinding("allPlatforms", na, na, null, null, Binding.SYSTEM, null); bindingManager.addBinding(allPlatforms); final Binding deletion = new TestBinding(null, na, na, null, Util.getWS(), Binding.SYSTEM, null); bindingManager.addBinding(deletion); final Binding platformSpecific = new TestBinding("platformSpecific", na, na, null, Util.getWS(), Binding.SYSTEM, null); bindingManager.addBinding(platformSpecific); assertEquals("We should be able to change a binding on a particular platform", platformSpecific, bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE)); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java
License:Open Source License
/** * <p>// w ww .j a va2 s .com * Tests whether a plug-in developer can override a binding for a particular * platform. * </p> * * @throws NotDefinedException * If the scheme we try to activate is not defined. */ public void testPlatformOverride() throws NotDefinedException { final Context context = contextManager.getContext("na"); context.define("name", "description", null); final Scheme scheme = bindingManager.getScheme("na"); scheme.define("name", "description", null); bindingManager.setActiveScheme(scheme); final Set activeContextIds = new HashSet(); activeContextIds.add("na"); contextManager.setActiveContextIds(activeContextIds); final Binding binding1 = new TestBinding("base", "na", "na", null, null, Binding.SYSTEM, null); bindingManager.addBinding(binding1); final Binding binding2 = new TestBinding(null, "na", "na", null, Util.getWS(), Binding.SYSTEM, null); bindingManager.addBinding(binding2); final Binding binding3 = new TestBinding("platform-specific", "na", "na", null, Util.getWS(), Binding.SYSTEM, null); bindingManager.addBinding(binding3); assertEquals("A plug-in developer should be able to change a binding for a platform", binding3, bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE)); }
From source file:org.eclipse.ui.internal.keys.BindingService.java
License:Open Source License
public String getPlatform() { return Util.getWS(); }
From source file:org.eclipse.ui.tests.internal.util.VerifyDialog.java
License:Open Source License
private void handleFailure() { IDialogTestPass test = _dialogTests[TEST_TYPE]; StringBuffer text = new StringBuffer(); String label = test.label();//from w w w . j a v a 2s . c o m label = label.substring(0, label.indexOf("&")) + label.substring(label.indexOf("&") + 1); text.append(label).append(" failed on the ").append(Util.getWS()).append(" platform:\n"); String failureMessages[] = test.failureTexts(); for (int i = 0; i < test.checkListTexts().size(); i++) { if (!_checkList[i].getSelection()) { text.append("- ").append(failureMessages[i]).append("\n"); } } FailureDialog dialog = new FailureDialog(getShell()); dialog.create(); dialog.setText(text.toString()); if (dialog.open() == IDialogConstants.OK_ID) { _failureText = dialog.toString(); setReturnCode(IDialogConstants.NO_ID); if (_testDialog.getShell() != null) { _testDialog.close(); } close(); } }
From source file:org.eclipse.ui.tests.performance.CommandsPerformanceTest.java
License:Open Source License
/** * <p>//from w w w. j av a2 s . c o m * Sets up a sufficiently complex set of bindings. * </p> * <p> * At the time of writing, Eclipse's key binding set contains about five * hundred bindings. Of these, 140 specify platform information, while only * 5 specify locale information. About 40 are deletion markers. The deepest * point in the context tree is four levels. There are two schemes. * </p> * <p> * The test binding set contains five thousand bindings. About 1400 specify * either locale or platform information. Five hundred are deletion markers. * The deepest point in the context tree is 40 levels. There are twenty * schemes. * </p> * <p> * The depth of the locale and platform tree is the same in both real life * and the test case. It is difficult to imagine why the locale list would * ever be anything but four elements, or why the platform list would ever * be anything but three elements. * </p> * * @throws NotDefinedException * If something went wrong initializing the active scheme. */ protected final void doSetUp() throws NotDefinedException, Exception { super.doSetUp(); /* * The constants to use in creating the various objects. The platform * locale count must be greater than or equal to the number of deletion * markers. Deletion markers are typically created based on the platform * or locale. */ final int contextTreeDepth = 40; final int schemeDepth = 20; final int bindingCount = 5000; final int platformLocaleCount = 1400; final int deletionMarkers = 500; final String currentLocale = Locale.getDefault().toString(); final String currentPlatform = Util.getWS(); // Set-up a table of modifier keys. final IKeyLookup lookup = KeyLookupFactory.getDefault(); final int modifierKeys0 = 0; final int modifierKeys1 = lookup.getAlt(); final int modifierKeys2 = lookup.getCommand(); final int modifierKeys3 = lookup.getCtrl(); final int modifierKeys4 = lookup.getShift(); final int modifierKeys5 = lookup.getAlt() | lookup.getCommand(); final int modifierKeys6 = lookup.getAlt() | lookup.getCtrl(); final int modifierKeys7 = lookup.getAlt() | lookup.getShift(); final int modifierKeys8 = lookup.getCommand() | lookup.getCtrl(); final int modifierKeys9 = lookup.getCommand() | lookup.getShift(); final int modifierKeys10 = lookup.getCtrl() | lookup.getShift(); final int modifierKeys11 = lookup.getAlt() | lookup.getCommand() | lookup.getCtrl(); final int modifierKeys12 = lookup.getAlt() | lookup.getCommand() | lookup.getShift(); final int modifierKeys13 = lookup.getAlt() | lookup.getCtrl() | lookup.getShift(); final int modifierKeys14 = lookup.getCommand() | lookup.getCtrl() | lookup.getShift(); final int modifierKeys15 = lookup.getAlt() | lookup.getCommand() | lookup.getCtrl() | lookup.getShift(); final int[] modifierKeyTable = { modifierKeys0, modifierKeys1, modifierKeys2, modifierKeys3, modifierKeys4, modifierKeys5, modifierKeys6, modifierKeys7, modifierKeys8, modifierKeys9, modifierKeys10, modifierKeys11, modifierKeys12, modifierKeys13, modifierKeys14, modifierKeys15 }; // Initialize the command manager. commandManager = new CommandManager(); // Initialize the contexts. contextManager = new ContextManager(); final List activeContextIds = new ArrayList(); createContext(contextManager, null, contextTreeDepth, activeContextIds); contextManager.setActiveContextIds(new HashSet(activeContextIds)); // Initialize the schemes. bindingManager = new BindingManager(contextManager, commandManager); final List schemes = new ArrayList(); createScheme(bindingManager, null, schemeDepth, schemes); bindingManager.setActiveScheme((Scheme) schemes.get(schemes.size() - 1)); // Create the deletion markers. final Binding[] bindings = new Binding[bindingCount]; for (int i = 0; i < deletionMarkers; i++) { /* * Set-up the locale and platform. These are based on the numbers * given above. */ String locale = null; String platform = null; if (i < platformLocaleCount) { switch (i % 4) { case 0: locale = currentLocale; break; case 1: platform = currentPlatform; break; case 2: locale = "gibberish"; break; case 3: platform = "gibberish"; break; } } // Build a key sequence. final char character = (char) ('A' + (i % 26)); final int modifierKeys = modifierKeyTable[(i / 26) % modifierKeyTable.length]; final KeyStroke keyStroke = KeyStroke.getInstance(modifierKeys, character); final KeySequence keySequence = KeySequence.getInstance(keyStroke); // Build the other parameters. final String schemeId = ((Scheme) schemes.get(i % schemes.size())).getId(); final String contextId = (String) activeContextIds.get(i % activeContextIds.size()); final int type = (i % 2); // Construct the binding. final Binding binding = new KeyBinding(keySequence, null, schemeId, contextId, locale, platform, null, type); bindings[i] = binding; } /* * Now create the regular bindings. By using the same loop structure and * resetting the index to zero, we ensure that the deletion markers will * actually delete something. */ for (int i = 0; i < bindingCount - deletionMarkers; i++) { /* * Set-up the locale and platform for those bindings that will not * be used to match the above deletion markers. These are based on * the numbers given above. */ String locale = null; String platform = null; if ((i > deletionMarkers) && (i < platformLocaleCount)) { switch (i % 4) { case 0: locale = currentLocale; break; case 1: platform = currentPlatform; break; case 2: locale = "gibberish"; break; case 3: platform = "gibberish"; break; } } // Build a key sequence. final char character = (char) ('A' + (i % 26)); final int modifierKeys = modifierKeyTable[(i / 26) % modifierKeyTable.length]; final KeyStroke keyStroke = KeyStroke.getInstance(modifierKeys, character); final KeySequence keySequence = KeySequence.getInstance(keyStroke); // Build the other parameters. final String commandId = "command" + i; final String schemeId = ((Scheme) schemes.get(i % schemes.size())).getId(); final String contextId = (String) activeContextIds.get(i % activeContextIds.size()); final int type = (i % 2); // Construct the binding. final Command command = commandManager.getCommand(commandId); final ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, null); final Binding binding = new KeyBinding(keySequence, parameterizedCommand, schemeId, contextId, locale, platform, null, type); bindings[i + deletionMarkers] = binding; } bindingManager.setBindings(bindings); }