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.var.atrinik.gui.map.renderer; 021 022import java.awt.Graphics2D; 023import java.util.Locale; 024import javax.swing.Icon; 025import net.sf.gridarta.gui.filter.FilterControl; 026import net.sf.gridarta.gui.map.renderer.GridMapSquarePainter; 027import net.sf.gridarta.gui.map.renderer.IsoMapRenderer; 028import net.sf.gridarta.model.archetype.TestArchetype; 029import net.sf.gridarta.model.gameobject.IsoMapSquareInfo; 030import net.sf.gridarta.model.gameobject.MultiPositionData; 031import net.sf.gridarta.model.gameobject.TestGameObject; 032import net.sf.gridarta.model.io.GameObjectParser; 033import net.sf.gridarta.model.maparchobject.TestMapArchObject; 034import net.sf.gridarta.model.mapgrid.MapGrid; 035import net.sf.gridarta.model.mapmodel.MapModel; 036import net.sf.gridarta.model.mapviewsettings.MapViewSettings; 037import net.sf.gridarta.utils.ResourceIcons; 038import org.jetbrains.annotations.NotNull; 039 040/** 041 * An {@link IsoMapRenderer} for regression tests. It records all painting 042 * operations. 043 * @author Andreas Kirschbaum 044 */ 045public class TestMapRenderer extends IsoMapRenderer<TestGameObject, TestMapArchObject, TestArchetype> { 046 047 /** 048 * The serial version UID. 049 */ 050 private static final long serialVersionUID = 1L; 051 052 /** 053 * The string builder that collects all paint operations. 054 */ 055 @NotNull 056 private final StringBuilder sb = new StringBuilder(); 057 058 /** 059 * Creates a new instance. 060 * @param mapViewSettings the map view settings instance to use 061 * @param filterControl the filter to use 062 * @param mapModel the map model to render 063 * @param mapGrid the grid to render 064 * @param multiPositionData the multi position data to query for multi-part 065 * objects 066 * @param isoMapSquareInfo the iso square info to use 067 * @param gridMapSquarePainter the grid square painter to use 068 * @param gameObjectParser the game object parser for creating tooltip 069 * information 070 * @param resourceIcons the resource icons for creating icons 071 */ 072 public TestMapRenderer(@NotNull final MapViewSettings mapViewSettings, @NotNull final FilterControl<TestGameObject, TestMapArchObject, TestArchetype> filterControl, @NotNull final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel, @NotNull final MapGrid mapGrid, @NotNull final MultiPositionData multiPositionData, @NotNull final IsoMapSquareInfo isoMapSquareInfo, @NotNull final GridMapSquarePainter gridMapSquarePainter, @NotNull final GameObjectParser<TestGameObject, TestMapArchObject, TestArchetype> gameObjectParser, @NotNull final ResourceIcons resourceIcons) { 073 super(100, mapViewSettings, filterControl, mapModel, mapGrid, multiPositionData, isoMapSquareInfo, gridMapSquarePainter, gameObjectParser, resourceIcons); 074 } 075 076 /** 077 * {@inheritDoc} 078 * @noinspection RefusedBequest 079 */ 080 @Override 081 protected void paintIcon(@NotNull final Graphics2D g, @NotNull final Icon icon) { 082 final double[] matrix = new double[6]; 083 g.getTransform().getMatrix(matrix); 084 appendDouble(matrix[0]); 085 sb.append(' '); 086 appendDouble(matrix[1]); 087 sb.append(' '); 088 appendDouble(matrix[2]); 089 sb.append(' '); 090 appendDouble(matrix[3]); 091 sb.append(' '); 092 appendDouble(matrix[4]); 093 sb.append(' '); 094 appendDouble(matrix[5]); 095 sb.append('\n'); 096 } 097 098 /** 099 * Appends a <code>double></code> value to {@link #sb}. 100 * @param value the double value 101 */ 102 private void appendDouble(final double value) { 103 sb.append(String.format((Locale) null, "%.03g", value)); 104 } 105 106 /** 107 * Returns and clears the accumulated painting operations. 108 * @return the painting operations 109 */ 110 @NotNull 111 public String getPaintingOperations() { 112 final String result = sb.toString(); 113 sb.setLength(0); 114 return result; 115 } 116 117}