package sun.awt.im;
import java.awt.AWTException;
import java.awt.CheckboxMenuItem;
import java.awt.Component;
import java.awt.Container;
import java.awt.PopupMenu;
import java.awt.Menu;
import java.awt.MenuItem;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.im.spi.InputMethodDescriptor;
import java.util.Locale;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPopupMenu;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
abstract class implements ActionListener {
static InputMethodPopupMenu (Component client, String title) {
if ((client instanceof JFrame) ||
(client instanceof JDialog)) {
return new JInputMethodPopupMenu(title);
} else {
return new AWTInputMethodPopupMenu(title);
}
}
abstract void (Component c, int x, int y);
abstract void ();
abstract void ();
abstract void (Component c);
abstract Object (String label);
abstract void (Object menuItem);
abstract void (String label, String command, String currentSelection);
abstract void (Object targetMenu, String label, String command,
String currentSelection);
void (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) {
localeCount = 0;
}
if (localeCount == 0) {
addMenuItem(label, null, currentSelection);
} else if (localeCount == 1) {
if (descriptor.hasDynamicLocaleList()) {
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);
}
}
}
static boolean (String command, String currentSelection) {
if (command == null || currentSelection == null) {
return false;
}
if (command.equals(currentSelection)) {
return true;
}
int index = currentSelection.indexOf('\n');
if (index != -1 && currentSelection.substring(0, index).equals(command)) {
return true;
}
return false;
}
String (Locale locale) {
String localeString = locale.toString();
String localeName = Toolkit.getProperty("AWT.InputMethodLanguage." + localeString, null);
if (localeName == null) {
localeName = locale.getDisplayName();
if (localeName == null || localeName.length() == 0)
localeName = localeString;
}
return localeName;
}
public void (ActionEvent event) {
String choice = event.getActionCommand();
((ExecutableInputMethodManager)InputMethodManager.getInstance()).changeInputMethod(choice);
}
}
class extends InputMethodPopupMenu {
static JPopupMenu = null;
(String title) {
synchronized (this) {
if (delegate == null) {
delegate = new JPopupMenu(title);
}
}
}
void (Component c, int x, int y) {
delegate.show(c, x, y);
}
void () {
delegate.removeAll();
}
void () {
delegate.addSeparator();
}
void (Component c) {
}
Object (String label) {
return new JMenu(label);
}
void (Object menuItem) {
delegate.add((JMenuItem)menuItem);
}
void (String label, String command, String currentSelection) {
addMenuItem(delegate, label, command, currentSelection);
}
void (Object targetMenu, String label, String command, String currentSelection) {
JMenuItem menuItem;
if (isSelected(command, currentSelection)) {
menuItem = new JCheckBoxMenuItem(label, true);
} else {
menuItem = new JMenuItem(label);
}
menuItem.setActionCommand(command);
menuItem.addActionListener(this);
menuItem.setEnabled(command != null);
if (targetMenu instanceof JMenu) {
((JMenu)targetMenu).add(menuItem);
} else {
((JPopupMenu)targetMenu).add(menuItem);
}
}
}
class extends InputMethodPopupMenu {
static PopupMenu = null;
(String title) {
synchronized (this) {
if (delegate == null) {
delegate = new PopupMenu(title);
}
}
}
void (Component c, int x, int y) {
delegate.show(c, x, y);
}
void () {
delegate.removeAll();
}
void () {
delegate.addSeparator();
}
void (Component c) {
c.add(delegate);
}
Object (String label) {
return new Menu(label);
}
void (Object menuItem) {
delegate.add((MenuItem)menuItem);
}
void (String label, String command, String currentSelection) {
addMenuItem(delegate, label, command, currentSelection);
}
void (Object targetMenu, String label, String command, String currentSelection) {
MenuItem menuItem;
if (isSelected(command, currentSelection)) {
menuItem = new CheckboxMenuItem(label, true);
} else {
menuItem = new MenuItem(label);
}
menuItem.setActionCommand(command);
menuItem.addActionListener(this);
menuItem.setEnabled(command != null);
((Menu)targetMenu).add(menuItem);
}
}