All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.cloudfarming.client.geoviewer.jxmap.layerlist.LayerSettingsPanel Maven / Gradle / Ivy

Go to download

AgroSense geoviewer JXMap implementation. Contains a map/geoviewer TopComponent based on the JXMap classes from swingx.

There is a newer version: 13.03-beta
Show newest version
/**
 * Copyright (C) 2010-2012 Agrosense [email protected]
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.geoviewer.jxmap.layerlist;

import java.awt.event.ItemEvent;
import javax.swing.JSlider;
import nl.cloudfarming.client.geoviewer.Layer;
import nl.cloudfarming.client.geoviewer.LayerInfo;

/**
 * Panel for showing (and editing) layer settings, like visibility and transparency.
 * 
 * @author Timon Veenstra
 */
public class LayerSettingsPanel extends javax.swing.JPanel {

    private final LayerInfo layerInfo;
    private Layer layer;
    private boolean isVisibleInit;
    private boolean initDialogFirstTime = true;
    private int transparancyInit;
    private javax.swing.JCheckBox jCheckBoxVisibility;
    private javax.swing.JLabel jLabelTitle;
    private javax.swing.JLabel jLabelTitleText;
    private javax.swing.JLabel jLabelTransparancy;
    private javax.swing.JLabel jLabelVisibility;
    private javax.swing.JPanel jPanelSettings;
    private javax.swing.JSlider jSliderTransparancy;

    /** Creates new form LayerSettingsPanel */
    public LayerSettingsPanel(Layer layer, LayerInfo layerInfo) {
        this.layer = layer;
        this.layerInfo = layerInfo;
        initComponents();
        initSettings();
    }

    /**
     * Initialize the settings in het panel based on the layer info.
     */
    private void initSettings() {
        isVisibleInit = layerInfo.isVisible();
        transparancyInit = recalcTrans(layerInfo.getTransparency());

        String displayName = layer.getName();

        jLabelTitleText.setText(displayName);

        jCheckBoxVisibility.setSelected(isVisibleInit);
        jSliderTransparancy.setValue(transparancyInit);
    }

    /**
     * Cancel the changes, so go back to the settings while the panel opened.
     */
    public void cancelSettings() {
        if (isVisibleInit) {
             layerInfo.setVisible(true);
        } else {
            layerInfo.setVisible(false);
        }
        layerInfo.setTransparency(recalcTrans(transparancyInit));
    }


    /**
     * recalculate transparency 
     * 
     * @param trans int value for transparency 0-100 where 100 is full transparent
     * @return float transparency from 0.0 to 1.0 where 1.0 is full transparent
     */
    public static float recalcTrans(int trans){
        return (float)((float)trans/100.0);
    }

    /**
     * recalculate transparency 
     * 
     * @param trans float transparency from 0.0 to 1.0 where 1.0 is full transparent
     * @return  trans int value for transparency 0-100 where 100 is full transparent
     */
    public static int recalcTrans(float trans){
        return (int)(trans*100.0f);
    }


    /** 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.
     */
    private void initComponents() {

        jPanelSettings = new javax.swing.JPanel();
        jLabelTitle = new javax.swing.JLabel();
        jLabelTitleText = new javax.swing.JLabel();
        jLabelVisibility = new javax.swing.JLabel();
        jLabelTransparancy = new javax.swing.JLabel();
        jSliderTransparancy = new javax.swing.JSlider();
        jCheckBoxVisibility = new javax.swing.JCheckBox();

        jPanelSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(LayerSettingsPanel.class, "LayerSettingsPanel.jPanelSettings.border.title"))); // NOI18N
        jPanelSettings.setName(""); // NOI18N

        jLabelTitle.setText(org.openide.util.NbBundle.getMessage(LayerSettingsPanel.class, "LayerSettingsPanel.jLabelTitle.text")); // NOI18N

        jLabelTitleText.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabelTitleText.setText(org.openide.util.NbBundle.getMessage(LayerSettingsPanel.class, "LayerSettingsPanel.jLabelTitleText.text")); // NOI18N


        jLabelVisibility.setText(org.openide.util.NbBundle.getMessage(LayerSettingsPanel.class, "LayerSettingsPanel.jLabelVisibility.text")); // NOI18N

        jLabelTransparancy.setText(org.openide.util.NbBundle.getMessage(LayerSettingsPanel.class, "LayerSettingsPanel.jLabelTransparancy.text")); // NOI18N

        jSliderTransparancy.addChangeListener(new javax.swing.event.ChangeListener() {
            @Override
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSliderTransparancyStateChanged(evt);
            }
        });

        jCheckBoxVisibility.setText(org.openide.util.NbBundle.getMessage(LayerSettingsPanel.class, "LayerSettingsPanel.jCheckBoxVisibility.text")); // NOI18N
        jCheckBoxVisibility.addItemListener(new java.awt.event.ItemListener() {
            @Override
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCheckBoxVisibilityItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanelSettingsLayout = new javax.swing.GroupLayout(jPanelSettings);
        jPanelSettings.setLayout(jPanelSettingsLayout);
        jPanelSettingsLayout.setHorizontalGroup(
            jPanelSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSettingsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelSettingsLayout.createSequentialGroup()
                        .addComponent(jLabelTransparancy, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(jPanelSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabelVisibility, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabelTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)))
                .addGroup(jPanelSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSliderTransparancy, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBoxVisibility, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabelTitleText, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanelSettingsLayout.setVerticalGroup(
            jPanelSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSettingsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelTitle)
                    .addComponent(jLabelTitleText, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelVisibility)
                    .addComponent(jCheckBoxVisibility))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelTransparancy)
                    .addComponent(jSliderTransparancy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(36, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanelSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelSettings.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(LayerSettingsPanel.class, "LayerSettingsPanel.jPanel1.AccessibleContext.accessibleName")); // NOI18N
    }

private void jSliderTransparancyStateChanged(javax.swing.event.ChangeEvent evt) {
    JSlider source = (JSlider) evt.getSource();
    layerInfo.setTransparency(recalcTrans(source.getValue()));
}

private void jCheckBoxVisibilityItemStateChanged(java.awt.event.ItemEvent evt) {
    if (initDialogFirstTime) {
        initDialogFirstTime = false;
    } else {
        if (evt.getStateChange() == ItemEvent.SELECTED) {
            layerInfo.setVisible(true);
        } else {
            layerInfo.setVisible(false);
        }
    }
}
    
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy