From: <aki...@us...> - 2014-02-22 07:33:04
|
Revision: 9608 http://sourceforge.net/p/gridarta/code/9608 Author: akirschbaum Date: 2014-02-22 07:33:01 +0000 (Sat, 22 Feb 2014) Log Message: ----------- Do not ignore caught exception. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/NoSuchParameterException.java Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java 2014-02-22 07:26:49 UTC (rev 9607) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java 2014-02-22 07:33:01 UTC (rev 9608) @@ -403,7 +403,7 @@ try { plugin.convertType(parameter, newParameterType); } catch (final NoSuchParameterException ex) { - LOG.warn("Cannot create parameter for type " + newParameterType); + LOG.warn("Cannot create parameter for " + ex.getMessage()); } } Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/NoSuchParameterException.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/NoSuchParameterException.java 2014-02-22 07:26:49 UTC (rev 9607) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/NoSuchParameterException.java 2014-02-22 07:33:01 UTC (rev 9608) @@ -37,7 +37,7 @@ * @param type the missing parameter type */ public NoSuchParameterException(@NotNull final String type) { - super(type); + super("type " + type); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-22 10:13:39
|
Revision: 9619 http://sourceforge.net/p/gridarta/code/9619 Author: akirschbaum Date: 2014-02-22 10:13:34 +0000 (Sat, 22 Feb 2014) Log Message: ----------- Remove PluginModel.getTypes(). Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModel.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java 2014-02-22 09:58:19 UTC (rev 9618) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java 2014-02-22 10:13:34 UTC (rev 9619) @@ -59,6 +59,7 @@ import net.sf.gridarta.plugin.PluginModel; import net.sf.gridarta.plugin.parameter.NoSuchParameterException; import net.sf.gridarta.plugin.parameter.PluginParameter; +import net.sf.gridarta.plugin.parameter.PluginParameterFactory; import net.sf.gridarta.utils.ActionBuilderUtils; import net.sf.gridarta.utils.ResourceIcons; import net.sf.japi.swing.action.ActionBuilder; @@ -434,7 +435,7 @@ return existingParameterTypeEditor; } - final JComboBox newParameterTypeEditor = new JComboBox(pluginModel.getTypes()); + final JComboBox newParameterTypeEditor = new JComboBox(PluginParameterFactory.getTypes()); newParameterTypeEditor.setSelectedItem(parameter.getParameterType()); newParameterTypeEditor.addItemListener(new ItemListener() { Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModel.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModel.java 2014-02-22 09:58:19 UTC (rev 9618) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModel.java 2014-02-22 10:13:34 UTC (rev 9619) @@ -220,11 +220,6 @@ firePluginRegisteredEvent(plugin); } - @NotNull - public String[] getTypes() { - return pluginParameterFactory.getTypes(); - } - @Nullable public Plugin<G, A, R> newPlugin(@NotNull final String name, @NotNull final String code) { final Plugin<G, A, R> plugin = new Plugin<G, A, R>(name, pluginParameterFactory); Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2014-02-22 09:58:19 UTC (rev 9618) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2014-02-22 10:13:34 UTC (rev 9619) @@ -106,8 +106,12 @@ return p; } + /** + * Returns all available plugin parameter type names. + * @return the type names types + */ @NotNull - public String[] getTypes() { + public static String[] getTypes() { return new String[] { StringParameter.PARAMETER_TYPE, IntegerParameter.PARAMETER_TYPE, DoubleParameter.PARAMETER_TYPE, BooleanParameter.PARAMETER_TYPE, ArchetypeParameter.PARAMETER_TYPE, MapParameter.PARAMETER_TYPE, MapPathParameter.PARAMETER_TYPE, }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-22 12:59:31
|
Revision: 9624 http://sourceforge.net/p/gridarta/code/9624 Author: akirschbaum Date: 2014-02-22 12:59:26 +0000 (Sat, 22 Feb 2014) Log Message: ----------- Fix type combo box in parameter tab in plugin editor. Modified Paths: -------------- trunk/src/atrinik/ChangeLog trunk/src/crossfire/ChangeLog trunk/src/daimonin/ChangeLog trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java Added Paths: ----------- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginListener.java Modified: trunk/src/atrinik/ChangeLog =================================================================== --- trunk/src/atrinik/ChangeLog 2014-02-22 11:12:07 UTC (rev 9623) +++ trunk/src/atrinik/ChangeLog 2014-02-22 12:59:26 UTC (rev 9624) @@ -1,3 +1,7 @@ +2014-02-22 Andreas Kirschbaum + + * Fix type combo box in parameter tab in plugin editor. + 2014-02-19 Andreas Kirschbaum * Remove implementation for plugin parameters of type Modified: trunk/src/crossfire/ChangeLog =================================================================== --- trunk/src/crossfire/ChangeLog 2014-02-22 11:12:07 UTC (rev 9623) +++ trunk/src/crossfire/ChangeLog 2014-02-22 12:59:26 UTC (rev 9624) @@ -1,3 +1,7 @@ +2014-02-22 Andreas Kirschbaum + + * Fix type combo box in parameter tab in plugin editor. + 2014-02-19 Andreas Kirschbaum * Remove implementation for plugin parameters of type Modified: trunk/src/daimonin/ChangeLog =================================================================== --- trunk/src/daimonin/ChangeLog 2014-02-22 11:12:07 UTC (rev 9623) +++ trunk/src/daimonin/ChangeLog 2014-02-22 12:59:26 UTC (rev 9624) @@ -1,3 +1,7 @@ +2014-02-22 Andreas Kirschbaum + + * Fix type combo box in parameter tab in plugin editor. + 2014-02-19 Andreas Kirschbaum * Remove implementation for plugin parameters of type Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java 2014-02-22 11:12:07 UTC (rev 9623) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java 2014-02-22 12:59:26 UTC (rev 9624) @@ -41,8 +41,6 @@ import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.SwingConstants; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import net.sf.gridarta.gui.dialog.plugin.parameter.PluginParameterViewFactory; @@ -50,6 +48,7 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.plugin.Plugin; +import net.sf.gridarta.plugin.PluginListener; import net.sf.gridarta.plugin.PluginModel; import net.sf.gridarta.plugin.parameter.NoSuchParameterException; import net.sf.gridarta.plugin.parameter.PluginParameter; @@ -220,12 +219,13 @@ @NotNull private Component createParameterTab() { - plugin.addChangeListener(new ChangeListener() { + plugin.addPluginListener(new PluginListener() { @Override - public void stateChanged(final ChangeEvent e) { + public void parametersChanged() { redrawTable(); } + }); final Container parameterButtons = new JPanel(); Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java 2014-02-22 11:12:07 UTC (rev 9623) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java 2014-02-22 12:59:26 UTC (rev 9624) @@ -23,13 +23,9 @@ import bsh.Interpreter; import java.io.File; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.filter.Filter; import net.sf.gridarta.model.gameobject.GameObject; @@ -40,6 +36,7 @@ import net.sf.gridarta.plugin.parameter.PluginParameterFactory; import net.sf.gridarta.plugin.parameter.PluginParameterListener; import net.sf.gridarta.plugin.parameter.StringParameter; +import net.sf.gridarta.utils.EventListenerList2; import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.jdom.Content; @@ -107,10 +104,10 @@ private boolean script; /** - * The {@link ChangeListener ChangeListeners} to inform about changes. + * The {@link PluginListener PluginListeners} to inform about changes. */ @NotNull - private final Collection<ChangeListener> listeners = new HashSet<ChangeListener>(); + private final EventListenerList2<PluginListener> listeners = new EventListenerList2<PluginListener>(PluginListener.class); /** * The location to save this plugin to; set to {@code null} if the plugin @@ -227,6 +224,7 @@ parameters.add(pluginParameter); pluginParameter.addPluginParameterListener(pluginParameterListener); setModified(); + notifyParametersChangedListeners(); } /** @@ -236,32 +234,32 @@ public void removeParameter(final int index) { parameters.remove(index).removePluginParameterListener(pluginParameterListener); setModified(); + notifyParametersChangedListeners(); } /** - * Adds a {@link ChangeListener} to be notified about changes. + * Adds a {@link PluginListener} to be notified about changes. * @param listener the change listener */ - public void addChangeListener(@NotNull final ChangeListener listener) { + public void addPluginListener(@NotNull final PluginListener listener) { listeners.add(listener); } /** - * Removes a {@link ChangeListener} to be notified about changes. + * Removes a {@link PluginListener} to be notified about changes. * @param listener the change listener */ - public void removeListener(@NotNull final ChangeListener listener) { + public void removePluginListener(@NotNull final PluginListener listener) { listeners.remove(listener); } /** - * Notifies all registered {@link ChangeListener ChangeListeners} that this - * plugin has changed. + * Notifies all registered {@link PluginListener PluginListeners} that the + * parameters have changed. */ - private void notifyListeners() { - final ChangeEvent e = new ChangeEvent(this); - for (final ChangeListener listener : listeners) { - listener.stateChanged(e); + private void notifyParametersChangedListeners() { + for (final PluginListener listener : listeners.getListeners()) { + listener.parametersChanged(); } } @@ -301,6 +299,7 @@ parameters.add(pluginParameter); pluginParameter.addPluginParameterListener(pluginParameterListener); setModified(); + notifyParametersChangedListeners(); } /** @@ -395,6 +394,7 @@ oldParameter.removePluginParameterListener(pluginParameterListener); newParameter.addPluginParameterListener(pluginParameterListener); setModified(); + notifyParametersChangedListeners(); } /** @@ -409,23 +409,14 @@ * Marks the plugin as unmodified since last save. */ public void resetModified() { - if (!modified) { - return; - } - modified = false; - notifyListeners(); } /** * Marks this plugin a modified since last save. */ private void setModified() { - if (modified) { - return; - } modified = true; - notifyListeners(); } /** Added: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginListener.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginListener.java (rev 0) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginListener.java 2014-02-22 12:59:26 UTC (rev 9624) @@ -0,0 +1,35 @@ +/* + * 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.plugin; + +import java.util.EventListener; + +/** + * Interface for listeners interested in {@link Plugin} related events. + * @author Andreas Kirschbaum + */ +public interface PluginListener extends EventListener { + + /** + * Called whenever a parameter has been added, removed, or replaced. + */ + void parametersChanged(); + +} Property changes on: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginListener.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ 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...> - 2014-02-22 15:02:27
|
Revision: 9626 http://sourceforge.net/p/gridarta/code/9626 Author: akirschbaum Date: 2014-02-22 15:02:21 +0000 (Sat, 22 Feb 2014) Log Message: ----------- Fix configuration dialogs for Boolean, Integer, and Double plugin parameter types. Modified Paths: -------------- trunk/src/atrinik/ChangeLog trunk/src/crossfire/ChangeLog trunk/src/daimonin/ChangeLog trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/BooleanParameterView.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/DoubleParameterView.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/IntegerParameterView.java Modified: trunk/src/atrinik/ChangeLog =================================================================== --- trunk/src/atrinik/ChangeLog 2014-02-22 13:00:48 UTC (rev 9625) +++ trunk/src/atrinik/ChangeLog 2014-02-22 15:02:21 UTC (rev 9626) @@ -1,5 +1,8 @@ 2014-02-22 Andreas Kirschbaum + * Fix configuration dialogs for Boolean, Integer, and Double + plugin parameter types. + * Fix type combo box in parameter tab in plugin editor. 2014-02-19 Andreas Kirschbaum Modified: trunk/src/crossfire/ChangeLog =================================================================== --- trunk/src/crossfire/ChangeLog 2014-02-22 13:00:48 UTC (rev 9625) +++ trunk/src/crossfire/ChangeLog 2014-02-22 15:02:21 UTC (rev 9626) @@ -1,5 +1,8 @@ 2014-02-22 Andreas Kirschbaum + * Fix configuration dialogs for Boolean, Integer, and Double + plugin parameter types. + * Fix type combo box in parameter tab in plugin editor. 2014-02-19 Andreas Kirschbaum Modified: trunk/src/daimonin/ChangeLog =================================================================== --- trunk/src/daimonin/ChangeLog 2014-02-22 13:00:48 UTC (rev 9625) +++ trunk/src/daimonin/ChangeLog 2014-02-22 15:02:21 UTC (rev 9626) @@ -1,5 +1,8 @@ 2014-02-22 Andreas Kirschbaum + * Fix configuration dialogs for Boolean, Integer, and Double + plugin parameter types. + * Fix type combo box in parameter tab in plugin editor. 2014-02-19 Andreas Kirschbaum Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/BooleanParameterView.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/BooleanParameterView.java 2014-02-22 13:00:48 UTC (rev 9625) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/BooleanParameterView.java 2014-02-22 15:02:21 UTC (rev 9626) @@ -77,8 +77,15 @@ @Override public void actionPerformed(@NotNull final ActionEvent e) { final String yes = JOptionPane.showInputDialog(parent, "Checked text", parameter.getTrueText()); + if (yes == null) { + return; + } + parameter.setTrueText(yes); + final String no = JOptionPane.showInputDialog(parent, "Unchecked text", parameter.getFalseText()); - parameter.setTrueText(yes); + if (no == null) { + return; + } parameter.setFalseText(no); } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/DoubleParameterView.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/DoubleParameterView.java 2014-02-22 13:00:48 UTC (rev 9625) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/DoubleParameterView.java 2014-02-22 15:02:21 UTC (rev 9626) @@ -66,16 +66,17 @@ */ public DoubleParameterView(@NotNull final Component parent, @NotNull final DoubleParameter<G, A, R> parameter) { this.parameter = parameter; - value = new JSpinner(new SpinnerNumberModel(0.0, parameter.getMin(), parameter.getMax(), (parameter.getMax() - parameter.getMin()) / 100.0)); - try { - value.setValue(parameter.getValue()); - } catch (final IllegalArgumentException e) { - } + final SpinnerNumberModel model = new SpinnerNumberModel(0.0, 0.0, 0.0, 0.0); + model.setMinimum(parameter.getMin()); + model.setMaximum(parameter.getMax()); + model.setValue(parameter.getValue()); + model.setStepSize((parameter.getMax() - parameter.getMin()) / 100.0); + value = new JSpinner(model); value.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent e) { - parameter.setValue((Double) ((SpinnerNumberModel) value.getModel()).getNumber()); + parameter.setValue((Double) model.getNumber()); } }); config.setBorderPainted(false); @@ -84,16 +85,36 @@ @Override public void actionPerformed(final ActionEvent e) { final String min = JOptionPane.showInputDialog(parent, "Minimum value:", parameter.getMin()); + if (min == null) { + return; + } + final double min1; + try { + min1 = Double.parseDouble(min); + } catch (final NumberFormatException ignored) { + JOptionPane.showMessageDialog(parent, "Invalid minimum value: " + min); + return; + } + parameter.setMin(min1); + model.setMinimum(min1); + model.setStepSize(((Double) model.getMaximum() - min1) / 100.0); + updateTooltip(); + final String max = JOptionPane.showInputDialog(parent, "Maximum value:", parameter.getMax()); + if (max == null) { + return; + } + final double max1; try { - parameter.setMax(Double.parseDouble(max)); - parameter.setMin(Double.parseDouble(min)); - ((SpinnerNumberModel) value.getModel()).setMinimum(parameter.getMin()); - ((SpinnerNumberModel) value.getModel()).setMaximum(parameter.getMax()); - updateTooltip(); - } catch (final Exception ex) { - JOptionPane.showMessageDialog(null, "Could not change Double configuration"); + max1 = Double.parseDouble(max); + } catch (final NumberFormatException ignored) { + JOptionPane.showMessageDialog(parent, "Invalid maximum value: " + max); + return; } + parameter.setMax(max1); + model.setMaximum(max1); + model.setStepSize((max1 - min1) / 100.0); + updateTooltip(); } }); Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/IntegerParameterView.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/IntegerParameterView.java 2014-02-22 13:00:48 UTC (rev 9625) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/IntegerParameterView.java 2014-02-22 15:02:21 UTC (rev 9626) @@ -66,12 +66,16 @@ */ public IntegerParameterView(@NotNull final Component parent, @NotNull final IntegerParameter<G, A, R> parameter) { this.parameter = parameter; - value = new JSpinner(new SpinnerNumberModel((int) parameter.getValue(), parameter.getMin(), parameter.getMax(), 1)); + final SpinnerNumberModel model = new SpinnerNumberModel((int) parameter.getValue(), parameter.getMin(), parameter.getMax(), 1); + model.setMinimum(parameter.getMin()); + model.setMaximum(parameter.getMax()); + model.setValue(parameter.getValue()); + value = new JSpinner(model); value.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent e) { - parameter.setValue((Integer) ((SpinnerNumberModel) value.getModel()).getNumber()); + parameter.setValue((Integer) model.getNumber()); } }); config.setBorderPainted(false); @@ -80,16 +84,34 @@ @Override public void actionPerformed(final ActionEvent e) { final String min = JOptionPane.showInputDialog(parent, "Minimum value:", parameter.getMin()); + if (min == null) { + return; + } + final int min1; + try { + min1 = Integer.parseInt(min); + } catch (final NumberFormatException ignored) { + JOptionPane.showMessageDialog(parent, "Invalid minimum value: " + min); + return; + } + parameter.setMin(min1); + model.setMinimum(min1); + updateTooltip(); + final String max = JOptionPane.showInputDialog(parent, "Maximum value:", parameter.getMax()); + if (max == null) { + return; + } + final int max1; try { - parameter.setMax(Integer.parseInt(max)); - parameter.setMin(Integer.parseInt(min)); - ((SpinnerNumberModel) value.getModel()).setMinimum(parameter.getMin()); - ((SpinnerNumberModel) value.getModel()).setMaximum(parameter.getMax()); - updateTooltip(); - } catch (final Exception ex) { - JOptionPane.showMessageDialog(null, "Could not change integer configuration"); + max1 = Integer.parseInt(max); + } catch (final NumberFormatException ignored) { + JOptionPane.showMessageDialog(parent, "Invalid maximum value: " + max); + return; } + parameter.setMax(max1); + model.setMaximum(max1); + updateTooltip(); } }); @@ -115,7 +137,8 @@ } /** - * Updates the tooltip text of {@link #config} and {@link #value} to reflect the current parameters. + * Updates the tooltip text of {@link #config} and {@link #value} to reflect + * the current parameters. */ private void updateTooltip() { final String toolTip = "[" + Integer.toString(parameter.getMin()) + "," + Integer.toString(parameter.getMax()) + "]"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-22 17:02:42
|
Revision: 9627 http://sourceforge.net/p/gridarta/code/9627 Author: akirschbaum Date: 2014-02-22 17:02:36 +0000 (Sat, 22 Feb 2014) Log Message: ----------- Do not retain configuration of plugin parameters when changing parameter types. Modified Paths: -------------- trunk/src/atrinik/ChangeLog trunk/src/crossfire/ChangeLog trunk/src/daimonin/ChangeLog trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java Modified: trunk/src/atrinik/ChangeLog =================================================================== --- trunk/src/atrinik/ChangeLog 2014-02-22 15:02:21 UTC (rev 9626) +++ trunk/src/atrinik/ChangeLog 2014-02-22 17:02:36 UTC (rev 9627) @@ -1,5 +1,8 @@ 2014-02-22 Andreas Kirschbaum + * Do not retain configuration of plugin parameters when changing + parameter types. + * Fix configuration dialogs for Boolean, Integer, and Double plugin parameter types. Modified: trunk/src/crossfire/ChangeLog =================================================================== --- trunk/src/crossfire/ChangeLog 2014-02-22 15:02:21 UTC (rev 9626) +++ trunk/src/crossfire/ChangeLog 2014-02-22 17:02:36 UTC (rev 9627) @@ -1,5 +1,8 @@ 2014-02-22 Andreas Kirschbaum + * Do not retain configuration of plugin parameters when changing + parameter types. + * Fix configuration dialogs for Boolean, Integer, and Double plugin parameter types. Modified: trunk/src/daimonin/ChangeLog =================================================================== --- trunk/src/daimonin/ChangeLog 2014-02-22 15:02:21 UTC (rev 9626) +++ trunk/src/daimonin/ChangeLog 2014-02-22 17:02:36 UTC (rev 9627) @@ -1,5 +1,8 @@ 2014-02-22 Andreas Kirschbaum + * Do not retain configuration of plugin parameters when changing + parameter types. + * Fix configuration dialogs for Boolean, Integer, and Double plugin parameter types. Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java 2014-02-22 15:02:21 UTC (rev 9626) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java 2014-02-22 17:02:36 UTC (rev 9627) @@ -389,7 +389,7 @@ if (index == -1) { throw new NoSuchParameterException(pluginParameter); } - final PluginParameter<G, A, R, ?> newParameter = pluginParameterFactory.createParameter(newType, codec.toXML(parameters.get(index))); + final PluginParameter<G, A, R, ?> newParameter = pluginParameterFactory.createParameter(newType); final PluginParameter<G, A, R, ?> oldParameter = parameters.set(index, newParameter); oldParameter.removePluginParameterListener(pluginParameterListener); newParameter.addPluginParameterListener(pluginParameterListener); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-22 20:00:14
|
Revision: 9635 http://sourceforge.net/p/gridarta/code/9635 Author: akirschbaum Date: 2014-02-22 20:00:05 +0000 (Sat, 22 Feb 2014) Log Message: ----------- Weaken types. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginView.java trunk/src/model/src/main/java/net/sf/gridarta/model/mapcursor/MapCursor.java Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginView.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginView.java 2014-02-22 19:22:28 UTC (rev 9634) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginView.java 2014-02-22 20:00:05 UTC (rev 9635) @@ -21,6 +21,7 @@ import java.awt.BorderLayout; import java.awt.Component; +import java.awt.Container; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; @@ -218,7 +219,7 @@ p.setMessageType(JOptionPane.QUESTION_MESSAGE); p.setMessage(ActionBuilderUtils.format(ACTION_BUILDER, "pluginViewProvideParameters", plugin.getName())); final GridBagLayout layout = new GridBagLayout(); - final JComponent panel = new JPanel(layout); + final Container panel = new JPanel(layout); final JDialog dialog = p.createDialog(parent, plugin.getName()); dialog.setModal(true); dialog.getContentPane().removeAll(); Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/mapcursor/MapCursor.java 2014-02-22 19:22:28 UTC (rev 9634) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/mapcursor/MapCursor.java 2014-02-22 20:00:05 UTC (rev 9635) @@ -22,6 +22,7 @@ import java.awt.Dimension; import java.awt.Point; import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.direction.Direction; @@ -148,7 +149,7 @@ * transaction. */ @NotNull - private final Rectangle transactionMapRec = new Rectangle(); + private final Rectangle2D transactionMapRec = new Rectangle(); /** * The MapCursorListeners to inform of changes. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-22 21:18:43
|
Revision: 9637 http://sourceforge.net/p/gridarta/code/9637 Author: akirschbaum Date: 2014-02-22 21:18:37 +0000 (Sat, 22 Feb 2014) Log Message: ----------- Change PluginParameter interface. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/archetype/ArchetypeParameterView.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/map/MapParameterView.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginExecutor.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/AbstractPathParameter.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/AbstractValuePluginParameter.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/ArchetypeParameter.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/MapParameter.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameter.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java Added Paths: ----------- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/InvalidValueException.java Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -60,7 +60,7 @@ * @noinspection TypeMayBeWeakened */ public MapPathParameterView(@NotNull final Component parent, @NotNull final MapPathParameter<G, A, R> parameter) { - final File value = parameter.getValue(); + final File value = parameter.getValueOrNull(); this.value = new JFileField(parent, null, parameter.getBaseDir(), value == null ? new File("") : value, JFileChooser.FILES_AND_DIRECTORIES); this.value.addDocumentListener(new DocumentListener() { Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/archetype/ArchetypeParameterView.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/archetype/ArchetypeParameterView.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/archetype/ArchetypeParameterView.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -75,7 +75,7 @@ value.setEditable(true); value.setEditor(archComboBoxEditor); value.setPreferredSize(new Dimension(value.getPreferredSize().width, archComboBoxEditor.getEditorComponent().getPreferredSize().height)); - value.setSelectedItem(parameter.getValue()); + value.setSelectedItem(parameter.getValueOrNull()); value.addItemListener(new ItemListener() { @Override Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/map/MapParameterView.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/map/MapParameterView.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/map/MapParameterView.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -81,7 +81,7 @@ } } }); - value.setSelectedItem(parameter.getValue()); + value.setSelectedItem(parameter.getValueOrNull()); } /** Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginExecutor.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginExecutor.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginExecutor.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -180,7 +180,7 @@ try { pluginParameters.setInterpreterValues(runner, PluginRunMode.BATCH); for (final PluginParameter<G, A, R, ?> parameter : plugin) { - runner.set(parameter.getName(), parameter.getValue()); + runner.set(parameter.getName(), parameter.getValueOrNull()); } } catch (final TargetError ex) { final CharArrayWriter charArrayWriter = new CharArrayWriter(); Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/AbstractPathParameter.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/AbstractPathParameter.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/AbstractPathParameter.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -69,15 +69,31 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public File getValue() { + public File getValue() throws InvalidValueException { final String stringValue = getStringValue(); if (stringValue.isEmpty()) { - return null; + throw new InvalidValueException("not value specified"); } final File file = new File(stringValue); - return file.exists() ? file : null; + if (!file.exists()) { + throw new InvalidValueException("file does not exist: " + stringValue); + } + return file; } + /** + * {@inheritDoc} + */ + @Nullable + @Override + public File getValueOrNull() { + try { + return getValue(); + } catch (final InvalidValueException ignored) { + return null; + } + } + } Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/AbstractValuePluginParameter.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/AbstractValuePluginParameter.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/AbstractValuePluginParameter.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -55,6 +55,15 @@ } /** + * {@inheritDoc} + */ + @NotNull + @Override + public V getValueOrNull() { + return value; + } + + /** * Updates the parameter value. * @param value the new value */ Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/ArchetypeParameter.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/ArchetypeParameter.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/ArchetypeParameter.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -65,12 +65,26 @@ /** * {@inheritDoc} */ + @NotNull + @Override + public Archetype<G, A, R> getValue() throws InvalidValueException { + final String archetypeName = getStringValue(); + try { + return archetypeSet.getArchetype(archetypeName); + } catch (final UndefinedArchetypeException ex) { + throw new InvalidValueException("undefined archetype: " + archetypeName, ex); + } + } + + /** + * {@inheritDoc} + */ @Nullable @Override - public Archetype<G, A, R> getValue() { + public Archetype<G, A, R> getValueOrNull() { try { - return archetypeSet.getArchetype(getStringValue()); - } catch (final UndefinedArchetypeException ignored) { + return getValue(); + } catch (final InvalidValueException ignored) { return null; } } Added: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/InvalidValueException.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/InvalidValueException.java (rev 0) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/InvalidValueException.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -0,0 +1,54 @@ +/* + * 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.plugin.parameter; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * An exception that is thrown if the string representation of value in a {@link + * PluginParameter} cannot be converted to an object. + * @author Andreas Kirschbaum + */ +public class InvalidValueException extends Exception { + + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance. + * @param reason the reason why the value cannot be created + */ + public InvalidValueException(@NotNull final String reason) { + super(reason); + } + + /** + * Creates a new instance. + * @param reason the reason why the value cannot be created + * @param cause the cause or {@code null} + */ + public InvalidValueException(@NotNull final String reason, @Nullable final Throwable cause) { + super(reason, cause); + } + +} Property changes on: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/InvalidValueException.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/MapParameter.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/MapParameter.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/MapParameter.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -19,11 +19,15 @@ package net.sf.gridarta.plugin.parameter; +import java.io.File; +import java.io.IOException; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.io.PathManager; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapcontrol.MapControl; import net.sf.gridarta.model.mapmanager.MapManager; +import net.sf.gridarta.model.mapmodel.MapFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -52,13 +56,23 @@ private final MapManager<G, A, R> mapManager; /** + * The {@link PathManager} instance for converting {@link File Files} into + * path names. + */ + @NotNull + private final PathManager pathManager; + + /** * Creates a new instance. * @param mapManager the map manager for converting map paths to map control * instances + * @param pathManager the path manager instance for incverting files into + * path names */ - public MapParameter(@NotNull final MapManager<G, A, R> mapManager) { + public MapParameter(@NotNull final MapManager<G, A, R> mapManager, @NotNull final PathManager pathManager) { super(""); // XXX this.mapManager = mapManager; + this.pathManager = pathManager; } /** @@ -82,21 +96,40 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public MapControl<G, A, R> getValue() { + public MapControl<G, A, R> getValue() throws InvalidValueException { final String stringValue = getStringValue(); if (CURRENT_MAP.equals(stringValue)) { - return mapManager.getCurrentMap(); + final MapControl<G, A, R> currentMap = mapManager.getCurrentMap(); + if (currentMap == null) { + throw new InvalidValueException("no map is opened"); + } + currentMap.acquire(); // XXX: this causes a leak + return currentMap; } - for (final MapControl<G, A, R> mapControl : mapManager.getOpenedMaps()) { - if (mapControl.getMapModel().getMapArchObject().getMapName().equalsIgnoreCase(stringValue)) { - return mapControl; - } + final MapFile mapFile = pathManager.getMapFile(new File(stringValue)); + final MapControl<G, A, R> mapControl; + try { + mapControl = mapManager.openMapFile(mapFile, false); + } catch (final IOException ex) { + throw new InvalidValueException("map " + stringValue + " does not exist: " + ex.getMessage(), ex); } + return mapControl; + } - return null; + /** + * {@inheritDoc} + */ + @Nullable + @Override + public MapControl<G, A, R> getValueOrNull() { + try { + return getValue(); + } catch (final InvalidValueException ignored) { + return null; + } } /** Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameter.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameter.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameter.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -80,11 +80,19 @@ void setDescription(@NotNull String description); /** - * Returns the current value of the parameter. - * @return the value or {@code null} if invalid. + * Returns the current value of this parameter. + * @return the value + * @throws InvalidValueException if the the value is invalid */ + @NotNull + V getValue() throws InvalidValueException; + + /** + * Returns the current value of this parameter. + * @return the value or {@code null} if the the value is invalid + */ @Nullable - V getValue(); + V getValueOrNull(); /** * Returns the string representation of the current value of the parameter. Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -22,6 +22,7 @@ import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.archetypeset.ArchetypeSet; import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.io.PathManager; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapmanager.MapManager; import net.sf.gridarta.model.settings.ProjectSettings; @@ -44,16 +45,27 @@ private final ProjectSettings projectSettings; /** + * The {@link PathManager} instance for converting files into path names. + */ + @NotNull + private final PathManager pathManager; + + /** * The {@link PluginParameterCodec} for converting {@link PluginParameter * PluginParameters} to or from XML representation. */ @NotNull private final PluginParameterCodec<G, A, R> codec = new PluginParameterCodec<G, A, R>(); - public PluginParameterFactory(@NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final ProjectSettings projectSettings) { + /** + * @param pathManager the path manager instance for incverting files into + * path names + */ + public PluginParameterFactory(@NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final ProjectSettings projectSettings, @NotNull final PathManager pathManager) { this.archetypeSet = archetypeSet; this.mapManager = mapManager; this.projectSettings = projectSettings; + this.pathManager = pathManager; } @NotNull @@ -91,7 +103,7 @@ return new ArchetypeParameter<G, A, R>(archetypeSet); } if (type.equals(MapParameter.PARAMETER_TYPE)) { - return new MapParameter<G, A, R>(mapManager); + return new MapParameter<G, A, R>(mapManager, pathManager); } if (type.equals(MapPathParameter.PARAMETER_TYPE)) { return new MapPathParameter<G, A, R>(projectSettings.getMapsDirectory()); Modified: trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java =================================================================== --- trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -260,7 +260,7 @@ @Test public void testMapToXml1() throws IOException { final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); - final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = new MapParameter<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getMapManager()); + final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = new MapParameter<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getMapManager(), mapControlCreator.getPathManager()); parameter.setName("Name"); parameter.setDescription("Description"); final StringBuilder sb = new StringBuilder(); @@ -282,7 +282,7 @@ @Test public void testMapToXml2() throws IOException { final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); - final MapParameter<TestGameObject, TestMapArchObject, TestArchetype> parameter = new MapParameter<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getMapManager()); + final MapParameter<TestGameObject, TestMapArchObject, TestArchetype> parameter = new MapParameter<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getMapManager(), mapControlCreator.getPathManager()); parameter.setValueToCurrent(); final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); @@ -303,7 +303,7 @@ @Test public void testMapToXml3() throws IOException { final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); - final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = new MapParameter<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getMapManager()); + final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = new MapParameter<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getMapManager(), mapControlCreator.getPathManager()); final File mapDir = new File("/tmp"); final String mapPath = "path/to/map"; mapControlCreator.newMapControl(mapControlCreator.getPathManager().getMapFile(new File(mapDir, mapPath)), "map name", new Size2D(13, 15)); @@ -427,7 +427,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("net.sf.gridarta.model.archetype.Archetype", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - Assert.assertNull(parameter.getValue()); + Assert.assertNull(parameter.getValueOrNull()); Assert.assertEquals("", parameter.getStringValue()); } @@ -454,7 +454,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("net.sf.gridarta.model.archetype.Archetype", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - Assert.assertNull(parameter.getValue()); + Assert.assertNull(parameter.getValueOrNull()); Assert.assertEquals("undefined_archetype", parameter.getStringValue()); } @@ -482,7 +482,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("net.sf.gridarta.model.archetype.Archetype", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - Assert.assertSame(archetype, parameter.getValue()); + Assert.assertSame(archetype, parameter.getValueOrNull()); Assert.assertEquals("existing_archetype", parameter.getStringValue()); } @@ -512,7 +512,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("java.lang.Boolean", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - Assert.assertSame(Boolean.FALSE, parameter.getValue()); + Assert.assertSame(Boolean.FALSE, parameter.getValueOrNull()); Assert.assertEquals("No", booleanParameter.getFalseText()); Assert.assertEquals("Yes", booleanParameter.getTrueText()); } @@ -543,7 +543,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("java.lang.Boolean", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - Assert.assertSame(Boolean.TRUE, parameter.getValue()); + Assert.assertSame(Boolean.TRUE, parameter.getValueOrNull()); Assert.assertEquals("false-text", booleanParameter.getFalseText()); Assert.assertEquals("true-text", booleanParameter.getTrueText()); } @@ -574,7 +574,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("java.lang.Double", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - Assert.assertEquals(0.0, parameter.getValue()); + Assert.assertEquals(0.0, parameter.getValueOrNull()); Assert.assertEquals(0.0, doubleParameter.getMin()); Assert.assertEquals(1.0, doubleParameter.getMax()); } @@ -605,7 +605,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("java.lang.Double", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - Assert.assertEquals(12.34, parameter.getValue()); + Assert.assertEquals(12.34, parameter.getValueOrNull()); Assert.assertEquals(-123.456, doubleParameter.getMin()); Assert.assertEquals(234.0, doubleParameter.getMax()); } @@ -636,7 +636,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("java.lang.Integer", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - Assert.assertEquals(0, parameter.getValue()); + Assert.assertEquals(0, parameter.getValueOrNull()); Assert.assertEquals(-2147483648, integerParameter.getMin()); Assert.assertEquals(2147483647, integerParameter.getMax()); } @@ -667,7 +667,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("java.lang.Integer", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - Assert.assertEquals(2, parameter.getValue()); + Assert.assertEquals(2, parameter.getValueOrNull()); Assert.assertEquals(-123, integerParameter.getMin()); Assert.assertEquals(234, integerParameter.getMax()); } @@ -696,7 +696,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("net.sf.gridarta.model.mapcontrol.MapControl", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - Assert.assertSame(mapControlCreator.getMapManager().getCurrentMap(), parameter.getValue()); + Assert.assertSame(mapControlCreator.getMapManager().getCurrentMap(), parameter.getValueOrNull()); } /** @@ -727,7 +727,7 @@ Assert.assertEquals("Name", parameter.getName()); Assert.assertEquals("net.sf.gridarta.model.mapcontrol.MapControl", parameter.getParameterType()); Assert.assertEquals("Description", parameter.getDescription()); - final MapControl<?, ?, ?> mapControl2 = mapParameter.getValue(); + final MapControl<?, ?, ?> mapControl2 = mapParameter.getValueOrNull(); Assert.assertNotNull(mapControl2); final MapFile mapFile = mapControl2.getMapModel().getMapFile(); Assert.assertNotNull(mapFile); @@ -766,7 +766,7 @@ private static PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> fromXML(@NotNull final TestMapControlCreator mapControlCreator, @NotNull final String string) throws IOException, JDOMException, NoSuchParameterException { final SAXBuilder builder = new SAXBuilder(false); final Document document = builder.build(new StringReader(string)); - final PluginParameterFactory<TestGameObject, TestMapArchObject, TestArchetype> parameterFactory = new PluginParameterFactory<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getArchetypeSet(), mapControlCreator.getMapManager(), mapControlCreator.getProjectSettings()); + final PluginParameterFactory<TestGameObject, TestMapArchObject, TestArchetype> parameterFactory = new PluginParameterFactory<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getArchetypeSet(), mapControlCreator.getMapManager(), mapControlCreator.getProjectSettings(), mapControlCreator.getPathManager()); final Element element = document.getRootElement(); return parameterFactory.createParameter(element); } Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java =================================================================== --- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-02-22 20:32:35 UTC (rev 9636) +++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-02-22 21:18:37 UTC (rev 9637) @@ -260,7 +260,7 @@ final Map<String, TreasureTreeNode> specialTreasureLists = loadSpecialTreasureLists(errorView, xmlHelper.getDocumentBuilder(), projectSettings); treasureTree = TreasureLoader.parseTreasures(errorView, specialTreasureLists, configSource, projectSettings); final NamedFilter defaultFilterList = new NamedFilter(Collections.<NamedGameObjectMatcher>emptyList()); - final PluginParameterFactory<G, A, R> pluginParameterFactory = new PluginParameterFactory<G, A, R>(archetypeSet, mapManager, projectSettings); + final PluginParameterFactory<G, A, R> pluginParameterFactory = new PluginParameterFactory<G, A, R>(archetypeSet, mapManager, projectSettings, pathManager); final PluginModelParser<G, A, R> pluginModelParser = new PluginModelParser<G, A, R>(pluginParameterFactory); pluginModel = PluginModelLoader.loadPlugins(pluginParameterFactory, pluginModelParser, errorView, scriptsFile); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-23 09:04:33
|
Revision: 9638 http://sourceforge.net/p/gridarta/code/9638 Author: akirschbaum Date: 2014-02-23 09:04:27 +0000 (Sun, 23 Feb 2014) Log Message: ----------- Do not run plugin scripts if not all parameter values are specified. Modified Paths: -------------- trunk/src/atrinik/ChangeLog trunk/src/crossfire/ChangeLog trunk/src/daimonin/ChangeLog trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginController.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginView.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginExecutor.java Modified: trunk/src/atrinik/ChangeLog =================================================================== --- trunk/src/atrinik/ChangeLog 2014-02-22 21:18:37 UTC (rev 9637) +++ trunk/src/atrinik/ChangeLog 2014-02-23 09:04:27 UTC (rev 9638) @@ -1,3 +1,8 @@ +2014-02-23 Andreas Kirschbaum + + * Do not run plugin scripts if not all parameter values are + specified. + 2014-02-22 Andreas Kirschbaum * Do not retain configuration of plugin parameters when changing Modified: trunk/src/crossfire/ChangeLog =================================================================== --- trunk/src/crossfire/ChangeLog 2014-02-22 21:18:37 UTC (rev 9637) +++ trunk/src/crossfire/ChangeLog 2014-02-23 09:04:27 UTC (rev 9638) @@ -1,3 +1,8 @@ +2014-02-23 Andreas Kirschbaum + + * Do not run plugin scripts if not all parameter values are + specified. + 2014-02-22 Andreas Kirschbaum * Do not retain configuration of plugin parameters when changing Modified: trunk/src/daimonin/ChangeLog =================================================================== --- trunk/src/daimonin/ChangeLog 2014-02-22 21:18:37 UTC (rev 9637) +++ trunk/src/daimonin/ChangeLog 2014-02-23 09:04:27 UTC (rev 9638) @@ -1,3 +1,8 @@ +2014-02-23 Andreas Kirschbaum + + * Do not run plugin scripts if not all parameter values are + specified. + 2014-02-22 Andreas Kirschbaum * Do not retain configuration of plugin parameters when changing Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginController.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginController.java 2014-02-22 21:18:37 UTC (rev 9637) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginController.java 2014-02-23 09:04:27 UTC (rev 9638) @@ -22,6 +22,7 @@ import java.awt.Component; import java.io.File; import java.io.IOException; +import java.util.Map; import javax.swing.Action; import javax.swing.JFileChooser; import javax.swing.JOptionPane; @@ -244,11 +245,12 @@ public void runPlugin(@NotNull final Plugin<G, A, R> plugin) { final Plugin<G, A, R> clonedPlugin = plugin.clonePlugin(); - if (!view.getRunValues(clonedPlugin, parent)) { + final Map<String, Object> runValues = view.getRunValues(clonedPlugin, parent); + if (runValues == null) { return; } - new PluginExecutor<G, A, R>(pluginModel, pluginParameters).doRunPlugin(clonedPlugin, view.createConsole(clonedPlugin.getName())); // XXX: drops thread + new PluginExecutor<G, A, R>(pluginModel, pluginParameters).doRunPlugin(clonedPlugin, view.createConsole(clonedPlugin.getName()), runValues); // XXX: drops thread } @ActionMethod Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginView.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginView.java 2014-02-22 21:18:37 UTC (rev 9637) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/PluginView.java 2014-02-23 09:04:27 UTC (rev 9638) @@ -25,6 +25,9 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import javax.swing.AbstractButton; import javax.swing.Action; import javax.swing.JComponent; @@ -45,6 +48,7 @@ import net.sf.gridarta.plugin.PluginConsole; import net.sf.gridarta.plugin.PluginModel; import net.sf.gridarta.plugin.PluginModelListener; +import net.sf.gridarta.plugin.parameter.InvalidValueException; import net.sf.gridarta.plugin.parameter.PluginParameter; import net.sf.gridarta.utils.ActionBuilderUtils; import net.sf.gridarta.utils.ResourceIcons; @@ -209,9 +213,16 @@ return pluginConsole; } - public boolean getRunValues(@NotNull final Plugin<G, A, R> plugin, @NotNull final Component parent) { + /** + * Asks the user for input parameter to run a plugin. + * @param plugin the plugin + * @param parent the parent component for dialogs + * @return the input parameters or {@code null} to not run the plugin + */ + @Nullable + public Map<String, Object> getRunValues(@NotNull final Plugin<G, A, R> plugin, @NotNull final Component parent) { if (!plugin.hasParameters()) { - return true; + return Collections.emptyMap(); } final JOptionPane p = new PluginViewPane(); @@ -243,9 +254,21 @@ dialog.setVisible(true); final Object result = p.getValue(); if (!(result instanceof Integer) || (Integer) result != JOptionPane.YES_OPTION) { - return false; + return null; } - return true; + final Map<String, Object> parameterValues = new HashMap<String, Object>(); + for (final PluginParameter<G, A, R, ?> parameter : plugin) { + final String parameterName = parameter.getName(); + final Object parameterValue; + try { + parameterValue = parameter.getValue(); + } catch (final InvalidValueException ex) { + JOptionPane.showMessageDialog(parent, "Invalid value for parameter " + parameterName + ": " + ex.getMessage()); + return null; + } + parameterValues.put(parameterName, parameterValue); + } + return parameterValues; } } Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginExecutor.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginExecutor.java 2014-02-22 21:18:37 UTC (rev 9637) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginExecutor.java 2014-02-23 09:04:27 UTC (rev 9638) @@ -28,6 +28,8 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.io.Reader; +import java.util.HashMap; +import java.util.Map; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -79,7 +81,7 @@ } final Plugin<G, A, R> clonedPlugin = modelTemplate.clonePlugin(); - + final Map<String, Object> runValues = new HashMap<String, Object>(); for (final String parameter : parameters) { final String[] tmp = StringUtils.PATTERN_EQUAL.split(parameter, 2); if (tmp.length != 2) { @@ -110,7 +112,20 @@ System.out.println("invalid value " + tmp[1] + " for parameter " + tmp[0]); return 1; } + + runValues.put(clonedParameter.getName(), tmp[1]); } + for (final PluginParameter<G, A, R, ?> parameter : clonedPlugin) { + final String parameterName = parameter.getName(); + if (!runValues.containsKey(parameterName)) { + final Object parameterValue = parameter.getValueOrNull(); + if (parameterValue == null) { + System.err.println("no value for parameter " + parameterName); + return 1; + } + runValues.put(parameterName, parameterValue); + } + } final ConsoleInterface console = new ConsoleInterface() { @@ -145,7 +160,7 @@ } }; - final BshThread<G, A, R> pluginThread = doRunPlugin(clonedPlugin, console); + final BshThread<G, A, R> pluginThread = doRunPlugin(clonedPlugin, console, runValues); if (pluginThread == null) { return 1; } @@ -167,20 +182,20 @@ } /** - * Runs a plugin model. The model is expected to have all needed parameters - * set. + * Runs a plugin model. * @param plugin the plugin model * @param console the console to use + * @param parameters the parameters to pass to the plugin * @return the thread executing the script */ @Nullable - public BshThread<G, A, R> doRunPlugin(@NotNull final Plugin<G, A, R> plugin, @NotNull final ConsoleInterface console) { + public BshThread<G, A, R> doRunPlugin(@NotNull final Plugin<G, A, R> plugin, @NotNull final ConsoleInterface console, @NotNull final Map<String, Object> parameters) { final Interpreter runner = new Interpreter(); runner.setConsole(console); try { pluginParameters.setInterpreterValues(runner, PluginRunMode.BATCH); - for (final PluginParameter<G, A, R, ?> parameter : plugin) { - runner.set(parameter.getName(), parameter.getValueOrNull()); + for (final Map.Entry<String, Object> parameter : parameters.entrySet()) { + runner.set(parameter.getKey(), parameter.getValue()); } } catch (final TargetError ex) { final CharArrayWriter charArrayWriter = new CharArrayWriter(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-23 12:56:20
|
Revision: 9644 http://sourceforge.net/p/gridarta/code/9644 Author: akirschbaum Date: 2014-02-23 12:56:15 +0000 (Sun, 23 Feb 2014) Log Message: ----------- Fix run plugin dialog for plugins which use MapPathParameter values. Modified Paths: -------------- trunk/src/atrinik/ChangeLog trunk/src/crossfire/ChangeLog trunk/src/daimonin/ChangeLog trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/model/src/main/java/net/sf/gridarta/model/io/PathManager.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/MapPathParameter.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java Modified: trunk/src/atrinik/ChangeLog =================================================================== --- trunk/src/atrinik/ChangeLog 2014-02-23 12:35:22 UTC (rev 9643) +++ trunk/src/atrinik/ChangeLog 2014-02-23 12:56:15 UTC (rev 9644) @@ -1,5 +1,8 @@ 2014-02-23 Andreas Kirschbaum + * Fix run plugin dialog for plugins which use MapPathParameter + values. + * Do not run plugin scripts if not all parameter values are specified. Modified: trunk/src/crossfire/ChangeLog =================================================================== --- trunk/src/crossfire/ChangeLog 2014-02-23 12:35:22 UTC (rev 9643) +++ trunk/src/crossfire/ChangeLog 2014-02-23 12:56:15 UTC (rev 9644) @@ -1,5 +1,8 @@ 2014-02-23 Andreas Kirschbaum + * Fix run plugin dialog for plugins which use MapPathParameter + values. + * Do not run plugin scripts if not all parameter values are specified. Modified: trunk/src/daimonin/ChangeLog =================================================================== --- trunk/src/daimonin/ChangeLog 2014-02-23 12:35:22 UTC (rev 9643) +++ trunk/src/daimonin/ChangeLog 2014-02-23 12:56:15 UTC (rev 9644) @@ -1,5 +1,8 @@ 2014-02-23 Andreas Kirschbaum + * Fix run plugin dialog for plugins which use MapPathParameter + values. + * Do not run plugin scripts if not all parameter values are specified. Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java 2014-02-23 12:35:22 UTC (rev 9643) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java 2014-02-23 12:56:15 UTC (rev 9644) @@ -20,16 +20,20 @@ package net.sf.gridarta.gui.dialog.plugin.parameter; import java.awt.Component; -import java.io.File; import javax.swing.JComponent; import javax.swing.JFileChooser; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import net.sf.gridarta.gui.utils.JFileField; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.io.PathManager; import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.model.mapmodel.MapFile; +import net.sf.gridarta.model.mapmodel.MapPathUtils; +import net.sf.gridarta.plugin.parameter.InvalidValueException; import net.sf.gridarta.plugin.parameter.MapPathParameter; import org.jetbrains.annotations.NotNull; @@ -57,28 +61,41 @@ * Creates a new instance. * @param parent the parent component for the file chooser * @param parameter the parameter to affect + * @param pathManager the path manager instance * @noinspection TypeMayBeWeakened */ - public MapPathParameterView(@NotNull final Component parent, @NotNull final MapPathParameter<G, A, R> parameter) { - final File value = parameter.getValueOrNull(); - this.value = new JFileField(parent, null, parameter.getBaseDir(), value == null ? new File("") : value, JFileChooser.FILES_AND_DIRECTORIES); + public MapPathParameterView(@NotNull final Component parent, @NotNull final MapPathParameter<G, A, R> parameter, @NotNull final PathManager pathManager) { + final String value = parameter.getValueOrNull(); + final MapFile mapFile = pathManager.getMapFile(MapPathUtils.newAbsoluteMapPath("/" + value)); + this.value = new JFileField(parent, null, mapFile.getMapsDir(), mapFile.getFile(), JFileChooser.FILES_AND_DIRECTORIES); this.value.addDocumentListener(new DocumentListener() { @Override public void insertUpdate(final DocumentEvent e) { - parameter.setFile(MapPathParameterView.this.value.getFile()); + setFile(); } @Override public void removeUpdate(final DocumentEvent e) { - parameter.setFile(MapPathParameterView.this.value.getFile()); + setFile(); } @Override public void changedUpdate(final DocumentEvent e) { - parameter.setFile(MapPathParameterView.this.value.getFile()); + setFile(); } + /** + * Updates the {@code parameter} from the input field. + */ + private void setFile() { + try { + parameter.setFile(MapPathParameterView.this.value.getFile()); + } catch (final InvalidValueException ex) { + JOptionPane.showMessageDialog(parent, "Invalid file: " + ex.getMessage()); + } + } + }); } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java 2014-02-23 12:35:22 UTC (rev 9643) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java 2014-02-23 12:56:15 UTC (rev 9644) @@ -28,6 +28,7 @@ import net.sf.gridarta.model.archetypeset.ArchetypeSet; import net.sf.gridarta.model.face.FaceObjectProviders; import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.io.PathManager; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapmanager.MapManager; import net.sf.gridarta.plugin.parameter.ArchetypeParameter; @@ -66,16 +67,24 @@ private final FaceObjectProviders faceObjectProviders; /** + * The {@link PathManager} instance for converting map files. + */ + @NotNull + private final PathManager pathManager; + + /** * Creates a new instance. * @param faceObjectProviders the face object providers for looking up * faces + * @param pathManager the path manager instance for converting map files */ - public PluginParameterViewFactory(@NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapManager<G, A, R> mapManager, @NotNull final FaceObjectProviders faceObjectProviders) { + public PluginParameterViewFactory(@NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapManager<G, A, R> mapManager, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final PathManager pathManager) { this.archetypeSet = archetypeSet; this.gameObjectAttributesModel = gameObjectAttributesModel; this.objectChooser = objectChooser; this.mapManager = mapManager; this.faceObjectProviders = faceObjectProviders; + this.pathManager = pathManager; } /** @@ -118,7 +127,7 @@ @NotNull @Override public PluginParameterView visit(@NotNull final MapPathParameter<G, A, R> parameter) { - return new MapPathParameterView<G, A, R>(parent, parameter); + return new MapPathParameterView<G, A, R>(parent, parameter, pathManager); } @NotNull Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java 2014-02-23 12:35:22 UTC (rev 9643) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java 2014-02-23 12:56:15 UTC (rev 9644) @@ -398,7 +398,7 @@ final GameObjectAttributesControl<G, A, R> gameObjectAttributesControl = new GameObjectAttributesControl<G, A, R>(gameObjectAttributesModel, gameObjectAttributesDialogFactory, objectChooser, projectModel.getMapManager(), selectedSquareModel, projectModel.getGameObjectFactory(), mapViewSettings); final GameObjectTab<G, A, R> gameObjectTab = new GameObjectTab<G, A, R>("gameObject", gameObjectAttributesControl, Location.BOTTOM, false, 0, true); final ReplaceDialogManager<G, A, R> replaceDialogManager = new ReplaceDialogManager<G, A, R>(parent, copyBuffer, objectChooser, mapViewManager, projectModel.getFaceObjectProviders(), insertionModeSet); - final PluginParameterViewFactory<G, A, R> pluginParameterViewFactory = new PluginParameterViewFactory<G, A, R>(projectModel.getArchetypeSet(), gameObjectAttributesModel, objectChooser, projectModel.getMapManager(), projectModel.getFaceObjectProviders()); + final PluginParameterViewFactory<G, A, R> pluginParameterViewFactory = new PluginParameterViewFactory<G, A, R>(projectModel.getArchetypeSet(), gameObjectAttributesModel, objectChooser, projectModel.getMapManager(), projectModel.getFaceObjectProviders(), projectModel.getPathManager()); final PluginParameters pluginParameters = projectModel.newPluginParameters(); pluginParameters.addPluginParameter("rendererFactory", rendererFactory); final PluginController<G, A, R> pluginControl = new PluginController<G, A, R>(filterControl, projectModel.getPluginModel(), pluginParameters, parent, pluginParameterViewFactory, scriptsFile, resourceIcons); Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/io/PathManager.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/io/PathManager.java 2014-02-23 12:35:22 UTC (rev 9643) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/io/PathManager.java 2014-02-23 12:56:15 UTC (rev 9644) @@ -21,6 +21,7 @@ import java.io.File; import java.io.IOException; +import net.sf.gridarta.model.mapmodel.AbsoluteMapPath; import net.sf.gridarta.model.mapmodel.MapFile; import net.sf.gridarta.model.mapmodel.MapPathUtils; import net.sf.gridarta.model.settings.ProjectSettings; @@ -62,6 +63,16 @@ } /** + * Returns a {@link MapFile} instance from an {@link AbsoluteMapPath}. + * @param mapPath the map path + * @return the map file instance + */ + @NotNull + public MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath) { + return new MapFile(new MapFile(projectSettings.getMapsDirectory()), mapPath); + } + + /** * Returns a {@link MapFile} instance for a {@link File}. If the file points * into the maps directory, a properly based map file is returned. Otherwise * a map file based on the root directory is returned. Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/MapPathParameter.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/MapPathParameter.java 2014-02-23 12:35:22 UTC (rev 9643) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/MapPathParameter.java 2014-02-23 12:56:15 UTC (rev 9644) @@ -22,14 +22,17 @@ import java.io.File; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.io.PathManager; import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.model.mapmodel.MapFile; +import net.sf.gridarta.model.settings.ProjectSettings; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** - * A {@link PluginParameter} that represents a map. - * @author Andreas Kirschbaum + * A {@link PluginParameter} that holds a path with in the maps directory. */ -public class MapPathParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPathParameter<G, A, R> { +public class MapPathParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractStringPluginParameter<G, A, R, String> { /** * The string representation of this parameter type. @@ -38,11 +41,28 @@ public static final String PARAMETER_TYPE = "MapPathParameter"; /** + * The {@link PathManager} instance for converting {@link File Files} into + * path names. + */ + @NotNull + private final PathManager pathManager; + + /** + * The {@link ProjectSettings} instance. + */ + @NotNull + private final ProjectSettings projectSettings; + + /** * Creates a new instance. - * @param baseDir the base directory + * @param pathManager the path manager instance for converting files into + * path names + * @param projectSettings the project settings instance */ - public MapPathParameter(@NotNull final File baseDir) { - super(baseDir); + public MapPathParameter(@NotNull final PathManager pathManager, @NotNull final ProjectSettings projectSettings) { + super(""); + this.pathManager = pathManager; + this.projectSettings = projectSettings; } /** @@ -50,6 +70,15 @@ */ @NotNull @Override + public String getParameterType() { + return PARAMETER_TYPE; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { return visitor.visit(this); } @@ -59,8 +88,34 @@ */ @NotNull @Override - public String getParameterType() { - return PARAMETER_TYPE; + public String getValue() throws InvalidValueException { + return getStringValue(); } + /** + * {@inheritDoc} + */ + @Nullable + @Override + public String getValueOrNull() { + try { + return getValue(); + } catch (final InvalidValueException ignored) { + return null; + } + } + + /** + * Sets the value from a {@link File} instance. + * @param file the file instance + * @throws InvalidValueException if the file instance is invalid + */ + public void setFile(@NotNull final File file) throws InvalidValueException { + final MapFile mapFile = pathManager.getMapFile(file); + if (!mapFile.getMapsDir().equals(projectSettings.getMapsDirectory())) { + throw new InvalidValueException("the selected file " + mapFile + " must be within the maps directory " + projectSettings.getMapsDirectory()); + } + setStringValue("/" + mapFile.getMapPath().getPath()); + } + } Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2014-02-23 12:35:22 UTC (rev 9643) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2014-02-23 12:56:15 UTC (rev 9644) @@ -106,7 +106,7 @@ return new MapParameter<G, A, R>(mapManager, pathManager); } if (type.equals(MapPathParameter.PARAMETER_TYPE)) { - return new MapPathParameter<G, A, R>(projectSettings.getMapsDirectory()); + return new MapPathParameter<G, A, R>(pathManager, projectSettings); } throw new NoSuchParameterException(type); } Modified: trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java =================================================================== --- trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java 2014-02-23 12:35:22 UTC (rev 9643) +++ trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java 2014-02-23 12:56:15 UTC (rev 9644) @@ -26,11 +26,14 @@ import java.io.Writer; import net.sf.gridarta.model.archetype.TestArchetype; import net.sf.gridarta.model.gameobject.TestGameObject; +import net.sf.gridarta.model.io.PathManager; import net.sf.gridarta.model.maparchobject.TestMapArchObject; import net.sf.gridarta.model.mapcontrol.MapControl; import net.sf.gridarta.model.mapcontrol.TestMapControlCreator; import net.sf.gridarta.model.mapmodel.MapFile; import net.sf.gridarta.model.mapmodel.TestMapModelCreator; +import net.sf.gridarta.model.settings.ProjectSettings; +import net.sf.gridarta.model.settings.TestProjectSettings; import net.sf.gridarta.utils.Size2D; import org.jdom.Document; import org.jdom.Element; @@ -326,8 +329,9 @@ */ @Test public void testMapPathToXml1() throws IOException { - final File mapDir = new File("/tmp"); - final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = new MapPathParameter<TestGameObject, TestMapArchObject, TestArchetype>(mapDir); + final ProjectSettings projectSettings = new TestProjectSettings(); + final PathManager pathManager = new PathManager(projectSettings); + final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = new MapPathParameter<TestGameObject, TestMapArchObject, TestArchetype>(pathManager, projectSettings); parameter.setName("Name"); parameter.setDescription("Description"); final StringBuilder sb = new StringBuilder(); @@ -348,8 +352,9 @@ */ @Test public void testMapPathToXml2() throws IOException { - final File mapDir = new File("/tmp"); - final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = new MapPathParameter<TestGameObject, TestMapArchObject, TestArchetype>(mapDir); + final ProjectSettings projectSettings = new TestProjectSettings(); + final PathManager pathManager = new PathManager(projectSettings); + final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = new MapPathParameter<TestGameObject, TestMapArchObject, TestArchetype>(pathManager, projectSettings); parameter.setStringValue("/path"); final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-23 20:14:31
|
Revision: 9648 http://sourceforge.net/p/gridarta/code/9648 Author: akirschbaum Date: 2014-02-23 20:14:24 +0000 (Sun, 23 Feb 2014) Log Message: ----------- Add missing library which broke the settings dialog. Modified Paths: -------------- trunk/src/atrinik/ChangeLog trunk/src/atrinik/build.gradle trunk/src/crossfire/ChangeLog trunk/src/crossfire/build.gradle trunk/src/daimonin/ChangeLog trunk/src/daimonin/build.gradle Modified: trunk/src/atrinik/ChangeLog =================================================================== --- trunk/src/atrinik/ChangeLog 2014-02-23 13:12:15 UTC (rev 9647) +++ trunk/src/atrinik/ChangeLog 2014-02-23 20:14:24 UTC (rev 9648) @@ -1,5 +1,7 @@ 2014-02-23 Andreas Kirschbaum + * Add missing library which broke the settings dialog. + * Fix run plugin dialog for plugins which use MapPathParameter values. Modified: trunk/src/atrinik/build.gradle =================================================================== --- trunk/src/atrinik/build.gradle 2014-02-23 13:12:15 UTC (rev 9647) +++ trunk/src/atrinik/build.gradle 2014-02-23 20:14:24 UTC (rev 9648) @@ -14,6 +14,7 @@ compile project(':src:resources') runtime name: 'bsh-classgen', version: '2.0b4', group: 'bsh' runtime name: 'bsh-commands', version: '2.0b4', group: 'bsh' + runtime name: 'japi-lib-swing-extlib', version: '0.1.0', group: 'japi-lib' testCompile name: 'junit', version: '4.2' testCompile project(':src:model').sourceSets.test.output } Modified: trunk/src/crossfire/ChangeLog =================================================================== --- trunk/src/crossfire/ChangeLog 2014-02-23 13:12:15 UTC (rev 9647) +++ trunk/src/crossfire/ChangeLog 2014-02-23 20:14:24 UTC (rev 9648) @@ -1,5 +1,7 @@ 2014-02-23 Andreas Kirschbaum + * Add missing library which broke the settings dialog. + * Fix run plugin dialog for plugins which use MapPathParameter values. Modified: trunk/src/crossfire/build.gradle =================================================================== --- trunk/src/crossfire/build.gradle 2014-02-23 13:12:15 UTC (rev 9647) +++ trunk/src/crossfire/build.gradle 2014-02-23 20:14:24 UTC (rev 9648) @@ -14,6 +14,7 @@ compile project(':src:resources') runtime name: 'bsh-classgen', version: '2.0b4', group: 'bsh' runtime name: 'bsh-commands', version: '2.0b4', group: 'bsh' + runtime name: 'japi-lib-swing-extlib', version: '0.1.0', group: 'japi-lib' testCompile name: 'junit', version: '4.2' testCompile project(':src:model').sourceSets.test.output } Modified: trunk/src/daimonin/ChangeLog =================================================================== --- trunk/src/daimonin/ChangeLog 2014-02-23 13:12:15 UTC (rev 9647) +++ trunk/src/daimonin/ChangeLog 2014-02-23 20:14:24 UTC (rev 9648) @@ -1,5 +1,7 @@ 2014-02-23 Andreas Kirschbaum + * Add missing library which broke the settings dialog. + * Fix run plugin dialog for plugins which use MapPathParameter values. Modified: trunk/src/daimonin/build.gradle =================================================================== --- trunk/src/daimonin/build.gradle 2014-02-23 13:12:15 UTC (rev 9647) +++ trunk/src/daimonin/build.gradle 2014-02-23 20:14:24 UTC (rev 9648) @@ -14,6 +14,7 @@ compile project(':src:resources') runtime name: 'bsh-classgen', version: '2.0b4', group: 'bsh' runtime name: 'bsh-commands', version: '2.0b4', group: 'bsh' + runtime name: 'japi-lib-swing-extlib', version: '0.1.0', group: 'japi-lib' testCompile name: 'junit', version: '4.2' testCompile project(':src:model').sourceSets.test.output } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-28 07:50:35
|
Revision: 9651 http://sourceforge.net/p/gridarta/code/9651 Author: akirschbaum Date: 2014-02-28 07:50:30 +0000 (Fri, 28 Feb 2014) Log Message: ----------- Remove JEditTextArea.setDocument(). Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.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 2014-02-28 07:01:20 UTC (rev 9650) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2014-02-28 07:50:30 UTC (rev 9651) @@ -483,8 +483,7 @@ } else { text = ""; } - final JEditTextArea input = new JEditTextArea(textAreaDefaults); - input.setDocument(new SyntaxDocument()); + final JEditTextArea input = new JEditTextArea(textAreaDefaults, new SyntaxDocument()); input.getDocument().setTokenMarker(TokenMarkerFactory.createTokenMarker(archetypeAttribute.getFileExtension())); input.setText(text == null ? "" : text); input.setCaretPosition(0); Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java =================================================================== --- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 07:01:20 UTC (rev 9650) +++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 07:50:30 UTC (rev 9651) @@ -191,10 +191,9 @@ * @param file file where this script is stored, null if new script opened */ public void addTab(@NotNull final String title, @Nullable final File file) { - final JEditTextArea ta = new JEditTextArea(textAreaDefaults); // open new TextArea + final SyntaxDocument syntaxDocument = new SyntaxDocument(); + final JEditTextArea ta = new JEditTextArea(textAreaDefaults, syntaxDocument); // open new TextArea //ta.setFont(new Font("Courier New", Font.PLAIN, 12)); - final SyntaxDocument syntaxDocument = new SyntaxDocument(); - ta.setDocument(syntaxDocument); textAreas.add(ta); ta.getDocument().setTokenMarker(TokenMarkerFactory.createTokenMarker(file)); scriptEditUndoActions.addDocument(syntaxDocument); Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java =================================================================== --- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 07:01:20 UTC (rev 9650) +++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 07:50:30 UTC (rev 9651) @@ -142,8 +142,8 @@ @NotNull private final InputHandler inputHandler; - @Nullable - private SyntaxDocument document; + @NotNull + private final SyntaxDocument document; @NotNull private final DocumentListener documentHandler; @@ -175,7 +175,7 @@ * Creates a new JEditTextArea with the specified settings. * @param defaults the default settings */ - public JEditTextArea(@NotNull final TextAreaDefaults defaults) { + public JEditTextArea(@NotNull final TextAreaDefaults defaults, @NotNull final SyntaxDocument document) { // Enable the necessary events enableEvents(AWTEvent.KEY_EVENT_MASK); @@ -205,7 +205,10 @@ // Load the defaults inputHandler = defaults.getInputHandler(); - setDocument(defaults.getDocument()); + this.document = document; + document.addDocumentListener(documentHandler); + select(0, 0); + updateScrollBars(); editable = defaults.getEditable(); electricScroll = defaults.getElectricScroll(); @@ -708,37 +711,11 @@ * Returns the document this text area is editing. */ @NotNull - @SuppressWarnings("NullableProblems") public SyntaxDocument getDocument() { - if (document == null) { - throw new IllegalStateException(); - } return document; } /** - * Sets the document this text area is editing. - * @param document the document - */ - public final void setDocument(@Nullable final SyntaxDocument document) { - if (this.document == document) { - return; - } - - if (this.document != null) { - this.document.removeDocumentListener(documentHandler); - } - - this.document = document; - - document.addDocumentListener(documentHandler); - - select(0, 0); - updateScrollBars(); - painter.repaint(); - } - - /** * Returns the document's token marker. Equivalent to calling {@code * getDocument().getTokenMarker()}. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-28 20:25:30
|
Revision: 9665 http://sourceforge.net/p/gridarta/code/9665 Author: akirschbaum Date: 2014-02-28 20:25:24 +0000 (Fri, 28 Feb 2014) Log Message: ----------- Remove JEditTextArea.getPainter(). Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.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 2014-02-28 20:19:40 UTC (rev 9664) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2014-02-28 20:25:24 UTC (rev 9665) @@ -483,12 +483,11 @@ } else { text = ""; } - final JEditTextArea input = new JEditTextArea(textAreaDefaults, new SyntaxDocument()); + final JEditTextArea input = new JEditTextArea(textAreaDefaults, new SyntaxDocument(), false); 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 GuiInfoGlue<G, A, R, ArchetypeAttributeText>(new DialogAttributeText<G, A, R>(archetypeAttribute, input), input); } Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java =================================================================== --- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 20:19:40 UTC (rev 9664) +++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 20:25:24 UTC (rev 9665) @@ -192,7 +192,7 @@ */ public void addTab(@NotNull final String title, @Nullable final File file) { final SyntaxDocument syntaxDocument = new SyntaxDocument(); - final JEditTextArea ta = new JEditTextArea(textAreaDefaults, syntaxDocument); // open new TextArea + final JEditTextArea ta = new JEditTextArea(textAreaDefaults, syntaxDocument, textAreaDefaults.getPaintInvalid()); // open new TextArea //ta.setFont(new Font("Courier New", Font.PLAIN, 12)); textAreas.add(ta); ta.getDocument().setTokenMarker(TokenMarkerFactory.createTokenMarker(file)); Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java =================================================================== --- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:19:40 UTC (rev 9664) +++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:25:24 UTC (rev 9665) @@ -155,8 +155,10 @@ /** * Creates a new JEditTextArea with the specified settings. * @param defaults the default settings + * @param paintInvalid whether invalid lines should be painted as red + * tildes */ - public JEditTextArea(@NotNull final TextAreaDefaults defaults, @NotNull final SyntaxDocument document) { + public JEditTextArea(@NotNull final TextAreaDefaults defaults, @NotNull final SyntaxDocument document, final boolean paintInvalid) { // Enable the necessary events enableEvents(AWTEvent.KEY_EVENT_MASK); @@ -164,7 +166,7 @@ caret = new TextAreaCaret(defaults.getCaretVisible(), defaults.getCaretBlinks()); selection = new TextAreaSelection(document); config = new TextAreaConfig(defaults.getEditable(), defaults.getElectricScroll()); - painter = new TextAreaPainter(this, selection, caret, defaults, brackets, config); + painter = new TextAreaPainter(this, selection, caret, defaults, brackets, config, paintInvalid); documentHandler = new DocumentHandler(); lineSegment = new Segment(); @@ -259,14 +261,6 @@ } /** - * Returns the object responsible for painting this text area. - */ - @NotNull - public TextAreaPainter getPainter() { - return painter; - } - - /** * Returns the input handler. */ @NotNull Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java =================================================================== --- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:19:40 UTC (rev 9664) +++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:25:24 UTC (rev 9665) @@ -143,7 +143,7 @@ * Whether invalid lines should be painted as red tildes. * @serial */ - private boolean paintInvalid; + private final boolean paintInvalid; /** * The color for painting eol markers. @@ -224,8 +224,10 @@ * @param defaults the text attributes to use * @param brackets the brackets to paint * @param config the text area configuration options to use + * @param paintInvalid whether invalid lines should be painted as red + * tildes */ - public TextAreaPainter(@NotNull final JEditTextArea textArea, @NotNull final TextAreaSelection selection, @NotNull final TextAreaCaret caret, @NotNull final TextAreaDefaults defaults, @NotNull final TextAreaBrackets brackets, @NotNull final TextAreaConfig config) { + public TextAreaPainter(@NotNull final JEditTextArea textArea, @NotNull final TextAreaSelection selection, @NotNull final TextAreaCaret caret, @NotNull final TextAreaDefaults defaults, @NotNull final TextAreaBrackets brackets, @NotNull final TextAreaConfig config, final boolean paintInvalid) { this.textArea = textArea; this.selection = selection; this.caret = caret; @@ -254,7 +256,7 @@ lineHighlight = defaults.getLineHighlight(); bracketHighlightColor = defaults.getBracketHighlightColor(); bracketHighlight = defaults.getBracketHighlight(); - paintInvalid = defaults.getPaintInvalid(); + this.paintInvalid = paintInvalid; eolMarkerColor = defaults.getEolMarkerColor(); eolMarkers = defaults.getEolMarkers(); } @@ -333,15 +335,6 @@ } /** - * Sets whether invalid lines are to be painted as red tildes. - * @param paintInvalid whether invalid lines should be drawn - */ - public void setInvalidLinesPainted(final boolean paintInvalid) { - this.paintInvalid = paintInvalid; - repaint(); - } - - /** * Returns the font metrics used by this component. * @return the font metrics */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-02-28 20:29:31
|
Revision: 9666 http://sourceforge.net/p/gridarta/code/9666 Author: akirschbaum Date: 2014-02-28 20:29:25 +0000 (Fri, 28 Feb 2014) Log Message: ----------- Remove some calls to JEditTextArea.getDocument(). Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.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 2014-02-28 20:25:24 UTC (rev 9665) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2014-02-28 20:29:25 UTC (rev 9666) @@ -483,8 +483,9 @@ } else { text = ""; } - final JEditTextArea input = new JEditTextArea(textAreaDefaults, new SyntaxDocument(), false); - input.getDocument().setTokenMarker(TokenMarkerFactory.createTokenMarker(archetypeAttribute.getFileExtension())); + final SyntaxDocument document = new SyntaxDocument(); + document.setTokenMarker(TokenMarkerFactory.createTokenMarker(archetypeAttribute.getFileExtension())); + final JEditTextArea input = new JEditTextArea(textAreaDefaults, document, false); input.setText(text == null ? "" : text); input.setCaretPosition(0); input.setBorder(BorderFactory.createEmptyBorder(3, 7, 0, 0)); Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java =================================================================== --- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 20:25:24 UTC (rev 9665) +++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 20:29:25 UTC (rev 9666) @@ -192,10 +192,10 @@ */ public void addTab(@NotNull final String title, @Nullable final File file) { final SyntaxDocument syntaxDocument = new SyntaxDocument(); + syntaxDocument.setTokenMarker(TokenMarkerFactory.createTokenMarker(file)); final JEditTextArea ta = new JEditTextArea(textAreaDefaults, syntaxDocument, textAreaDefaults.getPaintInvalid()); // open new TextArea //ta.setFont(new Font("Courier New", Font.PLAIN, 12)); textAreas.add(ta); - ta.getDocument().setTokenMarker(TokenMarkerFactory.createTokenMarker(file)); scriptEditUndoActions.addDocument(syntaxDocument); tabPane.addTab(title, ta); if (getTabCount() <= 1 || !isShowing()) { @@ -235,7 +235,7 @@ } buff.append(line); } - ta.getDocument().insertString(0, buff.toString(), null); + syntaxDocument.insertString(0, buff.toString(), null); } finally { in.close(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-01 07:10:14
|
Revision: 9671 http://sourceforge.net/p/gridarta/code/9671 Author: akirschbaum Date: 2014-03-01 07:10:09 +0000 (Sat, 01 Mar 2014) Log Message: ----------- Properly update pickmap view after map modifications. Reload pickmaps from disk when the pickmap folder is changed. Modified Paths: -------------- trunk/src/atrinik/ChangeLog trunk/src/crossfire/ChangeLog trunk/src/daimonin/ChangeLog trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java Modified: trunk/src/atrinik/ChangeLog =================================================================== --- trunk/src/atrinik/ChangeLog 2014-02-28 20:55:32 UTC (rev 9670) +++ trunk/src/atrinik/ChangeLog 2014-03-01 07:10:09 UTC (rev 9671) @@ -1,3 +1,8 @@ +2014-03-01 Andreas Kirschbaum + + * Properly update pickmap view after map modifications. Reload + pickmaps from disk when the pickmap folder is changed. + 2014-02-23 Andreas Kirschbaum * Add missing library which broke the settings dialog. Modified: trunk/src/crossfire/ChangeLog =================================================================== --- trunk/src/crossfire/ChangeLog 2014-02-28 20:55:32 UTC (rev 9670) +++ trunk/src/crossfire/ChangeLog 2014-03-01 07:10:09 UTC (rev 9671) @@ -1,3 +1,8 @@ +2014-03-01 Andreas Kirschbaum + + * Properly update pickmap view after map modifications. Reload + pickmaps from disk when the pickmap folder is changed. + 2014-02-23 Andreas Kirschbaum * Add missing library which broke the settings dialog. Modified: trunk/src/daimonin/ChangeLog =================================================================== --- trunk/src/daimonin/ChangeLog 2014-02-28 20:55:32 UTC (rev 9670) +++ trunk/src/daimonin/ChangeLog 2014-03-01 07:10:09 UTC (rev 9671) @@ -1,3 +1,8 @@ +2014-03-01 Andreas Kirschbaum + + * Properly update pickmap view after map modifications. Reload + pickmaps from disk when the pickmap folder is changed. + 2014-02-23 Andreas Kirschbaum * Add missing library which broke the settings dialog. Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java 2014-02-28 20:55:32 UTC (rev 9670) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java 2014-03-01 07:10:09 UTC (rev 9671) @@ -169,6 +169,7 @@ public void clear() { for (final PickmapState<G, A, R> pickmapState : pickmapStates) { removeMapModelListener(pickmapState.getPickmap()); + pickmapState.freePickmap(); } pickmapStates.clear(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-01 08:50:35
|
Revision: 9673 http://sourceforge.net/p/gridarta/code/9673 Author: akirschbaum Date: 2014-03-01 08:50:27 +0000 (Sat, 01 Mar 2014) Log Message: ----------- Extract common code from EditorAction implementations into EditorActionManager. Modified Paths: -------------- trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/actions/AtrinikServerActions.java trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/maincontrol/DefaultEditorFactory.java trunk/src/crossfire/src/main/java/net/sf/gridarta/var/crossfire/maincontrol/DefaultEditorFactory.java trunk/src/daimonin/src/main/java/net/sf/gridarta/var/daimonin/maincontrol/DefaultEditorFactory.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractMapCursorAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractSelectionAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddBookmarkAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ArchAttributesAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/DeleteArchAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GoLocationAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GrowSelectionAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ReleaseDragAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchAboveAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchBelowAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectSquareAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ShrinkSelectionAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/StartStopDragAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SubFromSelectionAction.java trunk/src/gridarta/src/main/java/net/sf/gridarta/actions/AbstractServerActions.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/map/mapactions/MapActions.java trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java trunk/src/gridarta/src/main/java/net/sf/gridarta/mainactions/MainActions.java trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/EditorFactory.java trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java Added Paths: ----------- trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/EditorActionManager.java Modified: trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/actions/AtrinikServerActions.java =================================================================== --- trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/actions/AtrinikServerActions.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/actions/AtrinikServerActions.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -24,7 +24,6 @@ import java.io.OutputStream; import java.net.Socket; import net.sf.gridarta.actions.AbstractServerActions; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.mapmanager.FileControl; import net.sf.gridarta.var.atrinik.model.archetype.Archetype; import net.sf.gridarta.var.atrinik.model.gameobject.GameObject; @@ -62,12 +61,10 @@ /** * Creates a new instance. - * @param mapViewManager the map view manager for tracking the current map - * view * @param fileControl the file control for saving maps */ - public AtrinikServerActions(@NotNull final MapViewManager<GameObject, MapArchObject, Archetype> mapViewManager, @NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) { - super(mapViewManager, fileControl); + public AtrinikServerActions(@NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) { + super(fileControl); } /** Modified: trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/maincontrol/DefaultEditorFactory.java =================================================================== --- trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/maincontrol/DefaultEditorFactory.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/maincontrol/DefaultEditorFactory.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -37,7 +37,6 @@ import net.sf.gridarta.gui.filter.FilterControl; import net.sf.gridarta.gui.map.mapview.DefaultMapViewFactory; import net.sf.gridarta.gui.map.mapview.MapViewFactory; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewsManager; import net.sf.gridarta.gui.map.renderer.GridMapSquarePainter; import net.sf.gridarta.gui.map.renderer.RendererFactory; @@ -448,8 +447,8 @@ */ @NotNull @Override - public EditorAction newServerActions(@NotNull final MapViewManager<GameObject, MapArchObject, Archetype> mapViewManager, @NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) { - return new AtrinikServerActions(mapViewManager, fileControl); + public EditorAction newServerActions(@NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) { + return new AtrinikServerActions(fileControl); } /** Modified: trunk/src/crossfire/src/main/java/net/sf/gridarta/var/crossfire/maincontrol/DefaultEditorFactory.java =================================================================== --- trunk/src/crossfire/src/main/java/net/sf/gridarta/var/crossfire/maincontrol/DefaultEditorFactory.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/crossfire/src/main/java/net/sf/gridarta/var/crossfire/maincontrol/DefaultEditorFactory.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -35,7 +35,6 @@ import net.sf.gridarta.gui.filter.FilterControl; import net.sf.gridarta.gui.map.mapview.DefaultMapViewFactory; import net.sf.gridarta.gui.map.mapview.MapViewFactory; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewsManager; import net.sf.gridarta.gui.map.renderer.GridMapSquarePainter; import net.sf.gridarta.gui.map.renderer.RendererFactory; @@ -339,7 +338,7 @@ */ @Nullable @Override - public EditorAction newServerActions(@NotNull final MapViewManager<GameObject, MapArchObject, Archetype> mapViewManager, @NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) { + public EditorAction newServerActions(@NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) { return null; // action not supported } Modified: trunk/src/daimonin/src/main/java/net/sf/gridarta/var/daimonin/maincontrol/DefaultEditorFactory.java =================================================================== --- trunk/src/daimonin/src/main/java/net/sf/gridarta/var/daimonin/maincontrol/DefaultEditorFactory.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/daimonin/src/main/java/net/sf/gridarta/var/daimonin/maincontrol/DefaultEditorFactory.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -37,7 +37,6 @@ import net.sf.gridarta.gui.filter.FilterControl; import net.sf.gridarta.gui.map.mapview.DefaultMapViewFactory; import net.sf.gridarta.gui.map.mapview.MapViewFactory; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewsManager; import net.sf.gridarta.gui.map.renderer.GridMapSquarePainter; import net.sf.gridarta.gui.map.renderer.RendererFactory; @@ -447,7 +446,7 @@ */ @Nullable @Override - public EditorAction newServerActions(@NotNull final MapViewManager<GameObject, MapArchObject, Archetype> mapViewManager, @NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) { + public EditorAction newServerActions(@NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) { return null; // action not supported } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractMapCursorAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractMapCursorAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractMapCursorAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -21,7 +21,6 @@ import java.awt.Point; import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; @@ -36,7 +35,7 @@ * Abstract base class for actions that have to track the current map cursor. * @author Andreas Kirschbaum */ -public abstract class AbstractMapCursorAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { +public abstract class AbstractMapCursorAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements MapCursorListener<G, A, R>, MapViewManagerListener<G, A, R> { /** * The active map view, or {@code null} if no map view exists. @@ -45,68 +44,6 @@ private MapView<G, A, R> currentMapView; /** - * The map view manager listener used to detect changed current maps. - */ - @NotNull - private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { - - @Override - public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { - currentMapView = mapView; - updateAction(); - } - - @Override - public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - mapView.getMapCursor().addMapCursorListener(mapCursorListener); - } - - @Override - public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - mapView.getMapCursor().removeMapCursorListener(mapCursorListener); - } - - }; - - /** - * The map cursor listener used to detect cursor state changes in {@link - * #currentMapView}. - */ - @NotNull - private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() { - - @Override - public void mapCursorChangedPos(@NotNull final Point location) { - updateAction(); - } - - @Override - public void mapCursorChangedMode() { - updateAction(); - } - - @Override - public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { - // ignore - } - - @Override - public void mapCursorChangedSize() { - // ignore - } - - }; - - /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - protected AbstractMapCursorAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - mapViewManager.addMapViewManagerListener(mapViewManagerListener); - currentMapView = mapViewManager.getActiveMapView(); - } - - /** * Return the map cursor of the current map view if it is active. * @return the map cursor, or {@code null} if the cursor is not active, or * if no map view exists @@ -131,4 +68,65 @@ */ protected abstract void updateAction(); + /** + * {@inheritDoc} + */ + @Override + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + currentMapView = mapView; + updateAction(); + } + + /** + * {@inheritDoc} + * @noinspection NoopMethodInAbstractClass + */ + @Override + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + + /** + * {@inheritDoc} + * @noinspection NoopMethodInAbstractClass + */ + @Override + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedPos(@NotNull final Point location) { + updateAction(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedMode() { + updateAction(); + } + + /** + * {@inheritDoc} + * @noinspection NoopMethodInAbstractClass + */ + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { + // ignore + } + + /** + * {@inheritDoc} + * @noinspection NoopMethodInAbstractClass + */ + @Override + public void mapCursorChangedSize() { + // ignore + } + } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractSelectionAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractSelectionAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractSelectionAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -19,7 +19,6 @@ package net.sf.gridarta.action; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -34,14 +33,6 @@ public abstract class AbstractSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractMapCursorAction<G, A, R> { /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - protected AbstractSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - super(mapViewManager); - } - - /** * Executes an action for changing the selection. * @param performAction whether the action should be performed * @param mode the type of action to perform Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddBookmarkAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddBookmarkAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddBookmarkAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -22,7 +22,6 @@ import javax.swing.Action; import net.sf.gridarta.gui.dialog.bookmarks.EditBookmarkDialog; import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.gui.mapmenu.AbstractMapMenuPreferences; import net.sf.gridarta.gui.mapmenu.MapMenuEntryMap; @@ -41,7 +40,7 @@ * An {@link EditorAction} that creates a new bookmark for the current map. * @author Andreas Kirschbaum */ -public class AddBookmarkAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction { +public class AddBookmarkAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> { /** * The {@link AbstractMapMenuPreferences} for adding new bookmarks. @@ -50,10 +49,10 @@ private final AbstractMapMenuPreferences bookmarksMapMenuPreferences; /** - * The {@link MapViewManager} instance. + * The currently active {@link MapView} or {@code null} if none is active. */ - @NotNull - private final MapViewManager<G, A, R> mapViewManager; + @Nullable + private MapView<G, A, R> currentMapView; /** * The action associated with this editor action. Set to {@code null} if no @@ -66,28 +65,9 @@ * Creates a new instance. * @param bookmarksMapMenuPreferences the map menu preferences defining the * bookmarks menu entries - * @param mapViewManager the map view manager instance */ - public AddBookmarkAction(@NotNull final AbstractMapMenuPreferences bookmarksMapMenuPreferences, @NotNull final MapViewManager<G, A, R> mapViewManager) { + public AddBookmarkAction(@NotNull final AbstractMapMenuPreferences bookmarksMapMenuPreferences) { this.bookmarksMapMenuPreferences = bookmarksMapMenuPreferences; - this.mapViewManager = mapViewManager; - final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { - - @Override - public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { - updateAction(); - } - - @Override - public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - } - - @Override - public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - } - - }; - mapViewManager.addMapViewManagerListener(mapViewManagerListener); } /** @@ -124,7 +104,7 @@ * @return whether the action has or can be performed */ private boolean doAddBookmark(final boolean performAction) { - final MapView<G, A, R> mapView = mapViewManager.getActiveMapView(); + final MapView<G, A, R> mapView = currentMapView; if (mapView == null) { return false; } @@ -148,4 +128,27 @@ return true; } + /** + * {@inheritDoc} + */ + @Override + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + currentMapView = mapView; + updateAction(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { + } + } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -20,7 +20,6 @@ package net.sf.gridarta.action; import javax.swing.Action; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -45,14 +44,6 @@ private Action action; /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - public AddToSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - super(mapViewManager); - } - - /** * {@inheritDoc} */ @Override Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ArchAttributesAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ArchAttributesAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ArchAttributesAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -23,7 +23,6 @@ import javax.swing.Action; import net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory; import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; @@ -41,7 +40,7 @@ * currently selected game object. * @author Andreas Kirschbaum */ -public class ArchAttributesAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction { +public class ArchAttributesAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapCursorListener<G, A, R>, MapViewManagerListener<G, A, R> { /** * The factory for creating game object attributes dialog instances. @@ -63,68 +62,12 @@ private Action action; /** - * The map view manager listener used to detect changed current maps. - */ - @NotNull - private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { - - @Override - public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { - currentMapView = mapView; - updateActions(); - } - - @Override - public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - mapView.getMapCursor().addMapCursorListener(mapCursorListener); - } - - @Override - public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - mapView.getMapCursor().removeMapCursorListener(mapCursorListener); - } - - }; - - /** - * The map cursor listener used to detect cursor state changes in {@link - * #currentMapView}. - */ - @NotNull - private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() { - - @Override - public void mapCursorChangedPos(@NotNull final Point location) { - updateActions(); - } - - @Override - public void mapCursorChangedMode() { - // ignore - } - - @Override - public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { - // ignore - } - - @Override - public void mapCursorChangedSize() { - // ignore - } - - }; - - /** * Creates a new instance. - * @param mapViewManager the map view manager * @param gameObjectAttributesDialogFactory the factory for creating game * object attributes dialog instances */ - public ArchAttributesAction(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory) { + public ArchAttributesAction(@NotNull final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory) { this.gameObjectAttributesDialogFactory = gameObjectAttributesDialogFactory; - mapViewManager.addMapViewManagerListener(mapViewManagerListener); - currentMapView = mapViewManager.getActiveMapView(); updateActions(); } @@ -177,4 +120,61 @@ return true; } + /** + * {@inheritDoc} + */ + @Override + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + currentMapView = mapView; + updateActions(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedPos(@NotNull final Point location) { + updateActions(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedMode() { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedSize() { + // ignore + } + } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/DeleteArchAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/DeleteArchAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/DeleteArchAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -20,7 +20,6 @@ package net.sf.gridarta.action; import javax.swing.Action; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -52,11 +51,9 @@ /** * Creates a new instance. - * @param mapViewManager the map view manager * @param mapViewSettings the map view settings for querying options */ - public DeleteArchAction(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final MapViewSettings mapViewSettings) { - super(mapViewManager); + public DeleteArchAction(@NotNull final MapViewSettings mapViewSettings) { this.mapViewSettings = mapViewSettings; } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GoLocationAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GoLocationAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GoLocationAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -58,7 +58,6 @@ * @param mapViewManager the map view manager */ public GoLocationAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - super(mapViewManager); goLocationDialogManager = new GoLocationDialogManager<G, A, R>(mapViewManager); } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GrowSelectionAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GrowSelectionAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GrowSelectionAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -23,7 +23,6 @@ import java.util.List; import javax.swing.Action; import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; @@ -43,7 +42,7 @@ * An {@link EditorAction} that grows the current selection by one map square. * @author Andreas Kirschbaum */ -public class GrowSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction { +public class GrowSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> { /** * The active map view, or {@code null} if no map view exists. @@ -59,34 +58,6 @@ private Action action; /** - * The map view manager listener used to detect changed current maps. - */ - @NotNull - private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { - - @Override - public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { - if (currentMapView != null) { - currentMapView.getMapGrid().removeMapGridListener(mapGridListener); - } - currentMapView = mapView; - if (currentMapView != null) { - currentMapView.getMapGrid().addMapGridListener(mapGridListener); - } - updateAction(); - } - - @Override - public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - } - - @Override - public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - } - - }; - - /** * The {@link MapGridListener} attached to {@link #currentMapView}. */ @NotNull @@ -105,18 +76,6 @@ }; /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - public GrowSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - mapViewManager.addMapViewManagerListener(mapViewManagerListener); - currentMapView = mapViewManager.getActiveMapView(); - if (currentMapView != null) { - currentMapView.getMapGrid().addMapGridListener(mapGridListener); - } - } - - /** * Grows the current map selection by one map square. */ @ActionMethod @@ -188,4 +147,33 @@ return true; } + /** + * {@inheritDoc} + */ + @Override + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + if (currentMapView != null) { + currentMapView.getMapGrid().removeMapGridListener(mapGridListener); + } + currentMapView = mapView; + if (currentMapView != null) { + currentMapView.getMapGrid().addMapGridListener(mapGridListener); + } + updateAction(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { + } + } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -20,7 +20,6 @@ package net.sf.gridarta.action; import javax.swing.Action; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.panel.objectchooser.ObjectChooser; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.baseobject.BaseObject; @@ -60,12 +59,10 @@ /** * Creates a new instance. - * @param mapViewManager the map view manager * @param objectChooser the object chooser * @param mapViewSettings the map view settings instance for looking up options */ - public InsertArchAction(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapViewSettings mapViewSettings) { - super(mapViewManager); + public InsertArchAction(@NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapViewSettings mapViewSettings) { this.objectChooser = objectChooser; this.mapViewSettings = mapViewSettings; } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ReleaseDragAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ReleaseDragAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ReleaseDragAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -21,7 +21,6 @@ import java.awt.Point; import javax.swing.Action; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -46,14 +45,6 @@ private Action action; /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - public ReleaseDragAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - super(mapViewManager); - } - - /** * {@inheritDoc} */ @Override Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchAboveAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchAboveAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchAboveAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -20,7 +20,6 @@ package net.sf.gridarta.action; import javax.swing.Action; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -45,14 +44,6 @@ private Action action; /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - public SelectArchAboveAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - super(mapViewManager); - } - - /** * {@inheritDoc} */ @Override Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchBelowAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchBelowAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchBelowAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -20,7 +20,6 @@ package net.sf.gridarta.action; import javax.swing.Action; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -45,14 +44,6 @@ private Action action; /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - public SelectArchBelowAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - super(mapViewManager); - } - - /** * {@inheritDoc} */ @Override Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectSquareAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectSquareAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectSquareAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -20,7 +20,6 @@ package net.sf.gridarta.action; import javax.swing.Action; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -45,14 +44,6 @@ private Action action; /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - public SelectSquareAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - super(mapViewManager); - } - - /** * {@inheritDoc} */ @Override Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ShrinkSelectionAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ShrinkSelectionAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ShrinkSelectionAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -25,7 +25,6 @@ import java.util.Map; import javax.swing.Action; import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; @@ -46,7 +45,7 @@ * square. * @author Andreas Kirschbaum */ -public class ShrinkSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction { +public class ShrinkSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> { /** * The active map view, or {@code null} if no map view exists. @@ -62,34 +61,6 @@ private Action action; /** - * The map view manager listener used to detect changed current maps. - */ - @NotNull - private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { - - @Override - public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { - if (currentMapView != null) { - currentMapView.getMapGrid().removeMapGridListener(mapGridListener); - } - currentMapView = mapView; - if (currentMapView != null) { - currentMapView.getMapGrid().addMapGridListener(mapGridListener); - } - updateAction(); - } - - @Override - public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - } - - @Override - public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - } - - }; - - /** * The {@link MapGridListener} attached to {@link #currentMapView}. */ @NotNull @@ -108,18 +79,6 @@ }; /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - public ShrinkSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - mapViewManager.addMapViewManagerListener(mapViewManagerListener); - currentMapView = mapViewManager.getActiveMapView(); - if (currentMapView != null) { - currentMapView.getMapGrid().addMapGridListener(mapGridListener); - } - } - - /** * Grows the current map selection by one map square. */ @ActionMethod @@ -200,4 +159,35 @@ return true; } + /** + * {@inheritDoc} + */ + @Override + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + if (currentMapView != null) { + currentMapView.getMapGrid().removeMapGridListener(mapGridListener); + } + currentMapView = mapView; + if (currentMapView != null) { + currentMapView.getMapGrid().addMapGridListener(mapGridListener); + } + updateAction(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + + @Override + /** + * {@inheritDoc} + */ + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/StartStopDragAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/StartStopDragAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/StartStopDragAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -20,7 +20,6 @@ package net.sf.gridarta.action; import javax.swing.Action; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -45,14 +44,6 @@ private Action action; /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - public StartStopDragAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - super(mapViewManager); - } - - /** * {@inheritDoc} */ @Override Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SubFromSelectionAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SubFromSelectionAction.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SubFromSelectionAction.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -20,7 +20,6 @@ package net.sf.gridarta.action; import javax.swing.Action; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -45,14 +44,6 @@ private Action action; /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - public SubFromSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { - super(mapViewManager); - } - - /** * {@inheritDoc} */ @Override Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/actions/AbstractServerActions.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/actions/AbstractServerActions.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/actions/AbstractServerActions.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -23,7 +23,6 @@ import java.io.IOException; import javax.swing.Action; import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; @@ -42,7 +41,7 @@ * @author Andreas Kirschbaum * @noinspection AbstractClassWithOnlyOneDirectInheritor */ -public abstract class AbstractServerActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction { +public abstract class AbstractServerActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> { /** * The currently active map or {@code null} if no map is active. @@ -64,41 +63,11 @@ private Action aOpenInClient; /** - * The map manager listener which is attached to the current map if the - * current map is tracked. Otherwise it is unused. - * @noinspection FieldCanBeLocal - */ - @NotNull - private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { - - @Override - public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { - currentMapView = mapView; - updateActions(); - } - - @Override - public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - // ignore - } - - @Override - public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - // ignore - } - - }; - - /** * Creates a new instance. - * @param mapViewManager the map view manager for tracking the current map - * view * @param fileControl the file control for saving maps */ - protected AbstractServerActions(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final FileControl<G, A, R> fileControl) { + protected AbstractServerActions(@NotNull final FileControl<G, A, R> fileControl) { this.fileControl = fileControl; - mapViewManager.addMapViewManagerListener(mapViewManagerListener); - currentMapView = mapViewManager.getActiveMapView(); } /** @@ -174,4 +143,31 @@ updateActions(); } + /** + * {@inheritDoc} + */ + @Override + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + currentMapView = mapView; + updateActions(); + } + + /** + * {@inheritDoc} + * @noinspection NoopMethodInAbstractClass + */ + @Override + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + + /** + * {@inheritDoc} + * @noinspection NoopMethodInAbstractClass + */ + @Override + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -23,7 +23,6 @@ import javax.swing.Action; import net.sf.gridarta.actions.ExitConnectorActions; import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.exitconnector.ExitConnectorModel; @@ -40,7 +39,7 @@ * The controller of the exit connector. * @author Andreas Kirschbaum */ -public class ExitConnectorController<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction { +public class ExitConnectorController<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> { /** * The actions for this controller. @@ -101,39 +100,13 @@ }; /** - * The {@link MapViewManagerListener} used to track the current map. - */ - @NotNull - private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { - - @Override - public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { - setCurrentMapView(mapView); - } - - @Override - public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - // ignore - } - - @Override - public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - // ignore - } - - }; - - /** * Creates a new instance. * @param exitConnectorActions the exit connector actions to use * @param exitConnectorModel the model for this controller - * @param mapViewManager the map view manager to track */ - public ExitConnectorController(@NotNull final ExitConnectorActions<G, A, R> exitConnectorActions, @NotNull final ExitConnectorModel exitConnectorModel, @NotNull final MapViewManager<G, A, R> mapViewManager) { + public ExitConnectorController(@NotNull final ExitConnectorActions<G, A, R> exitConnectorActions, @NotNull final ExitConnectorModel exitConnectorModel) { this.exitConnectorActions = exitConnectorActions; - mapViewManager.addMapViewManagerListener(mapViewManagerListener); exitConnectorModel.addExitConnectorModelListener(exitConnectorModelListener); - setCurrentMapView(mapViewManager.getActiveMapView()); } /** @@ -161,16 +134,6 @@ } /** - * Updates {@link #currentMapView}, registering or de-registering listeners - * as needed. - * @param currentMapView the new current map view - */ - private void setCurrentMapView(@Nullable final MapView<G, A, R> currentMapView) { - this.currentMapView = currentMapView; - refreshActions(); - } - - /** * Updates the enabled state of all actions. */ private void refreshActions() { @@ -251,4 +214,29 @@ refreshActions(); } + /** + * {@inheritDoc} + */ + @Override + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + currentMapView = mapView; + refreshActions(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/map/mapactions/MapActions.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/map/mapactions/MapActions.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/map/mapactions/MapActions.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -62,7 +62,7 @@ * Manages actions in the "map" menu. * @author Andreas Kirschbaum */ -public class MapActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction { +public class MapActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapCursorListener<G, A, R>, MapViewManagerListener<G, A, R> { /** * Possible directions for "enter xxx map". @@ -287,68 +287,6 @@ }; /** - * The map view manager listener which is attached to the current map if the - * current map is tracked. Otherwise it is unused. - */ - private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { - - @Override - public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { - if (currentMapView != null) { - currentMapView.getMapCursor().removeMapCursorListener(mapCursorListener); - assert currentMapView != null; - currentMapView.getMapControl().getMapModel().getMapArchObject().removeMapArchObjectListener(mapArchObjectListener); - } - currentMapView = mapView; - if (currentMapView != null) { - currentMapView.getMapCursor().addMapCursorListener(mapCursorListener); - assert currentMapView != null; - currentMapView.getMapControl().getMapModel().getMapArchObject().addMapArchObjectListener(mapArchObjectListener); - } - updateActions(); - } - - @Override - public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - // ignore - } - - @Override - public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - // ignore - } - - }; - - /** - * The map cursor listener which is attached to {@link #currentMapView}. - */ - @NotNull - private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() { - - @Override - public void mapCursorChangedPos(@NotNull final Point location) { - updateActions(); - } - - @Override - public void mapCursorChangedMode() { - // ignore - } - - @Override - public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { - // ignore - } - - @Override - public void mapCursorChangedSize() { - // ignore - } - - }; - - /** * The {@link MapArchObjectListener} attached to {@link #currentMapView}. */ @NotNull @@ -394,15 +332,7 @@ this.mapViewsManager = mapViewsManager; shrinkMapSizeDialogManager = new ShrinkMapSizeDialogManager<G, A, R>(mapViewManager); mapViewSettings.addMapViewSettingsListener(mapViewSettingsListener); - mapManager.addMapManagerListener(mapManagerListener); - mapViewManager.addMapViewManagerListener(mapViewManagerListener); - currentMapView = mapViewManager.getActiveMapView(); - if (currentMapView != null) { - currentMapView.getMapCursor().addMapCursorListener(mapCursorListener); - assert currentMapView != null; - currentMapView.getMapControl().getMapModel().getMapArchObject().addMapArchObjectListener(mapArchObjectListener); - } } /** @@ -1025,4 +955,67 @@ updateActions(); } + /** + * {@inheritDoc} + */ + @Override + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + if (currentMapView != null) { + currentMapView.getMapControl().getMapModel().getMapArchObject().removeMapArchObjectListener(mapArchObjectListener); + } + currentMapView = mapView; + if (currentMapView != null) { + currentMapView.getMapControl().getMapModel().getMapArchObject().addMapArchObjectListener(mapArchObjectListener); + } + updateActions(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedPos(@NotNull final Point location) { + updateActions(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedMode() { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedSize() { + // ignore + } + } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -24,7 +24,6 @@ import javax.swing.Action; import net.sf.gridarta.gui.map.mapactions.MapActions; import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.gui.map.renderer.MapRenderer; import net.sf.gridarta.model.archetype.Archetype; @@ -47,7 +46,7 @@ * Cursor related actions. * @author Andreas Kirschbaum */ -public class MapCursorActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction { +public class MapCursorActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapCursorListener<G, A, R>, MapViewManagerListener<G, A, R> { /** * The visible border around the cursor. Whenever the cursor moves, the map @@ -77,61 +76,6 @@ private MapView<G, A, R> currentMapView; /** - * The map view manager listener used to detect changed current maps. - */ - @NotNull - private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { - - @Override - public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { - currentMapView = mapView; - refreshActions(); - } - - @Override - public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - mapView.getMapCursor().addMapCursorListener(mapCursorListener); - mapView.getMapControl().getMapModel().addMapModelListener(mapModelListener); - } - - @Override - public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - mapView.getMapCursor().removeMapCursorListener(mapCursorListener); - mapView.getMapControl().getMapModel().removeMapModelListener(mapModelListener); - } - - }; - - /** - * The map cursor listener used to detect cursor state changes in {@link - * #currentMapView}. - */ - @NotNull - private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() { - - @Override - public void mapCursorChangedPos(@NotNull final Point location) { - refreshActions(); - } - - @Override - public void mapCursorChangedMode() { - // ignore - } - - @Override - public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { - // ignore - } - - @Override - public void mapCursorChangedSize() { - refreshActions(); - } - - }; - - /** * The map model listener used to detect map size changes in {@link * #currentMapView}. */ @@ -171,14 +115,11 @@ }; /** - * Create a new instance. - * @param mapViewManager the map view manager + * Creates a new instance. */ - public MapCursorActions(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final MapActions<G, A, R> mapActions) { + public MapCursorActions(@NotNull final MapActions<G, A, R> mapActions) { this.mapActions = mapActions; aMoveCursor = new Action[DIRECTIONS.length]; - mapViewManager.addMapViewManagerListener(mapViewManagerListener); - currentMapView = mapViewManager.getActiveMapView(); refreshActions(); } @@ -308,4 +249,61 @@ refreshActions(); } + /** + * {@inheritDoc} + */ + @Override + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + currentMapView = mapView; + refreshActions(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { + mapView.getMapControl().getMapModel().addMapModelListener(mapModelListener); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { + mapView.getMapControl().getMapModel().removeMapModelListener(mapModelListener); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedPos(@NotNull final Point location) { + refreshActions(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedMode() { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void mapCursorChangedSize() { + refreshActions(); + } + } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/mainactions/MainActions.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/mainactions/MainActions.java 2014-03-01 07:10:48 UTC (rev 9672) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/mainactions/MainActions.java 2014-03-01 08:50:27 UTC (rev 9673) @@ -31,7 +31,6 @@ import net.sf.gridarta.gui.dialog.find.FindDialogManager; import net.sf.gridarta.gui.dialog.replace.ReplaceDialogManager; import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.gui.misc.ShiftProcessor; import net.sf.gridarta.gui.panel.objectchooser.ObjectChooser; @@ -67,7 +66,7 @@ * Encapsulates actions and related functions. * @author Andreas Kirschbaum */ -public class MainActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction { +public class MainActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R ... [truncated message content] |
From: <aki...@us...> - 2014-03-08 20:14:53
|
Revision: 9677 http://sourceforge.net/p/gridarta/code/9677 Author: akirschbaum Date: 2014-03-08 20:14:48 +0000 (Sat, 08 Mar 2014) Log Message: ----------- Rewrite parser for TreasureLists.xml. Modified Paths: -------------- trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java 2014-03-08 19:53:12 UTC (rev 9676) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java 2014-03-08 20:14:48 UTC (rev 9677) @@ -20,12 +20,11 @@ package net.sf.gridarta.model.treasurelist; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; -import net.sf.japi.xml.NodeListIterator; +import net.sf.gridarta.utils.xml.ElementsIterable; +import nu.xom.Document; +import nu.xom.Element; import org.jetbrains.annotations.NotNull; -import org.w3c.dom.Document; -import org.w3c.dom.Element; /** * Utility class for loadings the TreasureLists.xml file. @@ -51,21 +50,17 @@ public static Map<String, TreasureTreeNode> parseTreasureLists(@NotNull final Document specialTreasureListsDocument) { final Map<String, TreasureTreeNode> specialTreasureLists = new HashMap<String, TreasureTreeNode>(); - final Element rootElement = specialTreasureListsDocument.getDocumentElement(); - assert rootElement != null && rootElement.getNodeName().equalsIgnoreCase("lists"); + final Element rootElement = specialTreasureListsDocument.getRootElement(); + assert rootElement != null && rootElement.getLocalName().equalsIgnoreCase("lists"); - final NodeListIterator<Element> it = new NodeListIterator<Element>(rootElement, "list"); - while (it.hasNext()) { - final Element list = it.next(); - final String listName = list.getAttribute("name"); + for (final Element list : new ElementsIterable(rootElement.getChildElements("list"))) { + final String listName = list.getAttribute("name").getValue(); assert listName != null; final TreasureTreeNode folder = new TreasureTreeNode(new FolderTreasureObj(listName)); - final Iterator<Element> it2 = new NodeListIterator<Element>(list, "entry"); - while (it2.hasNext()) { - final Element entry = it2.next(); - final String entryName = entry.getAttribute("name"); + for (final Element entry : new ElementsIterable(list.getChildElements("entry"))) { + final String entryName = entry.getAttribute("name").getValue(); assert entryName != null; specialTreasureLists.put(entryName, folder); Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java =================================================================== --- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 19:53:12 UTC (rev 9676) +++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 20:14:48 UTC (rev 9677) @@ -114,12 +114,12 @@ import net.sf.gridarta.utils.xml.ParseUtils; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; +import nu.xom.Document; import nu.xom.ParsingException; import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -259,7 +259,7 @@ gameObjectSpells = loadArchetypeSpells(projectFactory.getSpellType(), gameObjectFactory, archetypeSet); numberSpells = loadSpellFile(projectFactory.getSpellFile(), errorView, projectSettings, xmlHelper); scriptsFile = new File(projectSettings.getMapsDirectory(), projectFactory.getScriptsDir()); - final Map<String, TreasureTreeNode> specialTreasureLists = loadSpecialTreasureLists(errorView, xmlHelper.getDocumentBuilder(), projectSettings); + final Map<String, TreasureTreeNode> specialTreasureLists = loadSpecialTreasureLists(errorView, projectSettings); treasureTree = TreasureLoader.parseTreasures(errorView, specialTreasureLists, configSource, projectSettings); final NamedFilter defaultFilterList = new NamedFilter(Collections.<NamedGameObjectMatcher>emptyList()); final PluginParameterFactory<G, A, R> pluginParameterFactory = new PluginParameterFactory<G, A, R>(archetypeSet, mapManager, projectSettings, pathManager); @@ -326,7 +326,7 @@ } final ErrorViewCollector gameObjectMatchersErrorViewCollector = new ErrorViewCollector(errorView, url); try { - final nu.xom.Document document; + final Document document; final InputStream inputStream = url.openStream(); try { document = ParseUtils.readXmlStream(inputStream, "GameObjectMatchers", "GameObjectMatchers.dtd", "/system/dtd/GameObjectMatchers.dtd", new ErrorViewCollectorErrorHandler(gameObjectMatchersErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID)); @@ -443,7 +443,7 @@ } @NotNull - public static Map<String, TreasureTreeNode> loadSpecialTreasureLists(@NotNull final ErrorView errorView, @NotNull final DocumentBuilder documentBuilder, @NotNull final ProjectSettings projectSettings) { + public static Map<String, TreasureTreeNode> loadSpecialTreasureLists(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings) { Map<String, TreasureTreeNode> specialTreasureLists; try { final URL url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), "TreasureLists.xml"); @@ -451,19 +451,17 @@ try { final InputStream inputStream = url.openStream(); try { - documentBuilder.setErrorHandler(new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID)); - try { - final Document specialTreasureListsDocument = documentBuilder.parse(new InputSource(inputStream)); - specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument); - } finally { - documentBuilder.setErrorHandler(null); - } + final Document specialTreasureListsDocument = ParseUtils.readXmlStream(inputStream, "lists", "TreasureLists.dtd", "/sys/dtd/TreasureLists.dtd", new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID)); + specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument); } finally { inputStream.close(); } } catch (final IOException ex) { treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage()); specialTreasureLists = Collections.emptyMap(); + } catch (final ParsingException ex) { + treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage()); + specialTreasureLists = Collections.emptyMap(); } catch (final SAXException ex) { treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage()); specialTreasureLists = Collections.emptyMap(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-08 21:02:11
|
Revision: 9678 http://sourceforge.net/p/gridarta/code/9678 Author: akirschbaum Date: 2014-03-08 21:02:06 +0000 (Sat, 08 Mar 2014) Log Message: ----------- Extract duplicated code into function. Modified Paths: -------------- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java =================================================================== --- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 20:14:48 UTC (rev 9677) +++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 21:02:06 UTC (rev 9678) @@ -22,7 +22,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.net.URL; import java.util.Collections; import java.util.Map; @@ -326,13 +325,7 @@ } final ErrorViewCollector gameObjectMatchersErrorViewCollector = new ErrorViewCollector(errorView, url); try { - final Document document; - final InputStream inputStream = url.openStream(); - try { - document = ParseUtils.readXmlStream(inputStream, "GameObjectMatchers", "GameObjectMatchers.dtd", "/system/dtd/GameObjectMatchers.dtd", new ErrorViewCollectorErrorHandler(gameObjectMatchersErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID)); - } finally { - inputStream.close(); - } + final Document document = ParseUtils.readXmlUrl(url, "GameObjectMatchers", "GameObjectMatchers.dtd", "/system/dtd/GameObjectMatchers.dtd", new ErrorViewCollectorErrorHandler(gameObjectMatchersErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID)); GameObjectMatchersParser.readGameObjectMatchers(document, gameObjectMatchers, gameObjectMatchersErrorViewCollector); } catch (final IOException ex) { gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage()); @@ -449,13 +442,8 @@ final URL url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), "TreasureLists.xml"); final ErrorViewCollector treasureListsErrorViewCollector = new ErrorViewCollector(errorView, url); try { - final InputStream inputStream = url.openStream(); - try { - final Document specialTreasureListsDocument = ParseUtils.readXmlStream(inputStream, "lists", "TreasureLists.dtd", "/sys/dtd/TreasureLists.dtd", new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID)); - specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument); - } finally { - inputStream.close(); - } + final Document specialTreasureListsDocument = ParseUtils.readXmlUrl(url, "lists", "TreasureLists.dtd", "/sys/dtd/TreasureLists.dtd", new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID)); + specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument); } catch (final IOException ex) { treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage()); specialTreasureLists = Collections.emptyMap(); Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java =================================================================== --- trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java 2014-03-08 20:14:48 UTC (rev 9677) +++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java 2014-03-08 21:02:06 UTC (rev 9678) @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URL; import nu.xom.Builder; import nu.xom.DocType; import nu.xom.Document; @@ -45,6 +46,30 @@ } /** + * Reads an XML file from an {@link URL}. + * @param url the URL to read + * @param rootElement the tag name of the root element in the DOCTYPE + * declaration + * @param systemId the system ID of the doctype declaration + * @param resourceName the name of the resource that contains the DTD + * contents + * @param errorHandler the error handler to use or {@code null} + * @return the document for the XML file + * @throws IOException if the XML file cannot be read + * @throws ParsingException if parsing the XML file fails + * @throws SAXException the parsing the XML file fails + */ + @NotNull + public static Document readXmlUrl(@NotNull final URL url, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler) throws IOException, ParsingException, SAXException { + final InputStream inputStream = url.openStream(); + try { + return readXmlStream(inputStream, rootElement, systemId, resourceName, errorHandler); + } finally { + inputStream.close(); + } + } + + /** * Reads an XML file. * @param inputStream the XML file to read * @param rootElement the tag name of the root element in the DOCTYPE This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-08 22:18:58
|
Revision: 9680 http://sourceforge.net/p/gridarta/code/9680 Author: akirschbaum Date: 2014-03-08 22:18:53 +0000 (Sat, 08 Mar 2014) Log Message: ----------- Rewrite parser for types.xml. Modified Paths: -------------- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java 2014-03-08 22:17:01 UTC (rev 9679) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java 2014-03-08 22:18:53 UTC (rev 9680) @@ -22,11 +22,11 @@ import java.util.regex.Pattern; import net.sf.gridarta.model.errorview.ErrorViewCategory; import net.sf.gridarta.model.errorview.ErrorViewCollector; +import nu.xom.Attribute; +import nu.xom.Element; +import nu.xom.Node; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; /** * Utility class for parsing {@link ArchetypeAttribute ArchetypeAttributes}. @@ -187,7 +187,7 @@ */ @NotNull private static String parseText(@NotNull final Node attributeElement) { - final String tmp = attributeElement.getTextContent().trim(); + final String tmp = attributeElement.getValue().trim(); return LINE_BREAK.matcher(tmp).replaceAll(tmp.startsWith("<html>") ? " " : "\n"); } @@ -200,9 +200,9 @@ */ @NotNull private static String getAttributeValue(@NotNull final Element element, @NotNull final String attributeKey) throws MissingAttributeException { - final Attr attr = element.getAttributeNode(attributeKey); + final Attribute attr = element.getAttribute(attributeKey); if (attr == null) { - throw new MissingAttributeException(element.getTagName(), attributeKey); + throw new MissingAttributeException(element.getLocalName(), attributeKey); } return attr.getValue().trim(); @@ -217,7 +217,7 @@ */ @Nullable private static String getAttributeValueOptional(@NotNull final Element element, @NotNull final String attributeKey) { - final Attr attr = element.getAttributeNode(attributeKey); + final Attribute attr = element.getAttribute(attributeKey); return attr == null ? null : attr.getValue().trim(); } Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2014-03-08 22:17:01 UTC (rev 9679) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2014-03-08 22:18:53 UTC (rev 9680) @@ -21,19 +21,19 @@ import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashSet; import net.sf.gridarta.model.errorview.ErrorViewCategory; import net.sf.gridarta.model.errorview.ErrorViewCollector; import net.sf.gridarta.utils.StringUtils; -import net.sf.japi.xml.NodeListIterator; +import net.sf.gridarta.utils.XmlUtils; +import net.sf.gridarta.utils.xml.ElementsIterable; +import nu.xom.Attribute; +import nu.xom.Element; +import nu.xom.Node; import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; /** * Utility class for parsing {@link ArchetypeType} instances. @@ -87,7 +87,8 @@ LOG.debug("loadAttributeList: " + typeName); } final int typeNo = parseTypeNo(typeElement, isDefaultType, typeName, errorViewCollector); - final String display = typeElement.getAttribute(Constants.XML_TYPE_DISPLAY); + final Attribute typeElementAttribute = typeElement.getAttribute(Constants.XML_TYPE_DISPLAY); + final String display = typeElementAttribute == null ? "" : typeElementAttribute.getValue(); final boolean map = parseMap(typeElement); final int[] inv = parseInv(typeElement, typeName, errorViewCollector); final boolean allowsAllInv = parseAllowsAllInv(typeElement); @@ -95,9 +96,7 @@ final ArchetypeAttributesDefinition typeAttributes = isDefaultType ? new ArchetypeAttributesDefinition() : parseTypeAttributes(typeElement, typeName, errorViewCollector, ignoreTable, ignorelistsDefinition); final Collection<String> importTypes = new LinkedHashSet<String>(); - final Iterator<Element> importTypeIterator = new NodeListIterator<Element>(typeElement, Constants.XML_ELEMENT_IMPORT_TYPE); - while (importTypeIterator.hasNext()) { - final Element importTypeElement = importTypeIterator.next(); + for (final Element importTypeElement : new ElementsIterable(typeElement.getChildElements(Constants.XML_ELEMENT_IMPORT_TYPE))) { final String importType = parseImportType(importTypeElement, typeName, errorViewCollector); if (importType != null && !importTypes.add(importType)) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " has duplicate import for '" + importType + "'."); @@ -251,7 +250,7 @@ */ @Nullable private static String parseImportType(@NotNull final Element importTypeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) { - final Attr nameAttribute = importTypeElement.getAttributeNode(Constants.XML_IMPORT_TYPE_NAME); + final Attribute nameAttribute = importTypeElement.getAttribute(Constants.XML_IMPORT_TYPE_NAME); if (nameAttribute == null) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " has " + Constants.XML_ELEMENT_IMPORT_TYPE + " element without '" + Constants.XML_IMPORT_TYPE_NAME + "'."); return null; @@ -275,7 +274,7 @@ */ @NotNull private static String parseTypeName(@NotNull final Element typeElement, final boolean isDefaultType) { - return isDefaultType ? "default" : typeElement.getAttribute(Constants.XML_TYPE_NAME); + return isDefaultType ? "default" : typeElement.getAttribute(Constants.XML_TYPE_NAME).getValue(); } /** @@ -291,7 +290,7 @@ return -1; } - final String number = typeElement.getAttribute(Constants.XML_TYPE_NUMBER); + final String number = typeElement.getAttribute(Constants.XML_TYPE_NUMBER).getValue(); try { return Integer.parseInt(number); } catch (final NumberFormatException ignored) { @@ -306,8 +305,8 @@ * @return whether this archetype is allowed on maps */ private static boolean parseMap(@NotNull final Element typeElement) { - final String map = typeElement.getAttribute(Constants.XML_TYPE_MAP); - return map.equals("yes"); + final Attribute attribute = typeElement.getAttribute(Constants.XML_TYPE_MAP); + return attribute != null && attribute.getValue().equals("yes"); } /** @@ -320,11 +319,12 @@ */ @Nullable private static int[] parseInv(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) { - if (!typeElement.hasAttribute(Constants.XML_TYPE_INV)) { + final Attribute attribute = typeElement.getAttribute(Constants.XML_TYPE_INV); + if (attribute == null) { return null; } - final String inv = typeElement.getAttribute(Constants.XML_TYPE_INV); + final String inv = attribute.getValue(); if (inv.isEmpty()) { return EMPTY_INT_ARRAY; } @@ -351,8 +351,8 @@ * @return whether this archetype allows all inventory game objects */ private static boolean parseAllowsAllInv(@NotNull final Element typeElement) { - final String allowsAllInv = typeElement.getAttribute(Constants.XML_TYPE_ALLOWS_ALL_INV); - return allowsAllInv.equals("yes"); + final Attribute attribute = typeElement.getAttribute(Constants.XML_TYPE_ALLOWS_ALL_INV); + return attribute != null && attribute.getValue().equals("yes"); } /** @@ -369,7 +369,7 @@ private static ArchetypeAttributesDefinition parseTypeAttributes(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition) { final ArchetypeAttributesDefinition typeAttributes = parseRequiredAttribute(typeElement, typeName, errorViewCollector); - final Element ignoreElement = NodeListIterator.getFirstChild(typeElement, Constants.XML_ELEMENT_IGNORE); + final Element ignoreElement = XmlUtils.getChildOptional(typeElement, Constants.XML_ELEMENT_IGNORE); if (ignoreElement != null) { parseAttributeAttributes(ignoreElement, typeName, errorViewCollector, ignoreTable); parseIgnoreListAttribute(ignoreElement, typeName, errorViewCollector, ignoreTable, ignorelistsDefinition); @@ -388,13 +388,10 @@ @NotNull private static ArchetypeAttributesDefinition parseRequiredAttribute(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) { final ArchetypeAttributesDefinition attributes = new ArchetypeAttributesDefinition(); - final Element requiredElement = NodeListIterator.getFirstChild(typeElement, Constants.XML_ELEMENT_REQUIRED); + final Element requiredElement = XmlUtils.getChildOptional(typeElement, Constants.XML_ELEMENT_REQUIRED); if (requiredElement != null) { - final Iterator<Element> attributeIterator = new NodeListIterator<Element>(requiredElement, Constants.XML_ELEMENT_ATTRIBUTE); - while (attributeIterator.hasNext()) { - final Element attributeElement = attributeIterator.next(); - - final Attr archAttribute = attributeElement.getAttributeNode(Constants.XML_ATTRIBUTE_ARCH); + for (final Element attributeElement : new ElementsIterable(requiredElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) { + final Attribute archAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_ARCH); if (archAttribute == null) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_REQUIRED + ": element of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_ARCH + "'."); continue; @@ -405,7 +402,7 @@ continue; } - final Attr valueAttribute = attributeElement.getAttributeNode(Constants.XML_ATTRIBUTE_VALUE); + final Attribute valueAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_VALUE); if (valueAttribute == null) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_REQUIRED + ": element of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_VALUE + "'."); continue; @@ -430,11 +427,8 @@ * @param ignoreTable the ignore table to add to */ private static void parseAttributeAttributes(@NotNull final Element ignoreElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable) { - final Iterator<Element> attributeIterator = new NodeListIterator<Element>(ignoreElement, Constants.XML_ELEMENT_ATTRIBUTE); - while (attributeIterator.hasNext()) { - final Element attributeElement = attributeIterator.next(); - - final Attr archAttribute = attributeElement.getAttributeNode(Constants.XML_ATTRIBUTE_ARCH); + for (final Element attributeElement : new ElementsIterable(ignoreElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) { + final Attribute archAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_ARCH); if (archAttribute == null) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_IGNORE + ": section of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_ARCH + "'."); continue; @@ -459,11 +453,8 @@ * @param ignorelistsDefinition the ignore lists to use */ private static void parseIgnoreListAttribute(@NotNull final Element ignoreElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition) { - final Iterator<Element> ignoreListIterator = new NodeListIterator<Element>(ignoreElement, Constants.XML_ELEMENT_IGNORE_LIST); - while (ignoreListIterator.hasNext()) { - final Element ignoreListElement = ignoreListIterator.next(); - - final Attr nameAttribute = ignoreListElement.getAttributeNode(Constants.XML_IGNORE_LIST_NAME); + for (final Element ignoreListElement : new ElementsIterable(ignoreElement.getChildElements(Constants.XML_ELEMENT_IGNORE_LIST))) { + final Attribute nameAttribute = ignoreListElement.getAttribute(Constants.XML_IGNORE_LIST_NAME); if (nameAttribute == null) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_IGNORE + ": section of type " + typeName + ": " + Constants.XML_ELEMENT_IGNORE_LIST + " missing '" + Constants.XML_IGNORE_LIST_NAME + "'."); continue; @@ -489,8 +480,8 @@ */ @Nullable private static String parseDescription(@NotNull final Element root) { - final Node elem = NodeListIterator.getFirstChild(root, Constants.XML_DESCRIPTION); - return elem == null ? null : elem.getTextContent().trim(); + final Node elem = XmlUtils.getChildOptional(root, Constants.XML_DESCRIPTION); + return elem == null ? null : elem.getValue().trim(); } /** @@ -500,8 +491,8 @@ */ @Nullable private static String parseUse(@NotNull final Element root) { - final Node elem = NodeListIterator.getFirstChild(root, Constants.XML_USE); - return elem == null ? null : elem.getTextContent().trim(); + final Node elem = XmlUtils.getChildOptional(root, Constants.XML_USE); + return elem == null ? null : elem.getValue().trim(); } /** @@ -519,15 +510,13 @@ @NotNull private Iterable<ArchetypeAttributeSection> addAttributeList(@NotNull final Element typeElement, @NotNull final ArchetypeAttributeSection defaultAttributeSection, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet) { final ArchetypeAttributeSections sections = new ArchetypeAttributeSections(); - final Iterator<Element> childIterator = new NodeListIterator<Element>(typeElement, Node.ELEMENT_NODE); - while (childIterator.hasNext()) { - final Element childElement = childIterator.next(); - final String childName = childElement.getNodeName(); + for (final Element childElement : new ElementsIterable(typeElement.getChildElements())) { + final String childName = childElement.getLocalName(); if (childName.equals(Constants.XML_ELEMENT_ATTRIBUTE)) { parseAttribute(childElement, errorViewCollector, typeName, archetypeTypeSet, sections, defaultAttributeSection.getSectionName()); - } else if (childName.equals(Constants.XML_ELEMENT_SECTION) && childElement.hasChildNodes()) { - final Attr nameAttribute = childElement.getAttributeNode(Constants.XML_SECTION_NAME); + } else if (childName.equals(Constants.XML_ELEMENT_SECTION) && childElement.getChildElements().size() > 0) { + final Attribute nameAttribute = childElement.getAttribute(Constants.XML_SECTION_NAME); if (nameAttribute == null) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " contains a " + Constants.XML_ELEMENT_SECTION + " missing '" + Constants.XML_SECTION_NAME + "'."); continue; @@ -539,9 +528,8 @@ continue; } - final Iterator<Element> attributeIterator = new NodeListIterator<Element>(childElement, Constants.XML_ELEMENT_ATTRIBUTE); - while (attributeIterator.hasNext()) { - parseAttribute(attributeIterator.next(), errorViewCollector, typeName, archetypeTypeSet, sections, sectionName); + for (final Element element : new ElementsIterable(childElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) { + parseAttribute(element, errorViewCollector, typeName, archetypeTypeSet, sections, sectionName); } } } Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java 2014-03-08 22:17:01 UTC (rev 9679) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java 2014-03-08 22:18:53 UTC (rev 9680) @@ -19,25 +19,20 @@ package net.sf.gridarta.model.archetypetype; -import java.io.IOException; -import java.util.Iterator; -import javax.xml.parsers.DocumentBuilder; import net.sf.gridarta.model.errorview.ErrorViewCategory; import net.sf.gridarta.model.errorview.ErrorViewCollector; import net.sf.gridarta.utils.StringUtils; import net.sf.gridarta.utils.SyntaxErrorException; import net.sf.gridarta.utils.XmlUtils; -import net.sf.japi.xml.NodeListIterator; +import net.sf.gridarta.utils.xml.ElementsIterable; +import nu.xom.Attribute; +import nu.xom.Document; +import nu.xom.Element; +import nu.xom.Node; import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; /** * Parser for {@link ArchetypeTypeSet ArchetypeTypeSets} ("types.xml" files). @@ -53,12 +48,6 @@ private static final Category LOG = Logger.getLogger(ArchetypeTypeSetParser.class); /** - * The {@link DocumentBuilder} to use. - */ - @NotNull - private final DocumentBuilder documentBuilder; - - /** * The {@link ArchetypeTypeParser} }to use. */ @NotNull @@ -66,61 +55,35 @@ /** * Creates a new instance. - * @param documentBuilder the document builder to use * @param archetypeTypeParser the archetype type parser to use */ - public ArchetypeTypeSetParser(@NotNull final DocumentBuilder documentBuilder, @NotNull final ArchetypeTypeParser archetypeTypeParser) { - this.documentBuilder = documentBuilder; + public ArchetypeTypeSetParser(@NotNull final ArchetypeTypeParser archetypeTypeParser) { this.archetypeTypeParser = archetypeTypeParser; } /** * Loads a types.xml file. * @param errorViewCollector the error view collector for reporting errors - * @param inputSource the input source providing the contents of the - * types.xml file - * @return the loaded archetype types - */ - @NotNull - public ArchetypeTypeSet loadTypesFromXML(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final InputSource inputSource) { - final Document doc; - try { - doc = documentBuilder.parse(inputSource); - } catch (final SAXException e) { - errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "parsing error: " + e.getMessage()); - return new ArchetypeTypeSet(); - } catch (final IOException e) { - errorViewCollector.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, e.getMessage()); - return new ArchetypeTypeSet(); - } - return loadTypesFromXML(errorViewCollector, inputSource.getSystemId(), doc); - } - - /** - * Loads a types.xml file. - * @param errorViewCollector the error view collector for reporting errors - * @param filename the filename of the types.xml file for error messages * @param document the document containing the contents of the types.xml * file * @return the loaded archetype types */ @NotNull - public ArchetypeTypeSet loadTypesFromXML(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final String filename, @NotNull final Document document) { + public ArchetypeTypeSet loadTypesFromXML(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final Document document) { final ArchetypeTypeSet archetypeTypeSet = new ArchetypeTypeSet(); - final Element rootElement = document.getDocumentElement(); + final Element rootElement = document.getRootElement(); parseBitmasks(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_BITMASKS), errorViewCollector); parseLists(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_LISTS), errorViewCollector); final IgnorelistsDefinition ignorelistsDefinition = parseIgnoreLists(XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_IGNORELISTS), errorViewCollector); - parseAttributeOrder(archetypeTypeSet, NodeListIterator.getFirstChild(rootElement, Constants.XML_ELEMENT_ATTRIBUTE_ORDER), errorViewCollector); + parseAttributeOrder(archetypeTypeSet, XmlUtils.getChildOptional(rootElement, Constants.XML_ELEMENT_ATTRIBUTE_ORDER), errorViewCollector); final ArchetypeType defaultArchetypeType = parseDefaultType(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_DEFAULT_TYPE), errorViewCollector, ignorelistsDefinition); - final Iterator<Element> typeElements = new NodeListIterator<Element>(rootElement, Constants.XML_ELEMENT_TYPE); - while (typeElements.hasNext()) { - parseTypes(archetypeTypeSet, typeElements.next(), errorViewCollector, defaultArchetypeType, ignorelistsDefinition); + for (final Element element : new ElementsIterable(rootElement.getChildElements(Constants.XML_ELEMENT_TYPE))) { + parseTypes(archetypeTypeSet, element, errorViewCollector, defaultArchetypeType, ignorelistsDefinition); } if (LOG.isInfoEnabled()) { - LOG.info("Loaded " + archetypeTypeSet.getArchetypeTypeCount() + " types from '" + filename + "\'"); + LOG.info("Loaded " + archetypeTypeSet.getArchetypeTypeCount() + " types."); } return archetypeTypeSet; } @@ -133,11 +96,8 @@ * @param errorViewCollector the error view collector for reporting errors */ private static void parseBitmasks(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element bitmasksElement, @NotNull final ErrorViewCollector errorViewCollector) { - final Iterator<Element> bitmaskIterator = new NodeListIterator<Element>(bitmasksElement, Constants.XML_ELEMENT_BITMASK); - while (bitmaskIterator.hasNext()) { - final Element bitmaskElement = bitmaskIterator.next(); - - final String name = bitmaskElement.getAttribute(Constants.XML_BITMASK_NAME); + for (final Element bitmaskElement : new ElementsIterable(bitmasksElement.getChildElements(Constants.XML_ELEMENT_BITMASK))) { + final String name = bitmaskElement.getAttribute(Constants.XML_BITMASK_NAME).getValue(); final AttributeBitmask attributeBitmask = parseBitmask(bitmaskElement, name, errorViewCollector); if (attributeBitmask != null) { archetypeTypeSet.addBitmask(name, attributeBitmask); @@ -156,12 +116,11 @@ */ @Nullable private static AttributeBitmask parseBitmask(@NotNull final Element bitmaskElement, @NotNull final String name, @NotNull final ErrorViewCollector errorViewCollector) { - final boolean isNamed = bitmaskElement.getAttribute(Constants.XML_BITMASK_IS_NAMED).equals("yes"); + final boolean isNamed = bitmaskElement.getAttribute(Constants.XML_BITMASK_IS_NAMED).getValue().equals("yes"); final AttributeBitmask attributeBitmask = new AttributeBitmask(isNamed); - final NodeListIterator<Element> entries = new NodeListIterator<Element>(bitmaskElement, Constants.XML_ELEMENT_BMENTRY); - while (entries.hasNext()) { - parseBmentry(entries.next(), errorViewCollector, name, isNamed, attributeBitmask); + for (final Element element : new ElementsIterable(bitmaskElement.getChildElements(Constants.XML_ELEMENT_BMENTRY))) { + parseBmentry(element, errorViewCollector, name, isNamed, attributeBitmask); } if (attributeBitmask.getNumber() <= 0) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, name + ": no '" + Constants.XML_BMENTRY_BIT + "' entries"); @@ -191,15 +150,17 @@ * @param attributeBitmask the bitmask attribute to update */ private static void parseBmentry(@NotNull final Element bmentryElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String bitmaskName, final boolean isNamed, @NotNull final AttributeBitmask attributeBitmask) { - final String bitAttribute = bmentryElement.getAttribute(Constants.XML_BMENTRY_BIT); + final Attribute tmpBitAttribute = bmentryElement.getAttribute(Constants.XML_BMENTRY_BIT); + final String bitAttribute = tmpBitAttribute == null ? "" : tmpBitAttribute.getValue(); - final String valueAttribute = bmentryElement.getAttribute(Constants.XML_BMENTRY_VALUE); - if (bitAttribute.length() != 0 && valueAttribute.length() != 0) { + final Attribute tmpValueAttribute = bmentryElement.getAttribute(Constants.XML_BMENTRY_VALUE); + final String valueAttribute = tmpValueAttribute == null ? "" : tmpValueAttribute.getValue(); + if (!bitAttribute.isEmpty() && !valueAttribute.isEmpty()) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, bitmaskName + ": element contains both '" + Constants.XML_BMENTRY_BIT + "' and '" + Constants.XML_BMENTRY_VALUE + "' attributes"); return; } - final String name = bmentryElement.getAttribute(Constants.XML_BMENTRY_NAME); + final String name = bmentryElement.getAttribute(Constants.XML_BMENTRY_NAME).getValue(); final int value; if (bitAttribute.isEmpty()) { @@ -234,7 +195,8 @@ attributeBitmask.addName(name, value); - final String encoding = bmentryElement.getAttribute(Constants.XML_BMENTRY_ENCODING); + final Attribute tmpEncodingAttribute = bmentryElement.getAttribute(Constants.XML_BMENTRY_ENCODING); + final String encoding = tmpEncodingAttribute == null ? "" : tmpEncodingAttribute.getValue(); if (isNamed) { if (encoding.isEmpty()) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, bitmaskName + ": missing '" + Constants.XML_BMENTRY_ENCODING + "' attribute"); @@ -258,9 +220,8 @@ * @param errorViewCollector the error view collector for reporting errors */ private static void parseLists(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element listsElement, @NotNull final ErrorViewCollector errorViewCollector) { - final Iterator<Element> listIterator = new NodeListIterator<Element>(listsElement, Constants.XML_ELEMENT_LIST); - while (listIterator.hasNext()) { - parseList(archetypeTypeSet, listIterator.next(), errorViewCollector); + for (final Element element : new ElementsIterable(listsElement.getChildElements(Constants.XML_ELEMENT_LIST))) { + parseList(archetypeTypeSet, element, errorViewCollector); } } @@ -273,11 +234,10 @@ */ private static void parseList(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element listElement, @NotNull final ErrorViewCollector errorViewCollector) { final ArchetypeTypeList list = new ArchetypeTypeList(); - final Iterator<Element> listentryIterator = new NodeListIterator<Element>(listElement, Constants.XML_ELEMENT_LISTENTRY); - while (listentryIterator.hasNext()) { - parseListEntry(listentryIterator.next(), errorViewCollector, list); + for (final Element element : new ElementsIterable(listElement.getChildElements(Constants.XML_ELEMENT_LISTENTRY))) { + parseListEntry(element, errorViewCollector, list); } - final String name = listElement.getAttribute(Constants.XML_LIST_NAME); + final String name = listElement.getAttribute(Constants.XML_LIST_NAME).getValue(); archetypeTypeSet.addList(name, list); } @@ -289,8 +249,8 @@ * @param list the archetype type list to add to */ private static void parseListEntry(@NotNull final Element listentryElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final ArchetypeTypeList list) { - final String name = listentryElement.getAttribute(Constants.XML_LISTENTRY_NAME); - final String valueString = listentryElement.getAttribute(Constants.XML_LISTENTRY_VALUE); + final String name = listentryElement.getAttribute(Constants.XML_LISTENTRY_NAME).getValue(); + final String valueString = listentryElement.getAttribute(Constants.XML_LISTENTRY_VALUE).getValue(); final int value; try { value = Integer.valueOf(valueString); @@ -314,10 +274,9 @@ */ @NotNull private static IgnorelistsDefinition parseIgnoreLists(@NotNull final Element ignorelistsElement, @NotNull final ErrorViewCollector errorViewCollector) { - final Iterator<Element> ignoreListIterator = new NodeListIterator<Element>(ignorelistsElement, Constants.XML_ELEMENT_IGNORE_LIST); final IgnorelistsDefinition ignorelistsDefinition = new IgnorelistsDefinition(); - while (ignoreListIterator.hasNext()) { - parseIgnoreList(ignoreListIterator.next(), errorViewCollector, ignorelistsDefinition); + for (final Element element : new ElementsIterable(ignorelistsElement.getChildElements(Constants.XML_ELEMENT_IGNORE_LIST))) { + parseIgnoreList(element, errorViewCollector, ignorelistsDefinition); } return ignorelistsDefinition; } @@ -331,7 +290,7 @@ */ private static void parseAttributeOrder(@NotNull final ArchetypeTypeSet archetypeTypeSet, @Nullable final Node attributeOrderElement, @NotNull final ErrorViewCollector errorViewCollector) { if (attributeOrderElement != null) { - for (final String value : StringUtils.PATTERN_WHITESPACE_NEWLINE.split(attributeOrderElement.getTextContent())) { + for (final String value : StringUtils.PATTERN_WHITESPACE_NEWLINE.split(attributeOrderElement.getValue())) { if (!value.isEmpty()) { if (archetypeTypeSet.addAttributeOrder(value)) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, value + ": duplicate attribute name"); @@ -349,15 +308,13 @@ * @param ignorelistsDefinition the ignore lists definition to update */ private static void parseIgnoreList(@NotNull final Element ignoreListElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final IgnorelistsDefinition ignorelistsDefinition) { - final String name = ignoreListElement.getAttribute(Constants.XML_IGNORE_LIST_NAME); + final String name = ignoreListElement.getAttribute(Constants.XML_IGNORE_LIST_NAME).getValue(); if (ignorelistsDefinition.containsKey(name)) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, name + ": duplicate name"); } - final Iterator<Element> attributeIterator = new NodeListIterator<Element>(ignoreListElement, Constants.XML_ELEMENT_ATTRIBUTE); - while (attributeIterator.hasNext()) { - final Element attributeElement = attributeIterator.next(); - final Attr archAttribute = attributeElement.getAttributeNode(Constants.XML_ATTRIBUTE_ARCH); + for (final Element attributeElement : new ElementsIterable(ignoreListElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) { + final Attribute archAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_ARCH); if (archAttribute != null) { try { ignorelistsDefinition.put(name, archAttribute.getValue()); @@ -401,7 +358,7 @@ * @param ignorelistsDefinition the contents of the "ignorelists" section */ private void parseTypes(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element typeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final ArchetypeType defaultArchetypeType, @NotNull final IgnorelistsDefinition ignorelistsDefinition) { - if (!typeElement.getAttribute(Constants.XML_TYPE_AVAILABLE).equals("no")) { + if (!typeElement.getAttribute(Constants.XML_TYPE_AVAILABLE).getValue().equals("no")) { archetypeTypeSet.addArchetypeType(archetypeTypeParser.loadAttributeList(typeElement, errorViewCollector, defaultArchetypeType, archetypeTypeSet, ignorelistsDefinition, false)); } } @@ -414,7 +371,7 @@ */ private static void rejectAttributes(@NotNull final Element element, @NotNull final String... attributes) throws SyntaxErrorException { for (final String attribute : attributes) { - if (element.hasAttribute(attribute)) { + if (element.getAttribute(attribute) != null) { throw new SyntaxErrorException("unexpected attribute '" + attribute + "'"); } } Modified: trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java =================================================================== --- trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java 2014-03-08 22:17:01 UTC (rev 9679) +++ trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java 2014-03-08 22:18:53 UTC (rev 9680) @@ -27,15 +27,15 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import javax.xml.parsers.ParserConfigurationException; import net.sf.gridarta.model.errorview.ErrorView; import net.sf.gridarta.model.errorview.ErrorViewCollector; import net.sf.gridarta.model.errorview.TestErrorView; -import net.sf.gridarta.utils.XmlHelper; +import net.sf.gridarta.utils.xml.ParseUtils; +import nu.xom.ParsingException; import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Test; -import org.xml.sax.InputSource; +import org.xml.sax.SAXException; /** * Regression tests for {@link ArchetypeTypeSetParser}. @@ -57,101 +57,112 @@ /** * Read a simple types.xml file. - * @throws ParserConfigurationException if the test fails * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void test1() throws ParserConfigurationException, IOException { + public void test1() throws IOException, ParsingException, SAXException { check("test1"); } /** * Checks that imports do work. - * @throws ParserConfigurationException if the test fails * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testImport1() throws ParserConfigurationException, IOException { + public void testImport1() throws IOException, ParsingException, SAXException { check("import1"); } /** * Checks that multi-imports do work. - * @throws ParserConfigurationException if the test fails * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testImport2() throws ParserConfigurationException, IOException { + public void testImport2() throws IOException, ParsingException, SAXException { check("import2"); } /** * Checks that ignoring default attributes do work. - * @throws ParserConfigurationException if the test fails * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testIgnoreDefaultAttribute1() throws ParserConfigurationException, IOException { + public void testIgnoreDefaultAttribute1() throws IOException, ParsingException, SAXException { check("ignoreDefaultAttribute1"); } /** * Checks that ignoring import attributes do work. - * @throws ParserConfigurationException if the test fails * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testIgnoreImportAttribute1() throws ParserConfigurationException, IOException { + public void testIgnoreImportAttribute1() throws IOException, ParsingException, SAXException { check("ignoreImportAttribute1"); } /** * Checks that ignoring defined attributes do work. - * @throws ParserConfigurationException if the test fails * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testIgnoreDefinedAttribute1() throws ParserConfigurationException, IOException { + public void testIgnoreDefinedAttribute1() throws IOException, ParsingException, SAXException { check("ignoreDefinedAttribute1"); } /** * Checks that a "msg" field in default_type does work. - * @throws ParserConfigurationException if the test fails * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testMsgDefault1() throws ParserConfigurationException, IOException { + public void testMsgDefault1() throws IOException, ParsingException, SAXException { check("msgDefault1"); } /** * Checks that a "msg" field in default_type does work. - * @throws ParserConfigurationException if the test fails * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testMsgDefault2() throws ParserConfigurationException, IOException { + public void testMsgDefault2() throws IOException, ParsingException, SAXException { check("msgDefault2"); } /** * Checks that a "msg" field in default_type CAN BE "ignored". - * @throws ParserConfigurationException if the test fails * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testMsgDefault3() throws ParserConfigurationException, IOException { + public void testMsgDefault3() throws IOException, ParsingException, SAXException { check("msgDefault3"); } /** * Checks that a "archetype_order" is parsed correctly: missing * attribute_order element. - * @throws ParserConfigurationException if the test fails + * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testArchetypeOrder1() throws ParserConfigurationException { + public void testArchetypeOrder1() throws IOException, ParsingException, SAXException { final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder1"); Assert.assertFalse(errorView.hasErrors()); final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); @@ -161,10 +172,12 @@ /** * Checks that a "archetype_order" is parsed correctly: empty element. - * @throws ParserConfigurationException if the test fails + * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testArchetypeOrder2() throws ParserConfigurationException { + public void testArchetypeOrder2() throws IOException, ParsingException, SAXException { final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder2"); Assert.assertFalse(errorView.hasErrors()); final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); @@ -175,10 +188,12 @@ /** * Checks that a "archetype_order" is parsed correctly: all attributes * specified. - * @throws ParserConfigurationException if the test fails + * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testArchetypeOrder3() throws ParserConfigurationException { + public void testArchetypeOrder3() throws IOException, ParsingException, SAXException { final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder3"); Assert.assertFalse(errorView.hasErrors()); final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); @@ -189,10 +204,12 @@ /** * Checks that a "archetype_order" is parsed correctly: some attributes * missing. - * @throws ParserConfigurationException if the test fails + * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testArchetypeOrder4() throws ParserConfigurationException { + public void testArchetypeOrder4() throws IOException, ParsingException, SAXException { final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder4"); Assert.assertFalse(errorView.hasErrors()); final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); @@ -203,10 +220,11 @@ /** * Checks that a types.xml file can be read. * @param name the base name of the resources to load - * @throws ParserConfigurationException if the test fails * @throws IOException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ - private void check(@NotNull final String name) throws ParserConfigurationException, IOException { + private void check(@NotNull final String name) throws IOException, ParsingException, SAXException { final ArchetypeTypeSet archetypeTypeSet = loadArchetypeTypeSet(name); final InputStream is = getClass().getResourceAsStream("ArchetypeTypeSetParserTest-" + name + "-result.txt"); Assert.assertNotNull(is); @@ -227,33 +245,30 @@ * Loads a types.xml file from resources. * @param name the base name of the resources to load * @return the archetype type set - * @throws ParserConfigurationException if the file cannot be read + * @throws IOException if the file cannot be read + * @throws ParsingException if the file cannot be read + * @throws SAXException if the file cannot be read */ @NotNull - private ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final String name) throws ParserConfigurationException { + private ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final String name) throws IOException, ParsingException, SAXException { final ArchetypeTypeSetParser parser = createArchetypeTypeSetParser(); final InputStream typesXml = getClass().getResourceAsStream("ArchetypeTypeSetParserTest-" + name + "-types.xml"); System.out.println("ArchetypeTypeSetParserTest-" + name + "-types.xml"); Assert.assertNotNull(typesXml); - final InputSource inputSource = new InputSource(typesXml); - inputSource.setSystemId("types.dtd"); - - return parser.loadTypesFromXML(errorViewCollector, inputSource); + return parser.loadTypesFromXML(errorViewCollector, ParseUtils.readXmlStream(typesXml, "types", "types.dtd", "/system/dtd/types.dtd", null)); } /** * Creates a new {@link ArchetypeTypeSetParser} instance. * @return the archetype type set parser instance - * @throws ParserConfigurationException if the parser cannot be created */ @NotNull - private static ArchetypeTypeSetParser createArchetypeTypeSetParser() throws ParserConfigurationException { - final XmlHelper xmlHelper = new XmlHelper(); + private static ArchetypeTypeSetParser createArchetypeTypeSetParser() { final ArchetypeAttributeFactory archetypeAttributeFactory = new TestArchetypeAttributeFactory(); final ArchetypeAttributeParser archetypeAttributeParser = new ArchetypeAttributeParser(archetypeAttributeFactory); final ArchetypeTypeParser archetypeTypeParser = new ArchetypeTypeParser(archetypeAttributeParser); - return new ArchetypeTypeSetParser(xmlHelper.getDocumentBuilder(), archetypeTypeParser); + return new ArchetypeTypeSetParser(archetypeTypeParser); } } Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java =================================================================== --- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:17:01 UTC (rev 9679) +++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:18:53 UTC (rev 9680) @@ -119,7 +119,6 @@ import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** @@ -274,15 +273,15 @@ try { final URL url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), CommonConstants.TYPEDEF_FILE); final ErrorViewCollector typesErrorViewCollector = new ErrorViewCollector(errorView, url); - xmlHelper.getDocumentBuilder().setErrorHandler(new ErrorViewCollectorErrorHandler(typesErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID)); - try { - final ArchetypeTypeSetParser archetypeTypeSetParser = new ArchetypeTypeSetParser(xmlHelper.getDocumentBuilder(), archetypeTypeParser); - return archetypeTypeSetParser.loadTypesFromXML(typesErrorViewCollector, new InputSource(url.toString())); - } finally { - xmlHelper.getDocumentBuilder().setErrorHandler(null); - } - } catch (final FileNotFoundException ex) { + final Document document = ParseUtils.readXmlUrl(url, "types", "types.dtd", "/system/dtd/types.dtd", new ErrorViewCollectorErrorHandler(typesErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID)); + final ArchetypeTypeSetParser archetypeTypeSetParser = new ArchetypeTypeSetParser(archetypeTypeParser); + return archetypeTypeSetParser.loadTypesFromXML(typesErrorViewCollector, document); + } catch (final IOException ex) { errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage()); + } catch (final ParsingException ex) { + errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage()); + } catch (final SAXException ex) { + errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage()); } return new ArchetypeTypeSet(); } Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java =================================================================== --- trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java 2014-03-08 22:17:01 UTC (rev 9679) +++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java 2014-03-08 22:18:53 UTC (rev 9680) @@ -19,9 +19,10 @@ package net.sf.gridarta.utils; -import net.sf.japi.xml.NodeListIterator; +import nu.xom.Element; +import nu.xom.Elements; import org.jetbrains.annotations.NotNull; -import org.w3c.dom.Element; +import org.jetbrains.annotations.Nullable; /** * XML related utility functions. @@ -44,11 +45,23 @@ */ @NotNull public static Element getChild(@NotNull final Element parentElement, @NotNull final String childName) { - final Element element = NodeListIterator.getFirstChild(parentElement, childName); - if (element == null) { + final Elements elements = parentElement.getChildElements(childName); + if (elements.size() == 0) { throw new IllegalArgumentException("child element '" + childName + "' does not exist"); } - return element; + return elements.get(0); } + /** + * Returns a child {@link Element} of a parent element. + * @param parentElement the parent element + * @param childName the name of the child element + * @return the child element or {@code null} + */ + @Nullable + public static Element getChildOptional(@NotNull final Element parentElement, @NotNull final String childName) { + final Elements elements = parentElement.getChildElements(childName); + return elements.size() == 0 ? null : elements.get(0); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-08 22:40:18
|
Revision: 9681 http://sourceforge.net/p/gridarta/code/9681 Author: akirschbaum Date: 2014-03-08 22:40:13 +0000 (Sat, 08 Mar 2014) Log Message: ----------- Rewrite parser for spells.xml. Modified Paths: -------------- trunk/src/model/src/main/java/net/sf/gridarta/model/spells/XMLSpellLoader.java trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java Removed Paths: ------------- trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/spells/XMLSpellLoader.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/spells/XMLSpellLoader.java 2014-03-08 22:18:53 UTC (rev 9680) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/spells/XMLSpellLoader.java 2014-03-08 22:40:13 UTC (rev 9681) @@ -19,20 +19,14 @@ package net.sf.gridarta.model.spells; -import java.io.IOException; -import java.net.URL; -import java.util.Iterator; -import javax.xml.parsers.DocumentBuilder; import net.sf.gridarta.model.errorview.ErrorViewCategory; import net.sf.gridarta.model.errorview.ErrorViewCollector; -import net.sf.japi.xml.NodeListIterator; +import net.sf.gridarta.utils.xml.ElementsIterable; +import nu.xom.Document; +import nu.xom.Element; import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; /** * Load spell definitions from an XML file. @@ -55,49 +49,38 @@ /** * Load an XML spell definitions file. * @param errorViewCollector the error view collector for reporting errors - * @param url the URL of the spell definitions file - * @param documentBuilder the Document Builder to use for parsing + * @param document the document of the spell definitions file * @param spells the {@code Spells} instance to add the spells to */ - public static void load(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final URL url, @NotNull final DocumentBuilder documentBuilder, @NotNull final Spells<NumberSpell> spells) { - try { - final Document doc = documentBuilder.parse(new InputSource(url.toString())); - - // retrieve the spell data from the xml - final Element root = doc.getDocumentElement(); - if (root == null || !"spells".equalsIgnoreCase(root.getNodeName())) { - errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "root element 'spells' is missing"); - } else { - // initialize array with appropriate size - int numSpells = 0; - final Iterator<Element> it = new NodeListIterator<Element>(root, "spell"); - while (it.hasNext()) { - final Element spellElem = it.next(); - if (spellElem.getAttribute("id") == null) { - errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "found 'spell' element without 'id'"); - } else if (spellElem.getAttribute("name") == null) { - errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "found 'spell' element without 'name'"); - } else { - try { - // parse spell number and -name - spells.add(new NumberSpell(spellElem.getAttribute("name").trim(), Integer.parseInt(spellElem.getAttribute("id")))); - numSpells++; - } catch (final NumberFormatException ignored) { - errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "parsing error: spell id '" + spellElem.getAttribute("id") + "' is not an integer."); - } + public static void load(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final Document document, @NotNull final Spells<NumberSpell> spells) { + // retrieve the spell data from the xml + final Element root = document.getRootElement(); + if (root == null || !root.getLocalName().equals("spells")) { + errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "root element 'spells' is missing"); + } else { + // initialize array with appropriate size + int numSpells = 0; + for (final Element spellElem : new ElementsIterable(root.getChildElements("spell"))) { + if (spellElem.getAttribute("id") == null) { + errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "found 'spell' element without 'id'"); + } else if (spellElem.getAttribute("name") == null) { + errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "found 'spell' element without 'name'"); + } else { + try { + // parse spell number and -name + spells.add(new NumberSpell(spellElem.getAttribute("name").getValue().trim(), Integer.parseInt(spellElem.getAttribute("id").getValue()))); + numSpells++; + } catch (final NumberFormatException ignored) { + errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "parsing error: spell id '" + spellElem.getAttribute("id") + "' is not an integer."); } } + } - // loading successful - LOG.info("Loaded " + numSpells + " defined spells from '" + url + "'"); - if (numSpells == 0) { - errorViewCollector.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, "no content"); - } + // loading successful + LOG.info("Loaded " + numSpells + " defined spells."); + if (numSpells == 0) { + errorViewCollector.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, "no content"); } - } catch (final SAXException ex) { - errorViewCollector.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, "parsing error:" + ex.getMessage()); - } catch (final IOException ex) { - errorViewCollector.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, ex.getMessage()); } } Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java =================================================================== --- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:18:53 UTC (rev 9680) +++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:40:13 UTC (rev 9681) @@ -25,9 +25,6 @@ import java.net.URL; import java.util.Collections; import java.util.Map; -import java.util.MissingResourceException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.ParserConfigurationException; import net.sf.gridarta.model.anim.AnimationObjects; import net.sf.gridarta.model.anim.DefaultAnimationObjects; import net.sf.gridarta.model.archetype.Archetype; @@ -109,7 +106,6 @@ import net.sf.gridarta.utils.IOUtils; import net.sf.gridarta.utils.ResourceIcons; import net.sf.gridarta.utils.StringUtils; -import net.sf.gridarta.utils.XmlHelper; import net.sf.gridarta.utils.xml.ParseUtils; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; @@ -209,16 +205,7 @@ public ProjectModel(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings, @NotNull final ProjectFactory<G, A, R> projectFactory, @NotNull final ResourceIcons resourceIcons, @NotNull final ConfigSource configSource) { this.projectSettings = projectSettings; - final XmlHelper xmlHelper; - try { - xmlHelper = new XmlHelper(); - } catch (final ParserConfigurationException ex) { - LOG.fatal("Cannot create XML parser: " + ex.getMessage()); - //noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException - throw new MissingResourceException("Cannot create XML parser: " + ex.getMessage(), null, null); - } - - archetypeTypeSet = loadArchetypeTypeSet(errorView, projectSettings, xmlHelper); + archetypeTypeSet = loadArchetypeTypeSet(errorView, projectSettings); final int doubleFaceOffset = projectFactory.getDoubleFaceOffset(); faceObjects = new DefaultFaceObjects(projectFactory.getIncludeFaceNumbers()); smoothFaces = new SmoothFaces(faceObjects); @@ -255,7 +242,7 @@ mapManager = new DefaultMapManager<G, A, R>(mapReaderFactory, mapControlFactory, projectSettings, faceObjectProviders, pathManager); pickmapManager = new DefaultPickmapManager<G, A, R>(mapReaderFactory, mapControlFactory, projectSettings, faceObjectProviders, pathManager); gameObjectSpells = loadArchetypeSpells(projectFactory.getSpellType(), gameObjectFactory, archetypeSet); - numberSpells = loadSpellFile(projectFactory.getSpellFile(), errorView, projectSettings, xmlHelper); + numberSpells = loadSpellFile(projectFactory.getSpellFile(), errorView, projectSettings); scriptsFile = new File(projectSettings.getMapsDirectory(), projectFactory.getScriptsDir()); final Map<String, TreasureTreeNode> specialTreasureLists = loadSpecialTreasureLists(errorView, projectSettings); treasureTree = TreasureLoader.parseTreasures(errorView, specialTreasureLists, configSource, projectSettings); @@ -266,7 +253,7 @@ } @NotNull - private static ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings, @NotNull final XmlHelper xmlHelper) { + private static ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings) { final ArchetypeAttributeFactory archetypeAttributeFactory = new DefaultArchetypeAttributeFactory(); final ArchetypeAttributeParser archetypeAttributeParser = new ArchetypeAttributeParser(archetypeAttributeFactory); final ArchetypeTypeParser archetypeTypeParser = new ArchetypeTypeParser(archetypeAttributeParser); @@ -411,7 +398,7 @@ } @NotNull - public static Spells<NumberSpell> loadSpellFile(@Nullable final String spellFile, @NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings, @NotNull final XmlHelper xmlHelper) { + public static Spells<NumberSpell> loadSpellFile(@Nullable final String spellFile, @NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings) { @NotNull final Spells<NumberSpell> numberSpells = new Spells<NumberSpell>(); if (spellFile == null) { return numberSpells; @@ -420,15 +407,14 @@ try { final URL url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), spellFile); final ErrorViewCollector errorViewCollector = new ErrorViewCollector(errorView, url); - final DocumentBuilder documentBuilder = xmlHelper.getDocumentBuilder(); - documentBuilder.setErrorHandler(new ErrorViewCollectorErrorHandler(errorViewCollector, ErrorViewCategory.SPELLS_FILE_INVALID)); - try { - XMLSpellLoader.load(errorViewCollector, url, documentBuilder, numberSpells); - } finally { - documentBuilder.setErrorHandler(null); - } - } catch (final FileNotFoundException ex) { + final Document document = ParseUtils.readXmlUrl(url, "spells", "spells.dtd", "/system/dtd/spells.dtd", new ErrorViewCollectorErrorHandler(errorViewCollector, ErrorViewCategory.SPELLS_FILE_INVALID)); + XMLSpellLoader.load(errorViewCollector, document, numberSpells); + } catch (final IOException ex) { errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage()); + } catch (final ParsingException ex) { + errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage()); + } catch (final SAXException ex) { + errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage()); } numberSpells.sort(); return numberSpells; Deleted: trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java =================================================================== --- trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java 2014-03-08 22:18:53 UTC (rev 9680) +++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java 2014-03-08 22:40:13 UTC (rev 9681) @@ -1,114 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2010 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.utils; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.regex.Pattern; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; - -/** - * Little helper class for XML that holds a {@link DocumentBuilder} that is - * setup for Gridarta. - * @author Andreas Kirschbaum - */ -public class XmlHelper { - - /** - * The {@link Pattern} for matching the directory part of a system ID. - */ - @NotNull - private static final Pattern PATTERN_DIRECTORY_PART = Pattern.compile(".*/"); - - /** - * DocumentBuilder. - */ - private final DocumentBuilder documentBuilder; - - /** - * Initialize the XML engine. - * @throws ParserConfigurationException in case the xml parser couldn't be - * set up - */ - public XmlHelper() throws ParserConfigurationException { - // TODO: Change hard coded document builder factory to user configurable settings - final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setCoalescing(true); - // dbf.setExpandEntityReferences(true); // true is default on this - dbf.setIgnoringComments(true); - dbf.setIgnoringElementContentWhitespace(true); - dbf.setNamespaceAware(true); - dbf.setValidating(true); - dbf.setXIncludeAware(true); - documentBuilder = dbf.newDocumentBuilder(); - documentBuilder.setEntityResolver(new GridartaEntityResolver()); - } - - /** - * Return the DocumentBuilder. - * @return the document builder - */ - public DocumentBuilder getDocumentBuilder() { - return documentBuilder; - } - - /** - * Implements an {@link EntityResolver} for looking up built-in .dtd files. - */ - private static class GridartaEntityResolver implements EntityResolver { - - @Nullable - @Override - public InputSource resolveEntity(final String publicId, final String systemId) throws IOException { - if (systemId.endsWith(".xml")) { - return null; - } - - InputSource inputSource = null; - final URL url = IOUtils.getResource(new File("system/dtd"), PATTERN_DIRECTORY_PART.matcher(systemId).replaceAll("")); - final InputStream inputStream = url.openStream(); - try { - final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); - try { - inputSource = new InputSource(bufferedInputStream); - } finally { - if (inputSource == null) { - bufferedInputStream.close(); - } - } - } finally { - if (inputSource == null) { - inputStream.close(); - } - } - return inputSource; - } - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-09 01:26:58
|
Revision: 9683 http://sourceforge.net/p/gridarta/code/9683 Author: akirschbaum Date: 2014-03-09 01:26:51 +0000 (Sun, 09 Mar 2014) Log Message: ----------- Fix parser for types.xml. [Atrinik, Daimonin] Modified Paths: -------------- trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java Modified: trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java =================================================================== --- trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java 2014-03-08 22:49:36 UTC (rev 9682) +++ trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java 2014-03-09 01:26:51 UTC (rev 9683) @@ -23,6 +23,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -32,6 +34,7 @@ import net.sf.gridarta.model.errorview.TestErrorView; import net.sf.gridarta.utils.xml.ParseUtils; import nu.xom.ParsingException; +import nu.xom.xinclude.XIncludeException; import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Test; @@ -60,9 +63,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void test1() throws IOException, ParsingException, SAXException { + public void test1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { check("test1"); } @@ -71,9 +76,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testImport1() throws IOException, ParsingException, SAXException { + public void testImport1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { check("import1"); } @@ -82,9 +89,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testImport2() throws IOException, ParsingException, SAXException { + public void testImport2() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { check("import2"); } @@ -93,9 +102,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testIgnoreDefaultAttribute1() throws IOException, ParsingException, SAXException { + public void testIgnoreDefaultAttribute1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { check("ignoreDefaultAttribute1"); } @@ -104,9 +115,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testIgnoreImportAttribute1() throws IOException, ParsingException, SAXException { + public void testIgnoreImportAttribute1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { check("ignoreImportAttribute1"); } @@ -115,9 +128,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testIgnoreDefinedAttribute1() throws IOException, ParsingException, SAXException { + public void testIgnoreDefinedAttribute1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { check("ignoreDefinedAttribute1"); } @@ -126,9 +141,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testMsgDefault1() throws IOException, ParsingException, SAXException { + public void testMsgDefault1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { check("msgDefault1"); } @@ -137,9 +154,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testMsgDefault2() throws IOException, ParsingException, SAXException { + public void testMsgDefault2() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { check("msgDefault2"); } @@ -148,9 +167,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testMsgDefault3() throws IOException, ParsingException, SAXException { + public void testMsgDefault3() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { check("msgDefault3"); } @@ -160,9 +181,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testArchetypeOrder1() throws IOException, ParsingException, SAXException { + public void testArchetypeOrder1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder1"); Assert.assertFalse(errorView.hasErrors()); final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); @@ -175,9 +198,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testArchetypeOrder2() throws IOException, ParsingException, SAXException { + public void testArchetypeOrder2() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder2"); Assert.assertFalse(errorView.hasErrors()); final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); @@ -191,9 +216,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testArchetypeOrder3() throws IOException, ParsingException, SAXException { + public void testArchetypeOrder3() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder3"); Assert.assertFalse(errorView.hasErrors()); final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); @@ -207,9 +234,11 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ @Test - public void testArchetypeOrder4() throws IOException, ParsingException, SAXException { + public void testArchetypeOrder4() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder4"); Assert.assertFalse(errorView.hasErrors()); final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); @@ -223,8 +252,10 @@ * @throws IOException if the test fails * @throws ParsingException if the test fails * @throws SAXException if the test fails + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the test fails */ - private void check(@NotNull final String name) throws IOException, ParsingException, SAXException { + private void check(@NotNull final String name) throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { final ArchetypeTypeSet archetypeTypeSet = loadArchetypeTypeSet(name); final InputStream is = getClass().getResourceAsStream("ArchetypeTypeSetParserTest-" + name + "-result.txt"); Assert.assertNotNull(is); @@ -248,15 +279,17 @@ * @throws IOException if the file cannot be read * @throws ParsingException if the file cannot be read * @throws SAXException if the file cannot be read + * @throws URISyntaxException if the test fails + * @throws XIncludeException if the file cannot be read */ @NotNull - private ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final String name) throws IOException, ParsingException, SAXException { + private ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final String name) throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { final ArchetypeTypeSetParser parser = createArchetypeTypeSetParser(); - final InputStream typesXml = getClass().getResourceAsStream("ArchetypeTypeSetParserTest-" + name + "-types.xml"); + final URL typesXml = getClass().getResource("ArchetypeTypeSetParserTest-" + name + "-types.xml"); System.out.println("ArchetypeTypeSetParserTest-" + name + "-types.xml"); Assert.assertNotNull(typesXml); - return parser.loadTypesFromXML(errorViewCollector, ParseUtils.readXmlStream(typesXml, "types", "types.dtd", "/system/dtd/types.dtd", null)); + return parser.loadTypesFromXML(errorViewCollector, ParseUtils.readXmlUrl(typesXml, "types", "types.dtd", "/system/dtd/types.dtd", null)); } /** Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java =================================================================== --- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:49:36 UTC (rev 9682) +++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-09 01:26:51 UTC (rev 9683) @@ -22,6 +22,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.URISyntaxException; import java.net.URL; import java.util.Collections; import java.util.Map; @@ -111,6 +112,7 @@ import net.sf.japi.swing.action.ActionBuilderFactory; import nu.xom.Document; import nu.xom.ParsingException; +import nu.xom.xinclude.XIncludeException; import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -269,6 +271,10 @@ errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage()); } catch (final SAXException ex) { errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage()); + } catch (final URISyntaxException ex) { + errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage()); + } catch (final XIncludeException ex) { + errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage()); } return new ArchetypeTypeSet(); } @@ -319,6 +325,10 @@ gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage()); } catch (final SAXException ex) { gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage()); + } catch (final URISyntaxException ex) { + gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage()); + } catch (final XIncludeException ex) { + gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage()); } return gameObjectMatchers; } @@ -415,6 +425,10 @@ errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage()); } catch (final SAXException ex) { errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage()); + } catch (final URISyntaxException ex) { + errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage()); + } catch (final XIncludeException ex) { + errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage()); } numberSpells.sort(); return numberSpells; @@ -438,6 +452,12 @@ } catch (final SAXException ex) { treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage()); specialTreasureLists = Collections.emptyMap(); + } catch (final URISyntaxException ex) { + treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage()); + specialTreasureLists = Collections.emptyMap(); + } catch (final XIncludeException ex) { + treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage()); + specialTreasureLists = Collections.emptyMap(); } } catch (final FileNotFoundException ex) { errorView.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, "TreasureLists.xml: " + ex.getMessage()); Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java =================================================================== --- trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java 2014-03-08 22:49:36 UTC (rev 9682) +++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java 2014-03-09 01:26:51 UTC (rev 9683) @@ -21,11 +21,14 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.net.URL; import nu.xom.Builder; import nu.xom.DocType; import nu.xom.Document; import nu.xom.ParsingException; +import nu.xom.xinclude.XIncludeException; +import nu.xom.xinclude.XIncluder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.xml.sax.ErrorHandler; @@ -58,12 +61,14 @@ * @throws IOException if the XML file cannot be read * @throws ParsingException if parsing the XML file fails * @throws SAXException the parsing the XML file fails + * @throws URISyntaxException if an include cannot be resolved + * @throws XIncludeException if parsing of the XML file fails */ @NotNull - public static Document readXmlUrl(@NotNull final URL url, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler) throws IOException, ParsingException, SAXException { + public static Document readXmlUrl(@NotNull final URL url, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler) throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException { final InputStream inputStream = url.openStream(); try { - return readXmlStream(inputStream, rootElement, systemId, resourceName, errorHandler); + return readXmlStream(inputStream, url.toURI().toASCIIString(), rootElement, systemId, resourceName, errorHandler); } finally { inputStream.close(); } @@ -72,6 +77,7 @@ /** * Reads an XML file. * @param inputStream the XML file to read + * @param baseURI the base URI for resolving includes * @param rootElement the tag name of the root element in the DOCTYPE * declaration * @param systemId the system ID of the doctype declaration @@ -82,9 +88,10 @@ * @throws IOException if the XML file cannot be read * @throws ParsingException if parsing the XML file fails * @throws SAXException the parsing the XML file fails + * @throws XIncludeException if parsing of the XML file fails */ @NotNull - public static Document readXmlStream(@NotNull final InputStream inputStream, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler) throws IOException, ParsingException, SAXException { + public static Document readXmlStream(@NotNull final InputStream inputStream, @NotNull final String baseURI, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler) throws IOException, ParsingException, SAXException, XIncludeException { final XMLReader xmlReader = XMLReaderFactory.createXMLReader(); xmlReader.setEntityResolver(new FixedDtdEntityResolver(systemId, resourceName)); if (errorHandler != null) { @@ -94,7 +101,7 @@ final Document document; final InputStream in2 = new FixedDtdInputStream(inputStream, rootElement, systemId); try { - document = builder.build(in2); + document = builder.build(in2, baseURI); } finally { in2.close(); } @@ -114,6 +121,7 @@ if (!documentRootElement.equals(rootElement)) { throw new ParsingException("root element in DOCTYPE declaration is '" + documentRootElement + "'; expecting '" + rootElement + "'"); } + XIncluder.resolveInPlace(document, builder); return document; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-09 01:33:19
|
Revision: 9684 http://sourceforge.net/p/gridarta/code/9684 Author: akirschbaum Date: 2014-03-09 01:33:12 +0000 (Sun, 09 Mar 2014) Log Message: ----------- Inline function. Modified Paths: -------------- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2014-03-09 01:26:51 UTC (rev 9683) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2014-03-09 01:33:12 UTC (rev 9684) @@ -25,11 +25,10 @@ import net.sf.gridarta.model.errorview.ErrorViewCategory; import net.sf.gridarta.model.errorview.ErrorViewCollector; import net.sf.gridarta.utils.StringUtils; -import net.sf.gridarta.utils.XmlUtils; import net.sf.gridarta.utils.xml.ElementsIterable; import nu.xom.Attribute; import nu.xom.Element; -import nu.xom.Node; +import nu.xom.Elements; import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -369,8 +368,9 @@ private static ArchetypeAttributesDefinition parseTypeAttributes(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition) { final ArchetypeAttributesDefinition typeAttributes = parseRequiredAttribute(typeElement, typeName, errorViewCollector); - final Element ignoreElement = XmlUtils.getChildOptional(typeElement, Constants.XML_ELEMENT_IGNORE); - if (ignoreElement != null) { + final Elements ignoreElements = typeElement.getChildElements(Constants.XML_ELEMENT_IGNORE); + if (ignoreElements.size() > 0) { + final Element ignoreElement = ignoreElements.get(0); parseAttributeAttributes(ignoreElement, typeName, errorViewCollector, ignoreTable); parseIgnoreListAttribute(ignoreElement, typeName, errorViewCollector, ignoreTable, ignorelistsDefinition); } @@ -388,9 +388,9 @@ @NotNull private static ArchetypeAttributesDefinition parseRequiredAttribute(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) { final ArchetypeAttributesDefinition attributes = new ArchetypeAttributesDefinition(); - final Element requiredElement = XmlUtils.getChildOptional(typeElement, Constants.XML_ELEMENT_REQUIRED); - if (requiredElement != null) { - for (final Element attributeElement : new ElementsIterable(requiredElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) { + final Elements requiredElements = typeElement.getChildElements(Constants.XML_ELEMENT_REQUIRED); + if (requiredElements.size() > 0) { + for (final Element attributeElement : new ElementsIterable(requiredElements.get(0).getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) { final Attribute archAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_ARCH); if (archAttribute == null) { errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_REQUIRED + ": element of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_ARCH + "'."); @@ -480,8 +480,8 @@ */ @Nullable private static String parseDescription(@NotNull final Element root) { - final Node elem = XmlUtils.getChildOptional(root, Constants.XML_DESCRIPTION); - return elem == null ? null : elem.getValue().trim(); + final Elements elements = root.getChildElements(Constants.XML_DESCRIPTION); + return elements.size() == 0 ? null : elements.get(0).getValue().trim(); } /** @@ -491,8 +491,8 @@ */ @Nullable private static String parseUse(@NotNull final Element root) { - final Node elem = XmlUtils.getChildOptional(root, Constants.XML_USE); - return elem == null ? null : elem.getValue().trim(); + final Elements elements = root.getChildElements(Constants.XML_USE); + return elements.size() == 0 ? null : elements.get(0).getValue().trim(); } /** Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java 2014-03-09 01:26:51 UTC (rev 9683) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java 2014-03-09 01:33:12 UTC (rev 9684) @@ -28,6 +28,7 @@ import nu.xom.Attribute; import nu.xom.Document; import nu.xom.Element; +import nu.xom.Elements; import nu.xom.Node; import org.apache.log4j.Category; import org.apache.log4j.Logger; @@ -75,7 +76,8 @@ parseBitmasks(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_BITMASKS), errorViewCollector); parseLists(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_LISTS), errorViewCollector); final IgnorelistsDefinition ignorelistsDefinition = parseIgnoreLists(XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_IGNORELISTS), errorViewCollector); - parseAttributeOrder(archetypeTypeSet, XmlUtils.getChildOptional(rootElement, Constants.XML_ELEMENT_ATTRIBUTE_ORDER), errorViewCollector); + final Elements attributeOrderElements = rootElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE_ORDER); + parseAttributeOrder(archetypeTypeSet, attributeOrderElements.size() == 0 ? null : attributeOrderElements.get(0), errorViewCollector); final ArchetypeType defaultArchetypeType = parseDefaultType(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_DEFAULT_TYPE), errorViewCollector, ignorelistsDefinition); for (final Element element : new ElementsIterable(rootElement.getChildElements(Constants.XML_ELEMENT_TYPE))) { Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java =================================================================== --- trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java 2014-03-09 01:26:51 UTC (rev 9683) +++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java 2014-03-09 01:33:12 UTC (rev 9684) @@ -22,7 +22,6 @@ import nu.xom.Element; import nu.xom.Elements; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * XML related utility functions. @@ -52,16 +51,4 @@ return elements.get(0); } - /** - * Returns a child {@link Element} of a parent element. - * @param parentElement the parent element - * @param childName the name of the child element - * @return the child element or {@code null} - */ - @Nullable - public static Element getChildOptional(@NotNull final Element parentElement, @NotNull final String childName) { - final Elements elements = parentElement.getChildElements(childName); - return elements.size() == 0 ? null : elements.get(0); - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-09 10:48:57
|
Revision: 9686 http://sourceforge.net/p/gridarta/code/9686 Author: akirschbaum Date: 2014-03-09 10:48:51 +0000 (Sun, 09 Mar 2014) Log Message: ----------- Rewrite parser for editor plugins. Modified Paths: -------------- trunk/src/model/src/main/java/net/sf/gridarta/model/filter/FilterParser.java trunk/src/plugin/build.gradle trunk/src/plugin/plugin.iml trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModel.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModelLoader.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModelParser.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/filter/FilterParser.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/filter/FilterParser.java 2014-03-09 01:37:47 UTC (rev 9685) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/filter/FilterParser.java 2014-03-09 10:48:51 UTC (rev 9686) @@ -20,8 +20,11 @@ package net.sf.gridarta.model.filter; import java.util.Map.Entry; -import org.jdom.Content; -import org.jdom.Element; +import net.sf.gridarta.utils.XmlUtils; +import net.sf.gridarta.utils.xml.ElementsIterable; +import nu.xom.Element; +import nu.xom.Elements; +import nu.xom.ParentNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,21 +52,21 @@ public void visit(@NotNull final NamedFilterConfig filterConfig) { final Element result = new Element("value"); final Element enabled = new Element("enabled"); - enabled.addContent(Boolean.toString(filterConfig.isEnabled())); - result.addContent(enabled); + enabled.appendChild(Boolean.toString(filterConfig.isEnabled())); + result.appendChild(enabled); final Element inverted = new Element("inverted"); - inverted.addContent(Boolean.toString(filterConfig.isInverted())); - result.addContent(inverted); + inverted.appendChild(Boolean.toString(filterConfig.isInverted())); + result.appendChild(inverted); for (final Entry<String, FilterConfig<?, ?>> entry : filterConfig.getEntries().entrySet()) { final String key = entry.getKey(); final FilterConfig<?, ?> subFilterConfig = entry.getValue(); - final Content filterValue = toXML(subFilterConfig); - final Element subFilter = new Element("subfilter"); + final Element filterValue = toXML(subFilterConfig); + final ParentNode subFilter = new Element("subfilter"); final Element fName = new Element("name"); - fName.addContent(key); - subFilter.addContent(fName); - subFilter.addContent(filterValue); - result.addContent(subFilter); + fName.appendChild(key); + subFilter.appendChild(fName); + subFilter.appendChild(filterValue); + result.appendChild(subFilter); } element = result; } @@ -72,12 +75,12 @@ public void visit(@NotNull final NamedGameObjectMatcherFilterConfig filterConfig) { final Element value = new Element("value"); final Element enabled = new Element("enabled"); - enabled.addContent(Boolean.toString(filterConfig.isEnabled())); - value.addContent(enabled); + enabled.appendChild(Boolean.toString(filterConfig.isEnabled())); + value.appendChild(enabled); for (final String key : filterConfig.getProperties()) { final Element property = new Element("property"); - property.addContent(filterConfig.getProperty(key)); - value.addContent(property); + property.appendChild(filterConfig.getProperty(key)); + value.appendChild(property); } element = value; } @@ -98,19 +101,17 @@ return; } - final Element value = element.getChild("value"); - if (value == null) { + final Elements valueElements = element.getChildElements("value"); + if (valueElements.size() == 0) { return; } + final Element value = valueElements.get(0); - final boolean enabled = Boolean.valueOf(value.getChildTextTrim("enabled")); + final boolean enabled = Boolean.valueOf(XmlUtils.getChild(value, "enabled").getValue().trim()); filterConfig.setEnabled(enabled); - filterConfig.setInverted(Boolean.valueOf(value.getChildTextTrim("inverted"))); - //Element does not use type parameters - @SuppressWarnings("unchecked") - final Iterable<Element> it = (Iterable<Element>) value.getChildren("subfilter"); - for (final Element filterElement : it) { - final String name = filterElement.getChildTextTrim("name"); + filterConfig.setInverted(Boolean.valueOf(XmlUtils.getChild(value, "inverted").getValue().trim())); + for (final Element filterElement : new ElementsIterable(value.getChildElements("subfilter"))) { + final String name = XmlUtils.getChild(filterElement, "name").getValue().trim(); final FilterConfig<?, ?> subFilterConfig = filterConfig.getConfig(name); fromXML(filterElement, subFilterConfig); } @@ -122,19 +123,17 @@ return; } - final Element value = element.getChild("value"); - if (value == null) { + final Elements valueElements = element.getChildElements("value"); + if (valueElements.size() == 0) { return; } + final Element value = valueElements.get(0); - final boolean enabled = Boolean.valueOf(value.getChildTextTrim("enabled")); + final boolean enabled = Boolean.valueOf(XmlUtils.getChild(value, "enabled").getValue().trim()); filterConfig.setEnabled(enabled); - //Element does not use type parameters - @SuppressWarnings("unchecked") - final Iterable<Element> properties = (Iterable<Element>) value.getChildren("property"); - for (final Element property : properties) { - final String pName = property.getChildTextTrim("name"); - final String pValue = property.getChildTextTrim("value"); + for (final Element property : new ElementsIterable(value.getChildElements("property"))) { + final String pName = XmlUtils.getChild(property, "name").getValue().trim(); + final String pValue = XmlUtils.getChild(property, "value").getValue().trim(); filterConfig.setProperty(pName, pValue); } } @@ -147,7 +146,7 @@ * @return the exported settings */ @NotNull - public Content toXML(@NotNull final FilterConfig<?, ?> filterConfig) { + public Element toXML(@NotNull final FilterConfig<?, ?> filterConfig) { final Element prevElement = element; try { element = null; Modified: trunk/src/plugin/build.gradle =================================================================== --- trunk/src/plugin/build.gradle 2014-03-09 01:37:47 UTC (rev 9685) +++ trunk/src/plugin/build.gradle 2014-03-09 10:48:51 UTC (rev 9686) @@ -7,6 +7,7 @@ compile name: 'bsh-core', version: '2.0b4', group: 'bsh' compile name: 'bsh-util', version: '2.0b4', group: 'bsh' compile name: 'log4j', version: '1.2.13' + compile name: 'xom', version: '1.2.10' compile project(':src:model') testCompile name: 'junit', version: '4.2' testCompile project(':src:model').sourceSets.test.output Modified: trunk/src/plugin/plugin.iml =================================================================== --- trunk/src/plugin/plugin.iml 2014-03-09 01:37:47 UTC (rev 9685) +++ trunk/src/plugin/plugin.iml 2014-03-09 10:48:51 UTC (rev 9686) @@ -19,6 +19,7 @@ <orderEntry type="library" name="jdom" level="project" /> <orderEntry type="library" name="junit" level="project" /> <orderEntry type="library" name="log4j" level="project" /> + <orderEntry type="library" name="xom" level="project" /> </component> </module> Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java 2014-03-09 01:37:47 UTC (rev 9685) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/Plugin.java 2014-03-09 10:48:51 UTC (rev 9686) @@ -37,10 +37,9 @@ import net.sf.gridarta.plugin.parameter.PluginParameterListener; import net.sf.gridarta.plugin.parameter.StringParameter; import net.sf.gridarta.utils.EventListenerList2; +import nu.xom.Element; import org.apache.log4j.Category; import org.apache.log4j.Logger; -import org.jdom.Content; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -476,7 +475,7 @@ * @return the plugin parameter in XML representation */ @NotNull - public Content toXML(@NotNull final PluginParameter<G, A, R, ?> pluginParameter) { + public Element toXML(@NotNull final PluginParameter<G, A, R, ?> pluginParameter) { return codec.toXML(pluginParameter); } Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModel.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModel.java 2014-03-09 01:37:47 UTC (rev 9685) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModel.java 2014-03-09 10:48:51 UTC (rev 9686) @@ -31,15 +31,15 @@ import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.plugin.parameter.PluginParameterFactory; import net.sf.gridarta.utils.EventListenerList2; +import nu.xom.Document; +import nu.xom.Element; +import nu.xom.ParsingException; +import nu.xom.Serializer; import org.apache.log4j.Category; import org.apache.log4j.Logger; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.xml.sax.SAXException; /** * @author tchize @@ -116,8 +116,10 @@ addPlugin(PluginModelLoader.loadXML(pluginModelParser, file)); } catch (final IOException ex) { LOG.warn("can't load plugin: " + ex.getMessage()); - } catch (final JDOMException ex) { + } catch (final ParsingException ex) { LOG.warn("can't parse plugin: " + ex.getMessage()); + } catch (final SAXException ex) { + LOG.warn("can't parse plugin: " + ex.getMessage()); } } @@ -142,9 +144,9 @@ try { final Element root = pluginModelParser.toXML(plugin); final Document d = new Document(root); - final XMLOutputter out = new XMLOutputter(); - out.setFormat(Format.getPrettyFormat()); - out.output(d, fos); + final Serializer serializer = new Serializer(fos, "UTF-8"); + serializer.setIndent(2); + serializer.write(d); } finally { fos.close(); } Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModelLoader.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModelLoader.java 2014-03-09 01:37:47 UTC (rev 9685) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModelLoader.java 2014-03-09 10:48:51 UTC (rev 9686) @@ -27,14 +27,17 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.plugin.parameter.PluginParameterFactory; +import nu.xom.Builder; +import nu.xom.Document; +import nu.xom.Element; +import nu.xom.ParsingException; import org.apache.log4j.Category; import org.apache.log4j.Logger; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.input.SAXBuilder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; /** * Utility class for loading plugins. @@ -86,8 +89,10 @@ } } catch (final IOException ex) { errorView.addWarning(ErrorViewCategory.SCRIPTS_FILE_INVALID, pluginFile + ": " + ex.getMessage()); - } catch (final JDOMException ex) { + } catch (final ParsingException ex) { errorView.addWarning(ErrorViewCategory.SCRIPTS_FILE_INVALID, pluginFile + ": " + ex.getMessage()); + } catch (final SAXException ex) { + errorView.addWarning(ErrorViewCategory.SCRIPTS_FILE_INVALID, pluginFile + ": " + ex.getMessage()); } } } @@ -97,20 +102,20 @@ return pluginModel; } - public static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> Plugin<G, A, R> loadXML(@NotNull final PluginModelParser<G, A, R> pluginModelParser, @NotNull final File file) throws IOException, JDOMException { - final SAXBuilder builder = new SAXBuilder(false); /*non validating*/ + public static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> Plugin<G, A, R> loadXML(@NotNull final PluginModelParser<G, A, R> pluginModelParser, @NotNull final File file) throws IOException, ParsingException, SAXException { + final XMLReader xmlReader = XMLReaderFactory.createXMLReader(); + final Builder builder = new Builder(xmlReader, false); final Document d = builder.build(file); return loadXML(pluginModelParser, d, file); } @NotNull private static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> Plugin<G, A, R> loadXML(@NotNull final PluginModelParser<G, A, R> pluginModelParser, @NotNull final Document doc, @Nullable final File file) throws IOException { - if (!doc.hasRootElement()) { + final Element elt = doc.getRootElement(); + if (elt == null) { throw new IOException("plugin file is empty"); } - - final Element elt = doc.getRootElement(); - if (!elt.getName().equalsIgnoreCase("script")) { + if (!elt.getLocalName().equalsIgnoreCase("script")) { throw new IOException("missing root element named \"script\""); } Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModelParser.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModelParser.java 2014-03-09 01:37:47 UTC (rev 9685) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/PluginModelParser.java 2014-03-09 10:48:51 UTC (rev 9686) @@ -19,18 +19,21 @@ package net.sf.gridarta.plugin; -import java.util.Collection; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.plugin.parameter.NoSuchParameterException; import net.sf.gridarta.plugin.parameter.PluginParameter; import net.sf.gridarta.plugin.parameter.PluginParameterFactory; +import net.sf.gridarta.utils.XmlUtils; +import net.sf.gridarta.utils.xml.ElementsIterable; +import nu.xom.Attribute; +import nu.xom.Element; +import nu.xom.Elements; +import nu.xom.ParentNode; +import nu.xom.Text; import org.apache.log4j.Category; import org.apache.log4j.Logger; -import org.jdom.CDATA; -import org.jdom.Element; -import org.jdom.IllegalDataException; import org.jetbrains.annotations.NotNull; /** @@ -85,26 +88,23 @@ */ @NotNull public Plugin<G, A, R> fromXML(@NotNull final Element node) { - final Plugin<G, A, R> pluginModel = new Plugin<G, A, R>(node.getChildTextTrim("name"), pluginParameterFactory); - pluginModel.setCode(node.getChildTextTrim("code")); + final Plugin<G, A, R> pluginModel = new Plugin<G, A, R>(XmlUtils.getChild(node, "name").getValue().trim(), pluginParameterFactory); + pluginModel.setCode(XmlUtils.getChild(node, "code").getValue().trim()); boolean isAutoBoot = false; boolean isFilter = false; boolean isScript = false; - final Element mode = node.getChild("mode"); - if (mode == null) { + final Elements modeElements = node.getChildElements("mode"); + if (modeElements.size() == 0) { isScript = true; } else { - //Element does not use type parameters - @SuppressWarnings("unchecked") - final Iterable<Element> modes = mode.getChildren(); - for (final Element modeChild : modes) { - final boolean value = Boolean.valueOf(modeChild.getTextTrim()); - final String name = modeChild.getName(); - if (AUTO_BOOT.equalsIgnoreCase(name) && value) { + for (final Element modeChild : new ElementsIterable(modeElements.get(0).getChildElements())) { + final boolean value = Boolean.valueOf(modeChild.getValue()); + final String name = modeChild.getLocalName(); + if (name.equalsIgnoreCase(AUTO_BOOT) && value) { isAutoBoot = true; - } else if (FILTER.equalsIgnoreCase(name) && value) { + } else if (name.equalsIgnoreCase(FILTER) && value) { isFilter = true; - } else if (BASH.equalsIgnoreCase(name) && value) { + } else if (name.equalsIgnoreCase(BASH) && value) { isScript = true; } } @@ -112,20 +112,15 @@ pluginModel.setAutoBoot(isAutoBoot); pluginModel.setFilter(isFilter); pluginModel.setScript(isScript); - //Element does not use type parameters - @SuppressWarnings("unchecked") - final Collection<Element> parameters = node.getChildren("parameter"); - if (parameters != null && !parameters.isEmpty()) { - for (final Element parameter : parameters) { - PluginParameter<G, A, R, ?> pluginParameter; - try { - pluginParameter = pluginParameterFactory.createParameter(parameter); - } catch (final NoSuchParameterException ex) { - LOG.warn("Parameter type " + ex.getMessage() + " in plugin " + pluginModel + " is unknown"); - pluginParameter = pluginParameterFactory.createStringParameter(parameter); - } - pluginModel.addParameter(pluginParameter); + for (final Element parameter : new ElementsIterable(node.getChildElements("parameter"))) { + PluginParameter<G, A, R, ?> pluginParameter; + try { + pluginParameter = pluginParameterFactory.createParameter(parameter); + } catch (final NoSuchParameterException ex) { + LOG.warn("Parameter type " + ex.getMessage() + " in plugin " + pluginModel + " is unknown"); + pluginParameter = pluginParameterFactory.createStringParameter(parameter); } + pluginModel.addParameter(pluginParameter); } pluginModel.resetModified(); return pluginModel; @@ -141,30 +136,26 @@ final Element root = new Element("script"); final Element name = new Element("name"); final Element code = new Element("code"); - name.addContent(plugin.getName()); - try { - code.addContent(new CDATA(plugin.getCode())); // protect code in xml! - } catch (final IllegalDataException ignored) { - //can't be converted to CDATA :( - code.addContent(plugin.getCode()); - } - root.addContent(name); - root.addContent(code); - final Element modes = new Element("mode"); + name.appendChild(plugin.getName()); + code.appendChild(new Text(plugin.getCode())); + code.addAttribute(new Attribute("xml:space", "http://www.w3.org/XML/1998/namespace", "preserve")); + root.appendChild(name); + root.appendChild(code); + final ParentNode modes = new Element("mode"); final Element autoBoot = new Element(AUTO_BOOT); - autoBoot.addContent(Boolean.toString(plugin.isAutoBoot())); + autoBoot.appendChild(Boolean.toString(plugin.isAutoBoot())); final Element bash = new Element(BASH); - bash.addContent(Boolean.toString(plugin.isScript())); + bash.appendChild(Boolean.toString(plugin.isScript())); final Element filter = new Element(FILTER); - filter.addContent(Boolean.toString(plugin.isFilter())); - modes.addContent(autoBoot); - modes.addContent(bash); - modes.addContent(filter); + filter.appendChild(Boolean.toString(plugin.isFilter())); + modes.appendChild(autoBoot); + modes.appendChild(bash); + modes.appendChild(filter); - root.addContent(modes); + root.appendChild(modes); for (final PluginParameter<G, A, R, ?> pluginParameter : plugin) { - root.addContent(plugin.toXML(pluginParameter)); + root.appendChild(plugin.toXML(pluginParameter)); } return root; } Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java 2014-03-09 01:37:47 UTC (rev 9685) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java 2014-03-09 10:48:51 UTC (rev 9686) @@ -22,7 +22,8 @@ import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; -import org.jdom.Element; +import net.sf.gridarta.utils.XmlUtils; +import nu.xom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,12 +51,12 @@ final Element n = new Element("name"); final Element d = new Element("description"); final Element t = new Element("type"); - n.addContent(parameter.getName()); - d.addContent(parameter.getDescription()); - t.addContent(parameter.getParameterType()); - e.addContent(n); - e.addContent(d); - e.addContent(t); + n.appendChild(parameter.getName()); + d.appendChild(parameter.getDescription()); + t.appendChild(parameter.getParameterType()); + e.appendChild(n); + e.appendChild(d); + e.appendChild(t); return e; } @@ -64,8 +65,8 @@ public Element visit(@NotNull final ArchetypeParameter<G, A, R> parameter) { final Element e = toXML(parameter); final Element v = new Element("value"); - v.addContent(parameter.getStringValue()); - e.addContent(v); + v.appendChild(parameter.getStringValue()); + e.appendChild(v); return e; } @@ -74,14 +75,14 @@ public Element visit(@NotNull final BooleanParameter<G, A, R> parameter) { final Element e = toXML(parameter); final Element v = new Element("value"); - v.addContent(parameter.getStringValue()); - e.addContent(v); + v.appendChild(parameter.getStringValue()); + e.appendChild(v); final Element yes = new Element("trueText"); - yes.addContent(parameter.getTrueText()); + yes.appendChild(parameter.getTrueText()); final Element no = new Element("falseText"); - no.addContent(parameter.getFalseText()); - e.addContent(yes); - e.addContent(no); + no.appendChild(parameter.getFalseText()); + e.appendChild(yes); + e.appendChild(no); return e; } @@ -90,14 +91,14 @@ public Element visit(@NotNull final DoubleParameter<G, A, R> parameter) { final Element e = toXML(parameter); final Element v = new Element("value"); - v.addContent(parameter.getStringValue()); - e.addContent(v); + v.appendChild(parameter.getStringValue()); + e.appendChild(v); final Element min = new Element("minimum"); final Element max = new Element("maximum"); - min.addContent(Double.toString(parameter.getMin())); - max.addContent(Double.toString(parameter.getMax())); - e.addContent(min); - e.addContent(max); + min.appendChild(Double.toString(parameter.getMin())); + max.appendChild(Double.toString(parameter.getMax())); + e.appendChild(min); + e.appendChild(max); return e; } @@ -106,14 +107,14 @@ public Element visit(@NotNull final IntegerParameter<G, A, R> parameter) { final Element e = toXML(parameter); final Element v = new Element("value"); - v.addContent(parameter.getStringValue()); - e.addContent(v); + v.appendChild(parameter.getStringValue()); + e.appendChild(v); final Element min = new Element("minimum"); final Element max = new Element("maximum"); - min.addContent(Integer.toString(parameter.getMin())); - max.addContent(Integer.toString(parameter.getMax())); - e.addContent(min); - e.addContent(max); + min.appendChild(Integer.toString(parameter.getMin())); + max.appendChild(Integer.toString(parameter.getMax())); + e.appendChild(min); + e.appendChild(max); return e; } @@ -122,8 +123,8 @@ public Element visit(@NotNull final MapParameter<G, A, R> parameter) { final Element e = toXML(parameter); final Element v = new Element("value"); - v.addContent(parameter.isCurrentMap() ? "" : parameter.getStringValue()); - e.addContent(v); + v.appendChild(parameter.isCurrentMap() ? "" : parameter.getStringValue()); + e.appendChild(v); return e; } @@ -132,8 +133,8 @@ public Element visit(@NotNull final MapPathParameter<G, A, R> parameter) { final Element e = toXML(parameter); final Element s = new Element("value"); - s.addContent(parameter.getStringValue()); - e.addContent(s); + s.appendChild(parameter.getStringValue()); + e.appendChild(s); return e; } @@ -142,8 +143,8 @@ public Element visit(@NotNull final StringParameter<G, A, R> parameter) { final Element e = toXML(parameter); final Element s = new Element("value"); - s.addContent(parameter.getStringValue()); - e.addContent(s); + s.appendChild(parameter.getStringValue()); + e.appendChild(s); return e; } @@ -211,7 +212,7 @@ parameter.setMax(Integer.parseInt(getChildText("maximum", Integer.toString(Integer.MAX_VALUE)))); } catch (final NumberFormatException ignored) { } - parameter.setStringValue(e.getChildTextTrim("value")); + parameter.setStringValue(XmlUtils.getChild(e, "value").getValue().trim()); return parameter; } @@ -277,7 +278,7 @@ @NotNull private String getChildText(@NotNull final String key, @NotNull final String defaultValue) { assert e != null; - final String value = e.getChildTextTrim(key); + final String value = XmlUtils.getChild(e, key).getValue().trim(); return value == null ? defaultValue : value; } Modified: trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java =================================================================== --- trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2014-03-09 01:37:47 UTC (rev 9685) +++ trunk/src/plugin/src/main/java/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2014-03-09 10:48:51 UTC (rev 9686) @@ -26,7 +26,8 @@ import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapmanager.MapManager; import net.sf.gridarta.model.settings.ProjectSettings; -import org.jdom.Element; +import net.sf.gridarta.utils.XmlUtils; +import nu.xom.Element; import org.jetbrains.annotations.NotNull; /** @@ -70,7 +71,7 @@ @NotNull public PluginParameter<G, A, R, ?> createParameter(@NotNull final Element parameterNode) throws NoSuchParameterException { - return createParameter(parameterNode.getChildText("type"), parameterNode); + return createParameter(XmlUtils.getChild(parameterNode, "type").getValue(), parameterNode); } /** Modified: trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java =================================================================== --- trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java 2014-03-09 01:37:47 UTC (rev 9685) +++ trunk/src/plugin/src/test/java/net/sf/gridarta/plugin/parameter/PluginParameterCodecTest.java 2014-03-09 10:48:51 UTC (rev 9686) @@ -19,11 +19,10 @@ package net.sf.gridarta.plugin.parameter; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; import net.sf.gridarta.model.archetype.TestArchetype; import net.sf.gridarta.model.gameobject.TestGameObject; import net.sf.gridarta.model.io.PathManager; @@ -35,16 +34,18 @@ import net.sf.gridarta.model.settings.ProjectSettings; import net.sf.gridarta.model.settings.TestProjectSettings; import net.sf.gridarta.utils.Size2D; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.input.SAXBuilder; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; +import nu.xom.Builder; +import nu.xom.Document; +import nu.xom.Element; +import nu.xom.ParsingException; +import nu.xom.Serializer; import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; /** * Regression tests for {@link PluginParameterCodec}. @@ -66,9 +67,8 @@ sb.append(" <name>[name]</name>\r\n"); sb.append(" <description>[description]</description>\r\n"); sb.append(" <type>net.sf.gridarta.model.archetype.Archetype</type>\r\n"); - sb.append(" <value />\r\n"); + sb.append(" <value/>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -89,7 +89,6 @@ sb.append(" <type>net.sf.gridarta.model.archetype.Archetype</type>\r\n"); sb.append(" <value>undefined_archetype</value>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -111,7 +110,6 @@ sb.append(" <type>net.sf.gridarta.model.archetype.Archetype</type>\r\n"); sb.append(" <value>existing_archetype</value>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -134,7 +132,6 @@ sb.append(" <trueText>Yes</trueText>\r\n"); sb.append(" <falseText>No</falseText>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -158,7 +155,6 @@ sb.append(" <trueText>true-text</trueText>\r\n"); sb.append(" <falseText>false-text</falseText>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -181,7 +177,6 @@ sb.append(" <minimum>0.0</minimum>\r\n"); sb.append(" <maximum>1.0</maximum>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -205,7 +200,6 @@ sb.append(" <minimum>-123.456</minimum>\r\n"); sb.append(" <maximum>234.0</maximum>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -228,7 +222,6 @@ sb.append(" <minimum>-2147483648</minimum>\r\n"); sb.append(" <maximum>2147483647</maximum>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -252,7 +245,6 @@ sb.append(" <minimum>-123</minimum>\r\n"); sb.append(" <maximum>234</maximum>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -272,9 +264,8 @@ sb.append(" <name>Name</name>\r\n"); sb.append(" <description>Description</description>\r\n"); sb.append(" <type>net.sf.gridarta.model.mapcontrol.MapControl</type>\r\n"); - sb.append(" <value />\r\n"); + sb.append(" <value/>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -293,9 +284,8 @@ sb.append(" <name>[name]</name>\r\n"); sb.append(" <description>[description]</description>\r\n"); sb.append(" <type>net.sf.gridarta.model.mapcontrol.MapControl</type>\r\n"); - sb.append(" <value />\r\n"); + sb.append(" <value/>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -319,7 +309,6 @@ sb.append(" <type>net.sf.gridarta.model.mapcontrol.MapControl</type>\r\n"); sb.append(" <value>/path/to/map</value>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -340,9 +329,8 @@ sb.append(" <name>Name</name>\r\n"); sb.append(" <description>Description</description>\r\n"); sb.append(" <type>MapPathParameter</type>\r\n"); - sb.append(" <value />\r\n"); + sb.append(" <value/>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -364,7 +352,6 @@ sb.append(" <type>MapPathParameter</type>\r\n"); sb.append(" <value>/path</value>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -383,9 +370,8 @@ sb.append(" <name>Name</name>\r\n"); sb.append(" <description>Description</description>\r\n"); sb.append(" <type>java.lang.String</type>\r\n"); - sb.append(" <value />\r\n"); + sb.append(" <value/>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } @@ -405,18 +391,18 @@ sb.append(" <type>java.lang.String</type>\r\n"); sb.append(" <value>string value</value>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); Assert.assertEquals(sb.toString(), toXML(parameter)); } /** * Checks that a {@link ArchetypeParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testArchetypeFromXml1() throws IOException, JDOMException, NoSuchParameterException { + public void testArchetypeFromXml1() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); @@ -425,7 +411,6 @@ sb.append(" <type>net.sf.gridarta.model.archetype.Archetype</type>\r\n"); sb.append(" <value/>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = fromXML(mapControlCreator, sb.toString()); Assert.assertTrue(parameter instanceof ArchetypeParameter); @@ -439,11 +424,12 @@ /** * Checks that an {@link ArchetypeParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testArchetypeFromXml2() throws IOException, JDOMException, NoSuchParameterException { + public void testArchetypeFromXml2() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); @@ -452,7 +438,6 @@ sb.append(" <type>net.sf.gridarta.model.archetype.Archetype</type>\r\n"); sb.append(" <value>undefined_archetype</value>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = fromXML(mapControlCreator, sb.toString()); Assert.assertTrue(parameter instanceof ArchetypeParameter); @@ -466,11 +451,12 @@ /** * Checks that an {@link ArchetypeParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testArchetypeFromXml3() throws IOException, JDOMException, NoSuchParameterException { + public void testArchetypeFromXml3() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); @@ -479,7 +465,6 @@ sb.append(" <type>net.sf.gridarta.model.archetype.Archetype</type>\r\n"); sb.append(" <value>existing_archetype</value>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final TestArchetype archetype = mapControlCreator.getMapModelCreator().getArchetype("existing_archetype"); final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = fromXML(mapControlCreator, sb.toString()); @@ -494,22 +479,22 @@ /** * Checks that a {@link BooleanParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testBooleanFromXml1() throws IOException, JDOMException, NoSuchParameterException { + public void testBooleanFromXml1() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); sb.append(" <name>Name</name>\r\n"); sb.append(" <description>Description</description>\r\n"); sb.append(" <type>java.lang.Boolean</type>\r\n"); - sb.append(" <value />\r\n"); + sb.append(" <value/>\r\n"); sb.append(" <trueText>Yes</trueText>\r\n"); sb.append(" <falseText>No</falseText>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = fromXML(mapControlCreator, sb.toString()); Assert.assertTrue(parameter instanceof BooleanParameter); @@ -525,11 +510,12 @@ /** * Checks that a {@link BooleanParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testBooleanFromXml2() throws IOException, JDOMException, NoSuchParameterException { + public void testBooleanFromXml2() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); @@ -540,7 +526,6 @@ sb.append(" <trueText>true-text</trueText>\r\n"); sb.append(" <falseText>false-text</falseText>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = fromXML(mapControlCreator, sb.toString()); Assert.assertTrue(parameter instanceof BooleanParameter); @@ -556,22 +541,22 @@ /** * Checks that a {@link DoubleParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testDoubleFromXml1() throws IOException, JDOMException, NoSuchParameterException { + public void testDoubleFromXml1() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); sb.append(" <name>Name</name>\r\n"); sb.append(" <description>Description</description>\r\n"); sb.append(" <type>java.lang.Double</type>\r\n"); - sb.append(" <value />\r\n"); + sb.append(" <value/>\r\n"); sb.append(" <minimum>0.0</minimum>\r\n"); sb.append(" <maximum>1.0</maximum>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = fromXML(mapControlCreator, sb.toString()); Assert.assertTrue(parameter instanceof DoubleParameter); @@ -587,11 +572,12 @@ /** * Checks that a {@link DoubleParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testDoubleFromXml2() throws IOException, JDOMException, NoSuchParameterException { + public void testDoubleFromXml2() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); @@ -602,7 +588,6 @@ sb.append(" <minimum>-123.456</minimum>\r\n"); sb.append(" <maximum>234.0</maximum>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = fromXML(mapControlCreator, sb.toString()); Assert.assertTrue(parameter instanceof DoubleParameter); @@ -618,22 +603,22 @@ /** * Checks that an {@link IntegerParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testIntegerFromXml1() throws IOException, JDOMException, NoSuchParameterException { + public void testIntegerFromXml1() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); sb.append(" <name>Name</name>\r\n"); sb.append(" <description>Description</description>\r\n"); sb.append(" <type>java.lang.Integer</type>\r\n"); - sb.append(" <value />\r\n"); + sb.append(" <value/>\r\n"); sb.append(" <minimum>-2147483648</minimum>\r\n"); sb.append(" <maximum>2147483647</maximum>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = fromXML(mapControlCreator, sb.toString()); Assert.assertTrue(parameter instanceof IntegerParameter); @@ -649,11 +634,12 @@ /** * Checks that an {@link IntegerParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testIntegerFromXml2() throws IOException, JDOMException, NoSuchParameterException { + public void testIntegerFromXml2() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); @@ -664,7 +650,6 @@ sb.append(" <minimum>-123</minimum>\r\n"); sb.append(" <maximum>234</maximum>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = fromXML(mapControlCreator, sb.toString()); Assert.assertTrue(parameter instanceof IntegerParameter); @@ -680,20 +665,20 @@ /** * Checks that a {@link MapParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Test - public void testMapFromXml1() throws IOException, JDOMException, NoSuchParameterException { + public void testMapFromXml1() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); sb.append(" <name>Name</name>\r\n"); sb.append(" <description>Description</description>\r\n"); sb.append(" <type>net.sf.gridarta.model.mapcontrol.MapControl</type>\r\n"); - sb.append(" <value />\r\n"); + sb.append(" <value/>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter = fromXML(mapControlCreator, sb.toString()); Assert.assertTrue(parameter instanceof MapParameter); @@ -707,12 +692,13 @@ /** * Checks that a {@link MapParameter} is correctly decoded. * @throws IOException if the test fails - * @throws JDOMException if the test fails * @throws NoSuchParameterException if the test fails + * @throws ParsingException if the test fails + * @throws SAXException if the test fails */ @Ignore @Test - public void testMapFromXml3() throws IOException, JDOMException, NoSuchParameterException { + public void testMapFromXml3() throws IOException, NoSuchParameterException, ParsingException, SAXException { final StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); sb.append("<parameter>\r\n"); @@ -721,7 +707,6 @@ sb.append(" <type>net.sf.gridarta.model.mapcontrol.MapControl</type>\r\n"); sb.append(" <value>/path/to/map</value>\r\n"); sb.append("</parameter>\r\n"); - sb.append("\r\n"); final TestMapControlCreator mapControlCreator = new TestMapControlCreator(); final File mapDir = new File("/tmp"); mapControlCreator.getMapManager().newMap(null, new TestMapArchObject(), mapControlCreator.getPathManager().getMapFile(new File(mapDir, "path/to/map")), false); @@ -743,19 +728,17 @@ * Encodes a {@link PluginParameter} to its string representation. * @param parameter the plugin parameter * @return the string representation - * @throws IOException if encoding fails + * @throws IOException if the conversion fails */ @NotNull private static String toXML(@NotNull final PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> parameter) throws IOException { final PluginParameterCodec<TestGameObject, TestMapArchObject, TestArchetype> codec = new PluginParameterCodec<TestGameObject, TestMapArchObject, TestArchetype>(); final Element element = codec.toXML(parameter); - final Document d = new Document(element); - final XMLOutputter out = new XMLOutputter(); - out.setFormat(Format.getPrettyFormat()); - final Writer writer = new StringWriter(); - out.output(d, writer); - //noinspection ObjectToString - return writer.toString(); + final ByteArrayOutputStream stream = new ByteArrayOutputStream(); + final Serializer serializer = new Serializer(stream, "UTF-8"); + serializer.setIndent(2); + serializer.write(new Document(element)); + return new String(stream.toByteArray(), "UTF-8"); } /** @@ -764,12 +747,14 @@ * @param string the string representation * @return the plugin parameter * @throws IOException if decoding fails - * @throws JDOMException if decoding fails * @throws NoSuchParameterException if decoding fails + * @throws ParsingException if decoding fails + * @throws SAXException if decoding fails */ @NotNull - private static PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> fromXML(@NotNull final TestMapControlCreator mapControlCreator, @NotNull final String string) throws IOException, JDOMException, NoSuchParameterException { - final SAXBuilder builder = new SAXBuilder(false); + private static PluginParameter<TestGameObject, TestMapArchObject, TestArchetype, ?> fromXML(@NotNull final TestMapControlCreator mapControlCreator, @NotNull final String string) throws IOException, NoSuchParameterException, ParsingException, SAXException { + final XMLReader xmlReader = XMLReaderFactory.createXMLReader(); + final Builder builder = new Builder(xmlReader, false); final Document document = builder.build(new StringReader(string)); final PluginParameterFactory<TestGameObject, TestMapArchObject, TestArchetype> parameterFactory = new PluginParameterFactory<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getArchetypeSet(), mapControlCreator.getMapManager(), mapControlCreator.getProjectSettings(), mapControlCreator.getPathManager()); final Element element = document.getRootElement(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-09 13:21:14
|
Revision: 9689 http://sourceforge.net/p/gridarta/code/9689 Author: akirschbaum Date: 2014-03-09 13:21:10 +0000 (Sun, 09 Mar 2014) Log Message: ----------- Remove outdated files. Removed Paths: ------------- trunk/src/atrinik/INSTALL.txt trunk/src/atrinik/README.txt trunk/src/crossfire/INSTALL.txt trunk/src/crossfire/manifest.txt trunk/src/daimonin/INSTALL.txt trunk/src/daimonin/README.txt Deleted: trunk/src/atrinik/INSTALL.txt =================================================================== --- trunk/src/atrinik/INSTALL.txt 2014-03-09 11:28:03 UTC (rev 9688) +++ trunk/src/atrinik/INSTALL.txt 2014-03-09 13:21:10 UTC (rev 9689) @@ -1,63 +0,0 @@ -How to run the DaimoninEditor: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Simply run the jar file "AtrinikEditor.jar" in the main directory. -In Windows this is done by a double click on "AtrinikEditor.jar". -In Linux/Unix you type in the console: "java -jar AtrinikEditor.jar". - -The java runtime will be enough to run the client. Download it automatically -from sun. This will install the latest runtime using your browser. - -NOTE: you need Java 6.0 (=1.6.0) or newer to run the editor. - -** There is no need to install anything else (SDK, ...) except you want ** -** compile the editor ** - -You can download the java RUNTIME here: -http://java.sun.com/webapps/getjava/BrowserRedirect?locale=en&host=www.java.com:80 -or this -http://java.com - -If you edit many and big maps, it is recommended to run the editor -with a higher maximum memory size, like 128 Mb: -"java -jar -Xmx128m AtrinikEditor.jar" -(Note that in this way, the editor won't *always* use 128 Mb. -It will only use that much when it is required.) -For client users that edit normal maps (24x24 size) the default settings (which -is equal to -Xmx64m) is enough. - - -In case there is no jar file available, that means you will need -to compile the editor from the sources first. Read next paragraph. - - -How to build the AtrinikEditor from sources: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -If you have checked out the AtrinikEditor sources from SVN, or -downloaded a "developer version", then you've got the Java sources. -Now you can modify the Java code, you can add classes, but please -don't move or rename any directories. - -When you find yourself in the position that you want to compile -the Java sources for the editor, you have mainly these options: - -1. Compile using Apache Ant. -2. Compile & Debug using Intellij IDEA. -3. Compile using one of the OS-specific build scripts. - (There is no guarantee any of these works correctly.) - (Keep in mind that the sources are UTF-8) -4. Compile "by hand" via command line. - (Do not forget to add -encoding utf-8 for the Java compiler) - -I strongly recommend using Ant for compile and IDEA for coding & compile. - -I strongly recommend the supplied buildfile and running Ant directly, either -through your IDE's capabilities or the command line. - -Visit <http://ant.apache.org/> for more information about Ant. - - -System requirements & Supported Java Versions: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -You need at least 96 MB of system RAM and 400 MHz CPU speed -in order to run the AtrinikEditor. It has been reported to work -on systems with lesser specs, but the speed was very slow. Deleted: trunk/src/atrinik/README.txt =================================================================== --- trunk/src/atrinik/README.txt 2014-03-09 11:28:03 UTC (rev 9688) +++ trunk/src/atrinik/README.txt 2014-03-09 13:21:10 UTC (rev 9689) @@ -1,91 +0,0 @@ -Building the Daimonin Editor with Ant -===================================== - -To build with Ant, there are 3 possible ways: -* Stay in the main directory (daimonin/editor), use - ant -f make/ant/build.xml - for building -* Change to the ant directory, use ant for building - ( cd make/ant ; ant ) -* Create a new build.xml with the following content: -<?xml version="1.0" encoding="UTF-8"?> -<project name="DaimoninEditor Private" default="jar"> - <import file="make/ant/build.xml" /> -</project> - -The third way probably is the preferred way by vi / vim users, because the -build.xml is searched in current file upwards path, not sub-directories. - - -developer.properties --------------------- - -You can modify the build process to fit your personal needs. For this, create -a file named "developer.properties" in this directory. -The following can be changed (properties' names): -* debug mode compilation (debug) -* ctags tags creation (user.ctags) -* ftp upload of DaimoninEditor.jar (user.ftp.host, user.ftp.user, - user.ftp.pass, user.ftp.dir, user.ftp.depends, user.ftp.passive, - user.ftp.ignoreNoncriticalErrors) - -The following properties are supported (place them as name-value-pairs in -daimonin/editor/build.properties, like user.ctags=yes) -* debug - Developers sometimes want debug builds. A debug build contains all symbols - needed for debugging a Java application (private symbol names, line - numbers). But also, a debug build is 25% larger. - Value: yes|no - Default: no -* user.ctags - ctags is a program that scans source codes for symbols and generates symbol - tables. It is used by users of editors like vim or emacs for tag table - initialization. The tags can then be used to navigate from a symbol usage - to its declaration. - Value: yes|no - Default: no -* user.ftp.host - DaimoninEditor.jar FTP Upload Host. - Value: valid host name or ip address - Default: no default value -* user.ftp.user - DaimoninEditor.jar FTP Upload Login username. - Value: valid ftp username - Default: no default value -* user.ftp.pass - DaimoninEditor.jar FTP Upload Login password - Value: valid ftp password - Default: no default value -* user.ftp.dir - DaimoninEditor.jar FTP Upload Remote Directory - Value: valid remote directory - Default: no default value -* user.ftp.depends - DaimoninEditor.jar FTP Upload Only if file has changed - Value: yes|no - Default: yes -* user.ftp.passive - DaimoninEditor.jar FTP Upload use passive FTP - Value: yes|no - Default: yes -* user.ftp.ignoreNoncriticalErrors - DaimoninEditor.jar FTP Upload ignore non-critical errors - Value: yes|no - Default: yes -* build.number - Build number, will be automatically created and increased by Ant -* build.developer - If you plan to release your DaimoninEditor.jar, you definitely should set this. - The build number will only be shown in the about dialog if you also set - the property build.developer. - Theoretically, creating a unique build.number would be possible via CVS, but - the delay in CVS usage is too long. To keep build numbers unique, they are - only published if they also denote the build developer. - -Example user.properties file: -user.ctags=yes -debug=yes -user.ftp.host=www.example.com -user.ftp.user=cheristheus1234 -user.ftp.pass=12345678 -user.ftp.dir=daimonin Deleted: trunk/src/crossfire/INSTALL.txt =================================================================== --- trunk/src/crossfire/INSTALL.txt 2014-03-09 11:28:03 UTC (rev 9688) +++ trunk/src/crossfire/INSTALL.txt 2014-03-09 13:21:10 UTC (rev 9689) @@ -1,73 +0,0 @@ -How to run the editor: -^^^^^^^^^^^^^^^^^^^^^ -Simply run the jar file "CrossfireEditor.jar" in the main directory. -In Windows this is done by a double-click on "CrossfireEditor.jar". -In Linux/Unix you type in the console: "java -jar CrossfireEditor.jar". - -If you have enough memory, it is recommended to run the editor -with a higher maximum memory size, like 128 Mb: -"java -jar -Xmx128m CrossfireEditor.jar" -(Note that in this way, the editor won't *always* use 128 Mb. -It will only use that much when it is required.) - - -In case there is no jar file available, that means you will need -to compile the editor from the sources first. Read next paragraph. - - -How to build the CrossfireEditor from sources: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -If you have checked out the Gridarta sources from SVN, or -downloaded a "developer version", then you've got the Java sources. -Now you can modify the Java code, you can add classes, but please -don't move or rename any directories. - -When you find yourself in the position that you want to compile the -Java sources for the editor, you need Apache Ant. Visit -<http://ant.apache.org/> for more information about Ant. - - -Compiling the sources: -^^^^^^^^^^^^^^^^^^^^^ -Install Ant on your system. Make sure both the JAVA_HOME -and ANT_HOME environment variables are set correctly. - -Change into the crossfire sub-directory or the Gridarta directory. -On the console type "ant" - that's all. - - -(Note that, if you want, you can also run the editor with -ant by typing "ant run". This does exactly the same as -"java -jar CrossfireEditor.jar".) - - -How to create a CrossfireEditor release package: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -A "release" version is meant to be a complete running version of -the CrossfireEditor, without sources. A binary so to speak, though for -Java the most suitable thing is a jar file. -The jar file will contain everything except pickmaps, hence a -release package should only contain these two things: -Jar file and pickmaps. - -1. Run Ant to create the jar file "CrossfireEditor.jar" (see above). - -2. Assemble jar file and pickmaps in the following directory tree: - - crossfire/ - resource/ - pickmaps/ - [all pickmap files] - CrossfireEditor.jar - ChangeLog - -3. Zip the package in a widely available compression format. - Preferably use tar.gz as this is available both on Unix/Linux - and windows (winzip). - - -System requirements & Supported Java Versions: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -You need at least 128 MB of system RAM and 400 MHz CPU speed -in order to run the editor. It has been reported to work -on systems with lesser specs, but the speed was very slow. Deleted: trunk/src/crossfire/manifest.txt =================================================================== --- trunk/src/crossfire/manifest.txt 2014-03-09 11:28:03 UTC (rev 9688) +++ trunk/src/crossfire/manifest.txt 2014-03-09 13:21:10 UTC (rev 9689) @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Created-By: build_win script -Main-Class: net.sf.gridarta.var.crossfire.maincontrol.CrossfireEditor Deleted: trunk/src/daimonin/INSTALL.txt =================================================================== --- trunk/src/daimonin/INSTALL.txt 2014-03-09 11:28:03 UTC (rev 9688) +++ trunk/src/daimonin/INSTALL.txt 2014-03-09 13:21:10 UTC (rev 9689) @@ -1,63 +0,0 @@ -How to run the DaimoninEditor: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Simply run the jar file "DaimoninEditor.jar" in the main directory. -In Windows this is done by a double click on "DaimoninEditor.jar". -In Linux/Unix you type in the console: "java -jar DaimoninEditor.jar". - -The java runtime will be enough to run the client. Download it automatically -from sun. This will install the latest runtime using your browser. - -NOTE: you need Java 6.0 (=1.6.0) or newer to run the editor. - -** There is no need to install anything else (SDK, ...) except you want ** -** compile the editor ** - -You can download the java RUNTIME here: -http://java.sun.com/webapps/getjava/BrowserRedirect?locale=en&host=www.java.com:80 -or this -http://java.com - -If you edit many and big maps, it is recommended to run the editor -with a higher maximum memory size, like 128 Mb: -"java -jar -Xmx128m DaimoninEditor.jar" -(Note that in this way, the editor won't *always* use 128 Mb. -It will only use that much when it is required.) -For client users that edit normal maps (24x24 size) the default settings (which -is equal to -Xmx64m) is enough. - - -In case there is no jar file available, that means you will need -to compile the editor from the sources first. Read next paragraph. - - -How to build the DaimoninEditor from sources: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -If you have checked out the DaimoninEditor sources from SVN, or -downloaded a "developer version", then you've got the Java sources. -Now you can modify the Java code, you can add classes, but please -don't move or rename any directories. - -When you find yourself in the position that you want to compile -the Java sources for the editor, you have mainly these options: - -1. Compile using Apache Ant. -2. Compile & Debug using Intellij IDEA. -3. Compile using one of the OS-specific build scripts. - (There is no guarantee any of these works correctly.) - (Keep in mind that the sources are UTF-8) -4. Compile "by hand" via command line. - (Do not forget to add -encoding utf-8 for the Java compiler) - -I strongly recommend using Ant for compile and IDEA for coding & compile. - -I strongly recommend the supplied buildfile and running Ant directly, either -through your IDE's capabilities or the command line. - -Visit <http://ant.apache.org/> for more information about Ant. - - -System requirements & Supported Java Versions: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -You need at least 96 MB of system RAM and 400 MHz CPU speed -in order to run the DaimoninEditor. It has been reported to work -on systems with lesser specs, but the speed was very slow. Deleted: trunk/src/daimonin/README.txt =================================================================== --- trunk/src/daimonin/README.txt 2014-03-09 11:28:03 UTC (rev 9688) +++ trunk/src/daimonin/README.txt 2014-03-09 13:21:10 UTC (rev 9689) @@ -1,91 +0,0 @@ -Building the Daimonin Editor with Ant -===================================== - -To build with Ant, there are 3 possible ways: -* Stay in the main directory (daimonin/editor), use - ant -f make/ant/build.xml - for building -* Change to the ant directory, use ant for building - ( cd make/ant ; ant ) -* Create a new build.xml with the following content: -<?xml version="1.0" encoding="UTF-8"?> -<project name="DaimoninEditor Private" default="jar"> - <import file="make/ant/build.xml" /> -</project> - -The third way probably is the preferred way by vi / vim users, because the -build.xml is searched in current file upwards path, not sub-directories. - - -developer.properties --------------------- - -You can modify the build process to fit your personal needs. For this, create -a file named "developer.properties" in this directory. -The following can be changed (properties' names): -* debug mode compilation (debug) -* ctags tags creation (user.ctags) -* ftp upload of DaimoninEditor.jar (user.ftp.host, user.ftp.user, - user.ftp.pass, user.ftp.dir, user.ftp.depends, user.ftp.passive, - user.ftp.ignoreNoncriticalErrors) - -The following properties are supported (place them as name-value-pairs in -daimonin/editor/build.properties, like user.ctags=yes) -* debug - Developers sometimes want debug builds. A debug build contains all symbols - needed for debugging a Java application (private symbol names, line - numbers). But also, a debug build is 25% larger. - Value: yes|no - Default: no -* user.ctags - ctags is a program that scans source codes for symbols and generates symbol - tables. It is used by users of editors like vim or emacs for tag table - initialization. The tags can then be used to navigate from a symbol usage - to its declaration. - Value: yes|no - Default: no -* user.ftp.host - DaimoninEditor.jar FTP Upload Host. - Value: valid host name or ip address - Default: no default value -* user.ftp.user - DaimoninEditor.jar FTP Upload Login username. - Value: valid ftp username - Default: no default value -* user.ftp.pass - DaimoninEditor.jar FTP Upload Login password - Value: valid ftp password - Default: no default value -* user.ftp.dir - DaimoninEditor.jar FTP Upload Remote Directory - Value: valid remote directory - Default: no default value -* user.ftp.depends - DaimoninEditor.jar FTP Upload Only if file has changed - Value: yes|no - Default: yes -* user.ftp.passive - DaimoninEditor.jar FTP Upload use passive FTP - Value: yes|no - Default: yes -* user.ftp.ignoreNoncriticalErrors - DaimoninEditor.jar FTP Upload ignore non-critical errors - Value: yes|no - Default: yes -* build.number - Build number, will be automatically created and increased by Ant -* build.developer - If you plan to release your DaimoninEditor.jar, you definitely should set this. - The build number will only be shown in the about dialog if you also set - the property build.developer. - Theoretically, creating a unique build.number would be possible via CVS, but - the delay in CVS usage is too long. To keep build numbers unique, they are - only published if they also denote the build developer. - -Example user.properties file: -user.ctags=yes -debug=yes -user.ftp.host=www.example.com -user.ftp.user=cheristheus1234 -user.ftp.pass=12345678 -user.ftp.dir=daimonin This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-09 20:54:16
|
Revision: 9690 http://sourceforge.net/p/gridarta/code/9690 Author: akirschbaum Date: 2014-03-09 20:54:11 +0000 (Sun, 09 Mar 2014) Log Message: ----------- Move code from PathManager to IOUtils. Modified Paths: -------------- trunk/src/model/src/main/java/net/sf/gridarta/model/io/PathManager.java trunk/src/utils/src/main/java/net/sf/gridarta/utils/IOUtils.java Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/io/PathManager.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/io/PathManager.java 2014-03-09 13:21:10 UTC (rev 9689) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/io/PathManager.java 2014-03-09 20:54:11 UTC (rev 9690) @@ -20,11 +20,11 @@ package net.sf.gridarta.model.io; import java.io.File; -import java.io.IOException; import net.sf.gridarta.model.mapmodel.AbsoluteMapPath; import net.sf.gridarta.model.mapmodel.MapFile; import net.sf.gridarta.model.mapmodel.MapPathUtils; import net.sf.gridarta.model.settings.ProjectSettings; +import net.sf.gridarta.utils.IOUtils; import org.jetbrains.annotations.NotNull; /** @@ -81,9 +81,9 @@ */ @NotNull public MapFile getMapFile(@NotNull final File file) { - final String canonicalFile = getCanonicalPath(file); + final String canonicalFile = IOUtils.getCanonicalPath(file); final File mapsDirectory = projectSettings.getMapsDirectory(); - final String canonicalMapsDir = getCanonicalPath(mapsDirectory) + "/"; + final String canonicalMapsDir = IOUtils.getCanonicalPath(mapsDirectory) + "/"; final String mapPath; final File baseDir; if (canonicalFile.startsWith(canonicalMapsDir)) { @@ -98,19 +98,4 @@ return new MapFile(new MapFile(baseDir), MapPathUtils.newMapPath(mapPath)); } - /** - * Calls {@link File#getCanonicalPath()}. If this fails, returns {@link - * File#getAbsolutePath()}. - * @param file the file - * @return the absolute path - */ - @NotNull - private static String getCanonicalPath(@NotNull final File file) { - try { - return file.getCanonicalPath(); - } catch (final IOException ignored) { - return file.getAbsolutePath(); - } - } - } Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/IOUtils.java =================================================================== --- trunk/src/utils/src/main/java/net/sf/gridarta/utils/IOUtils.java 2014-03-09 13:21:10 UTC (rev 9689) +++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/IOUtils.java 2014-03-09 20:54:11 UTC (rev 9690) @@ -189,4 +189,19 @@ throw new IOException("'" + name + "' not found in " + pathSpec); } + /** + * Calls {@link File#getCanonicalPath()}. If this fails, returns {@link + * File#getAbsolutePath()}. + * @param file the file + * @return the absolute path + */ + @NotNull + public static String getCanonicalPath(@NotNull final File file) { + try { + return file.getCanonicalPath(); + } catch (final IOException ignored) { + return file.getAbsolutePath(); + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2014-03-09 21:01:51
|
Revision: 9691 http://sourceforge.net/p/gridarta/code/9691 Author: akirschbaum Date: 2014-03-09 21:01:46 +0000 (Sun, 09 Mar 2014) Log Message: ----------- Properly update pickmap view when using a relative maps directory. Modified Paths: -------------- trunk/src/atrinik/ChangeLog trunk/src/crossfire/ChangeLog trunk/src/daimonin/ChangeLog trunk/src/model/src/main/java/net/sf/gridarta/model/settings/AbstractDefaultProjectSettings.java trunk/src/utils/src/main/java/net/sf/gridarta/utils/IOUtils.java Modified: trunk/src/atrinik/ChangeLog =================================================================== --- trunk/src/atrinik/ChangeLog 2014-03-09 20:54:11 UTC (rev 9690) +++ trunk/src/atrinik/ChangeLog 2014-03-09 21:01:46 UTC (rev 9691) @@ -1,5 +1,8 @@ 2014-03-09 Andreas Kirschbaum + * Properly update pickmap view when using a relative maps + directory, + * Remove support for building with Ant. From now on Gradle is required to build the editor from sources. Modified: trunk/src/crossfire/ChangeLog =================================================================== --- trunk/src/crossfire/ChangeLog 2014-03-09 20:54:11 UTC (rev 9690) +++ trunk/src/crossfire/ChangeLog 2014-03-09 21:01:46 UTC (rev 9691) @@ -1,5 +1,8 @@ 2014-03-09 Andreas Kirschbaum + * Properly update pickmap view when using a relative maps + directory, + * Remove support for building with Ant. From now on Gradle is required to build the editor from sources. Modified: trunk/src/daimonin/ChangeLog =================================================================== --- trunk/src/daimonin/ChangeLog 2014-03-09 20:54:11 UTC (rev 9690) +++ trunk/src/daimonin/ChangeLog 2014-03-09 21:01:46 UTC (rev 9691) @@ -1,5 +1,8 @@ 2014-03-09 Andreas Kirschbaum + * Properly update pickmap view when using a relative maps + directory, + * Remove support for building with Ant. From now on Gradle is required to build the editor from sources. Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/settings/AbstractDefaultProjectSettings.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/settings/AbstractDefaultProjectSettings.java 2014-03-09 20:54:11 UTC (rev 9690) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/settings/AbstractDefaultProjectSettings.java 2014-03-09 21:01:46 UTC (rev 9691) @@ -24,6 +24,7 @@ import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; import net.sf.gridarta.MainControl; +import net.sf.gridarta.utils.IOUtils; import org.jetbrains.annotations.NotNull; /** @@ -122,11 +123,11 @@ @Override public void preferenceChange(final PreferenceChangeEvent evt) { if (evt.getKey().equals(ARCH_DIRECTORY_KEY)) { - archDirectory = new File(PREFERENCES.get(ARCH_DIRECTORY_KEY, editorSettings.getArchDirectoryDefault().toString())); + archDirectory = IOUtils.getCanonicalFile(new File(PREFERENCES.get(ARCH_DIRECTORY_KEY, editorSettings.getArchDirectoryDefault().toString()))); } else if (evt.getKey().equals(MAP_DIRECTORY_KEY)) { setMapsDirectoryInt(new File(PREFERENCES.get(MAP_DIRECTORY_KEY, editorSettings.getMapsDirectoryDefault().toString())), false); } else if (evt.getKey().equals(MEDIA_DIRECTORY_KEY)) { - mediaDirectory = new File(PREFERENCES.get(MEDIA_DIRECTORY_KEY, editorSettings.getMediaDirectoryDefault().toString())); + mediaDirectory = IOUtils.getCanonicalFile(new File(PREFERENCES.get(MEDIA_DIRECTORY_KEY, editorSettings.getMediaDirectoryDefault().toString()))); } else if (evt.getKey().equals(IMAGE_SET_KEY)) { imageSet = PREFERENCES.get(IMAGE_SET_KEY, editorSettings.getImageSetDefault()); } else if (evt.getKey().equals(CONFIG_SOURCE_KEY)) { @@ -137,9 +138,9 @@ }; PREFERENCES.addPreferenceChangeListener(preferenceChangeListener); - archDirectory = new File(PREFERENCES.get(ARCH_DIRECTORY_KEY, editorSettings.getArchDirectoryDefault().toString())); - mapsDirectory = new File(PREFERENCES.get(MAP_DIRECTORY_KEY, editorSettings.getMapsDirectoryDefault().toString())); - mediaDirectory = new File(PREFERENCES.get(MEDIA_DIRECTORY_KEY, editorSettings.getMediaDirectoryDefault().toString())); + archDirectory = IOUtils.getCanonicalFile(new File(PREFERENCES.get(ARCH_DIRECTORY_KEY, editorSettings.getArchDirectoryDefault().toString()))); + mapsDirectory = IOUtils.getCanonicalFile(new File(PREFERENCES.get(MAP_DIRECTORY_KEY, editorSettings.getMapsDirectoryDefault().toString()))); + mediaDirectory = IOUtils.getCanonicalFile(new File(PREFERENCES.get(MEDIA_DIRECTORY_KEY, editorSettings.getMediaDirectoryDefault().toString()))); imageSet = PREFERENCES.get(IMAGE_SET_KEY, editorSettings.getImageSetDefault()); configSourceName = PREFERENCES.get(CONFIG_SOURCE_KEY, ""); } @@ -158,12 +159,13 @@ */ @Override public void setArchDirectory(@NotNull final File archDirectory) { - if (this.archDirectory.equals(archDirectory)) { + final File effectiveArchDirectory = IOUtils.getCanonicalFile(archDirectory); + if (this.archDirectory.equals(effectiveArchDirectory)) { return; } - this.archDirectory = archDirectory; - PREFERENCES.put(ARCH_DIRECTORY_KEY, archDirectory.toString()); + this.archDirectory = effectiveArchDirectory; + PREFERENCES.put(ARCH_DIRECTORY_KEY, effectiveArchDirectory.toString()); } /** @@ -189,13 +191,14 @@ * @param updatePreferences whether the preferences should be updated */ private void setMapsDirectoryInt(@NotNull final File mapsDirectory, final boolean updatePreferences) { - if (this.mapsDirectory.equals(mapsDirectory)) { + final File effectiveMapsDirectory = IOUtils.getCanonicalFile(mapsDirectory); + if (this.mapsDirectory.equals(effectiveMapsDirectory)) { return; } - this.mapsDirectory = mapsDirectory; + this.mapsDirectory = effectiveMapsDirectory; if (updatePreferences) { - PREFERENCES.put(MAP_DIRECTORY_KEY, mapsDirectory.toString()); + PREFERENCES.put(MAP_DIRECTORY_KEY, effectiveMapsDirectory.toString()); } fireMapsDirectoryChanged(); } @@ -214,15 +217,16 @@ */ @Override public void setMediaDirectory(@NotNull final File mediaDirectory) { + final File effectiveMediaDirectory = IOUtils.getCanonicalFile(mediaDirectory); if (!editorSettings.hasMediaDirectory()) { return; } - if (this.mediaDirectory.equals(mediaDirectory)) { + if (this.mediaDirectory.equals(effectiveMediaDirectory)) { return; } - this.mediaDirectory = mediaDirectory; - PREFERENCES.put(MEDIA_DIRECTORY_KEY, mediaDirectory.getPath()); + this.mediaDirectory = effectiveMediaDirectory; + PREFERENCES.put(MEDIA_DIRECTORY_KEY, effectiveMediaDirectory.getPath()); } /** Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/IOUtils.java =================================================================== --- trunk/src/utils/src/main/java/net/sf/gridarta/utils/IOUtils.java 2014-03-09 20:54:11 UTC (rev 9690) +++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/IOUtils.java 2014-03-09 21:01:46 UTC (rev 9691) @@ -204,4 +204,19 @@ } } + /** + * Calls {@link File#getCanonicalFile()}. If this fails, returns {@link + * File#getAbsoluteFile()}. + * @param file the file + * @return the absolute path + */ + @NotNull + public static File getCanonicalFile(@NotNull final File file) { + try { + return file.getCanonicalFile(); + } catch (final IOException ignored) { + return file.getAbsoluteFile(); + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |