/*
* Geotoolkit - An Open Source Java GIS Toolkit
* http://www.geotoolkit.org
*
* (C) 2012 Geomatys
*
* 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.styleproperty.simple;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import javax.swing.SwingConstants;
import org.geotoolkit.gui.swing.resource.MessageBundle;
import org.geotoolkit.gui.swing.style.StyleElementEditor;
import org.geotoolkit.map.MapLayer;
import org.opengis.style.AnchorPoint;
/**
* Anchor point edition panel
*
* @author Fabien Rétif (Geomatys)
* @author Johann Sorel (Geomatys)
* @module
*/
public class JAnchorPointPane extends StyleElementEditor<AnchorPoint> {
private MapLayer layer = null;
private Float x;
private Float y;
/**
* Creates new form JAnchorPointPane
*/
public JAnchorPointPane() {
super(AnchorPoint.class);
initComponents();
init();
}
/**
* This method initializes all position button
*/
private void init() {
buttonGroup1.add(guiUpper);
buttonGroup1.add(guiUpperLeft);
buttonGroup1.add(guiUpperRight);
buttonGroup1.add(guiLeft);
buttonGroup1.add(guiCenter);
buttonGroup1.add(guiRight);
buttonGroup1.add(guiDownLeft);
buttonGroup1.add(guiDown);
buttonGroup1.add(guiDownRight);
}
/**
* {@inheritDoc }
*/
@Override
public void setLayer(final MapLayer layer) {
this.layer = layer;
}
/**
* {@inheritDoc }
*/
@Override
public MapLayer getLayer() {
return layer;
}
/**
* {@inheritDoc }
*/
@Override
public void parse(final AnchorPoint anchor) {
if (anchor != null) {
this.x = anchor.getAnchorPointX().evaluate(null, Float.class);
this.y = anchor.getAnchorPointY().evaluate(null, Float.class);
if (this.x == 0f && this.y == 0.5f) {
guiRight.setSelected(true);
} else if (this.x == 0f && this.y == 0f) {
guiUpperRight.setSelected(true);
} else if (this.x == 0f && this.y == 0f) {
guiUpperLeft.setSelected(true);
} else if (this.x == 0.5f && this.y == 0f) {
guiUpper.setSelected(true);
} else if (this.x == 1f && this.y == 0.5f) {
guiLeft.setSelected(true);
} else if (this.x == 0.5f && this.y == 0.5f) {
guiCenter.setSelected(true);
} else if (this.x == 1f && this.y == 1f) {
guiDownLeft.setSelected(true);
} else if (this.x == 0.5f && this.y == 1f) {
guiDown.setSelected(true);
} else if (this.x == 0f && this.y == 1f) {
guiDownRight.setSelected(true);
}
}
}
/**
* {@inheritDoc }
*/
@Override
public AnchorPoint create() {
return getStyleFactory().anchorPoint(
getFilterFactory().literal(x),
getFilterFactory().literal(y));
}
@Override
protected Object[] getFirstColumnComponents() {
return new Object[]{};
}
/**
* 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() {
buttonGroup1 = new ButtonGroup();
guiUpperLeft = new JRadioButton();
guiUpper = new JRadioButton();
guiUpperRight = new JRadioButton();
guiLeft = new JRadioButton();
guiCenter = new JRadioButton();
guiRight = new JRadioButton();
guiDownLeft = new JRadioButton();
guiDown = new JRadioButton();
guiDownRight = new JRadioButton();
setLayout(new GridLayout(0, 3));
buttonGroup1.add(guiUpperLeft);
guiUpperLeft.setText(MessageBundle.format("placement_topleft")); // NOI18N
guiUpperLeft.setHideActionText(true);
guiUpperLeft.setHorizontalAlignment(SwingConstants.LEFT);
guiUpperLeft.setHorizontalTextPosition(SwingConstants.RIGHT);
guiUpperLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
guiUpperLeftActionPerformed(evt);
}
});
add(guiUpperLeft);
buttonGroup1.add(guiUpper);
guiUpper.setText(MessageBundle.format("placement_topmiddle")); // NOI18N
guiUpper.setHideActionText(true);
guiUpper.setHorizontalAlignment(SwingConstants.LEFT);
guiUpper.setHorizontalTextPosition(SwingConstants.RIGHT);
guiUpper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
guiUpperActionPerformed(evt);
}
});
add(guiUpper);
buttonGroup1.add(guiUpperRight);
guiUpperRight.setText(MessageBundle.format("placement_topright")); // NOI18N
guiUpperRight.setHideActionText(true);
guiUpperRight.setHorizontalAlignment(SwingConstants.LEFT);
guiUpperRight.setHorizontalTextPosition(SwingConstants.RIGHT);
guiUpperRight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
guiUpperRightActionPerformed(evt);
}
});
add(guiUpperRight);
buttonGroup1.add(guiLeft);
guiLeft.setText(MessageBundle.format("placement_centerleft")); // NOI18N
guiLeft.setHideActionText(true);
guiLeft.setHorizontalAlignment(SwingConstants.LEFT);
guiLeft.setHorizontalTextPosition(SwingConstants.RIGHT);
guiLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
guiLeftActionPerformed(evt);
}
});
add(guiLeft);
buttonGroup1.add(guiCenter);
guiCenter.setText(MessageBundle.format("placement_centermiddle")); // NOI18N
guiCenter.setHideActionText(true);
guiCenter.setHorizontalAlignment(SwingConstants.LEFT);
guiCenter.setHorizontalTextPosition(SwingConstants.RIGHT);
guiCenter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
guiCenterActionPerformed(evt);
}
});
add(guiCenter);
buttonGroup1.add(guiRight);
guiRight.setText(MessageBundle.format("placement_centerright")); // NOI18N
guiRight.setHideActionText(true);
guiRight.setHorizontalAlignment(SwingConstants.LEFT);
guiRight.setHorizontalTextPosition(SwingConstants.RIGHT);
guiRight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
guiRightActionPerformed(evt);
}
});
add(guiRight);
buttonGroup1.add(guiDownLeft);
guiDownLeft.setText(MessageBundle.format("placement_bottomleft")); // NOI18N
guiDownLeft.setHideActionText(true);
guiDownLeft.setHorizontalAlignment(SwingConstants.LEFT);
guiDownLeft.setHorizontalTextPosition(SwingConstants.RIGHT);
guiDownLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
guiDownLeftActionPerformed(evt);
}
});
add(guiDownLeft);
buttonGroup1.add(guiDown);
guiDown.setText(MessageBundle.format("placement_bottommiddle")); // NOI18N
guiDown.setHideActionText(true);
guiDown.setHorizontalAlignment(SwingConstants.LEFT);
guiDown.setHorizontalTextPosition(SwingConstants.RIGHT);
guiDown.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
guiDownActionPerformed(evt);
}
});
add(guiDown);
buttonGroup1.add(guiDownRight);
guiDownRight.setText(MessageBundle.format("placement_bottomright")); // NOI18N
guiDownRight.setHideActionText(true);
guiDownRight.setHorizontalAlignment(SwingConstants.LEFT);
guiDownRight.setHorizontalTextPosition(SwingConstants.RIGHT);
guiDownRight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
guiDownRightActionPerformed(evt);
}
});
add(guiDownRight);
}// </editor-fold>//GEN-END:initComponents
private void guiRightActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiRightActionPerformed
this.x = 0f;
this.y = 0.5f;
firePropertyChange(PROPERTY_UPDATED, null, create());
}//GEN-LAST:event_guiRightActionPerformed
private void guiUpperRightActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiUpperRightActionPerformed
this.x = 0f;
this.y = 0f;
firePropertyChange(PROPERTY_UPDATED, null, create());
}//GEN-LAST:event_guiUpperRightActionPerformed
private void guiUpperLeftActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiUpperLeftActionPerformed
this.x = 1f;
this.y = 0f;
firePropertyChange(PROPERTY_UPDATED, null, create());
}//GEN-LAST:event_guiUpperLeftActionPerformed
private void guiUpperActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiUpperActionPerformed
this.x = 0.5f;
this.y = 0f;
firePropertyChange(PROPERTY_UPDATED, null, create());
}//GEN-LAST:event_guiUpperActionPerformed
private void guiLeftActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiLeftActionPerformed
this.x = 1f;
this.y = 0.5f;
firePropertyChange(PROPERTY_UPDATED, null, create());
}//GEN-LAST:event_guiLeftActionPerformed
private void guiCenterActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiCenterActionPerformed
this.x = 0.5f;
this.y = 0.5f;
firePropertyChange(PROPERTY_UPDATED, null, create());
}//GEN-LAST:event_guiCenterActionPerformed
private void guiDownLeftActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiDownLeftActionPerformed
this.x = 1f;
this.y = 1f;
firePropertyChange(PROPERTY_UPDATED, null, create());
}//GEN-LAST:event_guiDownLeftActionPerformed
private void guiDownActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiDownActionPerformed
this.x = 0.5f;
this.y = 1f;
firePropertyChange(PROPERTY_UPDATED, null, create());
}//GEN-LAST:event_guiDownActionPerformed
private void guiDownRightActionPerformed(ActionEvent evt) {//GEN-FIRST:event_guiDownRightActionPerformed
this.x = 0f;
this.y = 1f;
firePropertyChange(PROPERTY_UPDATED, null, create());
}//GEN-LAST:event_guiDownRightActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private ButtonGroup buttonGroup1;
private JRadioButton guiCenter;
private JRadioButton guiDown;
private JRadioButton guiDownLeft;
private JRadioButton guiDownRight;
private JRadioButton guiLeft;
private JRadioButton guiRight;
private JRadioButton guiUpper;
private JRadioButton guiUpperLeft;
private JRadioButton guiUpperRight;
// End of variables declaration//GEN-END:variables
}