001/* 002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. 003 * Copyright (C) 2000-2011 The Gridarta Developers. 004 * 005 * This program is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation; either version 2 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License along 016 * with this program; if not, write to the Free Software Foundation, Inc., 017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 018 */ 019 020package net.sf.gridarta.gui.map.test; 021 022import java.awt.Image; 023import java.awt.image.BufferedImage; 024import net.sf.gridarta.gui.copybuffer.CopyBuffer; 025import net.sf.gridarta.gui.map.mapview.MapView; 026import net.sf.gridarta.gui.map.mapview.MapViewFactory; 027import net.sf.gridarta.gui.map.mapview.MapViewsManager; 028import net.sf.gridarta.gui.map.mapview.TestMapView; 029import net.sf.gridarta.gui.map.mapview.TestMapViewFactory; 030import net.sf.gridarta.gui.map.renderer.RendererFactory; 031import net.sf.gridarta.gui.map.renderer.TestRendererFactory; 032import net.sf.gridarta.gui.mapimagecache.MapImageCache; 033import net.sf.gridarta.model.archetype.TestArchetype; 034import net.sf.gridarta.model.gameobject.TestGameObject; 035import net.sf.gridarta.model.io.CacheFiles; 036import net.sf.gridarta.model.io.TestCacheFiles; 037import net.sf.gridarta.model.maparchobject.TestMapArchObject; 038import net.sf.gridarta.model.mapcontrol.MapControl; 039import net.sf.gridarta.model.mapcontrol.TestMapControlCreator; 040import net.sf.gridarta.model.mapcursor.MapCursor; 041import net.sf.gridarta.model.mapgrid.MapGrid; 042import net.sf.gridarta.model.mapmodel.MapModel; 043import net.sf.gridarta.model.mapmodel.TestMapModelCreator; 044import org.jetbrains.annotations.NotNull; 045 046/** 047 * Helper class for creating {@link MapControl} instances for regression tests. 048 * @author Andreas Kirschbaum 049 */ 050public class TestMapControlCreatorUtils { 051 052 /** 053 * Private constructor to prevent instantiation. 054 */ 055 private TestMapControlCreatorUtils() { 056 } 057 058 /** 059 * Creates a new {@link MapView} instance. 060 * @param mapControl the associated map control 061 * @return the map view instance 062 */ 063 @NotNull 064 public static MapView<TestGameObject, TestMapArchObject, TestArchetype> newMapView(@NotNull final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl) { 065 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 066 final MapGrid mapGrid = new MapGrid(mapModel.getMapArchObject().getMapSize()); 067 return new TestMapView(mapControl, mapGrid, new MapCursor<TestGameObject, TestMapArchObject, TestArchetype>(mapGrid, mapModel)); 068 } 069 070 /** 071 * Returns a new {@link CopyBuffer} instance. 072 * @param mapControlCreator the map control creator 073 * @return the copy buffer instance 074 */ 075 @NotNull 076 public static CopyBuffer<TestGameObject, TestMapArchObject, TestArchetype> newCopyBuffer(@NotNull final TestMapControlCreator mapControlCreator) { 077 final TestMapModelCreator mapModelCreator = mapControlCreator.getMapModelCreator(); 078 return new CopyBuffer<TestGameObject, TestMapArchObject, TestArchetype>(mapModelCreator.getMapViewSettings(), mapModelCreator.getGameObjectFactory(), mapControlCreator.getMapArchObjectFactory(), mapControlCreator.getMapModelFactory(), mapModelCreator.getInsertionModeSet()); 079 } 080 081 /** 082 * Creates a new {@link MapViewsManager} instance. 083 * @param mapControlCreator the map control creator 084 * @return the map views manager instance 085 */ 086 @NotNull 087 public static MapViewsManager<TestGameObject, TestMapArchObject, TestArchetype> newMapViewsManager(@NotNull final TestMapControlCreator mapControlCreator) { 088 final MapViewFactory<TestGameObject, TestMapArchObject, TestArchetype> mapViewFactory = new TestMapViewFactory(); 089 return new MapViewsManager<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getMapModelCreator().getMapViewSettings(), mapViewFactory, mapControlCreator.getMapManager(), mapControlCreator.getPickmapManager()); 090 } 091 092 /** 093 * Creates a new {@link MapImageCache} instance. 094 * @param mapControlCreator the map control creator 095 * @return the map image cache instance 096 */ 097 @NotNull 098 public static MapImageCache<TestGameObject, TestMapArchObject, TestArchetype> newMapImageCache(@NotNull final TestMapControlCreator mapControlCreator) { 099 final RendererFactory<TestGameObject, TestMapArchObject, TestArchetype> rendererFactory = new TestRendererFactory(); 100 final Image defaultIcon = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); 101 final Image defaultPreview = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); 102 final CacheFiles cacheFiles = new TestCacheFiles(); 103 return new MapImageCache<TestGameObject, TestMapArchObject, TestArchetype>(mapControlCreator.getMapManager(), defaultIcon, defaultPreview, rendererFactory, cacheFiles); 104 } 105 106}