/*
* GeoInspectorPanel.java
*
* Created on May 4, 2007, 2:25 PM
*/
package ika.gui;
import com.l2fprod.common.swing.JFontChooser;
import ika.geo.GeoObject;
import ika.geo.GeoPath;
import ika.geo.GeoSet;
import ika.geo.GeoText;
import ika.geo.MapEvent;
import ika.geo.MapEventListener;
import ika.geo.VectorSymbol;
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Font;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JPanel;
/**
*
* @author Bernhard Jenny, Instute of Cartography, ETH Zurich.
*/
public class GeoInspectorPanel extends javax.swing.JPanel
implements MapEventListener{
private static final String VECTOR = "vector";
private static final String FONT = "font";
private static final String NONE = "none";
private VectorSymbolPanel vectorSymbolPanel;
private JFontChooser fontChooser;
private GeoText singleSelectedGeoText;
/** Creates new form GeoInspectorPanel */
public GeoInspectorPanel() {
initComponents();
JPanel emptyPanel = new JPanel();
this.add(emptyPanel, NONE);
this.vectorSymbolPanel = new VectorSymbolPanel();
this.add(vectorSymbolPanel, VECTOR);
this.fontChooser = new JFontChooser();
PropertyChangeListener l = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (singleSelectedGeoText == null)
return;
Font newFont = fontChooser.getSelectedFont();
if (newFont == null)
return;
singleSelectedGeoText.getFontSymbol().setFont(newFont);
}
};
this.fontChooser.addPropertyChangeListener(l);
this.add(fontChooser, FONT);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
setLayout(new java.awt.CardLayout());
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
public void mapEvent(MapEvent evt) {
GeoSet rootGeoSet = evt.getRootGeoSet();
if (rootGeoSet == null)
return;
GeoObject singleSelectedGeoObj = rootGeoSet.getSingleSelectedGeoObject();
CardLayout cl = (CardLayout)(this.getLayout());
if (singleSelectedGeoObj instanceof GeoPath) {
GeoPath geoPath = (GeoPath)singleSelectedGeoObj;
VectorSymbol vs = geoPath.getVectorSymbol();
this.vectorSymbolPanel.setVectorSymbol(vs);
cl.show(this, VECTOR);
} else if (singleSelectedGeoObj instanceof GeoText) {
this.singleSelectedGeoText = (GeoText)singleSelectedGeoObj;
Font font = this.singleSelectedGeoText.getFontSymbol().getFont();
this.fontChooser.setSelectedFont(font);
cl.show(this, FONT);
} else {
// if multiple objects are selected or if no object is selected,
// display an empty panel.
this.vectorSymbolPanel.setVectorSymbol(null);
this.fontChooser.setFont(null);
cl.show(this, NONE);
}
}
}