From: <aki...@us...> - 2008-10-01 16:56:06
|
Revision: 5318 http://gridarta.svn.sourceforge.net/gridarta/?rev=5318&view=rev Author: akirschbaum Date: 2008-10-01 16:55:44 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move ScriptRunMode to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/script/ScriptController.java trunk/crossfire/src/cfeditor/script/ScriptParameters.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/script/ScriptRunMode.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/script/ScriptRunMode.java Modified: trunk/crossfire/src/cfeditor/script/ScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 16:48:45 UTC (rev 5317) +++ trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 16:55:44 UTC (rev 5318) @@ -52,6 +52,7 @@ import net.sf.gridarta.script.BshThread; import net.sf.gridarta.script.ScriptModel; import net.sf.gridarta.script.ScriptModelParser; +import net.sf.gridarta.script.ScriptRunMode; import net.sf.gridarta.script.parameter.NoSuchParameterException; import net.sf.gridarta.script.parameter.PluginParameter; import net.sf.japi.swing.ActionFactory; Modified: trunk/crossfire/src/cfeditor/script/ScriptParameters.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptParameters.java 2008-10-01 16:48:45 UTC (rev 5317) +++ trunk/crossfire/src/cfeditor/script/ScriptParameters.java 2008-10-01 16:55:44 UTC (rev 5318) @@ -25,6 +25,7 @@ import net.sf.gridarta.MapManager; import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.map.validation.DelegatingMapValidator; +import net.sf.gridarta.script.ScriptRunMode; import org.jetbrains.annotations.NotNull; /** Deleted: trunk/crossfire/src/cfeditor/script/ScriptRunMode.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptRunMode.java 2008-10-01 16:48:45 UTC (rev 5317) +++ trunk/crossfire/src/cfeditor/script/ScriptRunMode.java 2008-10-01 16:55:44 UTC (rev 5318) @@ -1,34 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.script; - -/** - * The run mode of a plugin script. - * @author Andreas Kirschbaum - */ -public enum ScriptRunMode { - - AUTORUN, - - BATCH, - - FILTER; - -} // enum ScriptRunMode Copied: trunk/src/app/net/sf/gridarta/script/ScriptRunMode.java (from rev 5317, trunk/crossfire/src/cfeditor/script/ScriptRunMode.java) =================================================================== --- trunk/src/app/net/sf/gridarta/script/ScriptRunMode.java (rev 0) +++ trunk/src/app/net/sf/gridarta/script/ScriptRunMode.java 2008-10-01 16:55:44 UTC (rev 5318) @@ -0,0 +1,34 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 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.script; + +/** + * The run mode of a plugin script. + * @author Andreas Kirschbaum + */ +public enum ScriptRunMode { + + AUTORUN, + + BATCH, + + FILTER; + +} // enum ScriptRunMode Property changes on: trunk/src/app/net/sf/gridarta/script/ScriptRunMode.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 17:09:55
|
Revision: 5321 http://gridarta.svn.sourceforge.net/gridarta/?rev=5321&view=rev Author: akirschbaum Date: 2008-10-01 17:09:22 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move PluginParameterView to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java trunk/crossfire/src/cfeditor/gui/script/ScriptView.java trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java trunk/crossfire/src/cfeditor/gui/script/parameter/FilterParameterView.java trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java trunk/crossfire/src/cfeditor/gui/script/parameter/StringParameterView.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/ trunk/src/app/net/sf/gridarta/gui/script/parameter/ trunk/src/app/net/sf/gridarta/gui/script/parameter/PluginParameterView.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterView.java Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -23,7 +23,6 @@ import cfeditor.gui.script.parameter.ParameterDescriptionEditor; import cfeditor.gui.script.parameter.ParameterNameEditor; import cfeditor.gui.script.parameter.ParameterTypeEditor; -import cfeditor.gui.script.parameter.PluginParameterView; import cfeditor.gui.script.parameter.PluginParameterViewFactory; import cfeditor.script.ScriptController; import java.awt.BorderLayout; @@ -54,10 +53,11 @@ import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.gui.utils.GUIUtils; import net.sf.gridarta.script.ScriptModel; +import net.sf.gridarta.script.parameter.NoSuchParameterException; import net.sf.gridarta.script.parameter.PluginParameter; -import net.sf.gridarta.script.parameter.NoSuchParameterException; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -21,7 +21,6 @@ import bsh.ConsoleInterface; import bsh.util.JConsole; -import cfeditor.gui.script.parameter.PluginParameterView; import cfeditor.gui.script.parameter.PluginParameterViewFactory; import cfeditor.script.ScriptControlListener; import cfeditor.script.ScriptController; @@ -40,6 +39,7 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.gridarta.script.ScriptModel; import net.sf.gridarta.script.parameter.PluginParameter; Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -29,6 +29,7 @@ import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; import net.sf.gridarta.gui.objectchooser.ObjectChooser; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.ArchParameter; import org.jetbrains.annotations.NotNull; Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -25,6 +25,7 @@ import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JOptionPane; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.BooleanConfig; import net.sf.gridarta.script.parameter.BooleanParameter; import org.jetbrains.annotations.NotNull; Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -30,6 +30,7 @@ import javax.swing.SpinnerNumberModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.DoubleConfig; import net.sf.gridarta.script.parameter.DoubleParameter; import org.apache.log4j.Logger; Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/FilterParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/FilterParameterView.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/FilterParameterView.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -24,6 +24,7 @@ import javax.swing.JPanel; import net.sf.gridarta.filter.FilterConfig; import net.sf.gridarta.filter.NamedFilterList; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.FilterParameter; import org.jetbrains.annotations.NotNull; Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -30,6 +30,7 @@ import javax.swing.SpinnerNumberModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.IntegerConfig; import net.sf.gridarta.script.parameter.IntegerParameter; import org.apache.log4j.Logger; Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -29,6 +29,7 @@ import javax.swing.JComponent; import javax.swing.JPanel; import net.sf.gridarta.MapManager; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.MapParameter; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterView.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterView.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -1,43 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import javax.swing.JComponent; -import net.sf.gridarta.script.parameter.PluginParameter; -import org.jetbrains.annotations.NotNull; - -/** - * Interface for Views that display plugin parameters. - * @author tchize - */ -public interface PluginParameterView<V, C, P extends PluginParameter<V, C>> { - - JComponent getValueComponent(V value, P parameter); - - JComponent getConfigComponent(C config, P parameter); - - /** - * Sets the parameter value from string representation. - * @param value the value to set - * @return whether the values was updates - */ - boolean setValue(@NotNull final String value); - -} // interface PluginParameterView Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -28,6 +28,7 @@ import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; import net.sf.gridarta.gui.objectchooser.ObjectChooser; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.ArchParameter; import net.sf.gridarta.script.parameter.BooleanParameter; import net.sf.gridarta.script.parameter.DoubleParameter; Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/StringParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/StringParameterView.java 2008-10-01 17:03:02 UTC (rev 5320) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/StringParameterView.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -25,6 +25,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.Document; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.StringParameter; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/PluginParameterView.java (from rev 5318, trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterView.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/PluginParameterView.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/PluginParameterView.java 2008-10-01 17:09:22 UTC (rev 5321) @@ -0,0 +1,43 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import javax.swing.JComponent; +import net.sf.gridarta.script.parameter.PluginParameter; +import org.jetbrains.annotations.NotNull; + +/** + * Interface for Views that display plugin parameters. + * @author tchize + */ +public interface PluginParameterView<V, C, P extends PluginParameter<V, C>> { + + JComponent getValueComponent(V value, P parameter); + + JComponent getConfigComponent(C config, P parameter); + + /** + * Sets the parameter value from string representation. + * @param value the value to set + * @return whether the values was updates + */ + boolean setValue(@NotNull final String value); + +} // interface PluginParameterView Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/PluginParameterView.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 17:23:08
|
Revision: 5322 http://gridarta.svn.sourceforge.net/gridarta/?rev=5322&view=rev Author: akirschbaum Date: 2008-10-01 17:22:46 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move BooleanParameterView to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/BooleanParameterView.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java 2008-10-01 17:09:22 UTC (rev 5321) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java 2008-10-01 17:22:46 UTC (rev 5322) @@ -1,91 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import net.sf.gridarta.gui.script.parameter.PluginParameterView; -import net.sf.gridarta.script.parameter.BooleanConfig; -import net.sf.gridarta.script.parameter.BooleanParameter; -import org.jetbrains.annotations.NotNull; - -public class BooleanParameterView implements PluginParameterView<Boolean, BooleanConfig, BooleanParameter>, ActionListener { - - private final JCheckBox value; - - private final JButton config; - - private final BooleanParameter parameter; - - public BooleanParameterView(final BooleanParameter param) { - parameter = param; - value = new JCheckBox(); - value.setActionCommand("toggle"); - value.addActionListener(this); - config = new JButton("..."); - config.setBorderPainted(false); - config.setActionCommand("config"); - config.addActionListener(this); - } - - public JComponent getConfigComponent(final BooleanConfig config, final BooleanParameter parameter) { - return this.config; - } - - public JComponent getValueComponent(final Boolean value, final BooleanParameter parameter) { - return this.value; - } - - /** {@inheritDoc} */ - public boolean setValue(@NotNull final String value) { - if (value.equals("true")) { - parameter.setValue(Boolean.TRUE); - return true; - } else if (value.equals("false")) { - parameter.setValue(Boolean.FALSE); - return true; - } else { - return false; - } - } - - public void actionPerformed(final ActionEvent e) { - if (e.getActionCommand().equals("toggle")) { - if (value.isSelected()) { - parameter.setValue(Boolean.TRUE); - value.setText(parameter.getTrueText()); - } else { - parameter.setValue(Boolean.FALSE); - value.setText(parameter.getFalseText()); - } - } - if (e.getActionCommand().equals("config")) { - final String yes = JOptionPane.showInputDialog("Checked text", parameter.getTrueText()); - final String no = JOptionPane.showInputDialog("Unchecked text", parameter.getFalseText()); - parameter.setTrueText(yes); - parameter.setFalseText(no); - } - } - -} // class BooleanParameterView Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 17:09:22 UTC (rev 5321) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 17:22:46 UTC (rev 5322) @@ -28,6 +28,7 @@ import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; import net.sf.gridarta.gui.objectchooser.ObjectChooser; +import net.sf.gridarta.gui.script.parameter.BooleanParameterView; import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.ArchParameter; import net.sf.gridarta.script.parameter.BooleanParameter; Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/BooleanParameterView.java (from rev 5321, trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/BooleanParameterView.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/BooleanParameterView.java 2008-10-01 17:22:46 UTC (rev 5322) @@ -0,0 +1,91 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; +import net.sf.gridarta.script.parameter.BooleanConfig; +import net.sf.gridarta.script.parameter.BooleanParameter; +import org.jetbrains.annotations.NotNull; + +public class BooleanParameterView implements PluginParameterView<Boolean, BooleanConfig, BooleanParameter>, ActionListener { + + private final JCheckBox value; + + private final JButton config; + + private final BooleanParameter parameter; + + public BooleanParameterView(final BooleanParameter param) { + parameter = param; + value = new JCheckBox(); + value.setActionCommand("toggle"); + value.addActionListener(this); + config = new JButton("..."); + config.setBorderPainted(false); + config.setActionCommand("config"); + config.addActionListener(this); + } + + public JComponent getConfigComponent(final BooleanConfig config, final BooleanParameter parameter) { + return this.config; + } + + public JComponent getValueComponent(final Boolean value, final BooleanParameter parameter) { + return this.value; + } + + /** {@inheritDoc} */ + public boolean setValue(@NotNull final String value) { + if (value.equals("true")) { + parameter.setValue(Boolean.TRUE); + return true; + } else if (value.equals("false")) { + parameter.setValue(Boolean.FALSE); + return true; + } else { + return false; + } + } + + public void actionPerformed(final ActionEvent e) { + if (e.getActionCommand().equals("toggle")) { + if (value.isSelected()) { + parameter.setValue(Boolean.TRUE); + value.setText(parameter.getTrueText()); + } else { + parameter.setValue(Boolean.FALSE); + value.setText(parameter.getFalseText()); + } + } + if (e.getActionCommand().equals("config")) { + final String yes = JOptionPane.showInputDialog("Checked text", parameter.getTrueText()); + final String no = JOptionPane.showInputDialog("Unchecked text", parameter.getFalseText()); + parameter.setTrueText(yes); + parameter.setFalseText(no); + } + } + +} // class BooleanParameterView Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/BooleanParameterView.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 17:31:55
|
Revision: 5323 http://gridarta.svn.sourceforge.net/gridarta/?rev=5323&view=rev Author: akirschbaum Date: 2008-10-01 17:31:30 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move DoubleParameterView to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/DoubleParameterView.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java 2008-10-01 17:22:46 UTC (rev 5322) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java 2008-10-01 17:31:30 UTC (rev 5323) @@ -1,158 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JSpinner; -import javax.swing.SpinnerModel; -import javax.swing.SpinnerNumberModel; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import net.sf.gridarta.gui.script.parameter.PluginParameterView; -import net.sf.gridarta.script.parameter.DoubleConfig; -import net.sf.gridarta.script.parameter.DoubleParameter; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; - -public class DoubleParameterView implements PluginParameterView<Double, DoubleConfig, DoubleParameter>, ActionListener { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(DoubleParameterView.class); - - private final JSpinner value; - - private final JButton config; - - private final DoubleParameter parameter; - - public DoubleParameterView(final DoubleParameter param) { - parameter = param; - if (log.isDebugEnabled()) { - log.debug("Creating spinner: [" + param.getMin() + "," + param.getMax() + "]"); - } - final SpinnerModel mdl = new SpinnerNumberModel(0.0, param.getMin(), param.getMax(), (param.getMax() - param.getMin()) / 100); - value = new TooltipSpinner(mdl); - try { - value.setValue(param.getValue()); - } catch (final IllegalArgumentException e) { - } - value.addChangeListener(new ChangeListener() { - public void stateChanged(final ChangeEvent e) { - parameter.setValue((Double) ((SpinnerNumberModel) value.getModel()).getNumber()); - } - }); - config = new JButton("..."); - config.setBorderPainted(false); - config.setActionCommand("Config"); - config.addActionListener(this); - updateTooltip(); - } - - public JComponent getConfigComponent(final DoubleConfig config, final DoubleParameter parameter) { - return this.config; - } - - public JComponent getValueComponent(final Double value, final DoubleParameter parameter) { - return this.value; - } - - /** {@inheritDoc} */ - public boolean setValue(@NotNull final String value) { - final double doubleValue; - try { - doubleValue = Double.parseDouble(value); - } catch (final NumberFormatException ex) { - return false; - } - parameter.setValue(doubleValue); - return true; - } - - private void updateTooltip() { - final String toolTip = "[" + Double.toString(parameter.getMin()) + "," + Double.toString(parameter.getMax()) + "]"; - config.setToolTipText(toolTip); - value.setToolTipText(toolTip); - } - - public void actionPerformed(final ActionEvent e) { - if (log.isDebugEnabled()) { - log.debug("command: " + e.getActionCommand()); - } - - if (e.getActionCommand().equals("Config")) { - final String min = JOptionPane.showInputDialog("Minimum value:", parameter.getMin()); - final String max = JOptionPane.showInputDialog("Maximum value:", parameter.getMax()); - 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"); - } - } - } - - /** - * Extends JSpinner to work around it's tooltip bug This bug has been fixed - * since Java 5.0 but we need this workaround for java 4.x users. - * @author tchize - */ - private static class TooltipSpinner extends JSpinner { - - private static final long serialVersionUID = 1L; - - private TooltipSpinner(final SpinnerModel model) { - super(model); - } - - /** - * This override the JSpinner method to force the tooltip in all - * subcomponents. - * @param text the tooltip to show - */ - @Override - public void setToolTipText(final String text) { - forceTooltip(this, text); - } - - private void forceTooltip(final JComponent c, final String tip) { - if (c == this) { - super.setToolTipText(tip); - } else { - c.setToolTipText(tip); - } - final Component[] components = c.getComponents(); - for (final Component component : components) { - if (component instanceof JComponent) { - forceTooltip((JComponent) component, tip); - } - } - } - - } // class TooltipSpinner - -} // class DoubleParameterView Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 17:22:46 UTC (rev 5322) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 17:31:30 UTC (rev 5323) @@ -29,6 +29,7 @@ import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; import net.sf.gridarta.gui.objectchooser.ObjectChooser; import net.sf.gridarta.gui.script.parameter.BooleanParameterView; +import net.sf.gridarta.gui.script.parameter.DoubleParameterView; import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.ArchParameter; import net.sf.gridarta.script.parameter.BooleanParameter; Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/DoubleParameterView.java (from rev 5321, trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/DoubleParameterView.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/DoubleParameterView.java 2008-10-01 17:31:30 UTC (rev 5323) @@ -0,0 +1,158 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JSpinner; +import javax.swing.SpinnerModel; +import javax.swing.SpinnerNumberModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; +import net.sf.gridarta.script.parameter.DoubleConfig; +import net.sf.gridarta.script.parameter.DoubleParameter; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +public class DoubleParameterView implements PluginParameterView<Double, DoubleConfig, DoubleParameter>, ActionListener { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(DoubleParameterView.class); + + private final JSpinner value; + + private final JButton config; + + private final DoubleParameter parameter; + + public DoubleParameterView(final DoubleParameter param) { + parameter = param; + if (log.isDebugEnabled()) { + log.debug("Creating spinner: [" + param.getMin() + "," + param.getMax() + "]"); + } + final SpinnerModel mdl = new SpinnerNumberModel(0.0, param.getMin(), param.getMax(), (param.getMax() - param.getMin()) / 100); + value = new TooltipSpinner(mdl); + try { + value.setValue(param.getValue()); + } catch (final IllegalArgumentException e) { + } + value.addChangeListener(new ChangeListener() { + public void stateChanged(final ChangeEvent e) { + parameter.setValue((Double) ((SpinnerNumberModel) value.getModel()).getNumber()); + } + }); + config = new JButton("..."); + config.setBorderPainted(false); + config.setActionCommand("Config"); + config.addActionListener(this); + updateTooltip(); + } + + public JComponent getConfigComponent(final DoubleConfig config, final DoubleParameter parameter) { + return this.config; + } + + public JComponent getValueComponent(final Double value, final DoubleParameter parameter) { + return this.value; + } + + /** {@inheritDoc} */ + public boolean setValue(@NotNull final String value) { + final double doubleValue; + try { + doubleValue = Double.parseDouble(value); + } catch (final NumberFormatException ex) { + return false; + } + parameter.setValue(doubleValue); + return true; + } + + private void updateTooltip() { + final String toolTip = "[" + Double.toString(parameter.getMin()) + "," + Double.toString(parameter.getMax()) + "]"; + config.setToolTipText(toolTip); + value.setToolTipText(toolTip); + } + + public void actionPerformed(final ActionEvent e) { + if (log.isDebugEnabled()) { + log.debug("command: " + e.getActionCommand()); + } + + if (e.getActionCommand().equals("Config")) { + final String min = JOptionPane.showInputDialog("Minimum value:", parameter.getMin()); + final String max = JOptionPane.showInputDialog("Maximum value:", parameter.getMax()); + 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"); + } + } + } + + /** + * Extends JSpinner to work around it's tooltip bug This bug has been fixed + * since Java 5.0 but we need this workaround for java 4.x users. + * @author tchize + */ + private static class TooltipSpinner extends JSpinner { + + private static final long serialVersionUID = 1L; + + private TooltipSpinner(final SpinnerModel model) { + super(model); + } + + /** + * This override the JSpinner method to force the tooltip in all + * subcomponents. + * @param text the tooltip to show + */ + @Override + public void setToolTipText(final String text) { + forceTooltip(this, text); + } + + private void forceTooltip(final JComponent c, final String tip) { + if (c == this) { + super.setToolTipText(tip); + } else { + c.setToolTipText(tip); + } + final Component[] components = c.getComponents(); + for (final Component component : components) { + if (component instanceof JComponent) { + forceTooltip((JComponent) component, tip); + } + } + } + + } // class TooltipSpinner + +} // class DoubleParameterView Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/DoubleParameterView.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 18:04:53
|
Revision: 5325 http://gridarta.svn.sourceforge.net/gridarta/?rev=5325&view=rev Author: akirschbaum Date: 2008-10-01 18:04:31 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move IntegerParameterView to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/IntegerParameterView.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java 2008-10-01 18:01:20 UTC (rev 5324) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java 2008-10-01 18:04:31 UTC (rev 5325) @@ -1,158 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JSpinner; -import javax.swing.SpinnerModel; -import javax.swing.SpinnerNumberModel; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import net.sf.gridarta.gui.script.parameter.PluginParameterView; -import net.sf.gridarta.script.parameter.IntegerConfig; -import net.sf.gridarta.script.parameter.IntegerParameter; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; - -public class IntegerParameterView implements PluginParameterView<Integer, IntegerConfig, IntegerParameter>, ActionListener { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(IntegerParameterView.class); - - private final JSpinner value; - - private final JButton config; - - private final IntegerParameter parameter; - - public IntegerParameterView(final IntegerParameter param) { - parameter = param; - final SpinnerModel mdl = new SpinnerNumberModel(0, param.getMin(), param.getMax(), 1); - value = new TooltipSpinner(mdl); - try { - value.setValue(param.getValue()); - } catch (final Exception e) { - } - value.addChangeListener(new ChangeListener() { - public void stateChanged(final ChangeEvent e) { - try { - parameter.setValue((Integer) ((SpinnerNumberModel) value.getModel()).getNumber()); - } catch (final Exception ex) { - ex.printStackTrace(); - } - } - }); - config = new JButton("..."); - config.setBorderPainted(false); - config.setActionCommand("Config"); - config.addActionListener(this); - updateTooltip(); - } - - public JComponent getConfigComponent(final IntegerConfig config, final IntegerParameter parameter) { - return this.config; - } - - public JComponent getValueComponent(final Integer value, final IntegerParameter parameter) { - return this.value; - } - - /** {@inheritDoc} */ - public boolean setValue(@NotNull final String value) { - final int intValue; - try { - intValue = Integer.parseInt(value); - } catch (final NumberFormatException ex) { - return false; - } - parameter.setValue(intValue); - return true; - } - - private void updateTooltip() { - final String toolTip = "[" + Integer.toString(parameter.getMin()) + "," + Integer.toString(parameter.getMax()) + "]"; - config.setToolTipText(toolTip); - value.setToolTipText(toolTip); - } - - public void actionPerformed(final ActionEvent e) { - if (log.isDebugEnabled()) { - log.debug("command: " + e.getActionCommand()); - } - if (e.getActionCommand().equals("Config")) { - final String min = JOptionPane.showInputDialog("Minimum value:", parameter.getMin()); - final String max = JOptionPane.showInputDialog("Maximum value:", parameter.getMax()); - 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"); - } - } - } - - /** - * Extends JSpinner to work around it's tooltip bug This bug has been fixed - * since Java 5.0 but we need this workaround for java 4.x users. - * @author tchize - */ - private static class TooltipSpinner extends JSpinner { - - private static final long serialVersionUID = -797350272052837471L; - - private TooltipSpinner(final SpinnerModel model) { - super(model); - } - - /** - * This override the JSpinner method to force the tooltip in all - * subcomponents. - * @param text the tooltip to show - */ - @Override - public void setToolTipText(final String text) { - forceTooltip(this, text); - } - - private void forceTooltip(final JComponent c, final String tip) { - if (c == this) { - super.setToolTipText(tip); - } else { - c.setToolTipText(tip); - } - final Component[] components = c.getComponents(); - for (final Component component : components) { - if (component instanceof JComponent) { - forceTooltip((JComponent) component, tip); - } - } - } - - } // class TooltipSpinner - -} // class IntegerParameterView Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 18:01:20 UTC (rev 5324) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 18:04:31 UTC (rev 5325) @@ -31,6 +31,7 @@ import net.sf.gridarta.gui.script.parameter.BooleanParameterView; import net.sf.gridarta.gui.script.parameter.DoubleParameterView; import net.sf.gridarta.gui.script.parameter.FilterParameterView; +import net.sf.gridarta.gui.script.parameter.IntegerParameterView; import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.ArchParameter; import net.sf.gridarta.script.parameter.BooleanParameter; Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/IntegerParameterView.java (from rev 5321, trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/IntegerParameterView.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/IntegerParameterView.java 2008-10-01 18:04:31 UTC (rev 5325) @@ -0,0 +1,158 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JSpinner; +import javax.swing.SpinnerModel; +import javax.swing.SpinnerNumberModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import net.sf.gridarta.gui.script.parameter.PluginParameterView; +import net.sf.gridarta.script.parameter.IntegerConfig; +import net.sf.gridarta.script.parameter.IntegerParameter; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +public class IntegerParameterView implements PluginParameterView<Integer, IntegerConfig, IntegerParameter>, ActionListener { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(IntegerParameterView.class); + + private final JSpinner value; + + private final JButton config; + + private final IntegerParameter parameter; + + public IntegerParameterView(final IntegerParameter param) { + parameter = param; + final SpinnerModel mdl = new SpinnerNumberModel(0, param.getMin(), param.getMax(), 1); + value = new TooltipSpinner(mdl); + try { + value.setValue(param.getValue()); + } catch (final Exception e) { + } + value.addChangeListener(new ChangeListener() { + public void stateChanged(final ChangeEvent e) { + try { + parameter.setValue((Integer) ((SpinnerNumberModel) value.getModel()).getNumber()); + } catch (final Exception ex) { + ex.printStackTrace(); + } + } + }); + config = new JButton("..."); + config.setBorderPainted(false); + config.setActionCommand("Config"); + config.addActionListener(this); + updateTooltip(); + } + + public JComponent getConfigComponent(final IntegerConfig config, final IntegerParameter parameter) { + return this.config; + } + + public JComponent getValueComponent(final Integer value, final IntegerParameter parameter) { + return this.value; + } + + /** {@inheritDoc} */ + public boolean setValue(@NotNull final String value) { + final int intValue; + try { + intValue = Integer.parseInt(value); + } catch (final NumberFormatException ex) { + return false; + } + parameter.setValue(intValue); + return true; + } + + private void updateTooltip() { + final String toolTip = "[" + Integer.toString(parameter.getMin()) + "," + Integer.toString(parameter.getMax()) + "]"; + config.setToolTipText(toolTip); + value.setToolTipText(toolTip); + } + + public void actionPerformed(final ActionEvent e) { + if (log.isDebugEnabled()) { + log.debug("command: " + e.getActionCommand()); + } + if (e.getActionCommand().equals("Config")) { + final String min = JOptionPane.showInputDialog("Minimum value:", parameter.getMin()); + final String max = JOptionPane.showInputDialog("Maximum value:", parameter.getMax()); + 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"); + } + } + } + + /** + * Extends JSpinner to work around it's tooltip bug This bug has been fixed + * since Java 5.0 but we need this workaround for java 4.x users. + * @author tchize + */ + private static class TooltipSpinner extends JSpinner { + + private static final long serialVersionUID = -797350272052837471L; + + private TooltipSpinner(final SpinnerModel model) { + super(model); + } + + /** + * This override the JSpinner method to force the tooltip in all + * subcomponents. + * @param text the tooltip to show + */ + @Override + public void setToolTipText(final String text) { + forceTooltip(this, text); + } + + private void forceTooltip(final JComponent c, final String tip) { + if (c == this) { + super.setToolTipText(tip); + } else { + c.setToolTipText(tip); + } + final Component[] components = c.getComponents(); + for (final Component component : components) { + if (component instanceof JComponent) { + forceTooltip((JComponent) component, tip); + } + } + } + + } // class TooltipSpinner + +} // class IntegerParameterView Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/IntegerParameterView.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 18:17:05
|
Revision: 5328 http://gridarta.svn.sourceforge.net/gridarta/?rev=5328&view=rev Author: akirschbaum Date: 2008-10-01 18:16:38 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move ParameterTypeEditor to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterTypeEditor.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterTypeEditor.java Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 18:12:55 UTC (rev 5327) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 18:16:38 UTC (rev 5328) @@ -21,7 +21,6 @@ import cfeditor.IGUIConstants; import cfeditor.gui.script.parameter.ParameterDescriptionEditor; -import cfeditor.gui.script.parameter.ParameterTypeEditor; import cfeditor.gui.script.parameter.PluginParameterViewFactory; import cfeditor.script.ScriptController; import java.awt.BorderLayout; @@ -53,6 +52,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import net.sf.gridarta.gui.script.parameter.ParameterNameEditor; +import net.sf.gridarta.gui.script.parameter.ParameterTypeEditor; import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.gui.utils.GUIUtils; import net.sf.gridarta.script.ScriptModel; Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterTypeEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterTypeEditor.java 2008-10-01 18:12:55 UTC (rev 5327) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterTypeEditor.java 2008-10-01 18:16:38 UTC (rev 5328) @@ -1,67 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import javax.swing.JComboBox; -import net.sf.gridarta.script.ScriptModel; -import net.sf.gridarta.script.parameter.NoSuchParameterException; -import net.sf.gridarta.script.parameter.PluginParameter; -import net.sf.gridarta.script.parameter.PluginParameterFactory; -import org.apache.log4j.Logger; - -public class ParameterTypeEditor extends JComboBox { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ParameterTypeEditor.class); - - private static final long serialVersionUID = 1L; - - private final PluginParameter<?, ?> parameter; - - private final ScriptModel script; - - private final ItemListener itemListener = new ItemListener() { - - /** {@inheritDoc} */ - public void itemStateChanged(final ItemEvent e) { - if (e.getStateChange() == ItemEvent.SELECTED) { - if (!parameter.getType().equals(e.getItem())) { - try { - script.convertType(parameter, (String) e.getItem()); - } catch (final NoSuchParameterException ex) { - log.warn("Cannot create parameter for type " + e.getItem()); - } - } - } - } - - }; - - public ParameterTypeEditor(final ScriptModel script, final PluginParameter<?, ?> parameter) { - super(PluginParameterFactory.getTypes()); - this.parameter = parameter; - this.script = script; - setSelectedItem(parameter.getType()); - addItemListener(itemListener); - } - -} // class ParameterTypeEditor Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterTypeEditor.java (from rev 5318, trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterTypeEditor.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterTypeEditor.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterTypeEditor.java 2008-10-01 18:16:38 UTC (rev 5328) @@ -0,0 +1,67 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import javax.swing.JComboBox; +import net.sf.gridarta.script.ScriptModel; +import net.sf.gridarta.script.parameter.NoSuchParameterException; +import net.sf.gridarta.script.parameter.PluginParameter; +import net.sf.gridarta.script.parameter.PluginParameterFactory; +import org.apache.log4j.Logger; + +public class ParameterTypeEditor extends JComboBox { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(ParameterTypeEditor.class); + + private static final long serialVersionUID = 1L; + + private final PluginParameter<?, ?> parameter; + + private final ScriptModel script; + + private final ItemListener itemListener = new ItemListener() { + + /** {@inheritDoc} */ + public void itemStateChanged(final ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + if (!parameter.getType().equals(e.getItem())) { + try { + script.convertType(parameter, (String) e.getItem()); + } catch (final NoSuchParameterException ex) { + log.warn("Cannot create parameter for type " + e.getItem()); + } + } + } + } + + }; + + public ParameterTypeEditor(final ScriptModel script, final PluginParameter<?, ?> parameter) { + super(PluginParameterFactory.getTypes()); + this.parameter = parameter; + this.script = script; + setSelectedItem(parameter.getType()); + addItemListener(itemListener); + } + +} // class ParameterTypeEditor Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterTypeEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 18:40:53
|
Revision: 5329 http://gridarta.svn.sourceforge.net/gridarta/?rev=5329&view=rev Author: akirschbaum Date: 2008-10-01 18:40:30 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move MapParameterCellRenderer to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterCellRenderer.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterCellRenderer.java Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterCellRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterCellRenderer.java 2008-10-01 18:16:38 UTC (rev 5328) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterCellRenderer.java 2008-10-01 18:40:30 UTC (rev 5329) @@ -1,64 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import java.awt.Component; -import javax.swing.DefaultListCellRenderer; -import javax.swing.JList; -import net.sf.gridarta.MapManager; -import net.sf.gridarta.map.MapControl; -import org.jetbrains.annotations.NotNull; - -public class MapParameterCellRenderer extends DefaultListCellRenderer { - - private static final long serialVersionUID = 1L; - - /** - * The map manager to use. - */ - @NotNull - private final MapManager<?, ?, ?, ?> mapManager; - - /** - * Create a new instance. - * @param mapManager the map manager to use - */ - public MapParameterCellRenderer(@NotNull final MapManager<?, ?, ?, ?> mapManager) { - this.mapManager = mapManager; - } - - /** {@inheritDoc} */ - @Override - public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { - final String newVal; - if (!(value instanceof MapControl)) { - String currentMapName = ""; - final MapControl<?, ?, ?, ?> currentMap = mapManager.getCurrentMap(); - if (currentMap != null) { - currentMapName = currentMap.getMapFileName(); - } - newVal = "Current - " + currentMapName; - } else { - newVal = (((MapControl<?, ?, ?, ?>) value).getMapFileName()); - } - return super.getListCellRendererComponent(list, newVal, index, isSelected, cellHasFocus); - } - -} // class MapParameterCellRenderer Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2008-10-01 18:16:38 UTC (rev 5328) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2008-10-01 18:40:30 UTC (rev 5329) @@ -29,6 +29,7 @@ import javax.swing.JComponent; import javax.swing.JPanel; import net.sf.gridarta.MapManager; +import net.sf.gridarta.gui.script.parameter.MapParameterCellRenderer; import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.MapParameter; import org.apache.log4j.Logger; Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterCellRenderer.java (from rev 5328, trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterCellRenderer.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterCellRenderer.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterCellRenderer.java 2008-10-01 18:40:30 UTC (rev 5329) @@ -0,0 +1,64 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.awt.Component; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; +import net.sf.gridarta.MapManager; +import net.sf.gridarta.map.MapControl; +import org.jetbrains.annotations.NotNull; + +public class MapParameterCellRenderer extends DefaultListCellRenderer { + + private static final long serialVersionUID = 1L; + + /** + * The map manager to use. + */ + @NotNull + private final MapManager<?, ?, ?, ?> mapManager; + + /** + * Create a new instance. + * @param mapManager the map manager to use + */ + public MapParameterCellRenderer(@NotNull final MapManager<?, ?, ?, ?> mapManager) { + this.mapManager = mapManager; + } + + /** {@inheritDoc} */ + @Override + public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { + final String newVal; + if (!(value instanceof MapControl)) { + String currentMapName = ""; + final MapControl<?, ?, ?, ?> currentMap = mapManager.getCurrentMap(); + if (currentMap != null) { + currentMapName = currentMap.getMapFileName(); + } + newVal = "Current - " + currentMapName; + } else { + newVal = (((MapControl<?, ?, ?, ?>) value).getMapFileName()); + } + return super.getListCellRendererComponent(list, newVal, index, isSelected, cellHasFocus); + } + +} // class MapParameterCellRenderer Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterCellRenderer.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 18:49:16
|
Revision: 5332 http://gridarta.svn.sourceforge.net/gridarta/?rev=5332&view=rev Author: akirschbaum Date: 2008-10-01 18:49:05 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move ParameterDescriptionEditor to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterDescriptionEditor.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterDescriptionEditor.java Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 18:45:21 UTC (rev 5331) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 18:49:05 UTC (rev 5332) @@ -20,7 +20,6 @@ package cfeditor.gui.script; import cfeditor.IGUIConstants; -import cfeditor.gui.script.parameter.ParameterDescriptionEditor; import cfeditor.gui.script.parameter.PluginParameterViewFactory; import cfeditor.script.ScriptController; import java.awt.BorderLayout; @@ -51,6 +50,7 @@ import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import net.sf.gridarta.gui.script.parameter.ParameterDescriptionEditor; import net.sf.gridarta.gui.script.parameter.ParameterNameEditor; import net.sf.gridarta.gui.script.parameter.ParameterTypeEditor; import net.sf.gridarta.gui.script.parameter.PluginParameterView; Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterDescriptionEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterDescriptionEditor.java 2008-10-01 18:45:21 UTC (rev 5331) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterDescriptionEditor.java 2008-10-01 18:49:05 UTC (rev 5332) @@ -1,55 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import javax.swing.JTextField; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import net.sf.gridarta.script.parameter.PluginParameter; - -public class ParameterDescriptionEditor extends JTextField { - - private final PluginParameter<?, ?> parameter; - - private static final long serialVersionUID = 1L; - - public ParameterDescriptionEditor(final PluginParameter<?, ?> param) { - parameter = param; - setText(param.getDescription()); - getDocument().addDocumentListener(new DocumentListener() { - public void changedUpdate(final DocumentEvent e) { - change(); - } - - public void insertUpdate(final DocumentEvent e) { - change(); - } - - public void removeUpdate(final DocumentEvent e) { - change(); - } - - private void change() { - parameter.setDescription(getText()); - } - }); - } - -} // class ParameterDescriptionEditor Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterDescriptionEditor.java (from rev 5328, trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterDescriptionEditor.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterDescriptionEditor.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterDescriptionEditor.java 2008-10-01 18:49:05 UTC (rev 5332) @@ -0,0 +1,55 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import net.sf.gridarta.script.parameter.PluginParameter; + +public class ParameterDescriptionEditor extends JTextField { + + private final PluginParameter<?, ?> parameter; + + private static final long serialVersionUID = 1L; + + public ParameterDescriptionEditor(final PluginParameter<?, ?> param) { + parameter = param; + setText(param.getDescription()); + getDocument().addDocumentListener(new DocumentListener() { + public void changedUpdate(final DocumentEvent e) { + change(); + } + + public void insertUpdate(final DocumentEvent e) { + change(); + } + + public void removeUpdate(final DocumentEvent e) { + change(); + } + + private void change() { + parameter.setDescription(getText()); + } + }); + } + +} // class ParameterDescriptionEditor Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterDescriptionEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 18:57:24
|
Revision: 5333 http://gridarta.svn.sourceforge.net/gridarta/?rev=5333&view=rev Author: akirschbaum Date: 2008-10-01 18:57:15 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move MapParameterComboBoxModel to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterComboBoxModel.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterComboBoxModel.java Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterComboBoxModel.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterComboBoxModel.java 2008-10-01 18:49:05 UTC (rev 5332) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterComboBoxModel.java 2008-10-01 18:57:15 UTC (rev 5333) @@ -1,99 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.CMapViewBasic; -import cfeditor.map.MapArchObject; -import java.util.List; -import javax.swing.DefaultComboBoxModel; -import net.sf.gridarta.MapManager; -import net.sf.gridarta.map.MapControl; -import org.jetbrains.annotations.NotNull; - -public class MapParameterComboBoxModel extends DefaultComboBoxModel { - - private final Object currentMap = new Object(); - - private Object selected = null; - - private static final long serialVersionUID = 1L; - - /** - * The map manager to use. - */ - @NotNull - private final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager; - - /** - * Creates a new instance. - * @param mapManager the map manager to use - */ - public MapParameterComboBoxModel(@NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager) { - this.mapManager = mapManager; - } - - /** {@inheritDoc} */ - @Override - public Object getElementAt(final int index) { - if (index == 0) { - return currentMap; - } - - return mapManager.getOpenedMaps().get(index - 1); - } - - /** {@inheritDoc} */ - @Override - public int getIndexOf(final Object anObject) { - final List<MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>> maps = mapManager.getOpenedMaps(); - if (anObject == currentMap) { - return 0; - } - - for (int i = 0; i < maps.size(); i++) { - if (maps.get(i) == anObject) { - return i + 1; - } - } - - return -1; - } - - /** {@inheritDoc} */ - @Override - public Object getSelectedItem() { - return selected; - } - - /** {@inheritDoc} */ - @Override - public int getSize() { - return mapManager.getOpenedMaps().size() + 1; - } - - /** {@inheritDoc} */ - @Override - public void setSelectedItem(final Object anObject) { - selected = anObject; - } - -} // class MapParameterComboBoxModel Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2008-10-01 18:49:05 UTC (rev 5332) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2008-10-01 18:57:15 UTC (rev 5333) @@ -30,6 +30,7 @@ import javax.swing.JPanel; import net.sf.gridarta.MapManager; import net.sf.gridarta.gui.script.parameter.MapParameterCellRenderer; +import net.sf.gridarta.gui.script.parameter.MapParameterComboBoxModel; import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.MapParameter; import org.apache.log4j.Logger; @@ -49,7 +50,7 @@ public MapParameterView(final MapParameter<GameObject, MapArchObject, Archetype, CMapViewBasic> param, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager) { parameter = param; value = new JComboBox(); - final MapParameterComboBoxModel myModel = new MapParameterComboBoxModel(mapManager); + final MapParameterComboBoxModel<GameObject, MapArchObject, Archetype, CMapViewBasic> myModel = new MapParameterComboBoxModel<GameObject, MapArchObject, Archetype, CMapViewBasic>(mapManager); value.setModel(myModel); if (log.isDebugEnabled()) { log.debug("opened maps: " + mapManager.getOpenedMaps()); Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterComboBoxModel.java (from rev 5332, trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterComboBoxModel.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterComboBoxModel.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterComboBoxModel.java 2008-10-01 18:57:15 UTC (rev 5333) @@ -0,0 +1,99 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.util.List; +import javax.swing.DefaultComboBoxModel; +import net.sf.gridarta.MapManager; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.map.MapViewBasic; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.MapControl; +import org.jetbrains.annotations.NotNull; + +public class MapParameterComboBoxModel<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, V extends MapViewBasic<G, A, R, V>> extends DefaultComboBoxModel { + + private final Object currentMap = new Object(); + + private Object selected = null; + + private static final long serialVersionUID = 1L; + + /** + * The map manager to use. + */ + @NotNull + private final MapManager<G, A, R, V> mapManager; + + /** + * Creates a new instance. + * @param mapManager the map manager to use + */ + public MapParameterComboBoxModel(@NotNull final MapManager<G, A, R, V> mapManager) { + this.mapManager = mapManager; + } + + /** {@inheritDoc} */ + @Override + public Object getElementAt(final int index) { + if (index == 0) { + return currentMap; + } + + return mapManager.getOpenedMaps().get(index - 1); + } + + /** {@inheritDoc} */ + @Override + public int getIndexOf(final Object anObject) { + final List<MapControl<G, A, R, V>> maps = mapManager.getOpenedMaps(); + if (anObject == currentMap) { + return 0; + } + + for (int i = 0; i < maps.size(); i++) { + if (maps.get(i) == anObject) { + return i + 1; + } + } + + return -1; + } + + /** {@inheritDoc} */ + @Override + public Object getSelectedItem() { + return selected; + } + + /** {@inheritDoc} */ + @Override + public int getSize() { + return mapManager.getOpenedMaps().size() + 1; + } + + /** {@inheritDoc} */ + @Override + public void setSelectedItem(final Object anObject) { + selected = anObject; + } + +} // class MapParameterComboBoxModel Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterComboBoxModel.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 19:05:02
|
Revision: 5334 http://gridarta.svn.sourceforge.net/gridarta/?rev=5334&view=rev Author: akirschbaum Date: 2008-10-01 19:04:50 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move MapParameterView to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterView.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2008-10-01 18:57:15 UTC (rev 5333) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2008-10-01 19:04:50 UTC (rev 5334) @@ -1,92 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.CMapViewBasic; -import cfeditor.map.MapArchObject; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JPanel; -import net.sf.gridarta.MapManager; -import net.sf.gridarta.gui.script.parameter.MapParameterCellRenderer; -import net.sf.gridarta.gui.script.parameter.MapParameterComboBoxModel; -import net.sf.gridarta.gui.script.parameter.PluginParameterView; -import net.sf.gridarta.script.parameter.MapParameter; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; - -public class MapParameterView implements PluginParameterView<Object, Void, MapParameter<GameObject, MapArchObject, Archetype, CMapViewBasic>> { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(MapParameterView.class); - - private final MapParameter<GameObject, MapArchObject, Archetype, CMapViewBasic> parameter; - - private final JPanel config = new JPanel(); - - private final JComboBox value; - - public MapParameterView(final MapParameter<GameObject, MapArchObject, Archetype, CMapViewBasic> param, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager) { - parameter = param; - value = new JComboBox(); - final MapParameterComboBoxModel<GameObject, MapArchObject, Archetype, CMapViewBasic> myModel = new MapParameterComboBoxModel<GameObject, MapArchObject, Archetype, CMapViewBasic>(mapManager); - value.setModel(myModel); - if (log.isDebugEnabled()) { - log.debug("opened maps: " + mapManager.getOpenedMaps()); - } - value.setRenderer(new MapParameterCellRenderer(mapManager)); - value.addItemListener(new ItemListener() { - public void itemStateChanged(final ItemEvent e) { - if (e.getStateChange() == ItemEvent.SELECTED) { - if (value.getSelectedIndex() == 0) { - parameter.setValueToCurrent(); - } else { - parameter.setValue(value.getSelectedItem()); - } - } - } - }); - value.setSelectedItem(parameter.getValue()); - } - - /* (non-Javadoc) - * @see cfeditor.PluginParameterView#getValueComponent(java.lang.Object, cfeditor.PluginParameter) - */ - public JComponent getValueComponent(final Object value, final MapParameter<GameObject, MapArchObject, Archetype, CMapViewBasic> parameter) { - return this.value; - } - - /* (non-Javadoc) - * @see cfeditor.PluginParameterView#getConfigComponent(java.lang.Object, cfeditor.PluginParameter) - */ - public JComponent getConfigComponent(final Void config, final MapParameter<GameObject, MapArchObject, Archetype, CMapViewBasic> parameter) { - return this.config; - } - - /** {@inheritDoc} */ - public boolean setValue(@NotNull final String value) { - return false; // XXX: not yet implemented - } - -} // class MapParameterView Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 18:57:15 UTC (rev 5333) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 19:04:50 UTC (rev 5334) @@ -32,6 +32,7 @@ import net.sf.gridarta.gui.script.parameter.DoubleParameterView; import net.sf.gridarta.gui.script.parameter.FilterParameterView; import net.sf.gridarta.gui.script.parameter.IntegerParameterView; +import net.sf.gridarta.gui.script.parameter.MapParameterView; import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.gui.script.parameter.StringParameterView; import net.sf.gridarta.script.parameter.ArchParameter; @@ -99,7 +100,7 @@ /** {@inheritDoc} */ public void visit(final MapParameter parameter) { - view = new MapParameterView(parameter, mapManager); + view = new MapParameterView<GameObject, MapArchObject, Archetype, CMapViewBasic>(parameter, mapManager); } /** {@inheritDoc} */ Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterView.java (from rev 5333, trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterView.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterView.java 2008-10-01 19:04:50 UTC (rev 5334) @@ -0,0 +1,89 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JPanel; +import net.sf.gridarta.MapManager; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.map.MapViewBasic; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.script.parameter.MapParameter; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +public class MapParameterView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, V extends MapViewBasic<G, A, R, V>> implements PluginParameterView<Object, Void, MapParameter<G, A, R, V>> { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(MapParameterView.class); + + private final MapParameter<G, A, R, V> parameter; + + private final JPanel config = new JPanel(); + + private final JComboBox value; + + public MapParameterView(final MapParameter<G, A, R, V> param, @NotNull final MapManager<G, A, R, V> mapManager) { + parameter = param; + value = new JComboBox(); + final MapParameterComboBoxModel<G, A, R, V> myModel = new MapParameterComboBoxModel<G, A, R, V>(mapManager); + value.setModel(myModel); + if (log.isDebugEnabled()) { + log.debug("opened maps: " + mapManager.getOpenedMaps()); + } + value.setRenderer(new MapParameterCellRenderer(mapManager)); + value.addItemListener(new ItemListener() { + public void itemStateChanged(final ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + if (value.getSelectedIndex() == 0) { + parameter.setValueToCurrent(); + } else { + parameter.setValue(value.getSelectedItem()); + } + } + } + }); + value.setSelectedItem(parameter.getValue()); + } + + /* (non-Javadoc) + * @see cfeditor.PluginParameterView#getValueComponent(java.lang.Object, cfeditor.PluginParameter) + */ + public JComponent getValueComponent(final Object value, final MapParameter<G, A, R, V> parameter) { + return this.value; + } + + /* (non-Javadoc) + * @see cfeditor.PluginParameterView#getConfigComponent(java.lang.Object, cfeditor.PluginParameter) + */ + public JComponent getConfigComponent(final Void config, final MapParameter<G, A, R, V> parameter) { + return this.config; + } + + /** {@inheritDoc} */ + public boolean setValue(@NotNull final String value) { + return false; // XXX: not yet implemented + } + +} // class MapParameterView Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/MapParameterView.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 19:16:15
|
Revision: 5335 http://gridarta.svn.sourceforge.net/gridarta/?rev=5335&view=rev Author: akirschbaum Date: 2008-10-01 19:15:52 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move ArchComboBoxModel to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxEditor.java trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxModel.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxModel.java Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java 2008-10-01 19:04:50 UTC (rev 5334) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java 2008-10-01 19:15:52 UTC (rev 5335) @@ -27,6 +27,7 @@ import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; import net.sf.gridarta.gui.objectchooser.ObjectChooser; +import net.sf.gridarta.gui.script.parameter.ArchComboBoxModel; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -39,11 +40,11 @@ private final ArchComboBoxEditor archComboBoxEditor; - private final ArchComboBoxModel archComboBoxModel; + private final ArchComboBoxModel<GameObject, MapArchObject, Archetype> archComboBoxModel; - public ArchComboBox(@NotNull final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, @NotNull final ArchetypeSet<?, ?, Archetype> archetypeSet, @NotNull final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser) { + public ArchComboBox(@NotNull final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser) { setMaximumRowCount(4); - archComboBoxModel = new ArchComboBoxModel(archetypeSet); + archComboBoxModel = new ArchComboBoxModel<GameObject, MapArchObject, Archetype>(archetypeSet); archComboBoxEditor = new ArchComboBoxEditor(this, archComboBoxModel, objectChooser, gameObjectAttributesModel, archetypeSet); final ArchComboBoxCellRenderer cellRenderer = new ArchComboBoxCellRenderer(archComboBoxEditor, archetypeSet); //setPrototypeDisplayValue(cellRenderer.sizeTester); Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxEditor.java 2008-10-01 19:04:50 UTC (rev 5334) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxEditor.java 2008-10-01 19:15:52 UTC (rev 5335) @@ -45,13 +45,14 @@ import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; import net.sf.gridarta.gui.objectchooser.ObjectChooser; +import net.sf.gridarta.gui.script.parameter.ArchComboBoxModel; import org.jetbrains.annotations.Nullable; public class ArchComboBoxEditor implements ComboBoxEditor { private final ArchComboBox archComboBox; - private final ArchComboBoxModel archComboBoxModel; + private final ArchComboBoxModel<GameObject, MapArchObject, Archetype> archComboBoxModel; private final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser; @@ -69,7 +70,7 @@ private boolean locked = false; - public ArchComboBoxEditor(final ArchComboBox archComboBox, final ArchComboBoxModel archComboBoxModel, final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser, final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, final ArchetypeSet<?, ?, Archetype> archetypeSet) { + public ArchComboBoxEditor(final ArchComboBox archComboBox, final ArchComboBoxModel<GameObject, MapArchObject, Archetype> archComboBoxModel, final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser, final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, final ArchetypeSet<?, ?, Archetype> archetypeSet) { this.archComboBox = archComboBox; this.archComboBoxModel = archComboBoxModel; this.objectChooser = objectChooser; Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxModel.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxModel.java 2008-10-01 19:04:50 UTC (rev 5334) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxModel.java 2008-10-01 19:15:52 UTC (rev 5335) @@ -1,126 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import cfeditor.gameobject.Archetype; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; -import net.sf.gridarta.gameobject.ArchetypeSet; - -public class ArchComboBoxModel extends AbstractListModel implements ComboBoxModel { - - private Object value = null; - - private final Archetype[] archList; /*the current list*/ - - // FIXME: This constant looks pretty pointless. - private static final String CURRENT_FILTER = ""; - - private static final long serialVersionUID = 1L; - - public ArchComboBoxModel(final ArchetypeSet<?, ?, Archetype> archetypeSet) { - final Collection<Archetype> archetypes = archetypeSet.getArchetypes(); - archList = archetypes.toArray(new Archetype[archetypes.size()]); - Arrays.sort(archList, new Comparator<Archetype>() { - public int compare(final Archetype o1, final Archetype o2) { - return o1.getArchetypeName().toLowerCase().compareTo(o2.getArchetypeName().toLowerCase()); - } - }); - } - - public Object getSelectedItem() { - return value; - } - - public void setSelectedItem(final Object anItem) { - value = anItem; - } - - public int getSize() { - return archList.length; - } - - public Object getElementAt(final int index) { - return archList[index]; - } - - public void setFilter(final String filter) { - if (filter.startsWith(CURRENT_FILTER)) { - narrowFilter(filter); - } else if (CURRENT_FILTER.startsWith(filter)) { - enlargeFilter(filter); - } else { - final int p = getCommonPrefix(CURRENT_FILTER, filter); - enlargeFilter(filter.substring(0, p)); - narrowFilter(filter); - } - fireContentsChanged(this, 0, archList.length); - } - - private static int getCommonPrefix(final String s1, final String s2) { - int i = 0; - while (s1.length() > i && s2.length() > i && s1.charAt(i) == s2.charAt(i)) { - i++; - } - return i; - } - - private void enlargeFilter(final String filter) { - // "abcd" -> "abc" - } - - private void narrowFilter(final String filter) { - // "abc" -> "abcd" - } - - public Archetype getNearsetMatch(final String name) { - int pos = Arrays.binarySearch(archList, name, new Comparator<Object>() { - public int compare(final Object o1, final Object o2) { - final String s1; - if (o1 instanceof Archetype) { - s1 = ((Archetype) o1).getArchetypeName(); - } else { - s1 = o1.toString(); - } - final String s2; - if (o2 instanceof Archetype) { - s2 = ((Archetype) o2).getArchetypeName(); - } else { - s2 = o2.toString(); - } - return s1.compareToIgnoreCase(s2); - } - }); - if (pos < 0) { - pos = -(pos + 1); - } - if (pos >= archList.length) { - pos = archList.length - 1; - } - if (pos < 0) { - pos = 0; - } - return archList[pos]; - } - -} // class ArchComboBoxModel Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java 2008-10-01 19:04:50 UTC (rev 5334) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java 2008-10-01 19:15:52 UTC (rev 5335) @@ -47,7 +47,7 @@ private final ArchParameter<GameObject, MapArchObject, Archetype> parameter; - public ArchParameterView(final ArchParameter<GameObject, MapArchObject, Archetype> param, @NotNull final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, @NotNull final ArchetypeSet<?, ?, Archetype> archetypeSet, @NotNull final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser) { + public ArchParameterView(final ArchParameter<GameObject, MapArchObject, Archetype> param, @NotNull final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser) { this.archetypeSet = archetypeSet; value = new ArchComboBox(gameObjectAttributesModel, archetypeSet, objectChooser); parameter = param; Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxModel.java (from rev 5332, trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxModel.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxModel.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxModel.java 2008-10-01 19:15:52 UTC (rev 5335) @@ -0,0 +1,128 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import javax.swing.AbstractListModel; +import javax.swing.ComboBoxModel; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.ArchetypeSet; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.map.MapArchObject; + +public class ArchComboBoxModel<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractListModel implements ComboBoxModel { + + private Object value = null; + + private final R[] archList; /*the current list*/ + + // FIXME: This constant looks pretty pointless. + private static final String CURRENT_FILTER = ""; + + private static final long serialVersionUID = 1L; + + public ArchComboBoxModel(final ArchetypeSet<G, A, R> archetypeSet) { + final Collection<R> archetypes = archetypeSet.getArchetypes(); + archList = archetypes.toArray((R[]) new Archetype<?, ?, ?>[archetypes.size()]); + Arrays.sort(archList, new Comparator<R>() { + public int compare(final R o1, final R o2) { + return o1.getArchetypeName().toLowerCase().compareTo(o2.getArchetypeName().toLowerCase()); + } + }); + } + + public Object getSelectedItem() { + return value; + } + + public void setSelectedItem(final Object anItem) { + value = anItem; + } + + public int getSize() { + return archList.length; + } + + public Object getElementAt(final int index) { + return archList[index]; + } + + public void setFilter(final String filter) { + if (filter.startsWith(CURRENT_FILTER)) { + narrowFilter(filter); + } else if (CURRENT_FILTER.startsWith(filter)) { + enlargeFilter(filter); + } else { + final int p = getCommonPrefix(CURRENT_FILTER, filter); + enlargeFilter(filter.substring(0, p)); + narrowFilter(filter); + } + fireContentsChanged(this, 0, archList.length); + } + + private static int getCommonPrefix(final String s1, final String s2) { + int i = 0; + while (s1.length() > i && s2.length() > i && s1.charAt(i) == s2.charAt(i)) { + i++; + } + return i; + } + + private void enlargeFilter(final String filter) { + // "abcd" -> "abc" + } + + private void narrowFilter(final String filter) { + // "abc" -> "abcd" + } + + public R getNearsetMatch(final String name) { + int pos = Arrays.binarySearch(archList, name, new Comparator<Object>() { + public int compare(final Object o1, final Object o2) { + final String s1; + if (o1 instanceof Archetype) { + s1 = ((Archetype<?, ?, ?>) o1).getArchetypeName(); + } else { + s1 = o1.toString(); + } + final String s2; + if (o2 instanceof Archetype) { + s2 = ((Archetype<?, ?, ?>) o2).getArchetypeName(); + } else { + s2 = o2.toString(); + } + return s1.compareToIgnoreCase(s2); + } + }); + if (pos < 0) { + pos = -(pos + 1); + } + if (pos >= archList.length) { + pos = archList.length - 1; + } + if (pos < 0) { + pos = 0; + } + return archList[pos]; + } + +} // class ArchComboBoxModel Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxModel.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 19:36:56
|
Revision: 5336 http://gridarta.svn.sourceforge.net/gridarta/?rev=5336&view=rev Author: akirschbaum Date: 2008-10-01 19:36:46 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move ArchComboBox and related classes to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBox.java trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxCellRenderer.java trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxEditor.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxCellRenderer.java trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxEditor.java Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java 2008-10-01 19:15:52 UTC (rev 5335) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java 2008-10-01 19:36:46 UTC (rev 5336) @@ -1,73 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.map.MapArchObject; -import java.awt.Dimension; -import javax.swing.JComboBox; -import net.sf.gridarta.gameobject.ArchetypeSet; -import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; -import net.sf.gridarta.gui.objectchooser.ObjectChooser; -import net.sf.gridarta.gui.script.parameter.ArchComboBoxModel; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; - -public class ArchComboBox extends JComboBox { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ArchComboBox.class); - - private static final long serialVersionUID = 1L; - - private final ArchComboBoxEditor archComboBoxEditor; - - private final ArchComboBoxModel<GameObject, MapArchObject, Archetype> archComboBoxModel; - - public ArchComboBox(@NotNull final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser) { - setMaximumRowCount(4); - archComboBoxModel = new ArchComboBoxModel<GameObject, MapArchObject, Archetype>(archetypeSet); - archComboBoxEditor = new ArchComboBoxEditor(this, archComboBoxModel, objectChooser, gameObjectAttributesModel, archetypeSet); - final ArchComboBoxCellRenderer cellRenderer = new ArchComboBoxCellRenderer(archComboBoxEditor, archetypeSet); - //setPrototypeDisplayValue(cellRenderer.sizeTester); - setRenderer(cellRenderer); - setModel(archComboBoxModel); - setEditable(true); - setEditor(archComboBoxEditor); - final Dimension d = getPreferredSize(); - if (log.isDebugEnabled()) { - log.debug("Preferred size: " + d); - } - setPreferredSize(new Dimension(d.width, archComboBoxEditor.getEditorComponent().getPreferredSize().height)); - if (log.isDebugEnabled()) { - log.debug("NEW Preferred size: " + getPreferredSize()); - } - } - - public void editorEntryChange() { - archComboBoxEditor.lockEditor(); - final Archetype nearestMatch = archComboBoxModel.getNearsetMatch(archComboBoxEditor.getEditor().getText()); - setSelectedItem(nearestMatch); - archComboBoxEditor.setItem(nearestMatch); - archComboBoxEditor.unlockEditor(); - } - -} // class ArchComboBox Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxCellRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxCellRenderer.java 2008-10-01 19:15:52 UTC (rev 5335) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxCellRenderer.java 2008-10-01 19:36:46 UTC (rev 5336) @@ -1,83 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import cfeditor.gameobject.Archetype; -import java.awt.Component; -import javax.swing.DefaultListCellRenderer; -import javax.swing.JList; -import net.sf.gridarta.gameobject.ArchetypeSet; -import org.jetbrains.annotations.NotNull; - -public class ArchComboBoxCellRenderer extends DefaultListCellRenderer { - - public static final String SIZE_TESTER = "**Sizetester**"; - - private static final long serialVersionUID = 1L; - - @NotNull - private final ArchComboBoxEditor archComboBoxEditor; - - /** - * The archetype set to use. - */ - @NotNull - private final ArchetypeSet<?, ?, Archetype> archetypeSet; - - /** - * Creates a new instance. - * @param archComboBoxEditor the instance to use - * @param archetypeSet the archetype set to use - */ - public ArchComboBoxCellRenderer(@NotNull final ArchComboBoxEditor archComboBoxEditor, @NotNull final ArchetypeSet<?, ?, Archetype> archetypeSet) { - this.archComboBoxEditor = archComboBoxEditor; - this.archetypeSet = archetypeSet; - } - - /* This is the only method defined by ListCellRenderer. We just - * reconfigure the Jlabel each time we're called. - */ - @Override - public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { - if (SIZE_TESTER.equals(value)) { - return archComboBoxEditor.getEditorComponent(); - } - /* The DefaultListCellRenderer class will take care of - * the JLabels text property, it's foreground and background - *colors, and so on. - */ - super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - - /* We additionally set the JLabels icon property here. - */ - final Archetype arch = (Archetype) value; - if (arch == null) { - setText(""); - setIcon(null); - return this; - } - setText(arch.getArchetypeName()); - - setIcon(archetypeSet.getFace(arch)); - - return this; - } - -} // class ArchComboBoxCellRenderer Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxEditor.java 2008-10-01 19:15:52 UTC (rev 5335) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxEditor.java 2008-10-01 19:36:46 UTC (rev 5336) @@ -1,255 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.map.MapArchObject; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import javax.swing.ComboBoxEditor; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JTextField; -import javax.swing.border.LineBorder; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import net.sf.gridarta.CommonConstants; -import net.sf.gridarta.gameobject.ArchetypeSet; -import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; -import net.sf.gridarta.gui.objectchooser.ObjectChooser; -import net.sf.gridarta.gui.script.parameter.ArchComboBoxModel; -import org.jetbrains.annotations.Nullable; - -public class ArchComboBoxEditor implements ComboBoxEditor { - - private final ArchComboBox archComboBox; - - private final ArchComboBoxModel<GameObject, MapArchObject, Archetype> archComboBoxModel; - - private final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser; - - private final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel; - - private final ArchetypeSet<?, ?, Archetype> archetypeSet; - - private JPanel editorPanel = null; - - private JLabel icon = null; - - private JTextField editor = null; - - private JPopupMenu popup; - - private boolean locked = false; - - public ArchComboBoxEditor(final ArchComboBox archComboBox, final ArchComboBoxModel<GameObject, MapArchObject, Archetype> archComboBoxModel, final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser, final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, final ArchetypeSet<?, ?, Archetype> archetypeSet) { - this.archComboBox = archComboBox; - this.archComboBoxModel = archComboBoxModel; - this.objectChooser = objectChooser; - this.gameObjectAttributesModel = gameObjectAttributesModel; - this.archetypeSet = archetypeSet; - } - - public synchronized void lockEditor() { - locked = true; - } - - public synchronized void unlockEditor() { - locked = false; - } - - private synchronized void buildPanel() { - if (editorPanel == null) { - editorPanel = new JPanel(new GridBagLayout()); - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.gridx = 0; - gbc.gridy = 0; - gbc.weightx = 1.0; - gbc.gridwidth = 4; - gbc.fill = GridBagConstraints.HORIZONTAL; - editor = new JTextField(); - editorPanel.add(editor, gbc); - gbc.gridy = 1; - gbc.gridwidth = 1; - gbc.weightx = 0.0; - gbc.gridx = 1; - final JButton fromSelect = new JButton("From tile selection"); - fromSelect.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - try { - final Archetype ao = archComboBoxModel.getNearsetMatch(objectChooser.getSelection().getArchetypeName()); - archComboBox.setSelectedItem(ao); - setItem(ao); - } catch (final Exception ex) {//null pointer exception - } - } - }); - editorPanel.add(fromSelect, gbc); - final JButton fromActive = new JButton("From map selection"); - fromActive.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - try { - final Archetype ao = archComboBoxModel.getNearsetMatch(gameObjectAttributesModel.getSelectedGameObject().getArchetypeName()); - archComboBox.setSelectedItem(ao); - setItem(ao); - } catch (final Exception ex) {//null pointer exception - } - } - }); - gbc.gridx = 2; - editorPanel.add(fromActive, gbc); - editor.addMouseListener(new MouseListener() { - public void mouseClicked(final MouseEvent e) { - } - - public void mouseEntered(final MouseEvent e) { - //popup.setLocation(p.x, p.y+archComboBoxEditor.getHeight()+5); - popup.setPreferredSize(null); - final Dimension d = popup.getPreferredSize(); - final Dimension p = editorPanel.getSize(); - if (d.width < p.width) { - d.width = p.width; - } - if (d.height < p.height) { - d.height = p.height; - } - popup.setPreferredSize(d); - popup.show(editorPanel, 0, editorPanel.getHeight() + 5); - } - - public void mouseExited(final MouseEvent e) { - popup.setVisible(false); - } - - public void mousePressed(final MouseEvent e) { - } - - public void mouseReleased(final MouseEvent e) { - } - }); - editor.setEditable(true); - editor.getDocument().addDocumentListener(new DocumentListener() { - public void changedUpdate(final DocumentEvent e) { - archComboBox.editorEntryChange(); - } - - public void insertUpdate(final DocumentEvent e) { - archComboBox.editorEntryChange(); - } - - public void removeUpdate(final DocumentEvent e) { - archComboBox.editorEntryChange(); - } - }); - icon = new JLabel(); - popup = new JPopupMenu(); - popup.setLayout(new FlowLayout()); - popup.setBackground(CommonConstants.BG_COLOR); - popup.setBorder(new LineBorder(Color.black)); - popup.add(icon); - popup.setFocusable(false); - archComboBox.setBackground(CommonConstants.BG_COLOR); - } - } - - /* (non-Javadoc) - * @see javax.swing.ComboBoxEditor#selectAll() - */ - public void selectAll() { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see javax.swing.ComboBoxEditor#getEditorComponent() - */ - public Component getEditorComponent() { - if (editorPanel == null) { - buildPanel(); - } - return editorPanel; - } - - /* (non-Javadoc) - * @see javax.swing.ComboBoxEditor#addActionListener(java.awt.event.ActionListener) - */ - public void addActionListener(final ActionListener l) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see javax.swing.ComboBoxEditor#removeActionListener(java.awt.event.ActionListener) - */ - public void removeActionListener(final ActionListener l) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see javax.swing.ComboBoxEditor#getItem() - */ - @Nullable - public Object getItem() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see javax.swing.ComboBoxEditor#setItem(java.lang.Object) - */ - public void setItem(final Object anObject) { - final Archetype arch = (Archetype) anObject; - if (anObject == null) { - icon.setIcon(null); - icon.setText("No item selected"); - } else { - icon.setIcon(archetypeSet.getFace(arch)); - } - - if (arch == null) { - icon.setText(""); - if (!locked) { - editor.setText(""); - } - } else { - if (!locked) { - editor.setText(arch.getArchetypeName()); - } - icon.setText(arch.getArchetypeName()); - } - } - - public JTextField getEditor() { - return editor; - } - -} // class ArchComboBoxEditor Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java 2008-10-01 19:15:52 UTC (rev 5335) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java 2008-10-01 19:36:46 UTC (rev 5336) @@ -29,6 +29,7 @@ import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; import net.sf.gridarta.gui.objectchooser.ObjectChooser; +import net.sf.gridarta.gui.script.parameter.ArchComboBox; import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.script.parameter.ArchParameter; import org.jetbrains.annotations.NotNull; @@ -43,7 +44,7 @@ private final JPanel config = new JPanel(); - private final ArchComboBox value; + private final ArchComboBox<GameObject, MapArchObject, Archetype> value; private final ArchParameter<GameObject, MapArchObject, Archetype> parameter; Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBox.java (from rev 5335, trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBox.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBox.java 2008-10-01 19:36:46 UTC (rev 5336) @@ -0,0 +1,72 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.awt.Dimension; +import javax.swing.JComboBox; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.ArchetypeSet; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; +import net.sf.gridarta.gui.objectchooser.ObjectChooser; +import net.sf.gridarta.map.MapArchObject; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +public class ArchComboBox<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends JComboBox { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(ArchComboBox.class); + + private static final long serialVersionUID = 1L; + + private final ArchComboBoxEditor<G, A, R> archComboBoxEditor; + + private final ArchComboBoxModel<G, A, R> archComboBoxModel; + + public ArchComboBox(@NotNull final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final ObjectChooser<G, A, R> objectChooser) { + setMaximumRowCount(4); + archComboBoxModel = new ArchComboBoxModel<G, A, R>(archetypeSet); + archComboBoxEditor = new ArchComboBoxEditor(this, archComboBoxModel, objectChooser, gameObjectAttributesModel, archetypeSet); + final ArchComboBoxCellRenderer<G, A, R> cellRenderer = new ArchComboBoxCellRenderer<G, A, R>(archComboBoxEditor, archetypeSet); + //setPrototypeDisplayValue(cellRenderer.sizeTester); + setRenderer(cellRenderer); + setModel(archComboBoxModel); + setEditable(true); + setEditor(archComboBoxEditor); + final Dimension d = getPreferredSize(); + if (log.isDebugEnabled()) { + log.debug("Preferred size: " + d); + } + setPreferredSize(new Dimension(d.width, archComboBoxEditor.getEditorComponent().getPreferredSize().height)); + if (log.isDebugEnabled()) { + log.debug("NEW Preferred size: " + getPreferredSize()); + } + } + + public void editorEntryChange() { + archComboBoxEditor.lockEditor(); + final R nearestMatch = archComboBoxModel.getNearsetMatch(archComboBoxEditor.getEditor().getText()); + setSelectedItem(nearestMatch); + archComboBoxEditor.setItem(nearestMatch); + archComboBoxEditor.unlockEditor(); + } + +} // class ArchComboBox Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBox.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxCellRenderer.java (from rev 5332, trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxCellRenderer.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxCellRenderer.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxCellRenderer.java 2008-10-01 19:36:46 UTC (rev 5336) @@ -0,0 +1,85 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.awt.Component; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.ArchetypeSet; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.map.MapArchObject; +import org.jetbrains.annotations.NotNull; + +public class ArchComboBoxCellRenderer<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DefaultListCellRenderer { + + public static final String SIZE_TESTER = "**Sizetester**"; + + private static final long serialVersionUID = 1L; + + @NotNull + private final ArchComboBoxEditor archComboBoxEditor; + + /** + * The archetype set to use. + */ + @NotNull + private final ArchetypeSet<G, A, R> archetypeSet; + + /** + * Creates a new instance. + * @param archComboBoxEditor the instance to use + * @param archetypeSet the archetype set to use + */ + public ArchComboBoxCellRenderer(@NotNull final ArchComboBoxEditor archComboBoxEditor, @NotNull final ArchetypeSet<G, A, R> archetypeSet) { + this.archComboBoxEditor = archComboBoxEditor; + this.archetypeSet = archetypeSet; + } + + /* This is the only method defined by ListCellRenderer. We just + * reconfigure the Jlabel each time we're called. + */ + @Override + public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { + if (SIZE_TESTER.equals(value)) { + return archComboBoxEditor.getEditorComponent(); + } + /* The DefaultListCellRenderer class will take care of + * the JLabels text property, it's foreground and background + *colors, and so on. + */ + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + + /* We additionally set the JLabels icon property here. + */ + final R arch = (R) value; + if (arch == null) { + setText(""); + setIcon(null); + return this; + } + setText(arch.getArchetypeName()); + + setIcon(archetypeSet.getFace(arch)); + + return this; + } + +} // class ArchComboBoxCellRenderer Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxEditor.java (from rev 5335, trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBoxEditor.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxEditor.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxEditor.java 2008-10-01 19:36:46 UTC (rev 5336) @@ -0,0 +1,254 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import javax.swing.ComboBoxEditor; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JTextField; +import javax.swing.border.LineBorder; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import net.sf.gridarta.CommonConstants; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.ArchetypeSet; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; +import net.sf.gridarta.gui.objectchooser.ObjectChooser; +import net.sf.gridarta.map.MapArchObject; +import org.jetbrains.annotations.Nullable; + +public class ArchComboBoxEditor<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements ComboBoxEditor { + + private final ArchComboBox<G, A, R> archComboBox; + + private final ArchComboBoxModel<G, A, R> archComboBoxModel; + + private final ObjectChooser<G, A, R> objectChooser; + + private final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel; + + private final ArchetypeSet<G, A, R> archetypeSet; + + private JPanel editorPanel = null; + + private JLabel icon = null; + + private JTextField editor = null; + + private JPopupMenu popup; + + private boolean locked = false; + + public ArchComboBoxEditor(final ArchComboBox<G, A, R> archComboBox, final ArchComboBoxModel<G, A, R> archComboBoxModel, final ObjectChooser<G, A, R> objectChooser, final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel, final ArchetypeSet<G, A, R> archetypeSet) { + this.archComboBox = archComboBox; + this.archComboBoxModel = archComboBoxModel; + this.objectChooser = objectChooser; + this.gameObjectAttributesModel = gameObjectAttributesModel; + this.archetypeSet = archetypeSet; + } + + public synchronized void lockEditor() { + locked = true; + } + + public synchronized void unlockEditor() { + locked = false; + } + + private synchronized void buildPanel() { + if (editorPanel == null) { + editorPanel = new JPanel(new GridBagLayout()); + final GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 0; + gbc.weightx = 1.0; + gbc.gridwidth = 4; + gbc.fill = GridBagConstraints.HORIZONTAL; + editor = new JTextField(); + editorPanel.add(editor, gbc); + gbc.gridy = 1; + gbc.gridwidth = 1; + gbc.weightx = 0.0; + gbc.gridx = 1; + final JButton fromSelect = new JButton("From tile selection"); + fromSelect.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + try { + final R ao = archComboBoxModel.getNearsetMatch(objectChooser.getSelection().getArchetypeName()); + archComboBox.setSelectedItem(ao); + setItem(ao); + } catch (final Exception ex) {//null pointer exception + } + } + }); + editorPanel.add(fromSelect, gbc); + final JButton fromActive = new JButton("From map selection"); + fromActive.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + try { + final R ao = archComboBoxModel.getNearsetMatch(gameObjectAttributesModel.getSelectedGameObject().getArchetypeName()); + archComboBox.setSelectedItem(ao); + setItem(ao); + } catch (final Exception ex) {//null pointer exception + } + } + }); + gbc.gridx = 2; + editorPanel.add(fromActive, gbc); + editor.addMouseListener(new MouseListener() { + public void mouseClicked(final MouseEvent e) { + } + + public void mouseEntered(final MouseEvent e) { + //popup.setLocation(p.x, p.y+archComboBoxEditor.getHeight()+5); + popup.setPreferredSize(null); + final Dimension d = popup.getPreferredSize(); + final Dimension p = editorPanel.getSize(); + if (d.width < p.width) { + d.width = p.width; + } + if (d.height < p.height) { + d.height = p.height; + } + popup.setPreferredSize(d); + popup.show(editorPanel, 0, editorPanel.getHeight() + 5); + } + + public void mouseExited(final MouseEvent e) { + popup.setVisible(false); + } + + public void mousePressed(final MouseEvent e) { + } + + public void mouseReleased(final MouseEvent e) { + } + }); + editor.setEditable(true); + editor.getDocument().addDocumentListener(new DocumentListener() { + public void changedUpdate(final DocumentEvent e) { + archComboBox.editorEntryChange(); + } + + public void insertUpdate(final DocumentEvent e) { + archComboBox.editorEntryChange(); + } + + public void removeUpdate(final DocumentEvent e) { + archComboBox.editorEntryChange(); + } + }); + icon = new JLabel(); + popup = new JPopupMenu(); + popup.setLayout(new FlowLayout()); + popup.setBackground(CommonConstants.BG_COLOR); + popup.setBorder(new LineBorder(Color.black)); + popup.add(icon); + popup.setFocusable(false); + archComboBox.setBackground(CommonConstants.BG_COLOR); + } + } + + /* (non-Javadoc) + * @see javax.swing.ComboBoxEditor#selectAll() + */ + public void selectAll() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.swing.ComboBoxEditor#getEditorComponent() + */ + public Component getEditorComponent() { + if (editorPanel == null) { + buildPanel(); + } + return editorPanel; + } + + /* (non-Javadoc) + * @see javax.swing.ComboBoxEditor#addActionListener(java.awt.event.ActionListener) + */ + public void addActionListener(final ActionListener l) { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.swing.ComboBoxEditor#removeActionListener(java.awt.event.ActionListener) + */ + public void removeActionListener(final ActionListener l) { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.swing.ComboBoxEditor#getItem() + */ + @Nullable + public Object getItem() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.swing.ComboBoxEditor#setItem(java.lang.Object) + */ + public void setItem(final Object anObject) { + final R arch = (R) anObject; + if (anObject == null) { + icon.setIcon(null); + icon.setText("No item selected"); + } else { + icon.setIcon(archetypeSet.getFace(arch)); + } + + if (arch == null) { + icon.setText(""); + if (!locked) { + editor.setText(""); + } + } else { + if (!locked) { + editor.setText(arch.getArchetypeName()); + } + icon.setText(arch.getArchetypeName()); + } + } + + public JTextField getEditor() { + return editor; + } + +} // class ArchComboBoxEditor Property changes on: trunk/src/app/net/sf/gridarta/gui/script/parameter/ArchComboBoxEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 19:59:37
|
Revision: 5339 http://gridarta.svn.sourceforge.net/gridarta/?rev=5339&view=rev Author: akirschbaum Date: 2008-10-01 19:59:25 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move PluginParameterViewFactory to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java trunk/crossfire/src/cfeditor/gui/script/ScriptView.java trunk/crossfire/src/cfeditor/script/ScriptController.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/parameter/PluginParameterViewFactory.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-01 19:50:48 UTC (rev 5338) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-01 19:59:25 UTC (rev 5339) @@ -32,7 +32,6 @@ import cfeditor.gui.map.DefaultMapPropertiesDialogFactory; import cfeditor.gui.map.DefaultRendererFactory; import cfeditor.gui.prefs.ResPrefs; -import cfeditor.gui.script.parameter.PluginParameterViewFactory; import cfeditor.map.DefaultMapControlFactory; import cfeditor.map.MapArchObject; import cfeditor.script.ScriptController; @@ -72,6 +71,7 @@ import net.sf.gridarta.gui.prefs.MapValidatorPrefs; import net.sf.gridarta.gui.prefs.MiscPrefs; import net.sf.gridarta.gui.prefs.UpdatePrefs; +import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; import net.sf.gridarta.io.ConfigFileUtils; import net.sf.gridarta.io.GameObjectParser; @@ -217,7 +217,7 @@ ((DefaultGridartaObjectsFactory) gridartaObjectsFactory).setFilterControl(filterControl); final ScriptParameters scriptParameters = new ScriptParameters(archetypeSet, globalSettings, mapManager, validators); final NamedFilterList defaultFilterList = new NamedFilterList(Collections.<NamedGameObjectMatcher>emptyList()); - final PluginParameterViewFactory pluginParameterViewFactory = new PluginParameterViewFactory(archetypeSet, gameObjectAttributesModel, objectChooser, defaultFilterList, mapManager); + final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory = new PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic>(archetypeSet, gameObjectAttributesModel, objectChooser, defaultFilterList, mapManager); scriptControl = new ScriptController(filterControl, scriptParameters, getMainView(), pluginParameterViewFactory); } Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 19:50:48 UTC (rev 5338) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 19:59:25 UTC (rev 5339) @@ -20,7 +20,10 @@ package cfeditor.gui.script; import cfeditor.IGUIConstants; -import cfeditor.gui.script.parameter.PluginParameterViewFactory; +import cfeditor.gameobject.Archetype; +import cfeditor.gameobject.GameObject; +import cfeditor.gui.map.CMapViewBasic; +import cfeditor.map.MapArchObject; import cfeditor.script.ScriptController; import java.awt.BorderLayout; import java.awt.Component; @@ -54,6 +57,7 @@ import net.sf.gridarta.gui.script.parameter.ParameterNameEditor; import net.sf.gridarta.gui.script.parameter.ParameterTypeEditor; import net.sf.gridarta.gui.script.parameter.PluginParameterView; +import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.utils.GUIUtils; import net.sf.gridarta.script.ScriptModel; import net.sf.gridarta.script.parameter.NoSuchParameterException; @@ -67,7 +71,7 @@ private static final Logger log = Logger.getLogger(ScriptEditor.class); @NotNull - private final PluginParameterViewFactory pluginParameterViewFactory; + private final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory; private final JPanel paramTable; @@ -129,7 +133,7 @@ * @param script the script object to edit * @param control the associated script control instance */ - public ScriptEditor(final ScriptModel script, final ScriptController control, final PluginParameterViewFactory pluginParameterViewFactory) { + public ScriptEditor(final ScriptModel script, final ScriptController control, final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { this.script = script; this.pluginParameterViewFactory = pluginParameterViewFactory; final JTabbedPane tabs = new JTabbedPane(); Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 19:50:48 UTC (rev 5338) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 19:59:25 UTC (rev 5339) @@ -19,7 +19,10 @@ package cfeditor.gui.script; -import cfeditor.gui.script.parameter.PluginParameterViewFactory; +import cfeditor.gameobject.Archetype; +import cfeditor.gameobject.GameObject; +import cfeditor.gui.map.CMapViewBasic; +import cfeditor.map.MapArchObject; import cfeditor.script.ScriptControlListener; import cfeditor.script.ScriptController; import java.awt.BorderLayout; @@ -41,6 +44,7 @@ import javax.swing.border.LineBorder; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.script.ScriptModel; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -60,7 +64,7 @@ private final ScriptController scriptController; - private final PluginParameterViewFactory pluginParameterViewFactory; + private final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory; private final Map<ScriptModel, ScriptEditor> components = new HashMap<ScriptModel, ScriptEditor>(); @@ -70,7 +74,7 @@ * Creates a ScriptManager. * @param scriptController ScriptController to base this ScriptManager on. */ - public ScriptManager(final ScriptController scriptController, @NotNull final PluginParameterViewFactory pluginParameterViewFactory) { + public ScriptManager(final ScriptController scriptController, @NotNull final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { super("Editor plugins management"); this.scriptController = scriptController; this.pluginParameterViewFactory = pluginParameterViewFactory; Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 19:50:48 UTC (rev 5338) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 19:59:25 UTC (rev 5339) @@ -21,7 +21,10 @@ import bsh.ConsoleInterface; import bsh.util.JConsole; -import cfeditor.gui.script.parameter.PluginParameterViewFactory; +import cfeditor.gameobject.Archetype; +import cfeditor.gameobject.GameObject; +import cfeditor.gui.map.CMapViewBasic; +import cfeditor.map.MapArchObject; import cfeditor.script.ScriptControlListener; import cfeditor.script.ScriptController; import java.awt.BorderLayout; @@ -40,6 +43,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import net.sf.gridarta.gui.script.parameter.PluginParameterView; +import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.gridarta.script.ScriptModel; import net.sf.gridarta.script.parameter.PluginParameter; @@ -70,7 +74,7 @@ private final Component parent; @NotNull - private final PluginParameterViewFactory pluginParameterViewFactory; + private final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory; /** The menu to add script commands to. */ @Nullable @@ -112,7 +116,7 @@ * @warning Creating a view from a controller instead of a model is error * prone. */ - public ScriptView(final ScriptController control, @NotNull final Component parent, @NotNull final PluginParameterViewFactory pluginParameterViewFactory) { + public ScriptView(final ScriptController control, @NotNull final Component parent, @NotNull final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { this.control = control; this.parent = parent; this.pluginParameterViewFactory = pluginParameterViewFactory; Deleted: trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 19:50:48 UTC (rev 5338) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 19:59:25 UTC (rev 5339) @@ -1,133 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script.parameter; - -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.CMapViewBasic; -import cfeditor.map.MapArchObject; -import net.sf.gridarta.MapManager; -import net.sf.gridarta.filter.NamedFilterList; -import net.sf.gridarta.gameobject.ArchetypeSet; -import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; -import net.sf.gridarta.gui.objectchooser.ObjectChooser; -import net.sf.gridarta.gui.script.parameter.ArchParameterView; -import net.sf.gridarta.gui.script.parameter.BooleanParameterView; -import net.sf.gridarta.gui.script.parameter.DoubleParameterView; -import net.sf.gridarta.gui.script.parameter.FilterParameterView; -import net.sf.gridarta.gui.script.parameter.IntegerParameterView; -import net.sf.gridarta.gui.script.parameter.MapParameterView; -import net.sf.gridarta.gui.script.parameter.PluginParameterView; -import net.sf.gridarta.gui.script.parameter.StringParameterView; -import net.sf.gridarta.script.parameter.ArchParameter; -import net.sf.gridarta.script.parameter.BooleanParameter; -import net.sf.gridarta.script.parameter.DoubleParameter; -import net.sf.gridarta.script.parameter.FilterParameter; -import net.sf.gridarta.script.parameter.IntegerParameter; -import net.sf.gridarta.script.parameter.MapParameter; -import net.sf.gridarta.script.parameter.PluginParameter; -import net.sf.gridarta.script.parameter.PluginParameterVisitor; -import net.sf.gridarta.script.parameter.StringParameter; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Factory for creating {@link PluginParameterView} instances. - * @author Andreas Kirschbaum - */ -public class PluginParameterViewFactory { - - @NotNull - private final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet; - - @NotNull - private final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel; - - @NotNull - private final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser; - - @NotNull - private final NamedFilterList defaultFilterList; - - @NotNull - private final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager; - - @Nullable - private PluginParameterView view = null; - - private final PluginParameterVisitor<GameObject, MapArchObject, Archetype, CMapViewBasic> visitor = new PluginParameterVisitor<GameObject, MapArchObject, Archetype, CMapViewBasic>() { - - /** {@inheritDoc} */ - public void visit(final ArchParameter<GameObject, MapArchObject, Archetype> parameter) { - view = new ArchParameterView<GameObject, MapArchObject, Archetype>(parameter, gameObjectAttributesModel, archetypeSet, objectChooser); - } - - /** {@inheritDoc} */ - public void visit(final BooleanParameter parameter) { - view = new BooleanParameterView(parameter); - } - - /** {@inheritDoc} */ - public void visit(final DoubleParameter parameter) { - view = new DoubleParameterView(parameter); - } - - /** {@inheritDoc} */ - public void visit(final FilterParameter parameter) { - view = new FilterParameterView(defaultFilterList); // XXX: does not use "parameter"? - } - - /** {@inheritDoc} */ - public void visit(final IntegerParameter parameter) { - view = new IntegerParameterView(parameter); - } - - /** {@inheritDoc} */ - public void visit(final MapParameter<GameObject, MapArchObject, Archetype, CMapViewBasic> parameter) { - view = new MapParameterView<GameObject, MapArchObject, Archetype, CMapViewBasic>(parameter, mapManager); - } - - /** {@inheritDoc} */ - public void visit(final StringParameter parameter) { - view = new StringParameterView(parameter); - } - - }; - - /** - * Creates a new instance. - */ - public PluginParameterViewFactory(@NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, @NotNull final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser, @NotNull final NamedFilterList defaultFilterList, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager) { - this.archetypeSet = archetypeSet; - this.gameObjectAttributesModel = gameObjectAttributesModel; - this.objectChooser = objectChooser; - this.defaultFilterList = defaultFilterList; - this.mapManager = mapManager; - } - - @NotNull - public PluginParameterView getView(@NotNull final PluginParameter<?, ?> parameter) { - view = null; - parameter.visit(visitor); - assert view != null; - return view; - } - -} // class PluginParameterViewFactory Modified: trunk/crossfire/src/cfeditor/script/ScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 19:50:48 UTC (rev 5338) +++ trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 19:59:25 UTC (rev 5339) @@ -27,7 +27,6 @@ import cfeditor.gameobject.GameObject; import cfeditor.gui.map.CMapViewBasic; import cfeditor.gui.script.ScriptView; -import cfeditor.gui.script.parameter.PluginParameterViewFactory; import cfeditor.map.MapArchObject; import java.awt.Component; import java.io.CharArrayWriter; @@ -49,6 +48,7 @@ import javax.swing.event.EventListenerList; import net.sf.gridarta.filter.Filter; import net.sf.gridarta.filter.FilterControl; +import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.script.BshThread; import net.sf.gridarta.script.ScriptExecException; import net.sf.gridarta.script.ScriptModel; @@ -110,9 +110,9 @@ private File scriptsDir = null; @NotNull - private final PluginParameterViewFactory pluginParameterViewFactory; + private final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory; - public ScriptController(@NotNull final FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl, @NotNull final ScriptParameters scriptParameters, @NotNull final Component parent, @NotNull final PluginParameterViewFactory pluginParameterViewFactory) { + public ScriptController(@NotNull final FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl, @NotNull final ScriptParameters scriptParameters, @NotNull final Component parent, @NotNull final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { this.parent = parent; this.filterControl = filterControl; this.scriptParameters = scriptParameters; Copied: trunk/src/app/net/sf/gridarta/gui/script/parameter/PluginParameterViewFactory.java (from rev 5338, trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterViewFactory.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/PluginParameterViewFactory.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/PluginParameterViewFactory.java 2008-10-01 19:59:25 UTC (rev 5339) @@ -0,0 +1,125 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script.parameter; + +import net.sf.gridarta.MapManager; +import net.sf.gridarta.filter.NamedFilterList; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.ArchetypeSet; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; +import net.sf.gridarta.gui.map.MapViewBasic; +import net.sf.gridarta.gui.objectchooser.ObjectChooser; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.script.parameter.ArchParameter; +import net.sf.gridarta.script.parameter.BooleanParameter; +import net.sf.gridarta.script.parameter.DoubleParameter; +import net.sf.gridarta.script.parameter.FilterParameter; +import net.sf.gridarta.script.parameter.IntegerParameter; +import net.sf.gridarta.script.parameter.MapParameter; +import net.sf.gridarta.script.parameter.PluginParameter; +import net.sf.gridarta.script.parameter.PluginParameterVisitor; +import net.sf.gridarta.script.parameter.StringParameter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Factory for creating {@link PluginParameterView} instances. + * @author Andreas Kirschbaum + */ +public class PluginParameterViewFactory<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, V extends MapViewBasic<G, A, R, V>> { + + @NotNull + private final ArchetypeSet<G, A, R> archetypeSet; + + @NotNull + private final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel; + + @NotNull + private final ObjectChooser<G, A, R> objectChooser; + + @NotNull + private final NamedFilterList defaultFilterList; + + @NotNull + private final MapManager<G, A, R, V> mapManager; + + @Nullable + private PluginParameterView view = null; + + private final PluginParameterVisitor<G, A, R, V> visitor = new PluginParameterVisitor<G, A, R, V>() { + + /** {@inheritDoc} */ + public void visit(final ArchParameter<G, A, R> parameter) { + view = new ArchParameterView<G, A, R>(parameter, gameObjectAttributesModel, archetypeSet, objectChooser); + } + + /** {@inheritDoc} */ + public void visit(final BooleanParameter parameter) { + view = new BooleanParameterView(parameter); + } + + /** {@inheritDoc} */ + public void visit(final DoubleParameter parameter) { + view = new DoubleParameterView(parameter); + } + + /** {@inheritDoc} */ + public void visit(final FilterParameter parameter) { + view = new FilterParameterView(defaultFilterList); // XXX: does not use "parameter"? + } + + /** {@inheritDoc} */ + public void visit(final IntegerParameter parameter) { + view = new IntegerParameterView(parameter); + } + + /** {@inheritDoc} */ + public void visit(final MapParameter<G, A, R, V> parameter) { + view = new MapParameterView<G, A, R, V>(parameter, mapManager); + } + + /** {@inheritDoc} */ + public void visit(final StringParameter parameter) { + view = new StringParameterView(parameter); + } + + }; + + /** + * Creates a new instance. + */ + 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 NamedFilterList defaultFilterList, @NotNull final MapManager<G, A, R, V> mapManager) { + this.archetypeSet = archetypeSet; + this.gameObjectAttributesModel = gameObjectAttributesModel; + this.objectChooser = objectChooser; + this.defaultFilterList = defaultFilterList; + this.mapManager = mapManager; + } + + @NotNull + public PluginParameterView getView(@NotNull final PluginParameter<?, ?> parameter) { + view = null; + parameter.visit(visitor); + assert view != null; + return view; + } + +} // class PluginParameterViewFactory This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 20:05:22
|
Revision: 5341 http://gridarta.svn.sourceforge.net/gridarta/?rev=5341&view=rev Author: akirschbaum Date: 2008-10-01 20:05:12 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move ScriptControlListener to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java trunk/crossfire/src/cfeditor/gui/script/ScriptView.java trunk/crossfire/src/cfeditor/script/ScriptController.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/script/ScriptControlListener.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/script/ScriptControlListener.java Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 20:01:30 UTC (rev 5340) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 20:05:12 UTC (rev 5341) @@ -23,7 +23,6 @@ import cfeditor.gameobject.GameObject; import cfeditor.gui.map.CMapViewBasic; import cfeditor.map.MapArchObject; -import cfeditor.script.ScriptControlListener; import cfeditor.script.ScriptController; import java.awt.BorderLayout; import java.awt.CardLayout; @@ -45,6 +44,7 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; +import net.sf.gridarta.script.ScriptControlListener; import net.sf.gridarta.script.ScriptModel; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 20:01:30 UTC (rev 5340) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 20:05:12 UTC (rev 5341) @@ -25,7 +25,6 @@ import cfeditor.gameobject.GameObject; import cfeditor.gui.map.CMapViewBasic; import cfeditor.map.MapArchObject; -import cfeditor.script.ScriptControlListener; import cfeditor.script.ScriptController; import java.awt.BorderLayout; import java.awt.Component; @@ -45,6 +44,7 @@ import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.utils.MenuUtils; +import net.sf.gridarta.script.ScriptControlListener; import net.sf.gridarta.script.ScriptModel; import net.sf.gridarta.script.parameter.PluginParameter; import net.sf.japi.swing.ActionFactory; Deleted: trunk/crossfire/src/cfeditor/script/ScriptControlListener.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptControlListener.java 2008-10-01 20:01:30 UTC (rev 5340) +++ trunk/crossfire/src/cfeditor/script/ScriptControlListener.java 2008-10-01 20:05:12 UTC (rev 5341) @@ -1,50 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.script; - -import java.util.EventListener; -import net.sf.gridarta.script.ScriptModel; -import org.jetbrains.annotations.NotNull; - -/** - * Listener interface for scripting related events. - * @author Andreas Kirschbaum - */ -public interface ScriptControlListener extends EventListener { - - /** - * Notifies about the creation of a new script. - * @param script the created script - */ - void scriptCreated(@NotNull ScriptModel script); - - /** - * Notifies about the deletion of a script. - * @param script the deleted script - */ - void scriptDeleted(@NotNull ScriptModel script); - - /** - * Notifies about the registering of a script. - * @param script the registered script - */ - void scriptRegistered(@NotNull ScriptModel script); - -} // interface ScriptControlListener Modified: trunk/crossfire/src/cfeditor/script/ScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 20:01:30 UTC (rev 5340) +++ trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 20:05:12 UTC (rev 5341) @@ -50,6 +50,7 @@ import net.sf.gridarta.filter.FilterControl; import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.script.BshThread; +import net.sf.gridarta.script.ScriptControlListener; import net.sf.gridarta.script.ScriptExecException; import net.sf.gridarta.script.ScriptModel; import net.sf.gridarta.script.ScriptModelParser; Copied: trunk/src/app/net/sf/gridarta/script/ScriptControlListener.java (from rev 5339, trunk/crossfire/src/cfeditor/script/ScriptControlListener.java) =================================================================== --- trunk/src/app/net/sf/gridarta/script/ScriptControlListener.java (rev 0) +++ trunk/src/app/net/sf/gridarta/script/ScriptControlListener.java 2008-10-01 20:05:12 UTC (rev 5341) @@ -0,0 +1,50 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 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.script; + +import java.util.EventListener; +import net.sf.gridarta.script.ScriptModel; +import org.jetbrains.annotations.NotNull; + +/** + * Listener interface for scripting related events. + * @author Andreas Kirschbaum + */ +public interface ScriptControlListener extends EventListener { + + /** + * Notifies about the creation of a new script. + * @param script the created script + */ + void scriptCreated(@NotNull ScriptModel script); + + /** + * Notifies about the deletion of a script. + * @param script the deleted script + */ + void scriptDeleted(@NotNull ScriptModel script); + + /** + * Notifies about the registering of a script. + * @param script the registered script + */ + void scriptRegistered(@NotNull ScriptModel script); + +} // interface ScriptControlListener Property changes on: trunk/src/app/net/sf/gridarta/script/ScriptControlListener.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 20:08:40
|
Revision: 5342 http://gridarta.svn.sourceforge.net/gridarta/?rev=5342&view=rev Author: akirschbaum Date: 2008-10-01 20:08:30 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move ScriptViewPane to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/ScriptViewPane.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/ScriptViewPane.java Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 20:05:12 UTC (rev 5341) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 20:08:30 UTC (rev 5342) @@ -41,6 +41,7 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; +import net.sf.gridarta.gui.script.ScriptViewPane; import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.utils.MenuUtils; Deleted: trunk/crossfire/src/cfeditor/gui/script/ScriptViewPane.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptViewPane.java 2008-10-01 20:05:12 UTC (rev 5341) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptViewPane.java 2008-10-01 20:08:30 UTC (rev 5342) @@ -1,41 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script; - -import javax.swing.JDialog; -import javax.swing.JOptionPane; - -public class ScriptViewPane extends JOptionPane { - - /** The serial version UID. */ - private static final long serialVersionUID = 1; - - public JDialog dialog = null; - - /** {@inheritDoc} */ - @Override - public void setValue(final Object newValue) { - super.setValue(newValue); - if (dialog != null && newValue != UNINITIALIZED_VALUE) { - dialog.dispose(); - } - } - -} // class ScriptViewPane Copied: trunk/src/app/net/sf/gridarta/gui/script/ScriptViewPane.java (from rev 5341, trunk/crossfire/src/cfeditor/gui/script/ScriptViewPane.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/ScriptViewPane.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/ScriptViewPane.java 2008-10-01 20:08:30 UTC (rev 5342) @@ -0,0 +1,41 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script; + +import javax.swing.JDialog; +import javax.swing.JOptionPane; + +public class ScriptViewPane extends JOptionPane { + + /** The serial version UID. */ + private static final long serialVersionUID = 1; + + public JDialog dialog = null; + + /** {@inheritDoc} */ + @Override + public void setValue(final Object newValue) { + super.setValue(newValue); + if (dialog != null && newValue != UNINITIALIZED_VALUE) { + dialog.dispose(); + } + } + +} // class ScriptViewPane Property changes on: trunk/src/app/net/sf/gridarta/gui/script/ScriptViewPane.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 20:11:49
|
Revision: 5344 http://gridarta.svn.sourceforge.net/gridarta/?rev=5344&view=rev Author: akirschbaum Date: 2008-10-01 20:11:39 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move ClosingIcon to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/ClosingIcon.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/ClosingIcon.java Modified: trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java 2008-10-01 20:09:19 UTC (rev 5343) +++ trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java 2008-10-01 20:11:39 UTC (rev 5344) @@ -52,6 +52,7 @@ import java.awt.event.MouseEvent; import javax.swing.ImageIcon; import javax.swing.JTabbedPane; +import net.sf.gridarta.gui.script.ClosingIcon; import net.sf.gridarta.gui.utils.GUIUtils; public class CloseableTabbedPane extends JTabbedPane { Deleted: trunk/crossfire/src/cfeditor/gui/script/ClosingIcon.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ClosingIcon.java 2008-10-01 20:09:19 UTC (rev 5343) +++ trunk/crossfire/src/cfeditor/gui/script/ClosingIcon.java 2008-10-01 20:11:39 UTC (rev 5344) @@ -1,100 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script; - -import java.awt.Component; -import java.awt.Graphics; -import javax.swing.Icon; -import javax.swing.ImageIcon; - -/** - * the idea for this class stems from limewire's CancelSearchIconProxy - * class, thanks for going open source guys. - */ -public class ClosingIcon implements Icon { - - //--- Data field(s) --- - - private final Icon icon; - - @SuppressWarnings({"InstanceVariableNamingConvention"}) - private int x = 0; - - @SuppressWarnings({"InstanceVariableNamingConvention"}) - private int y = 0; - - private int height = 10; - - private int width = 10; - - //--- Constructor(s) --- - - protected ClosingIcon(final ImageIcon icon) { - this.icon = icon; - - if (icon != null) { - height = icon.getIconHeight(); - width = icon.getIconWidth(); - } - } - - //--- Method(s) --- - - public int getIconHeight() { - return height; - } - - public int getIconWidth() { - return width; - } - - /** - * Overwrites paintIcon to get hold of the coordinates of the icon, this - * is a rather rude approach just to find out if the closingIcon was - * pressed. - */ - public void paintIcon(final Component c, final Graphics g, final int x, final int y) { - this.x = x; - this.y = y; - - if (icon != null) { - icon.paintIcon(c, g, x, y + 1); - } else { - g.drawRect(x, y + 1, width, height); - } - } - - /** - * Returns whether <var>xEvent</var> and <var>yEvent</var> are within - * the icon's borders. - * @param xEvent X coordinate from an event. - * @param yEvent Y coordinate from an event. - * @return whether <var>xEvent</var> and <var>yEvent</var> are within - * the icon's borders. - * @retval <code>true</code> if <var>xEvent</var> and <var>yEvent</var> - * are within the icon's border. - * @retval <code>false</code> otherwise (<var>xEvent</var> or - * <var>yEvent</var> or both are outside the icon's border). - */ - public boolean contains(final int xEvent, final int yEvent) { - return !(!(xEvent >= x) || !(xEvent <= x + width)) && !(!(yEvent >= y) || !(yEvent <= y + height)); - } - -} // class ClosingIcon Copied: trunk/src/app/net/sf/gridarta/gui/script/ClosingIcon.java (from rev 5343, trunk/crossfire/src/cfeditor/gui/script/ClosingIcon.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/ClosingIcon.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/ClosingIcon.java 2008-10-01 20:11:39 UTC (rev 5344) @@ -0,0 +1,100 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.script; + +import java.awt.Component; +import java.awt.Graphics; +import javax.swing.Icon; +import javax.swing.ImageIcon; + +/** + * the idea for this class stems from limewire's CancelSearchIconProxy + * class, thanks for going open source guys. + */ +public class ClosingIcon implements Icon { + + //--- Data field(s) --- + + private final Icon icon; + + @SuppressWarnings({"InstanceVariableNamingConvention"}) + private int x = 0; + + @SuppressWarnings({"InstanceVariableNamingConvention"}) + private int y = 0; + + private int height = 10; + + private int width = 10; + + //--- Constructor(s) --- + + public ClosingIcon(final ImageIcon icon) { + this.icon = icon; + + if (icon != null) { + height = icon.getIconHeight(); + width = icon.getIconWidth(); + } + } + + //--- Method(s) --- + + public int getIconHeight() { + return height; + } + + public int getIconWidth() { + return width; + } + + /** + * Overwrites paintIcon to get hold of the coordinates of the icon, this + * is a rather rude approach just to find out if the closingIcon was + * pressed. + */ + public void paintIcon(final Component c, final Graphics g, final int x, final int y) { + this.x = x; + this.y = y; + + if (icon != null) { + icon.paintIcon(c, g, x, y + 1); + } else { + g.drawRect(x, y + 1, width, height); + } + } + + /** + * Returns whether <var>xEvent</var> and <var>yEvent</var> are within + * the icon's borders. + * @param xEvent X coordinate from an event. + * @param yEvent Y coordinate from an event. + * @return whether <var>xEvent</var> and <var>yEvent</var> are within + * the icon's borders. + * @retval <code>true</code> if <var>xEvent</var> and <var>yEvent</var> + * are within the icon's border. + * @retval <code>false</code> otherwise (<var>xEvent</var> or + * <var>yEvent</var> or both are outside the icon's border). + */ + public boolean contains(final int xEvent, final int yEvent) { + return !(!(xEvent >= x) || !(xEvent <= x + width)) && !(!(yEvent >= y) || !(yEvent <= y + height)); + } + +} // class ClosingIcon Property changes on: trunk/src/app/net/sf/gridarta/gui/script/ClosingIcon.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 20:17:37
|
Revision: 5345 http://gridarta.svn.sourceforge.net/gridarta/?rev=5345&view=rev Author: akirschbaum Date: 2008-10-01 20:17:26 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move StackLayout to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/StackLayout.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/StackLayout.java Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 20:11:39 UTC (rev 5344) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 20:17:26 UTC (rev 5345) @@ -53,6 +53,7 @@ import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import net.sf.gridarta.gui.script.StackLayout; import net.sf.gridarta.gui.script.parameter.ParameterDescriptionEditor; import net.sf.gridarta.gui.script.parameter.ParameterNameEditor; import net.sf.gridarta.gui.script.parameter.ParameterTypeEditor; Deleted: trunk/crossfire/src/cfeditor/gui/script/StackLayout.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/StackLayout.java 2008-10-01 20:11:39 UTC (rev 5344) +++ trunk/crossfire/src/cfeditor/gui/script/StackLayout.java 2008-10-01 20:17:26 UTC (rev 5345) @@ -1,100 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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. - */ - -/* Downloaded 02 nov 2004 from - * http://www.softbear.com/java/mktview/StackLayout.java - */ - -package cfeditor.gui.script; - -import java.awt.Component; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Insets; -import java.awt.LayoutManager; - -/** - * A layoutManager which stacks components one on top of the other, regardless - * of their size. - * @author unknown - */ -public class StackLayout implements LayoutManager { - - /** The vertical gap between components in pixels. */ - private final int vgap; - - /** - * Create a StackLayout. - * @param vgap vertical gap between components in pixels - */ - public StackLayout(final int vgap) { - this.vgap = vgap; - } - - /** {@inheritDoc} */ - public void addLayoutComponent(final String name, final Component comp) { - } - - /** {@inheritDoc} */ - public Dimension preferredLayoutSize(final Container parent) { - final Insets insets = parent.getInsets(); - final int ncomponents = parent.getComponentCount(); - int w = 0; - int h = 0; - - for (int i = 0; i < ncomponents; i++) { - final Component comp = parent.getComponent(i); - final Dimension d = comp.getPreferredSize(); - if (w < d.width) { - w = d.width; - } - h += d.height; - if (i != 0) { - h += vgap; - } - } - return new Dimension(insets.left + insets.right + w, insets.top + insets.bottom + h); - } - - /** {@inheritDoc} */ - public void layoutContainer(final Container parent) { - final Insets insets = parent.getInsets(); - final int x = insets.left; - int y = insets.top; - final int w = preferredLayoutSize(parent).width; - - final int ncomponents = parent.getComponentCount(); - for (int i = 0; i < ncomponents; ++i) { - final Component comp = parent.getComponent(i); - final Dimension d = comp.getPreferredSize(); - comp.setBounds(x, y, w, d.height); - y += d.height + vgap; - } - } - - /** {@inheritDoc} */ - public Dimension minimumLayoutSize(final Container parent) { - return preferredLayoutSize(parent); - } - - /** {@inheritDoc} */ - public void removeLayoutComponent(final Component comp) { - } - -} // class StackLayout Copied: trunk/src/app/net/sf/gridarta/gui/script/StackLayout.java (from rev 5341, trunk/crossfire/src/cfeditor/gui/script/StackLayout.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/StackLayout.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/script/StackLayout.java 2008-10-01 20:17:26 UTC (rev 5345) @@ -0,0 +1,100 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 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. + */ + +/* Downloaded 02 nov 2004 from + * http://www.softbear.com/java/mktview/StackLayout.java + */ + +package net.sf.gridarta.gui.script; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.LayoutManager; + +/** + * A layoutManager which stacks components one on top of the other, regardless + * of their size. + * @author unknown + */ +public class StackLayout implements LayoutManager { + + /** The vertical gap between components in pixels. */ + private final int vgap; + + /** + * Create a StackLayout. + * @param vgap vertical gap between components in pixels + */ + public StackLayout(final int vgap) { + this.vgap = vgap; + } + + /** {@inheritDoc} */ + public void addLayoutComponent(final String name, final Component comp) { + } + + /** {@inheritDoc} */ + public Dimension preferredLayoutSize(final Container parent) { + final Insets insets = parent.getInsets(); + final int ncomponents = parent.getComponentCount(); + int w = 0; + int h = 0; + + for (int i = 0; i < ncomponents; i++) { + final Component comp = parent.getComponent(i); + final Dimension d = comp.getPreferredSize(); + if (w < d.width) { + w = d.width; + } + h += d.height; + if (i != 0) { + h += vgap; + } + } + return new Dimension(insets.left + insets.right + w, insets.top + insets.bottom + h); + } + + /** {@inheritDoc} */ + public void layoutContainer(final Container parent) { + final Insets insets = parent.getInsets(); + final int x = insets.left; + int y = insets.top; + final int w = preferredLayoutSize(parent).width; + + final int ncomponents = parent.getComponentCount(); + for (int i = 0; i < ncomponents; ++i) { + final Component comp = parent.getComponent(i); + final Dimension d = comp.getPreferredSize(); + comp.setBounds(x, y, w, d.height); + y += d.height + vgap; + } + } + + /** {@inheritDoc} */ + public Dimension minimumLayoutSize(final Container parent) { + return preferredLayoutSize(parent); + } + + /** {@inheritDoc} */ + public void removeLayoutComponent(final Component comp) { + } + +} // class StackLayout Property changes on: trunk/src/app/net/sf/gridarta/gui/script/StackLayout.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 20:57:58
|
Revision: 5352 http://gridarta.svn.sourceforge.net/gridarta/?rev=5352&view=rev Author: akirschbaum Date: 2008-10-01 20:57:39 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Make ScriptModel.name final. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java trunk/crossfire/src/cfeditor/script/ScriptController.java trunk/src/app/net/sf/gridarta/script/ScriptModel.java trunk/src/app/net/sf/gridarta/script/ScriptModelParser.java Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 20:52:24 UTC (rev 5351) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 20:57:39 UTC (rev 5352) @@ -143,8 +143,7 @@ public void actionPerformed(final ActionEvent e) { final String name = JOptionPane.showInputDialog(scripts, "Name of the new Beanshell plugin?"); if (name != null) { - final ScriptModel m = new ScriptModel(); - m.setName(name); + final ScriptModel m = new ScriptModel(name); m.setCode("//input your beanshell Code"); if (!ScriptManager.this.scriptController.getScriptModel2().addScript(m)) { JOptionPane.showMessageDialog(scripts, "The script " + name + " already exists.", "Error", JOptionPane.WARNING_MESSAGE); Modified: trunk/crossfire/src/cfeditor/script/ScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 20:52:24 UTC (rev 5351) +++ trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 20:57:39 UTC (rev 5352) @@ -160,8 +160,7 @@ return; } - final ScriptModel cScript = new ScriptModel(); - ScriptModelParser.fromXML(cScript, elt); + final ScriptModel cScript = ScriptModelParser.fromXML(elt); cScript.setFile(file); log.debug("script: " + cScript.getName()); if (override || scriptModel2.getScript(cScript.getName()) == null) { Modified: trunk/src/app/net/sf/gridarta/script/ScriptModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/ScriptModel.java 2008-10-01 20:52:24 UTC (rev 5351) +++ trunk/src/app/net/sf/gridarta/script/ScriptModel.java 2008-10-01 20:57:39 UTC (rev 5352) @@ -49,7 +49,11 @@ private final List<PluginParameter<?, ?>> parameters = new ArrayList<PluginParameter<?, ?>>(); - private String name = ""; + /** + * The script name. + */ + @NotNull + private final String name; private boolean autoboot = false; @@ -71,8 +75,10 @@ /** * Creates a new instance. + * @param name the script name */ - public ScriptModel() { + public ScriptModel(@NotNull final String name) { + this.name = name; } /** @@ -84,22 +90,6 @@ } /** - * Sets the name of this ScriptModel. - * @param name The name of this ScriptModel. - * @todo Maybe this should be moved to the constructor and the underlying - * field made final. - */ - public void setName(final String name) { - if (this.name.equals(name)) { - return; - } - - this.name = name; - modified = true; - notifyListeners(); - } - - /** * Returns the code of this ScriptModel. * @return The code of this ScriptModel. * @todo Improve name - what code is it? Source code? A special coded @@ -195,9 +185,8 @@ */ @Override public Object clone() throws CloneNotSupportedException { - final ScriptModel model = new ScriptModel(); + final ScriptModel model = new ScriptModel(name); model.code = code; - model.name = name; model.autoboot = autoboot; model.filter = filter; model.script = script; Modified: trunk/src/app/net/sf/gridarta/script/ScriptModelParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/ScriptModelParser.java 2008-10-01 20:52:24 UTC (rev 5351) +++ trunk/src/app/net/sf/gridarta/script/ScriptModelParser.java 2008-10-01 20:57:39 UTC (rev 5352) @@ -44,8 +44,8 @@ private ScriptModelParser() { } - public static void fromXML(@NotNull final ScriptModel scriptModel, @NotNull final Element node) { - scriptModel.setName(node.getChildTextTrim("name")); + public static @NotNull final ScriptModel fromXML(@NotNull final Element node) { + final ScriptModel scriptModel = new ScriptModel(node.getChildTextTrim("name")); scriptModel.setCode(node.getChildTextTrim("code")); boolean isAutoboot = false; boolean isFilter = false; @@ -84,6 +84,7 @@ } } scriptModel.resetModified(); + return scriptModel; } public static Element toXML(@NotNull final ScriptModel scriptModel) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 21:14:52
|
Revision: 5356 http://gridarta.svn.sourceforge.net/gridarta/?rev=5356&view=rev Author: akirschbaum Date: 2008-10-01 21:14:27 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Rename ScriptModel to Script. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java trunk/crossfire/src/cfeditor/gui/script/ScriptView.java trunk/crossfire/src/cfeditor/script/ScriptController.java trunk/crossfire/src/cfeditor/script/ScriptModel2.java trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterTypeEditor.java trunk/src/app/net/sf/gridarta/script/BshThread.java trunk/src/app/net/sf/gridarta/script/ScriptControlListener.java trunk/src/app/net/sf/gridarta/script/ScriptModelParser.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/script/Script.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/script/ScriptModel.java Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 21:03:46 UTC (rev 5355) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -60,7 +60,7 @@ import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.utils.GUIUtils; -import net.sf.gridarta.script.ScriptModel; +import net.sf.gridarta.script.Script; import net.sf.gridarta.script.parameter.NoSuchParameterException; import net.sf.gridarta.script.parameter.PluginParameter; import org.apache.log4j.Logger; @@ -80,7 +80,7 @@ private final JTextArea code; - private final ScriptModel script; + private final Script script; private final Map<PluginParameter<?, ?>, ParameterNameEditor> paramNameEditors = new HashMap<PluginParameter<?, ?>, ParameterNameEditor>(); @@ -134,7 +134,7 @@ * @param script the script object to edit * @param scriptController the associated script control instance */ - public ScriptEditor(final ScriptModel script, final ScriptController scriptController, final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { + public ScriptEditor(final Script script, final ScriptController scriptController, final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { this.script = script; this.pluginParameterViewFactory = pluginParameterViewFactory; final JTabbedPane tabs = new JTabbedPane(); @@ -395,7 +395,7 @@ paramTable.add(getParameterView(param).getValueComponent(param.getValue(), param), gbc); } - private ScriptModel getScript() { + private Script getScript() { return script; } Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 21:03:46 UTC (rev 5355) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -44,8 +44,8 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; +import net.sf.gridarta.script.Script; import net.sf.gridarta.script.ScriptControlListener; -import net.sf.gridarta.script.ScriptModel; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -66,7 +66,7 @@ private final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory; //TODO fix a memory leak. If a script is remove, it stays in hashmap along with it's visual component - private final Map<ScriptModel, ScriptEditor> components = new HashMap<ScriptModel, ScriptEditor>(); + private final Map<Script, ScriptEditor> components = new HashMap<Script, ScriptEditor>(); private static final long serialVersionUID = 1L; @@ -94,17 +94,17 @@ private final ScriptControlListener scriptControlListener = new ScriptControlListener() { /** {@inheritDoc} */ - public void scriptCreated(@NotNull final ScriptModel script) { + public void scriptCreated(@NotNull final Script script) { fireContentsChanged(scripts, 0, ScriptManager.this.scriptController.getScriptModel2().getScriptCount() + 1); } /** {@inheritDoc} */ - public void scriptDeleted(@NotNull final ScriptModel script) { + public void scriptDeleted(@NotNull final Script script) { fireContentsChanged(scripts, 0, ScriptManager.this.scriptController.getScriptModel2().getScriptCount() + 1); } /** {@inheritDoc} */ - public void scriptRegistered(@NotNull final ScriptModel script) { + public void scriptRegistered(@NotNull final Script script) { fireContentsChanged(scripts, 0, ScriptManager.this.scriptController.getScriptModel2().getScriptCount() + 1); } @@ -131,7 +131,7 @@ scripts.addListSelectionListener(new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { - showScript((ScriptModel) scripts.getSelectedValue()); + showScript((Script) scripts.getSelectedValue()); } } }); @@ -143,12 +143,12 @@ public void actionPerformed(final ActionEvent e) { final String name = JOptionPane.showInputDialog(scripts, "Name of the new Beanshell plugin?"); if (name != null) { - final ScriptModel m = new ScriptModel(name); - m.setCode("//input your beanshell Code"); - if (!ScriptManager.this.scriptController.getScriptModel2().addScript(m)) { + final Script script = new Script(name); + script.setCode("//input your beanshell Code"); + if (!ScriptManager.this.scriptController.getScriptModel2().addScript(script)) { JOptionPane.showMessageDialog(scripts, "The script " + name + " already exists.", "Error", JOptionPane.WARNING_MESSAGE); } else { - showScript(m); + showScript(script); } } } @@ -156,19 +156,19 @@ final JButton removeScriptBtn = new JButton("Remove"); removeScriptBtn.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { - final ScriptModel m = (ScriptModel) scripts.getSelectedValue(); - if (m == null) { + final Script script = (Script) scripts.getSelectedValue(); + if (script == null) { return; } - if (JOptionPane.showConfirmDialog(scripts, "remove script name " + m.getName(), "remove", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { + if (JOptionPane.showConfirmDialog(scripts, "remove script name " + script.getName(), "remove", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { if (log.isDebugEnabled()) { log.debug("removing"); } - ScriptManager.this.scriptController.getScriptModel2().removeScript(m); + ScriptManager.this.scriptController.getScriptModel2().removeScript(script); scripts.setSelectedIndex(0); - removeScript(m); + removeScript(script); } } }); @@ -181,7 +181,7 @@ setVisible(true); } - private void showScript(final ScriptModel model) { + private void showScript(final Script script) { /* using a cardlayout is a necessary trick as * simply removing previous component and putting * the new one in the JPanel lead to problem unless @@ -189,23 +189,23 @@ * (the validate process goes strangely and only portions * of component are redrawn until window resize :s) */ - if (model == null) { + if (script == null) { return; } - ScriptEditor c = components.get(model); + ScriptEditor c = components.get(script); if (c == null) { - c = new ScriptEditor(model, scriptController, pluginParameterViewFactory); - components.put(model, c); + c = new ScriptEditor(script, scriptController, pluginParameterViewFactory); + components.put(script, c); scriptPanel.add(c, Integer.toString(c.hashCode())); } scriptLayout.show(scriptPanel, Integer.toString(c.hashCode())); } - private void removeScript(final ScriptModel model) { - final ScriptEditor c = components.get(model); + private void removeScript(final Script script) { + final ScriptEditor c = components.get(script); if (c != null) { - components.remove(model); + components.remove(script); scriptPanel.remove(c); } } Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 21:03:46 UTC (rev 5355) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -47,8 +47,8 @@ import net.sf.gridarta.gui.script.parameter.PluginParameterView; import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.utils.MenuUtils; +import net.sf.gridarta.script.Script; import net.sf.gridarta.script.ScriptControlListener; -import net.sf.gridarta.script.ScriptModel; import net.sf.gridarta.script.parameter.PluginParameter; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ReflectionAction; @@ -102,17 +102,17 @@ private final ScriptControlListener scriptControlListener = new ScriptControlListener() { /** {@inheritDoc} */ - public void scriptCreated(@NotNull final ScriptModel script) { + public void scriptCreated(@NotNull final Script script) { updateMenuEntries(); } /** {@inheritDoc} */ - public void scriptDeleted(@NotNull final ScriptModel script) { + public void scriptDeleted(@NotNull final Script script) { updateMenuEntries(); } /** {@inheritDoc} */ - public void scriptRegistered(@NotNull final ScriptModel script) { + public void scriptRegistered(@NotNull final Script script) { updateMenuEntries(); } @@ -154,7 +154,7 @@ MenuUtils.removeAllToSeparator(menuScripts); int index = 0; - for (final ScriptModel script : scriptModel2) { + for (final Script script : scriptModel2) { if (!script.isScript()) { continue; } @@ -215,24 +215,24 @@ return bshConsole; } - public boolean getRunValues(final ScriptModel model) { - if (!model.hasParameters()) { + public boolean getRunValues(final Script script) { + if (!script.hasParameters()) { return true; } final ScriptViewPane p = new ScriptViewPane(); p.setOptionType(JOptionPane.OK_CANCEL_OPTION); p.setMessageType(JOptionPane.QUESTION_MESSAGE); - p.setMessage("Please provide runtime parameters for " + model.getName()); + p.setMessage("Please provide runtime parameters for " + script.getName()); final GridBagLayout layout = new GridBagLayout(); final JPanel panel = new JPanel(layout); final JDialog dialog = p.createDialog(parent, "hi"); p.dialog = dialog; dialog.setModal(true); - dialog.setTitle(model.getName()); + dialog.setTitle(script.getName()); dialog.getContentPane().removeAll(); int i = 0; - for (final PluginParameter<?, ?> parameter : model) { + for (final PluginParameter<?, ?> parameter : script) { log.debug("adding parameter"); final JLabel name = new JLabel(parameter.getName()); final PluginParameterView view = pluginParameterViewFactory.getView(parameter); Modified: trunk/crossfire/src/cfeditor/script/ScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 21:03:46 UTC (rev 5355) +++ trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -45,7 +45,7 @@ import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.script.BshThread; import net.sf.gridarta.script.ScriptExecException; -import net.sf.gridarta.script.ScriptModel; +import net.sf.gridarta.script.Script; import net.sf.gridarta.script.ScriptModelParser; import net.sf.gridarta.script.ScriptParameters; import net.sf.gridarta.script.ScriptRunMode; @@ -160,19 +160,19 @@ return; } - final ScriptModel cScript = ScriptModelParser.fromXML(elt); - cScript.setFile(file); - log.debug("script: " + cScript.getName()); - if (override || scriptModel2.getScript(cScript.getName()) == null) { + final Script script = ScriptModelParser.fromXML(elt); + script.setFile(file); + log.debug("script: " + script.getName()); + if (override || scriptModel2.getScript(script.getName()) == null) { if (log.isDebugEnabled()) { - log.debug("storing with code " + cScript.getCode()); + log.debug("storing with code " + script.getCode()); } - unRegister(cScript.getName()); - scriptModel2.addScript(cScript); - register(cScript.getName()); + unRegister(script.getName()); + scriptModel2.addScript(script); + register(script.getName()); } else { - log.warn(file + ": ignoring duplicate script '" + cScript.getName() + "'"); + log.warn(file + ": ignoring duplicate script '" + script.getName() + "'"); } } catch (final Exception e) { e.printStackTrace(); @@ -184,7 +184,7 @@ * @return Whether all scripts have been saved. */ public boolean saveAllScripts() { - for (final ScriptModel scriptModel : scriptModel2) { + for (final Script scriptModel : scriptModel2) { if (!saveScript(scriptModel)) { return false; } @@ -198,11 +198,11 @@ * @return Whether no unsaved scripts remain. */ public boolean canExit() { - for (final ScriptModel scriptModel : scriptModel2) { - if (scriptModel.isModified()) { - final int result = ACTION_FACTORY.showConfirmDialog(parent, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "pluginConfirmSaveChanges", scriptModel.getName()); + for (final Script script : scriptModel2) { + if (script.isModified()) { + final int result = ACTION_FACTORY.showConfirmDialog(parent, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "pluginConfirmSaveChanges", script.getName()); if (result == JOptionPane.YES_OPTION) { - if (!saveScript(scriptModel)) { + if (!saveScript(script)) { return false; } } else @@ -217,43 +217,43 @@ /** * Save one script. Does nothing if the script is unchanged. - * @param scriptModel The script to save. + * @param script The script to save. * @return Whether the script has been saved, or if the script was not * modified. */ - public boolean saveScript(@NotNull final ScriptModel scriptModel) { - if (!scriptModel.isModified()) { + public boolean saveScript(@NotNull final Script script) { + if (!script.isModified()) { return true; } try { - final File file = scriptModel.getFile(); + final File file = script.getFile(); if (file != null) { - saveScript(scriptModel, file); + saveScript(script, file); } else { - saveScriptAs(scriptModel, true); + saveScriptAs(script, true); } } catch (final IOException ex) { // XXX: notify user return false; } - scriptModel.resetModified(); + script.resetModified(); return true; } /** * Prompt the user for a file name to save a script. The script is saved * regardless whether the script is modified or not. - * @param scriptModel The script to save. + * @param script The script to save. * @param updateScriptFile If set, update the script file to the save * location. * @return Whether the script has been saved. */ - public boolean saveScriptAs(@NotNull final ScriptModel scriptModel, final boolean updateScriptFile) { + public boolean saveScriptAs(@NotNull final Script script, final boolean updateScriptFile) { final JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(scriptsDir); - chooser.setDialogTitle("save script " + scriptModel.getName()); + chooser.setDialogTitle("save script " + script.getName()); final int result = chooser.showSaveDialog(null); if (result != JFileChooser.APPROVE_OPTION) { return false; @@ -261,12 +261,12 @@ final File file = chooser.getSelectedFile(); if (updateScriptFile) { - scriptModel.setFile(file); + script.setFile(file); } scriptsDir = file.getParentFile(); try { - saveScript(scriptModel, file); + saveScript(script, file); } catch (final IOException ex) { return false; } @@ -276,14 +276,14 @@ /** * Save a script to a given file. - * @param scriptModel The script to save. + * @param script The script to save. * @param file The file to save to. * @throws IOException If the file cannot be saved. */ - public static void saveScript(@NotNull final ScriptModel scriptModel, @NotNull final File file) throws IOException { + public static void saveScript(@NotNull final Script script, @NotNull final File file) throws IOException { final FileOutputStream fos = new FileOutputStream(file); try { - final Element root = ScriptModelParser.toXML(scriptModel); + final Element root = ScriptModelParser.toXML(script); final Document d = new Document(root); final XMLOutputter out = new XMLOutputter(); out.setFormat(Format.getPrettyFormat()); @@ -293,7 +293,7 @@ } } - public void autoRunScript(final ScriptModel script) { + public void autoRunScript(final Script script) { final Interpreter runner = new Interpreter(); try { scriptParameters.setInterpreterValues(runner, ScriptRunMode.AUTORUN); @@ -304,7 +304,7 @@ } @Nullable - public Filter getScriptAsFilter(final ScriptModel script) { + public Filter getScriptAsFilter(final Script script) { final Interpreter runner = new Interpreter(); try { scriptParameters.setInterpreterValues(runner, ScriptRunMode.FILTER); @@ -317,21 +317,21 @@ return null; } - public void runScript(final ScriptModel script) { - final ScriptModel model; + public void runScript(final Script script) { + final Script clonedScript; try { - model = (ScriptModel) script.clone(); + clonedScript = (Script) script.clone(); } catch (final CloneNotSupportedException e) { throw new AssertionError(); } - if (!view.getRunValues(model)) { + if (!view.getRunValues(clonedScript)) { return; } - final ConsoleInterface console = view.createConsole(model.getName()); + final ConsoleInterface console = view.createConsole(clonedScript.getName()); try { - doRunScript(model, console); + doRunScript(clonedScript, console); } catch (final ScriptExecException ex) { console.print(ex.getMessage()); } @@ -340,23 +340,23 @@ /** * Runs a script model. The model is expected to have all needed parameters * set. - * @param model the script model + * @param script the script model * @param console the console to use * @return the script thread or <code>null</code> * @throws ScriptExecException if an error occurs */ @Nullable - private BshThread doRunScript(@NotNull final ScriptModel model, @NotNull final ConsoleInterface console) throws ScriptExecException { + private BshThread doRunScript(@NotNull final Script script, @NotNull final ConsoleInterface console) throws ScriptExecException { final Interpreter runner = new Interpreter(); final BshThread scriptThread; try { runner.setConsole(console); scriptParameters.setInterpreterValues(runner, ScriptRunMode.BATCH); - for (final PluginParameter<?, ?> parameter : model) { + for (final PluginParameter<?, ?> parameter : script) { runner.set(parameter.getName(), parameter.getValue()); } - scriptThread = new BshThread(model.getName()); - scriptThread.setScript(model); + scriptThread = new BshThread(script.getName()); + scriptThread.setScript(script); scriptThread.setInterpreter(runner); scriptThread.start(); } catch (final TargetError e) { @@ -371,9 +371,9 @@ } public void runScript(final String name) { - final ScriptModel model = scriptModel2.getScript(name); - if (model != null) { - runScript(model); + final Script script = scriptModel2.getScript(name); + if (script != null) { + runScript(script); } } @@ -393,7 +393,7 @@ private void register(final String name) { final String filterName = "(s)" + name; - final ScriptModel script = scriptModel2.getScript(name); + final Script script = scriptModel2.getScript(name); if (script.isFilter()) { final Filter filter = getScriptAsFilter(script); if (filter != null) { @@ -420,14 +420,14 @@ * @throws ScriptExecException if an error occurs */ public void executeScript(final String script, final List<String> params) throws ScriptExecException { - final ScriptModel modelTemplate = scriptModel2.getScript(script); + final Script modelTemplate = scriptModel2.getScript(script); if (modelTemplate == null) { throw new ScriptExecException("script " + script + " does not exist"); } - final ScriptModel model; + final Script clonedScript; try { - model = (ScriptModel) modelTemplate.clone(); + clonedScript = (Script) modelTemplate.clone(); } catch (final CloneNotSupportedException e) { throw new AssertionError(); } @@ -438,11 +438,11 @@ throw new ScriptExecException("syntax error: " + param); } - final int index = model.getParameter(tmp[0]); + final int index = clonedScript.getParameter(tmp[0]); if (index == -1) { final StringBuilder sb = new StringBuilder(); boolean firstParameter = true; - for (final PluginParameter<?, ?> parameter : model) { + for (final PluginParameter<?, ?> parameter : clonedScript) { sb.append(firstParameter ? " " : ", "); sb.append(parameter.getName()); firstParameter = false; @@ -452,7 +452,7 @@ final PluginParameter<?, ?> parameter; try { - parameter = model.getParameter(index); + parameter = clonedScript.getParameter(index); } catch (final NoSuchParameterException ex) { throw new AssertionError(); } @@ -494,7 +494,7 @@ } }; - final BshThread scriptThread = doRunScript(model, console); + final BshThread scriptThread = doRunScript(clonedScript, console); try { scriptThread.join(); } catch (final InterruptedException ex) { Modified: trunk/crossfire/src/cfeditor/script/ScriptModel2.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptModel2.java 2008-10-01 21:03:46 UTC (rev 5355) +++ trunk/crossfire/src/cfeditor/script/ScriptModel2.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -24,8 +24,8 @@ import java.util.Map; import java.util.TreeMap; import javax.swing.event.EventListenerList; +import net.sf.gridarta.script.Script; import net.sf.gridarta.script.ScriptControlListener; -import net.sf.gridarta.script.ScriptModel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,10 +33,10 @@ * @author tchize * @author Andreas Kirschbaum */ -public class ScriptModel2 implements Iterable<ScriptModel> { +public class ScriptModel2 implements Iterable<Script> { @NotNull - private final Map<String, ScriptModel> scripts = new TreeMap<String, ScriptModel>(); + private final Map<String, Script> scripts = new TreeMap<String, Script>(); /** * The {@link ScriptControlListener}s to inform of changes. @@ -51,7 +51,7 @@ } @Nullable - public ScriptModel getScript(@NotNull final String name) { + public Script getScript(@NotNull final String name) { return scripts.get(name); } @@ -60,9 +60,9 @@ } @Nullable - public ScriptModel getScript(int index) { - final Iterator<ScriptModel> i = scripts.values().iterator(); - ScriptModel m = null; + public Script getScript(int index) { + final Iterator<Script> i = scripts.values().iterator(); + Script m = null; while (i.hasNext() && index-- >= 0) { m = i.next(); } @@ -79,7 +79,7 @@ * @return <code>true</code> if the script was added, or <code>false</code> * if the script name already exists */ - public boolean addScript(@NotNull final ScriptModel script) { + public boolean addScript(@NotNull final Script script) { if (scripts.containsKey(script.getName())) { return false; } @@ -89,7 +89,7 @@ return true; } - public void removeScript(@NotNull final ScriptModel script) { + public void removeScript(@NotNull final Script script) { if (!scripts.containsKey(script.getName())) { throw new IllegalArgumentException(); } @@ -118,7 +118,7 @@ * Notify all listeners about an added script. * @param script the added script */ - private void fireScriptCreatedEvent(@NotNull final ScriptModel script) { + private void fireScriptCreatedEvent(@NotNull final Script script) { for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { listener.scriptCreated(script); } @@ -128,7 +128,7 @@ * Notifies all listeners about a removed script. * @param script the removed script */ - private void fireScriptDeletedEvent(@NotNull final ScriptModel script) { + private void fireScriptDeletedEvent(@NotNull final Script script) { for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { listener.scriptDeleted(script); } @@ -138,7 +138,7 @@ * Notifies all listeners about a registered script. * @param script the registered script */ - public void fireScriptRegisteredEvent(@NotNull final ScriptModel script) { + public void fireScriptRegisteredEvent(@NotNull final Script script) { for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { listener.scriptRegistered(script); } @@ -146,7 +146,7 @@ /** {@inheritDoc} */ @NotNull - public Iterator<ScriptModel> iterator() { + public Iterator<Script> iterator() { return Collections.unmodifiableCollection(scripts.values()).iterator(); } Modified: trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterTypeEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterTypeEditor.java 2008-10-01 21:03:46 UTC (rev 5355) +++ trunk/src/app/net/sf/gridarta/gui/script/parameter/ParameterTypeEditor.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -22,7 +22,7 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JComboBox; -import net.sf.gridarta.script.ScriptModel; +import net.sf.gridarta.script.Script; import net.sf.gridarta.script.parameter.NoSuchParameterException; import net.sf.gridarta.script.parameter.PluginParameter; import net.sf.gridarta.script.parameter.PluginParameterFactory; @@ -37,7 +37,7 @@ private final PluginParameter<?, ?> parameter; - private final ScriptModel script; + private final Script script; private final ItemListener itemListener = new ItemListener() { @@ -56,7 +56,7 @@ }; - public ParameterTypeEditor(final ScriptModel script, final PluginParameter<?, ?> parameter) { + public ParameterTypeEditor(final Script script, final PluginParameter<?, ?> parameter) { super(PluginParameterFactory.getTypes()); this.parameter = parameter; this.script = script; Modified: trunk/src/app/net/sf/gridarta/script/BshThread.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/BshThread.java 2008-10-01 21:03:46 UTC (rev 5355) +++ trunk/src/app/net/sf/gridarta/script/BshThread.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -30,7 +30,7 @@ public final class BshThread extends Thread { /** The ScriptModel of this BshThread. */ - private ScriptModel script; + private Script script; /** The Interpreter of this BshThread. */ private Interpreter interpreter; @@ -68,7 +68,7 @@ * Sets the ScriptModel for this BshThread. * @param script ScriptModel for this BshThread. */ - public void setScript(final ScriptModel script) { + public void setScript(final Script script) { this.script = script; } Copied: trunk/src/app/net/sf/gridarta/script/Script.java (from rev 5352, trunk/src/app/net/sf/gridarta/script/ScriptModel.java) =================================================================== --- trunk/src/app/net/sf/gridarta/script/Script.java (rev 0) +++ trunk/src/app/net/sf/gridarta/script/Script.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -0,0 +1,329 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 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.script; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import net.sf.gridarta.script.parameter.NoSuchParameterException; +import net.sf.gridarta.script.parameter.PluginParameter; +import net.sf.gridarta.script.parameter.PluginParameterFactory; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Model for Scripts. + * @author tchize + * @todo documentation + */ +public final class Script implements Cloneable, Iterable<PluginParameter<?, ?>> { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(Script.class); + + private String code = ""; + + private final List<PluginParameter<?, ?>> parameters = new ArrayList<PluginParameter<?, ?>>(); + + /** + * The script name. + */ + @NotNull + private final String name; + + private boolean autoboot = false; + + private boolean filter = false; + + private boolean script = false; + + private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(); + + /** + * The location to save this script to; set to <code>null</code> if the + * script has no associated location. + */ + @Nullable + private File file = null; + + /** Whether the script contents has been modified since last save. */ + private boolean modified = false; + + /** + * Creates a new instance. + * @param name the script name + */ + public Script(@NotNull final String name) { + this.name = name; + } + + /** + * Returns the name of this ScriptModel. + * @return The name of this ScriptModel. + */ + public String getName() { + return name; + } + + /** + * Returns the code of this ScriptModel. + * @return The code of this ScriptModel. + * @todo Improve name - what code is it? Source code? A special coded + * String? + */ + public String getCode() { + return code; + } + + /** + * Sets the code of this ScriptModel. + * @param code The code of this ScriptModel. + */ + public void setCode(final String code) { + if (this.code.equals(code)) { + return; + } + + this.code = code; + modified = true; + notifyListeners(); + } + + /** + * Returns whether this script has at least one parameter. + * @return whether this script has at least one parameter + */ + public boolean hasParameters() { + return !parameters.isEmpty(); + } + + /** + * Returns the index for a parameter name. + * @param paramName the parameter name + * @return the index or <code>-1</code> if the parameter name does not + * exist + */ + public int getParameter(@NotNull final String paramName) { + int index = 0; + for (final PluginParameter<?, ?> param : parameters) { + if (param.getName().equals(paramName)) { + return index; + } + index++; + } + return -1; + } + + @Override + public String toString() { + return name; + } + + public void newParameter() { + final PluginParameter<?, ?> p; + try { + p = PluginParameterFactory.createParameter((String) null); + } catch (final NoSuchParameterException ex) { + log.warn("Cannot create parameter: " + ex.getMessage()); + return; + } + parameters.add(p); + modified = true; + notifyListeners(); + } + + public void removeParameter(final int index) { + parameters.remove(index); + modified = true; + notifyListeners(); + } + + public void addChangeListener(final ChangeListener listener) { + listeners.add(listener); + } + + public void removeListener(final ChangeListener listener) { + listeners.remove(listener); + } + + /** Tell all listeners plugged on this ScriptModel its content has changed. */ + private void notifyListeners() { + final ChangeEvent e = new ChangeEvent(this); + for (final ChangeListener listener : listeners) { + listener.stateChanged(e); + } + } + + /** + * Get a clone copy of this SCriptModel. The copy include name, code, type + * and a clone of each parameter. The listener are not moved along. + * @return a clone of this ScriptModel + */ + @Override + public Object clone() throws CloneNotSupportedException { + final Script model = new Script(name); + model.code = code; + model.autoboot = autoboot; + model.filter = filter; + model.script = script; + model.modified = modified; + for (final PluginParameter<?, ?> param : parameters) { + model.addParameter((PluginParameter<?, ?>) param.clone()); + } + return model; + } + + /** + * Adds a parameter to this script. + * @param p the parameter to add + */ + public void addParameter(final PluginParameter<?, ?> p) { + parameters.add(p); + modified = true; + notifyListeners(); + } + + /** + * Gets the PluginParameter at a given index. + * @param index The index of parameter to get. Must be between 0 and + * getParametersCount(). If index is out of range, result is undefined. + * @return the requested parameter + * @throws NoSuchParameterException if the index is invalid + */ + public PluginParameter<?, ?> getParameter(final int index) throws NoSuchParameterException { + try { + return parameters.get(index); + } catch (final IndexOutOfBoundsException ex) { + throw new NoSuchParameterException(index); + } + } + + /** + * Check if this script is an autoboot script (a script run at load time). + * @return true if script is an autoboot script, false otherwise + */ + public boolean isAutoboot() { + return autoboot; + } + + /** + * Check if this script is a script (script run from the run script menu). + * @return true if script is a script, false otherwise + */ + public boolean isScript() { + return script; + } + + /** + * Check if this script is a filter script (will appear in the map filter + * list menu). + * @return true if the script is a filter script, false otherwise + */ + public boolean isFilter() { + return filter; + } + + public void setAutoboot(final boolean autoboot) { + if (this.autoboot == autoboot) { + return; + } + this.autoboot = autoboot; + modified = true; + notifyListeners(); + } + + public void setScript(final boolean script) { + if (this.script == script) { + return; + } + this.script = script; + modified = true; + notifyListeners(); + } + + public void setFilter(final boolean filter) { + if (this.filter == filter) { + return; + } + this.filter = filter; + modified = true; + notifyListeners(); + } + + public void convertType(final int index, final String newType) throws NoSuchParameterException { + parameters.set(index, PluginParameterFactory.createParameter(newType, parameters.get(index).toXML())); + modified = true; + notifyListeners(); + } + + public void convertType(final PluginParameter<?, ?> parameter, final String newType) throws NoSuchParameterException { + final int index = parameters.indexOf(parameter); + convertType(index, newType); + } + + /** + * Return whether the script contents has been modified since last save. + * @return Whether the script contents has been modified since last save. + */ + public boolean isModified() { + return modified; + } + + /** Mark the script as unmodified since last save. */ + public void resetModified() { + if (!modified) { + return; + } + + modified = false; + notifyListeners(); + } + + /** + * Return the location to save this script to. + * @return The location to save to, or <code>null</code> if the script has + * no associated location. + */ + @Nullable + public File getFile() { + return file; + } + + /** + * Set The location to save this script to. + * @param file The location; may be <code>null</code>. + */ + public void setFile(@Nullable final File file) { + this.file = file; + } + + /** {@inheritDoc} */ + public Iterator<PluginParameter<?, ?>> iterator() { + return Collections.unmodifiableList(parameters).iterator(); + } + +} // class Script Modified: trunk/src/app/net/sf/gridarta/script/ScriptControlListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/ScriptControlListener.java 2008-10-01 21:03:46 UTC (rev 5355) +++ trunk/src/app/net/sf/gridarta/script/ScriptControlListener.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -20,7 +20,6 @@ package net.sf.gridarta.script; import java.util.EventListener; -import net.sf.gridarta.script.ScriptModel; import org.jetbrains.annotations.NotNull; /** @@ -33,18 +32,18 @@ * Notifies about the creation of a new script. * @param script the created script */ - void scriptCreated(@NotNull ScriptModel script); + void scriptCreated(@NotNull Script script); /** * Notifies about the deletion of a script. * @param script the deleted script */ - void scriptDeleted(@NotNull ScriptModel script); + void scriptDeleted(@NotNull Script script); /** * Notifies about the registering of a script. * @param script the registered script */ - void scriptRegistered(@NotNull ScriptModel script); + void scriptRegistered(@NotNull Script script); } // interface ScriptControlListener Deleted: trunk/src/app/net/sf/gridarta/script/ScriptModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/ScriptModel.java 2008-10-01 21:03:46 UTC (rev 5355) +++ trunk/src/app/net/sf/gridarta/script/ScriptModel.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -1,329 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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.script; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import net.sf.gridarta.script.parameter.NoSuchParameterException; -import net.sf.gridarta.script.parameter.PluginParameter; -import net.sf.gridarta.script.parameter.PluginParameterFactory; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Model for Scripts. - * @author tchize - * @todo documentation - */ -public final class ScriptModel implements Cloneable, Iterable<PluginParameter<?, ?>> { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ScriptModel.class); - - private String code = ""; - - private final List<PluginParameter<?, ?>> parameters = new ArrayList<PluginParameter<?, ?>>(); - - /** - * The script name. - */ - @NotNull - private final String name; - - private boolean autoboot = false; - - private boolean filter = false; - - private boolean script = false; - - private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(); - - /** - * The location to save this script to; set to <code>null</code> if the - * script has no associated location. - */ - @Nullable - private File file = null; - - /** Whether the script contents has been modified since last save. */ - private boolean modified = false; - - /** - * Creates a new instance. - * @param name the script name - */ - public ScriptModel(@NotNull final String name) { - this.name = name; - } - - /** - * Returns the name of this ScriptModel. - * @return The name of this ScriptModel. - */ - public String getName() { - return name; - } - - /** - * Returns the code of this ScriptModel. - * @return The code of this ScriptModel. - * @todo Improve name - what code is it? Source code? A special coded - * String? - */ - public String getCode() { - return code; - } - - /** - * Sets the code of this ScriptModel. - * @param code The code of this ScriptModel. - */ - public void setCode(final String code) { - if (this.code.equals(code)) { - return; - } - - this.code = code; - modified = true; - notifyListeners(); - } - - /** - * Returns whether this script has at least one parameter. - * @return whether this script has at least one parameter - */ - public boolean hasParameters() { - return !parameters.isEmpty(); - } - - /** - * Returns the index for a parameter name. - * @param paramName the parameter name - * @return the index or <code>-1</code> if the parameter name does not - * exist - */ - public int getParameter(@NotNull final String paramName) { - int index = 0; - for (final PluginParameter<?, ?> param : parameters) { - if (param.getName().equals(paramName)) { - return index; - } - index++; - } - return -1; - } - - @Override - public String toString() { - return name; - } - - public void newParameter() { - final PluginParameter<?, ?> p; - try { - p = PluginParameterFactory.createParameter((String) null); - } catch (final NoSuchParameterException ex) { - log.warn("Cannot create parameter: " + ex.getMessage()); - return; - } - parameters.add(p); - modified = true; - notifyListeners(); - } - - public void removeParameter(final int index) { - parameters.remove(index); - modified = true; - notifyListeners(); - } - - public void addChangeListener(final ChangeListener listener) { - listeners.add(listener); - } - - public void removeListener(final ChangeListener listener) { - listeners.remove(listener); - } - - /** Tell all listeners plugged on this ScriptModel its content has changed. */ - private void notifyListeners() { - final ChangeEvent e = new ChangeEvent(this); - for (final ChangeListener listener : listeners) { - listener.stateChanged(e); - } - } - - /** - * Get a clone copy of this SCriptModel. The copy include name, code, type - * and a clone of each parameter. The listener are not moved along. - * @return a clone of this ScriptModel - */ - @Override - public Object clone() throws CloneNotSupportedException { - final ScriptModel model = new ScriptModel(name); - model.code = code; - model.autoboot = autoboot; - model.filter = filter; - model.script = script; - model.modified = modified; - for (final PluginParameter<?, ?> param : parameters) { - model.addParameter((PluginParameter<?, ?>) param.clone()); - } - return model; - } - - /** - * Adds a parameter to this script. - * @param p the parameter to add - */ - public void addParameter(final PluginParameter<?, ?> p) { - parameters.add(p); - modified = true; - notifyListeners(); - } - - /** - * Gets the PluginParameter at a given index. - * @param index The index of parameter to get. Must be between 0 and - * getParametersCount(). If index is out of range, result is undefined. - * @return the requested parameter - * @throws NoSuchParameterException if the index is invalid - */ - public PluginParameter<?, ?> getParameter(final int index) throws NoSuchParameterException { - try { - return parameters.get(index); - } catch (final IndexOutOfBoundsException ex) { - throw new NoSuchParameterException(index); - } - } - - /** - * Check if this script is an autoboot script (a script run at load time). - * @return true if script is an autoboot script, false otherwise - */ - public boolean isAutoboot() { - return autoboot; - } - - /** - * Check if this script is a script (script run from the run script menu). - * @return true if script is a script, false otherwise - */ - public boolean isScript() { - return script; - } - - /** - * Check if this script is a filter script (will appear in the map filter - * list menu). - * @return true if the script is a filter script, false otherwise - */ - public boolean isFilter() { - return filter; - } - - public void setAutoboot(final boolean autoboot) { - if (this.autoboot == autoboot) { - return; - } - this.autoboot = autoboot; - modified = true; - notifyListeners(); - } - - public void setScript(final boolean script) { - if (this.script == script) { - return; - } - this.script = script; - modified = true; - notifyListeners(); - } - - public void setFilter(final boolean filter) { - if (this.filter == filter) { - return; - } - this.filter = filter; - modified = true; - notifyListeners(); - } - - public void convertType(final int index, final String newType) throws NoSuchParameterException { - parameters.set(index, PluginParameterFactory.createParameter(newType, parameters.get(index).toXML())); - modified = true; - notifyListeners(); - } - - public void convertType(final PluginParameter<?, ?> parameter, final String newType) throws NoSuchParameterException { - final int index = parameters.indexOf(parameter); - convertType(index, newType); - } - - /** - * Return whether the script contents has been modified since last save. - * @return Whether the script contents has been modified since last save. - */ - public boolean isModified() { - return modified; - } - - /** Mark the script as unmodified since last save. */ - public void resetModified() { - if (!modified) { - return; - } - - modified = false; - notifyListeners(); - } - - /** - * Return the location to save this script to. - * @return The location to save to, or <code>null</code> if the script has - * no associated location. - */ - @Nullable - public File getFile() { - return file; - } - - /** - * Set The location to save this script to. - * @param file The location; may be <code>null</code>. - */ - public void setFile(@Nullable final File file) { - this.file = file; - } - - /** {@inheritDoc} */ - public Iterator<PluginParameter<?, ?>> iterator() { - return Collections.unmodifiableList(parameters).iterator(); - } - -} // class ScriptModel Modified: trunk/src/app/net/sf/gridarta/script/ScriptModelParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/ScriptModelParser.java 2008-10-01 21:03:46 UTC (rev 5355) +++ trunk/src/app/net/sf/gridarta/script/ScriptModelParser.java 2008-10-01 21:14:27 UTC (rev 5356) @@ -30,7 +30,7 @@ import org.jetbrains.annotations.NotNull; /** - * Utility parser class for {@link ScriptModel} instances. + * Utility parser class for {@link Script} instances. * @author tchize */ public class ScriptModelParser { @@ -44,8 +44,8 @@ private ScriptModelParser() { } - public static @NotNull final ScriptModel fromXML(@NotNull final Element node) { - final ScriptModel scriptModel = new ScriptModel(node.getChildTextTrim("name")); + public static @NotNull final Script fromXML(@NotNull final Element node) { + final Script scriptModel = new Script(node.getChildTextTrim("name")); scriptModel.setCode(node.getChildTextTrim("code")); boolean isAutoboot = false; boolean isFilter = false; @@ -87,7 +87,7 @@ return scriptModel; } - public static Element toXML(@NotNull final ScriptModel scriptModel) { + public static Element toXML(@NotNull final Script scriptModel) { final Element root = new Element("script"); final Element n = new Element("name"); final Element c = new Element("code"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 21:35:28
|
Revision: 5360 http://gridarta.svn.sourceforge.net/gridarta/?rev=5360&view=rev Author: akirschbaum Date: 2008-10-01 21:35:06 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move ScriptModel to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java trunk/crossfire/src/cfeditor/gui/script/ScriptManagerFactory.java trunk/crossfire/src/cfeditor/gui/script/ScriptView.java trunk/crossfire/src/cfeditor/script/ScriptController.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/script/ScriptModel.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/script/ScriptModel.java Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 21:31:42 UTC (rev 5359) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 21:35:06 UTC (rev 5360) @@ -24,7 +24,6 @@ import cfeditor.gui.map.CMapViewBasic; import cfeditor.map.MapArchObject; import cfeditor.script.ScriptController; -import cfeditor.script.ScriptModel; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; @@ -47,6 +46,7 @@ import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.script.Script; import net.sf.gridarta.script.ScriptControlListener; +import net.sf.gridarta.script.ScriptModel; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptManagerFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptManagerFactory.java 2008-10-01 21:31:42 UTC (rev 5359) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptManagerFactory.java 2008-10-01 21:35:06 UTC (rev 5360) @@ -24,9 +24,9 @@ import cfeditor.gui.map.CMapViewBasic; import cfeditor.map.MapArchObject; import cfeditor.script.ScriptController; -import cfeditor.script.ScriptModel; import javax.swing.JFrame; import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; +import net.sf.gridarta.script.ScriptModel; import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 21:31:42 UTC (rev 5359) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 21:35:06 UTC (rev 5360) @@ -26,7 +26,6 @@ import cfeditor.gui.map.CMapViewBasic; import cfeditor.map.MapArchObject; import cfeditor.script.ScriptController; -import cfeditor.script.ScriptModel; import java.awt.BorderLayout; import java.awt.Component; import java.awt.GridBagConstraints; @@ -49,6 +48,7 @@ import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.gridarta.script.Script; import net.sf.gridarta.script.ScriptControlListener; +import net.sf.gridarta.script.ScriptModel; import net.sf.gridarta.script.parameter.PluginParameter; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ReflectionAction; Modified: trunk/crossfire/src/cfeditor/script/ScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 21:31:42 UTC (rev 5359) +++ trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 21:35:06 UTC (rev 5360) @@ -47,6 +47,7 @@ import net.sf.gridarta.script.BshThread; import net.sf.gridarta.script.Script; import net.sf.gridarta.script.ScriptExecException; +import net.sf.gridarta.script.ScriptModel; import net.sf.gridarta.script.ScriptModelParser; import net.sf.gridarta.script.ScriptParameters; import net.sf.gridarta.script.ScriptRunMode; Deleted: trunk/crossfire/src/cfeditor/script/ScriptModel.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptModel.java 2008-10-01 21:31:42 UTC (rev 5359) +++ trunk/crossfire/src/cfeditor/script/ScriptModel.java 2008-10-01 21:35:06 UTC (rev 5360) @@ -1,153 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.script; - -import java.util.Collections; -import java.util.Iterator; -import java.util.Map; -import java.util.TreeMap; -import javax.swing.event.EventListenerList; -import net.sf.gridarta.script.Script; -import net.sf.gridarta.script.ScriptControlListener; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @author tchize - * @author Andreas Kirschbaum - */ -public class ScriptModel implements Iterable<Script> { - - @NotNull - private final Map<String, Script> scripts = new TreeMap<String, Script>(); - - /** - * The {@link ScriptControlListener}s to inform of changes. - */ - @NotNull - private final EventListenerList listeners = new EventListenerList(); - - /** - * Creates a new instance. - */ - public ScriptModel() { - } - - @Nullable - public Script getScript(@NotNull final String name) { - return scripts.get(name); - } - - public int getScriptCount() { - return scripts.size(); - } - - @Nullable - public Script getScript(int index) { - final Iterator<Script> i = scripts.values().iterator(); - Script m = null; - while (i.hasNext() && index-- >= 0) { - m = i.next(); - } - if (index >= 0) { - return null; - } else { - return m; - } - } - - /** - * Add a new script. - * @param script the script to add - * @return <code>true</code> if the script was added, or <code>false</code> - * if the script name already exists - */ - public boolean addScript(@NotNull final Script script) { - if (scripts.containsKey(script.getName())) { - return false; - } - - scripts.put(script.getName(), script); - fireScriptCreatedEvent(script); - return true; - } - - public void removeScript(@NotNull final Script script) { - if (!scripts.containsKey(script.getName())) { - throw new IllegalArgumentException(); - } - - scripts.remove(script.getName()); - fireScriptDeletedEvent(script); - } - - /** - * Adds a listener to be informed of changes. - * @param listener the listener - */ - public void addScriptControlListener(@NotNull final ScriptControlListener listener) { - listeners.add(ScriptControlListener.class, listener); - } - - /** - * Removes a listener to be informed of changes. - * @param listener the listener - */ - public void removeScriptControlListener(@NotNull final ScriptControlListener listener) { - listeners.remove(ScriptControlListener.class, listener); - } - - /** - * Notify all listeners about an added script. - * @param script the added script - */ - private void fireScriptCreatedEvent(@NotNull final Script script) { - for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { - listener.scriptCreated(script); - } - } - - /** - * Notifies all listeners about a removed script. - * @param script the removed script - */ - private void fireScriptDeletedEvent(@NotNull final Script script) { - for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { - listener.scriptDeleted(script); - } - } - - /** - * Notifies all listeners about a registered script. - * @param script the registered script - */ - public void fireScriptRegisteredEvent(@NotNull final Script script) { - for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { - listener.scriptRegistered(script); - } - } - - /** {@inheritDoc} */ - @NotNull - public Iterator<Script> iterator() { - return Collections.unmodifiableCollection(scripts.values()).iterator(); - } - -} // class ScriptModel Copied: trunk/src/app/net/sf/gridarta/script/ScriptModel.java (from rev 5357, trunk/crossfire/src/cfeditor/script/ScriptModel.java) =================================================================== --- trunk/src/app/net/sf/gridarta/script/ScriptModel.java (rev 0) +++ trunk/src/app/net/sf/gridarta/script/ScriptModel.java 2008-10-01 21:35:06 UTC (rev 5360) @@ -0,0 +1,153 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 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.script; + +import java.util.Collections; +import java.util.Iterator; +import java.util.Map; +import java.util.TreeMap; +import javax.swing.event.EventListenerList; +import net.sf.gridarta.script.Script; +import net.sf.gridarta.script.ScriptControlListener; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author tchize + * @author Andreas Kirschbaum + */ +public class ScriptModel implements Iterable<Script> { + + @NotNull + private final Map<String, Script> scripts = new TreeMap<String, Script>(); + + /** + * The {@link ScriptControlListener}s to inform of changes. + */ + @NotNull + private final EventListenerList listeners = new EventListenerList(); + + /** + * Creates a new instance. + */ + public ScriptModel() { + } + + @Nullable + public Script getScript(@NotNull final String name) { + return scripts.get(name); + } + + public int getScriptCount() { + return scripts.size(); + } + + @Nullable + public Script getScript(int index) { + final Iterator<Script> i = scripts.values().iterator(); + Script m = null; + while (i.hasNext() && index-- >= 0) { + m = i.next(); + } + if (index >= 0) { + return null; + } else { + return m; + } + } + + /** + * Add a new script. + * @param script the script to add + * @return <code>true</code> if the script was added, or <code>false</code> + * if the script name already exists + */ + public boolean addScript(@NotNull final Script script) { + if (scripts.containsKey(script.getName())) { + return false; + } + + scripts.put(script.getName(), script); + fireScriptCreatedEvent(script); + return true; + } + + public void removeScript(@NotNull final Script script) { + if (!scripts.containsKey(script.getName())) { + throw new IllegalArgumentException(); + } + + scripts.remove(script.getName()); + fireScriptDeletedEvent(script); + } + + /** + * Adds a listener to be informed of changes. + * @param listener the listener + */ + public void addScriptControlListener(@NotNull final ScriptControlListener listener) { + listeners.add(ScriptControlListener.class, listener); + } + + /** + * Removes a listener to be informed of changes. + * @param listener the listener + */ + public void removeScriptControlListener(@NotNull final ScriptControlListener listener) { + listeners.remove(ScriptControlListener.class, listener); + } + + /** + * Notify all listeners about an added script. + * @param script the added script + */ + private void fireScriptCreatedEvent(@NotNull final Script script) { + for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { + listener.scriptCreated(script); + } + } + + /** + * Notifies all listeners about a removed script. + * @param script the removed script + */ + private void fireScriptDeletedEvent(@NotNull final Script script) { + for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { + listener.scriptDeleted(script); + } + } + + /** + * Notifies all listeners about a registered script. + * @param script the registered script + */ + public void fireScriptRegisteredEvent(@NotNull final Script script) { + for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { + listener.scriptRegistered(script); + } + } + + /** {@inheritDoc} */ + @NotNull + public Iterator<Script> iterator() { + return Collections.unmodifiableCollection(scripts.values()).iterator(); + } + +} // class ScriptModel This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-01 21:55:27
|
Revision: 5363 http://gridarta.svn.sourceforge.net/gridarta/?rev=5363&view=rev Author: akirschbaum Date: 2008-10-01 21:55:17 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Move remaining script related classes to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/script/ScriptEditor.java trunk/src/app/net/sf/gridarta/gui/script/ScriptManager.java trunk/src/app/net/sf/gridarta/gui/script/ScriptManagerFactory.java trunk/src/app/net/sf/gridarta/gui/script/ScriptView.java trunk/src/app/net/sf/gridarta/script/ScriptController.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java trunk/crossfire/src/cfeditor/gui/script/ScriptManagerFactory.java trunk/crossfire/src/cfeditor/gui/script/ScriptView.java trunk/crossfire/src/cfeditor/script/ScriptController.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-01 21:42:44 UTC (rev 5362) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-01 21:55:17 UTC (rev 5363) @@ -34,7 +34,6 @@ import cfeditor.gui.prefs.ResPrefs; import cfeditor.map.DefaultMapControlFactory; import cfeditor.map.MapArchObject; -import cfeditor.script.ScriptController; import java.io.File; import java.util.Collections; import java.util.List; @@ -85,6 +84,7 @@ import net.sf.gridarta.map.validation.checks.MapDifficultyChecker; import net.sf.gridarta.map.validation.checks.UndefinedArchetypeChecker; import net.sf.gridarta.map.validation.checks.UnsetSlayingChecker; +import net.sf.gridarta.script.ScriptController; import net.sf.gridarta.script.ScriptExecException; import net.sf.gridarta.script.ScriptParameters; import net.sf.gridarta.script.parameter.PluginParameterFactory; @@ -109,7 +109,7 @@ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); /** The current script controller. */ - private ScriptController scriptControl; + private ScriptController<GameObject, MapArchObject, Archetype, CMapViewBasic> scriptControl; private FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl; @@ -218,7 +218,7 @@ final ScriptParameters scriptParameters = new ScriptParameters(archetypeSet, globalSettings, mapManager, validators); final NamedFilterList defaultFilterList = new NamedFilterList(Collections.<NamedGameObjectMatcher>emptyList()); final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory = new PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic>(archetypeSet, gameObjectAttributesModel, objectChooser, defaultFilterList, mapManager); - scriptControl = new ScriptController(filterControl, scriptParameters, getMainView(), pluginParameterViewFactory); + scriptControl = new ScriptController<GameObject, MapArchObject, Archetype, CMapViewBasic>(filterControl, scriptParameters, getMainView(), pluginParameterViewFactory); } /** {@inheritDoc} */ Deleted: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 21:42:44 UTC (rev 5362) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-10-01 21:55:17 UTC (rev 5363) @@ -1,407 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script; - -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.CMapViewBasic; -import cfeditor.map.MapArchObject; -import cfeditor.script.ScriptController; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.util.HashMap; -import java.util.Map; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.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.script.StackLayout; -import net.sf.gridarta.gui.script.parameter.ParameterDescriptionEditor; -import net.sf.gridarta.gui.script.parameter.ParameterNameEditor; -import net.sf.gridarta.gui.script.parameter.ParameterTypeEditor; -import net.sf.gridarta.gui.script.parameter.PluginParameterView; -import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; -import net.sf.gridarta.gui.utils.GUIUtils; -import net.sf.gridarta.script.Script; -import net.sf.gridarta.script.parameter.NoSuchParameterException; -import net.sf.gridarta.script.parameter.PluginParameter; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; - -public class ScriptEditor extends JPanel { - - public static final String AUTORUN_SMALLICON = "AutorunSmallIcon.gif"; - - public static final String FILTER_SMALLICON = "FilterSmallIcon.gif"; - - public static final String RUN_PLUGIN_SMALLICON = "RunPluginSmallIcon.gif"; - - private static final long serialVersionUID = 1L; - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ScriptEditor.class); - - @NotNull - private final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory; - - private final JPanel paramTable; - - private final JButton removeParameter; - - private final JTextArea code; - - private final Script script; - - private final Map<PluginParameter<?, ?>, ParameterNameEditor> paramNameEditors = new HashMap<PluginParameter<?, ?>, ParameterNameEditor>(); - - private final Map<PluginParameter<?, ?>, ParameterDescriptionEditor> paramDescriptionEditors = new HashMap<PluginParameter<?, ?>, ParameterDescriptionEditor>(); - - private final Map<PluginParameter<?, ?>, ParameterTypeEditor> paramTypeEditors = new HashMap<PluginParameter<?, ?>, ParameterTypeEditor>(); - - private final Map<PluginParameter<?, ?>, PluginParameterView> paramViews = new HashMap<PluginParameter<?, ?>, PluginParameterView>(); - - private int selectedRow = -1; - - private final MouseListener cellMouseListener = new MouseListener() { - public void mouseClicked(final MouseEvent e) { - selectTableComponent((Component) e.getSource()); - } - - public void mouseEntered(final MouseEvent e) { - } - - public void mouseExited(final MouseEvent e) { - } - - public void mousePressed(final MouseEvent e) { - selectTableComponent((Component) e.getSource()); - } - - public void mouseReleased(final MouseEvent e) { - selectTableComponent((Component) e.getSource()); - } - }; - - private final FocusListener cellFocusListener = new FocusListener() { - public void focusGained(final FocusEvent e) { - selectTableComponent((Component) e.getSource()); - } - - public void focusLost(final FocusEvent e) { - } - }; - - private final JCheckBox typeAutorun; - - private final JCheckBox typeFilter; - - private final JCheckBox typeBash; - - /** - * Create a visual JComponent used to edit the given script. - * @param script the script object to edit - * @param scriptController the associated script control instance - */ - public ScriptEditor(final Script script, final ScriptController scriptController, final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { - this.script = script; - this.pluginParameterViewFactory = pluginParameterViewFactory; - final JTabbedPane tabs = new JTabbedPane(); - setLayout(new BorderLayout()); - add(tabs); - final JPanel optionsTab = new JPanel(new GridBagLayout()); - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.weightx = 1.0; - gbc.gridwidth = 2; - optionsTab.add(new JLabel("Plugin run mode", SwingConstants.LEFT), gbc); - gbc.gridwidth = 1; - gbc.gridy = 1; - gbc.weightx = 0.1; - optionsTab.add(new JPanel(), gbc); - gbc.gridx = 1; - gbc.weightx = 0.02; - final JLabel autorunIcon = new JLabel(GUIUtils.getIcon(AUTORUN_SMALLICON)); - optionsTab.add(autorunIcon, gbc); - gbc.gridy = 2; - final JLabel filterIcon = new JLabel(GUIUtils.getIcon(FILTER_SMALLICON)); - optionsTab.add(filterIcon, gbc); - gbc.gridy = 3; - final JLabel runPluginIcon = new JLabel(GUIUtils.getIcon(RUN_PLUGIN_SMALLICON)); - optionsTab.add(runPluginIcon, gbc); - gbc.gridx = 2; - gbc.gridy = 1; - gbc.weightx = 0.9; - gbc.fill = GridBagConstraints.NONE; - gbc.anchor = GridBagConstraints.WEST; - typeAutorun = new JCheckBox("autorun at application startup"); - typeAutorun.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - getScript().setAutoboot(typeAutorun.isSelected()); - } - }); - typeAutorun.setSelected(script.isAutoboot()); - optionsTab.add(typeAutorun, gbc); - gbc.gridy = 2; - typeFilter = new JCheckBox("reference in the filters list"); - typeFilter.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - getScript().setFilter(typeFilter.isSelected()); - } - }); - typeFilter.setSelected(script.isFilter()); - optionsTab.add(typeFilter, gbc); - gbc.gridy = 3; - typeBash = new JCheckBox("reference in the manual run list"); - typeBash.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - getScript().setScript(typeBash.isSelected()); - } - }); - typeBash.setSelected(script.isScript()); - optionsTab.add(typeBash, gbc); - gbc.gridx = 0; - gbc.gridy = 4; - final JButton registerButton = new JButton("re-register script"); - registerButton.setToolTipText("Force plugin manager to unregister this plugin from filter list, launch the autrun (if plugin is autostart) and re-register it (if filter plugin)"); - registerButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - scriptController.reRegister(getScript().getName()); - } - }); - optionsTab.add(registerButton, gbc); - tabs.add("Options", optionsTab); - gbc.gridy = 5; - final JButton exportButton = new JButton("Export script..."); - exportButton.setToolTipText("Export the specified plugin as XML (for distribution)"); - exportButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - scriptController.saveScriptAs(getScript(), false); - } - }); - optionsTab.add(exportButton, gbc); - tabs.add("Options", optionsTab); - final JPanel parameterTab = new JPanel(new BorderLayout()); - paramTable = new JPanel(new GridBagLayout()); - redrawTable(); - script.addChangeListener(new ChangeListener() { - public void stateChanged(final ChangeEvent e) { - redrawTable(); - } - }); - final JScrollPane scrollPane1 = new JScrollPane(paramTable); - parameterTab.add(scrollPane1, BorderLayout.CENTER); - //parameterTab.add(paramTable, BorderLayout.CENTER); - final JPanel paramButtons = new JPanel(); - paramButtons.setLayout(new StackLayout(5)); - final JButton addParameter = new JButton("Add parameter"); - addParameter.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - getScript().newParameter(); - } - }); - removeParameter = new JButton("Remove parameter"); - removeParameter.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - if (selectedRow < 0) { - return; - } - - final PluginParameter<?, ?> parameter; - try { - parameter = getScript().getParameter(selectedRow); - } catch (final NoSuchParameterException ex) { - return; - } - final String name = parameter.getName(); - if (JOptionPane.showConfirmDialog(removeParameter, "Delete " + name + "?", "Delete?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - getScript().removeParameter(selectedRow); - } - } - }); - paramButtons.add(addParameter); - paramButtons.add(removeParameter); - parameterTab.add(paramButtons, BorderLayout.EAST); - tabs.addTab("Manual run parameters", parameterTab); - code = new JTextArea(); - code.setText(script.getCode()); - code.setFont(new Font("Monospaced", Font.PLAIN, 14)); - code.getDocument().addDocumentListener(new DocumentListener() { - public void changedUpdate(final DocumentEvent e) { - getScript().setCode(code.getText()); - } - - public void insertUpdate(final DocumentEvent e) { - getScript().setCode(code.getText()); - } - - public void removeUpdate(final DocumentEvent e) { - getScript().setCode(code.getText()); - } - }); - final JScrollPane scrollPane2 = new JScrollPane(code); - final JPanel codePanel = new JPanel(new BorderLayout()); - codePanel.add(scrollPane2, BorderLayout.CENTER); - final JPanel codeBottom = new JPanel(new FlowLayout()); - final JButton test = new JButton("Run Script..."); - test.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - scriptController.runScript(getScript()); - } - }); - codeBottom.add(test); - codePanel.add(codeBottom, BorderLayout.SOUTH); - tabs.addTab("Code", codePanel); - } - - public void selectTableComponent(final Component c) { - final GridBagLayout l = (GridBagLayout) paramTable.getLayout(); - final GridBagConstraints gbc = l.getConstraints(c); - if (gbc != null) { - selectedRow = gbc.gridy - 1; - } - } - - private void redrawTable() { - final GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 5, 0); - paramTable.removeAll(); - paramTable.add(new JLabel("Name"), gbc); - gbc.gridx = 1; - paramTable.add(new JLabel("Description"), gbc); - gbc.gridx = 2; - paramTable.add(new JLabel("Type"), gbc); - gbc.gridx = 3; - paramTable.add(new JLabel("Config"), gbc); - gbc.gridx = 4; - paramTable.add(new JLabel("Default"), gbc); - int i = 0; - for (final PluginParameter<?, ?> parameter : script) { - gbc.gridy = i + 1; - putRow(gbc, parameter); - i++; - } - repaint(); - } - - private void newTableComponent(final Component c) { - c.addFocusListener(cellFocusListener); - c.addMouseListener(cellMouseListener); - } - - private ParameterNameEditor getParameterNameEditor(final PluginParameter<?, ?> param) { - if (log.isDebugEnabled()) { - log.debug("Doing " + param); - } - - final ParameterNameEditor existingParameterNameEditor = paramNameEditors.get(param); - if (existingParameterNameEditor != null) { - return existingParameterNameEditor; - } - - final ParameterNameEditor newParameterNameEditor = new ParameterNameEditor(param); - paramNameEditors.put(param, newParameterNameEditor); - newTableComponent(newParameterNameEditor); - return newParameterNameEditor; - } - - private ParameterDescriptionEditor getParameterDescriptionEditor(final PluginParameter<?, ?> param) { - final ParameterDescriptionEditor existingParameterDescriptionEditor = paramDescriptionEditors.get(param); - if (existingParameterDescriptionEditor != null) { - return existingParameterDescriptionEditor; - } - - final ParameterDescriptionEditor newParameterDescriptionEditor = new ParameterDescriptionEditor(param); - newTableComponent(newParameterDescriptionEditor); - paramDescriptionEditors.put(param, newParameterDescriptionEditor); - return newParameterDescriptionEditor; - } - - private ParameterTypeEditor getParameterTypeEditor(final PluginParameter<?, ?> param) { - final ParameterTypeEditor existingPArameterTypeEditor = paramTypeEditors.get(param); - if (existingPArameterTypeEditor != null) { - return existingPArameterTypeEditor; - } - - final ParameterTypeEditor newParameterTypeEditor = new ParameterTypeEditor(script, param); - paramTypeEditors.put(param, newParameterTypeEditor); - newTableComponent(newParameterTypeEditor); - return newParameterTypeEditor; - } - - private PluginParameterView getParameterView(final PluginParameter<?, ?> param) { - final PluginParameterView existingPluginParameterView = paramViews.get(param); - if (existingPluginParameterView != null) { - return existingPluginParameterView; - } - - final PluginParameterView newPluginParameterView = pluginParameterViewFactory.getView(param); - if (log.isDebugEnabled()) { - log.debug("param.getValue() is " + param.getValue()); - } - - newTableComponent(newPluginParameterView.getConfigComponent(param.getConfig(), param)); - newTableComponent(newPluginParameterView.getValueComponent(param.getValue(), param)); - if (log.isDebugEnabled()) { - log.debug("param.getValue() is " + param.getValue()); - } - - paramViews.put(param, newPluginParameterView); - return newPluginParameterView; - } - - private void putRow(final GridBagConstraints gbc, final PluginParameter<?, ?> param) { - gbc.gridx = 0; - paramTable.add(getParameterNameEditor(param), gbc); - gbc.gridx = 1; - gbc.weightx = 0.5; - paramTable.add(getParameterDescriptionEditor(param), gbc); - gbc.gridx = 2; - gbc.weightx = 0.1; - paramTable.add(getParameterTypeEditor(param), gbc); - gbc.gridx = 3; - paramTable.add(getParameterView(param).getConfigComponent(param.getConfig(), param), gbc); - gbc.gridx = 4; - paramTable.add(getParameterView(param).getValueComponent(param.getValue(), param), gbc); - } - - private Script getScript() { - return script; - } - -} // class ScriptEditor Deleted: trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 21:42:44 UTC (rev 5362) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2008-10-01 21:55:17 UTC (rev 5363) @@ -1,218 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script; - -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.CMapViewBasic; -import cfeditor.map.MapArchObject; -import cfeditor.script.ScriptController; -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Color; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.HashMap; -import java.util.Map; -import javax.swing.AbstractListModel; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.ListModel; -import javax.swing.ListSelectionModel; -import javax.swing.border.LineBorder; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; -import net.sf.gridarta.script.Script; -import net.sf.gridarta.script.ScriptControlListener; -import net.sf.gridarta.script.ScriptModel; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class ScriptManager extends JFrame { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ScriptManager.class); - - private final JList scripts; - - private final JPanel scriptPanel; - - private final CardLayout scriptLayout; - - private final ScriptController scriptController; - - @NotNull - private final ScriptModel scriptModel; - - private final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory; - - //TODO fix a memory leak. If a script is remove, it stays in hashmap along with it's visual component - private final Map<Script, ScriptEditor> components = new HashMap<Script, ScriptEditor>(); - - private static final long serialVersionUID = 1L; - - /** - * Creates a ScriptManager. - * @param scriptController ScriptController to base this ScriptManager on. - */ - public ScriptManager(final ScriptController scriptController, @NotNull final ScriptModel scriptModel, @NotNull final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { - super("Editor plugins management"); - this.scriptController = scriptController; - this.scriptModel = scriptModel; - this.pluginParameterViewFactory = pluginParameterViewFactory; - getContentPane().setLayout(new BorderLayout()); - final JPanel left = new JPanel(new BorderLayout()); - scriptLayout = new CardLayout(); - scriptPanel = new JPanel(scriptLayout); - getContentPane().add(left, BorderLayout.WEST); - getContentPane().add(scriptPanel, BorderLayout.CENTER); - final ListModel listModel = new AbstractListModel() { - private static final long serialVersionUID = 7636033005940159801L; - - /** - * The script control listener to be notified about changes in {@link - * ScriptManager#scriptController}. - */ - private final ScriptControlListener scriptControlListener = new ScriptControlListener() { - - /** {@inheritDoc} */ - public void scriptCreated(@NotNull final Script script) { - fireContentsChanged(scripts, 0, ScriptManager.this.scriptModel.getScriptCount() + 1); - } - - /** {@inheritDoc} */ - public void scriptDeleted(@NotNull final Script script) { - fireContentsChanged(scripts, 0, ScriptManager.this.scriptModel.getScriptCount() + 1); - } - - /** {@inheritDoc} */ - public void scriptRegistered(@NotNull final Script script) { - fireContentsChanged(scripts, 0, ScriptManager.this.scriptModel.getScriptCount() + 1); - } - - }; - - { - ScriptManager.this.scriptModel.addScriptControlListener(scriptControlListener); - } - - @Nullable - public Object getElementAt(final int index) { - try { - return ScriptManager.this.scriptModel.getScript(index); - } catch (final Exception e) { - return null; - } - } - - public int getSize() { - return ScriptManager.this.scriptModel.getScriptCount(); - } - }; - scripts = new JList(listModel); - scripts.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(final ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - showScript((Script) scripts.getSelectedValue()); - } - } - }); - scripts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - scripts.setBorder(new LineBorder(Color.black, 1)); - left.add(scripts, BorderLayout.CENTER); - final JButton addScriptBtn = new JButton("New..."); - addScriptBtn.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - final String name = JOptionPane.showInputDialog(scripts, "Name of the new Beanshell plugin?"); - if (name != null) { - final Script script = new Script(name); - script.setCode("//input your beanshell Code"); - if (!ScriptManager.this.scriptModel.addScript(script)) { - JOptionPane.showMessageDialog(scripts, "The script " + name + " already exists.", "Error", JOptionPane.WARNING_MESSAGE); - } else { - showScript(script); - } - } - } - }); - final JButton removeScriptBtn = new JButton("Remove"); - removeScriptBtn.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - final Script script = (Script) scripts.getSelectedValue(); - if (script == null) { - return; - } - - if (JOptionPane.showConfirmDialog(scripts, "remove script name " + script.getName(), "remove", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - if (log.isDebugEnabled()) { - log.debug("removing"); - } - - ScriptManager.this.scriptModel.removeScript(script); - scripts.setSelectedIndex(0); - removeScript(script); - } - } - }); - final JPanel bottomLeft = new JPanel(new GridLayout(2, 1)); - bottomLeft.add(addScriptBtn); - bottomLeft.add(removeScriptBtn); - left.add(bottomLeft, BorderLayout.SOUTH); - scripts.setSelectedIndex(0); - pack(); - setVisible(true); - } - - private void showScript(final Script script) { - /* using a cardlayout is a necessary trick as - * simply removing previous component and putting - * the new one in the JPanel lead to problem unless - * we recreate the component each time - * (the validate process goes strangely and only portions - * of component are redrawn until window resize :s) - */ - if (script == null) { - return; - } - - ScriptEditor scriptEditor = components.get(script); - if (scriptEditor == null) { - scriptEditor = new ScriptEditor(script, scriptController, pluginParameterViewFactory); - components.put(script, scriptEditor); - scriptPanel.add(scriptEditor, Integer.toString(scriptEditor.hashCode())); - } - scriptLayout.show(scriptPanel, Integer.toString(scriptEditor.hashCode())); - } - - private void removeScript(final Script script) { - final ScriptEditor scriptEditor = components.get(script); - if (scriptEditor != null) { - components.remove(script); - scriptPanel.remove(scriptEditor); - } - } - -} // class ScriptManager Deleted: trunk/crossfire/src/cfeditor/gui/script/ScriptManagerFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptManagerFactory.java 2008-10-01 21:42:44 UTC (rev 5362) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptManagerFactory.java 2008-10-01 21:55:17 UTC (rev 5363) @@ -1,65 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script; - -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.CMapViewBasic; -import cfeditor.map.MapArchObject; -import cfeditor.script.ScriptController; -import javax.swing.JFrame; -import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; -import net.sf.gridarta.script.ScriptModel; -import net.sf.japi.swing.ActionFactory; -import org.jetbrains.annotations.NotNull; - -public class ScriptManagerFactory { - - /** Action Factory to create Actions. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - private JFrame scriptManager = null; - - private final ScriptController scriptController; - - private final ScriptModel scriptModel; - - private final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory; - - /** - * Creates a new instance. - */ - public ScriptManagerFactory(@NotNull final ScriptController scriptController, @NotNull final ScriptModel scriptModel, @NotNull final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { - this.scriptController = scriptController; - this.scriptModel = scriptModel; - this.pluginParameterViewFactory = pluginParameterViewFactory; - ACTION_FACTORY.createActions(true, this, "editPlugins"); - } - - public synchronized void editPlugins() { - if (scriptManager == null) { - scriptManager = new ScriptManager(scriptController, scriptModel, pluginParameterViewFactory); - } - - scriptManager.pack(); - scriptManager.setVisible(true); - } - -} // class ScriptManagerFactory Deleted: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 21:42:44 UTC (rev 5362) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-10-01 21:55:17 UTC (rev 5363) @@ -1,251 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.gui.script; - -import bsh.ConsoleInterface; -import bsh.util.JConsole; -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.CMapViewBasic; -import cfeditor.map.MapArchObject; -import cfeditor.script.ScriptController; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import javax.swing.Action; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import net.sf.gridarta.gui.script.CloseableTabbedPane; -import net.sf.gridarta.gui.script.ScriptViewPane; -import net.sf.gridarta.gui.script.parameter.PluginParameterView; -import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; -import net.sf.gridarta.gui.utils.MenuUtils; -import net.sf.gridarta.script.Script; -import net.sf.gridarta.script.ScriptControlListener; -import net.sf.gridarta.script.ScriptModel; -import net.sf.gridarta.script.parameter.PluginParameter; -import net.sf.japi.swing.ActionFactory; -import net.sf.japi.swing.ReflectionAction; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * View for Scripts. - * @author tchize - */ -public final class ScriptView { - - /** Action Factory to create Actions. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ScriptView.class); - - private final ScriptController scriptController; - - /** - * The script model. - */ - @NotNull - private final ScriptModel scriptModel; - - /** - * The parent component for showing dialog boxes. - */ - @NotNull - private final Component parent; - - @NotNull - private final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory; - - /** The menu to add script commands to. */ - @Nullable - private JMenu menuScripts = null; - - private JFrame console = null; - - private CloseableTabbedPane consolePane = null; - - /** - * The script control listener to be notified about changes in {@link - * #scriptController}. - */ - private final ScriptControlListener scriptControlListener = new ScriptControlListener() { - - /** {@inheritDoc} */ - public void scriptCreated(@NotNull final Script script) { - updateMenuEntries(); - } - - /** {@inheritDoc} */ - public void scriptDeleted(@NotNull final Script script) { - updateMenuEntries(); - } - - /** {@inheritDoc} */ - public void scriptRegistered(@NotNull final Script script) { - updateMenuEntries(); - } - - }; - - /** - * Creates a ScriptView. - * @param scriptController controller of this ScriptView - * @param scriptModel the script model - * @param parent the parent component for showing dialog boxes - * @warning Creating a view from a controller instead of a model is error - * prone. - */ - public ScriptView(@NotNull final ScriptController scriptController, @NotNull final ScriptModel scriptModel, @NotNull final Component parent, @NotNull final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { - this.scriptController = scriptController; - this.scriptModel = scriptModel; - this.parent = parent; - this.pluginParameterViewFactory = pluginParameterViewFactory; - ACTION_FACTORY.createActions(true, this, "savePlugins", "importPlugin"); - scriptModel.addScriptControlListener(scriptControlListener); - } - - /** - * Set the menu to add script commands to. Entries already present in the - * menu are deleted. - * @param menuScripts the plugins menu - */ - public synchronized void setMenu(@Nullable final JMenu menuScripts) { - this.menuScripts = menuScripts; - updateMenuEntries(); - } - - /** Refresh the menu entries. */ - private synchronized void updateMenuEntries() { - if (menuScripts == null) { - return; - } - - MenuUtils.removeAllToSeparator(menuScripts); - - int index = 0; - for (final Script script : scriptModel) { - if (!script.isScript()) { - continue; - } - - final Action action = ACTION_FACTORY.createAction(true, "runPlugin", this); - action.putValue(ReflectionAction.REFLECTION_ARGUMENTS, new Object[] {script.getName(),}); - action.putValue(Action.NAME, ACTION_FACTORY.format("runPlugin.text", script.getName())); - final JMenuItem item = new JMenuItem(action); - item.setActionCommand(script.getName()); - menuScripts.add(item, index++); - } - if (index == 0) { - final JMenuItem def = new JMenuItem("no scripts available"); - def.setEnabled(false); - menuScripts.add(def, 0); - } - } - - public void runPlugin(final String script) { - scriptController.runScript(script); - } - - public void savePlugins() { - scriptController.saveAllScripts(); - } - - public void importPlugin() { - final JFileChooser choose = new JFileChooser(); - choose.setDialogTitle("import script"); - if (choose.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { - scriptController.importXML(choose.getSelectedFile(), true); - } - } - - private synchronized void showConsoleFrame() { - if (console == null) { - console = new JFrame("Beanshell scripts I/O Console"); - console.setSize(400, 200); - consolePane = new CloseableTabbedPane(); - console.getContentPane().add(consolePane); - } - console.setVisible(true); - } - - public ConsoleInterface createConsole(final String name) { - showConsoleFrame(); - final JConsole bshConsole = new JConsole(); - consolePane.addCloseableTab(name, bshConsole, true); - return bshConsole; - } - - public boolean getRunValues(final Script script) { - if (!script.hasParameters()) { - return true; - } - - final ScriptViewPane p = new ScriptViewPane(); - p.setOptionType(JOptionPane.OK_CANCEL_OPTION); - p.setMessageType(JOptionPane.QUESTION_MESSAGE); - p.setMessage("Please provide runtime parameters for " + script.getName()); - final GridBagLayout layout = new GridBagLayout(); - final JPanel panel = new JPanel(layout); - final JDialog dialog = p.createDialog(parent, "hi"); - p.dialog = dialog; - dialog.setModal(true); - dialog.setTitle(script.getName()); - dialog.getContentPane().removeAll(); - int i = 0; - for (final PluginParameter<?, ?> parameter : script) { - log.debug("adding parameter"); - final JLabel name = new JLabel(parameter.getName()); - final PluginParameterView view = pluginParameterViewFactory.getView(parameter); - final JComponent val = view.getValueComponent(parameter.getValue(), parameter); - val.setToolTipText(parameter.getDescription()); - final GridBagConstraints gn = new GridBagConstraints(0, i, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 5, 5); - final GridBagConstraints gf = new GridBagConstraints(1, i, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 5, 5); - panel.add(name, gn); - panel.add(val, gf); - i++; - } - - dialog.getContentPane().setLayout(new BorderLayout()); - dialog.getContentPane().add(panel, BorderLayout.CENTER); - dialog.getContentPane().add(p, BorderLayout.SOUTH); - dialog.pack(); - dialog.setVisible(true); - final Object result = p.getValue(); - if (result instanceof Integer) { - if ((Integer) result == JOptionPane.YES_OPTION) { - return true; - } - } - return false; - } - -} // class ScriptView Deleted: trunk/crossfire/src/cfeditor/script/ScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 21:42:44 UTC (rev 5362) +++ trunk/crossfire/src/cfeditor/script/ScriptController.java 2008-10-01 21:55:17 UTC (rev 5363) @@ -1,503 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 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 cfeditor.script; - -import bsh.ConsoleInterface; -import bsh.EvalError; -import bsh.Interpreter; -import bsh.TargetError; -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.CMapViewBasic; -import cfeditor.gui.script.ScriptManagerFactory; -import cfeditor.gui.script.ScriptView; -import cfeditor.map.MapArchObject; -import java.awt.Component; -import java.io.CharArrayWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.Reader; -import java.util.List; -import javax.swing.JFileChooser; -import javax.swing.JOptionPane; -import net.sf.gridarta.filter.Filter; -import net.sf.gridarta.filter.FilterControl; -import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; -import net.sf.gridarta.script.BshThread; -import net.sf.gridarta.script.Script; -import net.sf.gridarta.script.ScriptExecException; -import net.sf.gridarta.script.ScriptModel; -import net.sf.gridarta.script.ScriptModelParser; -import net.sf.gridarta.script.ScriptParameters; -import net.sf.gridarta.script.ScriptRunMode; -import net.sf.gridarta.script.parameter.NoSuchParameterException; -import net.sf.gridarta.script.parameter.PluginParameter; -import net.sf.japi.swing.ActionFactory; -import org.apache.log4j.Logger; -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 org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Controller for Scripts. - * @author tchize - * @todo documentation - */ -public final class ScriptController { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ScriptController.class); - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - @NotNull - private final ScriptModel scriptModel = new ScriptModel(); - - private final ScriptView view; - - /** - * The script parameters to use. - */ - @NotNull - private final ScriptParameters scriptParameters; - - /** - * The parent component for dialog boxes. - */ - @NotNull - private final Component parent; - - @NotNull - private final FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl; - - /** The default directory for saving scripts. */ - @Nullable - private File scriptsDir = null; - - @NotNull - private final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory; - - public ScriptController(@NotNull final FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl, @NotNull final ScriptParameters scriptParameters, @NotNull final Component parent, @NotNull final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory) { - this.parent = parent; - this.filterControl = filterControl; - this.scriptParameters = scriptParameters; - this.pluginParameterViewFactory = pluginParameterViewFactory; - new ScriptManagerFactory(this, scriptModel, pluginParameterViewFactory); - view = new ScriptView(this, scriptModel, parent, pluginParameterViewFactory); - } - - /** - * Load all files as scripts from the given directory. - * @param scriptsDir The directory to load. - */ - public void loadScripts(@NotNull final File scriptsDir) { - this.scriptsDir = scriptsDir; - - final File[] files = scriptsDir.listFiles(); - if (files == null) { - log.warn("Scripts directory not readable: " + scriptsDir); - return; - } - - final int scriptCount = scriptModel.getScriptCount(); - for (final File scriptFile : files) { - final String name = scriptFile.getName(); - if (!name.startsWith(".") && !name.endsWith("~") && scriptFile.isFile()) { - importXML(scriptFile, false); - } - } - if (log.isInfoEnabled()) { - log.info("Loaded " + (scriptModel.getScriptCount() - scriptCount) + " scripts from " + scriptsDir); - } - } - - public void importXML(@NotNull final File script, final boolean override) { - final SAXBuilder builder = new SAXBuilder(false); /*non validating*/ - try { - final Document d = builder.build(script); - importXML(d, script, override); - } catch (final JDOMException ex) { - log.warn(script + ": " + ex.getMessage()); - } catch (final IOException ex) { - log.warn(script + ": " + ex.getMessage()); - } - } - - private void importXML(final Document doc, @Nullable final File file, final boolean override) { - try { - if (!doc.hasRootElement()) { - log.info("No script found."); - return; - } - - final Element elt = doc.getRootElement(); - if ((!elt.getName().equalsIgnoreCase("script"))) { - log.warn("Problem reading xml scripts, need a root element named \"script\""); - return; - } - - final Script script = ScriptModelParser.fromXML(elt); - script.setFile(file); - log.debug("script: " + script.getName()); - if (override || scriptModel.getScript(script.getName()) == null) { - if (log.isDebugEnabled()) { - log.debug("storing with code " + script.getCode()); - } - - unRegister(script.getName()); - scriptModel.addScript(script); - register(script.getName()); - } else { - log.warn(file + ": ignoring duplicate script '" + script.getName() + "'"); - } - } catch (final Exception e) { - e.printStackTrace(); - } - } - - /** - * Save all unsaved scripts. - * @return Whether all scripts have been saved. - */ - public boolean saveAllScripts() { - for (final Script scriptModel : this.scriptModel) { - if (!saveScript(scriptModel)) { - return false; - } - } - - return true; - } - - /** - * Prompt the user for all unsaved scripts. - * @return Whether no unsaved scripts remain. - */ - public boolean canExit() { - for (final Script script : scriptModel) { - if (script.isModified()) { - final int result = ACTION_FACTORY.showConfirmDialog(parent, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "pluginConfirmSaveChanges", script.getName()); - if (result == JOptionPane.YES_OPTION) { - if (!saveScript(script)) { - return false; - } - } else - if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) { - return false; - } - } - } - - return true; - } - - /** - * Save one script. Does nothing if the script is unchanged. - * @param script The script to save. - * @return Whether the script has been saved, or if the script was not - * modified. - */ - public boolean saveScript(@NotNull final Script script) { - if (!script.isModified()) { - return true; - } - - try { - final File file = script.getFile(); - if (file != null) { - saveScript(script, file); - } else { - saveScriptAs(script, true); - } - } catch (final IOException ex) { - // XXX: notify user - return false; - } - - script.resetModified(); - return true; - } - - /** - * Prompt the user for a file name to save a script. The script is saved - * regardless whether the script is modified or not. - * @param script The script to save. - * @param updateScriptFile If set, update the script file to the save - * location. - * @return Whether the script has been saved. - */ - public boolean saveScriptAs(@NotNull final Script script, final boolean updateScriptFile) { - final JFileChooser chooser = new JFileChooser(); - chooser.setCurrentDirectory(scriptsDir); - chooser.setDialogTitle("save script " + script.getName()); - final int result = chooser.showSaveDialog(null); - if (result != JFileChooser.APPROVE_OPTION) { - return false; - } - - final File file = chooser.getSelectedFile(); - if (updateScriptFile) { - script.setFile(file); - } - scriptsDir = file.getParentFile(); - - try { - saveScript(script, file); - } catch (final IOException ex) { - return false; - } - - return true; - } - - /** - * Save a script to a given file. - * @param script The script to save. - * @param file The file to save to. - * @throws IOException If the file cannot be saved. - */ - public static void saveScript(@NotNull final Script script, @NotNull final File file) throws IOException { - final FileOutputStream fos = new FileOutputStream(file); - try { - final Element root = ScriptModelParser.toXML(script); - final Document d = new Document(root); - final XMLOutputter out = new XMLOutputter(); - out.setFormat(Format.getPrettyFormat()); - out.output(d, fos); - } finally { - fos.close(); - } - } - - public void autoRunScript(final Script script) { - final Interpreter runner = new Interpreter(); - try { - scriptParameters.setInterpreterValues(runner, ScriptRunMode.AUTORUN); - runner.eval(script.getCode()); - } catch (final EvalError e) { - log.warn("Evaluation error on (autorun)" + script.getName(), e); - } - } - - @Nullable - public Filter getScriptAsFilter(final Script script) { - final Interpreter runner = new Interpreter(); - try { - scriptParameters.setInterpreterValues(runner, ScriptRunMode.FILTER); - return (Filter) runner.eval(script.getCode()); - } catch (final EvalError e) { - log.warn("Evaluation error on (filter)" + script.getName(), e); - } catch (final ClassCastException e) { - log.warn("Script did not return a net.sf.gridarta.filter.Filter object" + script.getName(), e); - } - return null; - } - - public void runScript(final Script script) { - final Script clonedScript; - try { - clonedScript = (Script) script.clone(); - } catch (final CloneNotSupportedException e) { - throw new AssertionError(); - } - - if (!view.getRunValues(clonedScript)) { - return; - } - - final ConsoleInterface console = view.createConsole(clonedScript.getName()); - try { - doRunScript(clonedScript, console); - } catch (final ScriptExecException ex) { - console.print(ex.getMessage()); - } - } - - /** - * Runs a script model. The model is expected to have all needed parameters - * set. - * @param script the script model - * @param console the console to use - * @return the script thread or <code>null</code> - * @throws ScriptExecException if an error occurs - */ - @Nullable - private BshThread doRunScript(@NotNull final Script script, @NotNull final ConsoleInterface console) throws ScriptExecException { - final Interpreter runner = new Interpreter(); - final BshThread scriptThread; - try { - runner.setConsole(console); - scriptParameters.setInterpreterValues(runner, ScriptRunMode.BATCH); - for (final PluginParameter<?, ?> parameter : script) { - runner.set(parameter.getName(), parameter.getValue()); - } - scriptThread = new BshThread(script.getName()); - scriptThread.setScript(script); - scriptThread.setInterpreter(runner); - scriptThread.start(); - } catch (final TargetError e) { - final CharArrayWriter w = new CharArrayWriter(); - //noinspection IOResourceOpenedButNotSafelyClosed - e.getTarget().printStackTrace(new PrintWriter(w)); - throw new ScriptExecException("target error: " + w); - } catch (final EvalError e) { - throw new ScriptExecException("evaluation error: " + e.getMessage()); - } - return scriptThread; - } - - public void runScript(final String name) { - final Script script = scriptModel.getScript(name); - if (script != null) { - runScript(script); - } - } - - public ScriptView getView() { - return view; - } - - private void unRegister(final String name) { - final String filterName = "(s)" + name; - filterControl.removeFilter(filterName); - } - - private void register(final String name) { - final String filterName = "(s)" + name; - final Script script = scriptModel.getScript(name); - if (script.isFilter()) { - final Filter filter = getScriptAsFilter(script); - if (filter != null) { - filterControl.addFilter(filterName, filter); - } - } - - if (script.isAutoboot()) { - autoRunScript(script); - } - - scriptModel.fireScriptRegisteredEvent(script); - } - - public void reRegister(final String name) { - unRegister(name); - register(name); - } - - /** - * Executes an editor script. - * @param script the script name to execute - * @param params the script parameters - * @throws ScriptExecException if an error occurs - */ - public void executeScript(final String script, final List<String> params) throws ScriptExecException { - final Script modelTemplate = scriptModel.getScript(script); - if (modelTemplate == null) { - throw new ScriptExecException("script " + script + " does not exist"); - } - - final Script clonedScript; - try { - clonedScript = (Script) modelTemplate.clone(); - } catch (final CloneNotSupportedException e) { - throw new AssertionError(); - } - - for (final String param : params) { - final String[] tmp = param.split("=", 2); - if (tmp.length != 2) { - throw new ScriptExecException("syntax error: " + param); - } - - final int index = clonedScript.getParameter(tmp[0]); - if (index == -1) { - final StringBuilder sb = new StringBuilder(); - boolean firstParameter = true; - for (final PluginParameter<?, ?> parameter : clonedScript) { - sb.append(firstParameter ? " " : ", "); - sb.append(parameter.getName()); - firstParameter = false; - } - throw new ScriptExecException("script " + script + " has no parameter " + tmp[0] + "; available parameters:" + sb); - } - - final PluginParameter<?, ?> parameter; - try { - parameter = clonedScript.getParameter(index); - } catch (final NoSuchParameterException ex) { - throw new AssertionError(); - } - if (!pluginParameterViewFactory.getView(parameter).setValue(tmp[1])) { - throw new ScriptExecException("invalid value " + tmp[1] + " for parameter " + tmp[0]); - } - } - - final ConsoleInterface console = new ConsoleInterface() { - - /** {@inheritDoc}... [truncated message content] |
From: <aki...@us...> - 2008-10-01 22:07:08
|
Revision: 5369 http://gridarta.svn.sourceforge.net/gridarta/?rev=5369&view=rev Author: akirschbaum Date: 2008-10-01 22:06:58 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Fix editPlugins action. Modified Paths: -------------- trunk/crossfire/src/cfeditor/action.properties trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties trunk/crossfire/src/cfeditor/messages_fr.properties trunk/crossfire/src/cfeditor/messages_sv.properties trunk/src/app/net/sf/gridarta/action.properties trunk/src/app/net/sf/gridarta/gui/script/ScriptManagerFactory.java trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties Added Paths: ----------- trunk/resource/icons/EditPluginSmallIcon.gif Removed Paths: ------------- trunk/crossfire/resource/icons/EditPluginSmallIcon.gif Modified: trunk/crossfire/src/cfeditor/action.properties =================================================================== --- trunk/crossfire/src/cfeditor/action.properties 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/crossfire/src/cfeditor/action.properties 2008-10-01 22:06:58 UTC (rev 5369) @@ -58,8 +58,6 @@ runPlugin.icon=RunPluginSmallIcon -editPlugins.icon=EditPluginSmallIcon - savePlugins.icon=SaveLevelAsSmallIcon importPlugin.icon=ImportPluginSmallIcon Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/crossfire/src/cfeditor/messages.properties 2008-10-01 22:06:58 UTC (rev 5369) @@ -146,9 +146,6 @@ runPlugin.text=Run {0} -editPlugins.text=Edit plugins... -editPlugins.mnemonic=E - savePlugins.text=Save plugins savePlugins.mnemonic=S Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2008-10-01 22:06:58 UTC (rev 5369) @@ -128,9 +128,6 @@ runPlugin.text={0} starten -editPlugins.text=Plugins bearbeiten... -editPlugins.mnemonic=B - savePlugins.text=Plugins speichern savePlugins.mnemonic=S Modified: trunk/crossfire/src/cfeditor/messages_fr.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_fr.properties 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/crossfire/src/cfeditor/messages_fr.properties 2008-10-01 22:06:58 UTC (rev 5369) @@ -129,9 +129,6 @@ #runPlugin.text= -#editPlugins.text= -#editPlugins.mnemonic= - #savePlugins.text= #savePlugins.mnemonic= Modified: trunk/crossfire/src/cfeditor/messages_sv.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_sv.properties 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/crossfire/src/cfeditor/messages_sv.properties 2008-10-01 22:06:58 UTC (rev 5369) @@ -127,9 +127,6 @@ #runPlugin.text= -#editPlugins.text= -#editPlugins.mnemonic= - #savePlugins.text= #savePlugins.mnemonic= Property changes on: trunk/resource/icons/EditPluginSmallIcon.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: svn:mergeinfo + Modified: trunk/src/app/net/sf/gridarta/action.properties =================================================================== --- trunk/src/app/net/sf/gridarta/action.properties 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/src/app/net/sf/gridarta/action.properties 2008-10-01 22:06:58 UTC (rev 5369) @@ -90,6 +90,8 @@ revertPickmap.icon=general/Refresh16 pickmapFolders.menu= +editPlugins.icon=EditPluginSmallIcon + # Zoom zoom.icon=general/Zoom16 Modified: trunk/src/app/net/sf/gridarta/gui/script/ScriptManagerFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/ScriptManagerFactory.java 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/src/app/net/sf/gridarta/gui/script/ScriptManagerFactory.java 2008-10-01 22:06:58 UTC (rev 5369) @@ -33,7 +33,7 @@ public class ScriptManagerFactory<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, V extends MapViewBasic<G, A, R, V>> { /** Action Factory to create Actions. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.gridarta"); private JFrame scriptManager = null; Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/src/app/net/sf/gridarta/messages.properties 2008-10-01 22:06:58 UTC (rev 5369) @@ -151,6 +151,12 @@ enterNorthWestMap.text=Enter Northwest Map +# Plugins + +editPlugins.text=Edit plugins... +editPlugins.mnemonic=E + + # Resources viewTreasurelists.text=View Treasurelists viewTreasurelists.mnemonic=T Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2008-10-01 22:06:58 UTC (rev 5369) @@ -137,6 +137,11 @@ enterNorthWestMap.text=Gehe zu Nordwest-Karte +# Plugins + +editPlugins.text=Plugins bearbeiten... +editPlugins.mnemonic=B + # Resources viewTreasurelists.text=Schatzlisten anschauen viewTreasurelists.mnemonic=S Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-10-01 22:06:58 UTC (rev 5369) @@ -136,6 +136,12 @@ enterNorthWestMap.text=Aller Carte Nord-Ouest +# Plugins + +#editPlugins.text= +#editPlugins.mnemonic= + + # Resources viewTreasurelists.text=Afficher listes de tr\xE9sors viewTreasurelists.mnemonic=T Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-10-01 22:02:55 UTC (rev 5368) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-10-01 22:06:58 UTC (rev 5369) @@ -136,6 +136,12 @@ enterNorthWestMap.text=G\xE5 nordv\xE4st +# Plugins + +#editPlugins.text= +#editPlugins.mnemonic= + + # Resources viewTreasurelists.text=Visa skattlistor viewTreasurelists.mnemonic=V This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-02 06:36:09
|
Revision: 5373 http://gridarta.svn.sourceforge.net/gridarta/?rev=5373&view=rev Author: akirschbaum Date: 2008-10-02 06:35:59 +0000 (Thu, 02 Oct 2008) Log Message: ----------- Fix ScriptView related actions. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/script/ScriptView.java Added Paths: ----------- trunk/resource/icons/ImportPluginSmallIcon.gif trunk/resource/icons/RunPluginSmallIcon.gif trunk/resource/icons/SaveLevelAsSmallIcon.gif Removed Paths: ------------- trunk/crossfire/resource/icons/ImportPluginSmallIcon.gif trunk/crossfire/resource/icons/RunPluginSmallIcon.gif trunk/crossfire/resource/icons/SaveLevelAsSmallIcon.gif trunk/daimonin/resource/icons/SaveLevelAsSmallIcon.gif Property changes on: trunk/resource/icons/ImportPluginSmallIcon.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: svn:mergeinfo + Property changes on: trunk/resource/icons/RunPluginSmallIcon.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: svn:mergeinfo + Property changes on: trunk/resource/icons/SaveLevelAsSmallIcon.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: svn:mergeinfo + Modified: trunk/src/app/net/sf/gridarta/gui/script/ScriptView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/ScriptView.java 2008-10-02 06:25:52 UTC (rev 5372) +++ trunk/src/app/net/sf/gridarta/gui/script/ScriptView.java 2008-10-02 06:35:59 UTC (rev 5373) @@ -61,7 +61,7 @@ public final class ScriptView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, V extends MapViewBasic<G, A, R, V>> { /** Action Factory to create Actions. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.gridarta"); /** The Logger for printing log messages. */ private static final Logger log = Logger.getLogger(ScriptView.class); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-02 18:19:56
|
Revision: 5374 http://gridarta.svn.sourceforge.net/gridarta/?rev=5374&view=rev Author: akirschbaum Date: 2008-10-02 18:19:36 +0000 (Thu, 02 Oct 2008) Log Message: ----------- Add plugin script interpreter. Modified Paths: -------------- trunk/daimonin/ChangeLog trunk/daimonin/build.xml trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/IGUIConstants.java trunk/daimonin/src/daieditor/action.properties Added Paths: ----------- trunk/resource/icons/AutorunSmallIcon.gif trunk/resource/icons/CloseTabSmallIcon.gif trunk/resource/icons/FilterSmallIcon.gif Removed Paths: ------------- trunk/crossfire/resource/icons/AutorunSmallIcon.gif trunk/crossfire/resource/icons/CloseTabSmallIcon.gif trunk/crossfire/resource/icons/FilterSmallIcon.gif Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2008-10-02 06:35:59 UTC (rev 5373) +++ trunk/daimonin/ChangeLog 2008-10-02 18:19:36 UTC (rev 5374) @@ -1,3 +1,7 @@ +2008-10-02 Andreas Kirschbaum + + * Add plugin script interpreter. + 2008-09-28 Andreas Kirschbaum * Partly retain map window location when moving to an adjacent Modified: trunk/daimonin/build.xml =================================================================== --- trunk/daimonin/build.xml 2008-10-02 06:35:59 UTC (rev 5373) +++ trunk/daimonin/build.xml 2008-10-02 18:19:36 UTC (rev 5374) @@ -155,6 +155,10 @@ </fileset> <zipfileset src="../lib/log4j-1.2.13.jar" /> <zipfileset src="../lib/jdom.jar" /> + <zipfileset src="../lib/bsh-core-2.0b4.jar" excludes="META-INF/**" /> + <zipfileset src="../lib/bsh-commands-2.0b4.jar" excludes="META-INF/**" /> + <zipfileset src="../lib/bsh-classgen-2.0b4.jar" excludes="META-INF/**" /> + <zipfileset src="../lib/bsh-util-2.0b4.jar" excludes="META-INF/**" /> <zipgroupfileset dir="../lib/" includes="japi-*.jar" /> <!-- creating the manifest --> <manifest> Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-02 06:35:59 UTC (rev 5373) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-02 18:19:36 UTC (rev 5374) @@ -40,6 +40,7 @@ import daieditor.map.validation.checks.TilePathsChecker; import java.io.File; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import javax.swing.JComboBox; @@ -61,6 +62,7 @@ import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.gameobject.match.GameObjectMatchers; import net.sf.gridarta.gameobject.match.MutableOrGameObjectMatcher; +import net.sf.gridarta.gameobject.match.NamedGameObjectMatcher; import net.sf.gridarta.gameobject.match.ViewGameObjectMatcherManager; import net.sf.gridarta.gui.MainView; import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserControl; @@ -77,6 +79,7 @@ import net.sf.gridarta.gui.prefs.MapValidatorPrefs; import net.sf.gridarta.gui.prefs.MiscPrefs; import net.sf.gridarta.gui.prefs.UpdatePrefs; +import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; import net.sf.gridarta.gui.utils.GUIUtils; import net.sf.gridarta.io.GameObjectParser; @@ -101,6 +104,10 @@ import net.sf.gridarta.map.validation.checks.SysObjectNotOnLayerZeroChecker; import net.sf.gridarta.map.validation.checks.UndefinedArchetypeChecker; import net.sf.gridarta.map.validation.checks.UnsetSlayingChecker; +import net.sf.gridarta.script.ScriptController; +import net.sf.gridarta.script.ScriptExecException; +import net.sf.gridarta.script.ScriptParameters; +import net.sf.gridarta.script.parameter.PluginParameterFactory; import net.sf.gridarta.spells.SpellsUtils; import net.sf.gridarta.treasurelist.CFTreasureListTree; import net.sf.gridarta.treasurelist.TreasureLocation; @@ -131,6 +138,9 @@ /** The Logger for printing log messages. */ private static final Logger log = Logger.getLogger(CMainControl.class); + /** The current script controller. */ + private ScriptController<GameObject, MapArchObject, Archetype, CMapViewBasic> scriptControl; + private FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl; /** Bit field of edit types to show transparent. */ @@ -251,14 +261,20 @@ /** {@inheritDoc} */ @Override protected void init2(@NotNull final GridartaObjectsFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> gridartaObjectsFactory, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final net.sf.gridarta.gameobject.ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final DelegatingMapValidator<GameObject, MapArchObject, Archetype> validators, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, @NotNull final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser) { + PluginParameterFactory.init(archetypeSet, mapManager); final NamedFilterList defaultNamedFilterList = new NamedFilterList(gameObjectMatchers.getFilters()); filterControl = new FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(mapManager, defaultNamedFilterList); ((DefaultGridartaObjectsFactory) gridartaObjectsFactory).setFilterControl(filterControl); + final ScriptParameters scriptParameters = new ScriptParameters(archetypeSet, globalSettings, mapManager, validators); + final NamedFilterList defaultFilterList = new NamedFilterList(Collections.<NamedGameObjectMatcher>emptyList()); + final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory = new PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic>(archetypeSet, gameObjectAttributesModel, objectChooser, defaultFilterList, mapManager); + scriptControl = new ScriptController<GameObject, MapArchObject, Archetype, CMapViewBasic>(filterControl, scriptParameters, getMainView(), pluginParameterViewFactory); } /** {@inheritDoc} */ @Override protected void init3() { + scriptControl.getView().setMenu((JMenu) ACTION_FACTORY.find(getMainView().getJMenuBar(), "plugins")); } /** {@inheritDoc} */ @@ -275,6 +291,7 @@ if (menuAnalyze != null) { filterControl.createMenuEntries(menuAnalyze); } + scriptControl.loadScripts(new File(globalSettings.getMapDir(), IGUIConstants.SCRIPTS_DIR)); } /** {@inheritDoc} */ @@ -468,6 +485,12 @@ FaceObjectProviders.reloadAll(); } + /** {@inheritDoc} */ + @Override + public boolean canExit() { + return super.canExit() && scriptControl.canExit(); + } + /** * Run in batch png mode. * @param args the argument strings that were not parsed away by {@link @@ -542,4 +565,14 @@ return new ArchetypeSet(gridartaObjectsFactory); } + /** + * Executes an editor script. + * @param script the script name to execute + * @param params the script parameters + * @throws ScriptExecException if the script execution fails + */ + public void executeScript(final String script, final List<String> params) throws ScriptExecException { + scriptControl.executeScript(script, params); + } + } // class CMainControl Modified: trunk/daimonin/src/daieditor/IGUIConstants.java =================================================================== --- trunk/daimonin/src/daieditor/IGUIConstants.java 2008-10-02 06:35:59 UTC (rev 5373) +++ trunk/daimonin/src/daieditor/IGUIConstants.java 2008-10-02 18:19:36 UTC (rev 5374) @@ -64,6 +64,9 @@ /** Default height for pickmaps. */ int DEF_PICKMAP_HEIGHT = 7; + /** The directory that contains all scripts. */ + String SCRIPTS_DIR = "dev/editor/scripts"; + /** The directory that contains all pickmaps. */ String PICKMAP_DIR = "dev/editor/pickmaps"; Modified: trunk/daimonin/src/daieditor/action.properties =================================================================== --- trunk/daimonin/src/daieditor/action.properties 2008-10-02 06:35:59 UTC (rev 5373) +++ trunk/daimonin/src/daieditor/action.properties 2008-10-02 18:19:36 UTC (rev 5374) @@ -24,7 +24,7 @@ ######## # Menus -main.menubar=file edit map archetypes pickmaps resources tools analyze view window help +main.menubar=file edit map archetypes pickmaps resources tools analyze view plugins window help file.menu=createNew open recent close - save saveAs saveAll revert createImage - options - exit edit.menu=undo redo - clear cut copy paste - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodfill - selectAll map.menu=autoJoin - enterExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize @@ -38,6 +38,7 @@ #view.menu=resetView - viewAlpha gridVisible drawDouble - prevWindow nextWindow view.menu=resetView - gridVisible drawDouble - prevWindow nextWindow #viewAlpha.menu = alphaMonsters alphaExits alphaBackground alphaDoorsKeys alphaWall alphaEquipment alphaTreasure alphaConnected resetAlpha +plugins.menu=- editPlugins - savePlugins importPlugin #window.menu=newWindow - closeAll +windows window.menu=closeAll help.menu=onlineHelp tod about update Property changes on: trunk/resource/icons/AutorunSmallIcon.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: svn:mergeinfo + Property changes on: trunk/resource/icons/CloseTabSmallIcon.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: svn:mergeinfo + Property changes on: trunk/resource/icons/FilterSmallIcon.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: svn:mergeinfo + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-10-02 19:30:22
|
Revision: 5376 http://gridarta.svn.sourceforge.net/gridarta/?rev=5376&view=rev Author: akirschbaum Date: 2008-10-02 19:30:12 +0000 (Thu, 02 Oct 2008) Log Message: ----------- Move code to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/DefaultGridartaObjectsFactory.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/DefaultGridartaObjectsFactory.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java trunk/src/app/net/sf/gridarta/GridartaObjectsFactory.java trunk/src/test/net/sf/gridarta/map/DefaultMapModelTest.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-02 18:23:13 UTC (rev 5375) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-10-02 19:30:12 UTC (rev 5376) @@ -35,11 +35,9 @@ import cfeditor.map.DefaultMapControlFactory; import cfeditor.map.MapArchObject; import java.io.File; -import java.util.Collections; import java.util.List; import java.util.Map; import javax.swing.JComboBox; -import javax.swing.JMenu; import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.EditTypes; @@ -47,22 +45,16 @@ import net.sf.gridarta.GridartaObjectsFactory; import net.sf.gridarta.MapManager; import net.sf.gridarta.archtype.ArchetypeTypeSet; -import net.sf.gridarta.filter.FilterControl; -import net.sf.gridarta.filter.NamedFilterList; import net.sf.gridarta.gameobject.AbstractArchetypeParser; import net.sf.gridarta.gameobject.GameObjectFactory; import net.sf.gridarta.gameobject.anim.AnimationObject; import net.sf.gridarta.gameobject.match.GameObjectMatcher; -import net.sf.gridarta.gameobject.match.GameObjectMatchers; -import net.sf.gridarta.gameobject.match.NamedGameObjectMatcher; import net.sf.gridarta.gui.MainView; import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserControl; -import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; import net.sf.gridarta.gui.map.DefaultMapActions; import net.sf.gridarta.gui.map.MapActions; import net.sf.gridarta.gui.map.MapPropertiesDialogFactory; import net.sf.gridarta.gui.newmap.NewMapDialogFactory; -import net.sf.gridarta.gui.objectchooser.ObjectChooser; import net.sf.gridarta.gui.prefs.AppPrefs; import net.sf.gridarta.gui.prefs.AppPrefsModel; import net.sf.gridarta.gui.prefs.DevPrefs; @@ -70,7 +62,6 @@ import net.sf.gridarta.gui.prefs.MapValidatorPrefs; import net.sf.gridarta.gui.prefs.MiscPrefs; import net.sf.gridarta.gui.prefs.UpdatePrefs; -import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; import net.sf.gridarta.io.ConfigFileUtils; import net.sf.gridarta.io.GameObjectParser; @@ -84,9 +75,6 @@ import net.sf.gridarta.map.validation.checks.MapDifficultyChecker; import net.sf.gridarta.map.validation.checks.UndefinedArchetypeChecker; import net.sf.gridarta.map.validation.checks.UnsetSlayingChecker; -import net.sf.gridarta.script.ScriptController; -import net.sf.gridarta.script.ScriptExecException; -import net.sf.gridarta.script.ScriptParameters; import net.sf.gridarta.treasurelist.CFTreasureListTree; import net.sf.gridarta.treasurelist.TreasureLocation; import net.sf.gridarta.treasurelist.TreasureTreeNode; @@ -107,11 +95,6 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - /** The current script controller. */ - private ScriptController<GameObject, MapArchObject, Archetype, CMapViewBasic> scriptControl; - - private FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl; - /** Preferences default for auto validation. */ private static final boolean PREFS_VALIDATOR_AUTO_DEFAULT = true; @@ -121,7 +104,7 @@ * @throws RuntimeException If the controller cannot be initialized. */ public CMainControl(@NotNull final GridartaObjectsFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> gridartaObjectsFactory) { - super(gridartaObjectsFactory, new DefaultRendererFactory(), "cfeditor", new GlobalSettingsImpl(), new AnimationObjects(), new FaceObjects(), false, ConfigFileUtils.getHomeFile("thumbnails"), null, "CrossfireEditor.jar", pythonFileFilter, ".py", "Python", Archetype.TYPE_SPELL, null, Archetype.TYPE_EVENT_CONNECTOR, false, 0, new int[] { Archetype.TYPE_LOCKED_DOOR, Archetype.TYPE_SPECIAL_KEY, Archetype.TYPE_TRIGGER_ALTAR, Archetype.TYPE_DETECTOR, Archetype.TYPE_TRIGGER_MARKER, Archetype.TYPE_MARKER, Archetype.TYPE_INVENTORY_CHECKER, Archetype.TYPE_CONTAINER, }, PREFS_VALIDATOR_AUTO_DEFAULT); + super(gridartaObjectsFactory, new DefaultRendererFactory(), "cfeditor", new GlobalSettingsImpl(), new AnimationObjects(), new FaceObjects(), false, ConfigFileUtils.getHomeFile("thumbnails"), null, "CrossfireEditor.jar", pythonFileFilter, ".py", "Python", Archetype.TYPE_SPELL, null, Archetype.TYPE_EVENT_CONNECTOR, false, 0, new int[] { Archetype.TYPE_LOCKED_DOOR, Archetype.TYPE_SPECIAL_KEY, Archetype.TYPE_TRIGGER_ALTAR, Archetype.TYPE_DETECTOR, Archetype.TYPE_TRIGGER_MARKER, Archetype.TYPE_MARKER, Archetype.TYPE_INVENTORY_CHECKER, Archetype.TYPE_CONTAINER, }, PREFS_VALIDATOR_AUTO_DEFAULT, IGUIConstants.SCRIPTS_DIR); } /** {@inheritDoc} */ @@ -209,40 +192,12 @@ /** {@inheritDoc} */ @Override - protected void init2(@NotNull final GridartaObjectsFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> gridartaObjectsFactory, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final net.sf.gridarta.gameobject.ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final DelegatingMapValidator<GameObject, MapArchObject, Archetype> validators, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, @NotNull final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser) { - final NamedFilterList defaultNamedFilterList = new NamedFilterList(gameObjectMatchers.getFilters()); - filterControl = new FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(mapManager, defaultNamedFilterList); - ((DefaultGridartaObjectsFactory) gridartaObjectsFactory).setFilterControl(filterControl); - final ScriptParameters scriptParameters = new ScriptParameters(archetypeSet, globalSettings, mapManager, validators); - final NamedFilterList defaultFilterList = new NamedFilterList(Collections.<NamedGameObjectMatcher>emptyList()); - final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory = new PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic>(archetypeSet, gameObjectAttributesModel, objectChooser, defaultFilterList, mapManager); - scriptControl = new ScriptController<GameObject, MapArchObject, Archetype, CMapViewBasic>(filterControl, scriptParameters, getMainView(), pluginParameterViewFactory); - } - - /** {@inheritDoc} */ - @Override - protected void init3() { - scriptControl.getView().setMenu((JMenu) ACTION_FACTORY.find(getMainView().getJMenuBar(), "plugins")); - } - - /** {@inheritDoc} */ - @Override protected void init4(@NotNull final GameObjectParser<GameObject, MapArchObject, Archetype> gameObjectParser, @NotNull final AbstractArchetypeParser<GameObject, MapArchObject, Archetype> archetypeParser, @NotNull final EditTypes<GameObject, MapArchObject, Archetype, CMapViewBasic> editTypes, @NotNull final net.sf.gridarta.gameobject.face.FaceObjects faceObjects, @NotNull final net.sf.gridarta.gameobject.anim.AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final MainView<GameObject, MapArchObject, Archetype, CMapViewBasic> mainView, @NotNull final GlobalSettings globalSettings, @NotNull final net.sf.gridarta.gameobject.ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet) { new ArchetypeSetLoader(globalSettings, gameObjectParser, globalSettings.getCollectedDirectory(), globalSettings.getConfigurationDirectory(), archetypeSet, archetypeParser, editTypes, faceObjects, animationObjects, this).loadArchetypes(mainView); } /** {@inheritDoc} */ @Override - protected void init5(@NotNull final GlobalSettings globalSettings) { - final JMenu menuAnalyze = (JMenu) ACTION_FACTORY.find(getMainView().getJMenuBar(), "analyze"); - if (menuAnalyze != null) { - filterControl.createMenuEntries(menuAnalyze); - } - scriptControl.loadScripts(new File(globalSettings.getMapDir(), IGUIConstants.SCRIPTS_DIR)); - } - - /** {@inheritDoc} */ - @Override protected void deleteLibraries() { } @@ -332,12 +287,6 @@ public void reloadFaces() { } - /** {@inheritDoc} */ - @Override - public boolean canExit() { - return super.canExit() && scriptControl.canExit(); - } - public void createImageFile(final List<String> infiles, final String outfile) { openFiles(infiles); createImageWanted(mapViewManager.getCurrentMapView(), new File(outfile)); // create map image @@ -350,14 +299,4 @@ return new ArchetypeSet(((GlobalSettingsImpl) globalSettings).getImageSet(), gridartaObjectsFactory); } - /** - * Executes an editor script. - * @param script the script name to execute - * @param params the script parameters - * @throws ScriptExecException if the script execution fails - */ - public void executeScript(final String script, final List<String> params) throws ScriptExecException { - scriptControl.executeScript(script, params); - } - } // class CMainControl Modified: trunk/crossfire/src/cfeditor/DefaultGridartaObjectsFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/DefaultGridartaObjectsFactory.java 2008-10-02 18:23:13 UTC (rev 5375) +++ trunk/crossfire/src/cfeditor/DefaultGridartaObjectsFactory.java 2008-10-02 19:30:12 UTC (rev 5376) @@ -133,6 +133,7 @@ this.toolPalette = toolPalette; } + /** {@inheritDoc} */ public void setFilterControl(@NotNull final FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl) { this.filterControl = filterControl; } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-10-02 18:23:13 UTC (rev 5375) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-10-02 19:30:12 UTC (rev 5376) @@ -40,11 +40,9 @@ import daieditor.map.validation.checks.TilePathsChecker; import java.io.File; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import javax.swing.JComboBox; -import javax.swing.JMenu; import javax.swing.JOptionPane; import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.CommonConstants; @@ -53,25 +51,19 @@ import net.sf.gridarta.GridartaObjectsFactory; import net.sf.gridarta.MapManager; import net.sf.gridarta.archtype.ArchetypeTypeSet; -import net.sf.gridarta.filter.FilterControl; -import net.sf.gridarta.filter.NamedFilterList; import net.sf.gridarta.gameobject.AbstractArchetypeParser; import net.sf.gridarta.gameobject.GameObjectFactory; import net.sf.gridarta.gameobject.anim.AnimationObject; import net.sf.gridarta.gameobject.face.FaceObjectProviders; import net.sf.gridarta.gameobject.match.GameObjectMatcher; -import net.sf.gridarta.gameobject.match.GameObjectMatchers; import net.sf.gridarta.gameobject.match.MutableOrGameObjectMatcher; -import net.sf.gridarta.gameobject.match.NamedGameObjectMatcher; import net.sf.gridarta.gameobject.match.ViewGameObjectMatcherManager; import net.sf.gridarta.gui.MainView; import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserControl; -import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; import net.sf.gridarta.gui.map.DefaultMapActions; import net.sf.gridarta.gui.map.MapActions; import net.sf.gridarta.gui.map.MapPropertiesDialogFactory; import net.sf.gridarta.gui.newmap.NewMapDialogFactory; -import net.sf.gridarta.gui.objectchooser.ObjectChooser; import net.sf.gridarta.gui.prefs.AppPrefs; import net.sf.gridarta.gui.prefs.AppPrefsModel; import net.sf.gridarta.gui.prefs.DevPrefs; @@ -79,7 +71,6 @@ import net.sf.gridarta.gui.prefs.MapValidatorPrefs; import net.sf.gridarta.gui.prefs.MiscPrefs; import net.sf.gridarta.gui.prefs.UpdatePrefs; -import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; import net.sf.gridarta.gui.utils.GUIUtils; import net.sf.gridarta.io.GameObjectParser; @@ -104,9 +95,6 @@ import net.sf.gridarta.map.validation.checks.SysObjectNotOnLayerZeroChecker; import net.sf.gridarta.map.validation.checks.UndefinedArchetypeChecker; import net.sf.gridarta.map.validation.checks.UnsetSlayingChecker; -import net.sf.gridarta.script.ScriptController; -import net.sf.gridarta.script.ScriptExecException; -import net.sf.gridarta.script.ScriptParameters; import net.sf.gridarta.spells.SpellsUtils; import net.sf.gridarta.treasurelist.CFTreasureListTree; import net.sf.gridarta.treasurelist.TreasureLocation; @@ -137,11 +125,6 @@ /** The Logger for printing log messages. */ private static final Logger log = Logger.getLogger(CMainControl.class); - /** The current script controller. */ - private ScriptController<GameObject, MapArchObject, Archetype, CMapViewBasic> scriptControl; - - private FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl; - /** Bit field of edit types to show transparent. */ private int alphaType; @@ -169,7 +152,7 @@ * @throws RuntimeException If the controller cannot be initialized. */ public CMainControl(@NotNull final GridartaObjectsFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> gridartaObjectsFactory) { - super(gridartaObjectsFactory, new DefaultRendererFactory(), "daieditor", new GlobalSettingsImpl(), new AnimationObjects(), new FaceObjects(), true, null, GUIUtils.getSysIcon(IGUIConstants.TILE_NORTH), "DaimoninEditor.jar", luaFileFilter, ".lua", "Lua", 0, IGUIConstants.SPELL_FILE, 0, true, -1, new int[] { Archetype.TYPE_LOCKED_DOOR, Archetype.TYPE_SPECIAL_KEY, Archetype.TYPE_ALTAR_TRIGGER, Archetype.TYPE_MARKER, Archetype.TYPE_INVENTORY_CHECKER, Archetype.TYPE_SPAWN_POINT, Archetype.TYPE_CONTAINER, }, PREFS_VALIDATOR_AUTO_DEFAULT); + super(gridartaObjectsFactory, new DefaultRendererFactory(), "daieditor", new GlobalSettingsImpl(), new AnimationObjects(), new FaceObjects(), true, null, GUIUtils.getSysIcon(IGUIConstants.TILE_NORTH), "DaimoninEditor.jar", luaFileFilter, ".lua", "Lua", 0, IGUIConstants.SPELL_FILE, 0, true, -1, new int[] { Archetype.TYPE_LOCKED_DOOR, Archetype.TYPE_SPECIAL_KEY, Archetype.TYPE_ALTAR_TRIGGER, Archetype.TYPE_MARKER, Archetype.TYPE_INVENTORY_CHECKER, Archetype.TYPE_SPAWN_POINT, Archetype.TYPE_CONTAINER, }, PREFS_VALIDATOR_AUTO_DEFAULT, IGUIConstants.SCRIPTS_DIR); } /** {@inheritDoc} */ @@ -259,24 +242,6 @@ /** {@inheritDoc} */ @Override - protected void init2(@NotNull final GridartaObjectsFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> gridartaObjectsFactory, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final net.sf.gridarta.gameobject.ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final DelegatingMapValidator<GameObject, MapArchObject, Archetype> validators, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final GameObjectAttributesModel<GameObject, MapArchObject, Archetype> gameObjectAttributesModel, @NotNull final ObjectChooser<GameObject, MapArchObject, Archetype> objectChooser) { - final NamedFilterList defaultNamedFilterList = new NamedFilterList(gameObjectMatchers.getFilters()); - filterControl = new FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(mapManager, defaultNamedFilterList); - ((DefaultGridartaObjectsFactory) gridartaObjectsFactory).setFilterControl(filterControl); - final ScriptParameters scriptParameters = new ScriptParameters(archetypeSet, globalSettings, mapManager, validators); - final NamedFilterList defaultFilterList = new NamedFilterList(Collections.<NamedGameObjectMatcher>emptyList()); - final PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> pluginParameterViewFactory = new PluginParameterViewFactory<GameObject, MapArchObject, Archetype, CMapViewBasic>(archetypeSet, gameObjectAttributesModel, objectChooser, defaultFilterList, mapManager); - scriptControl = new ScriptController<GameObject, MapArchObject, Archetype, CMapViewBasic>(filterControl, scriptParameters, getMainView(), pluginParameterViewFactory); - } - - /** {@inheritDoc} */ - @Override - protected void init3() { - scriptControl.getView().setMenu((JMenu) ACTION_FACTORY.find(getMainView().getJMenuBar(), "plugins")); - } - - /** {@inheritDoc} */ - @Override protected void init4(@NotNull final GameObjectParser<GameObject, MapArchObject, Archetype> gameObjectParser, @NotNull final AbstractArchetypeParser<GameObject, MapArchObject, Archetype> archetypeParser, @NotNull final EditTypes<GameObject, MapArchObject, Archetype, CMapViewBasic> editTypes, @NotNull final net.sf.gridarta.gameobject.face.FaceObjects faceObjects, @NotNull final net.sf.gridarta.gameobject.anim.AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final MainView<GameObject, MapArchObject, Archetype, CMapViewBasic> mainView, @NotNull final GlobalSettings globalSettings, @NotNull final net.sf.gridarta.gameobject.ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet) { MultiPositionData.init(globalSettings.getConfigurationDirectory()); new ArchetypeSetLoader(globalSettings, gameObjectParser, globalSettings.getCollectedDirectory(), globalSettings.getConfigurationDirectory(), archetypeSet, archetypeParser, editTypes, faceObjects, animationObjects, this).loadArchetypes(mainView); @@ -284,16 +249,6 @@ /** {@inheritDoc} */ @Override - protected void init5(@NotNull final GlobalSettings globalSettings) { - final JMenu menuAnalyze = (JMenu) ACTION_FACTORY.find(getMainView().getJMenuBar(), "analyze"); - if (menuAnalyze != null) { - filterControl.createMenuEntries(menuAnalyze); - } - scriptControl.loadScripts(new File(globalSettings.getMapDir(), IGUIConstants.SCRIPTS_DIR)); - } - - /** {@inheritDoc} */ - @Override protected void deleteLibraries() { // Delete libraries. final File libs = new File(System.getProperty("user.dir"), "lib"); @@ -483,12 +438,6 @@ FaceObjectProviders.reloadAll(); } - /** {@inheritDoc} */ - @Override - public boolean canExit() { - return super.canExit() && scriptControl.canExit(); - } - /** * Run in batch png mode. * @param args the argument strings that were not parsed away by {@link @@ -563,14 +512,4 @@ return new ArchetypeSet(gridartaObjectsFactory); } - /** - * Executes an editor script. - * @param script the script name to execute - * @param params the script parameters - * @throws ScriptExecException if the script execution fails - */ - public void executeScript(final String script, final List<String> params) throws ScriptExecException { - scriptControl.executeScript(script, params); - } - } // class CMainControl Modified: trunk/daimonin/src/daieditor/DefaultGridartaObjectsFactory.java =================================================================== --- trunk/daimonin/src/daieditor/DefaultGridartaObjectsFactory.java 2008-10-02 18:23:13 UTC (rev 5375) +++ trunk/daimonin/src/daieditor/DefaultGridartaObjectsFactory.java 2008-10-02 19:30:12 UTC (rev 5376) @@ -142,6 +142,7 @@ this.toolPalette = toolPalette; } + /** {@inheritDoc} */ public void setFilterControl(@NotNull final FilterControl<GameObject, MapArchObject, Archetype, CMapViewBasic> filterControl) { this.filterControl = filterControl; } Modified: trunk/src/app/net/sf/gridarta/AbstractMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-02 18:23:13 UTC (rev 5375) +++ trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-10-02 19:30:12 UTC (rev 5376) @@ -26,6 +26,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -42,6 +43,8 @@ import net.sf.gridarta.archtype.ArchetypeTypeParser; import net.sf.gridarta.archtype.ArchetypeTypeSet; import net.sf.gridarta.archtype.ArchetypeTypeSetParser; +import net.sf.gridarta.filter.FilterControl; +import net.sf.gridarta.filter.NamedFilterList; import net.sf.gridarta.gameobject.AbstractArchetypeParser; import net.sf.gridarta.gameobject.Archetype; import net.sf.gridarta.gameobject.ArchetypeSet; @@ -52,6 +55,7 @@ import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gameobject.match.GameObjectMatcher; import net.sf.gridarta.gameobject.match.GameObjectMatchers; +import net.sf.gridarta.gameobject.match.NamedGameObjectMatcher; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptedEvent; import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; @@ -86,9 +90,9 @@ import net.sf.gridarta.gui.newmap.NewMapDialogFactory; import net.sf.gridarta.gui.objectchoicedisplay.ObjectChoiceDisplay; import net.sf.gridarta.gui.objectchooser.DefaultObjectChooser; -import net.sf.gridarta.gui.objectchooser.ObjectChooser; import net.sf.gridarta.gui.pickmapchooser.PickmapChooserControl; import net.sf.gridarta.gui.prefs.AppPrefsModel; +import net.sf.gridarta.gui.script.parameter.PluginParameterViewFactory; import net.sf.gridarta.gui.selectedsquare.SelectedSquareControl; import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; import net.sf.gridarta.gui.undo.UndoControl; @@ -103,6 +107,9 @@ import net.sf.gridarta.map.MapControlFactory; import net.sf.gridarta.map.validation.DelegatingMapValidator; import net.sf.gridarta.mapfiles.MapFolderTree; +import net.sf.gridarta.script.ScriptController; +import net.sf.gridarta.script.ScriptExecException; +import net.sf.gridarta.script.ScriptParameters; import net.sf.gridarta.script.parameter.PluginParameterFactory; import net.sf.gridarta.spells.ArchetypeSetSpellLoader; import net.sf.gridarta.spells.GameObjectSpell; @@ -271,6 +278,13 @@ @NotNull private final AppPrefsModel appPrefsModel; + /** The script controller. */ + @NotNull + private final ScriptController<G, A, R, V> scriptControl; + + @NotNull + private final FilterControl<G, A, R, V> filterControl; + /** * Creates a new instance. * @param gridartaObjectsFactory the gridarta objects factory @@ -299,8 +313,9 @@ * locked items * @param autoValidatorDefault whether the auto validator is enabled by * default + * @param scriptsDir the plugin scripts directory */ - protected AbstractMainControl(@NotNull final GridartaObjectsFactory<G, A, R, V> gridartaObjectsFactory, @NotNull final RendererFactory<G, A, R> rendererFactory, @NotNull final String key, @NotNull final GlobalSettings globalSettings, @NotNull final AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final FaceObjects faceObjects, final boolean createDirectionPane, @Nullable final File mapImageCacheDir, @Nullable final ImageIcon compassIcon, @NotNull final String gridartaJarFilename, @NotNull final FileFilter scriptFileFilter, @NotNull final String scriptExtension, @NotNull final String scriptName, final int spellType, @Nullable final String spellFile, final int typeNoEventConnector, final boolean includeFaceText, final int undefinedSpellIndex, @NotNull final int[] lockedItemsTypeNumbers, final boolean autoValidatorDefault) { + protected AbstractMainControl(@NotNull final GridartaObjectsFactory<G, A, R, V> gridartaObjectsFactory, @NotNull final RendererFactory<G, A, R> rendererFactory, @NotNull final String key, @NotNull final GlobalSettings globalSettings, @NotNull final AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final FaceObjects faceObjects, final boolean createDirectionPane, @Nullable final File mapImageCacheDir, @Nullable final ImageIcon compassIcon, @NotNull final String gridartaJarFilename, @NotNull final FileFilter scriptFileFilter, @NotNull final String scriptExtension, @NotNull final String scriptName, final int spellType, @Nullable final String spellFile, final int typeNoEventConnector, final boolean includeFaceText, final int undefinedSpellIndex, @NotNull final int[] lockedItemsTypeNumbers, final boolean autoValidatorDefault, @NotNull final String scriptsDir) { this.scriptExtension = scriptExtension; this.globalSettings = globalSettings; appPrefsModel = createAppPrefsModel(); @@ -415,7 +430,13 @@ final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel = new GameObjectAttributesModel<G, A, R>(); gameObjectAttributesControl = new GameObjectAttributesControl<G, A, R, V>(gameObjectAttributesModel, gameObjectAttributesDialogFactory, objectChooser, archetypeTypeSet, mapManager, mapViewManager, animationObjects, lockedItemsControl, monsterMatcher, selectedSquareControl, selectedSquareView, mainView); PluginParameterFactory.init(archetypeSet, mapManager); - init2(gridartaObjectsFactory, globalSettings, mapManager, archetypeSet, validators, gameObjectMatchers, gameObjectAttributesModel, objectChooser); + final NamedFilterList defaultNamedFilterList = new NamedFilterList(gameObjectMatchers.getFilters()); + filterControl = new FilterControl<G, A, R, V>(mapManager, defaultNamedFilterList); + gridartaObjectsFactory.setFilterControl(filterControl); + final ScriptParameters scriptParameters = new ScriptParameters(archetypeSet, globalSettings, mapManager, validators); + final NamedFilterList defaultFilterList = new NamedFilterList(Collections.<NamedGameObjectMatcher>emptyList()); + final PluginParameterViewFactory<G, A, R, V> pluginParameterViewFactory = new PluginParameterViewFactory<G, A, R, V>(archetypeSet, gameObjectAttributesModel, objectChooser, defaultFilterList, mapManager); + scriptControl = new ScriptController<G, A, R, V>(filterControl, scriptParameters, mainView, pluginParameterViewFactory); final ObjectChoiceDisplay<G, A, R, V> objectChoiceDisplay = new ObjectChoiceDisplay<G, A, R, V>(replaceDialogManager, archetypeTypeSet, objectChooser, archetypeChooserModel, pickmapChooserControl); final ToolPalette<G, A, R, V> toolPalette = new ToolPalette<G, A, R, V>(editTypes, selectedSquareView, objectChooser, pickmapChooserControl); final LeftPanel leftPanel = new LeftPanel(objectChooser, toolPalette, objectChoiceDisplay); @@ -423,7 +444,9 @@ createActions(); mainView.init(gameObjectAttributesControl, selectedSquareView, archetypeTypeSet, mapTileListBottom, gameObjectMatchers, archetypeChooserControl, pickmapChooserControl, objectChooser, leftPanel); mapActions.updateMenuState(); - init3(); + final Object abc = mainView.getJMenuBar(); + final Object def = actionFactory.find(mainView.getJMenuBar(), "plugins"); + scriptControl.getView().setMenu((JMenu) actionFactory.find(mainView.getJMenuBar(), "plugins")); final GameObjectFactory<G, A, R> gameObjectFactory = newGameObjectFactory(); final GameObjectParser<G, A, R> gameObjectParser = newGameObjectParser(gameObjectFactory); archetypeSet.init(gameObjectParser); @@ -445,7 +468,11 @@ deleteLibraries(); final RecentManager recentManager = new RecentManager(mapManager, (JMenu) actionFactory.find(mainView.getJMenuBar(), "recent"), globalSettings, mapPreviewAccessory); mapManager.setRecentManager(recentManager); - init5(globalSettings); + final JMenu menuAnalyze = (JMenu) actionFactory.find(mainView.getJMenuBar(), "analyze"); + if (menuAnalyze != null) { + filterControl.createMenuEntries(menuAnalyze); + } + scriptControl.loadScripts(new File(globalSettings.getMapDir(), scriptsDir)); archetypeChooserControl.getArchetypeChooserView().finishBuildProcess(); autojoinLists.loadList(archetypeSet, globalSettings.getConfigurationDirectory()); if (archetypeSet.getLoadStatus() == ArchetypeSet.LoadStatus.EMPTY) { @@ -486,16 +513,10 @@ @NotNull protected abstract MapActions init1(@NotNull final GridartaObjectsFactory<G, A, R, V> gridartaObjectsFactory, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<G, A, R, V> mapManager, @NotNull final ArchetypeTypeSet<G, A, R> archetypeTypeSet, @NotNull final SelectedSquareView<G, A, R, V> selectedSquareView, @NotNull final GameObjectMatcher exitMatcher); - protected abstract void init2(@NotNull final GridartaObjectsFactory<G, A, R, V> gridartaObjectsFactory, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<G, A, R, V> mapManager, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final DelegatingMapValidator<G, A, R> validators, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel, @NotNull final ObjectChooser<G, A, R> objectChooser); - - protected abstract void init3(); - protected abstract void init4(@NotNull final GameObjectParser<G, A, R> gameObjectParser, @NotNull final AbstractArchetypeParser<G, A, R> archetypeParser, @NotNull final EditTypes<G, A, R, V> editTypes, @NotNull final FaceObjects faceObjects, @NotNull final AnimationObjects<? extends AnimationObject> animationObjects, final MainView<G, A, R, V> mainView, @NotNull final GlobalSettings globalSettings, @NotNull final ArchetypeSet<G, A, R> archetypeSet); protected abstract void deleteLibraries(); - protected abstract void init5(@NotNull final GlobalSettings globalSettings); - /** * Initializes the map validators. * @param globalSettings the global settings instance @@ -695,8 +716,8 @@ * user if applicable). * @return whether all modified data has been saved */ - protected boolean canExit() { - return ScriptEditControlInstance.getInstance().closeAllTabs() && mapManager.closeAll() && pickmapChooserControl.canExit(); + private boolean canExit() { + return ScriptEditControlInstance.getInstance().closeAllTabs() && mapManager.closeAll() && pickmapChooserControl.canExit() && scriptControl.canExit(); } /** {@inheritDoc} */ @@ -842,4 +863,14 @@ controlClient.showDialog(getMainView()); } + /** + * Executes an editor script. + * @param script the script name to execute + * @param params the script parameters + * @throws ScriptExecException if the script execution fails + */ + public void executeScript(final String script, final List<String> params) throws ScriptExecException { + scriptControl.executeScript(script, params); + } + } // class AbstractMainControl Modified: trunk/src/app/net/sf/gridarta/GridartaObjectsFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/GridartaObjectsFactory.java 2008-10-02 18:23:13 UTC (rev 5375) +++ trunk/src/app/net/sf/gridarta/GridartaObjectsFactory.java 2008-10-02 19:30:12 UTC (rev 5376) @@ -22,6 +22,7 @@ import java.awt.Point; import java.io.File; import java.io.FileNotFoundException; +import net.sf.gridarta.filter.FilterControl; import net.sf.gridarta.gameobject.Archetype; import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gameobject.GameObject; @@ -100,4 +101,6 @@ */ void init(@NotNull FaceObjects faceObjects, @NotNull final SelectedSquareView<G, A, R, V> selectedSquareView, @NotNull MainControl<G, A, R, V> mainControl, @NotNull MainView<G, A, R, V> mainView, @NotNull EditTypes<G, A, R, V> editTypes, @NotNull MapImageCache<G, A, R, V> mapImageCache, @NotNull ArchetypeSet<G, A, R> archetypeSet, @NotNull ToolPalette<G, A, R, V> toolPalette); + void setFilterControl(@NotNull FilterControl<G, A, R, V> filterControl); + } // interface GridartaObjectsFactory Modified: trunk/src/test/net/sf/gridarta/map/DefaultMapModelTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/map/DefaultMapModelTest.java 2008-10-02 18:23:13 UTC (rev 5375) +++ trunk/src/test/net/sf/gridarta/map/DefaultMapModelTest.java 2008-10-02 19:30:12 UTC (rev 5376) @@ -49,6 +49,7 @@ import net.sf.gridarta.Size2D; import net.sf.gridarta.archtype.ArchetypeTypeSet; import net.sf.gridarta.data.NamedTreeNode; +import net.sf.gridarta.filter.FilterControl; import net.sf.gridarta.gameobject.AbstractArchetypeParser; import net.sf.gridarta.gameobject.AbstractArchetypeSet; import net.sf.gridarta.gameobject.Archetype; @@ -65,11 +66,9 @@ import net.sf.gridarta.gameobject.face.DuplicateFaceException; import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gameobject.match.GameObjectMatcher; -import net.sf.gridarta.gameobject.match.GameObjectMatchers; import net.sf.gridarta.gui.MainView; import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserControl; import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserModel; -import net.sf.gridarta.gui.gameobjectattributespanel.GameObjectAttributesModel; import net.sf.gridarta.gui.gameobjectattributespanel.ScriptTab; import net.sf.gridarta.gui.map.LevelRenderer; import net.sf.gridarta.gui.map.MapActions; @@ -78,7 +77,6 @@ import net.sf.gridarta.gui.map.RendererFactory; import net.sf.gridarta.gui.map.tools.ToolPalette; import net.sf.gridarta.gui.newmap.NewMapDialogFactory; -import net.sf.gridarta.gui.objectchooser.ObjectChooser; import net.sf.gridarta.gui.prefs.AppPrefsModel; import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; import net.sf.gridarta.io.AbstractGameObjectParser; @@ -443,7 +441,7 @@ * @param faceObjects the face objects instance to use */ protected TestMainControl(@NotNull final GridartaObjectsFactory<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> gridartaObjectsFactory, @NotNull final RendererFactory<TestGameObject, TestMapArchObject, TestArchetype> rendererFactory, @NotNull final String key, @NotNull final GlobalSettings globalSettings, @NotNull final AnimationObjects<TestAnimationObject> animationObjects, @NotNull final FaceObjects faceObjects) { - super(gridartaObjectsFactory, rendererFactory, key, globalSettings, animationObjects, faceObjects, true, null, null, "test.jar", new TestFileFilter(), ".script", "Script", 0, null, -1, false, 0, new int[] { 13, }, false); + super(gridartaObjectsFactory, rendererFactory, key, globalSettings, animationObjects, faceObjects, true, null, null, "test.jar", new TestFileFilter(), ".script", "Script", 0, null, -1, false, 0, new int[] { 13, }, false, "scripts"); } /** {@inheritDoc} */ @@ -527,29 +525,12 @@ /** {@inheritDoc} */ @Override - protected void init2(@NotNull final GridartaObjectsFactory<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> gridartaObjectsFactory, @NotNull final GlobalSettings globalSettings, @NotNull final MapManager<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> mapManager, @NotNull final ArchetypeSet<TestGameObject, TestMapArchObject, TestArchetype> archetypeSet, @NotNull final DelegatingMapValidator<TestGameObject, TestMapArchObject, TestArchetype> validators, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final GameObjectAttributesModel<TestGameObject, TestMapArchObject, TestArchetype> gameObjectAttributesModel, @NotNull final ObjectChooser<TestGameObject, TestMapArchObject, TestArchetype> objectChooser) { - throw new AssertionError(); - } - - /** {@inheritDoc} */ - @Override - protected void init3() { - throw new AssertionError(); - } - - /** {@inheritDoc} */ - @Override protected void init4(@NotNull final GameObjectParser<TestGameObject, TestMapArchObject, TestArchetype> gameObjectParser, @NotNull final AbstractArchetypeParser<TestGameObject, TestMapArchObject, TestArchetype> archetypeParser, @NotNull final EditTypes<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> editTypes, @NotNull final FaceObjects faceObjects, @NotNull final AnimationObjects<? extends AnimationObject> animationObjects, @NotNull final MainView<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> mainView, @NotNull final GlobalSettings globalSettings, @NotNull final ArchetypeSet<TestGameObject, TestMapArchObject, TestArchetype> archetypeSet) { throw new AssertionError(); } /** {@inheritDoc} */ @Override - protected void init5(@NotNull final GlobalSettings globalSettings) { - } - - /** {@inheritDoc} */ - @Override protected void deleteLibraries() { throw new AssertionError(); } @@ -984,6 +965,12 @@ public void init(@NotNull final FaceObjects faceObjects, @NotNull final SelectedSquareView<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> selectedSquareView, @NotNull final MainControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> mainControl, @NotNull final MainView<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> mainView, @NotNull final EditTypes<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> editTypes, @NotNull final MapImageCache<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> mapImageCache, @NotNull final ArchetypeSet<TestGameObject, TestMapArchObject, TestArchetype> archetypeSet, @NotNull final ToolPalette<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> toolPalette) { throw new AssertionError(); } + + /** {@inheritDoc} */ + public void setFilterControl(@NotNull final FilterControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> filterControl) { + throw new AssertionError(); + } + } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |