/*
* 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.propertyedit;
import java.awt.Image;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import org.geotoolkit.gui.swing.resource.IconBundle;
import org.geotoolkit.gui.swing.resource.MessageBundle;
import org.geotoolkit.map.CoverageMapLayer;
import org.geotoolkit.map.FeatureMapLayer;
import org.geotoolkit.map.MapBuilder;
import org.geotoolkit.map.MapLayer;
import org.geotoolkit.style.MutableStyle;
import org.geotoolkit.style.visitor.CopyStyleVisitor;
/**
* layer style panel
*
* @author Johann Sorel (Puzzle-GIS)
* @module
*/
public class LayerStylePropertyPanel extends MultiPropertyPanel {
private Object target = null;
//store a copy of the layer and it's style
//we do this to handle properly the apply and reset actions
private MapLayer mimicLayer = null;
/** Creates new form DefaultMapContextCRSEditPanel */
public LayerStylePropertyPanel() {
super();
}
@Override
public void setTarget(Object target) {
this.target = target;
this.mimicLayer = createMimic(target);
super.setTarget((mimicLayer!=null)?mimicLayer:target);
}
@Override
public void apply() {
super.apply();
if(target instanceof MapLayer && mimicLayer!=null){
final MutableStyle newSyle = CopyStyleVisitor.INSTANCE.visit(mimicLayer.getStyle(),null);
((MapLayer)target).setStyle(newSyle);
}
}
@Override
public void reset() {
setTarget(target);
}
private MapLayer createMimic(Object target){
if(target instanceof MapLayer){
final MapLayer origLayer = (MapLayer) target;
final MapLayer mimic;
if(target instanceof CoverageMapLayer){
final CoverageMapLayer original = (CoverageMapLayer) target;
mimic = MapBuilder.createCoverageLayer(original.getCoverageReference());
}else if(target instanceof FeatureMapLayer){
final FeatureMapLayer original = (FeatureMapLayer) target;
mimic = MapBuilder.createFeatureLayer(original.getCollection(), origLayer.getStyle());
}else{
mimic = MapBuilder.createEmptyMapLayer();
}
mimic.setStyle(CopyStyleVisitor.INSTANCE.visit(origLayer.getStyle(),null));
return mimic;
}
//could not mimic it, not a maplayer
return null;
}
/** 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() {
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
@Override
public String getTitle() {
return MessageBundle.format("property_style");
}
@Override
public ImageIcon getIcon() {
return IconBundle.EMPTY_ICON;
}
@Override
public Image getPreview() {
return null;
}
@Override
public String getToolTip() {
return MessageBundle.format("property_style");
}
@Override
public boolean canHandle(Object target) {
return true;
}
}