Package freegressi.graphics

Source Code of freegressi.graphics.JPanelCurve

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    Copyright (C) 2013  Marchand Eric <ricoh51@free.fr>
   
    This file is part of Freegressi.

    Freegressi is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Freegressi 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Freegressi.  If not, see <http://www.gnu.org/licenses/>.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package freegressi.graphics;

import freegressi.tableur.SpreadSheets;
import freegressi.tableur.Tableur;
import javax.swing.ImageIcon;
import javax.swing.JButton;

/**
*
* @author marchand, 15 avr. 2013, 09:34:42
*/
public class JPanelCurve extends javax.swing.JPanel {
  private final JDialogEditCurves jdec;
  private boolean flag = false;

  /** Creates new form JPanelCurve */
  public JPanelCurve(JDialogEditCurves jdec, Curve curve, ImageIcon[] iconPoints,
          String[] textPoints, ImageIcon[] iconLines, String[] textLines) {
    initComponents();
    this.jdec = jdec;
    Tableur sheet = SpreadSheets.getInstance().getActiveSheet();
    jcbName.setModel(new javax.swing.DefaultComboBoxModel(sheet.donneTableauDeNoms()));
    jcbPosition.setModel(new javax.swing.DefaultComboBoxModel(Position.getVerticalPositionArray()));
    jcbPoints.setAllItems(iconPoints, textPoints);
    jcbLines.setAllItems(iconLines, textLines);
    for (int i = 0; i < 10; i++){
      jcbPointSize.addItem(new Integer(i));
      jcbLineWidth.addItem(new Integer(i));
    }
    initValues(curve);  
    flag = true;
  }
 
  private void initValues(Curve curve){
    if (curve == null){
      jcbName.setSelectedIndex(0);
      jcbPosition.setSelectedIndex(0);
      PointLineStyle style = new PointLineStyle();
      jlcc.setColor(style.getColor());
      jcbPoints.setSelectedIndex(style.getPointStyle().getNumber());
      jcbPointSize.setSelectedIndex(style.getPointSize());
      jcbLines.setSelectedIndex(style.getLineStyle().getNumber());
      jcbLineWidth.setSelectedIndex(style.getLineWidth());     
    } else {
      jcbName.setSelectedItem(curve.getyName());
      int pos = Position.getBinaryIndex(curve.getAxisY().getAxisStyle().getPosition());
      jcbPosition.setSelectedIndex(pos);
      PointLineStyle style = curve.getStyle();
      jlcc.setColor(style.getColor());
      jcbPoints.setSelectedIndex(style.getPointStyle().getNumber());
      jcbPointSize.setSelectedIndex(style.getPointSize());
      jcbLines.setSelectedIndex(style.getLineStyle().getNumber());
      jcbLineWidth.setSelectedIndex(style.getLineWidth());
    }
    jcbLineWidth.setToolTipText("Epaisseur des lignes");
    jcbLines.setToolTipText("Style de la ligne");
    jcbName.setToolTipText("Nom de la variable");
    jcbPointSize.setToolTipText("Taille des points");
    jcbPoints.setToolTipText("Style des points");
    jcbPosition.setToolTipText("Position de l'axe");
    jlcc.setToolTipText("Couleur des points et des lignes");   
  }
 
  public String getCurveName(){
    return jcbName.getSelectedItem().toString();
  }
 
  public Position getPosition(){
    return Position.getPosition(jcbPosition.getSelectedItem().toString());
  }
 
  public JButton getRemoveButton(){
    return jbDelete;
  }
 
  public PointLineStyle getPointLineStyle(){
    PointLineStyle pls = new PointLineStyle();
    pls.setColor(jlcc.getColor());
    pls.setLineStyle(LineStyle.getByNumber(jcbLines.getSelectedIndex()));
    pls.setLineWidth(jcbLineWidth.getSelectedIndex());
    pls.setPointStyle(PointStyle.getByNumber(jcbPoints.getSelectedIndex()));
    pls.setPointSize(jcbPointSize.getSelectedIndex());
    return pls;
  }

    /** 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() {

        jcbName = new javax.swing.JComboBox();
        jcbPosition = new javax.swing.JComboBox();
        jlcc = new beans.JLabelColorChoice();
        jcbPointSize = new javax.swing.JComboBox();
        jcbLineWidth = new javax.swing.JComboBox();
        jcbPoints = new beans.JComboBoxIcon();
        jcbLines = new beans.JComboBoxIcon();
        jbDelete = new javax.swing.JButton();

        jcbName.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbName.setToolTipText("");
        jcbName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbNameActionPerformed(evt);
            }
        });

        jcbPosition.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbPosition.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbPositionActionPerformed(evt);
            }
        });

        jbDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/freegressi/img/Gnome-edit-delete-24.png"))); // NOI18N

        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(jcbName, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbPosition, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jlcc, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbPoints, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbPointSize, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbLines, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbLineWidth, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbDelete)
                .addContainerGap(35, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jbDelete)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jcbName, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jcbPosition, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jlcc, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jcbPointSize, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jcbLineWidth, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jcbPoints, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jcbLines, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

  private void jcbPositionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbPositionActionPerformed
    if (flag) {
      //jdec.notifyPositionChanged(this);
      //jdec.reCalculateCurvesAxis();
      jdec.update();
    }
  }//GEN-LAST:event_jcbPositionActionPerformed

  private void jcbNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbNameActionPerformed
    if (flag){
//      String name = jcbName.getSelectedItem().toString();
//      jdec.notifyNameChanged( name, getPosition());    
      jdec.update();
    }
  }//GEN-LAST:event_jcbNameActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jbDelete;
    private javax.swing.JComboBox jcbLineWidth;
    private beans.JComboBoxIcon jcbLines;
    private javax.swing.JComboBox jcbName;
    private javax.swing.JComboBox jcbPointSize;
    private beans.JComboBoxIcon jcbPoints;
    private javax.swing.JComboBox jcbPosition;
    private beans.JLabelColorChoice jlcc;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of freegressi.graphics.JPanelCurve

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.