From: <aki...@us...> - 2013-07-14 20:50:08
|
Revision: 9340 http://sourceforge.net/p/gridarta/code/9340 Author: akirschbaum Date: 2013-07-14 20:50:04 +0000 (Sun, 14 Jul 2013) Log Message: ----------- Convert GameObjectAttributesDialog.TypesBoxItemListener to anonymous class. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java 2013-07-14 20:44:18 UTC (rev 9339) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java 2013-07-14 20:50:04 UTC (rev 9340) @@ -139,6 +139,7 @@ /** * Common base class for game object attributes dialogs. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @author Andreas Kirschbaum */ public class GameObjectAttributesDialog<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends JOptionPane { @@ -734,6 +735,66 @@ }; /** + * ItemListener for the type-selection box on the attribute dialog. + */ + @NotNull + private final ItemListener typesBoxItemListener = new ItemListener() { + + /** + * The latest deselected item. + */ + @Nullable + private ArchetypeType deselected; + + /** + * While <code>true</code>, this listener ignores all events. + */ + private boolean ignoreEvent; + + /** + * {@inheritDoc} + */ + @Override + public void itemStateChanged(@NotNull final ItemEvent e) { + if (ignoreEvent) { + return; + } + + if (e.getStateChange() == ItemEvent.DESELECTED) { + deselected = (ArchetypeType) e.getItem(); + } else if (e.getStateChange() == ItemEvent.SELECTED && !e.getItem().equals(deselected)) { + final ArchetypeType newType = (ArchetypeType) e.getItem(); + + final JComboBox typeComboBox = (JComboBox) e.getSource(); + + typeComboBox.hidePopup(); + + if (deselected == null) { + deselected = archetypeType; + } + if (JOptionPane.showConfirmDialog(GameObjectAttributesDialog.this, "Do you really want to change the type of this\n" + "object from \"" + deselected.getTypeName() + "\" to \"" + newType.getTypeName() + "\"?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { + archetypeType = newType; + + final MapModel<G, A, R> mapModel = gameObject.getMapSquare().getMapModel(); + mapModel.beginTransaction("change type to " + newType.getTypeName()); + try { + gameObject.setAttributeInt(BaseObject.TYPE, newType.getTypeNo()); + } finally { + mapModel.endTransaction(); + } + + buildAttribute(); + } else { + ignoreEvent = true; + typeComboBox.setSelectedItem(archetypeType); + ignoreEvent = false; + } + } + } + + }; + + /** * Creates a new instance. * @param gameObjectAttributesDialogFactory the associated factory * @param archetypeTypeSet the reference to the list of archetype types @@ -879,7 +940,7 @@ typeComboBox.setName("Types"); - typeComboBox.addItemListener(new TypesBoxItemListener()); + typeComboBox.addItemListener(typesBoxItemListener); return typeComboBox; } @@ -1375,72 +1436,4 @@ return comboBox; } - /** - * ItemListener for the type-selection box on the attribute-dialog. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @author Andreas Kirschbaum - */ - private class TypesBoxItemListener implements ItemListener { - - /** - * The latest deselected item. - */ - @Nullable - private ArchetypeType deselected; - - /** - * While <code>true</code>, this listener ignores all events. - */ - private boolean ignoreEvent; - - /** - * Creates a new instance. - */ - private TypesBoxItemListener() { - ignoreEvent = false; - } - - /** - * {@inheritDoc} - */ - @Override - public void itemStateChanged(@NotNull final ItemEvent e) { - if (ignoreEvent) { - return; - } - - if (e.getStateChange() == ItemEvent.DESELECTED) { - deselected = (ArchetypeType) e.getItem(); - } else if (e.getStateChange() == ItemEvent.SELECTED && !e.getItem().equals(deselected)) { - final ArchetypeType newType = (ArchetypeType) e.getItem(); - - final JComboBox typeComboBox = (JComboBox) e.getSource(); - - typeComboBox.hidePopup(); - - if (deselected == null) { - deselected = archetypeType; - } - if (JOptionPane.showConfirmDialog(GameObjectAttributesDialog.this, "Do you really want to change the type of this\n" + "object from \"" + deselected.getTypeName() + "\" to \"" + newType.getTypeName() + "\"?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { - archetypeType = newType; - - final MapModel<G, A, R> mapModel = gameObject.getMapSquare().getMapModel(); - mapModel.beginTransaction("change type to " + newType.getTypeName()); - try { - gameObject.setAttributeInt(BaseObject.TYPE, newType.getTypeNo()); - } finally { - mapModel.endTransaction(); - } - - buildAttribute(); - } else { - ignoreEvent = true; - typeComboBox.setSelectedItem(archetypeType); - ignoreEvent = false; - } - } - } - - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |