Package jsynoptic.builtin.ui

Source Code of jsynoptic.builtin.ui.CurvePropertiesPanel$CurveParameters

/* ========================
* 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: CurvePropertiesPanel.java,v 1.15 2009/02/04 11:12:18 ogor Exp $
*
* Changes
* -------
* 28 juin 2005 : Initial public release (CC);
*
*/
package jsynoptic.builtin.ui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;

import jsynoptic.builtin.Plot;

import simtools.data.DataSource;
import simtools.shapes.CurveShape;
import simtools.shapes.StrokeParameters;
import simtools.ui.GridBagPanel;
import simtools.ui.JPropertiesPanel;
import simtools.ui.MenuResourceBundle;
import simtools.ui.ResourceFinder;


/**
* A panel to display/edit curve properties
*
* @author cazenave_c
*/
public class CurvePropertiesPanel extends JPropertiesPanel implements ActionListener{
   
  protected JComboBox cbxcurves;
  protected JComboBox cbxstrokes;
  protected JCheckBox cbpoints, cbdrawBars;
  protected JLabel axis;
  protected JTextField tfcurverename;
  protected JButton bcurvecolor, bcurvedelete;
 
  protected MenuResourceBundle resources;
  protected Vector curves;


  public static final MenuResourceBundle plotResources = ResourceFinder.getMenu(Plot.class);
  protected JLabel lShowPoints, lShowBars;
  protected static Icon showPointsIcon, showPointsIconOff, showBarIcon, showBarIconOff;
  static{
      showPointsIcon = plotResources.getIcon("showPointsIcon");
      showPointsIconOff = plotResources.getIcon("showPointsIconOff");

      showBarIcon = plotResources.getIcon("showBarIcon");
      showBarIconOff = plotResources.getIcon("showBarIconOff");
  }

  public CurvePropertiesPanel(MenuResourceBundle resources){ 
    super(null);
    this.resources=resources;

    // curves combo
    curves=new Vector();
    cbxcurves = new JComboBox(curves);
    cbxcurves.setMaximumRowCount(30);
    cbxcurves.addActionListener(this);
   
    bcurvedelete = resources.getButton("deleteCurveButton", this);

   
    // curve axis
    axis = new JLabel();
   
    // curve display
    GridBagPanel curveDiplay = new GridBagPanel(resources.getStringValue("curveDisplay"));

    bcurvecolor = new JButton("    ");
    bcurvecolor.addActionListener(this);
    cbxstrokes = new JComboBox(StrokeDisplay.defaultstrokes);
    cbxstrokes.setRenderer(new StrokeDisplay());
    cbxstrokes.addActionListener(this);

    curveDiplay.addOnCurrentRow(new JLabel(resources.getString("curveColor")));
    curveDiplay.addOnCurrentRow(bcurvecolor);
    curveDiplay.addOnCurrentRow(new JLabel(resources.getString("curveStyle")));
    curveDiplay.addOnCurrentRow(cbxstrokes);
    curveDiplay.carriageReturn();
   
   
    // curve type
        GridBagPanel curveType = new GridBagPanel(resources.getStringValue("pointDisplay"));
       
        curveType.addOnCurrentRow(lShowPoints = new JLabel(showPointsIconOff));
        curveType.addOnCurrentRow(cbpoints = resources.getCheckBox("points", this));
        curveType.carriageReturn();
       
        curveType.addOnCurrentRow(lShowBars = new JLabel(showBarIconOff));
        curveType.addOnCurrentRow(cbdrawBars = resources.getCheckBox("drawBars", this));
        curveType.carriageReturn();
   
    addOnCurrentRow(cbxcurves, 2, true, false, false);
    addOnCurrentRow(bcurvedelete);
    carriageReturn();
    addOnCurrentRow(axis, 1, true, false, true);
   
    addOnCurrentRow(curveDiplay, 1, true, false, true);
    addOnCurrentRow(curveType, 1, true, false, true);
  }
 

  public String[] getPropertyNames(){
    if (_propertyNames==null)
      _propertyNames = new CurveShape.CurveShapePropertiesNames().getPropertyNames();
    return _propertyNames;
  }
 
  /* (non-Javadoc)
   * @see simtools.util.NamedProperties#setPropertyValue(java.lang.String, java.lang.Object)
   */
  public void setPropertyValue(String name, Object value) {

    if (name.equalsIgnoreCase("PLOT_CURVE_LIST") && (value instanceof Vector)) {
      curves.clear();
      curves.addAll((Vector)value);
      boolean hasCurve = curves.size() > 0;
     
      setEnabled(hasCurve);
     
      if(hasCurve){
        cbxcurves.setSelectedIndex(0);
        curveSelectionhasChanged();
      }
    }
  }
 
  /* (non-Javadoc)
   * @see simtools.util.NamedProperties#getPropertyValue(java.lang.String)
   */
  public Object getPropertyValue(String name) {
    Object res= null;
   
    if (name.equalsIgnoreCase("PLOT_CURVE_LIST")) {
      return curves;
    }
    return res;
  }
 
 
  /* (non-Javadoc)
   * @see javax.swing.JComponent#setEnabled(boolean)
   */
  public void setEnabled(boolean enabled){
      super.setEnabled(enabled);
     
      cbxcurves.setEnabled(enabled);
        bcurvecolor.setEnabled(enabled);
        cbxstrokes.setEnabled(enabled);
        cbpoints.setEnabled(enabled);
        cbdrawBars.setEnabled(enabled);
        bcurvedelete.setEnabled(enabled);
       
        lShowPoints.setIcon(cbpoints.isEnabled()&&cbpoints.isSelected()? showPointsIcon : showPointsIconOff);
        lShowBars.setIcon(cbdrawBars.isEnabled()&&cbdrawBars.isSelected()? showBarIcon : showBarIconOff);
  }
 
 
  /**
   * Update
   */
  protected void curveSelectionhasChanged(){
      Object o = cbxcurves.getSelectedItem();
        if (o instanceof CurveParameters){
            CurveParameters cp=(CurveParameters)o;
            axis.setText(resources.getString("curveAxis")
                    + (cp.usePrimaryX? resources.getString("primaryXAxis": resources.getString("secondaryXAxis"))
                    + (cp.usePrimaryY? resources.getString("primaryYAxis": resources.getString("secondaryYAxis"))
            );
            bcurvecolor.setBackground(cp.color);
            selectStroke(cp.strokeParams);
            cbpoints.setSelected(cp.points);
            cbdrawBars.setSelected(cp.drawBars);
            cbpoints.setEnabled(!cp.drawBars);
           
            lShowPoints.setIcon(cbpoints.isEnabled()&&cbpoints.isSelected()? showPointsIcon : showPointsIconOff);
            lShowBars.setIcon(cbdrawBars.isEnabled()&&cbdrawBars.isSelected()? showBarIcon : showBarIconOff);
        }
  }
 
  //
  // Action listener interface
  //
  public void actionPerformed(ActionEvent e) {
    if (e.getSource()==cbxcurves) {
      if (e.getActionCommand().equals("comboBoxChanged")) {
          curveSelectionhasChanged();
      }
    }
    else if (e.getSource()==cbxstrokes) {
      if (e.getActionCommand().equals("comboBoxChanged")) {
        Object o = cbxstrokes.getSelectedItem();
        if(o instanceof StrokeDisplay){
          StrokeDisplay sd=(StrokeDisplay)o;
          o = cbxcurves.getSelectedItem();
          if (o instanceof CurveParameters){
            CurveParameters cp=(CurveParameters)o;
            cp.strokeParams=sd.getStrokeParams();
          }
        }
      }
    }
    else if (e.getSource()==bcurvecolor) {
      Object o = cbxcurves.getSelectedItem();
      if (o instanceof CurveParameters){
        CurveParameters cp=(CurveParameters)o;
        Color c = JColorChooser.showDialog(
            this,
            resources.getStringValue("curveColorChooserTitle"),
            cp.color
        );
        if (c!=null){
          cp.color=c;
        }
        bcurvecolor.setBackground(cp.color);
      }
    }
    else if (e.getSource()==cbpoints) {
      Object o = cbxcurves.getSelectedItem();
      if (o instanceof CurveParameters){
        CurveParameters cp=(CurveParameters)o;
        cp.points=cbpoints.isSelected();
      }
     
      // update icon
      lShowPoints.setIcon(cbpoints.isSelected()? showPointsIcon : showPointsIconOff);
    }     
    else if (e.getSource()==cbdrawBars) {
      Object o = cbxcurves.getSelectedItem();
      if (o instanceof CurveParameters){
        CurveParameters cp=(CurveParameters)o;
        cp.drawBars=cbdrawBars.isSelected();
        cbpoints.setEnabled(!cbdrawBars.isSelected())
      }
     
      // update icon
            lShowBars.setIcon(cbdrawBars.isSelected()? showBarIcon : showBarIconOff);
     
    }     
    else if (e.getSource()==bcurvedelete) {
      Object o = cbxcurves.getSelectedItem();
      if (o instanceof CurveParameters){
        CurveParameters cp=(CurveParameters)o;
        int index=curves.indexOf(cp);
        cbxcurves.removeItemAt(index);
        if(curves.size()==0){
          bcurvecolor.setEnabled(false);
          cbxstrokes.setEnabled(false);
          cbpoints.setEnabled(false);
          bcurvedelete.setEnabled(false);
        }
        else{

            if(index>(curves.size()-1)){
                index=curves.size()-1;
            }
            cp=(CurveParameters)curves.get(index);
            bcurvecolor.setBackground(cp.color);
            selectStroke(cp.strokeParams);
            cbpoints.setSelected(cp.points);
            cbdrawBars.setSelected(cp.drawBars);
            cbpoints.setEnabled(cp.drawBars)
        }
        lShowBars.setIcon(cbdrawBars.isSelected()? showBarIcon : showBarIconOff);
                lShowPoints.setIcon(cbpoints.isSelected()? showPointsIcon : showPointsIconOff);
      }
      repaint();
    }
  }

  void selectStroke(StrokeParameters dashes){
    for(int i=0;i<cbxstrokes.getItemCount();i++){
      StrokeDisplay sd=(StrokeDisplay)cbxstrokes.getItemAt(i);
      if(sd.getStrokeParams().equals(dashes)){
        cbxstrokes.setSelectedIndex(i);
        return;
      }
    }
    StrokeDisplay nsd=new StrokeDisplay(dashes);
    cbxstrokes.addItem(nsd);
    cbxstrokes.setSelectedItem(nsd);
  }
 
  public static class CurveParameters {
   
    public DataSource xds;
    public DataSource yds;
    public boolean points;
    public boolean drawBars;
    public StrokeParameters strokeParams;
    public Color color;
    public boolean usePrimaryX;
    public boolean usePrimaryY;
   
   
    public CurveParameters(){
      xds=null;
      yds=null;
      points=false;
      drawBars = false;
      strokeParams=new StrokeParameters();
      color=Color.BLACK;
      usePrimaryX = true;
      usePrimaryY = true;
    }
   
    public String toString(){
      if(yds==null){
        return "                              ";
      }
      else{
        return yds.getInformation().id;
      }
    }
   
    public String info(){
      String res="";
      if(xds==null){
        res+="null,";
      }
      else{
        res+=xds.getInformation().label+",";
      }
      if(yds==null){
        res+="null,";
      }
      else{
        res+=yds.getInformation().label+",";
      }
      res+=points+",";
      res+=drawBars+",";
      res+=strokeParams+",";
      res+=color;
      return res;
    }
   
    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj) {
        boolean res = false;
       
      if(obj instanceof CurveParameters){
          CurveParameters dobj=(CurveParameters)obj;
          res = dobj.xds==xds
           && dobj.yds==yds
           && dobj.points==points
           && dobj.drawBars==drawBars
           && dobj.strokeParams.equals(strokeParams)
           && dobj.color.equals(color);
      }
     
      return res;
    }
  }
   
}
TOP

Related Classes of jsynoptic.builtin.ui.CurvePropertiesPanel$CurveParameters

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.