/*
* 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.Component;
import java.awt.Dimension;
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.JButton;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import org.geotoolkit.gui.swing.resource.MessageBundle;
import org.geotoolkit.map.MapLayer;
import org.opengis.style.Fill;
/**
* Fill panel
*
* @author Johann Sorel
* @module
*/
public class JFillPane extends StyleElementEditor<Fill>{
private MapLayer layer = null;
private Fill fill = null;
/**
* Creates new form JFillPanel
*/
public JFillPane() {
super(Fill.class);
initComponents();
butFill.setEnabled(false);
guiAlpha.setModel(1d, 0d, 1d, 0.1d);
}
/**
* {@inheritDoc }
*/
@Override
public void setLayer(final MapLayer layer) {
this.layer = layer;
guiColor.setLayer(layer);
guiAlpha.setLayer(layer);
}
/**
* {@inheritDoc }
*/
@Override
public MapLayer getLayer(){
return layer;
}
/**
* {@inheritDoc }
*/
@Override
public void parse(final Fill fill) {
this.fill = fill;
if (fill != null) {
guiColor.parse(fill.getColor());
guiAlpha.parse(fill.getOpacity());
//handle by a button
//fill.getGraphicFill();
}
}
/**
* {@inheritDoc }
*/
@Override
public Fill create() {
return getStyleFactory().fill(
guiColor.create(),
guiAlpha.create());
}
@Override
protected Object[] getFirstColumnComponents() {
return new Object[]{guiLabelColor,guiLabelAlpha,guiLabelFill};
}
/** 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() {
butFill = new JButton();
guiLabelFill = new JLabel();
guiLabelAlpha = new JLabel();
guiLabelColor = new JLabel();
guiColor = new JColorExpressionPane();
guiAlpha = new JNumberExpressionPane();
setOpaque(false);
butFill.setText(MessageBundle.format("fill")); // NOI18N
butFill.setBorderPainted(false);
butFill.setPreferredSize(new Dimension(49, 22));
butFill.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
butFillActionPerformed(evt);
}
});
guiLabelFill.setText(MessageBundle.format("graphic")); // NOI18N
guiLabelAlpha.setText(MessageBundle.format("opacity")); // NOI18N
guiLabelColor.setText(MessageBundle.format("color")); // NOI18N
guiColor.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
JFillPane.this.propertyChange(evt);
}
});
guiAlpha.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
JFillPane.this.propertyChange(evt);
}
});
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(guiLabelColor)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(guiColor, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(guiLabelAlpha)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(guiAlpha, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(guiLabelFill)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(butFill, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
);
layout.linkSize(SwingConstants.HORIZONTAL, new Component[] {guiLabelAlpha, guiLabelColor, guiLabelFill});
layout.setVerticalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.TRAILING)
.addComponent(guiLabelColor)
.addComponent(guiColor, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(Alignment.LEADING, false)
.addComponent(guiLabelAlpha, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(guiAlpha, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(guiLabelFill)
.addComponent(butFill, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
);
}// </editor-fold>//GEN-END:initComponents
private void butFillActionPerformed(final ActionEvent evt) {//GEN-FIRST:event_butFillActionPerformed
//TODO
}//GEN-LAST:event_butFillActionPerformed
private void propertyChange(PropertyChangeEvent evt) {//GEN-FIRST:event_propertyChange
// TODO add your handling code here:
if (PROPERTY_UPDATED.equalsIgnoreCase(evt.getPropertyName())) {
firePropertyChange(PROPERTY_UPDATED, null, create());
parse(create());
}
}//GEN-LAST:event_propertyChange
// Variables declaration - do not modify//GEN-BEGIN:variables
private JButton butFill;
private JNumberExpressionPane guiAlpha;
private JColorExpressionPane guiColor;
private JLabel guiLabelAlpha;
private JLabel guiLabelColor;
private JLabel guiLabelFill;
// End of variables declaration//GEN-END:variables
}