/* * Geotoolkit - An Open Source Java GIS Toolkit * http://www.geotoolkit.org * * (C) 2013 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.parameters.creator; import java.awt.Color; import java.awt.Cursor; import java.beans.PropertyChangeEvent; import org.apache.sis.util.iso.SimpleInternationalString; import org.geotoolkit.font.FontAwesomeIcons; import org.geotoolkit.gui.swing.resource.FontIconJButton; import org.geotoolkit.gui.swing.resource.MessageBundle; import org.geotoolkit.utility.parameter.ParametersExt; import org.opengis.parameter.GeneralParameterDescriptor; import org.opengis.parameter.ParameterDescriptor; import org.opengis.util.InternationalString; /** * * @author Quentin Boileau (Geomatys) */ public final class JParameterDescriptorPanel extends GeneralParameterDescriptorPanel { private final boolean editable; private final boolean removable; /** * Simple parameter properties. */ private boolean mandatory; private Class type; private Object defaultValue; /** * Create new JParameterDescriptorPanel * @param paramDesc ParameterDescritor to edit. * @param parent parent JParameterDescriptorGroupPanel. */ public JParameterDescriptorPanel(final ParameterDescriptor paramDesc, final JParameterDescriptorGroupPanel parent, final EditableParameterFilter filter) { super(paramDesc, parent); initComponents(); this.editable = filter != null ? filter.isEditable(paramDesc) : true; this.removable = filter != null ? filter.isRemovable(paramDesc) : true; this.mandatory = paramDesc.getMinimumOccurs() > 0; this.type = paramDesc.getValueClass(); this.defaultValue = paramDesc.getDefaultValue(); guiRemoveParamBtn.setToolTipText(MessageBundle.format("parameters_removeParameter")); //disable remove button if parameter not removable guiRemoveParamBtn.setEnabled(editable); guiParameterNameLbl.setText(code); guiParameterNameLbl.setCursor(new Cursor(Cursor.HAND_CURSOR)); guiParameterNameLbl.addMouseListener(this); } @Override public GeneralParameterDescriptor getDescriptor() { final InternationalString remark = remarks != null ? new SimpleInternationalString(remarks) : null; return ParametersExt.createParameterDescriptor(code, remark, type, null, defaultValue, null, null, null, mandatory); } @Override public void updateContent() { guiParameterNameLbl.setText(code); this.revalidate(); } @Override public void setBackgroundColor(final Color color) { this.setBackground(color); } @Override public boolean isEditable() { return editable; } public boolean isMandatory() { return mandatory; } public void setMandatory(boolean mandatory) { this.mandatory = mandatory; } public Class getType() { return type; } public void setType(Class type) { this.type = type; } public Object getDefaultValue() { return defaultValue; } public void setDefaultValue(Object defaultValue) { this.defaultValue = defaultValue; } /** * 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() { guiParameterNameLbl = new javax.swing.JLabel(); guiRemoveParamBtn = new FontIconJButton(FontAwesomeIcons.ICON_MINUS, 18, Color.RED); org.openide.awt.Mnemonics.setLocalizedText(guiParameterNameLbl, null); guiParameterNameLbl.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 0)); guiRemoveParamBtn.setBorderPainted(false); guiRemoveParamBtn.setContentAreaFilled(false); guiRemoveParamBtn.setFocusable(false); guiRemoveParamBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { guiRemoveParamBtnActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(guiParameterNameLbl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(guiRemoveParamBtn)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(guiParameterNameLbl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(guiRemoveParamBtn) ); }// </editor-fold>//GEN-END:initComponents /** * Fire event to parent JParameterDescriptorGroupPanel * @param evt */ private void guiRemoveParamBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guiRemoveParamBtnActionPerformed //new value boolean used to know if parameter is removed. firePropertyChange(JParameterDescriptorsEditor.PARAMETER_REMOVED_EVENT, this, false); }//GEN-LAST:event_guiRemoveParamBtnActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel guiParameterNameLbl; private javax.swing.JButton guiRemoveParamBtn; // End of variables declaration//GEN-END:variables @Override public void propertyChange(PropertyChangeEvent evt) { if (JParameterDescriptorsEditor.PARAMETER_CHANGE_EVENT.equals(evt.getPropertyName())) { this.revalidate(); } } }