/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.gui.swing.propertyedit;
import java.awt.Color;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import org.geotools.data.FeatureSource;
import org.geotools.data.FeatureStore;
import org.geotools.data.Query;
import org.geotools.gui.swing.icon.IconBundle;
import org.geotools.gui.swing.propertyedit.model.FeatureSourceModel;
import org.geotools.gui.swing.propertyedit.model.GeometryCellEditor;
import org.geotools.gui.swing.propertyedit.model.GeometryCellRenderer;
import org.geotools.map.MapLayer;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.Highlighter;
import org.jdesktop.swingx.decorator.HighlighterFactory;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import com.vividsolutions.jts.geom.Geometry;
/**
* layer feature panel
*
* @author Johann Sorel
*
* @source $URL$
*/
public class LayerFeaturePropertyPanel extends javax.swing.JPanel implements PropertyPane {
private MapLayer layer = null;
private FeatureSource<SimpleFeatureType, SimpleFeature> source = null;
private boolean editable = false;
/** Creates new form DefaultMapLayerTablePanel */
public LayerFeaturePropertyPanel() {
//netbeans JPanel components init
initComponents();
tab_data.setDefaultRenderer(Geometry.class, new GeometryCellRenderer());
tab_data.setDefaultEditor(Geometry.class, new GeometryCellEditor());
tab_data.setEditable(false);
tab_data.setColumnControlVisible(true);
tab_data.setHorizontalScrollEnabled(true);
tab_data.setAutoResizeMode(JXTable.AUTO_RESIZE_OFF);
tab_data.setHighlighters(new Highlighter[]{HighlighterFactory.createAlternateStriping(Color.white, HighlighterFactory.QUICKSILVER, 5)});
tab_data.setShowGrid(true, true);
tab_data.setGridColor(Color.GRAY.brighter());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
tab_data.packAll();
}
});
jcb_collection.addItem(BUNDLE.getString("filter"));
jcb_collection.addItem(BUNDLE.getString("all"));
}
/** 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() {
jScrollPane1 = new javax.swing.JScrollPane();
tab_data = new org.jdesktop.swingx.JXTable();
jcb_edit = new javax.swing.JCheckBox();
jbu_action = new javax.swing.JButton();
jcb_collection = new javax.swing.JComboBox();
jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
tab_data.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
}
));
jScrollPane1.setViewportView(tab_data);
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/geotools/gui/swing/propertyedit/Bundle"); // NOI18N
jcb_edit.setText(bundle.getString("edit")); // NOI18N
jcb_edit.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
jcb_edit.setEnabled(false);
jcb_edit.setMargin(new java.awt.Insets(0, 0, 0, 0));
jcb_edit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
actionEditer(evt);
}
});
jbu_action.setText(bundle.getString("action")); // NOI18N
jbu_action.setEnabled(false);
jbu_action.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
actionMenu(evt);
}
});
jcb_collection.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
actionCollection(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jcb_collection, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 142, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jcb_edit)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 218, Short.MAX_VALUE)
.add(jbu_action)
.addContainerGap())
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jcb_collection, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jcb_edit)
.add(jbu_action))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void actionCollection(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionCollection
if (layer != null) {
if (jcb_collection.getSelectedIndex() == 0) {
((FeatureSourceModel) tab_data.getModel()).setQuery(layer.getQuery());
} else if (jcb_collection.getSelectedIndex() == 1) {
((FeatureSourceModel) tab_data.getModel()).setQuery(Query.ALL);
}
tab_data.setModel(tab_data.getModel());
}
}//GEN-LAST:event_actionCollection
private void actionEditer(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionEditer
tab_data.setEditable(((JCheckBox) evt.getSource()).isSelected());
}//GEN-LAST:event_actionEditer
private void actionMenu(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionMenu
JPopupMenu menu = new JPopupMenu();
menu.setLocation( jbu_action.getLocationOnScreen().x, jbu_action.getLocationOnScreen().y);
JMenuItem mi = new JMenuItem("test");
menu.add(mi);
//menu.setVisible(true);
}//GEN-LAST:event_actionMenu
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton jbu_action;
private javax.swing.JComboBox jcb_collection;
private javax.swing.JCheckBox jcb_edit;
private org.jdesktop.swingx.JXTable tab_data;
// End of variables declaration//GEN-END:variables
public void setTarget(Object target) {
if (target instanceof MapLayer) {
source = null;
layer = (MapLayer) target;
source = (FeatureSource<SimpleFeatureType, SimpleFeature>) layer.getFeatureSource();
if (source instanceof FeatureStore) {
editable = true;
} else {
editable = false;
}
setEditable(editable);
tab_data.setModel(new FeatureSourceModel(tab_data, layer));
}
}
public void apply() {
}
public String getTitle() {
return BUNDLE.getString("feature_table");
}
public ImageIcon getIcon() {
return IconBundle.getResource().getIcon("16_feature_table");
}
public String getToolTip() {
return "";
}
public Component getComponent() {
return this;
}
private void setEditable(boolean editable) {
jcb_edit.setEnabled(editable);
jbu_action.setEnabled(editable);
}
public void reset() {
}
}