/* * Geotoolkit - An Open Source Java GIS Toolkit * http://www.geotoolkit.org * * (C) 2007 - 2008, Open Source Geospatial Foundation (OSGeo) * (C) 2008 - 2009, Johann Sorel * * 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.geotoolkit.gui.swing.style; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.geotoolkit.gui.swing.resource.MessageBundle; import org.geotoolkit.map.MapLayer; import org.opengis.style.SelectedChannelType; /** * SelectedChannel type panel * * @author Johann Sorel * @module */ public class JSelectedChannelTypePane extends StyleElementEditor<SelectedChannelType> implements DocumentListener { private MapLayer layer = null; private SelectedChannelType channel = null; /** * Creates new form JFillPanel */ public JSelectedChannelTypePane() { super(SelectedChannelType.class); initComponents(); //those are not used by geotk engine, hide them to avoid confusing the user guiContrast.setVisible(false); } @Override public void setLayer(final MapLayer layer) { this.layer = layer; guiContrast.setLayer(layer); } @Override public MapLayer getLayer(){ return layer; } @Override public void parse(final SelectedChannelType channel) { this.channel = channel; if (channel != null) { guiName.setText(channel.getChannelName()); guiContrast.parse(channel.getContrastEnhancement()); } } @Override public SelectedChannelType create() { channel = getStyleFactory().selectedChannelType(guiName.getText(), guiContrast.create()); return channel; } @Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); guiName.setEnabled(enabled); if (enabled) { guiName.getDocument().addDocumentListener(this); } else { guiName.getDocument().removeDocumentListener(this); } } @Override protected Object[] getFirstColumnComponents() { return new Object[]{guiLabelName,guiContrast}; } @Override public void insertUpdate(DocumentEvent e) { firePropertyChange(PROPERTY_UPDATED, null, create()); } @Override public void removeUpdate(DocumentEvent e) { firePropertyChange(PROPERTY_UPDATED, null, create()); } @Override public void changedUpdate(DocumentEvent e) { firePropertyChange(PROPERTY_UPDATED, null, create()); } /** 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() { guiContrast = new JContrastEnhancement(); guiLabelName = new JLabel(); guiName = new JTextField(); setOpaque(false); guiContrast.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { JSelectedChannelTypePane.this.propertyChange(evt); } }); guiLabelName.setText(MessageBundle.format("name")); // NOI18N guiName.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { guiNameActionPerformed(evt); } }); GroupLayout layout = new GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(guiLabelName) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(guiName)) .addComponent(guiContrast, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(guiLabelName) .addComponent(guiName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(guiContrast, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents private void propertyChange(PropertyChangeEvent evt) {//GEN-FIRST:event_propertyChange if (PROPERTY_UPDATED.equalsIgnoreCase(evt.getPropertyName())) { firePropertyChange(PROPERTY_UPDATED, null, create()); } }//GEN-LAST:event_propertyChange private void guiNameActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiNameActionPerformed firePropertyChange(PROPERTY_UPDATED, null, create()); }//GEN-LAST:event_guiNameActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private JContrastEnhancement guiContrast; private JLabel guiLabelName; private JTextField guiName; // End of variables declaration//GEN-END:variables }