/* * 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.ItemEvent; import java.awt.event.ItemListener; import javax.measure.quantity.Length; import javax.measure.Unit; import javax.swing.DefaultComboBoxModel; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.LayoutStyle.ComponentPlacement; import org.geotoolkit.gui.swing.resource.MessageBundle; import org.apache.sis.measure.Units; /** * * @author Johann Sorel * @module */ public class JUOMPane extends StyleElementEditor<Unit>{ /** Creates new form JUOMPane */ public JUOMPane() { super(Unit.class); initComponents(); } @Override public void parse(final Unit target) { if(Units.METRE.equals(target)){ jcb_uom.setSelectedIndex(1); }else if(Units.FOOT.equals(target)){ jcb_uom.setSelectedIndex(2); }else { jcb_uom.setSelectedIndex(0); } } @Override public Unit<Length> create() { switch(jcb_uom.getSelectedIndex()){ case 1 : return Units.METRE; case 2 : return Units.FOOT; default : return Units.POINT; } } @Override protected Object[] getFirstColumnComponents() { return new Object[]{guiLabel}; } /** 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() { guiLabel = new JLabel(); jcb_uom = new JComboBox(); setOpaque(false); guiLabel.setText(MessageBundle.format("unit")); // NOI18N jcb_uom.setModel(new DefaultComboBoxModel(new String[] { "Pixels", "Meters", "Feet" })); jcb_uom.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { jcb_uomItemStateChanged(evt); } }); GroupLayout layout = new GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(guiLabel) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(jcb_uom, 0, 63, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(Alignment.LEADING) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(guiLabel) .addComponent(jcb_uom, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) ); }// </editor-fold>//GEN-END:initComponents private void jcb_uomItemStateChanged(ItemEvent evt) {//GEN-FIRST:event_jcb_uomItemStateChanged // TODO add your handling code here: firePropertyChange(PROPERTY_UPDATED, null, create()); }//GEN-LAST:event_jcb_uomItemStateChanged // Variables declaration - do not modify//GEN-BEGIN:variables private JLabel guiLabel; private JComboBox jcb_uom; // End of variables declaration//GEN-END:variables }