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;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
......@@ -47,6 +48,8 @@ public class ShowMapQuestMapViz extends JComponent
private String mapType;
private String mapQuestKey;
private BufferedImage background = null;
private boolean initialized = false;
......@@ -96,6 +99,24 @@ public class ShowMapQuestMapViz extends JComponent
}
}
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
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setComposite(
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
Image imageToDraw = resize(
Toolkit.getDefaultToolkit().getImage(tempImageFilePath),
VisualizationInjector.getWorldX(),
VisualizationInjector.getWorldY());
g2.drawImage(imageToDraw, 0, 0, this);
if (background != null) {
g2.drawImage(background, 0, 0, this);
}
}
public void setTempImageFilePath(String tempImageFilePath) {
......@@ -135,7 +154,7 @@ public class ShowMapQuestMapViz extends JComponent
* @param width
* @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;
BufferedImage resizedImage = new BufferedImage(width, height, type);
Graphics2D g = resizedImage.createGraphics();
......
......@@ -432,7 +432,7 @@ public class VisualizationTopologyView extends JFrame
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
paintPlayingFieldBorder(g2);
//paintPlayingFieldBorder(g2);
paintNodes(g2);
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