Package jsynoptic.builtin.ui

Source Code of jsynoptic.builtin.ui.AxePropertiesPanel

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program 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;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program 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.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2005, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: AxePropertiesPanel.java,v 1.13 2008/09/08 10:30:24 ogor Exp $
*
* Changes
* -------
* 28 juin 2005 : Initial public release (CC);
*
*/
package jsynoptic.builtin.ui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import simtools.shapes.AxisShape;
import simtools.shapes.AxisShape.AxePropertiesNames;
import simtools.ui.JPropertiesPanel;
import simtools.ui.MenuResourceBundle;
import simtools.ui.NumberField;
import simtools.ui.ResourceFinder;


/**
* A panel to display/edit axe properties
*
* @author cazenave_c
*/
public class AxePropertiesPanel extends JPropertiesPanel implements ActionListener  {
  protected NumberField tfmin, tfmax, tffloatingRange;
  protected NumberField tfstep;
  protected JTextField tflabel;
  protected JCheckBox cbgrid,cbdashedGrid, cbauto,cblog, chFloatingAxe;
  protected String id;
  protected JLabel lmin, lmax, lstep, llabel, lfloatingRange;

  protected static MenuResourceBundle  resources = (MenuResourceBundle)ResourceFinder.get(AxePropertiesPanel.class);

  public AxePropertiesPanel(String title, String id, boolean showFloatingProperties, String shapeName) {
    super(shapeName);
    this.id=id;
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),title));

    JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    cbgrid = resources.getCheckBox("grid", this);
    panel.add(cbgrid);

    cbdashedGrid = resources.getCheckBox("dashedGrid", null);
    panel.add(cbdashedGrid);

    //Adding a check box to switch to logarithmic mode.
    cblog = resources.getCheckBox("logarithmic", null);
    panel.add(cblog);
    llabel = new JLabel(resources.getStringValue("labelLabel"));
    panel.add(llabel);
    tflabel = new JTextField(15);
    panel.add(tflabel);
    cbauto = resources.getCheckBox("autoscale", this);
    panel.add(cbauto);


    add(panel);

    panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    chFloatingAxe = resources.getCheckBox("floatingAxe", null);
    chFloatingAxe.setVisible(showFloatingProperties);
    panel.add(chFloatingAxe);
    lfloatingRange = new JLabel(resources.getStringValue("labelFloatingRange"));
    lfloatingRange.setVisible(showFloatingProperties);
    panel.add(lfloatingRange);
    tffloatingRange = createFloatingRangeField();
    tffloatingRange.setVisible(showFloatingProperties);
    panel.add(tffloatingRange);

    add(panel);

    panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    lmin = new JLabel(resources.getStringValue("minLabel"));
    panel.add(lmin);
    addMinMaxComponent(true,panel);
    lmax = new JLabel(resources.getStringValue("maxLabel"));
    panel.add(lmax);
    tfmax = new NumberField(0, 10);
    addMinMaxComponent(false,panel);
    addStepComponent(panel);
    add(panel);
  }

  protected void addStepComponent(JPanel panel){
    lstep = new JLabel(resources.getStringValue("stepLabel"));
    panel.add(lstep);
    tfstep = new NumberField(0, 10);
    panel.add(tfstep);
  }

  protected void addMinMaxComponent(boolean min, JPanel panel){
    if(min){
      tfmin = new NumberField(0, 10);
      panel.add(tfmin);
    }
    else{
      tfmax = new NumberField(0, 10);
      panel.add(tfmax);
    }
  }

  protected void enableMinMaxStepComponents(boolean enable){
    tfmin.setEnabled(enable);
    tfmax.setEnabled(enable);
    tfstep.setEnabled(enable);
    lmin.setEnabled(enable);
    lmax.setEnabled(enable);
    lstep.setEnabled(enable);
  }
 
  protected NumberField createFloatingRangeField(){
    return new NumberField(5);
  }

  public String[] getPropertyNames(){
    if (_propertyNames==null)
      _propertyNames = new AxePropertiesNames(id).getPropertyNames();
    return _propertyNames;
  }

  protected void setMinMaxComponentValue(boolean min, double value){
    if(min) tfmin.setValue(value);
    else tfmax.setValue(value);
  }

  protected double getStepValue(){
    try{
      return tfstep.getDoubleValue();
    }
    catch(NumberFormatException e){     
    }
    double min;
    double max;
    try{
      min=tfmin.getDoubleValue();
      try{
        max=tfmax.getDoubleValue();
      }
      catch(NumberFormatException e){
        max=min+1.;
      }
    }
    catch(NumberFormatException nfe){
      try{
        max=tfmax.getDoubleValue();
        min=max-1.;
      }
      catch(NumberFormatException e){
        min=0.;
        max=1.;
      }
    }
    return (max-min)/10.;
  }

  protected double getMinMaxComponentValue(boolean min){
    double res;
    if(min){
      try{
        res=tfmin.getDoubleValue();
      }
      catch(NumberFormatException nfe){
        try{
          res=tfmax.getDoubleValue()-1.;
        }
        catch(NumberFormatException e){
          res=0.;
        }
      }
    }
    else{
      try{
        res=tfmax.getDoubleValue();
      }
      catch(NumberFormatException nfe){
        try{
          res=tfmin.getDoubleValue()+1.;
        }
        catch(NumberFormatException e){
          res=1.;
        }
      }
    }
    return res;
  }
 
 

    public void setLabel(String label){
        tflabel.setText(label);
    }


    public void setEnabled(boolean st){
        super.setEnabled(st);

        tflabel.setEnabled(st);
        llabel.setEnabled(st);
        cbgrid.setEnabled(st);
        cbdashedGrid.setEnabled(st);
        cbauto.setEnabled(st);
        cblog.setEnabled(st);
        chFloatingAxe.setEnabled(false);
        lfloatingRange.setEnabled(false);
        tffloatingRange.setEnabled(false);
    }
   
  /* (non-Javadoc)
   * @see simtools.util.NamedProperties#setPropertyValue(java.lang.String, java.lang.Object)
   */
  public void setPropertyValue(String name, Object value) {

    if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_OK") && (value instanceof Boolean)) {
      boolean st=((Boolean)value).booleanValue();
      enableMinMaxStepComponents(st);
      setEnabled(st)
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_GRID") && (value instanceof Boolean)) {
      cbgrid.setSelected(((Boolean)value).booleanValue());
      cbdashedGrid.setEnabled( (cbgrid.isEnabled() && ((Boolean)value).booleanValue()) );
     
    }else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_DASHEDGRID") && (value instanceof Boolean)) {
      cbdashedGrid.setSelected(((Boolean)value).booleanValue());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_AUTO") && (value instanceof Boolean)) {
      cbauto.setSelected(((Boolean)value).booleanValue());
      chFloatingAxe.setEnabled(cbauto.isEnabled() &&((Boolean)value).booleanValue());
      lfloatingRange.setEnabled(cbauto.isEnabled() &&((Boolean)value).booleanValue());
      tffloatingRange.setEnabled(cbauto.isEnabled() &&((Boolean)value).booleanValue());
      enableMinMaxStepComponents(cbauto.isEnabled() && !((Boolean)value).booleanValue());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_LOG") && (value instanceof Boolean)) {
      cblog.setSelected(((Boolean)value).booleanValue());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_MIN") && (value instanceof Double)) {
      setMinMaxComponentValue(true,((Double)value).doubleValue());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_MAX") && (value instanceof Double)) {
      setMinMaxComponentValue(false,((Double)value).doubleValue());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_STEP") && (value instanceof Double)) {
      tfstep.setValue(((Double)value).doubleValue());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_LABEL")){
        setLabel( (value instanceof String)? (String)value : "");
    }
    else if ((name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_FLOATING")) && (value instanceof Boolean)){
        chFloatingAxe.setSelected(((Boolean)value).booleanValue());
    }
    else if ((name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_FLOATING_RANGE")) && (value instanceof Double)){
        tffloatingRange.setValue(((Double)value).doubleValue());
    }
  }

 
  /* (non-Javadoc)
   * @see simtools.util.NamedProperties#getPropertyValue(java.lang.String)
   */
  public Object getPropertyValue(String name) {
      Object res = null;
     
    if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_OK")) {
      res=new Boolean(tflabel.isEnabled());
    }else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_GRID")) {
      res=new Boolean(cbgrid.isSelected());
    }else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_DASHEDGRID")) {
      res=new Boolean(cbdashedGrid.isSelected()&& cbdashedGrid.isEnabled());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_AUTO")) {
      res=new Boolean(cbauto.isSelected());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_LOG")) {
      //return true if logarithmic checkbox is selected.
      res=new Boolean(cblog.isSelected());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_MIN")) {
      res=new Double(getMinMaxComponentValue(true));
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_MAX")) {
      res=new Double(getMinMaxComponentValue(false));
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_STEP")) {
      res=new Double(getStepValue());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_LABEL")) {
      res=tflabel.getText().length()>0 ? tflabel.getText() : null;
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_FLOATING")) {
      res=new Boolean( chFloatingAxe.isSelected());
    }
    else if (name.equalsIgnoreCase(AxisShape.getPrefix(id)+"_FLOATING_RANGE")) {
        if (tffloatingRange.getText()!=null && !tffloatingRange.getText().equals("")){
            res=new Double(tffloatingRange.getDoubleValue());
        }
    }
    return res;
  }


  public void actionPerformed(ActionEvent e){
    if (e.getSource()==cbauto){
      boolean autoscale = cbauto.isSelected();
      chFloatingAxe.setEnabled(autoscale);
      lfloatingRange.setEnabled(autoscale);
      tffloatingRange.setEnabled(autoscale);
   
      enableMinMaxStepComponents(!autoscale);
     
    }else if (e.getSource()==cbgrid){
      cbdashedGrid.setEnabled(cbgrid.isSelected());
    }
  }
}
TOP

Related Classes of jsynoptic.builtin.ui.AxePropertiesPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.