Search in sources :

Example 11 with AWTException

use of java.awt.AWTException in project jdk8u_jdk by JetBrains.

the class ExecutableInputMethodManager method putPreferredInputMethod.

/**
     * Writes the preferred input method descriptor class name into
     * the user's Preferences tree in accordance with the given locale.
     *
     * @param inputMethodLocator input method locator to remember.
     */
private synchronized void putPreferredInputMethod(InputMethodLocator locator) {
    InputMethodDescriptor descriptor = locator.getDescriptor();
    Locale preferredLocale = locator.getLocale();
    if (preferredLocale == null) {
        // check available locales of the input method
        try {
            Locale[] availableLocales = descriptor.getAvailableLocales();
            if (availableLocales.length == 1) {
                preferredLocale = availableLocales[0];
            } else {
                // there is no way to know which locale is the preferred one, so do nothing.
                return;
            }
        } catch (AWTException ae) {
            // do nothing here, either.
            return;
        }
    }
    // "xx_YY" as "xx" when putting the preference into tree
    if (preferredLocale.equals(Locale.JAPAN)) {
        preferredLocale = Locale.JAPANESE;
    }
    if (preferredLocale.equals(Locale.KOREA)) {
        preferredLocale = Locale.KOREAN;
    }
    if (preferredLocale.equals(new Locale("th", "TH"))) {
        preferredLocale = new Locale("th");
    }
    // obtain node
    String path = preferredIMNode + "/" + createLocalePath(preferredLocale);
    // write in the preference tree
    writePreferredInputMethod(path, descriptor.getClass().getName());
    preferredLocatorCache.put(preferredLocale.toString().intern(), locator.deriveLocator(preferredLocale));
    return;
}
Also used : Locale(java.util.Locale) InputMethodDescriptor(java.awt.im.spi.InputMethodDescriptor) AWTException(java.awt.AWTException)

Example 12 with AWTException

use of java.awt.AWTException in project jdk8u_jdk by JetBrains.

the class AWTInputMethodPopupMenu method addOneInputMethodToMenu.

void addOneInputMethodToMenu(InputMethodLocator locator, String currentSelection) {
    InputMethodDescriptor descriptor = locator.getDescriptor();
    String label = descriptor.getInputMethodDisplayName(null, Locale.getDefault());
    String command = locator.getActionCommandString();
    Locale[] locales = null;
    int localeCount;
    try {
        locales = descriptor.getAvailableLocales();
        localeCount = locales.length;
    } catch (AWTException e) {
        // ??? should have better error handling -
        // tell user what happened, then remove this input method from the list.
        // For the time being, just show it disabled.
        localeCount = 0;
    }
    if (localeCount == 0) {
        // could be IIIMP adapter which has lost its connection
        addMenuItem(label, null, currentSelection);
    } else if (localeCount == 1) {
        if (descriptor.hasDynamicLocaleList()) {
            // try to make sure that what the user sees and what
            // we eventually select is consistent even if the locale
            // list changes in the meantime
            label = descriptor.getInputMethodDisplayName(locales[0], Locale.getDefault());
            command = locator.deriveLocator(locales[0]).getActionCommandString();
        }
        addMenuItem(label, command, currentSelection);
    } else {
        Object submenu = createSubmenu(label);
        add(submenu);
        for (int j = 0; j < localeCount; j++) {
            Locale locale = locales[j];
            String subLabel = getLocaleName(locale);
            String subCommand = locator.deriveLocator(locale).getActionCommandString();
            addMenuItem(submenu, subLabel, subCommand, currentSelection);
        }
    }
}
Also used : Locale(java.util.Locale) InputMethodDescriptor(java.awt.im.spi.InputMethodDescriptor) AWTException(java.awt.AWTException)

Example 13 with AWTException

use of java.awt.AWTException in project jdk8u_jdk by JetBrains.

the class X11GraphicsConfig method createBackBuffer.

/**
     * Attempts to create an XDBE-based backbuffer for the given peer.  If
     * the requested configuration is not natively supported, an AWTException
     * is thrown.  Otherwise, if the backbuffer creation is successful, a
     * handle to the native backbuffer is returned.
     */
public long createBackBuffer(X11ComponentPeer peer, int numBuffers, BufferCapabilities caps) throws AWTException {
    if (!X11GraphicsDevice.isDBESupported()) {
        throw new AWTException("Page flipping is not supported");
    }
    if (numBuffers > 2) {
        throw new AWTException("Only double or single buffering is supported");
    }
    BufferCapabilities configCaps = getBufferCapabilities();
    if (!configCaps.isPageFlipping()) {
        throw new AWTException("Page flipping is not supported");
    }
    long window = peer.getContentWindow();
    int swapAction = getSwapAction(caps.getFlipContents());
    return createBackBuffer(window, swapAction);
}
Also used : BufferCapabilities(java.awt.BufferCapabilities) AWTException(java.awt.AWTException)

Example 14 with AWTException

use of java.awt.AWTException in project cryptomator by cryptomator.

the class ExitUtil method initTrayIconExitHandler.

private void initTrayIconExitHandler(Runnable exitCommand) {
    final TrayIcon trayIcon = createTrayIcon(exitCommand);
    try {
        // double clicking tray icon should open Cryptomator
        if (SystemUtils.IS_OS_WINDOWS) {
            trayIcon.addMouseListener(new TrayIconMouseListener());
        }
        SystemTray.getSystemTray().add(trayIcon);
        mainWindow.setOnCloseRequest((e) -> {
            if (Platform.isImplicitExit()) {
                exitCommand.run();
            } else {
                macFunctions.map(MacFunctions::uiState).ifPresent(JniException.ignore(MacApplicationUiState::transformToAgentApplication));
                mainWindow.close();
                this.showTrayNotification(trayIcon);
            }
        });
    } catch (SecurityException | AWTException ex) {
        // not working? then just go ahead and close the app
        mainWindow.setOnCloseRequest((ev) -> {
            exitCommand.run();
        });
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) Settings(org.cryptomator.ui.settings.Settings) PopupMenu(java.awt.PopupMenu) Inject(javax.inject.Inject) SwingUtilities(javax.swing.SwingUtilities) TrayIcon(java.awt.TrayIcon) MacFunctions(org.cryptomator.jni.MacFunctions) MouseAdapter(java.awt.event.MouseAdapter) MessageType(java.awt.TrayIcon.MessageType) Named(javax.inject.Named) SystemTray(java.awt.SystemTray) Localization(org.cryptomator.ui.settings.Localization) ScriptException(javax.script.ScriptException) Logger(org.slf4j.Logger) Image(java.awt.Image) SystemUtils(org.apache.commons.lang3.SystemUtils) ScriptEngineManager(javax.script.ScriptEngineManager) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) TimeUnit(java.util.concurrent.TimeUnit) Platform(javafx.application.Platform) MenuItem(java.awt.MenuItem) Stage(javafx.stage.Stage) AWTException(java.awt.AWTException) ScriptEngine(javax.script.ScriptEngine) Optional(java.util.Optional) JniException(org.cryptomator.jni.JniException) MacApplicationUiState(org.cryptomator.jni.MacApplicationUiState) Toolkit(java.awt.Toolkit) TrayIcon(java.awt.TrayIcon) AWTException(java.awt.AWTException)

Example 15 with AWTException

use of java.awt.AWTException in project screenbird by adamhub.

the class ScreenRecorder method createTray.

/**
     * Sets up the system tray for screenRecorder application
     */
private void createTray() {
    PopupMenu menu = new PopupMenu();
    MenuItem aboutItem = new MenuItem("About");
    aboutItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(jfRecorderPanel, String.format("Screenbird%nBuild Version %s", RecorderPanel.resources.getString("BUILD")));
        }
    });
    menu.add(aboutItem);
    // Open the settings menu
    MenuItem settingsItem = new MenuItem("Preferences");
    settingsItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (jpRecorderPanel.isRecorderConfigSate())
                jpRecorderPanel.showSettingsForm();
        }
    });
    menu.add(settingsItem);
    // Hide or show the recorder 
    MenuItem messageItem = new MenuItem("Hide/Show");
    messageItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (jfRecorderPanel.getState() == JFrame.NORMAL) {
                jfRecorderPanel.setState(JFrame.ICONIFIED);
            } else {
                jfRecorderPanel.setState(JFrame.NORMAL);
            }
        }
    });
    menu.add(messageItem);
    MenuItem closeItem = new MenuItem("Quit/Exit");
    closeItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            destroy();
        }
    });
    menu.add(closeItem);
    // Loads the pastevid logo
    Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource(ResourceUtil.LOGO_16));
    if (!MediaUtil.osIsWindows()) {
        icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource(ResourceUtil.LOGO_24));
    }
    // Assigns the pastevid logo
    TrayIcon tray = new TrayIcon(icon, "Screenbird", menu);
    try {
        SystemTray.getSystemTray().add(tray);
    } catch (AWTException ex) {
        log(ex);
    }
}
Also used : ActionListener(java.awt.event.ActionListener) TrayIcon(java.awt.TrayIcon) ActionEvent(java.awt.event.ActionEvent) MenuItem(java.awt.MenuItem) Image(java.awt.Image) PopupMenu(java.awt.PopupMenu) AWTException(java.awt.AWTException)

Aggregations

AWTException (java.awt.AWTException)22 Robot (java.awt.Robot)13 BufferedImage (java.awt.image.BufferedImage)7 Point (java.awt.Point)5 Rectangle (java.awt.Rectangle)5 Frame (java.awt.Frame)4 IOException (java.io.IOException)4 Image (java.awt.Image)3 MenuItem (java.awt.MenuItem)3 PopupMenu (java.awt.PopupMenu)3 TrayIcon (java.awt.TrayIcon)3 ActionEvent (java.awt.event.ActionEvent)3 WindowEvent (java.awt.event.WindowEvent)3 File (java.io.File)3 BufferCapabilities (java.awt.BufferCapabilities)2 Dimension (java.awt.Dimension)2 Graphics (java.awt.Graphics)2 GraphicsConfiguration (java.awt.GraphicsConfiguration)2 ImageCapabilities (java.awt.ImageCapabilities)2 Insets (java.awt.Insets)2