From: <aki...@us...> - 2008-07-25 21:01:02
|
Revision: 4446 http://gridarta.svn.sourceforge.net/gridarta/?rev=4446&view=rev Author: akirschbaum Date: 2008-07-25 21:01:08 +0000 (Fri, 25 Jul 2008) Log Message: ----------- Extract singleton instance handling into CMainControlInstance. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFJavaEditor.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CrossfireObjectsFactory.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java trunk/crossfire/src/cfeditor/script/parameter/ArchParameter.java trunk/crossfire/src/cfeditor/script/parameter/MapParameter.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/DaimoninObjectsFactory.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Added Paths: ----------- trunk/crossfire/src/cfeditor/CMainControlInstance.java trunk/daimonin/src/daieditor/CMainControlInstance.java Modified: trunk/crossfire/src/cfeditor/CFJavaEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/CFJavaEditor.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/crossfire/src/cfeditor/CFJavaEditor.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -135,7 +135,7 @@ // Create the application and give it the parameters final CMainControl mainControl; try { - mainControl = new CMainControl(); + mainControl = CMainControlInstance.getInstance(); } catch (final RuntimeException ex) { log.fatal(ex.getMessage(), ex); System.exit(1); Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -142,9 +142,6 @@ /** Preferences. */ private static final Preferences prefs = Preferences.userNodeForPackage(MainControl.class); - /** Singleton instance reference. */ - private static CMainControl instance; - /** Preferences key for using System.exit(). */ public static final String PREFS_SYSTEM_EXIT = "systemExit"; @@ -216,7 +213,6 @@ */ public CMainControl() { super(new CrossfireObjectsFactory(), "cfeditor"); - instance = this; animationObjects = new cfeditor.gameobject.anim.AnimationObjects(); archetypeSet = new ArchetypeSet(this, animationObjects, faceObjects); scriptControl = new ScriptController(this); @@ -436,14 +432,6 @@ } /** - * Get the static instance of CMainControl. - * @return static instance of this class - */ - public static CMainControl getInstance() { - return instance; - } - - /** * Get the Animation Objects. * @return animationObjects */ Added: trunk/crossfire/src/cfeditor/CMainControlInstance.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControlInstance.java (rev 0) +++ trunk/crossfire/src/cfeditor/CMainControlInstance.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -0,0 +1,46 @@ +/* + * 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; + +/** + * Utility class managing the {@link CMainControl} singleton. + * @author Andreas Kirschbaum + */ +public class CMainControlInstance { + + /** + * The singleton instance. + */ + private static CMainControl instance = null; + + /** + * Private constructor to prevent instantiation. + */ + private CMainControlInstance() { + } + + public static synchronized CMainControl getInstance() { + if (instance == null) { + instance = new CMainControl(); + } + return instance; + } + +} // class CMainControlInstance Property changes on: trunk/crossfire/src/cfeditor/CMainControlInstance.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/crossfire/src/cfeditor/CrossfireObjectsFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/CrossfireObjectsFactory.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/crossfire/src/cfeditor/CrossfireObjectsFactory.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -95,7 +95,7 @@ /** {@inheritDoc} */ @NotNull public MapReader<GameObject, MapArchObject> newMapReader(@NotNull final File file) throws FileNotFoundException { - return new DefaultMapReader<GameObject, MapArchObject, Archetype>(CMainControl.getInstance(), file); + return new DefaultMapReader<GameObject, MapArchObject, Archetype>(CMainControlInstance.getInstance(), file); } /** {@inheritDoc} */ @@ -117,13 +117,13 @@ /** {@inheritDoc} */ @NotNull public MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> newMapControl(@Nullable final List<GameObject> objects, @NotNull final MapArchObject mapArchObject) { - return new DefaultMapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(this, CMainControl.getInstance(), objects, mapArchObject, false, GameObjectMatchersInstance.getInstance().getMatcher("exit"), archetypeChooserControl); + return new DefaultMapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(this, CMainControlInstance.getInstance(), objects, mapArchObject, false, GameObjectMatchersInstance.getInstance().getMatcher("exit"), archetypeChooserControl); } /** {@inheritDoc} */ @NotNull public MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> newPickmapControl(@Nullable final List<GameObject> objects, @NotNull final MapArchObject mapArchObject) { - return new DefaultMapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(this, CMainControl.getInstance(), objects, mapArchObject, true, GameObjectMatchersInstance.getInstance().getMatcher("exit"), archetypeChooserControl); + return new DefaultMapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(this, CMainControlInstance.getInstance(), objects, mapArchObject, true, GameObjectMatchersInstance.getInstance().getMatcher("exit"), archetypeChooserControl); } /** {@inheritDoc} */ @@ -135,7 +135,7 @@ /** {@inheritDoc} */ @NotNull public MapView<GameObject, MapArchObject, Archetype, CMapViewBasic> newMapView(@NotNull final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl, @Nullable final Point viewPosition, final int viewCounter) { - return new MapView<GameObject, MapArchObject, Archetype, CMapViewBasic>((MainControl<GameObject, MapArchObject, Archetype, CMapViewBasic>) (MainControl) AbstractMainControl.getInstance(), mapControl, viewCounter, new CMapViewBasic(CMainControl.getInstance(), mapControl, viewPosition, ((DefaultObjectChooser<GameObject, MapArchObject, Archetype, CMapViewBasic>) objectChooser).getToolSelectorPane(), 32, 32, selectedSquareView), ACTION_FACTORY); + return new MapView<GameObject, MapArchObject, Archetype, CMapViewBasic>((MainControl<GameObject, MapArchObject, Archetype, CMapViewBasic>) (MainControl) AbstractMainControl.getInstance(), mapControl, viewCounter, new CMapViewBasic(CMainControlInstance.getInstance(), mapControl, viewPosition, ((DefaultObjectChooser<GameObject, MapArchObject, Archetype, CMapViewBasic>) objectChooser).getToolSelectorPane(), 32, 32, selectedSquareView), ACTION_FACTORY); } /** {@inheritDoc} */ Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -19,7 +19,7 @@ package cfeditor.gameobject.scripts; -import cfeditor.CMainControl; +import cfeditor.CMainControlInstance; import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; @@ -172,7 +172,7 @@ if (eventArchetypeName == null) { throw new UndefinedEventArchetypeTypeException(eventType); } - final Archetype eventArchetype = CMainControl.getInstance().getArchetypeSet().getArchetype(eventArchetypeName); + final Archetype eventArchetype = CMainControlInstance.getInstance().getArchetypeSet().getArchetype(eventArchetypeName); if (eventArchetype == null) { throw new UndefinedEventArchetypeNameException(eventArchetypeName); } Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/ArchComboBox.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -20,6 +20,7 @@ package cfeditor.gui.script.parameter; import cfeditor.CMainControl; +import cfeditor.CMainControlInstance; import cfeditor.gameobject.Archetype; import java.awt.Color; import java.awt.Component; @@ -67,7 +68,7 @@ public ArchComboBox() { setMaximumRowCount(4); - mainControl = CMainControl.getInstance(); + mainControl = CMainControlInstance.getInstance(); final MyCellRenderer renderer = new MyCellRenderer(); archComboBoxEditor = new ArchComboBoxEditor(); //setPrototypeDisplayValue(renderer.sizeTester); Modified: trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/crossfire/src/cfeditor/gui/script/parameter/MapParameterView.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -20,6 +20,7 @@ package cfeditor.gui.script.parameter; import cfeditor.CMainControl; +import cfeditor.CMainControlInstance; import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; import cfeditor.gui.map.CMapViewBasic; @@ -127,7 +128,7 @@ @Override public int getIndexOf(final Object anObject) { - final List<MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>> maps = CMainControl.getInstance().getMapManager().getOpenedMaps(); + final List<MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>> maps = CMainControlInstance.getInstance().getMapManager().getOpenedMaps(); if (anObject == currentMap) { return 0; } Modified: trunk/crossfire/src/cfeditor/script/parameter/ArchParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/script/parameter/ArchParameter.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/crossfire/src/cfeditor/script/parameter/ArchParameter.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -19,7 +19,7 @@ package cfeditor.script.parameter; -import cfeditor.CMainControl; +import cfeditor.CMainControlInstance; import cfeditor.gameobject.Archetype; import cfeditor.gameobject.ArchetypeSet; import cfeditor.gui.script.parameter.ArchParameterView; @@ -30,7 +30,7 @@ public class ArchParameter extends PluginParameter { @NotNull - private final ArchetypeSet archetypeSet = CMainControl.getInstance().getArchetypeSet(); + private final ArchetypeSet archetypeSet = CMainControlInstance.getInstance().getArchetypeSet(); private String valueString; Modified: trunk/crossfire/src/cfeditor/script/parameter/MapParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/script/parameter/MapParameter.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/crossfire/src/cfeditor/script/parameter/MapParameter.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -20,6 +20,7 @@ package cfeditor.script.parameter; import cfeditor.CMainControl; +import cfeditor.CMainControlInstance; import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; import cfeditor.gui.map.CMapViewBasic; @@ -69,7 +70,7 @@ return CMainControl.getInstance().getMapManager().getCurrentMap(); } - for (final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl : CMainControl.getInstance().getMapManager().getOpenedMaps()) { + for (final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl : CMainControlInstance.getInstance().getMapManager().getOpenedMaps()) { if (mapControl.getMapFileName().equalsIgnoreCase(s)) { return mapControl; } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -162,9 +162,6 @@ /** Preferences. */ private static final Preferences prefs = Preferences.userNodeForPackage(MainControl.class); - /** Singleton instance reference. */ - private static CMainControl instance; - /** Preferences key for using System.exit(). */ public static final String PREFS_SYSTEM_EXIT = "systemExit"; @@ -272,7 +269,6 @@ */ public CMainControl() { super(new DaimoninObjectsFactory(), "daieditor"); - instance = this; animationObjects = new daieditor.gameobject.anim.AnimationObjects(); archetypeSet = new ArchetypeSet(this, animationObjects, faceObjects); final boolean mapTileListBottom = prefs.getBoolean(MainView.MAP_TILE_LIST_BOTTOM_KEY, MainView.MAP_TILE_LIST_BOTTOM_DEFAULT); @@ -528,14 +524,6 @@ } /** - * Get the static instance of CMainControl. - * @return static instance of this class - */ - public static CMainControl getInstance() { - return instance; - } - - /** * Whether to use double display like the client with walls. * @return <code>true</code> if double display should be used, otherwise * <code>false</code> Added: trunk/daimonin/src/daieditor/CMainControlInstance.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControlInstance.java (rev 0) +++ trunk/daimonin/src/daieditor/CMainControlInstance.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -0,0 +1,46 @@ +/* + * 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 daieditor; + +/** + * Utility class managing the {@link CMainControl} singleton. + * @author Andreas Kirschbaum + */ +public class CMainControlInstance { + + /** + * The singleton instance. + */ + private static CMainControl instance = null; + + /** + * Private constructor to prevent instantiation. + */ + private CMainControlInstance() { + } + + public static synchronized CMainControl getInstance() { + if (instance == null) { + instance = new CMainControl(); + } + return instance; + } + +} // class CMainControlInstance Property changes on: trunk/daimonin/src/daieditor/CMainControlInstance.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/DaimoninObjectsFactory.java =================================================================== --- trunk/daimonin/src/daieditor/DaimoninObjectsFactory.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/daimonin/src/daieditor/DaimoninObjectsFactory.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -98,7 +98,7 @@ /** {@inheritDoc} */ @NotNull public MapReader<GameObject, MapArchObject> newMapReader(@NotNull final File file) throws FileNotFoundException { - return new DefaultMapReader<GameObject, MapArchObject, Archetype>(CMainControl.getInstance(), file); + return new DefaultMapReader<GameObject, MapArchObject, Archetype>(CMainControlInstance.getInstance(), file); } /** {@inheritDoc} */ @@ -120,13 +120,13 @@ /** {@inheritDoc} */ @NotNull public MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> newMapControl(@Nullable final List<GameObject> objects, @NotNull final MapArchObject mapArchObject) { - return new DefaultMapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(this, CMainControl.getInstance(), objects, mapArchObject, false, GameObjectMatchersInstance.getInstance().getMatcher("exit"), archetypeChooserControl); + return new DefaultMapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(this, CMainControlInstance.getInstance(), objects, mapArchObject, false, GameObjectMatchersInstance.getInstance().getMatcher("exit"), archetypeChooserControl); } /** {@inheritDoc} */ @NotNull public MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> newPickmapControl(@Nullable final List<GameObject> objects, @NotNull final MapArchObject mapArchObject) { - final DefaultMapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl = new DefaultMapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(this, CMainControl.getInstance(), objects, mapArchObject, true, GameObjectMatchersInstance.getInstance().getMatcher("exit"), archetypeChooserControl); + final DefaultMapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl = new DefaultMapControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(this, CMainControlInstance.getInstance(), objects, mapArchObject, true, GameObjectMatchersInstance.getInstance().getMatcher("exit"), archetypeChooserControl); mapArchObject.setDifficulty(1); return mapControl; } @@ -140,7 +140,7 @@ /** {@inheritDoc} */ @NotNull public MapView<GameObject, MapArchObject, Archetype, CMapViewBasic> newMapView(@NotNull final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl, @Nullable final Point viewPosition, final int viewCounter) { - return new MapView<GameObject, MapArchObject, Archetype, CMapViewBasic>((MainControl<GameObject, MapArchObject, Archetype, CMapViewBasic>) (MainControl) AbstractMainControl.getInstance(), mapControl, viewCounter, new CMapViewBasic(CMainControl.getInstance(), mapControl, viewPosition, faceObjects, ((DefaultObjectChooser<GameObject, MapArchObject, Archetype, CMapViewBasic>) objectChooser).getToolSelectorPane(), IGUIConstants.TILE_ISO_XLEN, IGUIConstants.TILE_ISO_YLEN, selectedSquareView), ACTION_FACTORY); + return new MapView<GameObject, MapArchObject, Archetype, CMapViewBasic>((MainControl<GameObject, MapArchObject, Archetype, CMapViewBasic>) (MainControl) AbstractMainControl.getInstance(), mapControl, viewCounter, new CMapViewBasic(CMainControlInstance.getInstance(), mapControl, viewPosition, faceObjects, ((DefaultObjectChooser<GameObject, MapArchObject, Archetype, CMapViewBasic>) objectChooser).getToolSelectorPane(), IGUIConstants.TILE_ISO_XLEN, IGUIConstants.TILE_ISO_YLEN, selectedSquareView), ACTION_FACTORY); } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -19,7 +19,7 @@ package daieditor.gameobject; -import daieditor.CMainControl; +import daieditor.CMainControlInstance; import daieditor.gameobject.anim.AnimationObject; import daieditor.gameobject.scripts.ScriptArchData; import daieditor.map.MapArchObject; @@ -204,7 +204,7 @@ @Nullable String effectiveFaceObjName; if (effectiveAnimName != null) { // we have a animation - get the frame picture - final AnimationObjects<AnimationObject> animationObjects = CMainControl.getInstance().getAnimationObjects(); + final AnimationObjects<AnimationObject> animationObjects = CMainControlInstance.getInstance().getAnimationObjects(); final AnimationObject animationObject = animationObjects.get(effectiveAnimName); if (animationObject != null) { noface = false; @@ -252,8 +252,8 @@ * rendering. */ private void setFace() { - normalFace = CMainControl.getInstance().getArchetypeSet().getFace(this); - transFace = CMainControl.getInstance().getArchetypeSet().getTrans(this); + normalFace = CMainControlInstance.getInstance().getArchetypeSet().getFace(this); + transFace = CMainControlInstance.getInstance().getArchetypeSet().getTrans(this); } /** Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-07-25 20:58:59 UTC (rev 4445) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-07-25 21:01:08 UTC (rev 4446) @@ -19,7 +19,7 @@ package daieditor.gameobject.scripts; -import daieditor.CMainControl; +import daieditor.CMainControlInstance; import daieditor.gameobject.Archetype; import daieditor.gameobject.GameObject; import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; @@ -168,7 +168,7 @@ if (eventArchetypeName == null) { throw new UndefinedEventArchetypeTypeException(eventType); } - final Archetype eventArchetype = CMainControl.getInstance().getArchetypeSet().getArchetype(eventArchetypeName); + final Archetype eventArchetype = CMainControlInstance.getInstance().getArchetypeSet().getArchetype(eventArchetypeName); if (eventArchetype == null) { throw new UndefinedEventArchetypeNameException(eventArchetypeName); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |