package hrquest.preprocessing; //------------------------------------------------------------------------ // // MRUI 98.0 TMR FMRX-CT97-0160 // //------------------------------------------------------------------------ // Preprocessing.java //------------------------------------------------------------------------ // // HISTORY : //------------------------------------------------------------------------ //|Date |Author |Method/Description | //------------------------------------------------------------------------ //|02/99 |C.Couturier|creation | //|07/01 |D.Stefan |added time shift | //|15-02-02|Y.Coenradie|New SVD Filter | //------------------------------------------------------------------------ /** This class manages the whole preprocessings. * @author cc * @version 1.0 */ import java.util.Vector; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import hrquest.Data; import hrquest.DesktopWin; import hrquest.Mrui; import hrquest.constantInterface; //import hrquest.graph.model.SpectrumMap; //import hrquest.history.OutputToolBar; //------------------------------------------------------------------------ // Class //------------------------------------------------------------------------ public class Preprocessing implements constantInterface { /** Mrui instance */ protected Mrui mrui; private java.awt.GridBagConstraints constraints = new java.awt.GridBagConstraints(); //private PhasePrepro phasePrepro; // private SvdFilterPrepro svdFilterPrepro; // private SvdRefPrepro svdRefPrepro; //private ZeroFillingPrepro zeroFillingPrepro; // private FirFilterPrepro firFilterPrepro; //private DCCorrectPrepro dcCorrectPrepro; // private BaselinePrepro baselinePrepro; // private ConvolutionPrepro convolutionPrepro; //private TruncatePrepro truncatePrepro; //private MultiplyPrepro multiplyPrepro; //private ApodizePrepro apodizePrepro; //private NormalizePrepro normalizePrepro; //private ConjugatePrepro conjugatePrepro; //private FrequencyShift frequencyShift; //private TimeShift timeShift; //private AlignWater alignWater; //private CadzowPrepro cadzowPrepro; //private ErfilterPrepro erfilterPrepro; //private SumPrepro sumPrepro; //private SubstractPrepro substractPrepro; //private DividePrepro dividePrepro; //private EchoToFIDPrepro echoToFIDPrepro; //private AddFidPrepro addFidPrepro; //private CloseFidPrepro closeFidPrepro; int[] values = new int[2]; //------------------------------------------------------------------------ // Constructor //------------------------------------------------------------------------ public Preprocessing(Mrui m){//, OutputToolBar otb) { this.mrui = m; //phasePrepro = new PhasePrepro(mrui, otb); //svdFilterPrepro = new SvdFilterPrepro(mrui, otb); svdRefPrepro = new SvdRefPrepro(mrui, otb); //zeroFillingPrepro = new ZeroFillingPrepro(mrui, otb); // firFilterPrepro = new FirFilterPrepro(mrui, otb); //dcCorrectPrepro = new DCCorrectPrepro(mrui, otb); //baselinePrepro = new BaselinePrepro(mrui, otb); //convolutionPrepro = new ConvolutionPrepro(mrui, otb); //truncatePrepro = new TruncatePrepro(mrui, otb); //apodizePrepro = new ApodizePrepro(mrui, otb); //multiplyPrepro = new MultiplyPrepro(mrui, otb); //normalizePrepro = new NormalizePrepro(mrui, otb); //conjugatePrepro = new ConjugatePrepro(mrui, otb); //cadzowPrepro = new CadzowPrepro(mrui, otb); //frequencyShift = new FrequencyShift(mrui, otb); //timeShift = new TimeShift(mrui, otb); //alignWater = new AlignWater(mrui, otb); //erfilterPrepro = new ErfilterPrepro(mrui, otb); //sumPrepro = new SumPrepro(mrui, otb); //substractPrepro = new SubstractPrepro(mrui, otb); //dividePrepro = new DividePrepro(mrui, otb); //addFidPrepro = new AddFidPrepro(mrui, otb); //closeFidPrepro = new CloseFidPrepro(mrui, otb); //echoToFIDPrepro = new EchoToFIDPrepro(mrui, otb); //Mrui.mainWindow.phaseView.setVisible(mrui.preferences.phaseVisible); //Mrui.mainWindow.apodizeView.setVisible(mrui.preferences.apodizeVisible); //Mrui.mainWindow.zeroView.setVisible(mrui.preferences.zeroFillingVisible); } //------------------------------------------------------------------------ // Methods //------------------------------------------------------------------------ //------------------------------------------------------------------------ //dccorrect() //------------------------------------------------------------------------ /** This method launches DC Correct. It starts to open a dialog to allows the user to capture some parameters. Next it performs the program "DC Correct" and records its work in the histo file. Finally, it gives its results to mrui. @param signals set of signal to be treated @author cc @version 1*/ /*public boolean dc_correct() { dcCorrectPrepro.dialog(); if (dcCorrectPrepro.userChoice == 0) { dcCorrectPrepro.prepro(); return true; } else return false; }*/ //------------------------------------------------------------------------ //dccorrectBatch() //------------------------------------------------------------------------ /** This method launches DC Correct in batch mode. @param number of points @author MJanssen @version 1*/ /* public void dc_correctBatch(int nbPoints) { dcCorrectPrepro.batch(nbPoints); }*/ //------------------------------------------------------------------------ // baselineprepro() //------------------------------------------------------------------------ /** This method launches Baseline Correction It starts to open a dialog to allows the user to capture some parameters. Next it performs the program "BaselineCorrection" and records its work in the histo file. Finally, it gives its results to mrui. @param signals set of signal to be treated @author MJanssen @version 1*/ /*public boolean baseline() { baselinePrepro.dialog(); if (baselinePrepro.userChoice == 0) { baselinePrepro.prepro(); return true; } else return false; }*/ //------------------------------------------------------------------------ //baselineBatch() //------------------------------------------------------------------------ /** This method launches the Baseline Correction in batch mode. @param number of points @author cc @version 1*/ /* public void baselineBatch(int nbPoints) { baselinePrepro.batch(nbPoints); }*/ //------------------------------------------------------------------------ // convolutionPrepro() //------------------------------------------------------------------------ /** This method shows a dialog to enter a convolution function. An example: signal[i-1][REAL/IMAG][points]+2*signal[i][REAL/IMAG][points]+signal[i+1][REAL/IMAG][points] @author MJanssen @version 1*/ /*public boolean convolution() { convolutionPrepro.dialog(); if (convolutionPrepro.userChoice == 0) { convolutionPrepro.prepro(false); return true; } else return false; }*/ //------------------------------------------------------------------------ //convolutionBatch() //------------------------------------------------------------------------ /** This method launches a convolution function in batch mode. @author MJanssen @version 1*/ /*public void convolutionBatch(boolean c, boolean o, int i, Vector v) { convolutionPrepro.batch(c, o, i, v); }*/ //------------------------------------------------------------------------ //zeroFilling() //------------------------------------------------------------------------ /** This method allows to do zero filling. It starts to open a dialog to allows the user to capture some parameters. Next it performs the program "apodize" and records its work in the histo file. Finally, it gives its results to mrui. @author cc @version 1*/ /*public boolean zeroFilling() { zeroFillingPrepro.dialog(); if (zeroFillingPrepro.userChoice == 0) { zeroFillingPrepro.prepro(); return true; } else return false; }*/ //------------------------------------------------------------------------ //zeroFillingBatch() //------------------------------------------------------------------------ /** This method allows to do zero filling in batch mode. @param number of zero to add @author cc @version 1*/ /*public void zeroFillingBatch(int val) { zeroFillingPrepro.batch(val); }*/ //------------------------------------------------------------------------ //phasePrepro() //------------------------------------------------------------------------ /** This method allows to do Hard Phasing. It starts to open a dialog to allows the user to capture some parameters. Next it performs the phasing on the original signal and records its work in the histo file. Finally, it gives its results to mrui. @author MJanssen @version 1*/ /*public boolean phasePrepro(String operation) { if ((operation.equals("HARDPHASEWATER")) || (operation.equals("HARDPHASEPEAK"))) { if (operation.equals("HARDPHASEWATER")) phasePrepro.hardPhaseWater(false); if (operation.equals("HARDPHASEPEAK")) { phasePrepro.dialogHardPhasePeak(); } return true; } else { phasePrepro.dialog(operation); if (phasePrepro.userChoice == 0) { //phasePrepro.prepro(); return true; } else { return false; } } }*/ //------------------------------------------------------------------------ //phasePreproBatch() //------------------------------------------------------------------------ /** This method allows to do Hard Phasing in batch mode. @param String ALL/SIGNAL/WATER @param double phi0 (if ALL or SIGNAL) @param double begin time (if ALL or SIGNAL) @param double signalNumber (if SIGNAL) @author MJanssen @version 1*/ /*public void phaseBatch(String str, double[] phi0, double[] bt) { phasePrepro.batch(str, phi0, bt); }*/ //------------------------------------------------------------------------ //SVDFilter() //------------------------------------------------------------------------ /** This method allows to do SVDFilter. It starts to open a dialog to allows the user to capture some parameters. Next it performs the program SVDFilter and records its work in the histo file. Finally, it gives its results to mrui. @author yc @version 1*/ public void svdFilter() { svdFilterPrepro.dialog(); } //------------------------------------------------------------------------ //SVDFilterBatch() //------------------------------------------------------------------------ /** This method allows to do SVDFilter in batch mode. @param number of singular values to be found @author yc @version 1*/ public void svdFilterBatch( int iComponents, int iHankelRows, int iPoints, int iCorrectedPoints, double dMaxAmpl, double dMaxDamp, int iNumberOfRegions, double[] daLower, double[] daUpper, boolean isLanczos, boolean isTotalLS) { svdFilterPrepro.batch(iComponents, iHankelRows, iPoints, iCorrectedPoints, dMaxAmpl, dMaxDamp, iNumberOfRegions, daLower, daUpper, isLanczos, isTotalLS); } //------------------------------------------------------------------------ //FIRFilter() //------------------------------------------------------------------------ /** This method allows to do FIRFilter. It starts to open a dialog to allows the user to capture some parameters. Next it performs the program "apodize" and records its work in the histo file. Finally, it gives its results to mrui. @author cc @version 1*/ public boolean firFilter() { Mrui.logger.info("Implemented to Preprocessing"); return false; } //------------------------------------------------------------------------ //FIRFilterBatch() //------------------------------------------------------------------------ /** This method allows to do FIRFilter in batch mode. @param number of zero to add @author cc @version 1*/ public void firFilterBatch(int val) { Mrui.logger.info("Implemented to Preprocessing"); } //--------------------------------------------------------------------- //truncate() //--------------------------------------------------------------------- /** This method launches truncate. It starts to open a dialog to allows the user to capture some parameters. Next it performs the program "truncate" and records its work in the histo file. Finally, it gives its results to mrui. @param signals set of signal to be treated @author cc @version 1*/ public boolean truncate() { truncatePrepro.dialog(); if (truncatePrepro.userChoice == 0) { truncatePrepro.prepro(); Mrui.mainWindow.phaseView.update(); return true; } else return false; } //------------------------------------------------------------------------ //truncateBatch() //------------------------------------------------------------------------ /** This method launches truncate in batch mode. @param the signal is truncated until first point @param the signal is truncated after last point @author cc @version 1*/ public void truncateBatch(int firstPoint, int lastPoint) { truncatePrepro.batch(firstPoint, lastPoint); } //------------------------------------------------------------------------ //apodize() //------------------------------------------------------------------------ /** This method launches apodize. It starts to open a dialog to allows the user to capture some parameters. Next it performs the program "apodize" and records its work in the histo file. Finally, it gives its results to mrui. @param signals set of signal to be treated @author cc @version 1*/ public boolean apodize() { apodizePrepro.dialog(); if (apodizePrepro.userChoice == 0) { apodizePrepro.prepro(); return true; } else return false; } //------------------------------------------------------------------------ //ApodizeBatch() //------------------------------------------------------------------------ /** This method launches apodization in batch mode. @param value of the apodization @param line shape @author cc @version 1*/ public void apodizeBatch(double val, String line) { apodizePrepro.batch(val, line); } //------------------------------------------------------------------------ //erfilter() //------------------------------------------------------------------------ /** This method launches erfilter. It starts to open a dialog to allows the user to capture some parameters. Next it performs the program "erfilter" and records its work in the histo file. Finally, it gives its results to mrui. @param signals set of signal to be treated @author cc @version 1*/ public void erfilter() { erfilterPrepro.dialog(); } //------------------------------------------------------------------------ //erfilterBatch() //------------------------------------------------------------------------ /** This method launches erfilter in batch mode. @param lower value of the filter @param upper value of the filter @author cc @version 1*/ public void erfilterBatch(int low, int upp) { erfilterPrepro.batch(low, upp); } //------------------------------------------------------------------------ //frequencyShift() //------------------------------------------------------------------------ /** This method launches frequencyShift. It starts to open a dialog to allows the user to capture some parameters. Next it performs the program "erfilter" and records its work in the histo file. Finally, it gives its results to mrui. @author MJanssen @version 1*/ public void frequencyShift() { frequencyShift.dialog(); } //------------------------------------------------------------------------ //frequencyShiftBatch() //------------------------------------------------------------------------ /** This method launches frequency shift in batch mode. @param shifts (in Hz !!!) @author MJanssen @version 1*/ public void frequencyShiftBatch(int[] frequencies) { frequencyShift.batch(frequencies); } //------------------------------------------------------------------------ //timeShift() //------------------------------------------------------------------------ /** This method launches timeShift. It starts to open a dialog to allows the user to capture some parameters. Next it performs the program "erfilter" and records its work in the histo file. Finally, it gives its results to mrui. @author MJanssen @version 1*/ public void timeShift() { timeShift.dialog(); } //------------------------------------------------------------------------ //timeShiftBatch() -- to change cause for now it's only a copy of freq //------------------------------------------------------------------------ /** This method launches frequency shift in batch mode. @param shifts (in Hz !!!) @author MJanssen @version 1*/ public void timeShiftBatch(int[] frequencies) { timeShift.batch(frequencies); } //--------------------------------------------------------------------- //alignWater() //--------------------------------------------------------------------- /** This method launches the align water procedure. It records its work in the histo file. Finally, it gives its results to mrui. @author MJanssen @version 1*/ public void alignWater() { alignWater.prepro(); } //------------------------------------------------------------------------ //alignWaterBatch() //------------------------------------------------------------------------ /** This method launches align water in batch mode. @author MJanssen @version 1*/ public void alignWaterBatch() { alignWater.batch(); } //------------------------------------------------------------------------ //phase(double phase0, double phase1) //------------------------------------------------------------------------ /** This method launches the phasing. @param the zero order phase @param the begin time @author cc @version 1*/ public void phase(double phase0, double phase1) { Mrui.mainWindow.phaseView.prepro(phase0, phase1); } //------------------------------------------------------------------------ //multiply() //------------------------------------------------------------------------ /** This method launches multiply. It starts to open a dialog to allows the user to capture a parameter. Next it performs the program "multiply" and records its work in the histo file. Finally, it gives its results to mrui. @author cc @version 1*/ public boolean multiply() { multiplyPrepro.dialog(); if (multiplyPrepro.userChoice == 0) { multiplyPrepro.prepro(); return true; } else return false; } //------------------------------------------------------------------------ //multiplyBatch() //------------------------------------------------------------------------ /** This method launches multiplication in batch mode. @param multiplied by val @author cc @version 1*/ public void multiplyBatch(double val) { Mrui.logger.info("PREPRO > BATCH MULTIPLY"); multiplyPrepro.batch(val); } //------------------------------------------------------------------------ //sum() //------------------------------------------------------------------------ /** This method launches sum. It starts to open a dialog to allows the user to capture a parameter. Next it performs the program "sum" and records its work in the histo file. Finally, it gives its results to mrui. @author cc @version 1*/ public boolean sum() { sumPrepro.dialog(); if (sumPrepro.userChoice == 0) { sumPrepro.prepro(); return true; } else return false; } //------------------------------------------------------------------------ //sumBatch() //------------------------------------------------------------------------ /** This method launches summation in batch mode. @param multiplied by val @author cc @version 1*/ public void sumBatch(String filename) { sumPrepro.batch(filename); } //------------------------------------------------------------------------ //substract() //------------------------------------------------------------------------ /** This method launches substract. It starts to open a dialog to allows the user to capture a parameter. Next it performs the program "substract" and records its work in the histo file. Finally, it gives its results to mrui. @author cc @version 1*/ public boolean substract() { substractPrepro.dialog(); if (substractPrepro.userChoice == 0) { substractPrepro.prepro(); return true; } else return false; } //------------------------------------------------------------------------ //substractBatch() //------------------------------------------------------------------------ /** This method launches substract in batch mode. @param multiplied by val @author cc @version 1*/ public void substractBatch(String filename) { substractPrepro.batch(filename); } //------------------------------------------------------------------------ //divide() //------------------------------------------------------------------------ /** This method launches divide. It starts to open a dialog to allows the user to capture a parameter. Next it performs the program "divide" and records its work in the histo file. Finally, it gives its results to mrui. @author cc @version 1*/ public void divide() { dividePrepro.dialog(); if (dividePrepro.userChoice == 0) { dividePrepro.prepro(); } } //------------------------------------------------------------------------ //divideBatch() //------------------------------------------------------------------------ /** This method launches divide in batch mode. @param multiplied by val @author cc @version 1*/ public void divideBatch(String filename) { dividePrepro.batch(filename); } //------------------------------------------------------------------------ //normalize() //------------------------------------------------------------------------ /** This method launches normalize. It performs the program "normalize" and records its work in the histo file. Afterwards, it gives its results to mrui. @author cc @version 1*/ public void normalize() { normalizePrepro.prepro(); } //------------------------------------------------------------------------ //normalizeBatch() //------------------------------------------------------------------------ /** This method launches normalization in batch mode. @author cc @version 1*/ public void normalizeBatch() { normalizePrepro.batch(); } //------------------------------------------------------------------------ //conjugate() //------------------------------------------------------------------------ /** This method launches conjugate. It performs the program "conjugate" and records its work in the histo file. Afterwards, it gives its results to mrui. @author MJanssen @version 1*/ public void conjugate() { conjugatePrepro.prepro(); } //------------------------------------------------------------------------ //conjugateBatch() //------------------------------------------------------------------------ /** This method launches conjugation in batch mode. @author MJanssen @version 1*/ public void conjugateBatch() { conjugatePrepro.batch(); } //------------------------------------------------------------------------ //echoTofid(String str) //------------------------------------------------------------------------ /** This transforms echoes to fids @author MJanssen @version 1*/ public boolean echoTofid(String str) { echoToFIDPrepro.dialog(str); if (echoToFIDPrepro.userChoice == 0) { echoToFIDPrepro.prepro(str); return true; } else return false; } //------------------------------------------------------------------------ //echoTofid(String str, int number) //------------------------------------------------------------------------ /** This transforms echoes to fids in batch @author MJanssen @version 1*/ public void echoToFIDBatch(String str, int number) { echoToFIDPrepro.batch(str, number); } //------------------------------------------------------------------------ //addFid() //------------------------------------------------------------------------ public void addFid() { addFidPrepro.prepro(); } //------------------------------------------------------------------------ public void addSignalBatch(int[] signalsToAdd) { addFidPrepro.batch(signalsToAdd); } //------------------------------------------------------------------------ //closeFid() //------------------------------------------------------------------------ public void closeFid() { closeFidPrepro.prepro(); } //------------------------------------------------------------------------ public void closeSignalBatch(int[] signalsToClose) { closeFidPrepro.batch(signalsToClose); } //------------------------------------------------------------------------ //cadzow() //------------------------------------------------------------------------ /** This method launches cadzow. It performs the program "cadzow" and records its work in the histo file. Afterwards, it gives its results to mrui. @author cc @version 1*/ public boolean cadzow() { cadzowPrepro.dialog(); if (cadzowPrepro.userChoice == 0) { cadzowPrepro.prepro(); return true; } else return false; } //------------------------------------------------------------------------ //cadzowBatch() //------------------------------------------------------------------------ /** This method launches cadzow in batch mode. @param number of removed points @param number of used points @param number of peaks @param precision @param number of iterations @author cc @version 1*/ public void cadzowBatch(int removed, int used, int peaks, double eps, int iteration) { cadzowPrepro.batch(removed, used, peaks, eps, iteration); } //------------------------------------------------------------------------ // checkWaterMetaboliteFiles: to check and add water/metabolite files //------------------------------------------------------------------------ public Data checkWaterMetaboliteFiles(Mrui mrui) { double N = 10; // Minimal factor between max amplitudes // First look for the maximum values in the FIDs double minMax = 1e100, maxMax = 0, mean = 0; double[] maxima = new double[mrui.data.getSignalsNb()]; double[][] signal, add; for (int i = 0; i < mrui.data.getSignalsNb(); i++) { signal = mrui.data.getFFT(i); for (int j = 0; j < mrui.data.getOriginalLength(); j++) { double abs = Math.sqrt(signal[REAL][j] * signal[REAL][j] + signal[IMAG][j] * signal[IMAG][j]); if (abs > maxima[i]) maxima[i] = abs; } if (maxima[i] > maxMax) maxMax = maxima[i]; if (maxima[i] < minMax) minMax = maxima[i]; } // If files contain a max maximum amplitude N times the // min maximum amplitude, then this is a water/metabolite file if (maxMax < N * minMax) return mrui.data; mean = (maxMax - minMax) / 2; boolean[] water = new boolean[mrui.data.getSignalsNb()]; for (int i = 0; i < mrui.data.getSignalsNb(); i++) { water[i] = false; if (maxima[i] > mean) { water[i] = true; } } int beginNoise = 0, endNoise = 0; int beginWater = 0, endWater = 0; int beginMetabolite = 0, endMetabolite = mrui.data.getSignalsNb() - 1; boolean noiseFID = true; boolean waterFID = false; for (int i = 0; i < mrui.data.getSignalsNb(); i++) { // Begin looking for noise FIDs if (noiseFID) { // If water file stop looking for noise FIDs and continue with water if (water[i]) { endNoise = i - 1; noiseFID = false; waterFID = true; } else { beginWater = i + 1; } } // Then look for water FIDs if (waterFID) { // Until the metabolite files (no more water fids) if (!water[i]) { endWater = i - 1; noiseFID = false; waterFID = false; } else { beginMetabolite = i + 1; } } // The rest are metabolite files } // Bring up the dialog to confirm int[] valuesInit = new int[6]; valuesInit[0] = beginNoise; valuesInit[1] = endNoise; valuesInit[2] = beginWater; valuesInit[3] = endWater; valuesInit[4] = beginMetabolite; valuesInit[5] = endMetabolite; bringUpDialog(valuesInit); //see function calculateAddition() /*if ((values[0] != -1) && (values[1] != -1)) { // Add the signals to be added signal = mrui.data.getSignal(values[0]); for (int i = values[0] + 1; i <= values[1]; i++) { add = mrui.data.getSignal(i); for (int j = 0; j < mrui.data.getOriginalLength(); j++) { signal[REAL][j] += add[REAL][j]; signal[IMAG][j] += add[IMAG][j]; } } Mrui.mainWindow.mode1DWin.fidChooser.setVisible(false); Mrui.mainWindow.mode1DWin.validate(); // Get the 'map' SpectrumMap map = ((SpectrumMap) (Mrui.mainWindow.mode1DWin.graph.getMediateur().getMap())); // Remove all mrui.data.setOfFIDs = new java.util.Vector(); // Add the added signal mrui.data.addSignal(signal); // Christophes card house mrui.data.fireAll(); map.setSize(mrui.data.getSignalsNb()); Mrui.mainWindow.mode1DWin.graph.initView(); Mrui.mainWindow.mode1DWin.graph.repaint(); }*/ return mrui.data; } // Dialog to enter the values private void bringUpDialog(int[] valuesInit) { values[0] = -1; values[1] = -1; final JDialog dialog = new JDialog(Mrui.mainWindow); dialog.setTitle("jMRUI perhaps found Water/Metabolite data."); //dialog.setModal(true); dialog.setModal(false); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setBounds(100, 100, 400, 200); dialog.setResizable(false); constraints.fill = java.awt.GridBagConstraints.HORIZONTAL; JPanel dialogPanel = new JPanel(new java.awt.GridBagLayout()); JLabel labelEstimate = new JLabel("Press continue to process signals separately."); final JButton bCancel = new JButton("Continue"); JLabel labelNoise = new JLabel("Noise signals from:"); final JTextField noiseFromField = new JTextField("" + (valuesInit[0] + 1)); JLabel labelNoise2 = new JLabel(" to:"); final JTextField noiseEndField = new JTextField("" + (valuesInit[1] + 1)); final JButton bNoise = new JButton("Sum"); if (valuesInit[1] == -1) { noiseFromField.setText("none"); noiseEndField.setText("none"); } JLabel labelWater = new JLabel("Water signals from:"); final JTextField waterFromField = new JTextField("" + (valuesInit[2] + 1)); JLabel labelWater2 = new JLabel(" to:"); final JTextField waterEndField = new JTextField("" + (valuesInit[3] + 1)); final JButton bWater = new JButton("Sum"); JLabel labelMetabolite = new JLabel("Metabolite signals from:"); final JTextField metaboliteFromField = new JTextField("" + (valuesInit[4] + 1)); JLabel labelMetabolite2 = new JLabel(" to:"); final JTextField metaboliteEndField = new JTextField("" + (valuesInit[5] + 1)); final JButton bMetabolite = new JButton("Sum"); setConstraints(0, 0, 6, 1, 1, 1); dialogPanel.add(labelEstimate, constraints); setConstraints(6, 0, 2, 1, 1, 1); dialogPanel.add(bCancel, constraints); setConstraints(0, 1, 3, 1, 1, 1); dialogPanel.add(labelNoise, constraints); setConstraints(3, 1, 1, 1, 1, 1); dialogPanel.add(noiseFromField, constraints); setConstraints(4, 1, 1, 1, 1, 1); dialogPanel.add(labelNoise2, constraints); setConstraints(5, 1, 1, 1, 1, 1); dialogPanel.add(noiseEndField, constraints); setConstraints(6, 1, 2, 1, 1, 1); dialogPanel.add(bNoise, constraints); setConstraints(0, 2, 3, 1, 1, 1); dialogPanel.add(labelWater, constraints); setConstraints(3, 2, 1, 1, 1, 1); dialogPanel.add(waterFromField, constraints); setConstraints(4, 2, 1, 1, 1, 1); dialogPanel.add(labelWater2, constraints); setConstraints(5, 2, 1, 1, 1, 1); dialogPanel.add(waterEndField, constraints); setConstraints(6, 2, 2, 1, 1, 1); dialogPanel.add(bWater, constraints); setConstraints(0, 3, 3, 1, 1, 1); dialogPanel.add(labelMetabolite, constraints); setConstraints(3, 3, 1, 1, 1, 1); dialogPanel.add(metaboliteFromField, constraints); setConstraints(4, 3, 1, 1, 1, 1); dialogPanel.add(labelMetabolite2, constraints); setConstraints(5, 3, 1, 1, 1, 1); dialogPanel.add(metaboliteEndField, constraints); setConstraints(6, 3, 2, 1, 1, 1); dialogPanel.add(bMetabolite, constraints); // Cancel button pressed bCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { dialog.dispose(); } }); // Noise button pressed bNoise.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (checkValues(noiseFromField.getText(), noiseEndField.getText())) { dialog.dispose(); calculateAddition(); } else { JOptionPane msgbox = new JOptionPane(); JOptionPane.showMessageDialog(Mrui.mainWindow, "Error in the fields for the noise.", "Message", JOptionPane.ERROR_MESSAGE); } } }); // Noise button pressed bWater.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (checkValues(waterFromField.getText(), waterEndField.getText())) { dialog.dispose(); calculateAddition(); } else { JOptionPane msgbox = new JOptionPane(); JOptionPane.showMessageDialog(Mrui.mainWindow, "Error in the fields for the water.", "Message", JOptionPane.ERROR_MESSAGE); } } }); // Water button pressed bMetabolite.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (checkValues(metaboliteFromField.getText(), metaboliteEndField.getText())) { dialog.dispose(); calculateAddition(); } else { JOptionPane msgbox = new JOptionPane(); JOptionPane.showMessageDialog(Mrui.mainWindow, "Error in the fields for the metabolites.", "Message", JOptionPane.ERROR_MESSAGE); } } }); // Metabolite the dialog dialog.setContentPane(dialogPanel); dialog.show(); } private void setConstraints(int x, int y, int w, int h, double wx, double wy) { constraints.gridx = x; constraints.gridy = y; constraints.gridwidth = w; constraints.gridheight = h; constraints.weightx = wx; constraints.weighty = wy; } private boolean checkValues(String str1, String str2) { boolean ret = true; try { values[0] = (new Integer(str1)).intValue() - 1; values[1] = (new Integer(str2)).intValue() - 1; } catch (Exception e) { ret = false; } if (values[0] > values[1]) ret = false; if (values[0] < 0) ret = false; if (values[1] > mrui.data.getSignalsNb()) ret = false; return ret; } private void calculateAddition(){ double [][] signal,add; if ((values[0] != -1) && (values[1] != -1)) { // Add the signals to be added signal = mrui.data.getSignal(values[0]); for (int i = values[0] + 1; i <= values[1]; i++) { add = mrui.data.getSignal(i); for (int j = 0; j < mrui.data.getOriginalLength(); j++) { signal[REAL][j] += add[REAL][j]; signal[IMAG][j] += add[IMAG][j]; } } Mrui.mainWindow.mode1DWin.fidChooser.setVisible(false); Mrui.mainWindow.mode1DWin.validate(); // Get the 'map' SpectrumMap map = ((SpectrumMap) (Mrui.mainWindow.mode1DWin.graph.getMediateur().getMap())); // Remove all mrui.data.setOfFIDs = new java.util.Vector(); // Add the added signal mrui.data.addSignal(signal); // Christophes card house mrui.data.fireAll(); map.setSize(mrui.data.getSignalsNb()); Mrui.mainWindow.mode1DWin.graph.initView(); Mrui.mainWindow.mode1DWin.graph.repaint(); } } //------------------------------------------------------- public void setFidOrEcho(Mrui mrui) { // Set echoMode or fidMode // Use middle signal for this double[][] data = mrui.data.getSignal(mrui.data.getSignalsNb() / 2); double max = 0; int maxIndex = 0; for (int i = 0; i < mrui.data.getOriginalLength(); i++) { double abs = data[REAL][i] * data[REAL][i] + data[IMAG][i] * data[IMAG][i]; if (abs > max) { max = abs; maxIndex = i; } } // If max in first 10% of points --> FID else echo if (maxIndex < mrui.data.getOriginalLength() / 10) mrui.data.areEchoes = false; else mrui.data.areEchoes = true; mrui.data.setPhases(); // To force constructspectrum Mrui.mainWindow.menu.mPrepEcho2Fid.setEnabled(mrui.data.areEchoes); if (DesktopWin.bMode1DWinPresent) Mrui.mainWindow.mode1DWin.update(); } //------------------------------------------------------------------------ // closeSVDFilterPrepro() //------------------------------------------------------------------------ /** this method closes the SVD Filter Preprocessing dialog */ // @author T.Petit 27/06/2002 public void closeSVDFilterPrepro() { svdFilterPrepro.closeDialogSVDFilter(); } //------------------------------------------------------------------------ // closeERFilterPrepro() //------------------------------------------------------------------------ /** this method closes the ER Filter Preprocessing dialog */ // @author T.Petit 27/06/2002 public void closeERFilterPrepro() { erfilterPrepro.closeDialogERFilter(); } //------------------------------------------------------------------------ // closeFrequencyShift() //------------------------------------------------------------------------ /** this method closes the Frequency Shift Preprocessing dialog */ // @author T.Petit 27/06/2002 public void closeFrequencyShift() { frequencyShift.closeDialogFrequencyShift(); } /** * */ public void svdRef() { svdRefPrepro.dialog(); } }