Commit 1a52704a authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Removed some resource-hungry map repainting

parent 701b08e7
...@@ -24,6 +24,7 @@ import java.awt.AlphaComposite; ...@@ -24,6 +24,7 @@ import java.awt.AlphaComposite;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Image; import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
...@@ -47,6 +48,8 @@ public class ShowMapQuestMapViz extends JComponent ...@@ -47,6 +48,8 @@ public class ShowMapQuestMapViz extends JComponent
private String mapType; private String mapType;
private String mapQuestKey; private String mapQuestKey;
private BufferedImage background = null;
private boolean initialized = false; private boolean initialized = false;
...@@ -96,6 +99,24 @@ public class ShowMapQuestMapViz extends JComponent ...@@ -96,6 +99,24 @@ public class ShowMapQuestMapViz extends JComponent
} }
} }
initialized = true; initialized = true;
// Create a media tracker and add the image to it. If we had several
// images to load, they could all be added to the same media tracker.
MediaTracker tracker = new MediaTracker(this);
Image image = Toolkit.getDefaultToolkit().getImage(tempImageFilePath);
tracker.addImage(image, 0);
// Start downloading the image and wait until it finishes loading.
try {
tracker.waitForAll();
} catch(InterruptedException e) {
// help?
}
background = resize(
Toolkit.getDefaultToolkit().getImage(tempImageFilePath),
VisualizationInjector.getWorldX(),
VisualizationInjector.getWorldY());
} }
} }
...@@ -109,11 +130,9 @@ public class ShowMapQuestMapViz extends JComponent ...@@ -109,11 +130,9 @@ public class ShowMapQuestMapViz extends JComponent
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
g2.setComposite( g2.setComposite(
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f)); AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
Image imageToDraw = resize( if (background != null) {
Toolkit.getDefaultToolkit().getImage(tempImageFilePath), g2.drawImage(background, 0, 0, this);
VisualizationInjector.getWorldX(), }
VisualizationInjector.getWorldY());
g2.drawImage(imageToDraw, 0, 0, this);
} }
public void setTempImageFilePath(String tempImageFilePath) { public void setTempImageFilePath(String tempImageFilePath) {
...@@ -135,7 +154,7 @@ public class ShowMapQuestMapViz extends JComponent ...@@ -135,7 +154,7 @@ public class ShowMapQuestMapViz extends JComponent
* @param width * @param width
* @param height * @param height
*/ */
private Image resize(Image originalImage, int width, int height) { private BufferedImage resize(Image originalImage, int width, int height) {
int type = BufferedImage.TYPE_INT_ARGB; int type = BufferedImage.TYPE_INT_ARGB;
BufferedImage resizedImage = new BufferedImage(width, height, type); BufferedImage resizedImage = new BufferedImage(width, height, type);
Graphics2D g = resizedImage.createGraphics(); Graphics2D g = resizedImage.createGraphics();
......
...@@ -432,7 +432,7 @@ public class VisualizationTopologyView extends JFrame ...@@ -432,7 +432,7 @@ public class VisualizationTopologyView extends JFrame
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
paintPlayingFieldBorder(g2); //paintPlayingFieldBorder(g2);
paintNodes(g2); paintNodes(g2);
super.paintComponent(g); super.paintComponent(g);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment