--- /dev/null
+/*
+ * 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 <a
+ * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4304129">bug
+ * #4304129</a>).
+ *
+ * @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();
+ }
+ }
+ };
+ }
+
+}