From: <aki...@us...> - 2008-08-02 07:08:01
|
Revision: 4686 http://gridarta.svn.sourceforge.net/gridarta/?rev=4686&view=rev Author: akirschbaum Date: 2008-08-02 07:08:09 +0000 (Sat, 02 Aug 2008) Log Message: ----------- Move code from CFJavaEditor/DaimoninEditor to CMainControl. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFJavaEditor.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/DaimoninEditor.java Modified: trunk/crossfire/src/cfeditor/CFJavaEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/CFJavaEditor.java 2008-08-01 23:18:02 UTC (rev 4685) +++ trunk/crossfire/src/cfeditor/CFJavaEditor.java 2008-08-02 07:08:09 UTC (rev 4686) @@ -19,28 +19,19 @@ package cfeditor; -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.CMapViewBasic; -import cfeditor.map.MapArchObject; import java.awt.Component; -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.prefs.Preferences; import net.sf.gridarta.MainControl; -import net.sf.gridarta.MapManager; import net.sf.gridarta.gui.SplashScreen; -import net.sf.gridarta.gui.map.MapView; import net.sf.gridarta.preferences.FilePreferencesFactory; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.tod.TipOfTheDayManager; import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; /** * Main class, launches the level editor application. @@ -149,7 +140,7 @@ // process commandline parameters: if (inlist != null) { try { - processFile(mainControl, mainControl.getMapManager(), inlist); + mainControl.processFile(inlist); } catch (final IOException ex) { System.exit(-1); } @@ -169,46 +160,6 @@ mainControl.openFiles(infiles); } - private static void makeImage(final CMainControl mainControl, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, final File in, final File out) { - if (log.isInfoEnabled()) { - log.info("converting " + in + " to " + out); - } - - if (in.canRead()) { - final MapView<GameObject, MapArchObject, Archetype, CMapViewBasic> mapView = mapManager.openMapFileWithView(in, null); - if (mapView != null) { - mainControl.createImageWanted(mapView, out); - mapManager.closeView(mapView); - } - } - } - - private static void processFile(final CMainControl mainControl, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, final String filelist) throws IOException { - try { - final BufferedReader reader = new BufferedReader(new FileReader(filelist)); - try { - while (true) { - final String in = reader.readLine(); - final String out = reader.readLine(); - if (in == null || out == null) { - log.info("done."); - return; - } - makeImage(mainControl, mapManager, new File(in), new File(out)); - } - } catch (final IOException e) { - // XXX:cher:Getting an error and not reporting it is evil. - log.info("done."); - return; - } finally { - reader.close(); - } - } catch (final IOException e) { - log.warn("Read error: ", e); - throw e; - } - } - private static void usage() { System.out.println("usage: java -jar CrossfireEditor.jar [option...] [mapfile...]"); System.out.println(""); Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-08-01 23:18:02 UTC (rev 4685) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-08-02 07:08:09 UTC (rev 4686) @@ -37,8 +37,10 @@ import cfeditor.script.ScriptController; import cfeditor.script.parameter.PluginParameterFactory; import java.awt.Point; +import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.Collections; @@ -805,4 +807,44 @@ return mainActions; } + public void processFile(final String filelist) throws IOException { + try { + final BufferedReader reader = new BufferedReader(new FileReader(filelist)); + try { + while (true) { + final String in = reader.readLine(); + final String out = reader.readLine(); + if (in == null || out == null) { + log.info("done."); + return; + } + makeImage(new File(in), new File(out)); + } + } catch (final IOException e) { + // XXX:cher:Getting an error and not reporting it is evil. + log.info("done."); + return; + } finally { + reader.close(); + } + } catch (final IOException e) { + log.warn("Read error: ", e); + throw e; + } + } + + private void makeImage(final File in, final File out) { + if (log.isInfoEnabled()) { + log.info("converting " + in + " to " + out); + } + + if (in.canRead()) { + final MapView<GameObject, MapArchObject, Archetype, CMapViewBasic> mapView = mapManager.openMapFileWithView(in, null); + if (mapView != null) { + createImageWanted(mapView, out); + mapManager.closeView(mapView); + } + } + } + } // class CMainControl Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-08-01 23:18:02 UTC (rev 4685) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-08-02 07:08:09 UTC (rev 4686) @@ -40,12 +40,15 @@ import daieditor.map.validation.checks.SlayingChecker; import daieditor.map.validation.checks.TilePathsChecker; import java.awt.Point; +import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.MissingResourceException; import java.util.prefs.Preferences; @@ -135,6 +138,7 @@ import net.sf.gridarta.treasurelist.TreasureLocation; import net.sf.gridarta.treasurelist.TreasureTreeNode; import net.sf.gridarta.updater.UpdaterManager; +import net.sf.japi.io.args.ArgParser; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ActionMethod; import net.sf.japi.swing.prefs.PreferencesGroup; @@ -985,4 +989,92 @@ return mainActions; } + /** + * Run in batch png mode. + * @param args the argument strings that were not parsed away by {@link + * ArgParser}. + * @return return code suitable for passing to {@link System#exit(int)} + * (whether {@link System#exit(int)} is really invoked depends on + * the configuration of the {@link ArgParser}.) + * @throws Exception in case of problems during command execution. + */ + public int runBatchPng(@NotNull final List<String> args) throws Exception { + try { + for (final String arg : args) { + final File in = new File(arg); + final File out = new File(arg + ".png"); + makeImage(in, out); + } + } finally { + doExit(); + } + return 0; + } + + /** + * Run in single png mode. + * @param args the argument strings that were not parsed away by {@link + * ArgParser}. + * @return return code suitable for passing to {@link System#exit(int)} + * (whether {@link System#exit(int)} is really invoked depends on + * the configuration of the {@link ArgParser}.) + * @throws Exception in case of problems during command execution. + */ + public int runSinglePng(@NotNull final List<String> args) throws Exception { + try { + if (args.size() != 2) { + System.err.println("Usage: -s input output"); + return 1; + } + + final File in = new File(args.get(0)); + final File out = new File(args.get(1)); + makeImage(in, out); + } finally { + doExit(); + } + return 0; + } + + private void processFile(final String filelist) { + try { + final BufferedReader reader = new BufferedReader(new FileReader(filelist)); + try { + while (true) { + final String in = reader.readLine(); + final String out = reader.readLine(); + if (in == null || out == null) { + log.info("done."); + System.exit(0); + } + makeImage(new File(in), new File(out)); + } + } catch (final IOException e) { + // XXX:cher:Getting an error and not reporting it is evil. + log.info("done."); + System.exit(0); + } finally { + reader.close(); + } + } catch (final IOException e) { + log.warn("Read error: ", e); + System.exit(-1); + } + System.exit(0); + } + + private void makeImage(final File in, final File out) { + if (log.isInfoEnabled()) { + log.info("converting " + in + " to " + out); + } + + if (in.canRead()) { + final MapView<GameObject, MapArchObject, Archetype, CMapViewBasic> mapView = mapManager.openMapFileWithView(in, null); + if (mapView != null) { + createImageWanted(mapView, out); + mapManager.closeView(mapView); + } + } + } + } // class CMainControl Modified: trunk/daimonin/src/daieditor/DaimoninEditor.java =================================================================== --- trunk/daimonin/src/daieditor/DaimoninEditor.java 2008-08-01 23:18:02 UTC (rev 4685) +++ trunk/daimonin/src/daieditor/DaimoninEditor.java 2008-08-02 07:08:09 UTC (rev 4686) @@ -19,24 +19,14 @@ package daieditor; -import daieditor.gameobject.Archetype; -import daieditor.gameobject.GameObject; -import daieditor.gui.map.CMapViewBasic; -import daieditor.map.MapArchObject; import java.awt.Component; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; import java.util.List; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.prefs.Preferences; import net.sf.gridarta.MainControl; -import net.sf.gridarta.MapManager; import net.sf.gridarta.gui.SplashScreen; -import net.sf.gridarta.gui.map.MapView; import net.sf.japi.io.args.ArgParser; import net.sf.japi.io.args.BasicCommand; import net.sf.japi.io.args.Option; @@ -94,47 +84,6 @@ ArgParser.simpleParseAndRun(new DaimoninEditor(), args); } - private static void makeImage(final CMainControl mainControl, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, final File in, final File out) { - if (log.isInfoEnabled()) { - log.info("converting " + in + " to " + out); - } - - if (in.canRead()) { - final MapView<GameObject, MapArchObject, Archetype, CMapViewBasic> mapView = mapManager.openMapFileWithView(in, null); - if (mapView != null) { - mainControl.createImageWanted(mapView, out); - mapManager.closeView(mapView); - } - } - } - - private static void processFile(final CMainControl mainControl, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, final String filelist) { - try { - final BufferedReader reader = new BufferedReader(new FileReader(filelist)); - try { - while (true) { - final String in = reader.readLine(); - final String out = reader.readLine(); - if (in == null || out == null) { - log.info("done."); - System.exit(0); - } - makeImage(mainControl, mapManager, new File(in), new File(out)); - } - } catch (final IOException e) { - // XXX:cher:Getting an error and not reporting it is evil. - log.info("done."); - System.exit(0); - } finally { - reader.close(); - } - } catch (final IOException e) { - log.warn("Read error: ", e); - System.exit(-1); - } - System.exit(0); - } - /** Sets the mode to normal. This is the default. */ @Option({"n", "normal"}) public void setNormal() { @@ -184,9 +133,9 @@ case NORMAL: return runNormal(args); case BATCH_PNG: - return runBatchPng(args); + return mainControl.runBatchPng(args); case SINGLE_PNG: - return runSinglePng(args); + return mainControl.runSinglePng(args); case COLLECT_ARCHES: return runCollectArches(args); case CREATE_THUMBS: @@ -217,53 +166,6 @@ } /** - * Run in batch png mode. - * @param args the argument strings that were not parsed away by {@link - * ArgParser}. - * @return return code suitable for passing to {@link System#exit(int)} - * (whether {@link System#exit(int)} is really invoked depends on - * the configuration of the {@link ArgParser}.) - * @throws Exception in case of problems during command execution. - */ - private int runBatchPng(@NotNull final List<String> args) throws Exception { - try { - for (final String arg : args) { - final File in = new File(arg); - final File out = new File(arg + ".png"); - makeImage(mainControl, mainControl.getMapManager(), in, out); - } - } finally { - mainControl.doExit(); - } - return 0; - } - - /** - * Run in single png mode. - * @param args the argument strings that were not parsed away by {@link - * ArgParser}. - * @return return code suitable for passing to {@link System#exit(int)} - * (whether {@link System#exit(int)} is really invoked depends on - * the configuration of the {@link ArgParser}.) - * @throws Exception in case of problems during command execution. - */ - private int runSinglePng(@NotNull final List<String> args) throws Exception { - try { - if (args.size() != 2) { - System.err.println("Usage: -s input output"); - return 1; - } - - final File in = new File(args.get(0)); - final File out = new File(args.get(1)); - makeImage(mainControl, mainControl.getMapManager(), in, out); - } finally { - mainControl.doExit(); - } - return 0; - } - - /** * Run in collect arches mode. * @param args the argument strings that were not parsed away by {@link * ArgParser}. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |