/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* PIslandMap.java
*
* Created on 8/10/2009, 3:49:34 AM
*/
package org.petah.spring.bai.gui;
import org.petah.spring.bai.gui.model.MoveDataListModel;
import java.awt.EventQueue;
import java.awt.image.BufferedImage;
import java.util.concurrent.Future;
import javax.swing.ImageIcon;
import org.petah.spring.bai.ThreadManager;
import org.petah.spring.bai.cache.CachedMoveData;
import org.petah.spring.bai.delegate.GlobalDelegate;
import org.petah.spring.bai.map.slope.IslandMap;
import org.petah.spring.bai.map.slope.IslandMapManager;
import org.petah.spring.bai.map.slope.IslandMapRenderer;
/**
*
* @author Petah
*/
public class PIslandMap extends javax.swing.JPanel {
private CachedMoveData moveData;
private BufferedImage image;
private Future imageFuture;
/** Creates new form PIslandMap */
public PIslandMap() {
initComponents();
image = new BufferedImage(GlobalDelegate.getSlopeMapWidth(), GlobalDelegate.getSlopeMapHeight(), BufferedImage.TYPE_INT_RGB);
lImage.setIcon(new ImageIcon(image));
}
private void update() {
if (imageFuture == null || imageFuture.isDone()) {
imageFuture = ThreadManager.run("PControlMap.updateImage()", new Runnable() {
public void run() {
EventQueue.invokeLater(new Runnable() {
public void run() {
IslandMapRenderer.renderIsland(GlobalDelegate.getIslandMap(moveData), image);
updateUI();
}
});
}
});
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup = new javax.swing.ButtonGroup();
splitPane = new javax.swing.JSplitPane();
spMoveData = new javax.swing.JScrollPane();
lMoveData = new javax.swing.JList();
spImage = new javax.swing.JScrollPane();
lImage = new javax.swing.JLabel();
setLayout(new java.awt.BorderLayout());
splitPane.setDividerLocation(100);
lMoveData.setModel(new MoveDataListModel());
lMoveData.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
lMoveDataMouseClicked(evt);
}
});
spMoveData.setViewportView(lMoveData);
splitPane.setLeftComponent(spMoveData);
spImage.setViewportView(lImage);
splitPane.setRightComponent(spImage);
add(splitPane, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
private void lMoveDataMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lMoveDataMouseClicked
moveData = ((MoveDataListModel) lMoveData.getModel()).getCachedMoveData(lMoveData.getSelectedIndex());
update();
}//GEN-LAST:event_lMoveDataMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup;
private javax.swing.JLabel lImage;
private javax.swing.JList lMoveData;
private javax.swing.JScrollPane spImage;
private javax.swing.JScrollPane spMoveData;
private javax.swing.JSplitPane splitPane;
// End of variables declaration//GEN-END:variables
}