2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
* You should have received a copy of the GNU General Public License
11
* along with this program; if not, write to the Free Software
12
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
package games.strategy.triplea.ui.screen;
17
import java.awt.image.BufferedImage;
19
import java.util.logging.*;
21
import games.strategy.engine.data.*;
22
import games.strategy.triplea.ui.MapData;
23
import games.strategy.triplea.util.Stopwatch;
24
import games.strategy.ui.ImageScrollerSmallView;
25
import games.strategy.ui.Util;
31
* @author Sean Bridges
33
public class SmallMapImageManager
35
private static final Logger s_logger = Logger.getLogger(SmallMapImageManager.class.getName());
36
private final int UNIT_BOX_SIZE = 4;
38
private final ImageScrollerSmallView m_view;
39
private final Image m_offscreen;
40
private final TileManager m_tileManager;
43
public SmallMapImageManager(final ImageScrollerSmallView view, BufferedImage offscreen, TileManager tileManager)
46
m_offscreen = Util.copyImage(offscreen, false);
47
m_tileManager = tileManager;
50
public void update(GameData data, MapData mapData)
52
Stopwatch stopwatch = new Stopwatch(s_logger, Level.FINEST, "Small map updating took");
54
Graphics onScreenGraphics = m_view.getOffScreenImage().getGraphics();
56
onScreenGraphics.drawImage(m_offscreen, 0,0,null);
59
Iterator<UnitsDrawer> iter = new ArrayList<UnitsDrawer>(m_tileManager.getUnitDrawables()).iterator();
60
while (iter.hasNext())
62
UnitsDrawer drawer = iter.next();
63
int x = (int) (drawer.getPlacementPoint().x * m_view.getRatioX());
64
int y = (int) (drawer.getPlacementPoint().y * m_view.getRatioY());
66
onScreenGraphics.setColor(mapData.getPlayerColor(drawer.getPlayer()).darker() );
67
onScreenGraphics.fillRect(x,y, UNIT_BOX_SIZE, UNIT_BOX_SIZE);
70
onScreenGraphics.dispose();
75
public void updateTerritoryOwner(Territory t, GameData data, MapData mapData)
80
Rectangle bounds = new Rectangle(mapData.getBoundingRect(t.getName()));
82
//create a large image for the territory
83
Image largeImage = Util.createImage(bounds.width, bounds.height, true);
85
// make it transparent
86
//http://www-106.ibm.com/developerworks/library/j-begjava/
88
Graphics2D g = (Graphics2D) largeImage.getGraphics();
89
g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
90
g.setColor(new Color(0));
91
g.fillRect(0, 0, bounds.width, bounds.height);
97
Graphics g = largeImage.getGraphics();
98
LandTerritoryDrawable drawable = new LandTerritoryDrawable(t.getName());
99
drawable.draw(bounds, data, (Graphics2D)g , mapData, null, null);
104
int thumbWidth = (int) (bounds.width * m_view.getRatioX()) ;
105
int thumbHeight = (int) (bounds.height * m_view.getRatioY());
107
//make the image a little bigger
108
//the images wont overlap perfectly after being scaled, make them a little bigger to rebalance that
112
int thumbsX = (int) ( bounds.x * m_view.getRatioX()) -1;
113
int thumbsY = (int) ( bounds.y * m_view.getRatioY()) -1;
116
//create the thumb image
117
Image thumbImage = Util.createImage( thumbWidth, thumbHeight , true);
119
Graphics g = thumbImage.getGraphics();
120
g.drawImage(largeImage, 0,0, thumbImage.getWidth(null), thumbImage.getHeight(null), null);
125
Graphics g = m_offscreen.getGraphics();
126
//draw it on our offscreen
127
g.drawImage( thumbImage,
130
thumbImage.getWidth(null),
131
thumbImage.getHeight(null),