From 6c4d18e3242bda4df55d9f2207134acb5ef26fbb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 6 Apr 2008 12:38:07 +0000 Subject: [PATCH] fix broken JMenuItem git-svn-id: http://trooper/svn/projects/jSite/trunk@617 c3eda9e8-030b-0410-8277-bc7414b0a119 --- .../pterodactylus/jsite/gui/FixedJMenuItem.java | 93 ++++++++++++++++++++++ src/net/pterodactylus/jsite/gui/MainWindow.java | 6 +- 2 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 src/net/pterodactylus/jsite/gui/FixedJMenuItem.java diff --git a/src/net/pterodactylus/jsite/gui/FixedJMenuItem.java b/src/net/pterodactylus/jsite/gui/FixedJMenuItem.java new file mode 100644 index 0000000..5f0940a --- /dev/null +++ b/src/net/pterodactylus/jsite/gui/FixedJMenuItem.java @@ -0,0 +1,93 @@ +/* + * jSite2 - I18nMenuItem.java - + * Copyright © 2008 David Roden + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.pterodactylus.jsite.gui; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JMenuItem; +import javax.swing.KeyStroke; + +/** + * MenuItem which fixes the bug that when the {@link Action#ACCELERATOR_KEY} + * value of the action the JMenuItem is based upen is changed this change is not + * picked up (see bug + * #4304129). + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + * @version $Id$ + */ +public class FixedJMenuItem extends JMenuItem { + + /** + * Creates a new fixed menu item. + * + * @param action + * The action of the menu item + */ + public FixedJMenuItem(Action action) { + super(action); + } + + /** + * {@inheritDoc} + */ + @Override + protected PropertyChangeListener createActionPropertyChangeListener(Action a) { + return new PropertyChangeListener() { + + /** + * {@inheritDoc} + */ + public void propertyChange(PropertyChangeEvent propertyChangeEvent) { + String propertyName = propertyChangeEvent.getPropertyName(); + JMenuItem menuItem = FixedJMenuItem.this; + if (propertyChangeEvent.getPropertyName().equals(Action.NAME)) { + String text = (String) propertyChangeEvent.getNewValue(); + menuItem.setText(text); + menuItem.repaint(); + } else if (propertyName.equals("enabled")) { + Boolean enabledState = (Boolean) propertyChangeEvent.getNewValue(); + menuItem.setEnabled(enabledState.booleanValue()); + menuItem.repaint(); + } else if (propertyChangeEvent.getPropertyName().equals(Action.SMALL_ICON)) { + Icon icon = (Icon) propertyChangeEvent.getNewValue(); + menuItem.setIcon(icon); + menuItem.invalidate(); + menuItem.repaint(); + } else if (propertyChangeEvent.getPropertyName().equals(Action.MNEMONIC_KEY)) { + Integer mn = (Integer) propertyChangeEvent.getNewValue(); + menuItem.setMnemonic(mn.intValue()); + menuItem.invalidate(); + menuItem.repaint(); + } else if (propertyChangeEvent.getPropertyName().equals(Action.ACCELERATOR_KEY)) { + KeyStroke keyStroke = (KeyStroke) propertyChangeEvent.getNewValue(); + menuItem.setAccelerator(keyStroke); + menuItem.invalidate(); + menuItem.repaint(); + } + } + }; + } + +} diff --git a/src/net/pterodactylus/jsite/gui/MainWindow.java b/src/net/pterodactylus/jsite/gui/MainWindow.java index 97b9fe5..694cc98 100644 --- a/src/net/pterodactylus/jsite/gui/MainWindow.java +++ b/src/net/pterodactylus/jsite/gui/MainWindow.java @@ -102,10 +102,10 @@ public class MainWindow extends JFrame implements I18nable { nodeMenu = new I18nMenu("mainWindow.menu.node"); menuBar.add(nodeMenu); - nodeMenu.add(swingInterface.getManageNodesAction()); + nodeMenu.add(new FixedJMenuItem(swingInterface.getManageNodesAction())); nodeMenu.addSeparator(); - nodeMenu.add(swingInterface.getNodeConnectAction()); - nodeMenu.add(swingInterface.getNodeDisconnectAction()); + nodeMenu.add(new FixedJMenuItem(swingInterface.getNodeConnectAction())); + nodeMenu.add(new FixedJMenuItem(swingInterface.getNodeDisconnectAction())); languageMenu = new I18nMenu("mainWindow.menu.language"); menuBar.add(languageMenu); -- 2.7.4