From: <aki...@us...> - 2013-06-01 13:10:54
|
Revision: 9259 http://sourceforge.net/p/gridarta/code/9259 Author: akirschbaum Date: 2013-06-01 13:10:50 +0000 (Sat, 01 Jun 2013) Log Message: ----------- Rename identifiers. Modified Paths: -------------- 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/GuiInfo.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-06-01 12:11:21 UTC (rev 9258) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java 2013-06-01 13:10:50 UTC (rev 9259) @@ -426,26 +426,26 @@ public void visit(@NotNull final ArchetypeAttributeBitmask archetypeAttribute) { final JTextArea input = new JTextArea(); final DialogAttributeBitmask<G, A, R> tmpAttribute = new DialogAttributeBitmask<G, A, R>(archetypeAttribute, input); - @Nullable final JTextArea cComp; - @Nullable final JButton cLabel; - @Nullable final JLabel cRow; + @Nullable final JTextArea component; + @Nullable final JButton label; + @Nullable final JLabel row; final AttributeBitmask bitmask = archetypeTypeSet.getBitmask(archetypeAttribute.getBitmaskName()); if (bitmask != null) { tmpAttribute.setBitmask(bitmask); - cLabel = new JButton(new MaskChangeAL<G, A, R>(archetypeAttribute.getAttributeName() + ":", tmpAttribute)); + label = new JButton(new MaskChangeAL<G, A, R>(archetypeAttribute.getAttributeName() + ":", tmpAttribute)); input.setBackground(getBackground()); input.setEditable(false); input.setBorder(BorderFactory.createLineBorder(Color.gray)); input.setText(bitmask.getText(tmpAttribute.getValue())); - cComp = input; + component = input; tmpAttribute.setEncodedValue(gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName())); - cRow = null; + row = null; } else { - cLabel = null; - cComp = null; - cRow = new JLabel("Error: Undefined Bitmask"); + label = null; + component = null; + row = new JLabel("Error: Undefined Bitmask"); } - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBitmask>(tmpAttribute, cLabel, cComp, cRow, null, false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBitmask>(tmpAttribute, label, component, row, null, false); } @Override @@ -472,8 +472,8 @@ final String attributeName = archetypeAttribute.getArchetypeAttributeName(); final String defaultText = gameObject.getAttributeString(attributeName); final FaceComponent input = new FaceComponent(defaultText, faceObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon); - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ":"); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeFaceName>(new DialogAttributeFaceName<G, A, R>(archetypeAttribute, input), cLabel, input, null, null, false); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ":"); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeFaceName>(new DialogAttributeFaceName<G, A, R>(archetypeAttribute, input), label, input, null, null, false); } @Override @@ -483,8 +483,8 @@ @Override public void visit(@NotNull final ArchetypeAttributeFloat archetypeAttribute) { - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); - cLabel.setForeground(FLOAT_COLOR); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(FLOAT_COLOR); final int fieldLength = archetypeAttribute.getInputLength() == 0 ? ArchetypeAttribute.TEXTFIELD_COLUMNS : archetypeAttribute.getInputLength(); final DecimalFormat format = new DecimalFormat("#0.0#"); format.setMaximumFractionDigits(10); @@ -496,13 +496,13 @@ final Number value = gameObject.getAttributeDouble(archetypeAttribute.getArchetypeAttributeName()); final JFormattedTextField input = new JFormattedTextField(factory, value); input.setColumns(fieldLength); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeFloat>(new DialogAttributeFloat<G, A, R>(archetypeAttribute, input), cLabel, input, null, null, false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeFloat>(new DialogAttributeFloat<G, A, R>(archetypeAttribute, input), label, input, null, null, false); } @Override public void visit(@NotNull final ArchetypeAttributeInt archetypeAttribute) { - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); - cLabel.setForeground(INT_COLOR); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); final int fieldLength = archetypeAttribute.getInputLength() == 0 ? ArchetypeAttribute.TEXTFIELD_COLUMNS : archetypeAttribute.getInputLength(); final NumberFormat format = NumberFormat.getIntegerInstance(); format.setGroupingUsed(false); @@ -512,42 +512,42 @@ final Number value = gameObject.getAttributeInt(archetypeAttribute.getArchetypeAttributeName()); final JFormattedTextField input = new JFormattedTextField(factory, value); input.setColumns(fieldLength); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeInt>(new DialogAttributeInt<G, A, R>(archetypeAttribute, input), cLabel, input, null, null, false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeInt>(new DialogAttributeInt<G, A, R>(archetypeAttribute, input), label, input, null, null, false); } @Override public void visit(@NotNull final ArchetypeAttributeInvSpell archetypeAttribute) { - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); - cLabel.setForeground(INT_COLOR); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); // create ComboBox with parsed selection @Nullable final JComboBox input = buildInvSpellBox(gameObjectSpells, gameObject, archetypeAttribute.isOptionalSpell(), archetypeAttribute.getAttributeName()); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeInvSpell>(new DialogAttributeInvSpell<G, A, R>(archetypeAttribute.isOptionalSpell(), archetypeAttribute, input, gameObjectSpells), cLabel, input, null, null, false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeInvSpell>(new DialogAttributeInvSpell<G, A, R>(archetypeAttribute.isOptionalSpell(), archetypeAttribute, input, gameObjectSpells), label, input, null, null, false); } @Override public void visit(@NotNull final ArchetypeAttributeList archetypeAttribute) { - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); - cLabel.setForeground(INT_COLOR); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); // create ComboBox with parsed selection - final JComponent cComp; + final JComponent component; @Nullable final JComboBox input; final ArchetypeTypeList list = archetypeTypeSet.getList(archetypeAttribute.getListName()); if (list != null) { // build the list from vector data input = buildArrayBox(list, gameObject, archetypeAttribute.getArchetypeAttributeName(), archetypeAttribute.getAttributeName()); - cComp = input; + component = input; } else { // error: list data is missing or corrupt input = new JComboBox(); - cComp = new JLabel("Error: Undefined List"); + component = new JLabel("Error: Undefined List"); } - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeList>(new DialogAttributeList<G, A, R>(archetypeAttribute, input, archetypeTypeSet), cLabel, cComp, null, null, false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeList>(new DialogAttributeList<G, A, R>(archetypeAttribute, input, archetypeTypeSet), label, component, null, null, false); } @Override public void visit(@NotNull final ArchetypeAttributeLong archetypeAttribute) { - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); - cLabel.setForeground(INT_COLOR); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); final int fieldLength = archetypeAttribute.getInputLength() == 0 ? ArchetypeAttribute.TEXTFIELD_COLUMNS : archetypeAttribute.getInputLength(); final NumberFormat format = NumberFormat.getIntegerInstance(); format.setGroupingUsed(false); @@ -557,7 +557,7 @@ final Number value = gameObject.getAttributeLong(archetypeAttribute.getArchetypeAttributeName()); final JFormattedTextField input = new JFormattedTextField(factory, value); input.setColumns(fieldLength); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeLong>(new DialogAttributeLong<G, A, R>(archetypeAttribute, input), cLabel, input, null, null, false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeLong>(new DialogAttributeLong<G, A, R>(archetypeAttribute, input), label, input, null, null, false); } @Override @@ -567,34 +567,34 @@ if (relativeReference == null) { relativeReference = new File(globalSettings.getMapsDirectory(), "dummy"); } - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); final TilePanel tilePanel = new TilePanel(mapFileFilter, gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName()), relativeReference, globalSettings.getMapsDirectory()); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeMapPath>(new DialogAttributeMapPath<G, A, R>(archetypeAttribute, tilePanel), cLabel, tilePanel, null, null, false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeMapPath>(new DialogAttributeMapPath<G, A, R>(archetypeAttribute, tilePanel), label, tilePanel, null, null, false); } @Override public void visit(@NotNull final ArchetypeAttributeScriptFile archetypeAttribute) { - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); final File mapsDirectory = globalSettings.getMapsDirectory(); final TilePanel tilePanel = new TilePanel(scriptFileFilter, gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName()), new File(mapsDirectory, "dummy"), mapsDirectory); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeScriptFile>(new DialogAttributeScriptFile<G, A, R>(archetypeAttribute, tilePanel), cLabel, tilePanel, null, null, false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeScriptFile>(new DialogAttributeScriptFile<G, A, R>(archetypeAttribute, tilePanel), label, tilePanel, null, null, false); } @Override public void visit(@NotNull final ArchetypeAttributeSpell archetypeAttribute) { - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); - cLabel.setForeground(INT_COLOR); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); // create ComboBox with parsed selection @Nullable final JComboBox input = buildSpellBox(gameObject, numberSpells, undefinedSpellIndex, false, archetypeAttribute); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeSpell>(new DialogAttributeSpell<G, A, R>(archetypeAttribute, input, numberSpells), cLabel, input, null, null, false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeSpell>(new DialogAttributeSpell<G, A, R>(archetypeAttribute, input, numberSpells), label, input, null, null, false); } @Override public void visit(@NotNull final ArchetypeAttributeString archetypeAttribute) { final String defaultText = gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName()); final JTextField input = new JTextField(defaultText, ArchetypeAttribute.TEXTFIELD_COLUMNS); - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeString>(new DialogAttributeString<G, A, R>(archetypeAttribute, input), cLabel, input, null, null, false); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeString>(new DialogAttributeString<G, A, R>(archetypeAttribute, input), label, input, null, null, false); } @Override @@ -629,17 +629,17 @@ final JTextField input = new JTextField(" " + treasureName, ArchetypeAttribute.TEXTFIELD_COLUMNS); input.setEditable(false); final DialogAttributeTreasure<G, A, R> tmpAttribute = new DialogAttributeTreasure<G, A, R>(archetypeAttribute, input, treasureTree); - final JButton cLabel = new JButton(new ViewTreasurelistAL(input, GameObjectAttributesDialog.this, treasureListTree)); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeTreasure>(tmpAttribute, cLabel, input, null, null, false); + final JButton label = new JButton(new ViewTreasurelistAL(input, GameObjectAttributesDialog.this, treasureListTree)); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeTreasure>(tmpAttribute, label, input, null, null, false); } @Override public void visit(@NotNull final ArchetypeAttributeZSpell archetypeAttribute) { - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); - cLabel.setForeground(INT_COLOR); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); // create ComboBox with parsed selection @Nullable final JComboBox input = buildSpellBox(gameObject, numberSpells, undefinedSpellIndex, true, archetypeAttribute); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeZSpell>(new DialogAttributeZSpell<G, A, R>(archetypeAttribute, input, numberSpells, undefinedSpellIndex), cLabel, input, null, null, false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeZSpell>(new DialogAttributeZSpell<G, A, R>(archetypeAttribute, input, numberSpells, undefinedSpellIndex), label, input, null, null, false); } }; @@ -1043,10 +1043,10 @@ dialogAttributes.add(tmpGuiInfo.getNewAttr()); helpButton.addActionListener(new HelpActionListener(tmpGuiInfo.getNewAttr().getRef(), this)); - addElement(panel, tmpGuiInfo.getCLabel(), labelGbc); - addElement(panel, tmpGuiInfo.getCComp(), compGbc); - addElement(panel, tmpGuiInfo.getCRow(), rowGbc); - addElement(panel, tmpGuiInfo.getCGlue(), glueGbc); + addElement(panel, tmpGuiInfo.getLabel(), labelGbc); + addElement(panel, tmpGuiInfo.getComponent(), compGbc); + addElement(panel, tmpGuiInfo.getRow(), rowGbc); + addElement(panel, tmpGuiInfo.getGlue(), glueGbc); isText |= tmpGuiInfo.isText(); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java 2013-06-01 12:11:21 UTC (rev 9258) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java 2013-06-01 13:10:50 UTC (rev 9259) @@ -39,25 +39,25 @@ private final DialogAttribute<G, A, R, T> newAttr; @Nullable - private final Component cLabel; + private final Component label; @Nullable - private final Component cComp; + private final Component component; @Nullable - private final Component cRow; + private final Component row; @Nullable - private final Component cGlue; + private final Component glue; private final boolean isText; - public GuiInfo(@NotNull final DialogAttribute<G, A, R, T> newAttr, @Nullable final Component cLabel, @Nullable final Component cComp, @Nullable final Component cRow, @Nullable final Component cGlue, final boolean isText) { + public GuiInfo(@NotNull final DialogAttribute<G, A, R, T> newAttr, @Nullable final Component label, @Nullable final Component component, @Nullable final Component row, @Nullable final Component glue, final boolean isText) { this.newAttr = newAttr; - this.cLabel = cLabel; - this.cComp = cComp; - this.cRow = cRow; - this.cGlue = cGlue; + this.label = label; + this.component = component; + this.row = row; + this.glue = glue; this.isText = isText; } @@ -67,23 +67,23 @@ } @Nullable - public Component getCLabel() { - return cLabel; + public Component getLabel() { + return label; } @Nullable - public Component getCComp() { - return cComp; + public Component getComponent() { + return component; } @Nullable - public Component getCRow() { - return cRow; + public Component getRow() { + return row; } @Nullable - public Component getCGlue() { - return cGlue; + public Component getGlue() { + return glue; } public boolean isText() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2013-07-14 19:25:34
|
Revision: 9336 http://sourceforge.net/p/gridarta/code/9336 Author: akirschbaum Date: 2013-07-14 19:25:30 +0000 (Sun, 14 Jul 2013) Log Message: ----------- Remove unused code. Modified Paths: -------------- 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/TypesBoxItemListener.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 19:02:55 UTC (rev 9335) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java 2013-07-14 19:25:30 UTC (rev 9336) @@ -880,7 +880,7 @@ typeComboBox.setName("Types"); // the listener: - typesBoxItemListener = new TypesBoxItemListener<G, A, R>(this, gameObject, type, archetypeTypeSet, dialogAttributes, typeComboBox, archetypeType); + typesBoxItemListener = new TypesBoxItemListener<G, A, R>(this, gameObject, type, archetypeTypeSet, typeComboBox, archetypeType); typeComboBox.addItemListener(typesBoxItemListener); return typeComboBox; } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/TypesBoxItemListener.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/TypesBoxItemListener.java 2013-07-14 19:02:55 UTC (rev 9335) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/TypesBoxItemListener.java 2013-07-14 19:25:30 UTC (rev 9336) @@ -21,8 +21,6 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; -import java.util.ArrayList; -import java.util.Collection; import javax.swing.JComboBox; import javax.swing.JOptionPane; import net.sf.gridarta.model.archetype.Archetype; @@ -61,12 +59,6 @@ private final ArchetypeTypeSet archetypeTypeSet; /** - * The {@link DialogAttribute DialogAttributes} to update. - */ - @NotNull - private final Collection<DialogAttribute<G, A, R, ?>> dialogAttributes; - - /** * The selection box for the type. */ @NotNull @@ -103,16 +95,14 @@ * @param gameObject the game object which has the error to be added * @param type the initially selected type * @param archetypeTypeSet the archetype type set to display - * @param dialogAttributes the dialog attributes to update * @param typeComboBox the selection box for the type * @param archetypeType the references to the data type */ - public TypesBoxItemListener(@NotNull final GameObjectAttributesDialog<G, A, R> frameNew, @NotNull final GameObject<G, A, R> gameObject, final int type, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Collection<DialogAttribute<G, A, R, ?>> dialogAttributes, @NotNull final JComboBox typeComboBox, @NotNull final ArchetypeType archetypeType) { + public TypesBoxItemListener(@NotNull final GameObjectAttributesDialog<G, A, R> frameNew, @NotNull final GameObject<G, A, R> gameObject, final int type, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final JComboBox typeComboBox, @NotNull final ArchetypeType archetypeType) { gameObjectAttributesDialog = frameNew; this.gameObject = gameObject; this.type = type; this.archetypeTypeSet = archetypeTypeSet; - this.dialogAttributes = new ArrayList<DialogAttribute<G, A, R, ?>>(dialogAttributes); this.typeComboBox = typeComboBox; this.archetypeType = archetypeType; ignoreEvent = false; @@ -147,7 +137,6 @@ } finally { mapModel.endTransaction(); } - dialogAttributes.clear(); type = typeComboBox.getSelectedIndex(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2013-07-14 19:41:06
|
Revision: 9337 http://sourceforge.net/p/gridarta/code/9337 Author: akirschbaum Date: 2013-07-14 19:41:03 +0000 (Sun, 14 Jul 2013) Log Message: ----------- Simplify code. Modified Paths: -------------- 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/TypesBoxItemListener.java Added Paths: ----------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/ArchetypeTypeListCellRenderer.java Added: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/ArchetypeTypeListCellRenderer.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/ArchetypeTypeListCellRenderer.java (rev 0) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/ArchetypeTypeListCellRenderer.java 2013-07-14 19:41:03 UTC (rev 9337) @@ -0,0 +1,50 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.dialog.gameobjectattributes; + +import java.awt.Component; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; +import net.sf.gridarta.model.archetypetype.ArchetypeType; + +/** + * A {@link javax.swing.ListCellRenderer ListCellRenderer} implementation that + * displays {@link ArchetypeType ArchetypeTypes}. + */ +public class ArchetypeTypeListCellRenderer extends DefaultListCellRenderer { + + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + + /* This is the only method defined by ListCellRenderer. We just + * reconfigure the label each time we're called. + */ + + @Override + public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + final ArchetypeType archetypeType = (ArchetypeType) value; + setText(archetypeType.getTypeName()); + return this; + } + +} Property changes on: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/ArchetypeTypeListCellRenderer.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property 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 19:25:30 UTC (rev 9336) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java 2013-07-14 19:41:03 UTC (rev 9337) @@ -861,26 +861,27 @@ */ @NotNull private Component buildTypesBox(final int type, @NotNull final ArchetypeType archetypeType) { - final String[] nameList = new String[archetypeTypeSet.getArchetypeTypeCount()]; + final ArchetypeType[] model = new ArchetypeType[archetypeTypeSet.getArchetypeTypeCount()]; // read all type names int i = 0; for (final ArchetypeType tmp : archetypeTypeSet) { - nameList[i++] = " " + tmp.getTypeName(); + model[i++] = tmp; } // the active type appears selected in the box final int selection = type; - final JComboBox typeComboBox = new JComboBox(nameList); + final JComboBox typeComboBox = new JComboBox(model); typeComboBox.setSelectedIndex(selection); + typeComboBox.setRenderer(new ArchetypeTypeListCellRenderer()); //typeComboBox.setKeySelectionManager(new StringKeyManager(typeComboBox)); typeComboBox.setName("Types"); // the listener: - typesBoxItemListener = new TypesBoxItemListener<G, A, R>(this, gameObject, type, archetypeTypeSet, typeComboBox, archetypeType); + typesBoxItemListener = new TypesBoxItemListener<G, A, R>(this, gameObject, type, typeComboBox, archetypeType); typeComboBox.addItemListener(typesBoxItemListener); return typeComboBox; } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/TypesBoxItemListener.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/TypesBoxItemListener.java 2013-07-14 19:25:30 UTC (rev 9336) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/TypesBoxItemListener.java 2013-07-14 19:41:03 UTC (rev 9337) @@ -25,7 +25,6 @@ import javax.swing.JOptionPane; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.archetypetype.ArchetypeType; -import net.sf.gridarta.model.archetypetype.ArchetypeTypeSet; import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -53,12 +52,6 @@ private final GameObject<G, A, R> gameObject; /** - * The {@link ArchetypeTypeSet} to display. - */ - @NotNull - private final ArchetypeTypeSet archetypeTypeSet; - - /** * The selection box for the type. */ @NotNull @@ -75,7 +68,7 @@ * The latest deselected item. */ @Nullable - private String deselected; + private ArchetypeType deselected; /** * While <code>true</code>, this listener ignores all events. @@ -94,15 +87,13 @@ * @param frameNew the attribute dialog main frame * @param gameObject the game object which has the error to be added * @param type the initially selected type - * @param archetypeTypeSet the archetype type set to display * @param typeComboBox the selection box for the type * @param archetypeType the references to the data type */ - public TypesBoxItemListener(@NotNull final GameObjectAttributesDialog<G, A, R> frameNew, @NotNull final GameObject<G, A, R> gameObject, final int type, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final JComboBox typeComboBox, @NotNull final ArchetypeType archetypeType) { + public TypesBoxItemListener(@NotNull final GameObjectAttributesDialog<G, A, R> frameNew, @NotNull final GameObject<G, A, R> gameObject, final int type, @NotNull final JComboBox typeComboBox, @NotNull final ArchetypeType archetypeType) { gameObjectAttributesDialog = frameNew; this.gameObject = gameObject; this.type = type; - this.archetypeTypeSet = archetypeTypeSet; this.typeComboBox = typeComboBox; this.archetypeType = archetypeType; ignoreEvent = false; @@ -118,16 +109,16 @@ } if (e.getStateChange() == ItemEvent.DESELECTED) { - deselected = ((String) e.getItem()).trim(); + deselected = (ArchetypeType) e.getItem(); } else if (e.getStateChange() == ItemEvent.SELECTED && !e.getItem().equals(deselected)) { - final ArchetypeType newType = archetypeTypeSet.getArchetypeTypeByName((String) e.getItem()); + final ArchetypeType newType = (ArchetypeType) e.getItem(); typeComboBox.hidePopup(); if (deselected == null) { - deselected = archetypeType.getTypeName(); + deselected = archetypeType; } - if (JOptionPane.showConfirmDialog(gameObjectAttributesDialog, "Do you really want to change the type of this\n" + "object from \"" + deselected + "\" to \"" + newType.getTypeName() + "\"?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { + if (JOptionPane.showConfirmDialog(gameObjectAttributesDialog, "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(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2013-07-14 20:26:46
|
Revision: 9338 http://sourceforge.net/p/gridarta/code/9338 Author: akirschbaum Date: 2013-07-14 20:26:40 +0000 (Sun, 14 Jul 2013) Log Message: ----------- Convert TypesBoxItemListener to inner class of GameObjectAttributesDialog. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java Removed Paths: ------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/TypesBoxItemListener.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 19:41:03 UTC (rev 9337) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java 2013-07-14 20:26:40 UTC (rev 9338) @@ -30,6 +30,8 @@ import java.awt.Insets; import java.awt.Point; import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.io.File; import java.text.DecimalFormat; import java.text.NumberFormat; @@ -290,13 +292,6 @@ private final Collection<DialogAttribute<G, A, R, ?>> dialogAttributes = new ArrayList<DialogAttribute<G, A, R, ?>>(); /** - * The {@link TypesBoxItemListener} attached to the combo box box for - * selecting the object's type. - */ - @NotNull - private TypesBoxItemListener<G, A, R> typesBoxItemListener; - - /** * The panel for object's face (png). * @serial */ @@ -407,6 +402,12 @@ private GuiInfo<G, A, R, ?> guiInfo; /** + * The {@link ArchetypeType} of {@link #gameObject}. + */ + @NotNull + private ArchetypeType archetypeType; + + /** * The {@link ArchetypeAttributeVisitor} for creating GUI elements for * {@link ArchetypeAttribute ArchetypeAttributes}. */ @@ -789,8 +790,8 @@ mapManager.addMapManagerListener(mapManagerListener); // first split top-left and -right - final ArchetypeType archetypeType = archetypeTypeSet.getArchetypeTypeByBaseObject(gameObject); - final JComponent leftPane = buildHeader(archetypeTypeSet.getArchetypeTypeIndex(archetypeType), archetypeType); + archetypeType = archetypeTypeSet.getArchetypeTypeByBaseObject(gameObject); + final JComponent leftPane = buildHeader(); // Now split horizontally buildAttribute(); @@ -855,12 +856,10 @@ /** * Constructs the combo box of the available archetypes. - * @param type the initially selected type - * @param archetypeType the archetype type to display * @return a <code>JComponent</code> with the combo box in it */ @NotNull - private Component buildTypesBox(final int type, @NotNull final ArchetypeType archetypeType) { + private Component buildTypesBox() { final ArchetypeType[] model = new ArchetypeType[archetypeTypeSet.getArchetypeTypeCount()]; // read all type names @@ -870,7 +869,7 @@ } // the active type appears selected in the box - final int selection = type; + final int selection = archetypeTypeSet.getArchetypeTypeIndex(archetypeType); final JComboBox typeComboBox = new JComboBox(model); typeComboBox.setSelectedIndex(selection); @@ -880,9 +879,7 @@ typeComboBox.setName("Types"); - // the listener: - typesBoxItemListener = new TypesBoxItemListener<G, A, R>(this, gameObject, type, typeComboBox, archetypeType); - typeComboBox.addItemListener(typesBoxItemListener); + typeComboBox.addItemListener(new TypesBoxItemListener(selection)); return typeComboBox; } @@ -899,13 +896,11 @@ /** * Constructs the upper left part of the attribute dialog, containing name, * type, archetype name and face. - * @param type the initially selected type - * @param archetypeType the archetype type to display * @return a <code>JScrollPane</code> with the upper left part of the dialog * window */ @NotNull - private JComponent buildHeader(final int type, @NotNull final ArchetypeType archetypeType) { + private JComponent buildHeader() { final JComponent header = new JPanel(new GridBagLayout()); // the final thing, in a panel final GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; @@ -946,7 +941,7 @@ nameTextField.setEditable(false); header.add(nameTextField, gbc); gbc.gridy++; - header.add(buildTypesBox(type, archetypeType), gbc); // build type-selection box + header.add(buildTypesBox(), gbc); // build type-selection box gbc.gridy++; final JTextComponent archetypeTextField = new JTextField(archetype.getArchetypeName(), 16); archetypeTextField.setEditable(false); @@ -961,7 +956,6 @@ */ public final void buildAttribute() { tabbedPane.removeAll(); - final ArchetypeType archetypeType = typesBoxItemListener.getArchetypeType(); int sectionId = 0; for (final ArchetypeAttributeSection archetypeAttributeSection : archetypeType) { final Component panel = makeAttributePanel(archetypeAttributeSection); @@ -1091,7 +1085,6 @@ */ @ActionMethod public void attribHelp() { - final ArchetypeType archetypeType = typesBoxItemListener.getArchetypeType(); final String helpText = ACTION_BUILDER.format("arcDoc.htmlText", archetypeType.getTypeName(), archetypeType.getDescription(), archetypeType.getUse()); new Help(/* XXX */ parent, helpText).setVisible(true); } @@ -1198,7 +1191,7 @@ } // Also write all the 'fixed' attributes into the archetype text - for (final ArchetypeAttributeSection archetypeAttributeSection : typesBoxItemListener.getArchetypeType()) { + for (final ArchetypeAttributeSection archetypeAttributeSection : archetypeType) { for (final ArchetypeAttribute archetypeAttribute : archetypeAttributeSection) { // ### TODO: for changed types, copy fixed attributes over default arches ### if (archetypeAttribute instanceof ArchetypeAttributeFixed) { @@ -1382,4 +1375,82 @@ 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; + + /** + * The position of this type in the type list. This differs from the + * GameObject if the type is undefined. + * @serial + */ + private int type; + + /** + * Creates a new instance. + * @param type the initially selected type + */ + private TypesBoxItemListener(final int type) { + this.type = type; + 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; + type = typeComboBox.getSelectedIndex(); + + 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.setSelectedIndex(type); + ignoreEvent = false; + } + } + } + + } + } Deleted: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/TypesBoxItemListener.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/TypesBoxItemListener.java 2013-07-14 19:41:03 UTC (rev 9337) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/TypesBoxItemListener.java 2013-07-14 20:26:40 UTC (rev 9338) @@ -1,152 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2011 The Gridarta Developers. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package net.sf.gridarta.gui.dialog.gameobjectattributes; - -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import javax.swing.JComboBox; -import javax.swing.JOptionPane; -import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.archetypetype.ArchetypeType; -import net.sf.gridarta.model.baseobject.BaseObject; -import net.sf.gridarta.model.gameobject.GameObject; -import net.sf.gridarta.model.maparchobject.MapArchObject; -import net.sf.gridarta.model.mapmodel.MapModel; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * ItemListener for the type-selection box on the attribute-dialog. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @author Andreas Kirschbaum - */ -public class TypesBoxItemListener<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements ItemListener { - - /** - * The attribute dialog main frame. - */ - @NotNull - private final GameObjectAttributesDialog<G, A, R> gameObjectAttributesDialog; - - /** - * The game object which has the error to be added. - */ - @NotNull - private final GameObject<G, A, R> gameObject; - - /** - * The selection box for the type. - */ - @NotNull - private final JComboBox typeComboBox; - - /** - * Reference to the type data. - * @serial - */ - @NotNull - private ArchetypeType archetypeType; - - /** - * The latest deselected item. - */ - @Nullable - private ArchetypeType deselected; - - /** - * While <code>true</code>, this listener ignores all events. - */ - private boolean ignoreEvent; - - /** - * The position of this type in the type list. This differs from the - * GameObject if the type is undefined. - * @serial - */ - private int type; - - /** - * Creates a new instance. - * @param frameNew the attribute dialog main frame - * @param gameObject the game object which has the error to be added - * @param type the initially selected type - * @param typeComboBox the selection box for the type - * @param archetypeType the references to the data type - */ - public TypesBoxItemListener(@NotNull final GameObjectAttributesDialog<G, A, R> frameNew, @NotNull final GameObject<G, A, R> gameObject, final int type, @NotNull final JComboBox typeComboBox, @NotNull final ArchetypeType archetypeType) { - gameObjectAttributesDialog = frameNew; - this.gameObject = gameObject; - this.type = type; - this.typeComboBox = typeComboBox; - this.archetypeType = archetypeType; - 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(); - - typeComboBox.hidePopup(); - - if (deselected == null) { - deselected = archetypeType; - } - if (JOptionPane.showConfirmDialog(gameObjectAttributesDialog, "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(); - } - - type = typeComboBox.getSelectedIndex(); - - gameObjectAttributesDialog.buildAttribute(); - } else { - ignoreEvent = true; - typeComboBox.setSelectedIndex(type); - ignoreEvent = false; - } - } - } - - /** - * Returns a reference to the type data. - * @return the reference - */ - @NotNull - public ArchetypeType getArchetypeType() { - return archetypeType; - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2013-07-14 21:34:03
|
Revision: 9344 http://sourceforge.net/p/gridarta/code/9344 Author: akirschbaum Date: 2013-07-14 21:34:00 +0000 (Sun, 14 Jul 2013) Log Message: ----------- Extract AttributesPaneBuilder from GameObjectAttributesDialog. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java Added Paths: ----------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java Added: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java (rev 0) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2013-07-14 21:34:00 UTC (rev 9344) @@ -0,0 +1,802 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.dialog.gameobjectattributes; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.FocusListener; +import java.io.File; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import javax.swing.AbstractButton; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.DefaultComboBoxModel; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.filechooser.FileFilter; +import javax.swing.text.DefaultFormatterFactory; +import javax.swing.text.NumberFormatter; +import net.sf.gridarta.gui.map.maptilepane.TilePanel; +import net.sf.gridarta.gui.treasurelist.CFTreasureListTree; +import net.sf.gridarta.gui.utils.AnimationComponent; +import net.sf.gridarta.gui.utils.FaceComponent; +import net.sf.gridarta.model.anim.AnimationObjects; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.archetypetype.AbstractArchetypeAttributeSpell; +import net.sf.gridarta.model.archetypetype.ArchetypeAttribute; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeAnimationName; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeBitmask; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeBool; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeBoolSpec; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeFaceName; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeFixed; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeFloat; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeInt; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeInvSpell; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeList; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeLong; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeMapPath; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeScriptFile; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeSection; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeSpell; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeString; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeText; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeTreasure; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeVisitor; +import net.sf.gridarta.model.archetypetype.ArchetypeAttributeZSpell; +import net.sf.gridarta.model.archetypetype.ArchetypeTypeList; +import net.sf.gridarta.model.archetypetype.ArchetypeTypeSet; +import net.sf.gridarta.model.archetypetype.AttributeBitmask; +import net.sf.gridarta.model.baseobject.BaseObject; +import net.sf.gridarta.model.face.FaceObjectProviders; +import net.sf.gridarta.model.face.FaceObjects; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.model.mapmodel.MapSquare; +import net.sf.gridarta.model.settings.GlobalSettings; +import net.sf.gridarta.model.spells.GameObjectSpell; +import net.sf.gridarta.model.spells.NumberSpell; +import net.sf.gridarta.model.spells.Spell; +import net.sf.gridarta.model.spells.Spells; +import net.sf.gridarta.model.treasurelist.TreasureTree; +import net.sf.gridarta.textedit.textarea.JEditTextArea; +import net.sf.gridarta.textedit.textarea.SyntaxDocument; +import net.sf.gridarta.textedit.textarea.TextAreaDefaults; +import net.sf.gridarta.textedit.textarea.tokenmarker.TokenMarkerFactory; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Builder for game object attribute panels. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @author Andreas Kirschbaum + */ +public class AttributesPaneBuilder<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { + + /** + * Color for float values. + */ + @NotNull + public static final Color FLOAT_COLOR = new Color(19, 134, 0); + + /** + * Color for int values. + */ + @NotNull + public static final Color INT_COLOR = new Color(74, 70, 156); + + /** + * The game object being modified. + * @serial + */ + @NotNull + private G gameObject; + + /** + * The parent component for dialogs. + */ + @NotNull + private final Component parent; + + /** + * Reference to the {@link ArchetypeTypeSet}. + */ + @NotNull + private final ArchetypeTypeSet archetypeTypeSet; + + /** + * The {@link CFTreasureListTree} to use. + * @serial + */ + @NotNull + private final CFTreasureListTree treasureListTree; + + /** + * The {@link FaceObjectProviders} for looking up faces. + */ + @NotNull + private final FaceObjectProviders faceObjectProviders; + + /** + * The {@link AnimationObjects} instance for choosing animation names. + * @serial + */ + @NotNull + private final AnimationObjects animationObjects; + + /** + * The {@link GlobalSettings} instance. + */ + @NotNull + private final GlobalSettings globalSettings; + + /** + * The {@link FileFilter} to use for map files. + */ + @NotNull + private final FileFilter mapFileFilter; + + /** + * The {@link FileFilter} to use for script files. + */ + @NotNull + private final FileFilter scriptFileFilter; + + /** + * The {@link FaceObjects} instance for choosing face names. + * @serial + */ + @NotNull + private final FaceObjects faceObjects; + + /** + * The game object spells to use. + */ + @NotNull + private final Spells<GameObjectSpell<G, A, R>> gameObjectSpells; + + /** + * The numbered spells. + */ + @NotNull + private final Spells<NumberSpell> numberSpells; + + /** + * The index for "no spell". + * @serial + */ + private final int undefinedSpellIndex; + + /** + * The {@link TreasureTree} to use. + */ + @NotNull + private final TreasureTree treasureTree; + + /** + * The {@link ImageIcon} for no animations. + * @serial + */ + @NotNull + private final ImageIcon noFaceSquareIcon; + + /** + * The {@link ImageIcon} for undefined animations. + * @serial + */ + @NotNull + private final ImageIcon unknownSquareIcon; + + /** + * The {@link TextAreaDefaults} for text fields. + */ + @NotNull + private final TextAreaDefaults textAreaDefaults; + + /** + * The central tabbed pane (the place where all the attribute tabs are). + * @serial + */ + @NotNull + private final JTabbedPane tabbedPane = new JTabbedPane(); + + @NotNull + private final FocusListener focusListener = new ScrollToVisibleFocusListener(); + + /** + * All {@link DialogAttribute DialogAttributes} in the dialog. + */ + @NotNull + private final Collection<DialogAttribute<G, A, R, ?>> dialogAttributes = new ArrayList<DialogAttribute<G, A, R, ?>>(); + + /** + * The return value for {@link #archetypeAttributeVisitor}. + */ + @Nullable + private GuiInfo<G, A, R, ?> guiInfo; + + /** + * The {@link ArchetypeAttributeVisitor} for creating GUI elements for + * {@link ArchetypeAttribute ArchetypeAttributes}. + */ + @NotNull + private final ArchetypeAttributeVisitor archetypeAttributeVisitor = new ArchetypeAttributeVisitor() { + + @Override + public void visit(@NotNull final ArchetypeAttributeAnimationName archetypeAttribute) { + final String attributeName = archetypeAttribute.getArchetypeAttributeName(); + final String defaultText = gameObject.getAttributeString(attributeName); + final AnimationComponent input = new AnimationComponent(defaultText, animationObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon); + final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeAnimationName>(new DialogAttributeAnimationName<G, A, R>(archetypeAttribute, input), cLabel, input, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeBitmask archetypeAttribute) { + final JTextArea input = new JTextArea(); + final DialogAttributeBitmask<G, A, R> tmpAttribute = new DialogAttributeBitmask<G, A, R>(archetypeAttribute, input); + @Nullable final JTextArea component; + @Nullable final JButton label; + @Nullable final JLabel row; + final AttributeBitmask bitmask = archetypeTypeSet.getBitmask(archetypeAttribute.getBitmaskName()); + if (bitmask != null) { + tmpAttribute.setBitmask(bitmask); + label = new JButton(new MaskChangeAL<G, A, R>(archetypeAttribute.getAttributeName() + ":", tmpAttribute)); + input.setBackground(parent.getBackground()); + input.setEditable(false); + input.setBorder(BorderFactory.createLineBorder(Color.gray)); + input.setText(bitmask.getText(tmpAttribute.getValue())); + component = input; + tmpAttribute.setEncodedValue(gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName())); + row = null; + } else { + label = null; + component = null; + row = new JLabel("Error: Undefined Bitmask"); + } + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBitmask>(tmpAttribute, label, component, row, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeBool archetypeAttribute) { + final JCheckBox input = new JCheckBox(archetypeAttribute.getAttributeName(), gameObject.getAttributeInt(archetypeAttribute.getArchetypeAttributeName()) == 1); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBool>(new DialogAttributeBool<G, A, R>(archetypeAttribute, input), null, null, input, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeBoolSpec archetypeAttribute) { + final CharSequence attributeString = gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName()); + final boolean defaultValue; + if (archetypeAttribute.getTrueValue().equals("0")) { + defaultValue = attributeString.length() == 0 || attributeString.equals("0"); + } else { + defaultValue = attributeString.equals(archetypeAttribute.getTrueValue()); + } + final JCheckBox input = new JCheckBox(archetypeAttribute.getAttributeName(), defaultValue); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBoolSpec>(new DialogAttributeBoolSpec<G, A, R>(archetypeAttribute, input), null, input, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeFaceName archetypeAttribute) { + final String attributeName = archetypeAttribute.getArchetypeAttributeName(); + final String defaultText = gameObject.getAttributeString(attributeName); + final FaceComponent input = new FaceComponent(defaultText, faceObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ":"); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeFaceName>(new DialogAttributeFaceName<G, A, R>(archetypeAttribute, input), label, input, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeFixed archetypeAttribute) { + throw new AssertionError(); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeFloat archetypeAttribute) { + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(FLOAT_COLOR); + final int fieldLength = archetypeAttribute.getInputLength() == 0 ? ArchetypeAttribute.TEXTFIELD_COLUMNS : archetypeAttribute.getInputLength(); + final DecimalFormat format = new DecimalFormat("#0.0#"); + format.setMaximumFractionDigits(10); + format.setGroupingUsed(false); + final NumberFormatter formatter = new NumberFormatter(format); + formatter.setValueClass(Double.class); + final DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter); + // parse value from gameObject + final Number value = gameObject.getAttributeDouble(archetypeAttribute.getArchetypeAttributeName()); + final JFormattedTextField input = new JFormattedTextField(factory, value); + input.setColumns(fieldLength); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeFloat>(new DialogAttributeFloat<G, A, R>(archetypeAttribute, input), label, input, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeInt archetypeAttribute) { + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); + final int fieldLength = archetypeAttribute.getInputLength() == 0 ? ArchetypeAttribute.TEXTFIELD_COLUMNS : archetypeAttribute.getInputLength(); + final NumberFormat format = NumberFormat.getIntegerInstance(); + format.setGroupingUsed(false); + final NumberFormatter formatter = new NumberFormatter(format); + final DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter); + // parse value from gameObject + final Number value = gameObject.getAttributeInt(archetypeAttribute.getArchetypeAttributeName()); + final JFormattedTextField input = new JFormattedTextField(factory, value); + input.setColumns(fieldLength); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeInt>(new DialogAttributeInt<G, A, R>(archetypeAttribute, input), label, input, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeInvSpell archetypeAttribute) { + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); + // create ComboBox with parsed selection + @Nullable final JComboBox input = buildInvSpellBox(gameObjectSpells, gameObject, archetypeAttribute.isOptionalSpell(), archetypeAttribute.getAttributeName()); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeInvSpell>(new DialogAttributeInvSpell<G, A, R>(archetypeAttribute.isOptionalSpell(), archetypeAttribute, input, gameObjectSpells), label, input, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeList archetypeAttribute) { + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); + // create ComboBox with parsed selection + final JComponent component; + @Nullable final JComboBox input; + final ArchetypeTypeList list = archetypeTypeSet.getList(archetypeAttribute.getListName()); + if (list != null) { + // build the list from vector data + input = buildArrayBox(list, gameObject, archetypeAttribute.getArchetypeAttributeName(), archetypeAttribute.getAttributeName()); + component = input; + } else { + // error: list data is missing or corrupt + input = new JComboBox(); + component = new JLabel("Error: Undefined List"); + } + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeList>(new DialogAttributeList<G, A, R>(archetypeAttribute, input, archetypeTypeSet), label, component, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeLong archetypeAttribute) { + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); + final int fieldLength = archetypeAttribute.getInputLength() == 0 ? ArchetypeAttribute.TEXTFIELD_COLUMNS : archetypeAttribute.getInputLength(); + final NumberFormat format = NumberFormat.getIntegerInstance(); + format.setGroupingUsed(false); + final NumberFormatter formatter = new NumberFormatter(format); + final DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter); + // parse value from gameObject + final Number value = gameObject.getAttributeLong(archetypeAttribute.getArchetypeAttributeName()); + final JFormattedTextField input = new JFormattedTextField(factory, value); + input.setColumns(fieldLength); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeLong>(new DialogAttributeLong<G, A, R>(archetypeAttribute, input), label, input, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeMapPath archetypeAttribute) { + final MapSquare<G, A, R> mapSquare = gameObject.getMapSquare(); + File relativeReference = mapSquare == null ? null : mapSquare.getMapModel().getMapFile(); + if (relativeReference == null) { + relativeReference = new File(globalSettings.getMapsDirectory(), "dummy"); + } + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + final TilePanel tilePanel = new TilePanel(mapFileFilter, gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName()), relativeReference, globalSettings.getMapsDirectory()); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeMapPath>(new DialogAttributeMapPath<G, A, R>(archetypeAttribute, tilePanel), label, tilePanel, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeScriptFile archetypeAttribute) { + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + final File mapsDirectory = globalSettings.getMapsDirectory(); + final TilePanel tilePanel = new TilePanel(scriptFileFilter, gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName()), new File(mapsDirectory, "dummy"), mapsDirectory); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeScriptFile>(new DialogAttributeScriptFile<G, A, R>(archetypeAttribute, tilePanel), label, tilePanel, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeSpell archetypeAttribute) { + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); + // create ComboBox with parsed selection + @Nullable final JComboBox input = buildSpellBox(gameObject, numberSpells, undefinedSpellIndex, false, archetypeAttribute); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeSpell>(new DialogAttributeSpell<G, A, R>(archetypeAttribute, input, numberSpells), label, input, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeString archetypeAttribute) { + final String defaultText = gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName()); + final JTextField input = new JTextField(defaultText, ArchetypeAttribute.TEXTFIELD_COLUMNS); + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeString>(new DialogAttributeString<G, A, R>(archetypeAttribute, input), label, input, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeText archetypeAttribute) { + String text = ""; + if (archetypeAttribute.getArchetypeAttributeName().equals("msg")) { + final String archetypeMsgText = gameObject.getArchetype().getMsgText(); + final String gameObjectMsgText = gameObject.getMsgText(); + if (archetypeMsgText != null && archetypeMsgText.length() > 0 && (gameObjectMsgText == null || gameObjectMsgText.length() == 0)) { + text = archetypeMsgText; + } else { + text = gameObjectMsgText; + } + } + final JEditTextArea input = new JEditTextArea(textAreaDefaults); + input.setDocument(new SyntaxDocument()); + input.getDocument().setTokenMarker(TokenMarkerFactory.createTokenMarker(archetypeAttribute.getFileExtension())); + input.setText(text == null ? "" : text); + input.setCaretPosition(0); + input.setBorder(BorderFactory.createEmptyBorder(3, 7, 0, 0)); + input.getPainter().setInvalidLinesPainted(false); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeText>(new DialogAttributeText<G, A, R>(archetypeAttribute, input), null, null, null, input, true); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeTreasure archetypeAttribute) { + // textfield (no direct input, text is set by the treasurelist dialog) + String treasureName = gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName()); + if (treasureName.trim().length() == 0 || treasureName.trim().equalsIgnoreCase("none")) { + treasureName = CFTreasureListTree.NONE_SYM; + } + final JTextField input = new JTextField(" " + treasureName, ArchetypeAttribute.TEXTFIELD_COLUMNS); + input.setEditable(false); + final DialogAttributeTreasure<G, A, R> tmpAttribute = new DialogAttributeTreasure<G, A, R>(archetypeAttribute, input, treasureTree); + final JButton label = new JButton(new ViewTreasurelistAL(input, parent, treasureListTree)); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeTreasure>(tmpAttribute, label, input, null, null, false); + } + + @Override + public void visit(@NotNull final ArchetypeAttributeZSpell archetypeAttribute) { + final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); + label.setForeground(INT_COLOR); + // create ComboBox with parsed selection + @Nullable final JComboBox input = buildSpellBox(gameObject, numberSpells, undefinedSpellIndex, true, archetypeAttribute); + guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeZSpell>(new DialogAttributeZSpell<G, A, R>(archetypeAttribute, input, numberSpells, undefinedSpellIndex), label, input, null, null, false); + } + + }; + + /** + * Creates a new instance. + * @param gameObject the game object for which the attributes are built + * @param parent the parent component for dialogs + * @param archetypeTypeSet the reference to the list of archetype types + * @param treasureListTree the treasure list tree to display + * @param faceObjectProviders the face object providers for looking up + * faces + * @param animationObjects the animation objects instance for choosing + * animation names + * @param globalSettings the global settings to use + * @param mapFileFilter the file filter to use for map files + * @param scriptFileFilter the file filter to use for script files + * @param faceObjects the face objects instance for choosing face names + * @param gameObjectSpells the game object spells to use + * @param numberSpells the numbered spells to use + * @param undefinedSpellIndex the index for "no spell" + * @param treasureTree the treasure tree to use + * @param noFaceSquareIcon the image icon for no animations + * @param unknownSquareIcon the image icon for undefined animations + * @param textAreaDefaults the text area defaults for text fields + */ + public AttributesPaneBuilder(@NotNull final G gameObject, @NotNull final Component parent, final ArchetypeTypeSet archetypeTypeSet, @NotNull final CFTreasureListTree treasureListTree, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects, @NotNull final GlobalSettings globalSettings, @NotNull final FileFilter mapFileFilter, @NotNull final FileFilter scriptFileFilter, @NotNull final FaceObjects faceObjects, @NotNull final Spells<GameObjectSpell<G, A, R>> gameObjectSpells, @NotNull final Spells<NumberSpell> numberSpells, final int undefinedSpellIndex, @NotNull final TreasureTree treasureTree, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon, @NotNull final TextAreaDefaults textAreaDefaults) { + this.gameObject = gameObject; + this.parent = parent; + this.archetypeTypeSet = archetypeTypeSet; + this.treasureListTree = treasureListTree; + this.faceObjectProviders = faceObjectProviders; + this.animationObjects = animationObjects; + this.globalSettings = globalSettings; + this.mapFileFilter = mapFileFilter; + this.scriptFileFilter = scriptFileFilter; + this.faceObjects = faceObjects; + this.gameObjectSpells = gameObjectSpells; + this.numberSpells = numberSpells; + this.undefinedSpellIndex = undefinedSpellIndex; + this.treasureTree = treasureTree; + this.noFaceSquareIcon = noFaceSquareIcon; + this.unknownSquareIcon = unknownSquareIcon; + this.textAreaDefaults = textAreaDefaults; + } + + /** + * Returns the {@link JTabbedPane} that contains all attribute tabs. + * @return the pane + */ + @NotNull + public JTabbedPane getTabbedPane() { + return tabbedPane; + } + + /** + * Returns all {@link DialogAttribute DialogAttributes} in the dialog. + * @return the dialog attributes + */ + @NotNull + public Collection<DialogAttribute<G, A, R, ?>> getDialogAttributes() { + return Collections.unmodifiableCollection(dialogAttributes); + } + + /** + * Constructs the central part of the attribute dialog, containing the + * object's gameObject attributes. + * @param gameObject the game object for which the attributes are built + * @param archetypeType the archetype type of {@code gamObject} + */ + public void buildAttribute(@NotNull final G gameObject, @NotNull final Iterable<ArchetypeAttributeSection> archetypeType) { + this.gameObject = gameObject; + tabbedPane.removeAll(); + int sectionId = 0; + for (final ArchetypeAttributeSection archetypeAttributeSection : archetypeType) { + final Component panel = makeAttributePanel(archetypeAttributeSection); + if (panel != null) { + final String sectionName = archetypeAttributeSection.getSectionName(); + final String title; + if (sectionName.length() <= 1) { + title = sectionName; + } else { + title = sectionName.substring(0, 1).toUpperCase() + sectionName.substring(1); + } + tabbedPane.addTab(title, null, panel); + sectionId++; + } + } + + // set selected tab + tabbedPane.setSelectedIndex(sectionId > 0 ? 0 : -1); + tabbedPane.validate(); + } + + /** + * This method creates an attribute panel for one section of attributes. If + * the section is empty, null is returned. + * @param archetypeAttributeSection the section + * @return a <code>Component</code> containing the attribute panel + * (currently always a JScrollPane) + */ + @Nullable + private Component makeAttributePanel(@NotNull final Iterable<ArchetypeAttribute> archetypeAttributeSection) { + int matchingAttributes = 0; // number of attributes in this section + boolean hasBitmask = false; // true if this section contains a bitmask attribute + + // first we check how many attributes this section has + for (final ArchetypeAttribute archetypeAttribute : archetypeAttributeSection) { + // count number of attributes + if (!(archetypeAttribute instanceof ArchetypeAttributeFixed)) { + matchingAttributes++; + } + // check for bitmask attributes + if (!hasBitmask && archetypeAttribute instanceof ArchetypeAttributeBitmask) { + hasBitmask = true; + } + } + if (matchingAttributes == 0) { + return null; + } + + // All attribute-"lines" go into this panel: + final JPanel panel = new JPanel(new GridBagLayout()); + final Insets gbcInsets = new Insets(2, 2, 2, 2); + + final GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = gbcInsets; + final Object helpGbc = gbc.clone(); + gbc.fill = GridBagConstraints.HORIZONTAL; + final Object labelGbc = gbc.clone(); + gbc.weightx = 1.0; + gbc.gridwidth = GridBagConstraints.REMAINDER; + final Object compGbc = gbc.clone(); + gbc.anchor = GridBagConstraints.WEST; + final Object rowGbc = gbc.clone(); + gbc.fill = GridBagConstraints.BOTH; + gbc.weighty = 1.0; + final Object glueGbc = gbc.clone(); + + boolean isText = false; + // now add the entries, line by line + for (final ArchetypeAttribute archetypeAttribute : archetypeAttributeSection) { + if (!(archetypeAttribute instanceof ArchetypeAttributeFixed)) { + final AbstractButton helpButton = new JButton("?"); + helpButton.setMargin(new Insets(0, 5, 0, 5)); + panel.add(helpButton, helpGbc); + helpButton.addFocusListener(focusListener); + + guiInfo = null; + archetypeAttribute.visit(archetypeAttributeVisitor); + final GuiInfo<G, A, R, ?> tmpGuiInfo = guiInfo; + assert tmpGuiInfo != null; + + dialogAttributes.add(tmpGuiInfo.getNewAttr()); + helpButton.addActionListener(new HelpActionListener(tmpGuiInfo.getNewAttr().getRef(), parent)); + addElement(panel, tmpGuiInfo.getLabel(), labelGbc); + addElement(panel, tmpGuiInfo.getComponent(), compGbc); + addElement(panel, tmpGuiInfo.getRow(), rowGbc); + addElement(panel, tmpGuiInfo.getGlue(), glueGbc); + isText |= tmpGuiInfo.isText(); + } + } + + if (!isText) { + // if the component does not already have glue, put glue inside to align its contents to the top. + panel.add(Box.createGlue(), glueGbc); + } + final JScrollPane panelReturn = new JScrollPane(panel); + panelReturn.getVerticalScrollBar().setUnitIncrement(8); + return panelReturn; + } + + /** + * Adds a {@link Component} to a {@link Container}. + * @param container the container to add to + * @param component the component to add or <code>null</code> + * @param constraints the constraints + */ + private void addElement(@NotNull final Container container, @Nullable final Component component, @NotNull final Object constraints) { + if (component != null) { + container.add(component, constraints); + component.addFocusListener(focusListener); + } + } + + /** + * Constructs the combo box of the available spells. + * @param gameObjectSpells the game object spells to use + * @param isOptionalSpell whether the entry <none> should be shown + * @param attributeName the archetype attribute's name + * @param gameObject the associated game object + * @return the completed <code>JComboBox</code> + */ + @NotNull + private static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> JComboBox buildInvSpellBox(@NotNull final Spells<GameObjectSpell<G, A, R>> gameObjectSpells, @NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean isOptionalSpell, @NotNull final String attributeName) { + final int selectedIndex; + @Nullable final String title; + switch (gameObject.countInvObjects()) { + case 0: + selectedIndex = gameObjectSpells.size(); + title = isOptionalSpell ? null : "<none>"; + break; + + default: + selectedIndex = gameObjectSpells.size() + (isOptionalSpell ? 1 : 0); + title = "<multiple>"; + break; + + case 1: + final GameObject<?, ?, ?> invObject = gameObject.iterator().next(); + final String invObjectArchetypeName = invObject.getArchetype().getArchetypeName(); + int index = 0; + @Nullable String tmpTitle = "<customized spell>"; + for (final GameObjectSpell<?, ?, ?> spellObject : gameObjectSpells) { + if (invObjectArchetypeName.equals(spellObject.getArchetypeName())) { + tmpTitle = invObject.isDefaultGameObject() ? null : spellObject.getName() + " <customized>"; + break; + } + index++; + } + selectedIndex = tmpTitle != null ? gameObjectSpells.size() + (isOptionalSpell ? 1 : 0) : index; + title = tmpTitle; + break; + } + + final DefaultComboBoxModel model = new DefaultComboBoxModel(); + for (final Spell spell : gameObjectSpells) { + model.addElement(spell.getName()); + } + if (isOptionalSpell) { + model.addElement("<none>"); + } + if (title != null) { + model.addElement(title); + } + final JComboBox comboBox = new JComboBox(model); + comboBox.setSelectedIndex(selectedIndex); + comboBox.setMaximumRowCount(10); + comboBox.setKeySelectionManager(new StringKeyManager(comboBox)); + comboBox.setName(attributeName); + return comboBox; + } + + /** + * Constructs the combo box for arrays of "list data". + * @param listData list with list items and corresponding values + * @param gameObject the associated game object + * @param archetypeAttributeName the name of the shown attribute + * @param attributeName the label to show on the combo box + * @return the completed <code>JComboBox</code> + */ + @NotNull + private static JComboBox buildArrayBox(@NotNull final ArchetypeTypeList listData, @NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final String archetypeAttributeName, @NotNull final String attributeName) { + // build the array of list-items + final String[] array = new String[listData.size()]; + boolean hasSelection = false; + int active = gameObject.getAttributeInt(archetypeAttributeName); + for (int i = 0; i < array.length; i++) { + array[i] = listData.get(i).getSecond(); + if (!hasSelection && listData.get(i).getFirst() == active) { + hasSelection = true; + active = i; // set selection to this index in the array + } + } + // if there is no valid pre-selection, show first element of list + if (!hasSelection) { + active = 0; + } + final JComboBox comboBox = new JComboBox(array); // set "content" + comboBox.setSelectedIndex(active); // set active selection + comboBox.setMaximumRowCount(10); + comboBox.setKeySelectionManager(new StringKeyManager(comboBox)); + comboBox.setName(attributeName); + return comboBox; + } + + /** + * Constructs the combo box of the available spells. + * @param gameObject the associated game object + * @param numberSpells the number spells to use + * @param undefinedSpellIndex the index to use for the undefined spell + * @param isZSpell whether a z-spell or a spell combo box is built + * @param archetypeAttribute the archetype attribute + * @return the completed <code>JComboBox</code> + */ + @NotNull + private static JComboBox buildSpellBox(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final Spells<NumberSpell> numberSpells, final int undefinedSpellIndex, final boolean isZSpell, @NotNull final ArchetypeAttribute archetypeAttribute) { + int spellNumber = gameObject.getAttributeInt(archetypeAttribute.getArchetypeAttributeName()); + + if (spellNumber < 0 || spellNumber >= numberSpells.size()) { + spellNumber = undefinedSpellIndex; + } + + // do we have "none" spell? + final int selectedIndex; + if (spellNumber == undefinedSpellIndex && isZSpell) { + selectedIndex = 0; + } else { + // now look up the spell-number in the array of spells + selectedIndex = 1 + AbstractArchetypeAttributeSpell.findSpellIndex(numberSpells, spellNumber); + } + + final DefaultComboBoxModel model = new DefaultComboBoxModel(); + model.addElement("<none>"); + for (final Spell spell : numberSpells) { + model.addElement(spell.getName()); + } + final JComboBox comboBox = new JComboBox(model); + comboBox.setSelectedIndex(selectedIndex); + comboBox.setMaximumRowCount(10); + comboBox.setKeySelectionManager(new StringKeyManager(comboBox)); + comboBox.setName(archetypeAttribute.getAttributeName()); + return comboBox; + } + +} Property changes on: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property 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 21:01:05 UTC (rev 9343) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java 2013-07-14 21:34:00 UTC (rev 9344) @@ -29,78 +29,42 @@ import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Point; -import java.awt.event.FocusListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.File; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Collection; import java.util.Set; import javax.swing.AbstractButton; import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.Box; -import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; import javax.swing.JButton; -import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JDialog; -import javax.swing.JFormattedTextField; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.SwingConstants; import javax.swing.filechooser.FileFilter; import javax.swing.text.BadLocationException; -import javax.swing.text.DefaultFormatterFactory; import javax.swing.text.Document; import javax.swing.text.JTextComponent; -import javax.swing.text.NumberFormatter; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; import net.sf.gridarta.gui.dialog.help.Help; -import net.sf.gridarta.gui.map.maptilepane.TilePanel; import net.sf.gridarta.gui.treasurelist.CFTreasureListTree; -import net.sf.gridarta.gui.utils.AnimationComponent; -import net.sf.gridarta.gui.utils.FaceComponent; import net.sf.gridarta.model.anim.AnimationObjects; import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.archetypetype.AbstractArchetypeAttributeSpell; import net.sf.gridarta.model.archetypetype.ArchetypeAttribute; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeAnimationName; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeBitmask; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeBool; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeBoolSpec; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeFaceName; import net.sf.gridarta.model.archetypetype.ArchetypeAttributeFixed; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeFloat; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeInt; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeInvSpell; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeList; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeLong; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeMapPath; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeScriptFile; import net.sf.gridarta.model.archetypetype.ArchetypeAttributeSection; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeSpell; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeString; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeText; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeTreasure; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeVisitor; -import net.sf.gridarta.model.archetypetype.ArchetypeAttributeZSpell; import net.sf.gridarta.model.archetypetype.ArchetypeType; -import net.sf.gridarta.model.archetypetype.ArchetypeTypeList; import net.sf.gridarta.model.archetypetype.ArchetypeTypeSet; -import net.sf.gridarta.model.archetypetype.AttributeBitmask; import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.face.FaceObjectProviders; import net.sf.gridarta.model.face.FaceObjectProvidersListener; @@ -117,14 +81,10 @@ import net.sf.gridarta.model.settings.GlobalSettings; import net.sf.gridarta.model.spells.GameObjectSpell; import net.sf.gridarta.model.spells.NumberSpell; -import net.sf.gridarta.model.spells.Spell; import net.sf.gridarta.model.spells.Spells; import net.sf.gridarta.model.treasurelist.TreasureTree; import net.sf.gridarta.model.validation.ErrorCollector; -import net.sf.gridarta.textedit.textarea.JEditTextArea; -import net.sf.gridarta.textedit.textarea.SyntaxDocument; import net.sf.gridarta.textedit.textarea.TextAreaDefaults; -import net.sf.gridarta.textedit.textarea.tokenmarker.TokenMarkerFactory; import net.sf.gridarta.utils.ActionBuilderUtils; import net.sf.gridarta.utils.Size2D; import net.sf.gridarta.utils.StringUtils; @@ -144,23 +104,6 @@ public class GameObjectAttributesDialog<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { /** - * Color for float values. - */ - @NotNull - public static final Color FLOAT_COLOR = new Color(19, 134, 0); - - /** - * Color for int values. - */ - @NotNull - public static final Color INT_COLOR = new Color(74, 70, 156); - - /** - * The serial version UID. - */ - private static final long serialVersionUID = 1L; - - /** * The Logger for printing log messages. */ @NotNull @@ -192,107 +135,18 @@ private final Frame parent; /** - * The {@link CFTreasureListTree} to use. - * @serial - */ - @NotNull - private final CFTreasureListTree treasureListTree; - - /** * The {@link FaceObjectProviders} for looking up faces. */ @NotNull private final FaceObjectProviders faceObjectProviders; /** - * The {@link AnimationObjects} instance for choosing animation names. - * @serial - */ - @NotNull - private final AnimationObjects animationObjects; - - /** - * The {@link GlobalSettings} instance. - */ - @NotNull - private final GlobalSettings globalSettings; - - /** - * The {@link FileFilter} to use for map files. - */ - @NotNull - private final FileFilter mapFileFilter; - - /** - * The {@link FileFilter} to use for script files. - */ - @NotNull - private final FileFilter scriptFileFilter; - - /** - * The {@link FaceObjects} instance for choosing face names. - * @serial - */ - @NotNull - private final FaceObjects faceObjects; - - /** - * The game object spells to use. - */ - @NotNull - private final Spells<GameObjectSpell<G, A, R>> gameObjectSpells; - - /** - * The numbered spells. - */ - @NotNull - private final Spells<NumberSpell> numberSpells; - - /** - * The index for "no spell". - * @serial - */ - private final int undefinedSpellIndex; - - /** - * The {@link TreasureTree} to use. - */ - @NotNull - private final TreasureTree treasureTree; - - /** - * The {@link ImageIcon} for no animations. - * @serial - */ - @NotNull - private final ImageIcon noFaceSquareIcon; - - /** - * The {@link ImageIcon} for undefined animations. - * @serial - */ - @NotNull - private final ImageIcon unknownSquareIcon; - - /** - * The {@link TextAreaDefaults} for text fields. - */ - @NotNull - private final TextAreaDefaults textAreaDefaults; - - /** * The {@link MapManager} instance. */ @NotNull private final MapManager<G, A, R> mapManager; - /** - * All {@link DialogAttribute DialogAttributes} in the dialog. - */ @NotNull - private final Collection<DialogAttribute<G, A, R, ?>> dialogAttributes = new ArrayList<DialogAttribute<G, A, R, ?>>(); - - @NotNull private final JOptionPane optionPane = new JOptionPane() { /** @@ -312,6 +166,13 @@ }; /** + * /he {@link AttributesPaneBuilder} for creating (and re-creating) the + * attribute tabs. + */ + @NotNull + private final AttributesPaneBuilder<G, A, R> attributesPaneBuilder; + + /** * The panel for object's face (png). * @serial */ @@ -389,13 +250,6 @@ private JButton okButton; /** - * The central tabbed pane (the place where all the attribute tabs are). - * @serial - */ - @NotNull - private final JTabbedPane tabbedPane = new JTabbedPane(); - - /** * The central pane, this is the parent component of above tabbed pane. * @serial */ @@ -410,262 +264,15 @@ private final JTextPane summaryTextPane; @NotNull - private final FocusListener focusListener = new ScrollToVisibleFocusListener(); - - @NotNull private final Style summaryTextStyle; /** - * The return value for {@link #archetypeAttributeVisitor}. - */ - @Nullable - private GuiInfo<G, A, R, ?> guiInfo; - - /** * The {@link ArchetypeType} of {@link #gameObject}. */ @NotNull private ArchetypeType archetypeType; /** - * The {@link ArchetypeAttributeVisitor} for creating GUI elements for - * {@link ArchetypeAttribute ArchetypeAttributes}. - */ - @NotNull - private final ArchetypeAttributeVisitor archetypeAttributeVisitor = new ArchetypeAttributeVisitor() { - - @Override - public void visit(@NotNull final ArchetypeAttributeAnimationName archetypeAttribute) { - final String attributeName = archetypeAttribute.getArchetypeAttributeName(); - final String defaultText = gameObject.getAttributeString(attributeName); - final AnimationComponent input = new AnimationComponent(defaultText, animationObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon); - final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeAnimationName>(new DialogAttributeAnimationName<G, A, R>(archetypeAttribute, input), cLabel, input, null, null, false); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeBitmask archetypeAttribute) { - final JTextArea input = new JTextArea(); - final DialogAttributeBitmask<G, A, R> tmpAttribute = new DialogAttributeBitmask<G, A, R>(archetypeAttribute, input); - @Nullable final JTextArea component; - @Nullable final JButton label; - @Nullable final JLabel row; - final AttributeBitmask bitmask = archetypeTypeSet.getBitmask(archetypeAttribute.getBitmaskName()); - if (bitmask != null) { - tmpAttribute.setBitmask(bitmask); - label = new JButton(new MaskChangeAL<G, A, R>(archetypeAttribute.getAttributeName() + ":", tmpAttribute)); - input.setBackground(optionPane.getBackground()); - input.setEditable(false); - input.setBorder(BorderFactory.createLineBorder(Color.gray)); - input.setText(bitmask.getText(tmpAttribute.getValue())); - component = input; - tmpAttribute.setEncodedValue(gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName())); - row = null; - } else { - label = null; - component = null; - row = new JLabel("Error: Undefined Bitmask"); - } - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBitmask>(tmpAttribute, label, component, row, null, false); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeBool archetypeAttribute) { - final JCheckBox input = new JCheckBox(archetypeAttribute.getAttributeName(), gameObject.getAttributeInt(archetypeAttribute.getArchetypeAttributeName()) == 1); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBool>(new DialogAttributeBool<G, A, R>(archetypeAttribute, input), null, null, input, null, false); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeBoolSpec archetypeAttribute) { - final CharSequence attributeString = gameObject.getAttributeString(archetypeAttribute.getArchetypeAttributeName()); - final boolean defaultValue; - if (archetypeAttribute.getTrueValue().equals("0")) { - defaultValue = attributeString.length() == 0 || attributeString.equals("0"); - } else { - defaultValue = attributeString.equals(archetypeAttribute.getTrueValue()); - } - final JCheckBox input = new JCheckBox(archetypeAttribute.getAttributeName(), defaultValue); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBoolSpec>(new DialogAttributeBoolSpec<G, A, R>(archetypeAttribute, input), null, input, null, null, false); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeFaceName archetypeAttribute) { - final String attributeName = archetypeAttribute.getArchetypeAttributeName(); - final String defaultText = gameObject.getAttributeString(attributeName); - final FaceComponent input = new FaceComponent(defaultText, faceObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon); - final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ":"); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeFaceName>(new DialogAttributeFaceName<G, A, R>(archetypeAttribute, input), label, input, null, null, false); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeFixed archetypeAttribute) { - throw new AssertionError(); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeFloat archetypeAttribute) { - final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); - label.setForeground(FLOAT_COLOR); - final int fieldLength = archetypeAttribute.getInputLength() == 0 ? ArchetypeAttribute.TEXTFIELD_COLUMNS : archetypeAttribute.getInputLength(); - final DecimalFormat format = new DecimalFormat("#0.0#"); - format.setMaximumFractionDigits(10); - format.setGroupingUsed(false); - final NumberFormatter formatter = new NumberFormatter(format); - formatter.setValueClass(Double.class); - final DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter); - // parse value from gameObject - final Number value = gameObject.getAttributeDouble(archetypeAttribute.getArchetypeAttributeName()); - final JFormattedTextField input = new JFormattedTextField(factory, value); - input.setColumns(fieldLength); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeFloat>(new DialogAttributeFloat<G, A, R>(archetypeAttribute, input), label, input, null, null, false); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeInt archetypeAttribute) { - final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); - label.setForeground(INT_COLOR); - final int fieldLength = archetypeAttribute.getInputLength() == 0 ? ArchetypeAttribute.TEXTFIELD_COLUMNS : archetypeAttribute.getInputLength(); - final NumberFormat format = NumberFormat.getIntegerInstance(); - format.setGroupingUsed(false); - final NumberFormatter formatter = new NumberFormatter(format); - final DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter); - // parse value from gameObject - final Number value = gameObject.getAttributeInt(archetypeAttribute.getArchetypeAttributeName()); - final JFormattedTextField input = new JFormattedTextField(factory, value); - input.setColumns(fieldLength); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeInt>(new DialogAttributeInt<G, A, R>(archetypeAttribute, input), label, input, null, null, false); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeInvSpell archetypeAttribute) { - final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); - label.setForeground(INT_COLOR); - // create ComboBox with parsed selection - @Nullable final JComboBox input = buildInvSpellBox(gameObjectSpells, gameObject, archetypeAttribute.isOptionalSpell(), archetypeAttribute.getAttributeName()); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeInvSpell>(new DialogAttributeInvSpell<G, A, R>(archetypeAttribute.isOptionalSpell(), archetypeAttribute, input, gameObjectSpells), label, input, null, null, false); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeList archetypeAttribute) { - final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); - label.setForeground(INT_COLOR); - // create ComboBox with parsed selection - final JComponent component; - @Nullable final JComboBox input; - final ArchetypeTypeList list = archetypeTypeSet.getList(archetypeAttribute.getListName()); - if (list != null) { - // build the list from vector data - input = buildArrayBox(list, gameObject, archetypeAttribute.getArchetypeAttributeName(), archetypeAttribute.getAttributeName()); - component = input; - } else { - // error: list data is missing or corrupt - input = new JComboBox(); - component = new JLabel("Error: Undefined List"); - } - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeList>(new DialogAttributeList<G, A, R>(archetypeAttribute, input, archetypeTypeSet), label, component, null, null, false); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeLong archetypeAttribute) { - final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); - label.setForeground(INT_COLOR); - final int fieldLength = archetypeAttribute.getInputLength() == 0 ? ArchetypeAttribute.TEXTFIELD_COLUMNS : archetypeAttribute.getInputLength(); - final NumberFormat format = NumberFormat.getIntegerInstance(); - format.setGroupingUsed(false); - final NumberFormatter formatter = new NumberFormatter(format); - final DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter); - // parse value from gameObject - final Number value = gameObject.getAttributeLong(archetypeAttribute.getArchetypeAttributeName()); - final JFormattedTextField input = new JFormattedTextField(factory, value); - input.setColumns(fieldLength); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeLong>(new DialogAttributeLong<G, A, R>(archetypeAttribute, input), label, input, null, null, false); - } - - @Override - public void visit(@NotNull final ArchetypeAttributeMapPath archetypeAttribute) { - final MapSquare<G, A, R> mapSquare = gameObject.getMapSquare(); - File relativeReference = mapSquare == null ? null : mapSquare.getMapModel().getMapFile(); - if (relativeReference == null) { - relativeReference = new File(globalSettings.getMapsDirectory(), "dummy"); - } - final JLabel label = new JLabel(archetypeAttribute.get... [truncated message content] |
From: <aki...@us...> - 2013-07-19 06:23:06
|
Revision: 9358 http://sourceforge.net/p/gridarta/code/9358 Author: akirschbaum Date: 2013-07-19 06:23:01 +0000 (Fri, 19 Jul 2013) Log Message: ----------- Clean up GuiInfo. Fixes layout issue with type="bool_spec" in types.xml. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java Added Paths: ----------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoGlue.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoRow.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoTwoColumn.java Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2013-07-19 05:56:07 UTC (rev 9357) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2013-07-19 06:23:01 UTC (rev 9358) @@ -264,39 +264,33 @@ final String defaultText = attributes.getAttributeString(attributeName); final AnimationComponent input = new AnimationComponent(defaultText, animationObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon); final JLabel cLabel = new JLabel(archetypeAttribute.getAttributeName() + ": "); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeAnimationName>(new DialogAttributeAnimationName<G, A, R>(archetypeAttribute, input), cLabel, input, null, null, false); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeAnimationName>(new DialogAttributeAnimationName<G, A, R>(archetypeAttribute, input), cLabel, input); } @Override public void visit(@NotNull final ArchetypeAttributeBitmask archetypeAttribute) { final JTextArea input = new JTextArea(); final DialogAttributeBitmask<G, A, R> tmpAttribute = new DialogAttributeBitmask<G, A, R>(archetypeAttribute, input); - @Nullable final JTextArea component; - @Nullable final JButton label; - @Nullable final JLabel row; final AttributeBitmask bitmask = archetypeTypeSet.getBitmask(archetypeAttribute.getBitmaskName()); if (bitmask != null) { tmpAttribute.setBitmask(bitmask); - label = new JButton(new MaskChangeAL<G, A, R>(archetypeAttribute.getAttributeName() + ":", tmpAttribute)); + final JButton label = new JButton(new MaskChangeAL<G, A, R>(archetypeAttribute.getAttributeName() + ":", tmpAttribute)); input.setBackground(parent.getBackground()); input.setEditable(false); input.setBorder(BorderFactory.createLineBorder(Color.gray)); input.setText(bitmask.getText(tmpAttribute.getValue())); - component = input; tmpAttribute.setEncodedValue(attributes.getAttributeString(archetypeAttribute.getArchetypeAttributeName())); - row = null; + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeBitmask>(tmpAttribute, label, input); } else { - label = null; - component = null; - row = new JLabel("Error: Undefined Bitmask"); + final JLabel row = new JLabel("Error: Undefined Bitmask"); + guiInfo = new GuiInfoRow<G, A, R, ArchetypeAttributeBitmask>(tmpAttribute, row); } - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBitmask>(tmpAttribute, label, component, row, null, false); } @Override public void visit(@NotNull final ArchetypeAttributeBool archetypeAttribute) { final JCheckBox input = new JCheckBox(archetypeAttribute.getAttributeName(), attributes.getAttributeInt(archetypeAttribute.getArchetypeAttributeName()) == 1); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBool>(new DialogAttributeBool<G, A, R>(archetypeAttribute, input), null, null, input, null, false); + guiInfo = new GuiInfoRow<G, A, R, ArchetypeAttributeBool>(new DialogAttributeBool<G, A, R>(archetypeAttribute, input), input); } @Override @@ -309,7 +303,7 @@ defaultValue = attributeString.equals(archetypeAttribute.getTrueValue()); } final JCheckBox input = new JCheckBox(archetypeAttribute.getAttributeName(), defaultValue); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeBoolSpec>(new DialogAttributeBoolSpec<G, A, R>(archetypeAttribute, input), null, input, null, null, false); + guiInfo = new GuiInfoRow<G, A, R, ArchetypeAttributeBoolSpec>(new DialogAttributeBoolSpec<G, A, R>(archetypeAttribute, input), input); } @Override @@ -318,7 +312,7 @@ final String defaultText = attributes.getAttributeString(attributeName); final FaceComponent input = new FaceComponent(defaultText, faceObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon); final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ":"); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeFaceName>(new DialogAttributeFaceName<G, A, R>(archetypeAttribute, input), label, input, null, null, false); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeFaceName>(new DialogAttributeFaceName<G, A, R>(archetypeAttribute, input), label, input); } @Override @@ -340,7 +334,7 @@ final Number value = attributes.getAttributeDouble(archetypeAttribute.getArchetypeAttributeName()); final JFormattedTextField input = new JFormattedTextField(factory, value); input.setColumns(fieldLength); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeFloat>(new DialogAttributeFloat<G, A, R>(archetypeAttribute, input), label, input, null, null, false); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeFloat>(new DialogAttributeFloat<G, A, R>(archetypeAttribute, input), label, input); } @Override @@ -355,15 +349,15 @@ final Number value = attributes.getAttributeInt(archetypeAttribute.getArchetypeAttributeName()); final JFormattedTextField input = new JFormattedTextField(factory, value); input.setColumns(fieldLength); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeInt>(new DialogAttributeInt<G, A, R>(archetypeAttribute, input), label, input, null, null, false); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeInt>(new DialogAttributeInt<G, A, R>(archetypeAttribute, input), label, input); } @Override public void visit(@NotNull final ArchetypeAttributeInvSpell archetypeAttribute) { final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); label.setForeground(INT_COLOR); - @Nullable final JComboBox input = buildInvSpellBox(gameObjectSpells, attributes, archetypeAttribute.isOptionalSpell(), archetypeAttribute.getAttributeName()); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeInvSpell>(new DialogAttributeInvSpell<G, A, R>(archetypeAttribute.isOptionalSpell(), archetypeAttribute, input, gameObjectSpells), label, input, null, null, false); + final JComboBox input = buildInvSpellBox(gameObjectSpells, attributes, archetypeAttribute.isOptionalSpell(), archetypeAttribute.getAttributeName()); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeInvSpell>(new DialogAttributeInvSpell<G, A, R>(archetypeAttribute.isOptionalSpell(), archetypeAttribute, input, gameObjectSpells), label, input); } @Override @@ -371,7 +365,7 @@ final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); label.setForeground(INT_COLOR); final JComponent component; - @Nullable final JComboBox input; + final JComboBox input; final ArchetypeTypeList list = archetypeTypeSet.getList(archetypeAttribute.getListName()); if (list != null) { input = buildArrayBox(list, attributes, archetypeAttribute.getArchetypeAttributeName(), archetypeAttribute.getAttributeName()); @@ -381,7 +375,7 @@ input = new JComboBox(); component = new JLabel("Error: Undefined List"); } - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeList>(new DialogAttributeList<G, A, R>(archetypeAttribute, input, archetypeTypeSet), label, component, null, null, false); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeList>(new DialogAttributeList<G, A, R>(archetypeAttribute, input, archetypeTypeSet), label, component); } @Override @@ -396,7 +390,7 @@ final Number value = attributes.getAttributeLong(archetypeAttribute.getArchetypeAttributeName()); final JFormattedTextField input = new JFormattedTextField(factory, value); input.setColumns(fieldLength); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeLong>(new DialogAttributeLong<G, A, R>(archetypeAttribute, input), label, input, null, null, false); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeLong>(new DialogAttributeLong<G, A, R>(archetypeAttribute, input), label, input); } @Override @@ -408,7 +402,7 @@ } final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); final TilePanel tilePanel = new TilePanel(mapFileFilter, attributes.getAttributeString(archetypeAttribute.getArchetypeAttributeName()), relativeReference, globalSettings.getMapsDirectory()); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeMapPath>(new DialogAttributeMapPath<G, A, R>(archetypeAttribute, tilePanel), label, tilePanel, null, null, false); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeMapPath>(new DialogAttributeMapPath<G, A, R>(archetypeAttribute, tilePanel), label, tilePanel); } @Override @@ -416,15 +410,15 @@ final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); final File mapsDirectory = globalSettings.getMapsDirectory(); final TilePanel tilePanel = new TilePanel(scriptFileFilter, attributes.getAttributeString(archetypeAttribute.getArchetypeAttributeName()), new File(mapsDirectory, "dummy"), mapsDirectory); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeScriptFile>(new DialogAttributeScriptFile<G, A, R>(archetypeAttribute, tilePanel), label, tilePanel, null, null, false); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeScriptFile>(new DialogAttributeScriptFile<G, A, R>(archetypeAttribute, tilePanel), label, tilePanel); } @Override public void visit(@NotNull final ArchetypeAttributeSpell archetypeAttribute) { final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); label.setForeground(INT_COLOR); - @Nullable final JComboBox input = buildSpellBox(attributes, numberSpells, undefinedSpellIndex, false, archetypeAttribute); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeSpell>(new DialogAttributeSpell<G, A, R>(archetypeAttribute, input, numberSpells), label, input, null, null, false); + final JComboBox input = buildSpellBox(attributes, numberSpells, undefinedSpellIndex, false, archetypeAttribute); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeSpell>(new DialogAttributeSpell<G, A, R>(archetypeAttribute, input, numberSpells), label, input); } @Override @@ -432,7 +426,7 @@ final String defaultText = attributes.getAttributeString(archetypeAttribute.getArchetypeAttributeName()); final JTextField input = new JTextField(defaultText, ArchetypeAttribute.TEXTFIELD_COLUMNS); final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeString>(new DialogAttributeString<G, A, R>(archetypeAttribute, input), label, input, null, null, false); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeString>(new DialogAttributeString<G, A, R>(archetypeAttribute, input), label, input); } @Override @@ -457,7 +451,7 @@ input.setCaretPosition(0); input.setBorder(BorderFactory.createEmptyBorder(3, 7, 0, 0)); input.getPainter().setInvalidLinesPainted(false); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeText>(new DialogAttributeText<G, A, R>(archetypeAttribute, input), null, null, null, input, true); + guiInfo = new GuiInfoGlue<G, A, R, ArchetypeAttributeText>(new DialogAttributeText<G, A, R>(archetypeAttribute, input), input, true); } @Override @@ -470,15 +464,15 @@ input.setEditable(false); final DialogAttributeTreasure<G, A, R> tmpAttribute = new DialogAttributeTreasure<G, A, R>(archetypeAttribute, input, treasureTree); final JButton label = new JButton(new ViewTreasurelistAL(input, parent, treasureListTree)); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeTreasure>(tmpAttribute, label, input, null, null, false); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeTreasure>(tmpAttribute, label, input); } @Override public void visit(@NotNull final ArchetypeAttributeZSpell archetypeAttribute) { final JLabel label = new JLabel(archetypeAttribute.getAttributeName() + ": "); label.setForeground(INT_COLOR); - @Nullable final JComboBox input = buildSpellBox(attributes, numberSpells, undefinedSpellIndex, true, archetypeAttribute); - guiInfo = new GuiInfo<G, A, R, ArchetypeAttributeZSpell>(new DialogAttributeZSpell<G, A, R>(archetypeAttribute, input, numberSpells, undefinedSpellIndex), label, input, null, null, false); + final JComboBox input = buildSpellBox(attributes, numberSpells, undefinedSpellIndex, true, archetypeAttribute); + guiInfo = new GuiInfoTwoColumn<G, A, R, ArchetypeAttributeZSpell>(new DialogAttributeZSpell<G, A, R>(archetypeAttribute, input, numberSpells, undefinedSpellIndex), label, input); } }; @@ -632,8 +626,8 @@ final GuiInfo<G, A, R, ?> tmpGuiInfo = guiInfo; assert tmpGuiInfo != null; - dialogAttributes.add(tmpGuiInfo.getNewAttr()); - helpButton.addActionListener(new HelpActionListener(tmpGuiInfo.getNewAttr().getRef(), parent)); + dialogAttributes.add(tmpGuiInfo.getAttribute()); + helpButton.addActionListener(new HelpActionListener(tmpGuiInfo.getAttribute().getRef(), parent)); addElement(panel, tmpGuiInfo.getLabel(), labelGbc); addElement(panel, tmpGuiInfo.getComponent(), compGbc); addElement(panel, tmpGuiInfo.getRow(), rowGbc); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java 2013-07-19 05:56:07 UTC (rev 9357) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java 2013-07-19 06:23:01 UTC (rev 9358) @@ -31,63 +31,68 @@ * Information about one attribute line in a {@link GameObjectAttributesDialog}. * @author Andreas Kirschbaum */ -public class GuiInfo<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, T extends ArchetypeAttribute> { +public abstract class GuiInfo<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, T extends ArchetypeAttribute> { - // now create the attribute-GUI-instance - + /** + * The {@link DialogAttribute} this entry represents. + */ @NotNull - private final DialogAttribute<G, A, R, T> newAttr; + private final DialogAttribute<G, A, R, T> attribute; - @Nullable - private final Component label; - - @Nullable - private final Component component; - - @Nullable - private final Component row; - - @Nullable - private final Component glue; - - private final boolean isText; - - public GuiInfo(@NotNull final DialogAttribute<G, A, R, T> newAttr, @Nullable final Component label, @Nullable final Component component, @Nullable final Component row, @Nullable final Component glue, final boolean isText) { - this.newAttr = newAttr; - this.label = label; - this.component = component; - this.row = row; - this.glue = glue; - this.isText = isText; + /** + * Creates a new instance. + * @param attribute the dialog attribute this entry represents + */ + protected GuiInfo(@NotNull final DialogAttribute<G, A, R, T> attribute) { + this.attribute = attribute; } + /** + * Returns the {@link DialogAttribute} this entry represents. + * @return the dialog attribute + */ @NotNull - public DialogAttribute<G, A, R, T> getNewAttr() { - return newAttr; + public DialogAttribute<G, A, R, T> getAttribute() { + return attribute; } + /** + * Returns the label to display in the first column or {@code null}. If + * non-{@code null}, both {@link #getRow()} and {@link #getGlue()} are + * {@code null} and {@link #getComponent()} is non-{@code null}. + * @return the label + */ @Nullable - public Component getLabel() { - return label; - } + public abstract Component getLabel(); + /** + * Returns the component to display in the second column or {@code null}. If + * non-{@code null}, both {@link #getRow()} and {@link #getGlue()} are + * {@code null} and {@link #getLabel()} is non-{@code null}. + * @return the label + */ @Nullable - public Component getComponent() { - return component; - } + public abstract Component getComponent(); + /** + * Returns the row component to display filled horizontally or {@code null}. + * If non-{@code null}, all of {@link #getLabel()}, {@link #getComponent()}, + * and {@link #getGlue()} are {@code null}. + * @return the row component + */ @Nullable - public Component getRow() { - return row; - } + public abstract Component getRow(); + /** + * Returns the glue component to display filled both horizontally and + * vertically or {@code null}. If non-{@code null}, all of {@link + * #getLabel()}, {@link #getComponent()}, and {@link #getRow()} are {@code + * null}. + * @return the glue component + */ @Nullable - public Component getGlue() { - return glue; - } + public abstract Component getGlue(); - public boolean isText() { - return isText; - } + public abstract boolean isText(); } Added: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoGlue.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoGlue.java (rev 0) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoGlue.java 2013-07-19 06:23:01 UTC (rev 9358) @@ -0,0 +1,100 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.dialog.gameobjectattributes; + +import java.awt.Component; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.archetypetype.ArchetypeAttribute; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A {@link GuiInfo} that fills one component both horizontally and vertically. + * @author Andreas Kirschbaum + */ +public class GuiInfoGlue<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, T extends ArchetypeAttribute> extends GuiInfo<G, A, R, T> { + + /** + * The component to display filled both horizontally and vertically. + */ + @NotNull + private final Component glue; + + private final boolean isText; + + /** + * Creates a new instance. + * @param attribute the dialog attribute this entry represents + * @param glue the component to display filled both horizontally and + * verically + */ + public GuiInfoGlue(@NotNull final DialogAttribute<G, A, R, T> attribute, @NotNull final Component glue, final boolean isText) { + super(attribute); + this.glue = glue; + this.isText = isText; + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public Component getLabel() { + return null; + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public Component getComponent() { + return null; + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public Component getRow() { + return null; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public Component getGlue() { + return glue; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isText() { + return isText; + } + +} Property changes on: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoGlue.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Added: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoRow.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoRow.java (rev 0) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoRow.java 2013-07-19 06:23:01 UTC (rev 9358) @@ -0,0 +1,96 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.dialog.gameobjectattributes; + +import java.awt.Component; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.archetypetype.ArchetypeAttribute; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A {@link GuiInfo} that fills one component horizontally. + * @author Andreas Kirschbaum + */ +public class GuiInfoRow<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, T extends ArchetypeAttribute> extends GuiInfo<G, A, R, T> { + + /** + * The component to display filled horizontally. + */ + @NotNull + private final Component row; + + /** + * Creates a new instance. + * @param attribute the dialog attribute this entry represents + * @param row the component to display filled horizontally + */ + public GuiInfoRow(@NotNull final DialogAttribute<G, A, R, T> attribute, @NotNull final Component row) { + super(attribute); + this.row = row; + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public Component getLabel() { + return null; + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public Component getComponent() { + return null; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public Component getRow() { + return row; + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public Component getGlue() { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isText() { + return false; + } + +} Property changes on: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoRow.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Added: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoTwoColumn.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoTwoColumn.java (rev 0) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoTwoColumn.java 2013-07-19 06:23:01 UTC (rev 9358) @@ -0,0 +1,105 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.dialog.gameobjectattributes; + +import java.awt.Component; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.archetypetype.ArchetypeAttribute; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A {@link GuiInfo} that displays a label and another component in two + * columns. + * @author Andreas Kirschbaum + */ +public class GuiInfoTwoColumn<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, T extends ArchetypeAttribute> extends GuiInfo<G, A, R, T> { + + /** + * The label to display in the first column. + */ + @NotNull + private final Component label; + + /** + * The component to display in the second column. + */ + @NotNull + private final Component component; + + /** + * Creates a new instance. + * @param attribute the dialog attribute this entry represents + * @param label the label to display in the first column + * @param component the component to display in the second column + */ + public GuiInfoTwoColumn(@NotNull final DialogAttribute<G, A, R, T> attribute, @NotNull final Component label, @NotNull final Component component) { + super(attribute); + this.label = label; + this.component = component; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public Component getLabel() { + return label; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public Component getComponent() { + return component; + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public Component getRow() { + return null; + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public Component getGlue() { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isText() { + return false; + } + +} Property changes on: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoTwoColumn.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2013-07-19 06:35:29
|
Revision: 9359 http://sourceforge.net/p/gridarta/code/9359 Author: akirschbaum Date: 2013-07-19 06:35:23 +0000 (Fri, 19 Jul 2013) Log Message: ----------- Remove GuiInfoGlue.isText(). Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoGlue.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoRow.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoTwoColumn.java Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2013-07-19 06:23:01 UTC (rev 9358) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2013-07-19 06:35:23 UTC (rev 9359) @@ -451,7 +451,7 @@ input.setCaretPosition(0); input.setBorder(BorderFactory.createEmptyBorder(3, 7, 0, 0)); input.getPainter().setInvalidLinesPainted(false); - guiInfo = new GuiInfoGlue<G, A, R, ArchetypeAttributeText>(new DialogAttributeText<G, A, R>(archetypeAttribute, input), input, true); + guiInfo = new GuiInfoGlue<G, A, R, ArchetypeAttributeText>(new DialogAttributeText<G, A, R>(archetypeAttribute, input), input); } @Override @@ -612,7 +612,7 @@ gbc.weighty = 1.0; final Object glueGbc = gbc.clone(); - boolean isText = false; + boolean hasGlue = false; // now add the entries, line by line for (final ArchetypeAttribute archetypeAttribute : archetypeAttributeSection) { if (!(archetypeAttribute instanceof ArchetypeAttributeFixed)) { @@ -632,11 +632,11 @@ addElement(panel, tmpGuiInfo.getComponent(), compGbc); addElement(panel, tmpGuiInfo.getRow(), rowGbc); addElement(panel, tmpGuiInfo.getGlue(), glueGbc); - isText |= tmpGuiInfo.isText(); + hasGlue |= tmpGuiInfo.getGlue() != null; } } - if (!isText) { + if (!hasGlue) { // if the component does not already have glue, put glue inside to align its contents to the top. panel.add(Box.createGlue(), glueGbc); } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java 2013-07-19 06:23:01 UTC (rev 9358) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfo.java 2013-07-19 06:35:23 UTC (rev 9359) @@ -93,6 +93,4 @@ @Nullable public abstract Component getGlue(); - public abstract boolean isText(); - } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoGlue.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoGlue.java 2013-07-19 06:23:01 UTC (rev 9358) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoGlue.java 2013-07-19 06:35:23 UTC (rev 9359) @@ -39,18 +39,15 @@ @NotNull private final Component glue; - private final boolean isText; - /** * Creates a new instance. * @param attribute the dialog attribute this entry represents * @param glue the component to display filled both horizontally and * verically */ - public GuiInfoGlue(@NotNull final DialogAttribute<G, A, R, T> attribute, @NotNull final Component glue, final boolean isText) { + public GuiInfoGlue(@NotNull final DialogAttribute<G, A, R, T> attribute, @NotNull final Component glue) { super(attribute); this.glue = glue; - this.isText = isText; } /** @@ -89,12 +86,4 @@ return glue; } - /** - * {@inheritDoc} - */ - @Override - public boolean isText() { - return isText; - } - } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoRow.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoRow.java 2013-07-19 06:23:01 UTC (rev 9358) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoRow.java 2013-07-19 06:35:23 UTC (rev 9359) @@ -85,12 +85,4 @@ return null; } - /** - * {@inheritDoc} - */ - @Override - public boolean isText() { - return false; - } - } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoTwoColumn.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoTwoColumn.java 2013-07-19 06:23:01 UTC (rev 9358) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GuiInfoTwoColumn.java 2013-07-19 06:35:23 UTC (rev 9359) @@ -94,12 +94,4 @@ return null; } - /** - * {@inheritDoc} - */ - @Override - public boolean isText() { - return false; - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2013-07-19 06:49:00
|
Revision: 9361 http://sourceforge.net/p/gridarta/code/9361 Author: akirschbaum Date: 2013-07-19 06:48:57 +0000 (Fri, 19 Jul 2013) Log Message: ----------- Simplify code. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -74,9 +74,17 @@ public abstract void appendSummary(@NotNull final Document doc, @NotNull final Style style); - protected static void addLine(@NotNull final Document doc, @NotNull final AttributeSet style, @NotNull final String line) { + /** + * Appends a line to a {@link Document}. The line consists of the name of + * this attribute, possibly with some text prepended and/or appended. + * @param doc the document to add to + * @param style the style for the new text + * @param prefix the text to prepend; may be empty + * @param postfix the text to append; may be empty + */ + protected void addLine(@NotNull final Document doc, @NotNull final AttributeSet style, @NotNull final String prefix, @NotNull final String postfix) { try { - doc.insertString(doc.getLength(), line + "\n", style); + doc.insertString(doc.getLength(), prefix + ref.getAttributeName() + postfix + "\n", style); } catch (final BadLocationException e) { log.error("toggleSummary: Bad Location in Document!", e); } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -71,7 +71,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getAnimName(); if (!value.isEmpty()) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -98,7 +98,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String tmp = input.getText().trim(); if (!tmp.isEmpty() && !tmp.startsWith("<")) { - addLine(doc, style, getRef().getAttributeName() + " = " + tmp); + addLine(doc, style, "", " = " + tmp); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -72,7 +72,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final boolean value = input.isSelected(); if (value) { - addLine(doc, style, "<" + getRef().getAttributeName() + ">"); + addLine(doc, style, "<" , ">"); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -78,7 +78,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final boolean value = input.isSelected(); if (value) { - addLine(doc, style, "<" + getRef().getAttributeName() + ">"); + addLine(doc, style, "<", ">"); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -71,7 +71,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getFaceName(); if (!value.isEmpty()) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -86,7 +86,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); if (value != null && !value.isEmpty() && !value.equals("0")) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -95,7 +95,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); if (value != null && !value.isEmpty() && !value.equals("0")) { - addLine(doc, style, ref.getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -132,7 +132,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getSelectedItem().toString().trim(); if (!value.isEmpty() && !value.startsWith("<")) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -82,7 +82,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getSelectedItem().toString().trim(); if (!value.isEmpty() && !value.startsWith("<")) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -83,7 +83,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); if (value != null && !value.isEmpty() && !value.equals("0")) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -71,7 +71,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); if (value != null && !value.isEmpty()) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -71,7 +71,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); if (value != null && !value.isEmpty()) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -82,7 +82,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getSelectedItem().toString().trim(); if (!value.isEmpty() && !value.startsWith("<")) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -73,7 +73,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); if (value != null && !value.isEmpty()) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -96,7 +96,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText().trim(); if (!value.isEmpty() && !value.equals(CFTreasureListTree.NONE_SYM)) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java 2013-07-19 06:37:44 UTC (rev 9360) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java 2013-07-19 06:48:57 UTC (rev 9361) @@ -88,7 +88,7 @@ public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getSelectedItem().toString().trim(); if (!value.isEmpty() && !value.startsWith("<")) { - addLine(doc, style, getRef().getAttributeName() + " = " + value); + addLine(doc, style, "", " = " + value); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2013-07-19 06:58:14
|
Revision: 9362 http://sourceforge.net/p/gridarta/code/9362 Author: akirschbaum Date: 2013-07-19 06:58:07 +0000 (Fri, 19 Jul 2013) Log Message: ----------- Fix possible NullPointerExceptions in game object attributes dialog. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -72,6 +72,11 @@ @Nullable public abstract String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent); + /** + * Appends a summary line for this attribute to a {@link Document}. + * @param doc the document to append to + * @param style the style for the new text + */ public abstract void appendSummary(@NotNull final Document doc, @NotNull final Style style); /** Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -70,9 +70,11 @@ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getAnimName(); - if (!value.isEmpty()) { - addLine(doc, style, "", " = " + value); + if (value.isEmpty()) { + return; } + + addLine(doc, style, "", " = " + value); } } // DialogAttributeAnimationName Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -96,10 +96,17 @@ */ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { - final String tmp = input.getText().trim(); - if (!tmp.isEmpty() && !tmp.startsWith("<")) { - addLine(doc, style, "", " = " + tmp); + final String text = input.getText(); + if (text == null) { + return; } + + final String tmp = text.trim(); + if (tmp.isEmpty() || tmp.startsWith("<")) { + return; + } + + addLine(doc, style, "", " = " + tmp); } /** Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -70,10 +70,11 @@ */ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { - final boolean value = input.isSelected(); - if (value) { - addLine(doc, style, "<" , ">"); + if (!input.isSelected()) { + return; } + + addLine(doc, style, "<" , ">"); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -76,10 +76,11 @@ */ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { - final boolean value = input.isSelected(); - if (value) { - addLine(doc, style, "<", ">"); + if (!input.isSelected()) { + return; } + + addLine(doc, style, "<", ">"); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -70,9 +70,11 @@ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getFaceName(); - if (!value.isEmpty()) { - addLine(doc, style, "", " = " + value); + if (value.isEmpty()) { + return; } + + addLine(doc, style, "", " = " + value); } } // DialogAttributeFaceName Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -85,9 +85,11 @@ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); - if (value != null && !value.isEmpty() && !value.equals("0")) { - addLine(doc, style, "", " = " + value); + if (value == null || value.isEmpty() || value.equals("0")) { + return; } + + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -94,9 +94,11 @@ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); - if (value != null && !value.isEmpty() && !value.equals("0")) { - addLine(doc, style, "", " = " + value); + if (value == null || value.isEmpty() || value.equals("0")) { + return; } + + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -130,10 +130,17 @@ */ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { - final String value = input.getSelectedItem().toString().trim(); - if (!value.isEmpty() && !value.startsWith("<")) { - addLine(doc, style, "", " = " + value); + final Object selectedItem = input.getSelectedItem(); + if (selectedItem == null) { + return; } + + final String value = selectedItem.toString().trim(); + if (value.isEmpty() || value.startsWith("<")) { + return; + } + + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -80,10 +80,17 @@ */ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { - final String value = input.getSelectedItem().toString().trim(); - if (!value.isEmpty() && !value.startsWith("<")) { - addLine(doc, style, "", " = " + value); + final Object selectedItem = input.getSelectedItem(); + if (selectedItem == null) { + return; } + + final String value = selectedItem.toString().trim(); + if (value.isEmpty() || value.startsWith("<")) { + return; + } + + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -82,9 +82,11 @@ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); - if (value != null && !value.isEmpty() && !value.equals("0")) { - addLine(doc, style, "", " = " + value); + if (value == null || value.isEmpty() || value.equals("0")) { + return; } + + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -70,9 +70,11 @@ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); - if (value != null && !value.isEmpty()) { - addLine(doc, style, "", " = " + value); + if (value.isEmpty()) { + return; } + + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -70,9 +70,11 @@ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); - if (value != null && !value.isEmpty()) { - addLine(doc, style, "", " = " + value); + if (value.isEmpty()) { + return; } + + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -80,10 +80,17 @@ */ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { - final String value = input.getSelectedItem().toString().trim(); - if (!value.isEmpty() && !value.startsWith("<")) { - addLine(doc, style, "", " = " + value); + final Object selectedItem = input.getSelectedItem(); + if (selectedItem == null) { + return; } + + final String value = selectedItem.toString().trim(); + if (value.isEmpty() || value.startsWith("<")) { + return; + } + + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -72,9 +72,11 @@ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { final String value = input.getText(); - if (value != null && !value.isEmpty()) { - addLine(doc, style, "", " = " + value); + if (value == null || value.isEmpty()) { + return; } + + addLine(doc, style, "", " = " + value); } } // DialogAttributeString Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -71,7 +71,7 @@ */ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { - /* Nothing to do. */ + // Nothing to do. } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -94,10 +94,17 @@ */ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { - final String value = input.getText().trim(); - if (!value.isEmpty() && !value.equals(CFTreasureListTree.NONE_SYM)) { - addLine(doc, style, "", " = " + value); + final String text = input.getText(); + if (text == null) { + return; } + + final String value = text.trim(); + if (value.isEmpty() || value.equals(CFTreasureListTree.NONE_SYM)) { + return; + } + + addLine(doc, style, "", " = " + value); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java 2013-07-19 06:48:57 UTC (rev 9361) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java 2013-07-19 06:58:07 UTC (rev 9362) @@ -86,10 +86,17 @@ */ @Override public void appendSummary(@NotNull final Document doc, @NotNull final Style style) { - final String value = input.getSelectedItem().toString().trim(); - if (!value.isEmpty() && !value.startsWith("<")) { - addLine(doc, style, "", " = " + value); + final Object selectedItem = input.getSelectedItem(); + if (selectedItem == null) { + return; } + + final String value = selectedItem.toString().trim(); + if (value.isEmpty() || value.startsWith("<")) { + return; + } + + addLine(doc, style, "", " = " + value); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2013-07-19 07:20:00
|
Revision: 9365 http://sourceforge.net/p/gridarta/code/9365 Author: akirschbaum Date: 2013-07-19 07:19:52 +0000 (Fri, 19 Jul 2013) Log Message: ----------- Rename function name. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java 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/DialogAttribute.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -85,7 +85,7 @@ * encoded */ @Nullable - public abstract String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent); + public abstract String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent); /** * Appends a summary line for this attribute to a {@link Document}. Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -54,7 +54,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String inline = input.getAnimName(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!inline.equals(archetype.getAttributeString(archetypeAttributeName))) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -78,7 +78,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String encodedValue = getEncodedValue(); // get bitmask value final String archetypeAttributeName = getRef().getArchetypeAttributeName(); String oldValue = archetype.getAttributeString(archetypeAttributeName); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -56,7 +56,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (input.isSelected() != (archetype.getAttributeInt(archetypeAttributeName) == 1)) { return archetypeAttributeName + " " + (input.isSelected() ? 1 : 0); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -56,7 +56,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String valString; if (input.isSelected()) { valString = getRef().getTrueValue(); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -54,7 +54,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String inline = input.getFaceName(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!inline.equals(archetype.getAttributeString(archetypeAttributeName))) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -55,7 +55,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (input.getText().trim().isEmpty()) { if (archetype.hasAttribute(archetypeAttributeName)) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -62,7 +62,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String archetypeAttributeName = ref.getArchetypeAttributeName(); final int value; if (input.getText().trim().isEmpty()) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -71,7 +71,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final int index = input.getSelectedIndex(); if (index < gameObjectSpells.size() + (isOptionalSpell ? 1 : 0)) { final boolean isModified; Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -63,7 +63,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final int attributeValueTmp = input.getSelectedIndex(); final int attributeValue = archetypeTypeSet.getList(getRef().getListName()).get(attributeValueTmp).getFirst(); // attribute value Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -55,7 +55,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (input.getText().trim().isEmpty()) { if (archetype.getAttributeLong(archetypeAttributeName) != 0L) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -54,7 +54,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String newString = input.getText().trim(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!archetype.getAttributeString(archetypeAttributeName).equals(newString)) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -54,7 +54,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String newString = input.getText().trim(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!archetype.getAttributeString(archetypeAttributeName).equals(newString)) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -64,7 +64,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final int index = input.getSelectedIndex(); final int attributeValue = index == 0 ? 0 : numberSpells.getSpell(index - 1).getNumber(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -56,7 +56,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String inline = input.getText().trim(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!inline.equals(archetype.getAttributeString(archetypeAttributeName))) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -55,7 +55,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { if (getRef().getArchetypeAttributeName().equalsIgnoreCase("msg")) { final String msgText = StringUtils.removeTrailingWhitespaceFromLines(input.getText()); if (!msgText.isEmpty()) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -67,7 +67,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final String inline = input.getText().trim(); // input string final boolean isNone = inline.equals(CFTreasureListTree.NONE_SYM) || inline.isEmpty(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java 2013-07-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -70,7 +70,7 @@ */ @Nullable @Override - public String getText2(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { final int index = input.getSelectedIndex(); final int attributeValue = index == 0 ? undefinedSpellIndex : numberSpells.getSpell(index - 1).getNumber(); // attribute value final String archetypeAttributeName = getRef().getArchetypeAttributeName(); 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-19 07:19:06 UTC (rev 9364) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java 2013-07-19 07:19:52 UTC (rev 9365) @@ -715,7 +715,7 @@ final StringBuilder newArchText = new StringBuilder(); final String[] newMsg = new String[1]; for (final DialogAttribute<G, A, R, ?> dialogAttribute : attributesPaneBuilder.getDialogAttributes()) { - final String text = dialogAttribute.getText2(gameObject, archetype, newMsg, tmpArchetypeType, optionPane); + final String text = dialogAttribute.getObjectText(gameObject, archetype, newMsg, tmpArchetypeType, optionPane); if (text == null) { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2013-07-19 07:50:38
|
Revision: 9366 http://sourceforge.net/p/gridarta/code/9366 Author: akirschbaum Date: 2013-07-19 07:50:29 +0000 (Fri, 19 Jul 2013) Log Message: ----------- Move error dialogs out of DialogAttribute implementations. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java Added Paths: ----------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/InvalidAttributeException.java Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttribute.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.Document; @@ -32,7 +31,6 @@ import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * A single Attribute, combining an {@link ArchetypeAttribute} with its input @@ -79,13 +77,11 @@ * gameObject}'s current archetype * @param newMsg the new "msg" value for the owner * @param archetypeType the owner's archetype type - * @param parent the parent component of the dialog this attribute is part - * of - * @return the game object text or {@code null} if the attribute cannot be - * encoded + * @return the game object text or an empty string + * @throws InvalidAttributeException if the attribute cannot be encoded */ - @Nullable - public abstract String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent); + @NotNull + public abstract String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) throws InvalidAttributeException; /** * Appends a summary line for this attribute to a {@link Document}. Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeAnimationName.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.text.Document; import javax.swing.text.Style; import net.sf.gridarta.gui.utils.AnimationComponent; @@ -29,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeAnimationName<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeAnimationName> { @@ -52,9 +50,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final String inline = input.getAnimName(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!inline.equals(archetype.getAttributeString(archetypeAttributeName))) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBitmask.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -76,9 +76,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final String encodedValue = getEncodedValue(); // get bitmask value final String archetypeAttributeName = getRef().getArchetypeAttributeName(); String oldValue = archetype.getAttributeString(archetypeAttributeName); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBool.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.AbstractButton; import javax.swing.text.Document; import javax.swing.text.Style; @@ -29,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; // a boolean attribute (flag) @@ -54,9 +52,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (input.isSelected() != (archetype.getAttributeInt(archetypeAttributeName) == 1)) { return archetypeAttributeName + " " + (input.isSelected() ? 1 : 0); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeBoolSpec.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.AbstractButton; import javax.swing.text.Document; import javax.swing.text.Style; @@ -29,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; // a boolean attribute with customized true/false values @@ -54,9 +52,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final String valString; if (input.isSelected()) { valString = getRef().getTrueValue(); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFaceName.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.text.Document; import javax.swing.text.Style; import net.sf.gridarta.gui.utils.FaceComponent; @@ -29,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeFaceName<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeFaceName> { @@ -52,9 +50,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final String inline = input.getFaceName(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!inline.equals(archetype.getAttributeString(archetypeAttributeName))) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeFloat.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,9 +19,7 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.JFormattedTextField; -import javax.swing.JOptionPane; import javax.swing.text.Document; import javax.swing.text.Style; import net.sf.gridarta.model.archetype.Archetype; @@ -30,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeFloat<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeFloat> { @@ -53,9 +50,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) throws InvalidAttributeException { final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (input.getText().trim().isEmpty()) { if (archetype.hasAttribute(archetypeAttributeName)) { @@ -70,9 +67,7 @@ return archetypeAttributeName + " " + value; } } catch (final NumberFormatException ignored) { - // parsing failed: wrong entry!! - JOptionPane.showMessageDialog(parent, "Attribute '" + getRef().getAttributeName() + "' must be a number!", "Input Error", JOptionPane.ERROR_MESSAGE); - return null; + throw new InvalidAttributeException("must be a number"); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInt.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,9 +19,7 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.JFormattedTextField; -import javax.swing.JOptionPane; import javax.swing.text.Document; import javax.swing.text.Style; import net.sf.gridarta.model.archetype.Archetype; @@ -30,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeInt<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeInt> { @@ -60,9 +57,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) throws InvalidAttributeException { final String archetypeAttributeName = ref.getArchetypeAttributeName(); final int value; if (input.getText().trim().isEmpty()) { @@ -71,14 +68,12 @@ try { value = ((Number) input.getValue()).intValue(); } catch (final NumberFormatException ignored) { - JOptionPane.showMessageDialog(parent, "Attribute '" + ref.getAttributeName() + "' must be a number!", "Input Error", JOptionPane.ERROR_MESSAGE); - return null; + throw new InvalidAttributeException(getRef(), "must be a number"); } } if (value < ref.getMinValue() || value > ref.getMaxValue()) { - JOptionPane.showMessageDialog(parent, "Attribute '" + ref.getAttributeName() + "' must be " + ref.getMinValue() + ".." + ref.getMaxValue() + "!", "Input Error", JOptionPane.ERROR_MESSAGE); - return null; + throw new InvalidAttributeException(getRef(), "must be " + ref.getMinValue() + ".." + ref.getMaxValue()); } if (archetype.getAttributeInt(archetypeAttributeName) != value) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeInvSpell.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.JComboBox; import javax.swing.text.Document; import javax.swing.text.Style; @@ -31,7 +30,6 @@ import net.sf.gridarta.model.spells.GameObjectSpell; import net.sf.gridarta.model.spells.Spells; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeInvSpell<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeInvSpell> { @@ -69,9 +67,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final int index = input.getSelectedIndex(); if (index < gameObjectSpells.size() + (isOptionalSpell ? 1 : 0)) { final boolean isModified; Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeList.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.JComboBox; import javax.swing.text.Document; import javax.swing.text.Style; @@ -30,7 +29,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeList<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeList> { @@ -61,9 +59,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final int attributeValueTmp = input.getSelectedIndex(); final int attributeValue = archetypeTypeSet.getList(getRef().getListName()).get(attributeValueTmp).getFirst(); // attribute value Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeLong.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,9 +19,7 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.JFormattedTextField; -import javax.swing.JOptionPane; import javax.swing.text.Document; import javax.swing.text.Style; import net.sf.gridarta.model.archetype.Archetype; @@ -30,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeLong<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeLong> { @@ -53,9 +50,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) throws InvalidAttributeException { final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (input.getText().trim().isEmpty()) { if (archetype.getAttributeLong(archetypeAttributeName) != 0L) { @@ -68,8 +65,7 @@ return archetypeAttributeName + " " + value; } } catch (final NumberFormatException ignored) { - JOptionPane.showMessageDialog(parent, "Attribute '" + getRef().getAttributeName() + "' must be a number!", "Input Error", JOptionPane.ERROR_MESSAGE); - return null; + throw new InvalidAttributeException(getRef(), "must be a number"); } } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeMapPath.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.text.Document; import javax.swing.text.Style; import net.sf.gridarta.gui.map.maptilepane.TilePanel; @@ -29,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeMapPath<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeMapPath> { @@ -52,9 +50,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final String newString = input.getText().trim(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!archetype.getAttributeString(archetypeAttributeName).equals(newString)) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeScriptFile.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.text.Document; import javax.swing.text.Style; import net.sf.gridarta.gui.map.maptilepane.TilePanel; @@ -29,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeScriptFile<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeScriptFile> { @@ -52,9 +50,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final String newString = input.getText().trim(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!archetype.getAttributeString(archetypeAttributeName).equals(newString)) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeSpell.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.JComboBox; import javax.swing.text.Document; import javax.swing.text.Style; @@ -31,7 +30,6 @@ import net.sf.gridarta.model.spells.NumberSpell; import net.sf.gridarta.model.spells.Spells; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeSpell<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeSpell> { @@ -62,9 +60,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final int index = input.getSelectedIndex(); final int attributeValue = index == 0 ? 0 : numberSpells.getSpell(index - 1).getNumber(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeString.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.text.Document; import javax.swing.text.JTextComponent; import javax.swing.text.Style; @@ -29,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; // a String attribute @@ -54,9 +52,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final String inline = input.getText().trim(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!inline.equals(archetype.getAttributeString(archetypeAttributeName))) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeText.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.text.Document; import javax.swing.text.Style; import net.sf.gridarta.model.archetype.Archetype; @@ -30,7 +29,6 @@ import net.sf.gridarta.textedit.textarea.JEditTextArea; import net.sf.gridarta.utils.StringUtils; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeText<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeText> { @@ -53,9 +51,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { if (getRef().getArchetypeAttributeName().equalsIgnoreCase("msg")) { final String msgText = StringUtils.removeTrailingWhitespaceFromLines(input.getText()); if (!msgText.isEmpty()) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeTreasure.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,8 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; -import javax.swing.JOptionPane; import javax.swing.text.Document; import javax.swing.text.JTextComponent; import javax.swing.text.Style; @@ -32,7 +30,6 @@ import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.treasurelist.TreasureTree; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; // a treasurelist attribute @@ -65,17 +62,16 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) throws InvalidAttributeException { final String inline = input.getText().trim(); // input string final boolean isNone = inline.equals(CFTreasureListTree.NONE_SYM) || inline.isEmpty(); final String archetypeAttributeName = getRef().getArchetypeAttributeName(); if (!isNone && treasureTree.get(inline) == null && !inline.equalsIgnoreCase(archetype.getAttributeString(archetypeAttributeName))) { // The user has specified a WRONG treasurelist name, and it does not come // from the default gameObject. -> Error and out. - JOptionPane.showMessageDialog(parent, "In attribute '" + getRef().getAttributeName() + "':\n" + "'" + inline + "' is not a known treasurelist name!", "Input Error", JOptionPane.ERROR_MESSAGE); - return null; + throw new InvalidAttributeException("In attribute '" + getRef().getAttributeName() + "':\n" + "'" + inline + "' is not a known treasurelist name!"); } if (!inline.equalsIgnoreCase(archetype.getAttributeString(archetypeAttributeName)) && !(isNone && !archetype.hasAttribute(archetypeAttributeName))) { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java 2013-07-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/DialogAttributeZSpell.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.dialog.gameobjectattributes; -import java.awt.Component; import javax.swing.JComboBox; import javax.swing.text.Document; import javax.swing.text.Style; @@ -31,7 +30,6 @@ import net.sf.gridarta.model.spells.NumberSpell; import net.sf.gridarta.model.spells.Spells; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class DialogAttributeZSpell<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DialogAttribute<G, A, R, ArchetypeAttributeZSpell> { @@ -68,9 +66,9 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, final String[] newMsg, final ArchetypeType archetypeType, final Component parent) { + public String getObjectText(@NotNull final G gameObject, @NotNull final Archetype<G, A, R> archetype, @NotNull final String[] newMsg, @NotNull final ArchetypeType archetypeType) { final int index = input.getSelectedIndex(); final int attributeValue = index == 0 ? undefinedSpellIndex : numberSpells.getSpell(index - 1).getNumber(); // attribute value final String archetypeAttributeName = getRef().getArchetypeAttributeName(); 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-19 07:19:52 UTC (rev 9365) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/GameObjectAttributesDialog.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -715,8 +715,11 @@ final StringBuilder newArchText = new StringBuilder(); final String[] newMsg = new String[1]; for (final DialogAttribute<G, A, R, ?> dialogAttribute : attributesPaneBuilder.getDialogAttributes()) { - final String text = dialogAttribute.getObjectText(gameObject, archetype, newMsg, tmpArchetypeType, optionPane); - if (text == null) { + final String text; + try { + text = dialogAttribute.getObjectText(gameObject, archetype, newMsg, tmpArchetypeType); + } catch (final InvalidAttributeException ex) { + JOptionPane.showMessageDialog(optionPane, ex.getMessage(), "Input Error", JOptionPane.ERROR_MESSAGE); return false; } if (!text.isEmpty()) { Added: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/InvalidAttributeException.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/InvalidAttributeException.java (rev 0) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/InvalidAttributeException.java 2013-07-19 07:50:29 UTC (rev 9366) @@ -0,0 +1,53 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 The Gridarta Developers. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.dialog.gameobjectattributes; + +import net.sf.gridarta.model.archetypetype.ArchetypeAttribute; +import org.jetbrains.annotations.NotNull; + +/** + * Indicates that an attribute cannot be encoded. + * @author Andreas Kirschbaum + */ +public class InvalidAttributeException extends Exception { + + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance. + * @param message the reason why the attribute cannot be encoded + */ + public InvalidAttributeException(@NotNull final String message) { + super(message); + } + + /** + * Creates a new instance. + * @param attribute the attribute + * @param message the reason why the attribute cannot be encoded + */ + public InvalidAttributeException(@NotNull final ArchetypeAttribute attribute, @NotNull final String message) { + super("Attribute '" + attribute.getAttributeName() + "' " + message + "!"); + } + +} Property changes on: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/InvalidAttributeException.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |