/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ControlMap.java
*
* Created on 24/09/2009, 11:11:00 PM
*/
package org.petah.spring.bai.gui;
import java.awt.EventQueue;
import java.awt.image.BufferedImage;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import org.petah.spring.bai.ThreadManager;
import org.petah.spring.bai.cache.CachedMetalMap;
import org.petah.spring.bai.map.metal.MetalMapRenderer;
import org.petah.spring.bai.map.metal.MetalSpotManager;
/**
*
* @author Petah
*/
public class PMetalMap extends javax.swing.JPanel {
private CachedMetalMap cachedMetalMap;
private MetalSpotManager metalSpotManager;
private BufferedImage image;
// private Future imageFuture;
/** Creates new form ControlMap */
public PMetalMap(CachedMetalMap cachedMetalMap, MetalSpotManager metalSpotManager) {
this.cachedMetalMap = cachedMetalMap;
this.metalSpotManager = metalSpotManager;
initComponents();
image = new BufferedImage(cachedMetalMap.getWidth(), cachedMetalMap.getHeight(), BufferedImage.TYPE_INT_RGB);
lImage.setIcon(new ImageIcon(image));
}
// public void update(Object source) {
// updateImage();
// }
private void startAutoUpdate() {
ThreadManager.run("PMetalMap.startAutoUpdate()", new Runnable() {
public void run() {
try {
while (cbAutoUpdate.isSelected()) {
updateImage();
Thread.sleep(1000);
}
} catch (InterruptedException ex) {
Logger.getLogger(PMetalMap.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
private void updateImage() {
MetalMapRenderer.renderFullMetalMap(cachedMetalMap, metalSpotManager, image);
EventQueue.invokeLater(new Runnable() {
public void run() {
updateUI();
}
});
// if (imageFuture != null) {
// try {
// imageFuture.get();
// } catch (InterruptedException ex) {
// Logger.getLogger(PMetalMap.class.getName()).log(Level.SEVERE, null, ex);
// } catch (ExecutionException ex) {
// Logger.getLogger(PMetalMap.class.getName()).log(Level.SEVERE, null, ex);
// }
// }
// imageFuture = ThreadManager.run(new Runnable() {
//
// public void run() {
// EventQueue.invokeLater(new Runnable() {
//
// public void run() {
// MetalMapRenderer.renderFullMetalMap(bai, 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() {
toolBar = new javax.swing.JToolBar();
bRefresh = new javax.swing.JButton();
cbAutoUpdate = new javax.swing.JCheckBox();
scrollPane = new javax.swing.JScrollPane();
lImage = new javax.swing.JLabel();
setLayout(new java.awt.BorderLayout());
toolBar.setFloatable(false);
toolBar.setRollover(true);
bRefresh.setText("Refresh");
bRefresh.setFocusable(false);
bRefresh.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
bRefresh.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
bRefresh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bRefreshActionPerformed(evt);
}
});
toolBar.add(bRefresh);
cbAutoUpdate.setText("Auto Refresh");
cbAutoUpdate.setFocusable(false);
cbAutoUpdate.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
cbAutoUpdate.setOpaque(false);
cbAutoUpdate.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
cbAutoUpdate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbAutoUpdateActionPerformed(evt);
}
});
toolBar.add(cbAutoUpdate);
add(toolBar, java.awt.BorderLayout.PAGE_START);
lImage.setVerticalAlignment(javax.swing.SwingConstants.TOP);
scrollPane.setViewportView(lImage);
add(scrollPane, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
private void bRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bRefreshActionPerformed
updateImage();
}//GEN-LAST:event_bRefreshActionPerformed
private void cbAutoUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAutoUpdateActionPerformed
if (cbAutoUpdate.isSelected()) {
startAutoUpdate();
}
}//GEN-LAST:event_cbAutoUpdateActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton bRefresh;
private javax.swing.JCheckBox cbAutoUpdate;
private javax.swing.JLabel lImage;
private javax.swing.JScrollPane scrollPane;
private javax.swing.JToolBar toolBar;
// End of variables declaration//GEN-END:variables
}