dmolony-DiskBrowser/src/com/bytezone/diskbrowser/gui/NextPaletteAction.java

55 lines
1.9 KiB
Java
Raw Normal View History

2017-01-14 01:40:58 +00:00
package com.bytezone.diskbrowser.gui;
import java.awt.event.ActionEvent;
import java.util.Enumeration;
2020-02-08 22:20:08 +00:00
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.KeyStroke;
2017-01-14 01:40:58 +00:00
import com.bytezone.diskbrowser.applefile.Palette;
import com.bytezone.diskbrowser.applefile.PaletteFactory.CycleDirection;
2020-02-08 22:20:08 +00:00
// -----------------------------------------------------------------------------------//
class NextPaletteAction extends AbstractAction
// -----------------------------------------------------------------------------------//
2017-01-14 01:40:58 +00:00
{
private final DataPanel owner;
private final ButtonGroup buttonGroup;
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
NextPaletteAction (DataPanel owner, ButtonGroup buttonGroup)
// ---------------------------------------------------------------------------------//
2017-01-14 01:40:58 +00:00
{
super ("Next Palette");
putValue (Action.SHORT_DESCRIPTION, "Select next color palette");
2017-01-26 04:19:23 +00:00
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("meta alt N"));
2017-01-14 01:40:58 +00:00
this.owner = owner;
this.buttonGroup = buttonGroup;
}
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
2017-01-14 01:40:58 +00:00
@Override
public void actionPerformed (ActionEvent e)
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
2017-01-14 01:40:58 +00:00
{
Palette palette = owner.cyclePalette (CycleDirection.FORWARDS);
2017-01-14 11:11:07 +00:00
2017-01-14 01:40:58 +00:00
if (palette != null)
{
Enumeration<AbstractButton> enumeration = buttonGroup.getElements ();
while (enumeration.hasMoreElements ())
{
JCheckBoxMenuItem item = (JCheckBoxMenuItem) enumeration.nextElement ();
if (item.getText ().equals (palette.getName ()))
{
item.setSelected (true);
break;
}
}
}
}
}