下面列出了怎么用java.beans.EventHandler的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Creates the button for the detection if it doesn't already exist.
*
* @param value Detection.
* @return Button for the detection.
*/
private JButton getButton(Object value) {
if (buttons.containsKey(value)) {
return buttons.get(value);
}
if (!(value instanceof String)) {
return null;
}
String url = (String) value;
JButton button = new JButton(Utilities.getImageIcon(
"gnome-emblem-web.png",
EnumImageSize.SMALL));
button.setBorderPainted(false);
button.setContentAreaFilled(false);
button.setActionCommand(url);
button.setEnabled(true);
button.addActionListener(EventHandler.create(
ActionListener.class, this, "goTo", "actionCommand"));
buttons.put(value, button);
return button;
}
/**
* @return Login components.
*/
private Component createCommandComponents() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
panel.setBorder(BorderFactory.createEtchedBorder());
// Ok button
buttonOk = Utilities.createJButton(GT._T("&OK"), null);
buttonOk.addActionListener(EventHandler.create(
ActionListener.class, this, "actionOk"));
panel.add(buttonOk);
// Validate button
buttonRemove = Utilities.createJButton(GT._T("&Remove page comments"), null);
buttonRemove.addActionListener(EventHandler.create(
ActionListener.class, this, "actionRemove"));
panel.add(buttonRemove);
// Cancel button
buttonCancel = ActionDispose.createButton(getParentComponent(), true, true);
panel.add(buttonCancel);
return panel;
}
/**
* @return Tools menu.
*/
protected JMenu createToolsMenu() {
JMenu menu = Utilities.createJMenu(GT._T("&Tools"));
JMenuItem menuItem = null;
menu.add(createFixRedirectsMenu());
menuItem = Utilities.createJMenuItem(GT._T("&Preview"), false);
menuItem.addActionListener(EventHandler.create(
ActionListener.class, this, "actionPreview"));
menu.add(menuItem);
menuItem = Utilities.createJMenuItem(GT._T("&Expand templates"), false);
menuItem.addActionListener(EventHandler.create(
ActionListener.class, this, "actionExpandTemplates"));
menu.add(menuItem);
menuItem = Utilities.createJMenuItem(GT._T("Expand templates &and Preview"), false);
menuItem.addActionListener(EventHandler.create(
ActionListener.class, this, "actionExpandTemplatesPreview"));
menu.add(menuItem);
return menu;
}
/**
* Creates the button for the detection if it doesn't already exist.
*
* @param value Detection.
* @return Button for the detection.
*/
private JButton getButton(Object value) {
if (buttons.containsKey(value)) {
return buttons.get(value);
}
if ((value == null) || !(value instanceof CheckWikiDetection)) {
return null;
}
CheckWikiDetection detection = (CheckWikiDetection) value;
JButton button = new JButton(Utilities.getImageIcon(
"gnome-edit-find.png", EnumImageSize.SMALL));
button.setBorderPainted(false);
button.setContentAreaFilled(false);
button.setActionCommand(Integer.toString(detection.getLocation()));
button.setEnabled(textPane != null);
button.addActionListener(EventHandler.create(
ActionListener.class, this, "goToDetection", "actionCommand"));
buttons.put(value, button);
return button;
}
/**
* Action called when Special Lists button is pressed.
*/
public void actionSpecialLists() {
// Create menu for special lists
JPopupMenu menu = new JPopupMenu();
for (EnumQueryPage query : EnumQueryPage.values()) {
JMenuItem item = new JMenuItem(query.getName());
item.setActionCommand(query.getCode());
item.addActionListener(EventHandler.create(
ActionListener.class, this, "actionSpecialList", "actionCommand"));
menu.add(item);
}
menu.show(
buttonSpecialLists,
0,
buttonSpecialLists.getHeight());
}
/**
* Action called when a Variant button is clicked.
*
* @param number Variant number.
*/
public void actionVariant(String number) {
JPopupMenu menu = new JPopupMenu();
int variantNumber = Integer.parseInt(number);
String prefix = language.getCode();
if (script != null) {
prefix += "-" + script.getCode();
}
if (region != null) {
prefix += "-" + region.getCode();
}
for (int i = 0; i < variantNumber; i++) {
if (variant.get(i) != null) {
prefix += "-" + variant.get(i).getCode();
}
}
List<LanguageRegistry.Variant> variants = registry.getVariants(prefix);
for (LanguageRegistry.Variant tmpVariant : variants) {
JMenuItem item = new JMenuItem(tmpVariant.toString());
item.setActionCommand(number + ";" + tmpVariant.getCode());
item.addActionListener(EventHandler.create(
ActionListener.class, this, "selectVariant", "actionCommand"));
menu.add(item);
}
menu.show(buttonVariant.get(variantNumber), 0, buttonVariant.get(variantNumber).getHeight());
}
/**
* Creates the button for the detection if it doesn't already exist.
*
* @param value Detection.
* @return Button for the detection.
*/
private JButton getButton(Object value) {
if (buttons.containsKey(value)) {
return buttons.get(value);
}
if (!(value instanceof Interval)) {
return null;
}
Interval interval = (Interval) value;
String actionCommand = Integer.toString(interval.getBeginIndex()) + ";" + Integer.toString(interval.getEndIndex());
JButton button = new JButton(Utilities.getImageIcon(
"gnome-edit-find.png",
EnumImageSize.SMALL));
button.setBorderPainted(false);
button.setContentAreaFilled(false);
button.setActionCommand(actionCommand);
button.setEnabled(true);
button.addActionListener(EventHandler.create(
ActionListener.class, this, "goTo", "actionCommand"));
buttons.put(value, button);
return button;
}
/**
* Creates the button for the detection if it doesn't already exist.
*
* @param table Table.
* @param row Row.
* @return Button for the row.
*/
private JButton getButton(JTable table, int row) {
Integer rowNum = Integer.valueOf(row);
if (buttons.containsKey(rowNum)) {
return buttons.get(rowNum);
}
JButton button = new JButton(Utilities.getImageIcon(
"gnome-edit-copy.png", EnumImageSize.SMALL));
button.setBorderPainted(false);
button.setContentAreaFilled(false);
Object value = table.getValueAt(row, copyColumn);
button.setActionCommand(value != null ? value.toString() : "");
button.setEnabled(true);
button.addActionListener(EventHandler.create(
ActionListener.class, this, "copyCell", "actionCommand"));
buttons.put(rowNum, button);
return button;
}
/**
* Constructor.
*
* @param parentComponent Parent component.
*/
public UserNameSelector(Component parentComponent) {
this.parentComponent = parentComponent;
this.changeListeners = new ArrayList<>();
// Create combo box
combo = new JComboBox<>();
combo.setEditable(true);
combo.addItemListener(EventHandler.create(
ItemListener.class, this, "notifyUserNameChange"));
// Create label
label = Utilities.createJLabel(GT._T("Username:"));
label.setLabelFor(combo);
label.setHorizontalAlignment(SwingConstants.TRAILING);
}
/**
* Creates the button for the detection if it doesn't already exist.
*
* @param value Detection.
* @return Button for the detection.
*/
private JButton getButton(Object value) {
if (buttons.containsKey(value)) {
return buttons.get(value);
}
String actionCommand = constructActionCommand(value);
if (actionCommand == null) {
return null;
}
JButton button = new JButton(Utilities.getImageIcon(
(textPane != null) ? "gnome-edit-find.png" : "gnome-system-run.png",
EnumImageSize.SMALL));
button.setBorderPainted(false);
button.setContentAreaFilled(false);
button.setActionCommand(actionCommand);
button.setEnabled(true);
button.addActionListener(EventHandler.create(
ActionListener.class, this, "goTo", "actionCommand"));
buttons.put(value, button);
return button;
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
/**
* Show menu for updating warnings.
*
* @param e Event triggering this call.
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent e) {
if ((e == null) ||
(e.getSource() == null) ||
(!(e.getSource() instanceof Component))) {
return;
}
Component source = (Component) e.getSource();
// Display menu
JPopupMenu menuWarning = new JPopupMenu();
JMenuItem menuItem = Utilities.createJMenuItem(
GT._T("Add a warning about links to disambiguation pages"),
true);
menuItem.addActionListener(EventHandler.create(
ActionListener.class, this, "actionDisambiguationWarning"));
menuWarning.add(menuItem);
menuItem = Utilities.createJMenuItem(
GT._T("Add a warning about ISBN errors"),
true);
menuItem.addActionListener(EventHandler.create(
ActionListener.class, this, "actionISBNWarning"));
menuWarning.add(menuItem);
menuItem = Utilities.createJMenuItem(
GT._T("Add a warning about duplicate arguments errors"),
true);
menuItem.addActionListener(EventHandler.create(
ActionListener.class, this, "actionDuplicateArgsWarning"));
menuWarning.add(menuItem);
menuWarning.show(source, 0, source.getHeight());
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
public static void main(String[] args) {
Test6179222 test = new Test6179222();
// test 6179222
test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
// test 6265540
test(EventHandler.create(ActionListener.class, test, "bar.doit"));
if (!test.bar.invoked) {
throw new Error("Bar was not set");
}
}
/**
* @return Login components.
*/
private Component createCommandComponents() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
// Apply button
buttonApply = Utilities.createJButton(
GT._T("Apply"),
ConfigurationValueShortcut.APPLY);
buttonApply.addActionListener(EventHandler.create(
ActionListener.class, this, "actionApply"));
panel.add(buttonApply);
// Validate button
buttonValidate = Utilities.createJButton(
GT._T("Validate"),
ConfigurationValueShortcut.VALIDATE);
buttonValidate.addActionListener(EventHandler.create(
ActionListener.class, this, "actionValidate"));
panel.add(buttonValidate);
// Cancel button
buttonCancel = ActionDispose.createButton(getParentComponent(), true, true);
panel.add(buttonCancel);
// Restore defaults button
buttonDefault = Utilities.createJButton(
GT._T("Restore defaults"),
ConfigurationValueShortcut.RESTORE_DEFAULTS);
buttonDefault.addActionListener(EventHandler.create(
ActionListener.class, this, "actionDefault"));
panel.add(buttonDefault);
return panel;
}
/**
* Add a component for the Disambiguation button.
*
* @param panel Container.
* @param icon Flag indicating if an icon should be used.
*/
protected void addButtonDisambiguation(JComponent panel, boolean icon) {
if (buttonDisambiguation == null) {
if (icon) {
buttonDisambiguation = Utilities.createJButton(
"commons-disambig-colour.png", EnumImageSize.NORMAL,
GT._T("Disambiguation"), false, null);
} else {
buttonDisambiguation = Utilities.createJButton(GT._T("Disambiguation"), null);
}
buttonDisambiguation.addActionListener(EventHandler.create(
ActionListener.class, this, "actionDisambiguation"));
panel.add(buttonDisambiguation);
}
}
/**
* Add a component for the Redirect buttons.
*
* @param panel Container.
*/
protected void addButtonRedirect(JComponent panel) {
buttonAnalysisRedirect = Utilities.createJButton(
"commons-redirect-arrow-without-text.png", EnumImageSize.NORMAL,
GT._T("Redirect"), false, null);
buttonAnalysisRedirect.addActionListener(EventHandler.create(
ActionListener.class, this, "actionAnalysisRedir"));
panel.add(buttonAnalysisRedirect);
}
/**
* Add an item to the generate lists menu.
*
* @param menu Menu.
* @param mode List to be generated.
*/
private void addItemInInternalLinks(JPopupMenu menu, PageListWorker.Mode mode) {
JMenuItem item = Utilities.createJMenuItem(mode.getTitle(), true);
item.setActionCommand(mode.name());
item.addActionListener(EventHandler.create(
ActionListener.class, this, "actionInternalLinks", "actionCommand"));
menu.add(item);
}
/**
* Add an item to the generate lists menu.
*
* @param menu Menu.
* @param mode List to be generated.
*/
private void addItemInGenerateLists(JPopupMenu menu, PageListWorker.Mode mode) {
JMenuItem item = Utilities.createJMenuItem(mode.getTitle(), true);
item.setActionCommand(mode.name());
item.addActionListener(EventHandler.create(
ActionListener.class, this, "actionGenerateList", "actionCommand"));
menu.add(item);
}
/**
* @return Filter namespace menu.
*/
private JMenu createFilterMenu() {
if (menuFilter == null) {
menuFilter = Utilities.createJMenu(GT._T("Filter namespaces"));
} else {
menuFilter.removeAll();
}
EnumWikipedia wiki = getWikipedia();
if (wiki == null) {
return menuFilter;
}
Configuration config = Configuration.getConfiguration();
List<String> filtered = config.getStringList(wiki, Configuration.ARRAY_FILTER_NS);
for (Namespace ns : wiki.getWikiConfiguration().getNamespaces()) {
Integer id = ns.getId();
if ((id != null) && (id.intValue() >= 0)) {
boolean active = !filtered.contains(Integer.toString(ns.getId()));
JMenuItem item = new JCheckBoxMenuItem(
ns.toString(), active);
item.setActionCommand(id.toString());
item.addActionListener(EventHandler.create(
ActionListener.class, this,
active ? "actionFilterNamespaceTrue" : "actionFilterNamespaceFalse",
"actionCommand"));
menuFilter.add(item);
}
}
return menuFilter;
}