From: <aki...@us...> - 2007-05-14 17:47:13
|
Revision: 2467 http://svn.sourceforge.net/gridarta/?rev=2467&view=rev Author: akirschbaum Date: 2007-05-14 10:47:14 -0700 (Mon, 14 May 2007) Log Message: ----------- Remove dependency to Java 1.6. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/MapActions.java Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2007-05-14 17:45:21 UTC (rev 2466) +++ trunk/crossfire/src/cfeditor/CMainView.java 2007-05-14 17:47:14 UTC (rev 2467) @@ -173,6 +173,8 @@ mainControl.getScriptController().setMenu((JMenu) ACTION_FACTORY.find(getJMenuBar(), "plugins")); lookAndFeelManager.init((JMenu) ACTION_FACTORY.find(getJMenuBar(), "view")); + mapActions.updateMenuState(); + // set bounds (location and size) of the main frame setBounds( prefs.getInt(WINDOW_X, (int) (screen.getX() + (screen.getWidth() - defwidth) / 2.0)), Modified: trunk/crossfire/src/cfeditor/MapActions.java =================================================================== --- trunk/crossfire/src/cfeditor/MapActions.java 2007-05-14 17:45:21 UTC (rev 2466) +++ trunk/crossfire/src/cfeditor/MapActions.java 2007-05-14 17:47:14 UTC (rev 2467) @@ -111,7 +111,6 @@ this.mainControl = mainControl; autoJoin = prefs.getBoolean(AUTOJOIN_KEY, false); - aAutoJoin.putValue(Action.SELECTED_KEY, autoJoin); for (int i = 0; i < directionsMap.length; i++) { aDirections[i] = ACTION_FACTORY.createAction(true, directionsMap[i], this); @@ -140,6 +139,13 @@ } /** + * Set the state of all actions. + */ + public void updateMenuState() { + aAutoJoin.setSelected(autoJoin); + } + + /** * Action method for "grid visible". * @return <code>true</code> if the grid is visible, or <code>false</code> * if the grid is invisible This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-05-14 17:57:20
|
Revision: 2468 http://svn.sourceforge.net/gridarta/?rev=2468&view=rev Author: akirschbaum Date: 2007-05-14 10:57:21 -0700 (Mon, 14 May 2007) Log Message: ----------- Replace String with File. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CResourceLoader.java trunk/crossfire/src/cfeditor/CSettings.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-14 17:47:14 UTC (rev 2467) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-14 17:57:21 UTC (rev 2468) @@ -256,7 +256,7 @@ readGlobalSettings(); - mapImageCache = new MapImageCache(this, new File(CResourceLoader.getHomeFileName("thumbnails")), defaultIcon, defaultPreview); + mapImageCache = new MapImageCache(this, CResourceLoader.getHomeFile("thumbnails"), defaultIcon, defaultPreview); mapPreviewAccessory = new MapPreviewAccessory(mapImageCache); Modified: trunk/crossfire/src/cfeditor/CResourceLoader.java =================================================================== --- trunk/crossfire/src/cfeditor/CResourceLoader.java 2007-05-14 17:47:14 UTC (rev 2467) +++ trunk/crossfire/src/cfeditor/CResourceLoader.java 2007-05-14 17:57:21 UTC (rev 2468) @@ -101,16 +101,15 @@ /*Second, try Home directory*/ if (checkHome) { try { - final String homeFile = getHomeFileName(filename); + final File homeFile = getHomeFile(filename); if (log.isDebugEnabled()) { log.debug("trying to load " + filename + " from current " + homeFile); } - final File f = new File(homeFile); - if (f.exists() && !f.isDirectory()) { + if (homeFile.exists() && !homeFile.isDirectory()) { log.debug("ok!"); type = LOCATION_HOME; - url = f.toURI().toURL(); - this.file = f; + url = homeFile.toURI().toURL(); + this.file = homeFile; return; } } catch (final Exception e) { @@ -165,8 +164,7 @@ } if (type == LOCATION_JAR || type == LOCATION_UNKNOWN) { - final String homeFile = getHomeFileName(filename); - file = new File(homeFile); + file = getHomeFile(filename); return new FileOutputStream(file); } throw new IOException("Could not create output Stream for" + filename); @@ -176,14 +174,14 @@ * Return the filename to use when dealing with this * application's and current users' home dir. * For example, if called like this - * <code>CResourceLoader.getHomeFileName("myfile");</code> + * <code>CResourceLoader.getHomeFile("myfile");</code> * will return something like /home/someuser/.cfeditor/myfile * under linux. * @param filename the name of requested file. * @return the full to user home dir, appended with * application dir and the filename. */ - public static String getHomeFileName(final String filename) { + public static File getHomeFile(final String filename) { final StringBuilder buf = new StringBuilder(128); final String home = System.getProperty("user.home"); buf.append(home); @@ -194,7 +192,7 @@ } buf.append(File.separator); buf.append(filename); - return buf.toString(); + return new File(buf.toString()); } /** @@ -233,8 +231,8 @@ } Document homeDoc = null; if (readHome) { + final File f = getHomeFile(filename); try { - final File f = new File(getHomeFileName(filename)); if (f.exists() && !f.isDirectory()) { homeDoc = builder.build(f); } @@ -243,7 +241,7 @@ log.info("Error while loading " + filename + " from current home directory (" - + getHomeFileName(filename) + + f + "). Ignoring file", e); } } Modified: trunk/crossfire/src/cfeditor/CSettings.java =================================================================== --- trunk/crossfire/src/cfeditor/CSettings.java 2007-05-14 17:47:14 UTC (rev 2467) +++ trunk/crossfire/src/cfeditor/CSettings.java 2007-05-14 17:57:21 UTC (rev 2468) @@ -80,7 +80,7 @@ * @param strFile file name to read the configuration from. */ private CSettings(final String strFile) { - this.strFile = CResourceLoader.getHomeFileName(strFile); + this.strFile = CResourceLoader.getHomeFile(strFile).getPath(); } /** Loads the settings from the file. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-05-15 08:52:07
|
Revision: 2481 http://svn.sourceforge.net/gridarta/?rev=2481&view=rev Author: christianhujer Date: 2007-05-15 01:52:09 -0700 (Tue, 15 May 2007) Log Message: ----------- Removed unneccessary return statements. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinLists.java trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserControl.java Modified: trunk/crossfire/src/cfeditor/AutojoinLists.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinLists.java 2007-05-15 08:51:15 UTC (rev 2480) +++ trunk/crossfire/src/cfeditor/AutojoinLists.java 2007-05-15 08:52:09 UTC (rev 2481) @@ -149,10 +149,8 @@ if (log.isInfoEnabled()) { log.info("Autojoin definitions file '" + FILENAME + "' not found."); } - return; } catch (final IOException e) { log.warn("Read error in file '" + FILENAME + "'."); - return; } } Modified: trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserControl.java 2007-05-15 08:51:15 UTC (rev 2480) +++ trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserControl.java 2007-05-15 08:52:09 UTC (rev 2481) @@ -143,7 +143,6 @@ } } catch (final IOException e) { log.warn("Couldn't load pickmap", e); - return; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-05-15 20:42:33
|
Revision: 2493 http://svn.sourceforge.net/gridarta/?rev=2493&view=rev Author: akirschbaum Date: 2007-05-15 13:42:28 -0700 (Tue, 15 May 2007) Log Message: ----------- Unify key bindings for 'go location'. Modified Paths: -------------- 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 Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2007-05-15 13:04:59 UTC (rev 2492) +++ trunk/crossfire/src/cfeditor/messages.properties 2007-05-15 20:42:28 UTC (rev 2493) @@ -281,7 +281,8 @@ goNorthWest.accel=NUMPAD7 goLocation.text=Goto Location -goLocation.accel=ctrl pressed G +goLocation.mnemonic=L +goLocation.accel=ctrl pressed L selectTile.text=Select tile selectTile.accel=NUMPAD5 Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2007-05-15 13:04:59 UTC (rev 2492) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2007-05-15 20:42:28 UTC (rev 2493) @@ -278,7 +278,8 @@ goNorthWest.accel=NUMPAD7 goLocation.text=Cursor setzen -goLocation.accel=ctrl pressed G +goLocation.mnemonic=S +goLocation.accel=ctrl pressed L selectTile.text=Feld ausw\xE4hlen selectTile.accel=NUMPAD5 Modified: trunk/crossfire/src/cfeditor/messages_fr.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_fr.properties 2007-05-15 13:04:59 UTC (rev 2492) +++ trunk/crossfire/src/cfeditor/messages_fr.properties 2007-05-15 20:42:28 UTC (rev 2493) @@ -279,7 +279,7 @@ goNorthWest.accel=NUMPAD8 #goLocation.text= -goLocation.accel=ctrl pressed G +goLocation.accel=ctrl pressed L #selectTile.text= selectTile.accel=NUMPAD5 Modified: trunk/crossfire/src/cfeditor/messages_sv.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_sv.properties 2007-05-15 13:04:59 UTC (rev 2492) +++ trunk/crossfire/src/cfeditor/messages_sv.properties 2007-05-15 20:42:28 UTC (rev 2493) @@ -277,7 +277,7 @@ goNorthWest.accel=NUMPAD8 #goLocation.text= -goLocation.accel=ctrl pressed G +goLocation.accel=ctrl pressed L selectTile.text=Markera ruta selectTile.accel=NUMPAD5 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-05-16 08:26:31
|
Revision: 2501 http://svn.sourceforge.net/gridarta/?rev=2501&view=rev Author: akirschbaum Date: 2007-05-16 01:26:33 -0700 (Wed, 16 May 2007) Log Message: ----------- Move scripting related classes to cfeditor.script package. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gui/ScriptEditor.java trunk/crossfire/src/cfeditor/gui/ScriptManager.java trunk/crossfire/src/cfeditor/script/parameter/ArchParameter.java trunk/crossfire/src/cfeditor/script/parameter/ArchParameterView.java trunk/crossfire/src/cfeditor/script/parameter/BooleanParameter.java trunk/crossfire/src/cfeditor/script/parameter/BooleanParameterView.java trunk/crossfire/src/cfeditor/script/parameter/DoubleParameter.java trunk/crossfire/src/cfeditor/script/parameter/DoubleParameterView.java trunk/crossfire/src/cfeditor/script/parameter/FilterParameter.java trunk/crossfire/src/cfeditor/script/parameter/FilterParameterView.java trunk/crossfire/src/cfeditor/script/parameter/IntegerParameter.java trunk/crossfire/src/cfeditor/script/parameter/IntegerParameterView.java trunk/crossfire/src/cfeditor/script/parameter/MapParameter.java trunk/crossfire/src/cfeditor/script/parameter/MapParameterView.java trunk/crossfire/src/cfeditor/script/parameter/ParameterDescriptionEditor.java trunk/crossfire/src/cfeditor/script/parameter/ParameterNameEditor.java trunk/crossfire/src/cfeditor/script/parameter/ParameterTypeEditor.java trunk/crossfire/src/cfeditor/script/parameter/PluginParameter.java trunk/crossfire/src/cfeditor/script/parameter/PluginParameterFactory.java trunk/crossfire/src/cfeditor/script/parameter/PluginParameterView.java trunk/crossfire/src/cfeditor/script/parameter/StringParameter.java trunk/crossfire/src/cfeditor/script/parameter/StringParameterView.java Added Paths: ----------- trunk/crossfire/src/cfeditor/script/ trunk/crossfire/src/cfeditor/script/BshThread.java trunk/crossfire/src/cfeditor/script/CScriptController.java trunk/crossfire/src/cfeditor/script/CScriptModel.java trunk/crossfire/src/cfeditor/script/CScriptView.java trunk/crossfire/src/cfeditor/script/ScriptControlListener.java trunk/crossfire/src/cfeditor/script/parameter/ Removed Paths: ------------- trunk/crossfire/src/cfeditor/BshThread.java trunk/crossfire/src/cfeditor/CScriptController.java trunk/crossfire/src/cfeditor/CScriptModel.java trunk/crossfire/src/cfeditor/CScriptView.java trunk/crossfire/src/cfeditor/ScriptControlListener.java trunk/crossfire/src/cfeditor/parameter/ Deleted: trunk/crossfire/src/cfeditor/BshThread.java =================================================================== --- trunk/crossfire/src/cfeditor/BshThread.java 2007-05-16 08:07:57 UTC (rev 2500) +++ trunk/crossfire/src/cfeditor/BshThread.java 2007-05-16 08:26:33 UTC (rev 2501) @@ -1,96 +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; - -import bsh.EvalError; -import bsh.Interpreter; - -/** - * A BshThread. - * @todo Document this class. - * @author tchize - */ -public final class BshThread extends Thread { - - /** - * The ScriptModel of this BshThread. - */ - private CScriptModel script; - - /** - * The Interpreter of this BshThread. - */ - private Interpreter interpreter; - - /** - * Create a BshThread. - */ - public BshThread() { - } - - /** - * Create a BshThread with name. - * @param name Name to assign to the BshThread. - */ - public BshThread(final String name) { - super(name); - } - - /** - * Create a BshThread with a name in a certain thread group. - * @param group ThreadGroup to put BshThread in. - * @param name Name to assign to the BshThread. - */ - public BshThread(final ThreadGroup group, final String name) { - super(group, name); - } - - /** - * Sets the interpreter for this BshThread. - * @param interpreter Interpreter for this BshThread. - */ - public void setInterpreter(final Interpreter interpreter) { - this.interpreter = interpreter; - } - - /** - * Sets the ScriptModel for this BshThread. - * @param script ScriptModel for this BshThread. - */ - public void setScript(final CScriptModel script) { - this.script = script; - } - - /** {@inheritDoc} */ - @Override public void run() { - try { - interpreter.set("scriptThread", this); - interpreter.eval(script.getCode()); - } catch (final EvalError e) { - //do something? - interpreter.getErr().print(e.getMessage()); - if (e.getCause() != null) { - interpreter.getErr().print(e.getCause().getMessage()); - } - e.printStackTrace(); - } - } - -} // class BshThread Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-16 08:07:57 UTC (rev 2500) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-16 08:26:33 UTC (rev 2501) @@ -34,6 +34,7 @@ import cfeditor.gui.prefs.ResPrefs; import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; +import cfeditor.script.CScriptController; import java.awt.Point; import java.io.File; import java.io.IOException; Deleted: trunk/crossfire/src/cfeditor/CScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptController.java 2007-05-16 08:07:57 UTC (rev 2500) +++ trunk/crossfire/src/cfeditor/CScriptController.java 2007-05-16 08:26:33 UTC (rev 2501) @@ -1,415 +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; - -import bsh.ConsoleInterface; -import bsh.EvalError; -import bsh.Interpreter; -import bsh.TargetError; -import cfeditor.filter.Filter; -import java.io.CharArrayWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.Reader; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import javax.swing.JFileChooser; -import javax.swing.JMenu; -import javax.swing.JOptionPane; -import javax.swing.event.EventListenerList; -import javax.swing.filechooser.FileFilter; -import org.apache.log4j.Logger; -import org.jdom.Document; -import org.jdom.Element; -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. - * @todo documentation - * @author tchize - */ -public final class CScriptController { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(CScriptController.class); - - private final Map<String, CScriptModel> scripts = new LinkedHashMap<String, CScriptModel>(); - - private final CScriptView view; - - /** The MainControlListeners to inform of changes. */ - private final EventListenerList listeners = new EventListenerList(); - - private final CMainControl mainControl; - - private final CResourceLoader scriptRsc; - - public CScriptController(final CMainControl mainControl) { - view = new CScriptView(this); - this.mainControl = mainControl; - scriptRsc = new CResourceLoader("scripts.xml"); - importXML(); - } - - /** - * Set the menu to add script commands to. Entries already present in the - * menu are deleted. - * - * @param menuScripts the plugins menu - */ - public void setMenu(@Nullable final JMenu menuScripts) { - view.setMenu(menuScripts); - } - - public String[] listScript() { - return scripts.keySet().toArray(new String[scripts.keySet().size()]); - } - - /** - * 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(final CScriptModel script) { - if (scripts.containsKey(script.getName())) { - return false; - } - - scripts.put(script.getName(), script); - fireScriptCreatedEvent(script); - return true; - } - - public void removeScript(final CScriptModel script) { - if (!scripts.containsKey(script.getName())) { - throw new IllegalArgumentException(); - } - - scripts.remove(script.getName()); - fireScriptDeletedEvent(script); - } - - public void importXML() { - final Document d = CResourceLoader.getAggregateXML("scripts.xml", true, true, true); - importXML(d, true); - } - - public void importXML(final Reader source, final boolean override) { - final SAXBuilder builder = new SAXBuilder(false);/*non validating*/ - log.debug("Loading...."); - try { - final Document scriptDoc = builder.build(source); - importXML(scriptDoc, override); - } catch (final Exception e) { - } - } - - public void importXML(final Document doc, final boolean override) { - try { - if (!doc.hasRootElement()) { - log.info("No script found."); - return; - } - - final Element elt = doc.getRootElement(); - if ((!elt.getName().equalsIgnoreCase("scripts"))) { - log.warn("Problem reading xml scripts, need a root element named \"scripts\""); - return; - } - final List scriptList = elt.getChildren("script"); - if (scriptList == null || scriptList.isEmpty()) { - log.info("no script found"); - return; - } - for (final Object o : scriptList) { - log.debug("Reading one script"); - final CScriptModel cScript = new CScriptModel(this); - cScript.fromXML((Element) o); - log.debug("script: " + cScript.getName()); - if (override || !scripts.containsKey(cScript.getName())) { - if (log.isDebugEnabled()) { - log.debug("storing with code " + cScript.getCode()); - } - - unRegister(cScript.getName()); - addScript(cScript); - register(cScript.getName()); - } else { - log.debug("not storing"); - } - } - } catch (final Exception e) { - e.printStackTrace(); - } - } - - public void exportScript(final CScriptModel model) { - //show a dialog an propose a filename - final JFileChooser chooser = new JFileChooser(); - final FileFilter f = new FileFilter() { - @Override public boolean accept(final File f) { - return f.getName().endsWith(".xml"); - } - - @Override public String getDescription() { - return "cfeditor script (*.xml)"; - } - }; - chooser.setFileFilter(f); - final int result = chooser.showSaveDialog(null); - if (result == JFileChooser.APPROVE_OPTION) { - final Element root = new Element("scripts"); - final Document d = new Document(root); - root.addContent(model.toXML()); - final XMLOutputter out = new XMLOutputter(); - out.setFormat(Format.getPrettyFormat()); - try { - final FileWriter fw = new FileWriter(chooser.getSelectedFile()); - out.output(d, fw); - } catch (final IOException e) { - e.printStackTrace(); - } - } - } - - public void exportXML() { - try { - exportXML(scriptRsc.getOutputStream()); - } catch (final IOException e) { - JOptionPane.showMessageDialog(mainControl.getMainView(), e.getLocalizedMessage(), "Script Error", JOptionPane.INFORMATION_MESSAGE); - e.printStackTrace(); - } - } - - public void exportXML(final OutputStream destination) { - final Element root = new Element("scripts"); - final Document d = new Document(root); - for (final CScriptModel sm : scripts.values()) { - root.addContent(sm.toXML()); - } - final XMLOutputter out = new XMLOutputter(); - out.setFormat(Format.getPrettyFormat()); - try { - out.output(d, destination); - } catch (final IOException e) { - e.printStackTrace(); - } - } - - public void exportXML(final File destination) { - try { - final OutputStream w = new FileOutputStream(destination); - exportXML(w); - } catch (final Exception e) { - e.printStackTrace(); - //TODO handle using main controller - } - } - - private void setInterpreterValues(final Interpreter i, final String mode) throws EvalError { - i.set("mainControl", mainControl); - i.set("mainView", mainControl.getMainView()); - i.set("archList", mainControl.getArchetypeSet()); - i.set("runMode", mode); - } - - public void autoRunScript(final CScriptModel script) { - final Interpreter runner = new Interpreter(); - try { - setInterpreterValues(runner, "autorun"); - runner.eval(script.getCode()); - } catch (final EvalError e) { - log.warn("Evaluation error on (autorun)" + script.getName(), e); - } - } - - @Nullable public Filter getScriptAsFilter(final CScriptModel script) { - final Interpreter runner = new Interpreter(); - try { - setInterpreterValues(runner, "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 cfeditor.filter.Filter object" + script.getName(), e); - } - return null; - } - - public void runScript(final CScriptModel script) { - final CScriptModel model; - try { - model = (CScriptModel) script.clone(); - } catch (final CloneNotSupportedException e) { - throw new AssertionError(); - } - - if (!view.getRunValues(model)) { - return; - } - - final Interpreter runner = new Interpreter(); - final ConsoleInterface console = view.createConsole(model.getName()); - try { - runner.setConsole(console); - setInterpreterValues(runner, "batch"); - for (int i = 0; i < model.getParametersCount(); i++) { - runner.set(model.getParamName(i), model.getParamValue(i)); - } - final BshThread scriptThread = new BshThread(script.getName()); - scriptThread.setScript(script); - scriptThread.setInterpreter(runner); - scriptThread.start(); - } catch (final TargetError e) { - final CharArrayWriter w = new CharArrayWriter(); - e.getTarget().printStackTrace(new PrintWriter(w)); - console.print(w.toString()); - } catch (final EvalError e) { - console.print("Evaluation error: " + e.getMessage()); - } - } - - public void runScript(final String name) { - final CScriptModel model = scripts.get(name); - runScript(model); - } - - public void runScript(final int index) { - final CScriptModel model = getScript(index); - if (model != null) { - runScript(model); - } - } - - public boolean isScriptValid(final String code) { - return true; - } - - public CScriptView getView() { - return view; - } - - @Nullable public CScriptModel getScript(int index) { - final Iterator<CScriptModel> i = scripts.values().iterator(); - CScriptModel m = null; - while (i.hasNext() && index-- >= 0) { - m = i.next(); - } - if (index >= 0) { - return null; - } else { - return m; - } - } - - public CScriptModel getScript(final String name) { - return scripts.get(name); - } - - public int getScriptCount() { - return scripts.size(); - } - - public void addScriptControlListener(@NotNull final ScriptControlListener listener) { - listeners.add(ScriptControlListener.class, 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 CScriptModel script) { - for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { - listener.scriptCreated(script); - } - } - - /** - * Notify all listeners about a removed script. - * - * @param script the removed script - */ - private void fireScriptDeletedEvent(@NotNull final CScriptModel script) { - for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { - listener.scriptDeleted(script); - } - } - - /** - * Notify all listeners about a registered script. - * - * @param script the registered script - */ - private void fireScriptRegisteredEvent(@NotNull final CScriptModel script) { - for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { - listener.scriptRegistered(script); - } - } - - public CMainControl getMainControl() { - return mainControl; - } - - private static void unRegister(final String name) { - final String filterName = "(s)" + name; - CFilterControl.getDefaultFilter().removeFilter(filterName); - } - - private void register(final String name) { - final String filterName = "(s)" + name; - final CScriptModel script = getScript(name); - if (script.isFilter()) { - final Filter filter = getScriptAsFilter(script); - if (filter != null) { - CFilterControl.getDefaultFilter().addFilter(filterName, filter); - } - } - - if (script.isAutoboot()) { - autoRunScript(script); - } - - fireScriptRegisteredEvent(script); - } - - public void reRegister(final String name) { - unRegister(name); - register(name); - } - -} // class CScriptController Deleted: trunk/crossfire/src/cfeditor/CScriptModel.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptModel.java 2007-05-16 08:07:57 UTC (rev 2500) +++ trunk/crossfire/src/cfeditor/CScriptModel.java 2007-05-16 08:26:33 UTC (rev 2501) @@ -1,401 +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; - -import cfeditor.parameter.PluginParameter; -import cfeditor.parameter.PluginParameterFactory; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import org.apache.log4j.Logger; -import org.jdom.CDATA; -import org.jdom.Element; -import org.jdom.IllegalDataException; -import org.jetbrains.annotations.Nullable; - -/** - * Model for Scripts. - * @todo documentation - * @author tchize - */ -public final class CScriptModel implements Cloneable { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(CScriptModel.class); - - public static final int PLUGIN_AUTOBOOT = 1; - - public static final int PLUGIN_FILTER = 2; - - public static final int PLUGIN_SCRIPT = 4; - - public static final Integer RUN_AUTOBOOT = 1; - - public static final Integer RUN_FILTER = 2; - - public static final Integer RUN_SCRIPT = 4; - - private String code = ""; - - private final List<PluginParameter> params = new ArrayList<PluginParameter>(); - - private String name = ""; - - private int scriptType; - - private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(); - - private final CScriptController control; - - public CScriptModel(final CScriptController control) { - this.control = control; - } - - /** - * Returns the name of this ScriptModel. - * @return The name of this ScriptModel. - */ - public String getName() { - return name; - } - - /** - * 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) { - this.name = name; - 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 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) { - this.code = code; - notifyListeners(); - } - - /** - * Set the name of a given parameter. - * @param index The index of parameter to rename - * @param name the new name of parameter - */ - public void setParamName(final int index, final String name) { - try { - params.get(index).setName(name); - } catch (final Exception e) { - } - } - - /** - * Get the name of a script parameter. - * @param index The index number of parameter - * @return the name of parameter - */ - @Nullable public String getParamName(final int index) { - try { - return params.get(index).getName(); - } catch (final Exception e) { - return null; - } - - } - - /** - * Returns the parameter description for the parameter with the specified index. - * @param index the parameter index to get - * @return The description of the specified parameter. - */ - @Nullable public String getParamDescription(final int index) { - try { - return params.get(index).getDescription(); - } catch (final Exception e) { - return null; - } - } - - /** - * Sets the parameter description for the parameter with the specified index. - * @param index the parameter index to set - * @param description the new description of parameter - */ - public void setParamDescription(final int index, final String description) { - try { - params.get(index).setDescription(description); - } catch (final Exception e) { - } - notifyListeners(); - } - - /** - * Returns the parameter value for the parameter with the specified index. - * @param index the parameter index to get - * @return Returns the parameter default value. - */ - @Nullable public Object getParamValue(final int index) { - try { - return params.get(index).getValue(); - } catch (final Exception e) { - e.printStackTrace(); - return null; - } - } - - /** - * Sets the parameter value for the parameter with the specified index. - * @param index the parameter index to set - * @param value the default value to set - */ - public void setParamValue(final int index, final Object value) { - try { - params.get(index).setValue(value); - } catch (final Exception e) { - } - notifyListeners(); - } - - public int getParametersCount() { - return params.size(); - } - - public String[] getParameters() { - final List<String> l = new ArrayList<String>(); - for (final PluginParameter p : params) { - if (!l.contains(p.getName())) { - l.add(p.getName()); - } - } - return l.toArray(new String[l.size()]); - } - - @Override public String toString() { - return name; - } - - public void newParameter() { - final PluginParameter p = PluginParameterFactory.createParameter(); - params.add(p); - notifyListeners(); - } - - public void removeParameter(final int index) { - params.remove(index); - 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 CScriptModel 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 CScriptModel - */ - @Override public Object clone() throws CloneNotSupportedException { - final CScriptModel model = new CScriptModel(control); - model.code = code; - model.name = name; - model.scriptType = scriptType; - for (final PluginParameter param : params) { - model.addParameter((PluginParameter) param.clone()); - } - return model; - } - - /** - * Gets the controller which handles this CScriptModel. - * @return the controller - */ - public CScriptController getController() { - return control; - } - - /** - * Adds a parameter to this script. - * @param p the parameter to add - */ - public void addParameter(final PluginParameter p) { - params.add(p); - 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 - */ - public PluginParameter getParameter(final int index) { - return params.get(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() { - if (log.isDebugEnabled()) { - log.debug("isautoboot: scriptType = " + scriptType); - } - return (scriptType & PLUGIN_AUTOBOOT) != 0; - } - - /** - * Check if this script is a bash script (script run from the run script - * menu). - * @return true if script is a bash script, false otherwise - */ - public boolean isBash() { - return (scriptType & PLUGIN_SCRIPT) != 0; - } - - /** - * 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 (scriptType & PLUGIN_FILTER) != 0; - } - - public void toggleScriptType(final int type, final boolean b) { - if (b) { - scriptType |= type; - } else { - scriptType &= ~type; - } - notifyListeners(); - } - - public void setAutoboot(final boolean b) { - toggleScriptType(PLUGIN_AUTOBOOT, b); - } - - public void setBash(final boolean b) { - toggleScriptType(PLUGIN_SCRIPT, b); - } - - public void setFilter(final boolean b) { - toggleScriptType(PLUGIN_FILTER, b); - } - - public void fromXML(final Element node) { - setName(node.getChildTextTrim("name")); - setCode(node.getChildTextTrim("code")); - scriptType = 0; - final Element mode = node.getChild("mode"); - if (mode == null) { - scriptType = PLUGIN_SCRIPT; - } else { - final List<Element> modes = mode.getChildren(); - for (final Element m : modes) { - final boolean b = Boolean.valueOf(m.getTextTrim()); - final String name = m.getName(); - if ("autoboot".equalsIgnoreCase(name) && b) { - scriptType |= PLUGIN_AUTOBOOT; - } else if ("filter".equalsIgnoreCase(name) && b) { - scriptType |= PLUGIN_FILTER; - } else if ("bash".equalsIgnoreCase(name) && b) { - scriptType |= PLUGIN_SCRIPT; - } - } - } - final List<Element> params = node.getChildren("parameter"); - if (params != null && !params.isEmpty()) { - for (final Element parameter : params) { - final PluginParameter p = PluginParameterFactory.createParameter(parameter); - addParameter(p); - } - } - } - - public Element toXML() { - final Element root = new Element("script"); - final Element n = new Element("name"); - final Element c = new Element("code"); - n.addContent(getName()); - try { - c.addContent(new CDATA(getCode()));// protect code in xml! - } catch (final IllegalDataException e) { - //can't be converted to CDATA :( - c.addContent(getCode()); - } - root.addContent(n); - root.addContent(c); - final Element modes = new Element("mode"); - - { - final Element autoboot = new Element("autoboot"); - autoboot.addContent(Boolean.toString((scriptType & PLUGIN_AUTOBOOT) != 0)); - final Element bash = new Element("bash"); - bash.addContent(Boolean.toString((scriptType & PLUGIN_SCRIPT) != 0)); - final Element filter = new Element("filter"); - filter.addContent(Boolean.toString((scriptType & PLUGIN_FILTER) != 0)); - modes.addContent(autoboot); - modes.addContent(bash); - modes.addContent(filter); - } - - root.addContent(modes); - for (final PluginParameter param : params) { - root.addContent(param.toXML()); - } - return root; - } - - public void convertType(final int index, final String newType) { - params.set(index, PluginParameterFactory.createParameter(newType, params.get(index).toXML())); - notifyListeners(); - } - - public void convertType(final PluginParameter param, final String newType) { - final int index = params.indexOf(param); - convertType(index, newType); - } - -} // class CScriptModel Deleted: trunk/crossfire/src/cfeditor/CScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptView.java 2007-05-16 08:07:57 UTC (rev 2500) +++ trunk/crossfire/src/cfeditor/CScriptView.java 2007-05-16 08:26:33 UTC (rev 2501) @@ -1,269 +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; - -import bsh.ConsoleInterface; -import bsh.util.JConsole; -import cfeditor.gui.CloseableTabbedPane; -import cfeditor.gui.ScriptManager; -import cfeditor.parameter.PluginParameterView; -import java.awt.BorderLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -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 javax.swing.filechooser.FileFilter; -import net.sf.gridarta.Menu; -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 CScriptView { - - /** 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(CScriptView.class); - - private final CScriptController control; - - /** - * The menu to add script commands to. - */ - @Nullable private JMenu menuScripts = null; - - private JFrame console = null; - - private CloseableTabbedPane consolePane = null; - - private JFrame scriptManager = null; - - /** - * The script control listener to be notified about changes in {@link - * #control}. - */ - private final ScriptControlListener scriptControlListener = new ScriptControlListener() { - - /** {@inheritDoc} */ - public void scriptCreated(@NotNull final CScriptModel script) { - updateMenuEntries(); - } - - /** {@inheritDoc} */ - public void scriptDeleted(@NotNull final CScriptModel script) { - updateMenuEntries(); - } - - /** {@inheritDoc} */ - public void scriptRegistered(@NotNull final CScriptModel script) { - updateMenuEntries(); - } - - }; - - /** - * Creates a ScriptView. - * @param control controller of this ScriptView - * @warning Creating a view from a controller instead of a model is error prone. - */ - public CScriptView(final CScriptController control) { - this.control = control; - - control.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; - } - - Menu.removeAllToSeparator(menuScripts); - - final String[] scripts = control.listScript(); - int index = 0; - for (final String script : scripts) { - if (!control.getScript(script).isBash()) { - continue; - } - - final Action action = ACTION_FACTORY.createAction(true, "runPlugin", this); - action.putValue(ReflectionAction.REFLECTION_ARGUMENTS, new Object[] { script, }); - action.putValue(Action.NAME, ACTION_FACTORY.format("runPlugin.text", script)); - final JMenuItem item = new JMenuItem(action); - item.setActionCommand(script); - 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) { - control.runScript(script); - } - - public synchronized void editPlugins() { - if (scriptManager == null) { - scriptManager = new ScriptManager(control); - } - - scriptManager.pack(); - scriptManager.setVisible(true); - } - - public void savePlugins() { - control.exportXML(); - } - - public void exportPluginAs() { - final JFileChooser choose = new JFileChooser(); - final FileFilter filter = new FileFilter() { - @Override public boolean accept(final File f) { - return f.isFile() && f.getName().endsWith(".xml"); - } - - @Override public String getDescription() { - return "XML script collection (*.xml)"; - } - }; - choose.setFileFilter(filter); - if (choose.showSaveDialog(control.getMainControl().getMainView()) == JFileChooser.APPROVE_OPTION) { - final File f = choose.getSelectedFile(); - control.exportXML(f); - } - } - - public void importPlugin() { - final JFileChooser choose = new JFileChooser(); - final FileFilter filter = new FileFilter() { - @Override public boolean accept(final File f) { - return f.isFile() && f.getName().endsWith(".xml") && f.exists() && f.canWrite(); - } - - @Override public String getDescription() { - return "XML script collection (*.xml)"; - } - }; - choose.setFileFilter(filter); - if (choose.showOpenDialog(control.getMainControl().getMainView()) == JFileChooser.APPROVE_OPTION) { - final File f = choose.getSelectedFile(); - try { - control.importXML(new FileReader(f), true); - } catch (final FileNotFoundException ex) { - } - } - } - - 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.addTab(name, bshConsole, true); - return bshConsole; - } - - public boolean getRunValues(final CScriptModel model) { - //JDialog d = new JDialog(control.getMainControl().getMainView(), true); - if (model.getParametersCount() < 1) { - return true; - } - - final JOptionPane p = new JOptionPane(); - p.setOptionType(JOptionPane.OK_CANCEL_OPTION); - p.setMessageType(JOptionPane.QUESTION_MESSAGE); - p.setMessage("Please provide runtime parameters for " + model.getName()); - final GridBagLayout layout = new GridBagLayout(); - final JPanel panel = new JPanel(layout); - final JDialog dialog = p.createDialog(control.getMainControl().getMainView(), "hi"); - dialog.setModal(true); - dialog.setTitle(model.getName()); - dialog.getContentPane().removeAll(); - //JTextField[] fields = new JTextField[model.getParametersCount()]; - for (int i = 0; i < model.getParametersCount(); i++) { - log.debug("adding parameter"); - final JLabel name = new JLabel(model.getParamName(i)); - final PluginParameterView view = model.getParameter(i).getView(); - final JComponent val = view.getValueComponent(model.getParamValue(i), model.getParameter(i)); - val.setToolTipText(model.getParamDescription(i)); - 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); - } - - 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 CScriptView Deleted: trunk/crossfire/src/cfeditor/ScriptControlListener.java =================================================================== --- trunk/crossfire/src/cfeditor/ScriptControlListener.java 2007-05-16 08:07:57 UTC (rev 2500) +++ trunk/crossfire/src/cfeditor/ScriptControlListener.java 2007-05-16 08:26:33 UTC (rev 2501) @@ -1,52 +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; - -import java.util.EventListener; -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 CScriptModel script); - - /** - * Notifies about the deletion of a script. - * - * @param script the deleted script - */ - void scriptDeleted(@NotNull CScriptModel script); - - /** - * Notifies about the registering of a script. - * - * @param script the registered script - */ - void scriptRegistered(@NotNull CScriptModel script); - -} // interface ScriptControlListener Modified: trunk/crossfire/src/cfeditor/gui/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ScriptEditor.java 2007-05-16 08:07:57 UTC (rev 2500) +++ trunk/crossfire/src/cfeditor/gui/ScriptEditor.java 2007-05-16 08:26:33 UTC (rev 2501) @@ -20,13 +20,13 @@ package cfeditor.gui; import cfeditor.CGUIUtils; -import cfeditor.CScriptModel; import cfeditor.IGUIConstants; -import cfeditor.parameter.ParameterDescriptionEditor; -import cfeditor.parameter.ParameterNameEditor; -import cfeditor.parameter.ParameterTypeEditor; -import cfeditor.parameter.PluginParameter; -import cfeditor.parameter.PluginParameterView; +import cfeditor.script.CScriptModel; +import cfeditor.script.parameter.ParameterDescriptionEditor; +import cfeditor.script.parameter.ParameterNameEditor; +import cfeditor.script.parameter.ParameterTypeEditor; +import cfeditor.script.parameter.PluginParameter; +import cfeditor.script.parameter.PluginParameterView; import java.awt.BorderLayout; import java.awt.Component; import java.awt.FlowLayout; Modified: trunk/crossfire/src/cfeditor/gui/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ScriptManager.java 2007-05-16 08:07:57 UTC (rev 2500) +++ trunk/crossfire/src/cfeditor/gui/ScriptManager.java 2007-05-16 08:26:33 UTC (rev 2501) @@ -19,9 +19,9 @@ package cfeditor.gui; -import cfeditor.CScriptController; -import cfeditor.CScriptModel; -import cfeditor.ScriptControlListener; +import cfeditor.script.CScriptController; +import cfeditor.script.CScriptModel; +import cfeditor.script.ScriptControlListener; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; Copied: trunk/crossfire/src/cfeditor/script/BshThread.java (from rev 2495, trunk/crossfire/src/cfeditor/BshThread.java) =================================================================== --- trunk/crossfire/src/cfeditor/script/BshThread.java (rev 0) +++ trunk/crossfire/src/cfeditor/script/BshThread.java 2007-05-16 08:26:33 UTC (rev 2501) @@ -0,0 +1,96 @@ +/* + * 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.EvalError; +import bsh.Interpreter; + +/** + * A BshThread. + * @todo Document this class. + * @author tchize + */ +public final class BshThread extends Thread { + + /** + * The ScriptModel of this BshThread. + */ + private CScriptModel script; + + /** + * The Interpreter of this BshThread. + */ + private Interpreter interpreter; + + /** + * Create a BshThread. + */ + public BshThread() { + } + + /** + * Create a BshThread with name. + * @param name Name to assign to the BshThread. + */ + public BshThread(final String name) { + super(name); + } + + /** + * Create a BshThread with a name in a certain thread group. + * @param group ThreadGroup to put BshThread in. + * @param name Name to assign to the BshThread. + */ + public BshThread(final ThreadGroup group, final String name) { + super(group, name); + } + + /** + * Sets the interpreter for this BshThread. + * @param interpreter Interpreter for this BshThread. + */ + public void setInterpreter(final Interpreter interpreter) { + this.interpreter = interpreter; + } + + /** + * Sets the ScriptModel for this BshThread. + * @param script ScriptModel for this BshThread. + */ + public void setScript(final CScriptModel script) { + this.script = script; + } + + /** {@inheritDoc} */ + @Override public void run() { + try { + interpreter.set("scriptThread", this); + interpreter.eval(script.getCode()); + } catch (final EvalError e) { + //do something? + interpreter.getErr().print(e.getMessage()); + if (e.getCause() != null) { + interpreter.getErr().print(e.getCause().getMessage()); + } + e.printStackTrace(); + } + } + +} // class BshThread Copied: trunk/crossfire/src/cfeditor/script/CScriptController.java (from rev 2495, trunk/crossfire/src/cfeditor/CScriptController.java) =================================================================== --- trunk/crossfire/src/cfeditor/script/CScriptController.java (rev 0) +++ trunk/crossfire/src/cfeditor/script/CScriptController.java 2007-05-16 08:26:33 UTC (rev 2501) @@ -0,0 +1,418 @@ +/* + * 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.CFilterControl; +import cfeditor.CMainControl; +import cfeditor.CResourceLoader; +import cfeditor.filter.Filter; +import java.io.CharArrayWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.Reader; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import javax.swing.JFileChooser; +import javax.swing.JMenu; +import javax.swing.JOptionPane; +import javax.swing.event.EventListenerList; +import javax.swing.filechooser.FileFilter; +import org.apache.log4j.Logger; +import org.jdom.Document; +import org.jdom.Element; +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. + * @todo documentation + * @author tchize + */ +public final class CScriptController { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(CScriptController.class); + + private final Map<String, CScriptModel> scripts = new LinkedHashMap<String, CScriptModel>(); + + private final CScriptView view; + + /** The MainControlListeners to inform of changes. */ + private final EventListenerList listeners = new EventListenerList(); + + private final CMainControl mainControl; + + private final CResourceLoader scriptRsc; + + public CScriptController(final CMainControl mainControl) { + view = new CScriptView(this); + this.mainControl = mainControl; + scriptRsc = new CResourceLoader("scripts.xml"); + importXML(); + } + + /** + * Set the menu to add script commands to. Entries already present in the + * menu are deleted. + * + * @param menuScripts the plugins menu + */ + public void setMenu(@Nullable final JMenu menuScripts) { + view.setMenu(menuScripts); + } + + public String[] listScript() { + return scripts.keySet().toArray(new String[scripts.keySet().size()]); + } + + /** + * 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(final CScriptModel script) { + if (scripts.containsKey(script.getName())) { + return false; + } + + scripts.put(script.getName(), script); + fireScriptCreatedEvent(script); + return true; + } + + public void removeScript(final CScriptModel script) { + if (!scripts.containsKey(script.getName())) { + throw new IllegalArgumentException(); + } + + scripts.remove(script.getName()); + fireScriptDeletedEvent(script); + } + + public void importXML() { + final Document d = CResourceLoader.getAggregateXML("scripts.xml", true, true, true); + importXML(d, true); + } + + public void importXML(final Reader source, final boolean override) { + final SAXBuilder builder = new SAXBuilder(false);/*non validating*/ + log.debug("Loading...."); + try { + final Document scriptDoc = builder.build(source); + importXML(scriptDoc, override); + } catch (final Exception e) { + } + } + + public void importXML(final Document doc, final boolean override) { + try { + if (!doc.hasRootElement()) { + log.info("No script found."); + return; + } + + final Element elt = doc.getRootElement(); + if ((!elt.getName().equalsIgnoreCase("scripts"))) { + log.warn("Problem reading xml scripts, need a root element named \"scripts\""); + return; + } + final List scriptList = elt.getChildren("script"); + if (scriptList == null || scriptList.isEmpty()) { + log.info("no script found"); + return; + } + for (final Object o : scriptList) { + log.debug("Reading one script"); + final CScriptModel cScript = new CScriptModel(this); + cScript.fromXML((Element) o); + log.debug("script: " + cScript.getName()); + if (override || !scripts.containsKey(cScript.getName())) { + if (log.isDebugEnabled()) { + log.debug("storing with code " + cScript.getCode()); + } + + unRegister(cScript.getName()); + addScript(cScript); + register(cScript.getName()); + } else { + log.debug("not storing"); + } + } + } catch (final Exception e) { + e.printStackTrace(); + } + } + + public void exportScript(final CScriptModel model) { + //show a dialog an propose a filename + final JFileChooser chooser = new JFileChooser(); + final FileFilter f = new FileFilter() { + @Override public boolean accept(final File f) { + return f.getName().endsWith(".xml"); + } + + @Override public String getDescription() { + return "cfeditor script (*.xml)"; + } + }; + chooser.setFileFilter(f); + final int result = chooser.showSaveDialog(null); + if (result == JFileChooser.APPROVE_OPTION) { + final Element root = new Element("scripts"); + final Document d = new Document(root); + root.addContent(model.toXML()); + final XMLOutputter out = new XMLOutputter(); + out.setFormat(Format.getPrettyFormat()); + try { + final FileWriter fw = new FileWriter(chooser.getSelectedFile()); + out.output(d, fw); + } catch (final IOException e) { + e.printStackTrace(); + } + } + } + + public void exportXML() { + try { + exportXML(scriptRsc.getOutputStream()); + } catch (final IOException e) { + JOptionPane.showMessageDialog(mainControl.getMainView(), e.getLocalizedMessage(), "Script Error", JOptionPane.INFORMATION_MESSAGE); + e.printStackTrace(); + } + } + + public void exportXML(final OutputStream destination) { + final Element root = new Element("scripts"); + final Document d = new Document(root); + for (final CScriptModel sm : scripts.values()) { + root.addContent(sm.toXML()); + } + final XMLOutputter out = new XMLOutputter(); + out.setFormat(Format.getPrettyFormat()); + try { + out.output(d, destination); + } catch (final IOException e) { + e.printStackTrace(); + } + } + + public void exportXML(final File destination) { + try { + final OutputStream w = new FileOutputStream(destination); + exportXML(w); + } catch (final Exception e) { + e.printStackTrace(); + //TODO handle using main controller + } + } + + private void setInterpreterValues(final Interpreter i, final String mode) throws EvalError { + i.set("mainControl", mainControl); + i.set("mainView", mainControl.getMainView()); + i.set("archList", mainControl.getArchetypeSet()); + i.set("runMode", mode); + } + + public void autoRunScript(final CScriptModel script) { + final Interpreter runner = new Interpreter(); + try { + setInterpreterValues(runner, "autorun"); + runner.eval(script.getCode()); + } catch (final EvalError e) { + log.warn("Evaluation error on (autorun)" + script.getName(), e); + } + } + + @Nullable public Filter getScriptAsFilter(final CScriptModel script) { + final Interpreter runner = new Interpreter(); + try { + setInterpreterValues(runner, "filter"); + return (Filter) runner.eval(script.getCode()); + } catch (final E... [truncated message content] |
From: <aki...@us...> - 2007-05-16 08:37:47
|
Revision: 2502 http://svn.sourceforge.net/gridarta/?rev=2502&view=rev Author: akirschbaum Date: 2007-05-16 01:37:48 -0700 (Wed, 16 May 2007) Log Message: ----------- Move scripting related classes to cfeditor.gui.script package. Modified Paths: -------------- trunk/crossfire/src/cfeditor/script/CScriptController.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/script/ trunk/crossfire/src/cfeditor/gui/script/CScriptView.java trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java trunk/crossfire/src/cfeditor/gui/script/StackLayout.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/CloseableTabbedPane.java trunk/crossfire/src/cfeditor/gui/ScriptEditor.java trunk/crossfire/src/cfeditor/gui/ScriptManager.java trunk/crossfire/src/cfeditor/gui/StackLayout.java trunk/crossfire/src/cfeditor/script/CScriptView.java Deleted: trunk/crossfire/src/cfeditor/gui/CloseableTabbedPane.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/CloseableTabbedPane.java 2007-05-16 08:26:33 UTC (rev 2501) +++ trunk/crossfire/src/cfeditor/gui/CloseableTabbedPane.java 2007-05-16 08:37:48 UTC (rev 2502) @@ -1,187 +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. - */ - -/* -* Section two. Copy of licensing declaration xnap source code. -* -* Java Napster version x.yz (for current version number as well as for -* additional information see version.txt) -* -* Previous versions of this program were written by Florian Student -* and Michael Ransburg available at www.weblicity.de/jnapster and -* http://www.tux.org/~daneel/content/projects/10.shtml respectively. -* -* -* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -*/ - -package cfeditor.gui; - -import cfeditor.CGUIUtils; -import cfeditor.IGUIConstants; -import java.awt.Component; -import java.awt.Graphics; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.JTabbedPane; - -public class CloseableTabbedPane extends JTabbedPane { - - //--- Data field(s) --- - - protected final ImageIcon closingIcon; - - private static final long serialVersionUID = 1L; - - //--- Constructor(s) --- - - public CloseableTabbedPane(final ImageIcon closingIcon) { - this.closingIcon = closingIcon; - - addMouseListener(new ClosingListener()); - } - - public CloseableTabbedPane() { - this(CGUIUtils.getIcon(IGUIConstants.CLOSE_TAB_SMALLICON)); - } - - //--- Method(s) --- - - public void addTab(final String title, final Component component, final boolean closeable) { - if (closeable) { - super.addTab(title, new ClosingIcon(closingIcon), component); - } else { - super.addTab(title, component); - } - setSelectedComponent(component); - } - - @Override public void addTab(final String title, final Component component) { - addTab(title, component, true); - } - - //--- Inner Class(es) --- - - protected class ClosingListener extends MouseAdapter { - - @Override public void mouseReleased(final MouseEvent e) { - final int i = getSelectedIndex(); - - // nothing selected - if (i == -1) { - return; - } - - final ClosingIcon icon = (ClosingIcon) getIconAt(i); - - // close tab, if icon was clicked - if (icon != null && icon.contains(e.getX(), e.getY())) { - removeTabAt(i); - } - } - - } // class ClosingListener - - /** - * the idea for this class stems from limewire's CancelSearchIconProxy - * class, thanks for going open source guys. - */ - protected static 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 - -} // class CloseableTabbedPane Deleted: trunk/crossfire/src/cfeditor/gui/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ScriptEditor.java 2007-05-16 08:26:33 UTC (rev 2501) +++ trunk/crossfire/src/cfeditor/gui/ScriptEditor.java 2007-05-16 08:37:48 UTC (rev 2502) @@ -1,385 +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; - -import cfeditor.CGUIUtils; -import cfeditor.IGUIConstants; -import cfeditor.script.CScriptModel; -import cfeditor.script.parameter.ParameterDescriptionEditor; -import cfeditor.script.parameter.ParameterNameEditor; -import cfeditor.script.parameter.ParameterTypeEditor; -import cfeditor.script.parameter.PluginParameter; -import cfeditor.script.parameter.PluginParameterView; -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 org.apache.log4j.Logger; - -public class ScriptEditor extends JPanel { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ScriptEditor.class); - - private final JPanel paramTable; - - private final JButton removeParameter; - - private final JTextArea code; - - private final CScriptModel 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; - - private static final long serialVersionUID = 1L; - - /** - * Create a visual JComponent used to edit the given script. - * @param script the script object to edit - */ - public ScriptEditor(final CScriptModel script) { - this.script = script; - final JTabbedPane tabs = new JTabbedPane(); - this.setLayout(new BorderLayout()); - this.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; - JLabel icon; - icon = new JLabel(CGUIUtils.getIcon(IGUIConstants.AUTORUN_SMALLICON)); - optionsTab.add(icon, gbc); - gbc.gridy = 2; - icon = new JLabel(CGUIUtils.getIcon(IGUIConstants.FILTER_SMALLICON)); - optionsTab.add(icon, gbc); - gbc.gridy = 3; - icon = new JLabel(CGUIUtils.getIcon(IGUIConstants.RUN_PLUGIN_SMALLICON)); - optionsTab.add(icon, 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().setBash(typeBash.isSelected()); - } - }); - typeBash.setSelected(script.isBash()); - optionsTab.add(typeBash, gbc); - gbc.gridx = 0; - gbc.gridy = 4; - JButton btn = new JButton("re-register script"); - btn.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)"); - btn.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - getScript().getController().reRegister(getScript().getName()); - } - }); - optionsTab.add(btn, gbc); - tabs.add("Options", optionsTab); - gbc.gridy = 5; - btn = new JButton("Export script..."); - btn.setToolTipText("Export the specified plugin as XML (for distribution)"); - btn.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - getScript().getController().exportScript(getScript()); - } - }); - optionsTab.add(btn, 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(); - } - }); - JScrollPane scrl = new JScrollPane(paramTable); - parameterTab.add(scrl, 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 String name = getScript().getParamName(selectedRow); - 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()); - } - }); - scrl = new JScrollPane(code); - final JPanel codePanel = new JPanel(new BorderLayout()); - codePanel.add(scrl, 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) { - getScript().getController().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); - for (int i = 0; i < script.getParametersCount(); i++) { - if (log.isDebugEnabled()) { - log.debug("Doing " + i + " on " + script.getParametersCount()); - } - - gbc.gridy = i + 1; - putRow(gbc, script.getParameter(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); - } - - ParameterNameEditor o = paramNameEditors.get(param); - if (o != null) { - return o; - } - - o = new ParameterNameEditor(param); - paramNameEditors.put(param, o); - newTableComponent(o); - return o; - } - - private ParameterDescriptionEditor getParameterDescriptionEditor(final PluginParameter param) { - ParameterDescriptionEditor o = paramDescriptionEditors.get(param); - if (o != null) { - return o; - } - - o = new ParameterDescriptionEditor(param); - newTableComponent(o); - paramDescriptionEditors.put(param, o); - return o; - } - - private ParameterTypeEditor getParameterTypeEditor(final PluginParameter param) { - ParameterTypeEditor o = paramTypeEditors.get(param); - if (o != null) { - return o; - } - - o = new ParameterTypeEditor(script, param); - paramTypeEditors.put(param, o); - newTableComponent(o); - return o; - } - - private PluginParameterView getParameterView(final PluginParameter param) { - PluginParameterView o = paramViews.get(param); - if (o != null) { - return o; - } - - o = param.getView(); - if (log.isDebugEnabled()) { - log.debug("param.getValue() is " + param.getValue()); - } - - newTableComponent(o.getConfigComponent(param.getConfig(), param)); - newTableComponent(o.getValueComponent(param.getValue(), param)); - if (log.isDebugEnabled()) { - log.debug("param.getValue() is " + param.getValue()); - } - - paramViews.put(param, o); - return o; - } - - 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 CScriptModel getScript() { - return script; - } - -} // class ScriptEditor Deleted: trunk/crossfire/src/cfeditor/gui/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ScriptManager.java 2007-05-16 08:26:33 UTC (rev 2501) +++ trunk/crossfire/src/cfeditor/gui/ScriptManager.java 2007-05-16 08:37:48 UTC (rev 2502) @@ -1,209 +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; - -import cfeditor.script.CScriptController; -import cfeditor.script.CScriptModel; -import cfeditor.script.ScriptControlListener; -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 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); - //TODO fix a memory leak. If a script is remove, it stays in hashmap along with it's visual component - - private final JList scripts; - - private final JPanel scriptPanel; - - private final CardLayout scriptLayout; - - private final CScriptController ctrl; - - private final Map<CScriptModel, ScriptEditor> components = new HashMap<CScriptModel, ScriptEditor>(); - - private static final long serialVersionUID = 1L; - - /** - * Creates a ScriptManager. - * @param scriptController ScriptController to base this ScriptManager on. - */ - public ScriptManager(final CScriptController scriptController) { - super("Editor plugins management"); - this.ctrl = scriptController; - this.getContentPane().setLayout(new BorderLayout()); - final JPanel left = new JPanel(new BorderLayout()); - scriptLayout = new CardLayout(); - scriptPanel = new JPanel(scriptLayout); - this.getContentPane().add(left, BorderLayout.WEST); - this.getContentPane().add(scriptPanel, BorderLayout.CENTER); - final ListModel mdl = new AbstractListModel() { - private static final long serialVersionUID = 7636033005940159801L; - - /** - * The script control listener to be notified about changes in {@link - * ScriptManager#ctrl}. - */ - private final ScriptControlListener scriptControlListener = new ScriptControlListener() { - - /** {@inheritDoc} */ - public void scriptCreated(@NotNull final CScriptModel script) { - fireContentsChanged(scripts, 0, getController().getScriptCount() + 1); - } - - /** {@inheritDoc} */ - public void scriptDeleted(@NotNull final CScriptModel script) { - fireContentsChanged(scripts, 0, getController().getScriptCount() + 1); - } - - /** {@inheritDoc} */ - public void scriptRegistered(@NotNull final CScriptModel script) { - fireContentsChanged(scripts, 0, getController().getScriptCount() + 1); - } - - }; - - { - getController().addScriptControlListener(scriptControlListener); - } - - @Nullable public Object getElementAt(final int index) { - try { - return ctrl.getScript(index); - } catch (final Exception e) { - return null; - } - } - - public int getSize() { - return ctrl.getScriptCount(); - } - }; - scripts = new JList(mdl); - scripts.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(final ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - showScript((CScriptModel) 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 CScriptModel m = new CScriptModel(ctrl); - m.setName(name); - m.setCode("//input your beanshell Code"); - if (!getController().addScript(m)) { - JOptionPane.showMessageDialog(scripts, "The script " + name + " already exists.", "Error", JOptionPane.WARNING_MESSAGE); - } else { - showScript(m); - } - } - } - }); - final JButton removeScriptBtn = new JButton("Remove"); - removeScriptBtn.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - final CScriptModel m = (CScriptModel) scripts.getSelectedValue(); - if (m == null) { - return; - } - - if (JOptionPane.showConfirmDialog(scripts, "remove script name " + m.getName(), "remove", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - if (log.isDebugEnabled()) { - log.debug("removing"); - } - - getController().removeScript(m); - scripts.setSelectedIndex(0); - removeScript(m); - } - } - }); - final JPanel bottomLeft = new JPanel(new GridLayout(2, 1)); - bottomLeft.add(addScriptBtn); - bottomLeft.add(removeScriptBtn); - left.add(bottomLeft, BorderLayout.SOUTH); - scripts.setSelectedIndex(0); - this.pack(); - this.setVisible(true); - } - - private CScriptController getController() { - return this.ctrl; - } - - private void showScript(final CScriptModel model) { - /* 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 (model == null) { - return; - } - - ScriptEditor c = components.get(model); - if (c == null) { - c = new ScriptEditor(model); - components.put(model, c); - scriptPanel.add(c, Integer.toString(c.hashCode())); - } - scriptLayout.show(scriptPanel, Integer.toString(c.hashCode())); - } - - private void removeScript(final CScriptModel model) { - final ScriptEditor c = components.get(model); - if (c != null) { - components.remove(model); - scriptPanel.remove(c); - } - } - -} // class ScriptManager Deleted: trunk/crossfire/src/cfeditor/gui/StackLayout.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/StackLayout.java 2007-05-16 08:26:33 UTC (rev 2501) +++ trunk/crossfire/src/cfeditor/gui/StackLayout.java 2007-05-16 08:37:48 UTC (rev 2502) @@ -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; - -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/crossfire/src/cfeditor/gui/script/CScriptView.java (from rev 2501, trunk/crossfire/src/cfeditor/script/CScriptView.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/CScriptView.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/CScriptView.java 2007-05-16 08:37:48 UTC (rev 2502) @@ -0,0 +1,270 @@ +/* + * 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.script.CScriptController; +import cfeditor.script.CScriptModel; +import cfeditor.script.ScriptControlListener; +import cfeditor.script.parameter.PluginParameterView; +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +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 javax.swing.filechooser.FileFilter; +import net.sf.gridarta.Menu; +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 CScriptView { + + /** 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(CScriptView.class); + + private final CScriptController control; + + /** + * The menu to add script commands to. + */ + @Nullable private JMenu menuScripts = null; + + private JFrame console = null; + + private CloseableTabbedPane consolePane = null; + + private JFrame scriptManager = null; + + /** + * The script control listener to be notified about changes in {@link + * #control}. + */ + private final ScriptControlListener scriptControlListener = new ScriptControlListener() { + + /** {@inheritDoc} */ + public void scriptCreated(@NotNull final CScriptModel script) { + updateMenuEntries(); + } + + /** {@inheritDoc} */ + public void scriptDeleted(@NotNull final CScriptModel script) { + updateMenuEntries(); + } + + /** {@inheritDoc} */ + public void scriptRegistered(@NotNull final CScriptModel script) { + updateMenuEntries(); + } + + }; + + /** + * Creates a ScriptView. + * @param control controller of this ScriptView + * @warning Creating a view from a controller instead of a model is error prone. + */ + public CScriptView(final CScriptController control) { + this.control = control; + + control.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; + } + + Menu.removeAllToSeparator(menuScripts); + + final String[] scripts = control.listScript(); + int index = 0; + for (final String script : scripts) { + if (!control.getScript(script).isBash()) { + continue; + } + + final Action action = ACTION_FACTORY.createAction(true, "runPlugin", this); + action.putValue(ReflectionAction.REFLECTION_ARGUMENTS, new Object[] { script, }); + action.putValue(Action.NAME, ACTION_FACTORY.format("runPlugin.text", script)); + final JMenuItem item = new JMenuItem(action); + item.setActionCommand(script); + 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) { + control.runScript(script); + } + + public synchronized void editPlugins() { + if (scriptManager == null) { + scriptManager = new ScriptManager(control); + } + + scriptManager.pack(); + scriptManager.setVisible(true); + } + + public void savePlugins() { + control.exportXML(); + } + + public void exportPluginAs() { + final JFileChooser choose = new JFileChooser(); + final FileFilter filter = new FileFilter() { + @Override public boolean accept(final File f) { + return f.isFile() && f.getName().endsWith(".xml"); + } + + @Override public String getDescription() { + return "XML script collection (*.xml)"; + } + }; + choose.setFileFilter(filter); + if (choose.showSaveDialog(control.getMainControl().getMainView()) == JFileChooser.APPROVE_OPTION) { + final File f = choose.getSelectedFile(); + control.exportXML(f); + } + } + + public void importPlugin() { + final JFileChooser choose = new JFileChooser(); + final FileFilter filter = new FileFilter() { + @Override public boolean accept(final File f) { + return f.isFile() && f.getName().endsWith(".xml") && f.exists() && f.canWrite(); + } + + @Override public String getDescription() { + return "XML script collection (*.xml)"; + } + }; + choose.setFileFilter(filter); + if (choose.showOpenDialog(control.getMainControl().getMainView()) == JFileChooser.APPROVE_OPTION) { + final File f = choose.getSelectedFile(); + try { + control.importXML(new FileReader(f), true); + } catch (final FileNotFoundException ex) { + } + } + } + + 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.addTab(name, bshConsole, true); + return bshConsole; + } + + public boolean getRunValues(final CScriptModel model) { + //JDialog d = new JDialog(control.getMainControl().getMainView(), true); + if (model.getParametersCount() < 1) { + return true; + } + + final JOptionPane p = new JOptionPane(); + p.setOptionType(JOptionPane.OK_CANCEL_OPTION); + p.setMessageType(JOptionPane.QUESTION_MESSAGE); + p.setMessage("Please provide runtime parameters for " + model.getName()); + final GridBagLayout layout = new GridBagLayout(); + final JPanel panel = new JPanel(layout); + final JDialog dialog = p.createDialog(control.getMainControl().getMainView(), "hi"); + dialog.setModal(true); + dialog.setTitle(model.getName()); + dialog.getContentPane().removeAll(); + //JTextField[] fields = new JTextField[model.getParametersCount()]; + for (int i = 0; i < model.getParametersCount(); i++) { + log.debug("adding parameter"); + final JLabel name = new JLabel(model.getParamName(i)); + final PluginParameterView view = model.getParameter(i).getView(); + final JComponent val = view.getValueComponent(model.getParamValue(i), model.getParameter(i)); + val.setToolTipText(model.getParamDescription(i)); + 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); + } + + 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 CScriptView Copied: trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java (from rev 2495, trunk/crossfire/src/cfeditor/gui/CloseableTabbedPane.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java 2007-05-16 08:37:48 UTC (rev 2502) @@ -0,0 +1,187 @@ +/* + * 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. + */ + +/* +* Section two. Copy of licensing declaration xnap source code. +* +* Java Napster version x.yz (for current version number as well as for +* additional information see version.txt) +* +* Previous versions of this program were written by Florian Student +* and Michael Ransburg available at www.weblicity.de/jnapster and +* http://www.tux.org/~daneel/content/projects/10.shtml respectively. +* +* +* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +*/ + +package cfeditor.gui.script; + +import cfeditor.CGUIUtils; +import cfeditor.IGUIConstants; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JTabbedPane; + +public class CloseableTabbedPane extends JTabbedPane { + + //--- Data field(s) --- + + protected final ImageIcon closingIcon; + + private static final long serialVersionUID = 1L; + + //--- Constructor(s) --- + + public CloseableTabbedPane(final ImageIcon closingIcon) { + this.closingIcon = closingIcon; + + addMouseListener(new ClosingListener()); + } + + public CloseableTabbedPane() { + this(CGUIUtils.getIcon(IGUIConstants.CLOSE_TAB_SMALLICON)); + } + + //--- Method(s) --- + + public void addTab(final String title, final Component component, final boolean closeable) { + if (closeable) { + super.addTab(title, new ClosingIcon(closingIcon), component); + } else { + super.addTab(title, component); + } + setSelectedComponent(component); + } + + @Override public void addTab(final String title, final Component component) { + addTab(title, component, true); + } + + //--- Inner Class(es) --- + + protected class ClosingListener extends MouseAdapter { + + @Override public void mouseReleased(final MouseEvent e) { + final int i = getSelectedIndex(); + + // nothing selected + if (i == -1) { + return; + } + + final ClosingIcon icon = (ClosingIcon) getIconAt(i); + + // close tab, if icon was clicked + if (icon != null && icon.contains(e.getX(), e.getY())) { + removeTabAt(i); + } + } + + } // class ClosingListener + + /** + * the idea for this class stems from limewire's CancelSearchIconProxy + * class, thanks for going open source guys. + */ + protected static 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 + +} // class CloseableTabbedPane Copied: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java (from rev 2501, trunk/crossfire/src/cfeditor/gui/ScriptEditor.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2007-05-16 08:37:48 UTC (rev 2502) @@ -0,0 +1,385 @@ +/* + * 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.CGUIUtils; +import cfeditor.IGUIConstants; +import cfeditor.script.CScriptModel; +import cfeditor.script.parameter.ParameterDescriptionEditor; +import cfeditor.script.parameter.ParameterNameEditor; +import cfeditor.script.parameter.ParameterTypeEditor; +import cfeditor.script.parameter.PluginParameter; +import cfeditor.script.parameter.PluginParameterView; +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 org.apache.log4j.Logger; + +public class ScriptEditor extends JPanel { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(ScriptEditor.class); + + private final JPanel paramTable; + + private final JButton removeParameter; + + private final JTextArea code; + + private final CScriptModel 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; + + private static final long serialVersionUID = 1L; + + /** + * Create a visual JComponent used to edit the given script. + * @param script the script object to edit + */ + public ScriptEditor(final CScriptModel script) { + this.script = script; + final JTabbedPane tabs = new JTabbedPane(); + this.setLayout(new BorderLayout()); + this.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; + JLabel icon; + icon = new JLabel(CGUIUtils.getIcon(IGUIConstants.AUTORUN_SMALLICON)); + optionsTab.add(icon, gbc); + gbc.gridy = 2; + icon = new JLabel(CGUIUtils.getIcon(IGUIConstants.FILTER_SMALLICON)); + optionsTab.add(icon, gbc); + gbc.gridy = 3; + icon = new JLabel(CGUIUtils.getIcon(IGUIConstants.RUN_PLUGIN_SMALLICON)); + optionsTab.add(icon, 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().setBash(typeBash.isSelected()); + } + }); + typeBash.setSelected(script.isBash()); + optionsTab.add(typeBash, gbc); + gbc.gridx = 0; + gbc.gridy = 4; + JButton btn = new JButton("re-register script"); + btn.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)"); + btn.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + getScript().getController().reRegister(getScript().getName()); + } + }); + optionsTab.add(btn, gbc); + tabs.add("Options", optionsTab); + gbc.gridy = 5; + btn = new JButton("Export script..."); + btn.setToolTipText("Export the specified plugin as XML (for distribution)"); + btn.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + getScript().getController().exportScript(getScript()); + } + }); + optionsTab.add(btn, 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(); + } + }); + JScrollPane scrl = new JScrollPane(paramTable); + parameterTab.add(s... [truncated message content] |
From: <aki...@us...> - 2007-05-16 08:55:38
|
Revision: 2503 http://svn.sourceforge.net/gridarta/?rev=2503&view=rev Author: akirschbaum Date: 2007-05-16 01:55:39 -0700 (Wed, 16 May 2007) Log Message: ----------- Move scripting parameter related classes to cfeditor.gui.script.parameter package. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/CScriptView.java trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java trunk/crossfire/src/cfeditor/script/parameter/ArchParameter.java trunk/crossfire/src/cfeditor/script/parameter/BooleanParameter.java trunk/crossfire/src/cfeditor/script/parameter/DoubleParameter.java trunk/crossfire/src/cfeditor/script/parameter/FilterParameter.java trunk/crossfire/src/cfeditor/script/parameter/IntegerParameter.java trunk/crossfire/src/cfeditor/script/parameter/MapParameter.java trunk/crossfire/src/cfeditor/script/parameter/PluginParameter.java trunk/crossfire/src/cfeditor/script/parameter/StringParameter.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/script/parameter/ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.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/ParameterDescriptionEditor.java trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterNameEditor.java trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterTypeEditor.java trunk/crossfire/src/cfeditor/gui/script/parameter/PluginParameterView.java trunk/crossfire/src/cfeditor/gui/script/parameter/StringParameterView.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/ArchComboBox.java trunk/crossfire/src/cfeditor/script/parameter/ArchParameterView.java trunk/crossfire/src/cfeditor/script/parameter/BooleanParameterView.java trunk/crossfire/src/cfeditor/script/parameter/DoubleParameterView.java trunk/crossfire/src/cfeditor/script/parameter/FilterParameterView.java trunk/crossfire/src/cfeditor/script/parameter/IntegerParameterView.java trunk/crossfire/src/cfeditor/script/parameter/MapParameterView.java trunk/crossfire/src/cfeditor/script/parameter/ParameterDescriptionEditor.java trunk/crossfire/src/cfeditor/script/parameter/ParameterNameEditor.java trunk/crossfire/src/cfeditor/script/parameter/ParameterTypeEditor.java trunk/crossfire/src/cfeditor/script/parameter/PluginParameterView.java trunk/crossfire/src/cfeditor/script/parameter/StringParameterView.java Deleted: trunk/crossfire/src/cfeditor/gui/ArchComboBox.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ArchComboBox.java 2007-05-16 08:37:48 UTC (rev 2502) +++ trunk/crossfire/src/cfeditor/gui/ArchComboBox.java 2007-05-16 08:55:39 UTC (rev 2503) @@ -1,412 +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; - -import cfeditor.CMainControl; -import cfeditor.gameobject.Archetype; -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 java.util.Arrays; -import java.util.Comparator; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxEditor; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultListCellRenderer; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JList; -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 org.apache.log4j.Logger; -import org.jetbrains.annotations.Nullable; - -public class ArchComboBox extends JComboBox { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ArchComboBox.class); - - private final CMainControl mainControl; - - private final ArchComboBoxEditor editor; - - private final ArchComboBoxModel archComboBoxModel; - - private static final long serialVersionUID = 1L; - - public ArchComboBox() { - setMaximumRowCount(4); - mainControl = CMainControl.getInstance(); - final MyCellRenderer renderer = new MyCellRenderer(); - editor = new ArchComboBoxEditor(); - //setPrototypeDisplayValue(renderer.sizeTester); - setRenderer(renderer); - archComboBoxModel = new ArchComboBoxModel(); - setModel(archComboBoxModel); - setEditable(true); - setEditor(editor); - final Dimension d = getPreferredSize(); - if (log.isDebugEnabled()) { - log.debug("Preferred size: " + d); - } - setPreferredSize(new Dimension(d.width, editor.getEditorComponent().getPreferredSize().height)); - if (log.isDebugEnabled()) { - log.debug("NEW Preferred size: " + getPreferredSize()); - } - } - - private void editorEntryChange() { - editor.lockEditor(); - final Archetype nearestMatch = archComboBoxModel.getNearsetMatch(editor.editor.getText()); - setSelectedItem(nearestMatch); - editor.setItem(nearestMatch); - editor.unlockEditor(); - } - - public class ArchComboBoxEditor implements ComboBoxEditor { - - private JPanel editorPanel = null; - - private JLabel icon = null; - - private JTextField editor = null; - - private JPopupMenu popup; - - private boolean locked = false; - - 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(mainControl.getObjectChooserHighlight().getArchetypeName()); - 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(mainControl.getMainView().getGameObjectAttributesPanel().getSelectedGameObject().getArchetypeName()); - 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+editor.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) { - editorEntryChange(); - } - - public void insertUpdate(final DocumentEvent e) { - editorEntryChange(); - } - - public void removeUpdate(final DocumentEvent e) { - 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); - 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(mainControl.getArchetypeSet().getFace(arch)); - } - - if (arch == null) { - icon.setText(""); - if (!locked) { - editor.setText(""); - } - } else { - if (!locked) { - editor.setText(arch.getArchetypeName()); - } - icon.setText(arch.getArchetypeName()); - } - } - - } // class ArchComboBoxEditor - - 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() { - archList = mainControl.getArchetypeSet().getArchList(); - 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 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" - } - - private 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().toLowerCase(); - } else { - s1 = o1.toString().toLowerCase(); - } - final String s2; - if (o2 instanceof Archetype) { - s2 = ((Archetype) o2).getArchetypeName().toLowerCase(); - } else { - s2 = o2.toString().toLowerCase(); - } - return s1.compareTo(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 - - private class MyCellRenderer extends DefaultListCellRenderer { - - public static final String SIZE_TESTER = "**Sizetester**"; - - private static final long serialVersionUID = 1L; - - /* 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 editor.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(mainControl.getArchetypeSet().getFace(arch)); - - return this; - } - - } // class MyCellRenderer - -} // class ArchComboBox Modified: trunk/crossfire/src/cfeditor/gui/script/CScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/CScriptView.java 2007-05-16 08:37:48 UTC (rev 2502) +++ trunk/crossfire/src/cfeditor/gui/script/CScriptView.java 2007-05-16 08:55:39 UTC (rev 2503) @@ -21,10 +21,10 @@ import bsh.ConsoleInterface; import bsh.util.JConsole; +import cfeditor.gui.script.parameter.PluginParameterView; import cfeditor.script.CScriptController; import cfeditor.script.CScriptModel; import cfeditor.script.ScriptControlListener; -import cfeditor.script.parameter.PluginParameterView; import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2007-05-16 08:37:48 UTC (rev 2502) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2007-05-16 08:55:39 UTC (rev 2503) @@ -21,12 +21,12 @@ import cfeditor.CGUIUtils; import cfeditor.IGUIConstants; +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.script.CScriptModel; -import cfeditor.script.parameter.ParameterDescriptionEditor; -import cfeditor.script.parameter.ParameterNameEditor; -import cfeditor.script.parameter.ParameterTypeEditor; import cfeditor.script.parameter.PluginParameter; -import cfeditor.script.parameter.PluginParameterView; import java.awt.BorderLayout; import java.awt.Component; import java.awt.FlowLayout; Copied: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java (from rev 2495, trunk/crossfire/src/cfeditor/gui/ArchComboBox.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java 2007-05-16 08:55:39 UTC (rev 2503) @@ -0,0 +1,412 @@ +/* + * 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.CMainControl; +import cfeditor.gameobject.Archetype; +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 java.util.Arrays; +import java.util.Comparator; +import javax.swing.AbstractListModel; +import javax.swing.ComboBoxEditor; +import javax.swing.ComboBoxModel; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JList; +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 org.apache.log4j.Logger; +import org.jetbrains.annotations.Nullable; + +public class ArchComboBox extends JComboBox { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(ArchComboBox.class); + + private final CMainControl mainControl; + + private final ArchComboBoxEditor editor; + + private final ArchComboBoxModel archComboBoxModel; + + private static final long serialVersionUID = 1L; + + public ArchComboBox() { + setMaximumRowCount(4); + mainControl = CMainControl.getInstance(); + final MyCellRenderer renderer = new MyCellRenderer(); + editor = new ArchComboBoxEditor(); + //setPrototypeDisplayValue(renderer.sizeTester); + setRenderer(renderer); + archComboBoxModel = new ArchComboBoxModel(); + setModel(archComboBoxModel); + setEditable(true); + setEditor(editor); + final Dimension d = getPreferredSize(); + if (log.isDebugEnabled()) { + log.debug("Preferred size: " + d); + } + setPreferredSize(new Dimension(d.width, editor.getEditorComponent().getPreferredSize().height)); + if (log.isDebugEnabled()) { + log.debug("NEW Preferred size: " + getPreferredSize()); + } + } + + private void editorEntryChange() { + editor.lockEditor(); + final Archetype nearestMatch = archComboBoxModel.getNearsetMatch(editor.editor.getText()); + setSelectedItem(nearestMatch); + editor.setItem(nearestMatch); + editor.unlockEditor(); + } + + public class ArchComboBoxEditor implements ComboBoxEditor { + + private JPanel editorPanel = null; + + private JLabel icon = null; + + private JTextField editor = null; + + private JPopupMenu popup; + + private boolean locked = false; + + 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(mainControl.getObjectChooserHighlight().getArchetypeName()); + 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(mainControl.getMainView().getGameObjectAttributesPanel().getSelectedGameObject().getArchetypeName()); + 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+editor.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) { + editorEntryChange(); + } + + public void insertUpdate(final DocumentEvent e) { + editorEntryChange(); + } + + public void removeUpdate(final DocumentEvent e) { + 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); + 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(mainControl.getArchetypeSet().getFace(arch)); + } + + if (arch == null) { + icon.setText(""); + if (!locked) { + editor.setText(""); + } + } else { + if (!locked) { + editor.setText(arch.getArchetypeName()); + } + icon.setText(arch.getArchetypeName()); + } + } + + } // class ArchComboBoxEditor + + 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() { + archList = mainControl.getArchetypeSet().getArchList(); + 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 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" + } + + private 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().toLowerCase(); + } else { + s1 = o1.toString().toLowerCase(); + } + final String s2; + if (o2 instanceof Archetype) { + s2 = ((Archetype) o2).getArchetypeName().toLowerCase(); + } else { + s2 = o2.toString().toLowerCase(); + } + return s1.compareTo(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 + + private class MyCellRenderer extends DefaultListCellRenderer { + + public static final String SIZE_TESTER = "**Sizetester**"; + + private static final long serialVersionUID = 1L; + + /* 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 editor.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(mainControl.getArchetypeSet().getFace(arch)); + + return this; + } + + } // class MyCellRenderer + +} // class ArchComboBox Copied: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java (from rev 2501, trunk/crossfire/src/cfeditor/script/parameter/ArchParameterView.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchParameterView.java 2007-05-16 08:55:39 UTC (rev 2503) @@ -0,0 +1,57 @@ +/* + * 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.script.parameter.ArchParameter; +import cfeditor.script.parameter.PluginParameter; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import javax.swing.JComponent; +import javax.swing.JPanel; + +public class ArchParameterView implements PluginParameterView { + + private final JPanel config = new JPanel(); + + private final ArchComboBox value = new ArchComboBox(); + + private final ArchParameter parameter; + + public JComponent getConfigComponent(final Object config, final PluginParameter parameter) { + return this.config; + } + + public JComponent getValueComponent(final Object value, final PluginParameter parameter) { + return this.value; + } + + public ArchParameterView(final ArchParameter param) { + parameter = param; + value.setSelectedItem(param.getValue()); + value.addItemListener(new ItemListener() { + public void itemStateChanged(final ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + parameter.setValue(value.getSelectedItem()); + } + } + }); + } + +} // class ArchParameterView Copied: trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java (from rev 2501, trunk/crossfire/src/cfeditor/script/parameter/BooleanParameterView.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/BooleanParameterView.java 2007-05-16 08:55:39 UTC (rev 2503) @@ -0,0 +1,76 @@ +/* + * 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.script.parameter.BooleanParameter; +import cfeditor.script.parameter.PluginParameter; +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; + +public class BooleanParameterView implements PluginParameterView, ActionListener { + + private final JCheckBox value; + + private final JButton config; + + private final BooleanParameter parameter; + + public JComponent getConfigComponent(final Object config, final PluginParameter parameter) { + return this.config; + } + + public JComponent getValueComponent(final Object value, final PluginParameter parameter) { + return this.value; + } + + public BooleanParameterView(final BooleanParameter param) { + this.parameter = param; + value = new JCheckBox(); + value.setActionCommand("toggle"); + value.addActionListener(this); + config = new JButton("..."); + config.setBorderPainted(false); + config.setActionCommand("config"); + config.addActionListener(this); + } + + 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 Copied: trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java (from rev 2501, trunk/crossfire/src/cfeditor/script/parameter/DoubleParameterView.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/DoubleParameterView.java 2007-05-16 08:55:39 UTC (rev 2503) @@ -0,0 +1,150 @@ +/* + * 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.script.parameter.DoubleParameter; +import cfeditor.script.parameter.PluginParameter; +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 org.apache.log4j.Logger; + +public class DoubleParameterView implements PluginParameterView, 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 JComponent getConfigComponent(final Object config, final PluginParameter parameter) { + return this.config; + } + + public JComponent getValueComponent(final Object value, final PluginParameter parameter) { + return this.value; + } + + public DoubleParameterView(final DoubleParameter param) { + this.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 Exception e) { + } + value.addChangeListener(new ChangeListener() { + public void stateChanged(final ChangeEvent e) { + try { + parameter.setValue(((SpinnerNumberModel) value.getModel()).getNumber()); + } catch (final Exception ex) { + ex.printStackTrace(); + } + } + }); + config = new JButton("..."); + config.setBorderPainted(false); + config.setActionCommand("Config"); + config.addActionListener(this); + updateTooltip(); + } + + 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() { + } + + 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 Copied: trunk/crossfire/src/cfeditor/gui/script/parameter/FilterParameterView.java (from rev 2501, trunk/crossfire/src/cfeditor/script/parameter/FilterParameterView.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/FilterParameterView.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/FilterParameterView.java 2007-05-16 08:55:39 UTC (rev 2503) @@ -0,0 +1,47 @@ +/* + * 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.filter.FilterConfig; +import cfeditor.filter.NamedFilterList; +import cfeditor.script.parameter.PluginParameter; +import javax.swing.JComponent; +import javax.swing.JMenuItem; +import javax.swing.JPanel; + +public class FilterParameterView implements PluginParameterView { + + /* (non-Javadoc) + * @see cfeditor.PluginParameterView#getValueComponent(java.lang.Object, cfeditor.PluginParameter) + */ + public JComponent getValueComponent(final Object value, final PluginParameter parameter) { + final JMenuItem mu = NamedFilterList.getDefaultList().createMenuEntry((FilterConfig) parameter.getValue()); + mu.setName("Choose filters"); + return mu; // XXX: was mu.getToolbarComponent() with cfeditor.menu.BasicMenuEntry mu + } + + /* (non-Javadoc) + * @see cfeditor.PluginParameterView#getConfigComponent(java.lang.Object, cfeditor.PluginParameter) + */ + public JComponent getConfigComponent(final Object config, final PluginParameter parameter) { + return new JPanel(); + } + +} // class FilterParameterView Copied: trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java (from rev 2501, trunk/crossfire/src/cfeditor/script/parameter/IntegerParameterView.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/IntegerParameterView.java 2007-05-16 08:55:39 UTC (rev 2503) @@ -0,0 +1,146 @@ +/* + * 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.script.parameter.IntegerParameter; +import cfeditor.script.parameter.PluginParameter; +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 org.apache.log4j.Logger; + +public class IntegerParameterView implements PluginParameterView, 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 JComponent getConfigComponent(final Object config, final PluginParameter parameter) { + return this.config; + } + + public JComponent getValueComponent(final Object value, final PluginParameter parameter) { + return this.value; + } + + public IntegerParameterView(final IntegerParameter param) { + this.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(((SpinnerNumberModel) value.getModel()).getNumber()); + } catch (final Exception ex) { + ex.printStackTrace(); + } + } + }); + config = new JButton("..."); + config.setBorderPainted(false); + config.setActionCommand("Config"); + config.addActionListener(this); + updateTooltip(); + } + + 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() { + } + + 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 Copied: trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java (from rev 2501, trunk/crossfire/src/cfeditor/script/parameter/MapParameterView.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2007-05-16 08:55:39 UTC (rev 2503) @@ -0,0 +1,150 @@ +/* + * 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.CMainControl; +import cfeditor.map.MapControl; +import cfeditor.script.parameter.MapParameter; +import cfeditor.script.parameter.PluginParameter; +import java.awt.Component; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JList; +import javax.swing.JPanel; +import org.apache.log4j.Logger; + +public class MapParameterView implements PluginParameterView { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(MapParameterView.class); + + private final MapParameter parameter; + + private final JPanel config = new JPanel(); + + private final JComboBox value; + + public MapParameterView(final MapParameter param) { + this.parameter = param; + value = new JComboBox(); + final MyComboBoxModel myModel = new MyComboBoxModel(); + value.setModel(myModel); + if (log.isDebugEnabled()) { + log.debug("opened maps: " + CMainControl.getInstance().getMapManager().getOpenedMaps() + " len: " + CMainControl.getInstance().getMapManager().getOpenedMaps().length); + } + value.setRenderer(new MyCellRenderer()); + 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 PluginParameter parameter) { + return this.value; + } + + /* (non-Javadoc) + * @see cfeditor.PluginParameterView#getConfigComponent(java.lang.Object, cfeditor.PluginParameter) + */ + public JComponent getConfigComponent(final Object config, final PluginParameter parameter) { + return this.config; + } + + public static class MyCellRenderer extends DefaultListCellRenderer { + + private static final long serialVersionUID = 1L; + + @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 = ""; + if (CMainControl.get... [truncated message content] |
From: <aki...@us...> - 2007-05-16 09:05:25
|
Revision: 2504 http://svn.sourceforge.net/gridarta/?rev=2504&view=rev Author: akirschbaum Date: 2007-05-16 02:05:26 -0700 (Wed, 16 May 2007) Log Message: ----------- Remove 'C' prefix from class names. 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/parameter/ParameterTypeEditor.java trunk/crossfire/src/cfeditor/script/BshThread.java trunk/crossfire/src/cfeditor/script/ScriptControlListener.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java trunk/crossfire/src/cfeditor/script/ScriptController.java trunk/crossfire/src/cfeditor/script/ScriptModel.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gui/script/CScriptView.java trunk/crossfire/src/cfeditor/script/CScriptController.java trunk/crossfire/src/cfeditor/script/CScriptModel.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-16 08:55:39 UTC (rev 2503) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -34,7 +34,7 @@ import cfeditor.gui.prefs.ResPrefs; import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; -import cfeditor.script.CScriptController; +import cfeditor.script.ScriptController; import java.awt.Point; import java.io.File; import java.io.IOException; @@ -157,7 +157,7 @@ private final ArchetypeSet archetypeSet; /** The current script controller. */ - private final CScriptController scriptControl; + private final ScriptController scriptControl; /** The current main directory. */ private File currentDir; @@ -220,7 +220,7 @@ PathManager.setMainControl(this); instance = this; archetypeSet = new ArchetypeSet(this); - scriptControl = new CScriptController(this); + scriptControl = new ScriptController(this); mapCursorControl = new MapCursorControl(this); mainView = new CMainView(); undoControl = new UndoControl(this); @@ -935,7 +935,7 @@ return CFilterControl.getDefaultFilter(); } - public CScriptController getScriptController() { + public ScriptController getScriptController() { return scriptControl; } Deleted: trunk/crossfire/src/cfeditor/gui/script/CScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/CScriptView.java 2007-05-16 08:55:39 UTC (rev 2503) +++ trunk/crossfire/src/cfeditor/gui/script/CScriptView.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -1,270 +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.gui.script.parameter.PluginParameterView; -import cfeditor.script.CScriptController; -import cfeditor.script.CScriptModel; -import cfeditor.script.ScriptControlListener; -import java.awt.BorderLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -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 javax.swing.filechooser.FileFilter; -import net.sf.gridarta.Menu; -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 CScriptView { - - /** 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(CScriptView.class); - - private final CScriptController control; - - /** - * The menu to add script commands to. - */ - @Nullable private JMenu menuScripts = null; - - private JFrame console = null; - - private CloseableTabbedPane consolePane = null; - - private JFrame scriptManager = null; - - /** - * The script control listener to be notified about changes in {@link - * #control}. - */ - private final ScriptControlListener scriptControlListener = new ScriptControlListener() { - - /** {@inheritDoc} */ - public void scriptCreated(@NotNull final CScriptModel script) { - updateMenuEntries(); - } - - /** {@inheritDoc} */ - public void scriptDeleted(@NotNull final CScriptModel script) { - updateMenuEntries(); - } - - /** {@inheritDoc} */ - public void scriptRegistered(@NotNull final CScriptModel script) { - updateMenuEntries(); - } - - }; - - /** - * Creates a ScriptView. - * @param control controller of this ScriptView - * @warning Creating a view from a controller instead of a model is error prone. - */ - public CScriptView(final CScriptController control) { - this.control = control; - - control.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; - } - - Menu.removeAllToSeparator(menuScripts); - - final String[] scripts = control.listScript(); - int index = 0; - for (final String script : scripts) { - if (!control.getScript(script).isBash()) { - continue; - } - - final Action action = ACTION_FACTORY.createAction(true, "runPlugin", this); - action.putValue(ReflectionAction.REFLECTION_ARGUMENTS, new Object[] { script, }); - action.putValue(Action.NAME, ACTION_FACTORY.format("runPlugin.text", script)); - final JMenuItem item = new JMenuItem(action); - item.setActionCommand(script); - 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) { - control.runScript(script); - } - - public synchronized void editPlugins() { - if (scriptManager == null) { - scriptManager = new ScriptManager(control); - } - - scriptManager.pack(); - scriptManager.setVisible(true); - } - - public void savePlugins() { - control.exportXML(); - } - - public void exportPluginAs() { - final JFileChooser choose = new JFileChooser(); - final FileFilter filter = new FileFilter() { - @Override public boolean accept(final File f) { - return f.isFile() && f.getName().endsWith(".xml"); - } - - @Override public String getDescription() { - return "XML script collection (*.xml)"; - } - }; - choose.setFileFilter(filter); - if (choose.showSaveDialog(control.getMainControl().getMainView()) == JFileChooser.APPROVE_OPTION) { - final File f = choose.getSelectedFile(); - control.exportXML(f); - } - } - - public void importPlugin() { - final JFileChooser choose = new JFileChooser(); - final FileFilter filter = new FileFilter() { - @Override public boolean accept(final File f) { - return f.isFile() && f.getName().endsWith(".xml") && f.exists() && f.canWrite(); - } - - @Override public String getDescription() { - return "XML script collection (*.xml)"; - } - }; - choose.setFileFilter(filter); - if (choose.showOpenDialog(control.getMainControl().getMainView()) == JFileChooser.APPROVE_OPTION) { - final File f = choose.getSelectedFile(); - try { - control.importXML(new FileReader(f), true); - } catch (final FileNotFoundException ex) { - } - } - } - - 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.addTab(name, bshConsole, true); - return bshConsole; - } - - public boolean getRunValues(final CScriptModel model) { - //JDialog d = new JDialog(control.getMainControl().getMainView(), true); - if (model.getParametersCount() < 1) { - return true; - } - - final JOptionPane p = new JOptionPane(); - p.setOptionType(JOptionPane.OK_CANCEL_OPTION); - p.setMessageType(JOptionPane.QUESTION_MESSAGE); - p.setMessage("Please provide runtime parameters for " + model.getName()); - final GridBagLayout layout = new GridBagLayout(); - final JPanel panel = new JPanel(layout); - final JDialog dialog = p.createDialog(control.getMainControl().getMainView(), "hi"); - dialog.setModal(true); - dialog.setTitle(model.getName()); - dialog.getContentPane().removeAll(); - //JTextField[] fields = new JTextField[model.getParametersCount()]; - for (int i = 0; i < model.getParametersCount(); i++) { - log.debug("adding parameter"); - final JLabel name = new JLabel(model.getParamName(i)); - final PluginParameterView view = model.getParameter(i).getView(); - final JComponent val = view.getValueComponent(model.getParamValue(i), model.getParameter(i)); - val.setToolTipText(model.getParamDescription(i)); - 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); - } - - 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 CScriptView Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2007-05-16 08:55:39 UTC (rev 2503) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -25,7 +25,7 @@ import cfeditor.gui.script.parameter.ParameterNameEditor; import cfeditor.gui.script.parameter.ParameterTypeEditor; import cfeditor.gui.script.parameter.PluginParameterView; -import cfeditor.script.CScriptModel; +import cfeditor.script.ScriptModel; import cfeditor.script.parameter.PluginParameter; import java.awt.BorderLayout; import java.awt.Component; @@ -68,7 +68,7 @@ private final JTextArea code; - private final CScriptModel script; + private final ScriptModel script; private final Map<PluginParameter, ParameterNameEditor> paramNameEditors = new HashMap<PluginParameter, ParameterNameEditor>(); @@ -121,7 +121,7 @@ * Create a visual JComponent used to edit the given script. * @param script the script object to edit */ - public ScriptEditor(final CScriptModel script) { + public ScriptEditor(final ScriptModel script) { this.script = script; final JTabbedPane tabs = new JTabbedPane(); this.setLayout(new BorderLayout()); @@ -378,7 +378,7 @@ paramTable.add(getParameterView(param).getValueComponent(param.getValue(), param), gbc); } - private CScriptModel getScript() { + private ScriptModel getScript() { return script; } Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2007-05-16 08:55:39 UTC (rev 2503) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -19,8 +19,8 @@ package cfeditor.gui.script; -import cfeditor.script.CScriptController; -import cfeditor.script.CScriptModel; +import cfeditor.script.ScriptController; +import cfeditor.script.ScriptModel; import cfeditor.script.ScriptControlListener; import java.awt.BorderLayout; import java.awt.CardLayout; @@ -57,9 +57,9 @@ private final CardLayout scriptLayout; - private final CScriptController ctrl; + private final ScriptController ctrl; - private final Map<CScriptModel, ScriptEditor> components = new HashMap<CScriptModel, ScriptEditor>(); + private final Map<ScriptModel, ScriptEditor> components = new HashMap<ScriptModel, ScriptEditor>(); private static final long serialVersionUID = 1L; @@ -67,7 +67,7 @@ * Creates a ScriptManager. * @param scriptController ScriptController to base this ScriptManager on. */ - public ScriptManager(final CScriptController scriptController) { + public ScriptManager(final ScriptController scriptController) { super("Editor plugins management"); this.ctrl = scriptController; this.getContentPane().setLayout(new BorderLayout()); @@ -86,17 +86,17 @@ private final ScriptControlListener scriptControlListener = new ScriptControlListener() { /** {@inheritDoc} */ - public void scriptCreated(@NotNull final CScriptModel script) { + public void scriptCreated(@NotNull final ScriptModel script) { fireContentsChanged(scripts, 0, getController().getScriptCount() + 1); } /** {@inheritDoc} */ - public void scriptDeleted(@NotNull final CScriptModel script) { + public void scriptDeleted(@NotNull final ScriptModel script) { fireContentsChanged(scripts, 0, getController().getScriptCount() + 1); } /** {@inheritDoc} */ - public void scriptRegistered(@NotNull final CScriptModel script) { + public void scriptRegistered(@NotNull final ScriptModel script) { fireContentsChanged(scripts, 0, getController().getScriptCount() + 1); } @@ -122,7 +122,7 @@ scripts.addListSelectionListener(new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { - showScript((CScriptModel) scripts.getSelectedValue()); + showScript((ScriptModel) scripts.getSelectedValue()); } } }); @@ -134,7 +134,7 @@ public void actionPerformed(final ActionEvent e) { final String name = JOptionPane.showInputDialog(scripts, "Name of the new Beanshell plugin?"); if (name != null) { - final CScriptModel m = new CScriptModel(ctrl); + final ScriptModel m = new ScriptModel(ctrl); m.setName(name); m.setCode("//input your beanshell Code"); if (!getController().addScript(m)) { @@ -148,7 +148,7 @@ final JButton removeScriptBtn = new JButton("Remove"); removeScriptBtn.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { - final CScriptModel m = (CScriptModel) scripts.getSelectedValue(); + final ScriptModel m = (ScriptModel) scripts.getSelectedValue(); if (m == null) { return; } @@ -173,11 +173,11 @@ this.setVisible(true); } - private CScriptController getController() { + private ScriptController getController() { return this.ctrl; } - private void showScript(final CScriptModel model) { + private void showScript(final ScriptModel model) { /* using a cardlayout is a necessary trick as * simply removing previous component and putting * the new one in the JPanel lead to problem unless @@ -198,7 +198,7 @@ scriptLayout.show(scriptPanel, Integer.toString(c.hashCode())); } - private void removeScript(final CScriptModel model) { + private void removeScript(final ScriptModel model) { final ScriptEditor c = components.get(model); if (c != null) { components.remove(model); Copied: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java (from rev 2503, trunk/crossfire/src/cfeditor/gui/script/CScriptView.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -0,0 +1,270 @@ +/* + * 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.gui.script.parameter.PluginParameterView; +import cfeditor.script.ScriptController; +import cfeditor.script.ScriptModel; +import cfeditor.script.ScriptControlListener; +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +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 javax.swing.filechooser.FileFilter; +import net.sf.gridarta.Menu; +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 control; + + /** + * The menu to add script commands to. + */ + @Nullable private JMenu menuScripts = null; + + private JFrame console = null; + + private CloseableTabbedPane consolePane = null; + + private JFrame scriptManager = null; + + /** + * The script control listener to be notified about changes in {@link + * #control}. + */ + private final ScriptControlListener scriptControlListener = new ScriptControlListener() { + + /** {@inheritDoc} */ + public void scriptCreated(@NotNull final ScriptModel script) { + updateMenuEntries(); + } + + /** {@inheritDoc} */ + public void scriptDeleted(@NotNull final ScriptModel script) { + updateMenuEntries(); + } + + /** {@inheritDoc} */ + public void scriptRegistered(@NotNull final ScriptModel script) { + updateMenuEntries(); + } + + }; + + /** + * Creates a ScriptView. + * @param control controller of this ScriptView + * @warning Creating a view from a controller instead of a model is error prone. + */ + public ScriptView(final ScriptController control) { + this.control = control; + + control.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; + } + + Menu.removeAllToSeparator(menuScripts); + + final String[] scripts = control.listScript(); + int index = 0; + for (final String script : scripts) { + if (!control.getScript(script).isBash()) { + continue; + } + + final Action action = ACTION_FACTORY.createAction(true, "runPlugin", this); + action.putValue(ReflectionAction.REFLECTION_ARGUMENTS, new Object[] { script, }); + action.putValue(Action.NAME, ACTION_FACTORY.format("runPlugin.text", script)); + final JMenuItem item = new JMenuItem(action); + item.setActionCommand(script); + 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) { + control.runScript(script); + } + + public synchronized void editPlugins() { + if (scriptManager == null) { + scriptManager = new ScriptManager(control); + } + + scriptManager.pack(); + scriptManager.setVisible(true); + } + + public void savePlugins() { + control.exportXML(); + } + + public void exportPluginAs() { + final JFileChooser choose = new JFileChooser(); + final FileFilter filter = new FileFilter() { + @Override public boolean accept(final File f) { + return f.isFile() && f.getName().endsWith(".xml"); + } + + @Override public String getDescription() { + return "XML script collection (*.xml)"; + } + }; + choose.setFileFilter(filter); + if (choose.showSaveDialog(control.getMainControl().getMainView()) == JFileChooser.APPROVE_OPTION) { + final File f = choose.getSelectedFile(); + control.exportXML(f); + } + } + + public void importPlugin() { + final JFileChooser choose = new JFileChooser(); + final FileFilter filter = new FileFilter() { + @Override public boolean accept(final File f) { + return f.isFile() && f.getName().endsWith(".xml") && f.exists() && f.canWrite(); + } + + @Override public String getDescription() { + return "XML script collection (*.xml)"; + } + }; + choose.setFileFilter(filter); + if (choose.showOpenDialog(control.getMainControl().getMainView()) == JFileChooser.APPROVE_OPTION) { + final File f = choose.getSelectedFile(); + try { + control.importXML(new FileReader(f), true); + } catch (final FileNotFoundException ex) { + } + } + } + + 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.addTab(name, bshConsole, true); + return bshConsole; + } + + public boolean getRunValues(final ScriptModel model) { + //JDialog d = new JDialog(control.getMainControl().getMainView(), true); + if (model.getParametersCount() < 1) { + return true; + } + + final JOptionPane p = new JOptionPane(); + p.setOptionType(JOptionPane.OK_CANCEL_OPTION); + p.setMessageType(JOptionPane.QUESTION_MESSAGE); + p.setMessage("Please provide runtime parameters for " + model.getName()); + final GridBagLayout layout = new GridBagLayout(); + final JPanel panel = new JPanel(layout); + final JDialog dialog = p.createDialog(control.getMainControl().getMainView(), "hi"); + dialog.setModal(true); + dialog.setTitle(model.getName()); + dialog.getContentPane().removeAll(); + //JTextField[] fields = new JTextField[model.getParametersCount()]; + for (int i = 0; i < model.getParametersCount(); i++) { + log.debug("adding parameter"); + final JLabel name = new JLabel(model.getParamName(i)); + final PluginParameterView view = model.getParameter(i).getView(); + final JComponent val = view.getValueComponent(model.getParamValue(i), model.getParameter(i)); + val.setToolTipText(model.getParamDescription(i)); + 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); + } + + 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 Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterTypeEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterTypeEditor.java 2007-05-16 08:55:39 UTC (rev 2503) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ParameterTypeEditor.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -19,7 +19,7 @@ package cfeditor.gui.script.parameter; -import cfeditor.script.CScriptModel; +import cfeditor.script.ScriptModel; import cfeditor.script.parameter.PluginParameter; import cfeditor.script.parameter.PluginParameterFactory; import java.awt.event.ItemEvent; @@ -30,11 +30,11 @@ private final PluginParameter parameter; - private final CScriptModel theScript; + private final ScriptModel theScript; private static final long serialVersionUID = 1L; - public ParameterTypeEditor(final CScriptModel script, final PluginParameter param) { + public ParameterTypeEditor(final ScriptModel script, final PluginParameter param) { super(PluginParameterFactory.getTypes()); parameter = param; theScript = script; Modified: trunk/crossfire/src/cfeditor/script/BshThread.java =================================================================== --- trunk/crossfire/src/cfeditor/script/BshThread.java 2007-05-16 08:55:39 UTC (rev 2503) +++ trunk/crossfire/src/cfeditor/script/BshThread.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -32,7 +32,7 @@ /** * The ScriptModel of this BshThread. */ - private CScriptModel script; + private ScriptModel script; /** * The Interpreter of this BshThread. @@ -74,7 +74,7 @@ * Sets the ScriptModel for this BshThread. * @param script ScriptModel for this BshThread. */ - public void setScript(final CScriptModel script) { + public void setScript(final ScriptModel script) { this.script = script; } Deleted: trunk/crossfire/src/cfeditor/script/CScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/script/CScriptController.java 2007-05-16 08:55:39 UTC (rev 2503) +++ trunk/crossfire/src/cfeditor/script/CScriptController.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -1,419 +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.CFilterControl; -import cfeditor.CMainControl; -import cfeditor.CResourceLoader; -import cfeditor.filter.Filter; -import cfeditor.gui.script.CScriptView; -import java.io.CharArrayWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.Reader; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import javax.swing.JFileChooser; -import javax.swing.JMenu; -import javax.swing.JOptionPane; -import javax.swing.event.EventListenerList; -import javax.swing.filechooser.FileFilter; -import org.apache.log4j.Logger; -import org.jdom.Document; -import org.jdom.Element; -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. - * @todo documentation - * @author tchize - */ -public final class CScriptController { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(CScriptController.class); - - private final Map<String, CScriptModel> scripts = new LinkedHashMap<String, CScriptModel>(); - - private final CScriptView view; - - /** The MainControlListeners to inform of changes. */ - private final EventListenerList listeners = new EventListenerList(); - - private final CMainControl mainControl; - - private final CResourceLoader scriptRsc; - - public CScriptController(final CMainControl mainControl) { - view = new CScriptView(this); - this.mainControl = mainControl; - scriptRsc = new CResourceLoader("scripts.xml"); - importXML(); - } - - /** - * Set the menu to add script commands to. Entries already present in the - * menu are deleted. - * - * @param menuScripts the plugins menu - */ - public void setMenu(@Nullable final JMenu menuScripts) { - view.setMenu(menuScripts); - } - - public String[] listScript() { - return scripts.keySet().toArray(new String[scripts.keySet().size()]); - } - - /** - * 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(final CScriptModel script) { - if (scripts.containsKey(script.getName())) { - return false; - } - - scripts.put(script.getName(), script); - fireScriptCreatedEvent(script); - return true; - } - - public void removeScript(final CScriptModel script) { - if (!scripts.containsKey(script.getName())) { - throw new IllegalArgumentException(); - } - - scripts.remove(script.getName()); - fireScriptDeletedEvent(script); - } - - public void importXML() { - final Document d = CResourceLoader.getAggregateXML("scripts.xml", true, true, true); - importXML(d, true); - } - - public void importXML(final Reader source, final boolean override) { - final SAXBuilder builder = new SAXBuilder(false);/*non validating*/ - log.debug("Loading...."); - try { - final Document scriptDoc = builder.build(source); - importXML(scriptDoc, override); - } catch (final Exception e) { - } - } - - public void importXML(final Document doc, final boolean override) { - try { - if (!doc.hasRootElement()) { - log.info("No script found."); - return; - } - - final Element elt = doc.getRootElement(); - if ((!elt.getName().equalsIgnoreCase("scripts"))) { - log.warn("Problem reading xml scripts, need a root element named \"scripts\""); - return; - } - final List scriptList = elt.getChildren("script"); - if (scriptList == null || scriptList.isEmpty()) { - log.info("no script found"); - return; - } - for (final Object o : scriptList) { - log.debug("Reading one script"); - final CScriptModel cScript = new CScriptModel(this); - cScript.fromXML((Element) o); - log.debug("script: " + cScript.getName()); - if (override || !scripts.containsKey(cScript.getName())) { - if (log.isDebugEnabled()) { - log.debug("storing with code " + cScript.getCode()); - } - - unRegister(cScript.getName()); - addScript(cScript); - register(cScript.getName()); - } else { - log.debug("not storing"); - } - } - } catch (final Exception e) { - e.printStackTrace(); - } - } - - public void exportScript(final CScriptModel model) { - //show a dialog an propose a filename - final JFileChooser chooser = new JFileChooser(); - final FileFilter f = new FileFilter() { - @Override public boolean accept(final File f) { - return f.getName().endsWith(".xml"); - } - - @Override public String getDescription() { - return "cfeditor script (*.xml)"; - } - }; - chooser.setFileFilter(f); - final int result = chooser.showSaveDialog(null); - if (result == JFileChooser.APPROVE_OPTION) { - final Element root = new Element("scripts"); - final Document d = new Document(root); - root.addContent(model.toXML()); - final XMLOutputter out = new XMLOutputter(); - out.setFormat(Format.getPrettyFormat()); - try { - final FileWriter fw = new FileWriter(chooser.getSelectedFile()); - out.output(d, fw); - } catch (final IOException e) { - e.printStackTrace(); - } - } - } - - public void exportXML() { - try { - exportXML(scriptRsc.getOutputStream()); - } catch (final IOException e) { - JOptionPane.showMessageDialog(mainControl.getMainView(), e.getLocalizedMessage(), "Script Error", JOptionPane.INFORMATION_MESSAGE); - e.printStackTrace(); - } - } - - public void exportXML(final OutputStream destination) { - final Element root = new Element("scripts"); - final Document d = new Document(root); - for (final CScriptModel sm : scripts.values()) { - root.addContent(sm.toXML()); - } - final XMLOutputter out = new XMLOutputter(); - out.setFormat(Format.getPrettyFormat()); - try { - out.output(d, destination); - } catch (final IOException e) { - e.printStackTrace(); - } - } - - public void exportXML(final File destination) { - try { - final OutputStream w = new FileOutputStream(destination); - exportXML(w); - } catch (final Exception e) { - e.printStackTrace(); - //TODO handle using main controller - } - } - - private void setInterpreterValues(final Interpreter i, final String mode) throws EvalError { - i.set("mainControl", mainControl); - i.set("mainView", mainControl.getMainView()); - i.set("archList", mainControl.getArchetypeSet()); - i.set("runMode", mode); - } - - public void autoRunScript(final CScriptModel script) { - final Interpreter runner = new Interpreter(); - try { - setInterpreterValues(runner, "autorun"); - runner.eval(script.getCode()); - } catch (final EvalError e) { - log.warn("Evaluation error on (autorun)" + script.getName(), e); - } - } - - @Nullable public Filter getScriptAsFilter(final CScriptModel script) { - final Interpreter runner = new Interpreter(); - try { - setInterpreterValues(runner, "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 cfeditor.filter.Filter object" + script.getName(), e); - } - return null; - } - - public void runScript(final CScriptModel script) { - final CScriptModel model; - try { - model = (CScriptModel) script.clone(); - } catch (final CloneNotSupportedException e) { - throw new AssertionError(); - } - - if (!view.getRunValues(model)) { - return; - } - - final Interpreter runner = new Interpreter(); - final ConsoleInterface console = view.createConsole(model.getName()); - try { - runner.setConsole(console); - setInterpreterValues(runner, "batch"); - for (int i = 0; i < model.getParametersCount(); i++) { - runner.set(model.getParamName(i), model.getParamValue(i)); - } - final BshThread scriptThread = new BshThread(script.getName()); - scriptThread.setScript(script); - scriptThread.setInterpreter(runner); - scriptThread.start(); - } catch (final TargetError e) { - final CharArrayWriter w = new CharArrayWriter(); - e.getTarget().printStackTrace(new PrintWriter(w)); - console.print(w.toString()); - } catch (final EvalError e) { - console.print("Evaluation error: " + e.getMessage()); - } - } - - public void runScript(final String name) { - final CScriptModel model = scripts.get(name); - runScript(model); - } - - public void runScript(final int index) { - final CScriptModel model = getScript(index); - if (model != null) { - runScript(model); - } - } - - public boolean isScriptValid(final String code) { - return true; - } - - public CScriptView getView() { - return view; - } - - @Nullable public CScriptModel getScript(int index) { - final Iterator<CScriptModel> i = scripts.values().iterator(); - CScriptModel m = null; - while (i.hasNext() && index-- >= 0) { - m = i.next(); - } - if (index >= 0) { - return null; - } else { - return m; - } - } - - public CScriptModel getScript(final String name) { - return scripts.get(name); - } - - public int getScriptCount() { - return scripts.size(); - } - - public void addScriptControlListener(@NotNull final ScriptControlListener listener) { - listeners.add(ScriptControlListener.class, 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 CScriptModel script) { - for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { - listener.scriptCreated(script); - } - } - - /** - * Notify all listeners about a removed script. - * - * @param script the removed script - */ - private void fireScriptDeletedEvent(@NotNull final CScriptModel script) { - for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { - listener.scriptDeleted(script); - } - } - - /** - * Notify all listeners about a registered script. - * - * @param script the registered script - */ - private void fireScriptRegisteredEvent(@NotNull final CScriptModel script) { - for (final ScriptControlListener listener : listeners.getListeners(ScriptControlListener.class)) { - listener.scriptRegistered(script); - } - } - - public CMainControl getMainControl() { - return mainControl; - } - - private static void unRegister(final String name) { - final String filterName = "(s)" + name; - CFilterControl.getDefaultFilter().removeFilter(filterName); - } - - private void register(final String name) { - final String filterName = "(s)" + name; - final CScriptModel script = getScript(name); - if (script.isFilter()) { - final Filter filter = getScriptAsFilter(script); - if (filter != null) { - CFilterControl.getDefaultFilter().addFilter(filterName, filter); - } - } - - if (script.isAutoboot()) { - autoRunScript(script); - } - - fireScriptRegisteredEvent(script); - } - - public void reRegister(final String name) { - unRegister(name); - register(name); - } - -} // class CScriptController Deleted: trunk/crossfire/src/cfeditor/script/CScriptModel.java =================================================================== --- trunk/crossfire/src/cfeditor/script/CScriptModel.java 2007-05-16 08:55:39 UTC (rev 2503) +++ trunk/crossfire/src/cfeditor/script/CScriptModel.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -1,401 +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 cfeditor.script.parameter.PluginParameter; -import cfeditor.script.parameter.PluginParameterFactory; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import org.apache.log4j.Logger; -import org.jdom.CDATA; -import org.jdom.Element; -import org.jdom.IllegalDataException; -import org.jetbrains.annotations.Nullable; - -/** - * Model for Scripts. - * @todo documentation - * @author tchize - */ -public final class CScriptModel implements Cloneable { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(CScriptModel.class); - - public static final int PLUGIN_AUTOBOOT = 1; - - public static final int PLUGIN_FILTER = 2; - - public static final int PLUGIN_SCRIPT = 4; - - public static final Integer RUN_AUTOBOOT = 1; - - public static final Integer RUN_FILTER = 2; - - public static final Integer RUN_SCRIPT = 4; - - private String code = ""; - - private final List<PluginParameter> params = new ArrayList<PluginParameter>(); - - private String name = ""; - - private int scriptType; - - private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(); - - private final CScriptController control; - - public CScriptModel(final CScriptController control) { - this.control = control; - } - - /** - * Returns the name of this ScriptModel. - * @return The name of this ScriptModel. - */ - public String getName() { - return name; - } - - /** - * 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) { - this.name = name; - 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 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) { - this.code = code; - notifyListeners(); - } - - /** - * Set the name of a given parameter. - * @param index The index of parameter to rename - * @param name the new name of parameter - */ - public void setParamName(final int index, final String name) { - try { - params.get(index).setName(name); - } catch (final Exception e) { - } - } - - /** - * Get the name of a script parameter. - * @param index The index number of parameter - * @return the name of parameter - */ - @Nullable public String getParamName(final int index) { - try { - return params.get(index).getName(); - } catch (final Exception e) { - return null; - } - - } - - /** - * Returns the parameter description for the parameter with the specified index. - * @param index the parameter index to get - * @return The description of the specified parameter. - */ - @Nullable public String getParamDescription(final int index) { - try { - return params.get(index).getDescription(); - } catch (final Exception e) { - return null; - } - } - - /** - * Sets the parameter description for the parameter with the specified index. - * @param index the parameter index to set - * @param description the new description of parameter - */ - public void setParamDescription(final int index, final String description) { - try { - params.get(index).setDescription(description); - } catch (final Exception e) { - } - notifyListeners(); - } - - /** - * Returns the parameter value for the parameter with the specified index. - * @param index the parameter index to get - * @return Returns the parameter default value. - */ - @Nullable public Object getParamValue(final int index) { - try { - return params.get(index).getValue(); - } catch (final Exception e) { - e.printStackTrace(); - return null; - } - } - - /** - * Sets the parameter value for the parameter with the specified index. - * @param index the parameter index to set - * @param value the default value to set - */ - public void setParamValue(final int index, final Object value) { - try { - params.get(index).setValue(value); - } catch (final Exception e) { - } - notifyListeners(); - } - - public int getParametersCount() { - return params.size(); - } - - public String[] getParameters() { - final List<String> l = new ArrayList<String>(); - for (final PluginParameter p : params) { - if (!l.contains(p.getName())) { - l.add(p.getName()); - } - } - return l.toArray(new String[l.size()]); - } - - @Override public String toString() { - return name; - } - - public void newParameter() { - final PluginParameter p = PluginParameterFactory.createParameter(); - params.add(p); - notifyListeners(); - } - - public void removeParameter(final int index) { - params.remove(index); - 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 CScriptModel 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 CScriptModel - */ - @Override public Object clone() throws CloneNotSupportedException { - final CScriptModel model = new CScriptModel(control); - model.code = code; - model.name = name; - model.scriptType = scriptType; - for (final PluginParameter param : params) { - model.addParameter((PluginParameter) param.clone()); - } - return model; - } - - /** - * Gets the controller which handles this CScriptModel. - * @return the controller - */ - public CScriptController getController() { - return control; - } - - /** - * Adds a parameter to this script. - * @param p the parameter to add - */ - public void addParameter(final PluginParameter p) { - params.add(p); - 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 - */ - public PluginParameter getParameter(final int index) { - return params.get(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() { - if (log.isDebugEnabled()) { - log.debug("isautoboot: scriptType = " + scriptType); - } - return (scriptType & PLUGIN_AUTOBOOT) != 0; - } - - /** - * Check if this script is a bash script (script run from the run script - * menu). - * @return true if script is a bash script, false otherwise - */ - public boolean isBash() { - return (scriptType & PLUGIN_SCRIPT) != 0; - } - - /** - * 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 (scriptType & PLUGIN_FILTER) != 0; - } - - public void toggleScriptType(final int type, final boolean b) { - if (b) { - scriptType |= type; - } else { - scriptType &= ~type; - } - notifyListeners(); - } - - public void setAutoboot(final boolean b) { - toggleScriptType(PLUGIN_AUTOBOOT, b); - } - - public void setBash(final boolean b) { - toggleScriptType(PLUGIN_SCRIPT, b); - } - - public void setFilter(final boolean b) { - toggleScriptType(PLUGIN_FILTER, b); - } - - public void fromXML(final Element node) { - setName(node.getChildTextTrim("name")); - setCode(node.getChildTextTrim("code")); - scriptType = 0; - final Element mode = node.getChild("mode"); - if (mode == null) { - scriptType = PLUGIN_SCRIPT; - } else { - final List<Element> modes = mode.getChildren(); - for (final Element m : modes) { - final boolean b = Boolean.valueOf(m.getTextTrim()); - final String name = m.getName(); - if ("autoboot".equalsIgnoreCase(name) && b) { - scriptType |= PLUGIN_AUTOBOOT; - } else if ("filter".equalsIgnoreCase(name) && b) { - scriptType |= PLUGIN_FILTER; - } else if ("bash".equalsIgnoreCase(name) && b) { - scriptType |= PLUGIN_SCRIPT; - } - } - } - final List<Element> params = node.getChildren("parameter"); - if (params != null && !params.isEmpty()) { - for (final Element parameter : params) { - final PluginParameter p = PluginParameterFactory.createParameter(parameter); - addParameter(p); - } - } - } - - public Element toXML() { - final Element root = new Element("script"); - final Element n = new Element("name"); - final Element c = new Element("code"); - n.addContent(getName()); - try { - c.addContent(new CDATA(getCode()));// protect code in xml! - } catch (final IllegalDataException e) { - //can't be converted to CDATA :( - c.addContent(getCode()); - } - root.addContent(n); - root.addContent(c); - final Element modes = new Element("mode"); - - { - final Element autoboot = new Element("autoboot"); - autoboot.addContent(Boolean.toString((scriptType & PLUGIN_AUTOBOOT) != 0)); - final Element bash = new Element("bash"); - bash.addContent(Boolean.toString((scriptType & PLUGIN_SCRIPT) != 0)); - final Element filter = new Element("filter"); - filter.addContent(Boolean.toString((scriptType & PLUGIN_FILTER) != 0)); - modes.addContent(autoboot); - modes.addContent(bash); - modes.addContent(filter); - } - - root.addContent(modes); - for (final PluginParameter param : params) { - root.addContent(param.toXML()); - } - return root; - } - - public void convertType(final int index, final String newType) { - params.set(index, PluginParameterFactory.createParameter(newType, params.get(index).toXML())); - notifyListeners(); - } - - public void convertType(final PluginParameter param, final String newType) { - final int index = params.indexOf(param); - convertType(index, newType); - } - -} // class CScriptModel Modified: trunk/crossfire/src/cfeditor/script/ScriptControlListener.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptControlListener.java 2007-05-16 08:55:39 UTC (rev 2503) +++ trunk/crossfire/src/cfeditor/script/ScriptControlListener.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -33,20 +33,20 @@ * * @param script the created script */ - void scriptCreated(@NotNull CScriptModel script); + void scriptCreated(@NotNull ScriptModel script); /** * Notifies about the deletion of a script. * * @param script the deleted script */ - void scriptDeleted(@NotNull CScriptModel script); + void scriptDeleted(@NotNull ScriptModel script); /** * Notifies about the registering of a script. * * @param script the registered script */ - void scriptRegistered(@NotNull CScriptModel script); + void scriptRegistered(@NotNull ScriptModel script); } // interface ScriptControlListener Copied: trunk/crossfire/src/cfeditor/script/ScriptController.java (from rev 2502, trunk/crossfire/src/cfeditor/script/CScriptController.java) =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptController.java (rev 0) +++ trunk/crossfire/src/cfeditor/script/ScriptController.java 2007-05-16 09:05:26 UTC (rev 2504) @@ -0,0 +1,419 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistr... [truncated message content] |
From: <chr...@us...> - 2007-05-17 21:46:20
|
Revision: 2533 http://svn.sourceforge.net/gridarta/?rev=2533&view=rev Author: christianhujer Date: 2007-05-17 14:46:21 -0700 (Thu, 17 May 2007) Log Message: ----------- Optimized imports. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java trunk/crossfire/src/cfeditor/gui/script/ScriptView.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-17 15:08:22 UTC (rev 2532) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-17 21:46:21 UTC (rev 2533) @@ -59,8 +59,8 @@ import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ActionMethod; +import net.sf.japi.swing.misc.Progress; import net.sf.japi.swing.misc.ProgressDisplay; -import net.sf.japi.swing.misc.Progress; import net.sf.japi.swing.prefs.PreferencesGroup; import net.sf.japi.swing.prefs.PreferencesPane; import net.sf.japi.swing.tod.TipOfTheDayManager; Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2007-05-17 15:08:22 UTC (rev 2532) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2007-05-17 21:46:21 UTC (rev 2533) @@ -31,8 +31,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; +import java.io.IOException; import java.io.InputStream; -import java.io.IOException; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.util.Arrays; Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2007-05-17 15:08:22 UTC (rev 2532) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptManager.java 2007-05-17 21:46:21 UTC (rev 2533) @@ -19,9 +19,9 @@ package cfeditor.gui.script; +import cfeditor.script.ScriptControlListener; import cfeditor.script.ScriptController; import cfeditor.script.ScriptModel; -import cfeditor.script.ScriptControlListener; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2007-05-17 15:08:22 UTC (rev 2532) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2007-05-17 21:46:21 UTC (rev 2533) @@ -22,9 +22,9 @@ import bsh.ConsoleInterface; import bsh.util.JConsole; import cfeditor.gui.script.parameter.PluginParameterView; +import cfeditor.script.ScriptControlListener; import cfeditor.script.ScriptController; import cfeditor.script.ScriptModel; -import cfeditor.script.ScriptControlListener; import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-05-18 19:17:24
|
Revision: 2556 http://svn.sourceforge.net/gridarta/?rev=2556&view=rev Author: akirschbaum Date: 2007-05-18 12:17:26 -0700 (Fri, 18 May 2007) Log Message: ----------- Move APP_SETTINGS_DIR constant to CResourceLoader. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CResourceLoader.java trunk/crossfire/src/cfeditor/IGUIConstants.java Modified: trunk/crossfire/src/cfeditor/CResourceLoader.java =================================================================== --- trunk/crossfire/src/cfeditor/CResourceLoader.java 2007-05-18 19:14:59 UTC (rev 2555) +++ trunk/crossfire/src/cfeditor/CResourceLoader.java 2007-05-18 19:17:26 UTC (rev 2556) @@ -48,6 +48,9 @@ /** The Logger for printing log messages. */ private static final Logger log = Logger.getLogger(CResourceLoader.class); + /** Name of directory with settings file. */ + private static final String APP_SETTINGS_DIR = ".gridarta"; + /** The current working directory location. */ public static final int LOCATION_CURRENT = 1; @@ -185,7 +188,7 @@ final StringBuilder buf = new StringBuilder(128); final String home = System.getProperty("user.home"); buf.append(home); - buf.append(File.separator).append(IGUIConstants.APP_SETTINGS_DIR); + buf.append(File.separator).append(APP_SETTINGS_DIR); final File rc = new File(buf.toString()); if (!rc.isDirectory()) { rc.mkdir(); Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-05-18 19:14:59 UTC (rev 2555) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-05-18 19:17:26 UTC (rev 2556) @@ -59,9 +59,6 @@ /** Application name. */ String APP_NAME = "CFJavaEditor"; - /** Name of directory with settings file. */ - String APP_SETTINGS_DIR = ".gridarta"; - /** The amount of space to be left between dialog buttons. */ int SPACE_BETWEEN_BUTTONS = 4; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-05-18 23:15:57
|
Revision: 2579 http://svn.sourceforge.net/gridarta/?rev=2579&view=rev Author: christianhujer Date: 2007-05-18 16:15:59 -0700 (Fri, 18 May 2007) Log Message: ----------- Added icons to recent in Crossfire. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/RecentManager.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-18 23:11:39 UTC (rev 2578) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-18 23:15:59 UTC (rev 2579) @@ -1007,6 +1007,15 @@ } /** + * return the map preview accessory. + * + * @return the map preview accessory + */ + public MapPreviewAccessory getMapPreviewAccessory() { + return mapPreviewAccessory; + } + + /** * return the recent menu manager. * * @return the recent menu manager Modified: trunk/crossfire/src/cfeditor/RecentManager.java =================================================================== --- trunk/crossfire/src/cfeditor/RecentManager.java 2007-05-18 23:11:39 UTC (rev 2578) +++ trunk/crossfire/src/cfeditor/RecentManager.java 2007-05-18 23:15:59 UTC (rev 2579) @@ -27,11 +27,13 @@ import java.util.ListIterator; import java.util.prefs.Preferences; import javax.swing.AbstractAction; +import javax.swing.ImageIcon; import javax.swing.JMenu; import javax.swing.KeyStroke; import net.sf.gridarta.MenuHelper; import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Manages the recent menu entries. @@ -123,6 +125,7 @@ this.filename = filename; this.title = title; putValue(SHORT_DESCRIPTION, ACTION_FACTORY.format("recentItem.shortdescriptionformat", title, getShortFileName())); + putValue(SMALL_ICON, getIcon()); } /** @@ -133,6 +136,7 @@ title = prefs.get("recentTitle[" + Integer.toString(index - 1) + ']', null); filename = prefs.get("recentFilename[" + Integer.toString(index - 1) + ']', null); putValue(SHORT_DESCRIPTION, ACTION_FACTORY.format("recentItem.shortdescriptionformat", title, getShortFileName())); + putValue(SMALL_ICON, getIcon()); setIndex(index); } @@ -180,6 +184,14 @@ mainControl.getMapManager().openMapFileWithView(new File(filename), null); } + /** + * Get the icon of this file. + * @return icon of this file + */ + @Nullable private ImageIcon getIcon() { + return mainControl.getMapPreviewAccessory().getMapIcon(new File(filename)); + } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { return !(obj == null || !(obj instanceof Recent)) && filename.equals(((Recent) obj).filename); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-05-19 18:04:23
|
Revision: 2640 http://svn.sourceforge.net/gridarta/?rev=2640&view=rev Author: akirschbaum Date: 2007-05-19 11:04:24 -0700 (Sat, 19 May 2007) Log Message: ----------- Remove call to AbstractMainControl.getInstance(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinLists.java trunk/crossfire/src/cfeditor/CMainControl.java Modified: trunk/crossfire/src/cfeditor/AutojoinLists.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinLists.java 2007-05-19 17:59:18 UTC (rev 2639) +++ trunk/crossfire/src/cfeditor/AutojoinLists.java 2007-05-19 18:04:24 UTC (rev 2640) @@ -25,7 +25,6 @@ import java.io.IOException; import java.util.IdentityHashMap; import java.util.Map; -import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.gameobject.Archetype; import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; @@ -83,11 +82,11 @@ * The links from the default arches to their appropriate * AutojoinLists also get set here. * @param archstack the stack of default arches + * @param baseDir The configuration directory to load autojoin info from. */ - public static void loadList(final ArchetypeSet archstack) { + public static void loadList(final ArchetypeSet archstack, @NotNull final String baseDir) { try { // open the resource file - final String baseDir = AbstractMainControl.getInstance().getConfigurationDirectory(); final BufferedReader stream = IOUtils.createReader(baseDir, FILENAME); try { Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-19 17:59:18 UTC (rev 2639) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-05-19 18:04:24 UTC (rev 2640) @@ -311,7 +311,7 @@ * into the ArchetypeSet 'archetypeSet'!) */ public void loadJoinlist() { - AutojoinLists.loadList(archetypeSet); + AutojoinLists.loadList(archetypeSet, getConfigurationDirectory()); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-07-10 08:46:53
|
Revision: 2761 http://svn.sourceforge.net/gridarta/?rev=2761&view=rev Author: akirschbaum Date: 2007-07-10 01:44:10 -0700 (Tue, 10 Jul 2007) Log Message: ----------- Unify code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/archetypechooser/ArchetypePanel.java 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 Modified: trunk/crossfire/src/cfeditor/gui/archetypechooser/ArchetypePanel.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/archetypechooser/ArchetypePanel.java 2007-07-10 08:43:33 UTC (rev 2760) +++ trunk/crossfire/src/cfeditor/gui/archetypechooser/ArchetypePanel.java 2007-07-10 08:44:10 UTC (rev 2761) @@ -21,8 +21,13 @@ import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; +import cfeditor.gui.GameObjectAttributesDialog; import cfeditor.map.MapArchObject; +import javax.swing.JPopupMenu; import javax.swing.ListCellRenderer; +import net.sf.gridarta.AbstractMainControl; +import net.sf.japi.swing.ActionFactory; +import net.sf.japi.swing.ActionMethod; import org.apache.log4j.Logger; /** @@ -38,11 +43,32 @@ /** Serial Version UID. */ private static final long serialVersionUID = 1L; + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + + /** The popup menu for the arch lists to bring up the editor. */ + // This looks unused, but don't remove it. It will be used in future. + private final JPopupMenu menu = createListPopupMenu(); + /* Build Panel */ public ArchetypePanel(final ArchetypeChooserControl archetypeChooserControl) { super(archetypeChooserControl); } + private JPopupMenu createListPopupMenu() { + final JPopupMenu menu = new JPopupMenu(); + menu.add(ACTION_FACTORY.createAction(false, "editPopup", this)); + return menu; + } + + /** + * Action method for the popup menu to edit a default arch. + */ + @ActionMethod public void editPopup() { + final GameObject arch = getArchListObject(); + GameObjectAttributesDialog.showAttribDialog(AbstractMainControl.getInstance().getTypeList(), arch, AbstractMainControl.getInstance()); + } + @Override protected ListCellRenderer createRenderer() { return new CellRenderer(); } Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2007-07-10 08:43:33 UTC (rev 2760) +++ trunk/crossfire/src/cfeditor/messages.properties 2007-07-10 08:44:10 UTC (rev 2761) @@ -485,7 +485,11 @@ prefsMisc.title=Miscellaneous +#################### +# Archetype Chooser +editPopup.text=Edit Archetype + ####################### # Various Log Messages logExitWithExit=Exiting with System.exit(). Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2007-07-10 08:43:33 UTC (rev 2760) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2007-07-10 08:44:10 UTC (rev 2761) @@ -426,3 +426,7 @@ prefsMisc.title=Allgemeines + +#################### +# Archetype Chooser +editPopup.text=Archetyp bearbeiten Modified: trunk/crossfire/src/cfeditor/messages_fr.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_fr.properties 2007-07-10 08:43:33 UTC (rev 2760) +++ trunk/crossfire/src/cfeditor/messages_fr.properties 2007-07-10 08:44:10 UTC (rev 2761) @@ -426,3 +426,7 @@ #prefsMisc.title= + +#################### +# Archetype Chooser +#editPopup.text= Modified: trunk/crossfire/src/cfeditor/messages_sv.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_sv.properties 2007-07-10 08:43:33 UTC (rev 2760) +++ trunk/crossfire/src/cfeditor/messages_sv.properties 2007-07-10 08:44:10 UTC (rev 2761) @@ -424,3 +424,7 @@ prefsMisc.title=Diverse + +#################### +# Archetype Chooser +#editPopup.text= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-07-21 07:34:54
|
Revision: 2787 http://svn.sourceforge.net/gridarta/?rev=2787&view=rev Author: akirschbaum Date: 2007-07-21 00:34:57 -0700 (Sat, 21 Jul 2007) Log Message: ----------- Remove singleton CFilterControl.defaultFilter. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFilterControl.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/script/ScriptController.java Modified: trunk/crossfire/src/cfeditor/CFilterControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CFilterControl.java 2007-07-21 07:26:13 UTC (rev 2786) +++ trunk/crossfire/src/cfeditor/CFilterControl.java 2007-07-21 07:34:57 UTC (rev 2787) @@ -69,8 +69,6 @@ @Nullable private final MapControl mapControl; - private static final CFilterControl defaultFilter = new CFilterControl(null); - /** * Create a new FilterControl. * Do not highlight anything and does not filterOut anything @@ -91,10 +89,6 @@ this.mapControl = mapControl; } - public static CFilterControl getDefaultFilter() { - return defaultFilter; - } - public void createMenuEntries(final JMenu menu) { final JMenuItem menuItem = filterList.createMenuEntry(filterOutConfig); menuItem.setText("Filter view"); Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-07-21 07:26:13 UTC (rev 2786) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-07-21 07:34:57 UTC (rev 2787) @@ -205,6 +205,9 @@ /** The recent menu manager. */ private final RecentManager recentManager; + /** The filter control. */ + private final CFilterControl filterControl = new CFilterControl(null); + /** The autojoin lists. */ public static final AutojoinLists<GameObject, MapArchObject, Archetype> autojoinLists = new AutojoinLists<GameObject, MapArchObject, Archetype>(); @@ -859,7 +862,7 @@ } public CFilterControl getFilterControl() { - return CFilterControl.getDefaultFilter(); + return filterControl; } public ScriptController getScriptController() { Modified: trunk/crossfire/src/cfeditor/script/ScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptController.java 2007-07-21 07:26:13 UTC (rev 2786) +++ trunk/crossfire/src/cfeditor/script/ScriptController.java 2007-07-21 07:34:57 UTC (rev 2787) @@ -23,7 +23,6 @@ import bsh.EvalError; import bsh.Interpreter; import bsh.TargetError; -import cfeditor.CFilterControl; import cfeditor.CMainControl; import cfeditor.CResourceLoader; import cfeditor.filter.Filter; @@ -389,9 +388,9 @@ return mainControl; } - private static void unRegister(final String name) { + private void unRegister(final String name) { final String filterName = "(s)" + name; - CFilterControl.getDefaultFilter().removeFilter(filterName); + mainControl.getFilterControl().removeFilter(filterName); } private void register(final String name) { @@ -400,7 +399,7 @@ if (script.isFilter()) { final Filter filter = getScriptAsFilter(script); if (filter != null) { - CFilterControl.getDefaultFilter().addFilter(filterName, filter); + mainControl.getFilterControl().addFilter(filterName, filter); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-07-21 07:37:12
|
Revision: 2788 http://svn.sourceforge.net/gridarta/?rev=2788&view=rev Author: akirschbaum Date: 2007-07-21 00:37:15 -0700 (Sat, 21 Jul 2007) Log Message: ----------- Remove use of CMainControl.getInstance(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFilterControl.java trunk/crossfire/src/cfeditor/CMainControl.java Modified: trunk/crossfire/src/cfeditor/CFilterControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CFilterControl.java 2007-07-21 07:34:57 UTC (rev 2787) +++ trunk/crossfire/src/cfeditor/CFilterControl.java 2007-07-21 07:37:15 UTC (rev 2788) @@ -31,6 +31,7 @@ import javax.swing.JMenuItem; import net.sf.gridarta.gameobject.GameObject; import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -67,14 +68,19 @@ private final boolean[] highLightResult; + /** The main control. */ + @NotNull private final CMainControl mainControl; + @Nullable private final MapControl mapControl; /** * Create a new FilterControl. * Do not highlight anything and does not filterOut anything * @param mapControl MapControl to create FilterControl for. + * @param mainControl The main control. */ - public CFilterControl(@Nullable final MapControl mapControl) { + public CFilterControl(@Nullable final MapControl mapControl, @NotNull final CMainControl mainControl) { + this.mainControl = mainControl; filterOutConfig = (NamedFilterConfig) filterList.createConfig(); highLightConfig = new NamedFilterConfig[]{ (NamedFilterConfig) filterList.createConfig(), @@ -147,7 +153,7 @@ if (mapControl != null) { mapControl.repaint(); } else { - final MapControl[] mapControls = CMainControl.getInstance().getMapManager().getOpenedMaps(); + final MapControl[] mapControls = mainControl.getMapManager().getOpenedMaps(); for (final MapControl mapControl : mapControls) { mapControl.repaint(); } Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-07-21 07:34:57 UTC (rev 2787) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-07-21 07:37:15 UTC (rev 2788) @@ -206,7 +206,7 @@ private final RecentManager recentManager; /** The filter control. */ - private final CFilterControl filterControl = new CFilterControl(null); + private final CFilterControl filterControl = new CFilterControl(null, this); /** The autojoin lists. */ public static final AutojoinLists<GameObject, MapArchObject, Archetype> autojoinLists = new AutojoinLists<GameObject, MapArchObject, Archetype>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-07-31 19:11:10
|
Revision: 2803 http://gridarta.svn.sourceforge.net/gridarta/?rev=2803&view=rev Author: akirschbaum Date: 2007-07-31 12:11:11 -0700 (Tue, 31 Jul 2007) Log Message: ----------- Unify code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/MainActions.java trunk/crossfire/src/cfeditor/gameobject/face/FaceObjects.java 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 Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-07-31 19:07:52 UTC (rev 2802) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-07-31 19:11:11 UTC (rev 2803) @@ -784,6 +784,11 @@ TipOfTheDayManager.show(mainView); } + /** Invoked when the user wants to reload the images. */ + public void reloadFaces() { + FaceObjects.reloadAll(); + } + /** Invoked when user wants to exit from the program. */ public void exit() { if (ScriptEditControl.getInstance().closeAllTabs() && mapManager.closeAll()) { Modified: trunk/crossfire/src/cfeditor/MainActions.java =================================================================== --- trunk/crossfire/src/cfeditor/MainActions.java 2007-07-31 19:07:52 UTC (rev 2802) +++ trunk/crossfire/src/cfeditor/MainActions.java 2007-07-31 19:11:11 UTC (rev 2803) @@ -89,6 +89,9 @@ /** Action called for "collect archetypes". */ private final Action aCollectArches = ACTION_FACTORY.createAction(true, "collectArches", this); + /** Action called for "reload faces". */ + private final Action aReloadFaces = ACTION_FACTORY.createAction(true, "reloadFaces", this); + /** * The last known active map view, or <code>null</code> if no map is * active. @@ -244,6 +247,7 @@ aFloodfill.setEnabled(getFloodfillEnabled() != null); aSelectAll.setEnabled(getSelectAllEnabled() != null); aCollectArches.setEnabled(!mainControl.getArchetypeSet().isLoadedFromArchive()); + aReloadFaces.setEnabled(!mainControl.getArchetypeSet().isLoadedFromArchive()); } /** "Clear" was selected from the Edit menu. */ @@ -400,6 +404,11 @@ mainControl.collectArches(); } + /** Invoked when the user wants to reload the images. */ + public void reloadFaces() { + mainControl.reloadFaces(); + } + /** * Determine if "clear" is enabled. * @return the map view to clear if "clear" is enabled, or Modified: trunk/crossfire/src/cfeditor/gameobject/face/FaceObjects.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/face/FaceObjects.java 2007-07-31 19:07:52 UTC (rev 2802) +++ trunk/crossfire/src/cfeditor/gameobject/face/FaceObjects.java 2007-07-31 19:11:11 UTC (rev 2803) @@ -49,6 +49,11 @@ /** Size of the image buffer. */ private static final int IMAGE_BUFFER_SIZE = 50 * 1024; + /** Reloads all providers provided by this FaceObjects. */ + public static void reloadAll() { + // TODO + } + /** The Logger for printing log messages. */ private static final Logger log = Logger.getLogger(FaceObjects.class); Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2007-07-31 19:07:52 UTC (rev 2802) +++ trunk/crossfire/src/cfeditor/messages.properties 2007-07-31 19:11:11 UTC (rev 2803) @@ -260,6 +260,10 @@ collectArches.text=Collect Arches collectArches.mnemonic=A +reloadFaces.text=Reload Faces +reloadFaces.mnemonic=F +reloadFaces.accel=ctrl pressed F5 + viewTreasurelists.text=View Tresurelists viewTreasurelists.mnemonic=T Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2007-07-31 19:07:52 UTC (rev 2802) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2007-07-31 19:11:11 UTC (rev 2803) @@ -228,6 +228,10 @@ collectArches.text=Archetypen sammeln collectArches.mnemonic=A +reloadFaces.text=Grafiken neu laden +reloadFaces.mnemonic=F +reloadFaces.accel=ctrl pressed F5 + viewTreasurelists.text=Schatzlisten anschauen viewTreasurelists.mnemonic=S Modified: trunk/crossfire/src/cfeditor/messages_fr.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_fr.properties 2007-07-31 19:07:52 UTC (rev 2802) +++ trunk/crossfire/src/cfeditor/messages_fr.properties 2007-07-31 19:11:11 UTC (rev 2803) @@ -229,6 +229,10 @@ collectArches.text=Rassembler Arches collectArches.mnemonic=A +#reloadFaces.text= +#reloadFaces.mnemonic= +#reloadFaces.accel=ctrl pressed F5 + viewTreasurelists.text=Afficher listes de tr\xE9sors viewTreasurelists.mnemonic=T Modified: trunk/crossfire/src/cfeditor/messages_sv.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_sv.properties 2007-07-31 19:07:52 UTC (rev 2802) +++ trunk/crossfire/src/cfeditor/messages_sv.properties 2007-07-31 19:11:11 UTC (rev 2803) @@ -227,6 +227,10 @@ collectArches.text=Skapa archetypsamling collectArches.mnemonic=A +reloadFaces.text=Ladda om bilder +reloadFaces.mnemonic=L +reloadFaces.accel=ctrl pressed F5 + 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...> - 2007-08-09 22:03:18
|
Revision: 2860 http://gridarta.svn.sourceforge.net/gridarta/?rev=2860&view=rev Author: akirschbaum Date: 2007-08-09 15:03:21 -0700 (Thu, 09 Aug 2007) Log Message: ----------- Remove some raw types. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFilterControl.java trunk/crossfire/src/cfeditor/filter/Filter.java trunk/crossfire/src/cfeditor/filter/NamedFilterList.java trunk/crossfire/src/cfeditor/filter/NamedGameObjectMatcherFilter.java Modified: trunk/crossfire/src/cfeditor/CFilterControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CFilterControl.java 2007-08-09 21:58:30 UTC (rev 2859) +++ trunk/crossfire/src/cfeditor/CFilterControl.java 2007-08-09 22:03:21 UTC (rev 2860) @@ -119,7 +119,7 @@ return highLightConfig[path].isEnabled() && highLightResult[path]; } - public void objectInSquare(final GameObject gameObject) { + public void objectInSquare(final GameObject<?, ?, ?> gameObject) { for (int i = 0; i < 3; i++) { if (!highLightConfig[i].isEnabled()) { continue; /*matching system not activated*/ @@ -131,7 +131,7 @@ } } - public boolean canShow(final GameObject gameObject) { + public boolean canShow(final GameObject<?, ?, ?> gameObject) { if (!filterOutConfig.isEnabled()) { return true; } Modified: trunk/crossfire/src/cfeditor/filter/Filter.java =================================================================== --- trunk/crossfire/src/cfeditor/filter/Filter.java 2007-08-09 21:58:30 UTC (rev 2859) +++ trunk/crossfire/src/cfeditor/filter/Filter.java 2007-08-09 22:03:21 UTC (rev 2860) @@ -47,7 +47,7 @@ * @return true if it match the criterion, false otherwise. This value is * ignored if hasGlobalMatch() returns true. */ - boolean match(FilterConfig config, GameObject gameObject); + boolean match(FilterConfig config, GameObject<?, ?, ?> gameObject); /** * This tells the filter we have finished with current map square and, Modified: trunk/crossfire/src/cfeditor/filter/NamedFilterList.java =================================================================== --- trunk/crossfire/src/cfeditor/filter/NamedFilterList.java 2007-08-09 21:58:30 UTC (rev 2859) +++ trunk/crossfire/src/cfeditor/filter/NamedFilterList.java 2007-08-09 22:03:21 UTC (rev 2860) @@ -83,7 +83,7 @@ /* (non-Javadoc) * @see cfeditor.filter.Filter#match(cfeditor.GameObject) */ - public boolean match(final FilterConfig config, final GameObject gameObject) { + public boolean match(final FilterConfig config, final GameObject<?, ?, ?> gameObject) { try { if (log.isDebugEnabled()) { log.debug("match called on " + gameObject.getArchetypeName()); Modified: trunk/crossfire/src/cfeditor/filter/NamedGameObjectMatcherFilter.java =================================================================== --- trunk/crossfire/src/cfeditor/filter/NamedGameObjectMatcherFilter.java 2007-08-09 21:58:30 UTC (rev 2859) +++ trunk/crossfire/src/cfeditor/filter/NamedGameObjectMatcherFilter.java 2007-08-09 22:03:21 UTC (rev 2860) @@ -58,7 +58,7 @@ } /** {@inheritDoc} */ - public boolean match(final FilterConfig config, final GameObject gameObject) { + public boolean match(final FilterConfig config, final GameObject<?, ?, ?> gameObject) { return matcher.isMatching(gameObject); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-09-07 22:03:51
|
Revision: 2894 http://gridarta.svn.sourceforge.net/gridarta/?rev=2894&view=rev Author: akirschbaum Date: 2007-09-07 15:03:55 -0700 (Fri, 07 Sep 2007) Log Message: ----------- Remove MapViewIFrame.modelChanged(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/MapViewIFrame.java trunk/crossfire/src/cfeditor/map/MapControl.java Modified: trunk/crossfire/src/cfeditor/MapViewIFrame.java =================================================================== --- trunk/crossfire/src/cfeditor/MapViewIFrame.java 2007-09-07 22:01:58 UTC (rev 2893) +++ trunk/crossfire/src/cfeditor/MapViewIFrame.java 2007-09-07 22:03:55 UTC (rev 2894) @@ -243,10 +243,6 @@ windowAction.putValue(Action.SMALL_ICON, icon); } - public void modelChanged() { - view.modelChanged(); - } - /** * Return the Action for selecting this window. * @return the Action for selecting this window Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2007-09-07 22:01:58 UTC (rev 2893) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2007-09-07 22:03:55 UTC (rev 2894) @@ -192,7 +192,7 @@ */ public void repaint() { for (final MapViewIFrame mapViewFrame : mapViewIFrames) { - mapViewFrame.modelChanged(); + mapViewFrame.getView().modelChanged(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-09-07 22:36:42
|
Revision: 2900 http://gridarta.svn.sourceforge.net/gridarta/?rev=2900&view=rev Author: akirschbaum Date: 2007-09-07 15:36:42 -0700 (Fri, 07 Sep 2007) Log Message: ----------- Remove CMapViewBasic.modelChanged(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/map/MapControl.java Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2007-09-07 22:35:05 UTC (rev 2899) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2007-09-07 22:36:42 UTC (rev 2900) @@ -216,10 +216,6 @@ return renderer.getFullImage(); } - public void modelChanged() { - renderer.modelChanged(); - } - /** {@inheritDoc} */ public void mapSizeChanged(final MapModelEvent<GameObject, MapArchObject, Archetype> e) { mapGrid.resize(e.getMapModel().getMapSize()); Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2007-09-07 22:35:05 UTC (rev 2899) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2007-09-07 22:36:42 UTC (rev 2900) @@ -192,7 +192,7 @@ */ public void repaint() { for (final MapViewIFrame mapViewFrame : mapViewIFrames) { - mapViewFrame.getView().modelChanged(); + mapViewFrame.getView().getRenderer().modelChanged(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-09-08 15:57:48
|
Revision: 2980 http://gridarta.svn.sourceforge.net/gridarta/?rev=2980&view=rev Author: akirschbaum Date: 2007-09-08 08:57:51 -0700 (Sat, 08 Sep 2007) Log Message: ----------- Remove CMainControl.isAutoJoin(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-09-08 15:48:05 UTC (rev 2979) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-09-08 15:57:51 UTC (rev 2980) @@ -448,10 +448,6 @@ } } - public boolean isAutoJoin() { - return mainView.isAutoJoin(); - } - public void onlineHelp() { mainView.openHelpWindow(); } Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2007-09-08 15:48:05 UTC (rev 2979) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2007-09-08 15:57:51 UTC (rev 2980) @@ -107,7 +107,7 @@ return null; } - if (mainControl.isAutoJoin() && join && CMainControl.autojoinLists.getAutojoinList(archetype) != null && !archetype.isMulti()) { + if (mainControl.getMainView().isAutoJoin() && join && CMainControl.autojoinLists.getAutojoinList(archetype) != null && !archetype.isMulti()) { // do autojoining if enabled archetype = CMainControl.autojoinLists.getAutojoinList(archetype).joinInsert(this, pos); if (archetype == null) { @@ -255,7 +255,7 @@ // do autojoining final Archetype temp = getArchetype(node.getArchetypeName()); // get defarch - if (mainControl.isAutoJoin() && join && CMainControl.autojoinLists.getAutojoinList(temp) != null && !temp.isMulti()) { + if (mainControl.getMainView().isAutoJoin() && join && CMainControl.autojoinLists.getAutojoinList(temp) != null && !temp.isMulti()) { // remove connections to the deleted arch CMainControl.autojoinLists.getAutojoinList(temp).joinDelete(this, pos); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-10-10 18:36:43
|
Revision: 3203 http://gridarta.svn.sourceforge.net/gridarta/?rev=3203&view=rev Author: akirschbaum Date: 2007-10-10 11:36:44 -0700 (Wed, 10 Oct 2007) Log Message: ----------- Replace array with Set. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java trunk/crossfire/src/cfeditor/script/ScriptController.java Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2007-10-10 18:33:38 UTC (rev 3202) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2007-10-10 18:36:44 UTC (rev 3203) @@ -128,9 +128,8 @@ MenuHelper.removeAllToSeparator(menuScripts); - final String[] scripts = control.listScript(); int index = 0; - for (final String script : scripts) { + for (final String script : control.listScript()) { if (!control.getScript(script).isBash()) { continue; } Modified: trunk/crossfire/src/cfeditor/script/ScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/script/ScriptController.java 2007-10-10 18:33:38 UTC (rev 3202) +++ trunk/crossfire/src/cfeditor/script/ScriptController.java 2007-10-10 18:36:44 UTC (rev 3203) @@ -36,10 +36,12 @@ import java.io.PrintWriter; import java.io.Reader; import java.io.Writer; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import javax.swing.JFileChooser; import javax.swing.JMenu; import javax.swing.JOptionPane; @@ -123,8 +125,8 @@ view.setMenu(menuScripts); } - public String[] listScript() { - return scripts.keySet().toArray(new String[scripts.keySet().size()]); + public Set<String> listScript() { + return Collections.unmodifiableSet(scripts.keySet()); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-11-12 18:07:43
|
Revision: 3366 http://gridarta.svn.sourceforge.net/gridarta/?rev=3366&view=rev Author: akirschbaum Date: 2007-11-12 10:07:40 -0800 (Mon, 12 Nov 2007) Log Message: ----------- Unify code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/IGUIConstants.java trunk/crossfire/src/cfeditor/map/MapArchObject.java Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-11-08 22:29:58 UTC (rev 3365) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-11-12 18:07:40 UTC (rev 3366) @@ -91,6 +91,4 @@ /** The default map preview to use if no icon can be created. */ String DEFAULT_PREVIEW = "default_preview.png"; - int DIRECTIONS = 4; - } // interface IGUIConstants Modified: trunk/crossfire/src/cfeditor/map/MapArchObject.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapArchObject.java 2007-11-08 22:29:58 UTC (rev 3365) +++ trunk/crossfire/src/cfeditor/map/MapArchObject.java 2007-11-12 18:07:40 UTC (rev 3366) @@ -19,7 +19,6 @@ package cfeditor.map; -import cfeditor.IGUIConstants; import net.sf.gridarta.map.AbstractMapArchObject; import org.jetbrains.annotations.NotNull; @@ -39,7 +38,7 @@ @SuppressWarnings({"HardcodedLineSeparator"}) public final class MapArchObject extends AbstractMapArchObject<MapArchObject> { - public static final int MAX_TILE = IGUIConstants.DIRECTIONS; + public static final int MAX_TILE = 4; private final StringBuilder loreText = new StringBuilder(); // lore text buffer This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-11-21 08:29:04
|
Revision: 3422 http://gridarta.svn.sourceforge.net/gridarta/?rev=3422&view=rev Author: akirschbaum Date: 2007-11-21 00:29:02 -0800 (Wed, 21 Nov 2007) Log Message: ----------- Correctly update object choice display when switching pickmaps. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapSelectionListener.java Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2007-11-21 08:18:36 UTC (rev 3421) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2007-11-21 08:29:02 UTC (rev 3422) @@ -143,6 +143,13 @@ renderer.removeMouseMotionListener(mapUserListener); } + /** Turn the highlight off. */ + public void unHighlight() { + if (mapCursor.isActive()) { + mapCursor.deactivate(); + } + } + /** {@inheritDoc} */ @Override @Nullable public MapSquare<GameObject, MapArchObject, Archetype> getCursorSquare() { try { Modified: trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapSelectionListener.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapSelectionListener.java 2007-11-21 08:18:36 UTC (rev 3421) +++ trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapSelectionListener.java 2007-11-21 08:29:02 UTC (rev 3422) @@ -22,6 +22,7 @@ import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; import cfeditor.map.MapArchObject; +import cfeditor.map.MapControl; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import net.sf.gridarta.gui.InsertionObjectChooser; @@ -34,12 +35,20 @@ private final PickmapChooserControl control; + private final InsertionObjectChooser<GameObject, MapArchObject, Archetype> objectChooser; + public PickmapSelectionListener(final PickmapChooserControl control, final InsertionObjectChooser<GameObject, MapArchObject, Archetype> objectChooser) { this.control = control; + this.objectChooser = objectChooser; } public void stateChanged(final ChangeEvent e) { control.updateActivePickmap(); + final MapControl pickmap = control.getCurrentPickmap(); + if (pickmap != null) { + pickmap.getMapViewFrame().getView().unHighlight(); + } + objectChooser.showObjectChooserQuickObject(null); // send it to quick view } } // class PickmapSelectionListener This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-11-21 08:54:23
|
Revision: 3425 http://gridarta.svn.sourceforge.net/gridarta/?rev=3425&view=rev Author: akirschbaum Date: 2007-11-21 00:53:42 -0800 (Wed, 21 Nov 2007) Log Message: ----------- Remove unused code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/IGUIConstants.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-11-21 08:50:43 UTC (rev 3424) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-11-21 08:53:42 UTC (rev 3425) @@ -164,8 +164,6 @@ // icons for the map and arch pictures. private static ImageIcon mapSelIcon; - private static ImageIcon mapGridIcon; - private static ImageIcon mapCursorIcon; private static ImageIcon emptyTileIcon; @@ -958,7 +956,6 @@ * access. */ private static void loadDefTiles() { - mapGridIcon = GUIUtils.getSysIcon(IGUIConstants.TILE_GRID_TILE); mapSelIcon = GUIUtils.getSysIcon(IGUIConstants.TILE_SEL_TILE); mapCursorIcon = GUIUtils.getSysIcon(IGUIConstants.TILE_CURSOR); emptyTileIcon = GUIUtils.getSysIcon(IGUIConstants.TILE_EMPTY); Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-11-21 08:50:43 UTC (rev 3424) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-11-21 08:53:42 UTC (rev 3425) @@ -73,8 +73,6 @@ String RUN_PLUGIN_SMALLICON = "RunPluginSmallIcon.gif"; - String TILE_GRID_TILE = "gridtile.png"; - String TILE_SEL_TILE = "seltile.png"; String TILE_CURSOR = "cursor.png"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-11-21 09:16:56
|
Revision: 3431 http://gridarta.svn.sourceforge.net/gridarta/?rev=3431&view=rev Author: akirschbaum Date: 2007-11-21 01:17:00 -0800 (Wed, 21 Nov 2007) Log Message: ----------- Remove ArchetypeSet.getArchList(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2007-11-21 09:11:42 UTC (rev 3430) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2007-11-21 09:17:00 UTC (rev 3431) @@ -568,13 +568,4 @@ } } - /** - * Returns an array with all Archetypes. - * @return An array with all Archetypes. - */ - public Archetype[] getArchList() { - final Collection<Archetype> archetypes = getArchetypes(); - return archetypes.toArray(new Archetype[archetypes.size()]); - } - } // class ArchetypeSet Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java 2007-11-21 09:11:42 UTC (rev 3430) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java 2007-11-21 09:17:00 UTC (rev 3431) @@ -32,6 +32,7 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Arrays; +import java.util.Collection; import java.util.Comparator; import javax.swing.AbstractListModel; import javax.swing.ComboBoxEditor; @@ -288,7 +289,8 @@ private static final long serialVersionUID = 1L; public ArchComboBoxModel() { - archList = mainControl.getArchetypeSet().getArchList(); + final Collection<Archetype> archetypes = mainControl.getArchetypeSet().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()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |