/* * 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.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JToggleButton; import org.geotoolkit.gui.swing.resource.IconBundle; import org.geotoolkit.map.MapLayer; import org.geotoolkit.style.StyleConstants; import org.opengis.filter.expression.Expression; /** * * @author Johann Sorel (Puzzle-GIS) * @module */ public class JLineJoinExpressionPane extends StyleElementEditor<Expression>{ private static final ImageIcon ICON_JOIN_ROUND = IconBundle.getIcon("16_linejoin_round"); private static final ImageIcon ICON_JOIN_MITRE = IconBundle.getIcon("16_linejoin_mitre"); private static final ImageIcon ICON_JOIN_BEVEL = IconBundle.getIcon("16_linejoin_bevel"); private final Dimension specialSize; /** Creates new form JColorExpressionPane */ public JLineJoinExpressionPane() { super(Expression.class); initComponents(); guiBevel.setIcon(ICON_JOIN_BEVEL); guiMiter.setIcon(ICON_JOIN_MITRE); guiRound.setIcon(ICON_JOIN_ROUND); specialSize = guiSpecial.getPreferredSize(); } public void setExpressionVisible(boolean visible){ guiSpecial.setPreferredSize( visible ? new Dimension(specialSize) : new Dimension(1, 1)); guiSpecial.setVisible(visible); } @Override public void setLayer(final MapLayer layer) { super.setLayer(layer); guiSpecial.setLayer(layer); } /** 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() { GridBagConstraints gridBagConstraints; joinGroup = new ButtonGroup(); guiSpecial = new JSpecialExpressionButton(); guiRound = new JToggleButton(); guiMiter = new JToggleButton(); guiBevel = new JToggleButton(); jLabel1 = new JLabel(); setOpaque(false); setLayout(new GridBagLayout()); guiSpecial.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { guiSpecialPropertyChange(evt); } }); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weighty = 1.0; add(guiSpecial, gridBagConstraints); joinGroup.add(guiRound); guiRound.setSelected(true); guiRound.setBorderPainted(false); guiRound.setIconTextGap(0); guiRound.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { guiRoundActionPerformed(evt); } }); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weighty = 1.0; add(guiRound, gridBagConstraints); joinGroup.add(guiMiter); guiMiter.setBorderPainted(false); guiMiter.setIconTextGap(0); guiMiter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { guiMiterActionPerformed(evt); } }); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weighty = 1.0; add(guiMiter, gridBagConstraints); joinGroup.add(guiBevel); guiBevel.setBorderPainted(false); guiBevel.setIconTextGap(0); guiBevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { guiBevelActionPerformed(evt); } }); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weighty = 1.0; add(guiBevel, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 4; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; add(jLabel1, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents private void guiSpecialPropertyChange(final PropertyChangeEvent evt) {//GEN-FIRST:event_guiSpecialPropertyChange if(evt.getPropertyName().equals(JSpecialExpressionButton.EXPRESSION_PROPERTY)) { parse(guiSpecial.get()); } }//GEN-LAST:event_guiSpecialPropertyChange private void guiRoundActionPerformed(final ActionEvent evt) {//GEN-FIRST:event_guiRoundActionPerformed parse(StyleConstants.STROKE_JOIN_ROUND); }//GEN-LAST:event_guiRoundActionPerformed private void guiMiterActionPerformed(final ActionEvent evt) {//GEN-FIRST:event_guiMiterActionPerformed parse(StyleConstants.STROKE_JOIN_MITRE); }//GEN-LAST:event_guiMiterActionPerformed private void guiBevelActionPerformed(final ActionEvent evt) {//GEN-FIRST:event_guiBevelActionPerformed parse(StyleConstants.STROKE_JOIN_BEVEL); }//GEN-LAST:event_guiBevelActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private JToggleButton guiBevel; private JToggleButton guiMiter; private JToggleButton guiRound; private JSpecialExpressionButton guiSpecial; private JLabel jLabel1; private ButtonGroup joinGroup; // End of variables declaration//GEN-END:variables @Override public void parse(final Expression target) { if(target != null){ if(StyleConstants.STROKE_JOIN_BEVEL.equals(target)){ guiSpecial.parse(null); guiBevel.setSelected(true); }else if(StyleConstants.STROKE_JOIN_ROUND.equals(target)){ guiSpecial.parse(null); guiRound.setSelected(true); }else if(StyleConstants.STROKE_JOIN_MITRE.equals(target)){ guiSpecial.parse(null); guiMiter.setSelected(true); }else{ guiSpecial.parse(target); joinGroup.clearSelection(); } }else{ guiSpecial.parse(null); guiBevel.setSelected(true); guiRound.setSelected(false); guiMiter.setSelected(false); } guiBevel.setEnabled(guiSpecial.get()==null); guiBevel.setToolTipText(guiSpecial.getToolTipText()); guiRound.setEnabled(guiSpecial.get()==null); guiRound.setToolTipText(guiSpecial.getToolTipText()); guiMiter.setEnabled(guiSpecial.get()==null); guiMiter.setToolTipText(guiSpecial.getToolTipText()); firePropertyChange(PROPERTY_UPDATED, null, create()); } @Override public Expression create() { final Expression special = guiSpecial.get(); if(special != null){ return special; }else{ if(guiRound.isSelected()) return StyleConstants.STROKE_JOIN_ROUND; else if(guiMiter.isSelected()) return StyleConstants.STROKE_JOIN_MITRE; else return StyleConstants.STROKE_JOIN_BEVEL; } } @Override protected Object[] getFirstColumnComponents() { return new Object[]{}; } }