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;
}
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);
}
}
}
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);
}
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();
});
}
}
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);
}
}
Aggregations