home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
JActionMenuItem.java
< prev
next >
Wrap
Text File
|
1998-10-07
|
4KB
|
132 lines
package com.symantec.itools.swing.actions;
import java.beans.*;
import com.sun.java.swing.*;
public class JActionMenuItem
extends JMenuItem
{
public JActionMenuItem()
{
setHorizontalTextPosition(RIGHT);
setVerticalTextPosition(CENTER);
}
public JActionMenuItem(com.sun.java.swing.Action newAction)
{
this();
setAction(newAction);
}
//
// Properties
//
// Action
public com.sun.java.swing.Action getAction()
{
return m_Action;
}
public void setAction(com.sun.java.swing.Action newAction)
{
//Handle bad arg
if (newAction == null)
throw new IllegalArgumentException();
//Do nothing if no change
if (newAction == m_Action)
return;
//Release last action
if (m_Action != null)
{
removeActionListener(m_Action);
m_Action.removePropertyChangeListener(m_ActionPropertyChangeListener);
}
m_Action = newAction;
addActionListener(m_Action);
m_ActionPropertyChangeListener = createActionChangeListener();
m_Action.addPropertyChangeListener(m_ActionPropertyChangeListener);
updateMenuItem();
}
//
// Implementation
//
protected PropertyChangeListener createActionChangeListener()
{
return new ActionChangedListener();
}
protected class ActionChangedListener implements PropertyChangeListener
{
public void propertyChange(PropertyChangeEvent e) {
String propertyName = e.getPropertyName();
if (propertyName.equals(Action.NAME)) {
String text = (String) e.getNewValue();
setText(text);
} else if (propertyName.equals("enabled")) {
Boolean enabledState = (Boolean) e.getNewValue();
setEnabled(enabledState.booleanValue());
} else if (propertyName.equals(Action.SMALL_ICON)) {
Icon icon = (Icon) e.getNewValue();
setIcon(icon);
invalidate();
repaint();
}
}
}
public void setIcon(Icon newIcon)
{
if (newIcon == null)
{
super.setIcon(null);
setDisabledIcon(null);
}
else
{
super.setIcon(newIcon);
if (!(newIcon instanceof com.sun.java.swing.ImageIcon))
{
if (newIcon instanceof com.symantec.itools.swing.icons.ImageIcon)
{
setDisabledIcon
(new com.sun.java.swing.ImageIcon
(GrayFilter.createDisabledImage
(((com.symantec.itools.swing.icons.ImageIcon)newIcon).getImage())));
}
}
}
}
protected void updateMenuItem()
{
if (m_Action == null)
{
setText("");
setIcon(null);
setEnabled(true);
}
else
{
setText((String)m_Action.getValue(Action.NAME));
setEnabled(m_Action.isEnabled());
setIcon((Icon)m_Action.getValue(Action.SMALL_ICON));
}
invalidate();
repaint();
}
protected com.sun.java.swing.Action m_Action = null;
protected PropertyChangeListener m_ActionPropertyChangeListener = null;
}