package fidsvd; /** *
Title:
* *Description:
* *Copyright: Copyright (c) 2009
* *Company:
* * @author not attributable * @version 1.0 */ import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; //for JSlider--------------- import java.util.Observable; import java.util.Observer; /***************************************************************************** * * * view SVDMVC * * * *****************************************************************************/ public class SVDMVC extends JApplet { private SVDController controller = new SVDController(); private Graph ggFid = new Graph(); //for FID plotting private Graph ggSpec = new Graph(); //for spectrum plotting private Graph ggSVD = new Graph(); //for SVD plotting private int labelHeight = 20, // label height buttonHeight = 30, // button height panelHeight = 400, // panel height panelWidth = 402; // panel width /***************************************** * Menubar * *****************************************/ JMenuBar menuBar = new JMenuBar(); JMenu menuMatrix = new JMenu("Matrix"); JMenu menuSVD = new JMenu("S V D"); JMenu menuFID = new JMenu("F I D"); JMenu menuSpe = new JMenu("Spectrum"); JMenuItem menuItemShowMatrix = new JMenuItem("Show matrix"); JMenuItem menuItemSaveFID = new JMenuItem("Save initial FID"); JMenuItem menuItemRecallFID = new JMenuItem("Recall initial FID"); JMenuItem menuItemZerofilling128w = new JMenuItem("Zero filling 128w"); JMenuItem menuItemZerofilling256w = new JMenuItem("Zero filling 256w"); JMenuItem menuItemZerofilling512w = new JMenuItem("Zero filling 512w"); JMenuItem menuItemZerofilling1k = new JMenuItem("Zero filling 1k"); JMenuItem menuItemZerofilling2k = new JMenuItem("Zero filling 2k"); JMenuItem menuItemZerofilling4k = new JMenuItem("Zero filling 4k"); JMenuItem menuItemShowSVD = new JMenuItem("Show SVD"); JMenuItem menuItemShowGraphFID = new JMenuItem("Show Graph FID"); JMenuItem menuItemShowGraphSpe = new JMenuItem("Show Graph spectrum"); JMenuItem menuItemShowDataSpe = new JMenuItem("Show Data spectrum"); /*************************************** * Panel Matrix * ***************************************/ //panelMatrix contains panelFid and panelMatrixDim JPanel panelMatrix = new JPanel(); JPanel panelFid = new JPanel(); JPanel panelHeader = new JPanel(); JPanel panelFidData = new JPanel(); JPanel panelMatrixDim = new JPanel(); JLabel labelFidRe = new JLabel("Real"); JLabel labelFidIm = new JLabel("Imaginary"); JLabel labelFid1 = new JLabel("FID"); JLabel labelFid2 = new JLabel("FID"); JLabel labelMatrixDim = new JLabel("Complex matrix dimension:"); JLabel labelMatrixDimRow = new JLabel("rows"); JLabel labelMatrixDimColumn = new JLabel("columns"); JLabel labelMatrixDimCondition = new JLabel("with columns <= rows"); JLabel labelSizeFID = new JLabel("Size of FID"); JTextArea textAreaFIDReal = new JTextArea(); JTextArea textAreaFIDImag = new JTextArea(); //0+"\n"+1+"\n"+4+"\n"+9+"\n" JScrollPane scrollPaneFid = new JScrollPane(); JTextField textFieldMatrixRow = new JTextField(); JTextField textFieldMatrixColumn = new JTextField(); JTextField textFieldSizeFID = new JTextField(); JButton buttonViewFID = new JButton("View FID"); JButton buttonClearFID = new JButton("Clear FID"); JButton buttonRunSVD = new JButton("Run SVD"); /*************************************** * Panel S V D * ***************************************/ JPanel panelSVD = new JPanel(); JPanel panelEigenValue = new JPanel(); JPanel panelEigenValueHeader = new JPanel(); JPanel panelEigenValueData = new JPanel(); JLabel labelEigen = new JLabel("Singular values"); JTextField textFieldSVD = new JTextField("2"); JTextArea textAreaEigenValue = new JTextArea(); JScrollPane scrollPaneEigenValue = new JScrollPane(); JButton buttonHankel = new JButton("Hankel"); /*************************************** * Panel Graph FID * ***************************************/ JPanel panelGraphFID = new JPanel(); JLabel labelNbData1 = new JLabel("Number of"); JLabel labelNbData2 = new JLabel("data:"); JLabel labelDataPoint = new JLabel(); JLabel labelZeroFill = new JLabel("Zero filling to"); JTextField textFieldZeroFill = new JTextField(); JButton buttonRunFFT = new JButton("Run FFT"); /*************************************** * Panel Graph spectrum * ***************************************/ JPanel panelGraphSpectrum = new JPanel(); JPanel panelDataSpectrum = new JPanel(); JPanel panelDataSpe = new JPanel(); JPanel panelDataSpeHeader = new JPanel(); JPanel panelSpectrumData = new JPanel(); JLabel labelPhaseCorr = new JLabel("Phase correction:"); JLabel labelPhase0 = new JLabel("0-th"); JLabel labelPhase1 = new JLabel("1-st"); JLabel labelSpeRe = new JLabel("Absorption"); JLabel labelSpeIm = new JLabel("Dispersion"); JLabel labelSpectrum1 = new JLabel("Spectrum"); JLabel labelSpectrum2 = new JLabel("Spectrum"); JTextArea textAreaSpeAbs = new JTextArea(); JTextArea textAreaSpeDisp = new JTextArea(); JScrollPane scrollPaneSpe = new JScrollPane(); JButton buttonIncrease0 = new JButton("+"); JButton buttonDecrease0 = new JButton("-"); JButton buttonIncrease1 = new JButton("+"); JButton buttonDecrease1 = new JButton("-"); JButton buttonSavePhase = new JButton("Save Spectrum"); static final int PI_ANGLE = 180; static final int MINUS_PI_ANGLE = -180; static final int INIT_ANGLE = 0; JSlider zeroPhaseCorrection = new JSlider(JSlider.VERTICAL, MINUS_PI_ANGLE, PI_ANGLE, INIT_ANGLE); JSlider firstPhaseCorrection = new JSlider(JSlider.VERTICAL, MINUS_PI_ANGLE, PI_ANGLE, INIT_ANGLE); //Construct the applet public SVDMVC() { } //Initialize the applet public void init() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { //très important : une seule fois dans un programme avant l'utilisation //de Jampack SVDMVCModel modela = new SVDMVCModel(); try { modela.essaisetBaseIndex(); } catch (Exception e) { buttonViewFID.setBackground(Color.yellow); } /*************************************** * Menu bar * ***************************************/ setJMenuBar(menuBar); menuBar.add(menuMatrix); menuBar.add(menuSVD); menuBar.add(menuFID); menuBar.add(menuSpe); menuMatrix.add(menuItemShowMatrix); menuMatrix.addSeparator(); menuMatrix.add(menuItemSaveFID); menuMatrix.add(menuItemRecallFID); menuSVD.add(menuItemShowSVD); menuFID.add(menuItemShowGraphFID); menuFID.addSeparator(); menuFID.add(menuItemZerofilling128w); menuFID.add(menuItemZerofilling256w); menuFID.add(menuItemZerofilling512w); menuFID.add(menuItemZerofilling1k); menuFID.add(menuItemZerofilling2k); menuFID.add(menuItemZerofilling4k); menuSpe.add(menuItemShowGraphSpe); menuSpe.add(menuItemShowDataSpe); //applet area this.setBackground(Color.white); this.getContentPane().setLayout(null); /*************************************** * Panel Matrix * ***************************************/ panelMatrix.setLayout(null); panelMatrix.setBackground(Color.yellow); panelMatrix.setBounds(2, 2, panelWidth, panelHeight); panelMatrix.setFont(new Font("TimesRoman", Font.PLAIN, 12)); this.getContentPane().add(panelMatrix); //Panel FIDData panelFid.setBounds(2, 2, 200, panelHeight-4); panelMatrix.add(panelFid); panelFid.setBackground(Color.pink); panelFid.setLayout(null); panelFid.setFont(new Font("TimesRoman", Font.PLAIN, 12)); panelHeader.setBounds(10, 7, 180, 2*labelHeight); panelHeader.setLayout(null); panelHeader.setBackground(Color.pink); labelFidRe.setBounds(0, 0, 90, labelHeight); panelHeader.add(labelFidRe); labelFidIm.setBounds(90, 0, 90, labelHeight); panelHeader.add(labelFidIm); labelFid1.setBounds(0, labelHeight, 90, labelHeight); panelHeader.add(labelFid1); labelFid2.setBounds(90, labelHeight, 90, labelHeight); panelHeader.add(labelFid2); panelFid.add(panelHeader); scrollPaneFid.setBounds(10, 50, 180, 240); scrollPaneFid.getViewport().add(panelFidData); panelFid.add(scrollPaneFid); panelFidData.setLayout(new GridLayout(1,2)); panelFidData.add(textAreaFIDReal); panelFidData.add(textAreaFIDImag); textAreaFIDReal.setBackground(Color.orange); textAreaFIDImag.setBackground(Color.yellow); textAreaFIDReal.setMargin(new Insets(5, 5, 5, 5)); textAreaFIDImag.setMargin(new Insets(5, 5, 5, 5)); textAreaFIDReal.setEditable(true); textAreaFIDImag.setEditable(true); buttonViewFID.setBounds(10, 300, 90, buttonHeight); buttonViewFID.setBackground(Color.red); panelFid.add(buttonViewFID); buttonRunSVD.setBounds(100, 300, 90, buttonHeight); buttonRunSVD.setBackground(Color.red); panelFid.add(buttonRunSVD); buttonClearFID.setBounds(40, 350, 115, buttonHeight); buttonClearFID.setBackground(Color.red); panelFid.add(buttonClearFID); //Panel MatrixDim panelMatrixDim.setBounds(206, 2, 194, panelHeight-4); panelMatrix.add(panelMatrixDim); panelMatrixDim.setBackground(Color.pink); panelMatrixDim.setLayout(null); panelMatrixDim.setFont(new Font("TimesRoman", Font.PLAIN, 14)); labelMatrixDim.setBounds(10, 20, 190, labelHeight); panelMatrixDim.add(labelMatrixDim); textFieldMatrixRow.setBounds(10, 50, 50, labelHeight); panelMatrixDim.add(textFieldMatrixRow); labelMatrixDimRow.setBounds(70, 50, 120, labelHeight); panelMatrixDim.add(labelMatrixDimRow); textFieldMatrixColumn.setBounds(10, 80, 50, labelHeight); panelMatrixDim.add(textFieldMatrixColumn); labelMatrixDimColumn.setBounds(70, 80, 100, labelHeight); panelMatrixDim.add(labelMatrixDimColumn); labelMatrixDimCondition.setBounds(10, 110, 160, labelHeight); panelMatrixDim.add(labelMatrixDimCondition); labelSizeFID.setBounds(10, 140, 100, labelHeight); panelMatrixDim.add(labelSizeFID); textFieldSizeFID.setBounds(70, 140, 50, labelHeight); panelMatrixDim.add(textFieldSizeFID); /*************************************** * Panel S V D * ***************************************/ panelSVD.setLayout(null); panelSVD.setBackground(Color.yellow); panelSVD.setBounds(2, 2, panelWidth, panelHeight); panelSVD.setFont(new Font("TimesRoman", Font.PLAIN, 12)); this.getContentPane().add(panelSVD); //Panel EigenValue panelEigenValue.setBounds(2, 2, panelWidth-4, panelHeight-4); panelSVD.add(panelEigenValue); panelEigenValue.setBackground(Color.pink); panelEigenValue.setLayout(null); panelEigenValue.setFont(new Font("TimesRoman", Font.PLAIN, 12)); //Panel EigenValueHeader panelEigenValueHeader.setBounds(10, 7, 120, labelHeight); panelEigenValueHeader.setLayout(null); panelEigenValueHeader.setBackground(Color.pink); labelEigen.setBounds(0, 0, 120, labelHeight); panelEigenValueHeader.add(labelEigen); panelEigenValue.add(panelEigenValueHeader); scrollPaneEigenValue.setBounds(10, labelHeight+10, 260, 80); scrollPaneEigenValue.getViewport().add(panelEigenValueData); panelEigenValue.add(scrollPaneEigenValue); panelEigenValueData.setLayout(new GridLayout(1,1)); panelEigenValueData.add(textAreaEigenValue); textAreaEigenValue.setBackground(Color.orange); textAreaEigenValue.setMargin(new Insets(5, 5, 5, 5)); textAreaEigenValue.setEditable(true); textFieldSVD.setBounds(290, labelHeight+10, 95, buttonHeight); textFieldSVD.setBackground(Color.white); panelEigenValue.add(textFieldSVD); buttonHankel.setBounds(290, 100-labelHeight, 95, buttonHeight); buttonHankel.setBackground(Color.red); panelEigenValue.add(buttonHankel); ggSVD.setBounds(10, 110, panelWidth-25, 275); ggSVD.setBackground(Color.pink); panelEigenValue.add(ggSVD); ggSVD.setVisible(false); //very important /*************************************** * Panel Graph FID * ***************************************/ panelGraphFID.setLayout(null); panelGraphFID.setBackground(Color.yellow); panelGraphFID.setBounds(2, 2, panelWidth, panelHeight); panelGraphFID.setFont(new Font("TimesRoman", Font.PLAIN, 12)); this.getContentPane().add(panelGraphFID); ggFid.setBounds(2, 2, 300, panelHeight-4); ggFid.setBackground(Color.pink); panelGraphFID.add(ggFid); ggFid.setVisible(false); //very important labelNbData1.setBounds(310, 10, 85, labelHeight); panelGraphFID.add(labelNbData1); labelNbData2.setBounds(310, 10+labelHeight, 48, labelHeight); panelGraphFID.add(labelNbData2); labelDataPoint.setBounds(358, 10+labelHeight, 48, labelHeight); panelGraphFID.add(labelDataPoint); labelZeroFill.setBounds(310, 10+2*labelHeight, 85, labelHeight); panelGraphFID.add(labelZeroFill); textFieldZeroFill.setBounds(310, 10+3*labelHeight+4, 50, buttonHeight); panelGraphFID.add(textFieldZeroFill); buttonRunFFT.setBounds(310, 30+3*labelHeight+buttonHeight, 85, buttonHeight); buttonRunFFT.setBackground(Color.red); panelGraphFID.add(buttonRunFFT); /*************************************** * Panel Graph Spectrum * ***************************************/ panelGraphSpectrum.setLayout(null); panelGraphSpectrum.setBackground(Color.yellow); panelGraphSpectrum.setBounds(2, 2, panelWidth, panelHeight); panelGraphSpectrum.setFont(new Font("TimesRoman", Font.PLAIN, 12)); this.getContentPane().add(panelGraphSpectrum); ggSpec.setBounds(2, 2, 282, panelHeight-4); ggSpec.setBackground(Color.pink); panelGraphSpectrum.add(ggSpec); ggSpec.setVisible(false); //very important labelPhaseCorr.setBounds(286, 2, 114, labelHeight); panelGraphSpectrum.add(labelPhaseCorr); labelPhase0.setBounds(286, 2+labelHeight, 56, labelHeight); panelGraphSpectrum.add(labelPhase0); labelPhase1.setBounds(344, 2+labelHeight, 56, labelHeight); panelGraphSpectrum.add(labelPhase1); buttonIncrease0.setBounds(286, 2+2*labelHeight, 56, buttonHeight/2); buttonIncrease0.setBackground(Color.red); panelGraphSpectrum.add(buttonIncrease0); buttonDecrease0.setBounds(286, 2+2*labelHeight+16, 56, buttonHeight/2); buttonDecrease0.setBackground(Color.red); panelGraphSpectrum.add(buttonDecrease0); buttonIncrease1.setBounds(344, 2+2*labelHeight, 56, buttonHeight/2); buttonIncrease1.setBackground(Color.red); panelGraphSpectrum.add(buttonIncrease1); buttonDecrease1.setBounds(344, 2+2*labelHeight+16, 56, buttonHeight/2); buttonDecrease1.setBackground(Color.red); panelGraphSpectrum.add(buttonDecrease1); zeroPhaseCorrection.setBackground(Color.lightGray); zeroPhaseCorrection.setBounds(286, 10+labelHeight+buttonHeight+buttonHeight/2, 56, panelHeight-10-2*buttonHeight-2*labelHeight); panelGraphSpectrum.add(zeroPhaseCorrection); firstPhaseCorrection.setBackground(Color.lightGray); firstPhaseCorrection.setBounds(344, 10+labelHeight+buttonHeight+buttonHeight/2, 56, panelHeight-10-2*buttonHeight-2*labelHeight); panelGraphSpectrum.add(firstPhaseCorrection); //Turn on labels at major tick marks zeroPhaseCorrection.setMajorTickSpacing(20); zeroPhaseCorrection.setPaintTicks(true); zeroPhaseCorrection.setPaintLabels(false); firstPhaseCorrection.setMajorTickSpacing(20); firstPhaseCorrection.setPaintTicks(true); firstPhaseCorrection.setPaintLabels(false); buttonSavePhase.setBounds(286, panelHeight-2-buttonHeight, 114, buttonHeight); buttonSavePhase.setBackground(Color.red); panelGraphSpectrum.add(buttonSavePhase); /*************************************** * Panel Data Spectrum * ***************************************/ panelDataSpectrum.setLayout(null); panelDataSpectrum.setBackground(Color.yellow); panelDataSpectrum.setBounds(2, 2, panelWidth, panelHeight); panelDataSpectrum.setFont(new Font("TimesRoman", Font.PLAIN, 12)); this.getContentPane().add(panelDataSpectrum); //Panel Data Spe panelDataSpe.setBounds(2, 2, 200, panelHeight-4); panelDataSpectrum.add(panelDataSpe); panelDataSpe.setBackground(Color.pink); panelDataSpe.setLayout(null); panelDataSpe.setFont(new Font("TimesRoman", Font.PLAIN, 12)); panelDataSpeHeader.setBounds(10, 7, 180, 2*labelHeight); panelDataSpeHeader.setLayout(null); panelDataSpeHeader.setBackground(Color.pink); labelSpeRe.setBounds(0, 0, 90, labelHeight); panelDataSpeHeader.add(labelSpeRe); labelSpeIm.setBounds(90, 0, 90, labelHeight); panelDataSpeHeader.add(labelSpeIm); labelSpectrum1.setBounds(0, labelHeight, 90, labelHeight); panelDataSpeHeader.add(labelSpectrum1); labelSpectrum2.setBounds(90, labelHeight, 90, labelHeight); panelDataSpeHeader.add(labelSpectrum2); panelDataSpe.add(panelDataSpeHeader); scrollPaneSpe.setBounds(10, 50, 180, 240); scrollPaneSpe.getViewport().add(panelSpectrumData); panelDataSpe.add(scrollPaneSpe); panelSpectrumData.setLayout(new GridLayout(1,2)); panelSpectrumData.add(textAreaSpeAbs); panelSpectrumData.add(textAreaSpeDisp); textAreaSpeAbs.setBackground(Color.orange); textAreaSpeDisp.setBackground(Color.yellow); textAreaSpeAbs.setMargin(new Insets(5, 5, 5, 5)); textAreaSpeDisp.setMargin(new Insets(5, 5, 5, 5)); textAreaSpeAbs.setEditable(true); textAreaSpeDisp.setEditable(true); } //end of jbinit /*************************************** * start() * ***************************************/ public void start() { panelMatrix.setVisible(true); panelMatrixDim.setVisible(false); panelSVD.setVisible(false); panelGraphFID.setVisible(false); panelGraphSpectrum.setVisible(false); menuMatrix.setEnabled(true); menuSVD.setEnabled(false); menuFID.setEnabled(false); menuSpe.setEnabled(false); //------------------------------- buttonRunSVD.setEnabled(false); textFieldZeroFill.setEnabled(false); buttonViewFID.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonViewFID.getText() == "View FID") { controller.buttonViewFID() ; }; } }); buttonRunSVD.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonRunSVD.getText() == "Run SVD") { controller.buttonRunSVD() ; }; } }); buttonClearFID.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonClearFID.getText() == "Clear FID") { controller.buttonClearFID() ; }; } }); buttonHankel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonHankel.getText() == "Hankel") { controller.buttonHankel(); }; } }); buttonRunFFT.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonRunFFT.getText() == "Run FFT") { controller.buttonRunFFT(); }; } }); buttonIncrease0.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonIncrease0.getText() == "+") { controller.buttonIncrease0(); }; } }); buttonDecrease0.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonDecrease0.getText() == "-") { controller.buttonDecrease0(); }; } }); buttonIncrease1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonIncrease1.getText() == "+") { controller.buttonIncrease1(); }; } }); buttonDecrease1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonDecrease1.getText() == "-") { controller.buttonDecrease1(); }; } }); buttonSavePhase.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonSavePhase.getText() == "Save Spectrum") { controller.buttonSavePhase(); }; } }); menuItemShowMatrix.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemShowMatrix.getText() == "Show matrix") { controller.menuItemShowMatrix(); }; } }); menuItemSaveFID.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemSaveFID.getText() == "Save initial FID") { controller.menuItemSaveFID(); }; } }); menuItemRecallFID.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemRecallFID.getText() == "Recall initial FID") { controller.menuItemRecallFID(); }; } }); menuItemZerofilling128w.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemZerofilling128w.getText() == "Zero filling 128w") { controller.menuItemZerofilling128w(); }; } }); menuItemZerofilling256w.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemZerofilling256w.getText() == "Zero filling 256w") { controller.menuItemZerofilling256w(); }; } }); menuItemZerofilling512w.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemZerofilling512w.getText() == "Zero filling 512w") { controller.menuItemZerofilling512w(); }; } }); menuItemZerofilling1k.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemZerofilling1k.getText() == "Zero filling 1k") { controller.menuItemZerofilling1k(); }; } }); menuItemZerofilling2k.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemZerofilling2k.getText() == "Zero filling 2k") { controller.menuItemZerofilling2k(); }; } }); menuItemZerofilling4k.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemZerofilling4k.getText() == "Zero filling 4k") { controller.menuItemZerofilling4k(); }; } }); menuItemShowSVD.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemShowSVD.getText() == "Show SVD") { controller.menuItemShowSVD(); }; } }); menuItemShowGraphFID.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemShowGraphFID.getText() == "Show Graph FID") { controller.menuItemShowGraphFID(); }; } }); menuItemShowGraphSpe.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemShowGraphSpe.getText() == "Show Graph spectrum") { controller.menuItemShowGraphSpe(); }; } }); menuItemShowDataSpe.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemShowDataSpe.getText() == "Show Data spectrum") { controller.menuItemShowDataSpe(); }; } }); }//end of start() /**Stop the applet*/ public void stop() { } /**Destroy the applet*/ public void destroy() { } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } /************************************************************************ * * * controller SVDController * * * ************************************************************************/ private class SVDController implements Observer, ChangeListener { //ChangeListener for JSlider--------------- public SVDMVCModel model = new SVDMVCModel(); public Fourier four = new Fourier(); final double ANGLE_DEGRE = Math.PI/180; private String stringFIDreal, stringFIDimaginary; public SVDController() { model.addObserver(this); } public void update(Observable o, Object arg){ } /** Listen to the slider. */ //JSlider has only one method stateChanged()--------------- public void stateChanged(ChangeEvent e) { int maxNb = model.getmaxNbComplex(); double[] fma = model.getAbsorption(); double[] fmd = model.getDispersion(); double[] fna = new double[maxNb]; double[] fnd = new double[maxNb]; int phi0 = 0; int phi1 = 0; //zero order phase correction if (zeroPhaseCorrection.getValueIsAdjusting()) { phi0 = (int) zeroPhaseCorrection.getValue(); double phase = model.getPhi1(); double phasetmp; for (int i = 0; i < maxNb; i++) { phasetmp = ANGLE_DEGRE*(phi0 + phase*i/maxNb); fna[i] = fma[i]*Math.cos(phasetmp) - fmd[i]*Math.sin(phasetmp); fnd[i] = fmd[i]*Math.cos(phasetmp) + fma[i]*Math.sin(phasetmp); } //spectrum plotting double inc; ggSpec.Graph("Spectrum", "omega", "Intensity"); ggSpec.setSymbol(false); ggSpec.setLine(true); ggSpec.setColor(ggSpec.red); ggSpec.setTitle("spec"); for (int i = 0; i < maxNb; i++) { inc = i; ggSpec.add(inc, fna[i]); } ggSpec.showGraph(); //save phi0 model.setPhi0(phi0); }//end if zeroPhaseCorrection //first order phase correction if (firstPhaseCorrection.getValueIsAdjusting()) { phi1 = (int) firstPhaseCorrection.getValue(); double phase = model.getPhi0(); double phasetmp; for (int i = 0; i < maxNb; i++) { phasetmp = ANGLE_DEGRE*(phase + phi1*i/maxNb); fna[i] = fma[i]*Math.cos(phasetmp) - fmd[i]*Math.sin(phasetmp); fnd[i] = fmd[i]*Math.cos(phasetmp) + fma[i]*Math.sin(phasetmp); } //spectrum plotting double inc; ggSpec.Graph("Spectrum", "omega", "Intensity"); ggSpec.setSymbol(false); ggSpec.setLine(true); ggSpec.setColor(ggSpec.red); ggSpec.setTitle("spec"); for (int i = 0; i < maxNb; i++) { inc = i; ggSpec.add(inc, fna[i]); } ggSpec.showGraph(); //save phi1 model.setPhi1(phi1); }//end if firstPhaseCorrection }// end of stateChanged /*************************************** * Matrix * ***************************************/ private void menuItemShowMatrix() { panelMatrix.setVisible(true); panelSVD.setVisible(false); panelGraphFID.setVisible(false); panelGraphSpectrum.setVisible(false); panelDataSpectrum.setVisible(false); menuItemSaveFID.setEnabled(true); menuItemRecallFID.setEnabled(true); } private void menuItemSaveFID() { stringFIDreal = textAreaFIDReal.getText(); stringFIDimaginary = textAreaFIDImag.getText(); } private void menuItemRecallFID() { textAreaFIDReal.setText(stringFIDreal); textAreaFIDImag.setText(stringFIDimaginary); } //--------------------// // ButtonClearFID // //--------------------// private void buttonClearFID() { textAreaFIDReal.setText(""); textAreaFIDImag.setText(""); panelMatrixDim.setVisible(false); menuSVD.setEnabled(false); menuFID.setEnabled(false); buttonRunSVD.setEnabled(false); menuItemSaveFID.setEnabled(true); menuItemRecallFID.setEnabled(true); menuItemZerofilling128w.setEnabled(true); menuItemZerofilling256w.setEnabled(true); menuItemZerofilling512w.setEnabled(true); menuItemZerofilling1k.setEnabled(true); menuItemZerofilling2k.setEnabled(true); menuItemZerofilling4k.setEnabled(true); } //--------------------// // ButtonViewFID // //--------------------// private void buttonViewFID() { provideFid(); menuFID.setEnabled(true); buttonRunSVD.setEnabled(true); menuItemZerofilling128w.setEnabled(false); menuItemZerofilling256w.setEnabled(false); menuItemZerofilling512w.setEnabled(false); menuItemZerofilling1k.setEnabled(false); menuItemZerofilling2k.setEnabled(false); menuItemZerofilling4k.setEnabled(false); } //--------------------// // ButtonRunSVD // //--------------------// private void buttonRunSVD() { provideFid(); //SVD call double[] titi; try { model.essaiZsvd(); } catch (Exception e) { buttonViewFID.setBackground(Color.green); } titi = model.getSVD(); //Show eigenvalues String s2 = ""; for (int j = 0; j < model.getmvalue(); j++) { s2 += titi[j] + "\n"; } textAreaEigenValue.setText(s2); //SVD plotting double inc; double[] tmp = model.getSVD(); ggSVD.Graph("SVD", "n", "svd"); ggSVD.setSymbol(true); ggSVD.setLine(true); ggSVD.setColor(ggSVD.black); for (int i = 0; i < model.getmvalue(); i++){ inc = i; ggSVD.add(inc, tmp[i]); } ggSVD.showGraph(); panelMatrixDim.setVisible(true); menuSVD.setEnabled(true); } //--------------------// // provideFid() // //--------------------// private void provideFid() { //number of complex points in the FID, -1 due to carriage return int lineCount = textAreaFIDReal.getLineCount() - 1; model.setmaxNbComplex(lineCount); textFieldSizeFID.setText(lineCount+"\n"); //number of rows for the Hankel matrix textFieldMatrixRow.setText(model.getnvalue()+"\n"); //number of columns for the Hankel matrix textFieldMatrixColumn.setText(model.getmvalue()+"\n"); //convert experimental real part of FID intensities into numbers String sr = textAreaFIDReal.getText(), s1r = ""; int spaceAtr = 0, startingFormr = 0, ipr = 0; double[] tmpr = new double[model.getmaxNbComplex()]; while (true) { spaceAtr = sr.indexOf("\n", startingFormr); if (spaceAtr == -1) break; s1r = sr.substring(startingFormr, spaceAtr); tmpr[ipr] = Double.valueOf(s1r).doubleValue(); startingFormr = spaceAtr + 1; ipr++; } model.setfidRe(tmpr); //convert experimental imaginary part of FID intensities into numbers String si = textAreaFIDImag.getText(), s1i = ""; int spaceAti = 0, startingFormi = 0, ipi = 0; double[] tmpi = new double[model.getmaxNbComplex()]; while (true) { spaceAti = si.indexOf("\n", startingFormi); if (spaceAti == -1) break; s1i = si.substring(startingFormi, spaceAti); tmpi[ipi] = Double.valueOf(s1i).doubleValue(); startingFormi = spaceAti + 1; ipi++; } model.setfidIm(tmpi); } /*************************************** * S V D * ***************************************/ private void menuItemShowSVD() { panelMatrix.setVisible(false); panelSVD.setVisible(true); panelGraphFID.setVisible(false); panelGraphSpectrum.setVisible(false); panelDataSpectrum.setVisible(false); menuItemSaveFID.setEnabled(false); menuItemRecallFID.setEnabled(false); menuItemZerofilling128w.setEnabled(false); menuItemZerofilling256w.setEnabled(false); menuItemZerofilling512w.setEnabled(false); menuItemZerofilling1k.setEnabled(false); menuItemZerofilling2k.setEnabled(false); menuItemZerofilling4k.setEnabled(false); } //--------------------// // ButtonHankel // //--------------------// private void buttonHankel() { buttonRunSVD.setEnabled(false); //number of SVD elements used int nbSVD = Integer.parseInt(textFieldSVD.getText()); int mvalue = model.getmvalue(); //convert selected SVD elements into numbers double[] usedSVD = new double[mvalue]; String s = textAreaEigenValue.getText(), s1 = ""; int spaceAt = 0, startingForm = 0; for (int i = 0; i < nbSVD; i++) { spaceAt = s.indexOf("\n", startingForm); if (spaceAt == -1) break; s1 = s.substring(startingForm, spaceAt); usedSVD[i] = Double.valueOf(s1).doubleValue(); startingForm = spaceAt + 1; } //provide usedSVD to SVDMVCmodel model.setSVD(usedSVD); //show used SVD elements double[] titi = model.getSVD(); String s2 = ""; for (int j = 0; j < model.getmvalue(); j++) { s2 += titi[j] + "\n"; } textAreaEigenValue.setText(s2); try { model.createFID(); //put FID in textAreaFIDReal and textAreaFIDImag String sfidre = "", sfidim = ""; double[] fr = model.getfidRe(); double[] fi = model.getfidIm(); int max = model.getmaxNbComplex(); for (int i = 0; i < max; i++) { sfidre += fr[i] + "\n"; sfidim += fi[i] + "\n"; } textAreaFIDReal.setText(sfidre); textAreaFIDImag.setText(sfidim); } catch (Exception e) { textAreaEigenValue.setBackground(Color.green); } } /*************************************** * Graph FID * ***************************************/ private void zerofilling(int n) { int maxNb = model.getmaxNbComplex(); double [] fidReZerofilling = new double[n]; double [] fidImZerofilling = new double[n]; double [] fidReZero = model.getfidRe(); double [] fidImZero = model.getfidIm(); for (int i = 0; i < maxNb; i++) { fidReZerofilling[i] = fidReZero[i]; fidImZerofilling[i] = fidImZero[i]; } model.setfidRe(fidReZerofilling); model.setfidIm(fidImZerofilling); model.setmaxNbComplex(n); buttonRunFFT.setEnabled(true); textFieldZeroFill.setEnabled(true); textFieldZeroFill.setText(Integer.toString(n)); } private void menuItemZerofilling128w() { zerofilling(128); } private void menuItemZerofilling256w() { zerofilling(256); } private void menuItemZerofilling512w() { zerofilling(512); } private void menuItemZerofilling1k() { zerofilling(1024); } private void menuItemZerofilling2k() { zerofilling(2048); } private void menuItemZerofilling4k() { zerofilling(4096); } private void menuItemShowGraphFID() { buttonRunFFT.setEnabled(false); provideFid(); double yr[] = model.getfidRe(); double yi[] = model.getfidIm(); panelMatrix.setVisible(false); panelSVD.setVisible(false); panelGraphFID.setVisible(true); panelGraphSpectrum.setVisible(false); panelDataSpectrum.setVisible(false); menuItemSaveFID.setEnabled(false); menuItemRecallFID.setEnabled(false); menuItemZerofilling128w.setEnabled(true); menuItemZerofilling256w.setEnabled(true); menuItemZerofilling512w.setEnabled(true); menuItemZerofilling1k.setEnabled(true); menuItemZerofilling2k.setEnabled(true); menuItemZerofilling4k.setEnabled(true); labelDataPoint.setText(model.getmaxNbComplex()+"\n"); textFieldZeroFill.setEnabled(false); //curve real FID plotting double inc; ggFid.Graph("FID", "t", "Amplitude"); ggFid.setSymbol(false); ggFid.setLine(true); ggFid.setColor(ggFid.blue); ggFid.setTitle("Real FID"); for (int i = 0; i < model.getmaxNbComplex(); i++){ inc = i; ggFid.add(inc, yr[i]); } ggFid.nextGraph(); //curve imaginary FID plotting ggFid.setSymbol(false); ggFid.setLine(true); ggFid.setColor(ggFid.red); ggFid.setTitle("Imaginary FID"); for (int i = 0; i < model.getmaxNbComplex(); i++){ inc = i; ggFid.add(inc, yi[i]); } ggFid.showGraph(); } //--------------------// // ButtonRunFFT // //--------------------// private void buttonRunFFT() { zeroPhaseCorrection.setValue(0); firstPhaseCorrection.setValue(0); zeroPhaseCorrection.addChangeListener(this); //JSlider--------------- firstPhaseCorrection.addChangeListener(this); //JSlider--------------- panelMatrix.setVisible(false); panelSVD.setVisible(false); panelGraphFID.setVisible(false); panelGraphSpectrum.setVisible(true); panelDataSpectrum.setVisible(false); menuItemZerofilling128w.setEnabled(false); menuItemZerofilling256w.setEnabled(false); menuItemZerofilling512w.setEnabled(false); menuItemZerofilling1k.setEnabled(false); menuItemZerofilling2k.setEnabled(false); menuItemZerofilling4k.setEnabled(false); menuSpe.setEnabled(true); //valeur fournie par clavier int maxNb = Integer.parseInt(textFieldZeroFill.getText()); //comparée avec celle choisie par menu if (maxNb < model.getmaxNbComplex()) { model.setmaxNbComplex(maxNb); } int maxNbSur2 = maxNb/2; zerofilling(maxNb); textFieldZeroFill.setEnabled(false); double[] xr, xi; double[] tm = new double[maxNb]; double[] tn = new double[maxNb]; double[] tmd = new double[maxNb]; double[] tnd = new double[maxNb]; double[] xs = new double[2*maxNb]; xr = model.getfidRe(); xi = model.getfidIm(); for (int i = 0; i < maxNb; i++){ xs[2*i] = xr[i]; xs[2*i + 1] = xi[i]; } Fourier.fastFT(xs, maxNb, true); //xs[2*i] real //xs[2*i + 1] imaginary for (int i = 0; i < maxNb; i++){ tm[i] = xs[2*i]; tmd[i] = xs[2*i + 1]; } for (int i = 0; i < maxNbSur2; i++){ //reconstruction of absorption tn[i] = tm[maxNbSur2 + i]; tn[maxNbSur2 + i] = tm[i]; //reconstruction of dispersion tnd[i] = tmd[maxNbSur2 + i]; tnd[maxNbSur2 + i] = tmd[i]; } //Save unphased spectrum model.setAbsorption(tn); model.setDispersion(tnd); //spectrum plotting double inc; ggSpec.Graph("Spectrum", "omega", "Intensity"); ggSpec.setSymbol(false); ggSpec.setLine(true); ggSpec.setColor(ggSpec.red); ggSpec.setTitle("spec"); for (int i = 0; i < maxNb; i++){ inc = i; ggSpec.add(inc, tn[i]); } ggSpec.showGraph(); } /*************************************** * Graph spectrum * ***************************************/ private void menuItemShowGraphSpe() { panelMatrix.setVisible(false); panelSVD.setVisible(false); panelGraphFID.setVisible(false); panelGraphSpectrum.setVisible(true); panelDataSpectrum.setVisible(false); menuItemSaveFID.setEnabled(false); menuItemRecallFID.setEnabled(false); } private void menuItemShowDataSpe() { panelMatrix.setVisible(false); panelSVD.setVisible(false); panelGraphFID.setVisible(false); panelGraphSpectrum.setVisible(false); panelDataSpectrum.setVisible(true); menuItemSaveFID.setEnabled(false); menuItemRecallFID.setEnabled(false); //put absorption and dispersion of the spectrum //in textAreaSpeAbs and textAreaSpeDisp String sSpeAbs = "", sSpeDisp = ""; int maxNb = model.getmaxNbComplex(); double phi0 = model.getPhi0(); double phi1 = model.getPhi1(); double omegatmp; double[] absorptionSpe = new double[maxNb]; double[] dispersionSpe = new double[maxNb]; double[] fma = model.getAbsorption(); double[] fmd = model.getDispersion(); for (int i = 0; i < maxNb; i++) { omegatmp = ANGLE_DEGRE*(phi0 + phi1*i/maxNb); absorptionSpe[i] = fma[i]*Math.cos(omegatmp) - fmd[i]*Math.sin(omegatmp); dispersionSpe[i] = fmd[i]*Math.cos(omegatmp) + fma[i]*Math.sin(omegatmp); } for (int i = 0; i < maxNb; i++) { /* for Simpson sSpeAbs += (Math.round(100000000*absorptionSpe[maxNb-i-1]))/100000000.0 + "\n"; sSpeDisp += (Math.round(100000000*dispersionSpe[maxNb-i-1]))/100000000.0 + "\n"; */ sSpeAbs += (Math.round(100000000*absorptionSpe[i]))/100000000.0 + "\n"; sSpeDisp += (Math.round(100000000*dispersionSpe[i]))/100000000.0 + "\n"; } textAreaSpeAbs.setText(sSpeAbs); textAreaSpeDisp.setText(sSpeDisp); } //--------------------// // ButtonIncrease0 // //--------------------// private void buttonIncrease0() { int i = zeroPhaseCorrection.getMaximum(); int j = zeroPhaseCorrection.getMajorTickSpacing(); zeroPhaseCorrection.setMaximum(2*i); zeroPhaseCorrection.setMinimum(-2*i); zeroPhaseCorrection.setPaintTicks(true); zeroPhaseCorrection.setPaintLabels(false); } //--------------------// // ButtonDecrease0 // //--------------------// private void buttonDecrease0() { int i = zeroPhaseCorrection.getMaximum(); int j = zeroPhaseCorrection.getMajorTickSpacing(); zeroPhaseCorrection.setMaximum(i/2); zeroPhaseCorrection.setMinimum(-i/2); zeroPhaseCorrection.setPaintTicks(true); zeroPhaseCorrection.setPaintLabels(false); } //--------------------// // ButtonIncrease1 // //--------------------// private void buttonIncrease1() { int i = firstPhaseCorrection.getMaximum(); int j = firstPhaseCorrection.getMajorTickSpacing(); firstPhaseCorrection.setMaximum(2*i); firstPhaseCorrection.setMinimum(-2*i); firstPhaseCorrection.setPaintTicks(true); firstPhaseCorrection.setPaintLabels(false); } //--------------------// // ButtonDecrease1 // //--------------------// private void buttonDecrease1() { int i = firstPhaseCorrection.getMaximum(); int j = firstPhaseCorrection.getMajorTickSpacing(); firstPhaseCorrection.setMaximum(i/2); firstPhaseCorrection.setMinimum(-i/2); firstPhaseCorrection.setPaintTicks(true); firstPhaseCorrection.setPaintLabels(false); } //----------------------// // ButtonSavePhase // //----------------------// private void buttonSavePhase() { int f0 = zeroPhaseCorrection.getValue(); int f1 = firstPhaseCorrection.getValue(); model.setPhi0(f0); model.setPhi1(f1); } }//end of SVDController() /************************************************************************ * * * Method main() * * * ************************************************************************/ public static void main(String[] args) { AppletApplicationFrame f = new AppletApplicationFrame("FID SVD applet window"); }//end of main() //Initialiseur statique pour le paramètre LookAndFeel static { try { //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch(Exception e) { } } }//end of class SVDMVC /***************************************************************************** * * * class AppletApplicationFrame * * * *****************************************************************************/ class AppletApplicationFrame extends JFrame { private SVDMVC myApplet; public AppletApplicationFrame(String title) { super(title); myApplet = new SVDMVC(); this.getContentPane().add(myApplet, BorderLayout.CENTER); this.setSize(406, 400); myApplet.init(); myApplet.start(); this.setVisible(true); this.setDefaultCloseOperation(3); } }//end of class AppletApplicationFrame