/*     */ package DFT;
/*     */ 
/*     */ import java.awt.Color;
/*     */ import java.awt.Dimension;
/*     */ import java.awt.Graphics;
/*     */ import java.awt.event.ActionEvent;
/*     */ import java.awt.event.ActionListener;
/*     */ import java.awt.event.MouseEvent;
/*     */ import java.awt.event.MouseListener;
/*     */ import java.awt.event.MouseMotionListener;
/*     */ import java.text.NumberFormat;
/*     */ import javax.swing.ButtonModel;
/*     */ import javax.swing.JButton;
/*     */ import javax.swing.JCheckBox;
/*     */ import javax.swing.JFormattedTextField;
/*     */ import javax.swing.JLabel;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JSeparator;
/*     */ import signals.Signals;
/*     */ 
/*     */ public class Tools
/*     */   extends JPanel
/*     */   implements ActionListener, MouseListener, MouseMotionListener
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*     */   private float[] samples;
/*     */   private float[] dft;
/*  28 */   private int Nsample = 150;
/*     */   private Signals signal;
/*     */   private Graph graph;
/*     */   private int width;
/*  32 */   private float offset = 0.0F;
/*     */   
/*  34 */   private boolean onSig = false;
/*     */   private int widthTmp;
/*  36 */   private boolean removeContinous = false;
/*     */   
/*     */ 
/*  39 */   private JLabel samplingLabel = new JLabel("Sampling Rate: ");
/*  40 */   private JFormattedTextField samplingField = new JFormattedTextField(NumberFormat.getIntegerInstance());
/*  41 */   private JButton okSampleButton = new JButton("Ok");
/*  42 */   private JCheckBox continousPart = new JCheckBox("Remove continous part");
/*     */   
/*     */   public Tools(Signals s, int width, Graph graph) {
/*  45 */     this.signal = s;
/*  46 */     this.graph = graph;
/*  47 */     this.width = width;
/*  48 */     addMouseListener(this);
/*  49 */     addMouseMotionListener(this);
/*     */     
/*  51 */     this.samplingField.setPreferredSize(new Dimension(60, 20));
/*  52 */     this.samplingField.setValue(Integer.valueOf(this.Nsample));
/*  53 */     this.okSampleButton.setPreferredSize(new Dimension(50, 20));
/*  54 */     this.okSampleButton.addActionListener(this);
/*  55 */     this.okSampleButton.addActionListener(new ActionListener() {
/*     */       public void actionPerformed(ActionEvent evt) {
/*  57 */         String tmp = Tools.this.samplingField.getText();
/*  58 */         tmp = tmp.replaceAll(",", "");
/*  59 */         Tools.this.Nsample = Integer.parseInt(tmp);
/*  60 */         Tools.this.genDFT();
/*  61 */         Tools.this.repaint();
/*     */       }
/*     */       
/*  64 */     });
/*  65 */     this.continousPart.addActionListener(new ActionListener() {
/*     */       public void actionPerformed(ActionEvent evt) {
/*  67 */         Tools.this.removeContinous = Tools.this.continousPart.getModel().isSelected();
/*  68 */         Tools.this.genDFT();
/*  69 */         Tools.this.repaint();
/*     */       }
/*     */       
/*  72 */     });
/*  73 */     JSeparator sep = new JSeparator(1);
/*  74 */     sep.setPreferredSize(new Dimension(5, 20));
/*     */     
/*  76 */     add(this.samplingLabel);
/*  77 */     add(this.samplingField);
/*  78 */     add(this.okSampleButton);
/*     */     
/*  80 */     add(sep);
/*     */     
/*  82 */     add(this.continousPart);
/*     */     
/*  84 */     genDFT();
/*     */   }
/*     */   
/*     */   public void paintComponent(Graphics g)
/*     */   {
/*  89 */     g.setColor(new Color(220, 220, 220));
/*  90 */     g.fillRect(0, 0, getWidth(), getHeight());
/*     */     
/*     */ 
/*  93 */     g.translate(0, 30);
/*  94 */     int sigHeight = Signals.heightUnit + Signals.Yspace + 10;
/*     */     
/*  96 */     g.setColor(Color.WHITE);
/*  97 */     g.fillRect(3, 5, getWidth() - 6, sigHeight - 5);
/*  98 */     g.setColor(Color.BLACK);
/*  99 */     g.drawRect(3, 5, getWidth() - 6, sigHeight - 5);
/*     */     
/* 101 */     if (this.onSig) {
/* 102 */       g.setColor(new Color(210, 210, 230));
/* 103 */       g.fillRect(Signals.leftSpace, Signals.Yspace - 8, this.widthTmp - Signals.leftSpace, Signals.heightUnit + 16);
/*     */     }
/*     */     
/* 106 */     this.signal.draw(g, null, 0, getWidth());
/*     */     
/* 108 */     g.setColor(Color.RED);
/* 109 */     for (int i = 0; i < this.Nsample; i++) {
/* 110 */       int x = Signals.leftSpace + i * (this.width - Signals.leftSpace) / this.Nsample;
/* 111 */       g.fillRect(x - 1, (int)(1.0F - this.samples[i]) * Signals.heightUnit + Signals.Yspace - 1, 3, 3);
/*     */     }
/* 113 */     g.translate(0, -30);
/*     */     
/* 115 */     this.graph.update(this.dft);
/*     */   }
/*     */   
/*     */   public void genDFT()
/*     */   {
/* 120 */     this.samples = new float[this.Nsample];
/*     */     
/* 122 */     float[] dftTmp = new float[this.Nsample];
/* 123 */     this.dft = new float[this.Nsample / 2];
/*     */     
/*     */ 
/*     */ 
/* 127 */     for (int i = 0; i < this.Nsample; i++) {
/* 128 */       int x = Signals.leftSpace + i * (this.width - Signals.leftSpace) / this.Nsample;
/* 129 */       this.samples[i] = (this.signal.wave[this.signal.getIndex(x)] + this.offset);
/*     */     }
/*     */     
/* 132 */     dftTmp = DftGen.from(this.samples);
/*     */     
/* 134 */     for (int i = 0; i < this.Nsample / 2; i++) { this.dft[i] = dftTmp[i];
/*     */     }
/*     */     
/* 137 */     if (this.removeContinous) { this.dft[0] = 0.0F;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void actionPerformed(ActionEvent e) {}
/*     */   
/*     */ 
/*     */   public void mouseClicked(MouseEvent arg0)
/*     */   {
    
/* 148 */     //if ((this.onSig = this.widthTmp > Signals.leftSpace ? 1 : 0) != 0) 
              //{
/* 149 */      // this.width = this.widthTmp;
/* 150 */      // genDFT();
/* 151 */      // repaint();
/*     */    // }
/*     */   }
/*     */   
/*     */ 
/*     */   public void mouseEntered(MouseEvent e) {}
/*     */   
/*     */ 
/*     */   public void mouseExited(MouseEvent arg0)
/*     */   {
/* 161 */     this.onSig = false;
/* 162 */     repaint();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public void mousePressed(MouseEvent arg0) {}
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public void mouseReleased(MouseEvent arg0) {}
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public void mouseDragged(MouseEvent arg0) {}
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public void mouseMoved(MouseEvent e)
/*     */   {
/* 185 */     if (e.getY() > 30) this.onSig = true; else
/* 186 */       this.onSig = false;
/* 187 */     this.widthTmp = ((e.getX() - Signals.leftSpace + this.signal.widthUnit / 2) / this.signal.widthUnit * this.signal.widthUnit + Signals.leftSpace);
/* 188 */     repaint();
/*     */   }
/*     */ }


/* Location:              F:\JAVA\WORKSPACE\chronoEditor_v2.3.jar!\DFT\Tools.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */