Java Code Examples for org.sikuli.basics.Settings#isMac()
The following examples show how to use
org.sikuli.basics.Settings#isMac() .
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: RobotDesktop.java From SikuliX1 with MIT License | 6 votes |
@Override public void typeKey(int key) { Debug.log(4, "Robot: doType: %s ( %d )", KeyEvent.getKeyText(key), key); if (Settings.isMac()) { if (key == Key.toJavaKeyCodeFromText("#N.")) { doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#C.")); doType(KeyMode.PRESS_RELEASE, key); doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#C.")); return; } else if (key == Key.toJavaKeyCodeFromText("#T.")) { doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#C.")); doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#A.")); doType(KeyMode.PRESS_RELEASE, key); doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#A.")); doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#C.")); return; } else if (key == Key.toJavaKeyCodeFromText("#X.")) { key = Key.toJavaKeyCodeFromText("#T."); doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#A.")); doType(KeyMode.PRESS_RELEASE, key); doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#A.")); return; } } doType(KeyMode.PRESS_RELEASE, key); }
Example 2
Source File: Guide.java From SikuliX1 with MIT License | 6 votes |
public void focusBelow() { if (Settings.isMac()) { // TODO: replace this hack with a more robust method // Mac's hack to bring focus to the window directly underneath // this hack works on the assumption that the caller has // the input focus but no interaction area at the current // mouse cursor position // This hack does not work well with applications that // can receive mouse clicks without having the input focus // (e.g., finder, system preferences) // robot.mousePress(InputEvent.BUTTON1_MASK); // robot.mouseRelease(InputEvent.BUTTON1_MASK); // Another temporary hack to switch to the previous window on Mac robot.keyPress(KeyEvent.VK_META); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_META); robot.keyRelease(KeyEvent.VK_TAB); // wait a little bit for the switch to complete robot.delay(1000); } }
Example 3
Source File: EditorViewFactory.java From SikuliX1 with MIT License | 5 votes |
private float tabbedWidth() { String str = getText(getStartOffset(), getEndOffset()).toString(); int tab = countTab(str); if (Settings.isMac()) { return stringWidth(str) + getRealTabWidth() * tab; } else { return stringWidth(str) + getTabWidth() * tab; } }
Example 4
Source File: EditorViewFactory.java From SikuliX1 with MIT License | 5 votes |
private float getRealTabWidth() { final int tabCharWidth; if (Settings.isMac()) { tabCharWidth = stringWidth("\t"); } else { tabCharWidth = stringWidth(" "); } return getTabWidth() - tabCharWidth /* + 1f */; //still buggy }
Example 5
Source File: Key.java From SikuliX1 with MIT License | 5 votes |
/** * HotKey modifier to be used with Sikuli's HotKey feature * @return META(CMD) on Mac, CTRL otherwise */ public static int getHotkeyModifier() { if (Settings.isMac()) { return KeyEvent.VK_META; } else { return KeyEvent.VK_CONTROL; } }
Example 6
Source File: IDETaskbarSupport.java From SikuliX1 with MIT License | 4 votes |
/** * Sets the task icon in the OS task bar. * * This class contains some reflective code that can be removed * as soon as we ditch Java 8 support. * * @param img the task image to set. */ public static void setTaksIcon(Image img) { /* * Java 9 provides java.awt.Taskbar which is a nice abstraction to do this on multiple platforms. * But because we have to be Java 8 backwards compatible we have to use some reflection here to * get the job done properly. * * TODO Replace reflective code with code snippet below as soon as we ditch Java 8 support. */ // if(Taskbar.isTaskbarSupported()) { // Taskbar taskbar = Taskbar.getTaskbar(); // // if (taskbar.isSupported(Taskbar.Feature.ICON_IMAGE)) { // taskbar.setIconImage(img); // } // } try { if (RunTime.get().isJava9()) { Class<?> clTaskbar = Class.forName("java.awt.Taskbar"); Method isTaskbarSupported = clTaskbar.getMethod("isTaskbarSupported"); Method getTaskbar = clTaskbar.getMethod("getTaskbar"); if(Boolean.TRUE.equals(isTaskbarSupported.invoke(clTaskbar))) { Object taskbar = getTaskbar.invoke(clTaskbar); @SuppressWarnings({ "rawtypes", "unchecked" }) Class<Enum> clDesktopFeature = (Class<Enum>) Class.forName("java.awt.Taskbar$Feature"); @SuppressWarnings("unchecked") Object iconImageEnum = Enum.valueOf(clDesktopFeature, "ICON_IMAGE"); if(Boolean.TRUE.equals(clTaskbar.getMethod("isSupported", clDesktopFeature).invoke(taskbar, iconImageEnum))) { Method setIconImage = clTaskbar.getMethod("setIconImage", new Class[]{java.awt.Image.class}); setIconImage.invoke(taskbar, img); } } } else if (Settings.isMac()) { // special handling for MacOS if we are on Java 8 Class<?> appClass = Class.forName("com.apple.eawt.Application"); Method getApplication = appClass.getMethod("getApplication"); Object application = getApplication.invoke(appClass); Method setDockIconImage = appClass.getMethod("setDockIconImage", new Class[]{java.awt.Image.class}); setDockIconImage.invoke(application, img); } } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException | SecurityException e) { // Just ignore this if not supported } }
Example 7
Source File: EditorPane.java From SikuliX1 with MIT License | 4 votes |
private void initForScriptType() { // initialize runner to speed up first script run (new Thread() { @Override public void run() { editorPaneRunner.init(null); } }).start(); editorPaneType = editorPaneRunner.getType(); indentationLogic = null; setEditorPaneIDESupport(editorPaneType); if (null != editorPaneIDESupport) { try { indentationLogic = editorPaneIDESupport.getIndentationLogic(); indentationLogic.setTabWidth(PreferencesUser.get().getTabWidth()); } catch (Exception ex) { } codeGenerator = editorPaneIDESupport.getCodeGenerator(); } else { // Take Jython generator if no IDESupport is available // TODO Needs better implementation codeGenerator = new JythonCodeGenerator(); } if (editorPaneType != null) { editorKit = new SikuliEditorKit(); setEditorKit(editorKit); setContentType(editorPaneType); if (indentationLogic != null) { PreferencesUser.get().addPreferenceChangeListener(new PreferenceChangeListener() { @Override public void preferenceChange(PreferenceChangeEvent event) { if (event.getKey().equals("TAB_WIDTH")) { indentationLogic.setTabWidth(Integer.parseInt(event.getNewValue())); } } }); } if (transferHandler == null) { transferHandler = new MyTransferHandler(); } setTransferHandler(transferHandler); if (lineHighlighter == null) { lineHighlighter = new EditorCurrentLineHighlighter(this); addCaretListener(lineHighlighter); initKeyMap(); //addKeyListener(this); //addCaretListener(this); } popMenuImage = new SikuliIDEPopUpMenu("POP_IMAGE", this); if (!popMenuImage.isValidMenu()) { popMenuImage = null; } popMenuCompletion = new SikuliIDEPopUpMenu("POP_COMPLETION", this); if (!popMenuCompletion.isValidMenu()) { popMenuCompletion = null; } setFont(new Font(PreferencesUser.get().getFontName(), Font.PLAIN, PreferencesUser.get().getFontSize())); setMargin(new Insets(3, 3, 3, 3)); setBackground(Color.WHITE); if (!Settings.isMac()) { setSelectionColor(new Color(170, 200, 255)); } // updateDocumentListeners("initBeforeLoad"); SikulixIDE.getStatusbar().setType(editorPaneType); log(lvl, "InitTab: (%s)", editorPaneType); } }
Example 8
Source File: Env.java From SikuliX1 with MIT License | 4 votes |
/** * @return true/false * @deprecated use Settings. ... instead */ @Deprecated public static boolean isMac() { return Settings.isMac(); }
Example 9
Source File: SikulixFileChooser.java From SikuliX1 with MIT License | 4 votes |
private void processDialog(int selectionMode, String last_dir, String title, int mode, Object[] filters, Object[] result) { JFileChooser fchooser = new JFileChooser(); File fileChoosen = null; FileFilter filterChoosen = null; if (!last_dir.isEmpty()) { fchooser.setCurrentDirectory(new File(last_dir)); } fchooser.setSelectedFile(null); fchooser.setDialogTitle(title); String btnApprove = "Select"; if (fromPopFile) { fchooser.setFileSelectionMode(DIRSANDFILES); fchooser.setAcceptAllFileFilterUsed(true); } else { fchooser.setFileSelectionMode(selectionMode); if (mode == FileDialog.SAVE) { fchooser.setDialogType(JFileChooser.SAVE_DIALOG); btnApprove = "Save"; } if (filters.length == 0) { fchooser.setAcceptAllFileFilterUsed(true); } else { fchooser.setAcceptAllFileFilterUsed(false); for (Object filter : filters) { fchooser.setFileFilter((FileFilter) filter); } } } if (Settings.isMac()) { fchooser.putClientProperty("JFileChooser.packageIsTraversable", "always"); } int dialogResponse = fchooser.showDialog(parentFrame, btnApprove); if (dialogResponse != JFileChooser.APPROVE_OPTION) { fileChoosen = null; } else { fileChoosen = fchooser.getSelectedFile(); } result[0] = fileChoosen; if (filters.length > 0) { result[1] = fchooser.getFileFilter(); } }