/*
* 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.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.JCheckBox;
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.ShadedRelief;
/**
* ShadedRelief panel
*
* @author Johann Sorel
* @module
*/
public class JShadedReliefPane extends StyleElementEditor<ShadedRelief>{
private MapLayer layer = null;
/**
* Creates new form JFillPanel
*/
public JShadedReliefPane() {
super(ShadedRelief.class);
initComponents();
guiFactor.setModel(1d, 0d, 10000000d, 0.1d);
//those are not used by geotk engine, hide them to avoid confusing the user
guiLabelBrightness.setVisible(false);
guiBrightness.setVisible(false);
}
public void setExpressionVisible(boolean visible){
guiFactor.setExpressionVisible(visible);
}
@Override
public void setLayer(final MapLayer layer) {
this.layer = layer;
guiFactor.setLayer(layer);
}
@Override
public MapLayer getLayer(){
return layer;
}
@Override
public void parse(final ShadedRelief relief) {
if (relief != null) {
guiFactor.parse(relief.getReliefFactor());
guiBrightness.setSelected(relief.isBrightnessOnly());
}
}
@Override
public ShadedRelief create() {
return getStyleFactory().shadedRelief(
guiFactor.create(),
guiBrightness.isSelected());
}
@Override
protected Object[] getFirstColumnComponents() {
return new Object[]{guiLabelFactor,guiLabelBrightness};
}
/** 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() {
guiLabelFactor = new JLabel();
guiBrightness = new JCheckBox();
guiFactor = new JNumberExpressionPane();
guiLabelBrightness = new JLabel();
setOpaque(false);
guiLabelFactor.setText(MessageBundle.format("factor")); // NOI18N
guiBrightness.setText(" ");
guiBrightness.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
guiBrightnessActionPerformed(evt);
}
});
guiFactor.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
JShadedReliefPane.this.propertyChange(evt);
}
});
guiLabelBrightness.setText(MessageBundle.format("brightnessonly")); // NOI18N
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(guiLabelFactor)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(guiFactor, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(guiLabelBrightness)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(guiBrightness))
);
layout.linkSize(SwingConstants.HORIZONTAL, new Component[] {guiLabelBrightness, guiLabelFactor});
layout.setVerticalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(guiLabelFactor)
.addComponent(guiFactor, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(guiLabelBrightness)
.addComponent(guiBrightness)))
);
layout.linkSize(SwingConstants.VERTICAL, new Component[] {guiFactor, guiLabelFactor});
}// </editor-fold>//GEN-END:initComponents
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
private void guiBrightnessActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiBrightnessActionPerformed
firePropertyChange(PROPERTY_UPDATED, null, create());
}//GEN-LAST:event_guiBrightnessActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private JCheckBox guiBrightness;
private JNumberExpressionPane guiFactor;
private JLabel guiLabelBrightness;
private JLabel guiLabelFactor;
// End of variables declaration//GEN-END:variables
}