import edu.gwu.lintool.*; import java.util.*; import java.text.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.event.*; public class DemoDFT2D extends JFrame { // N x N grid or image. int N = 5; JTextField vField = new JTextField (6); // The signal and spectrum are now 2D images or 2D arrays of complex numbers. ComplexLocal[][] signal, spectrum; // We're going to display the real and imaginary parts separately. Clickable2DGrid signalRe, signalIm, spectrumRe, spectrumIm; // For selection and change of value. Clickable2DGrid currentGrid; int selecti = -1, selectj = -1; public DemoDFT2D () { // Build the GUI. this.setSize (800, 700); this.setTitle ("FFT in 2D"); Container cPane = this.getContentPane(); cPane.add (makeBottomPanel(), BorderLayout.SOUTH); cPane.add (makeCenterPanel(), BorderLayout.CENTER); this.setVisible (true); } // Apply() scales the values to the range [-127, 127] so that we can treat the // values as greyscale intensities. void apply () { apply ("Signal", signal, signalRe, signalIm); apply ("Spectrum", spectrum, spectrumRe, spectrumIm); signalRe.repaint (); signalIm.repaint (); spectrumRe.repaint (); spectrumIm.repaint (); } void apply (String msg, ComplexLocal[][] data, Clickable2DGrid realGrid, Clickable2DGrid imGrid) { for (int i=0; i 127) { re = 127; } if (im < -127) { im = -127; } if (im > 127) { im = 127; } realGrid.grid[i][j] = (int) re; imGrid.grid[i][j] = (int) im; } } } void change () { try { double v = Double.parseDouble (vField.getText()); if (currentGrid == signalRe) { signal[selecti][selectj].re = v; } else if (currentGrid == signalIm) { signal[selecti][selectj].im = v; } else if (currentGrid == spectrumRe) { spectrum[selecti][selectj].re = v; } else if (currentGrid == spectrumIm) { spectrum[selecti][selectj].im = v; } apply (); } catch (NumberFormatException e) { System.out.println (e); } } void setTextField () { double v = 0; if (currentGrid == signalRe) { v = signal[selecti][selectj].re; } else if (currentGrid == signalIm) { v = signal[selecti][selectj].im; } else if (currentGrid == spectrumRe) { v = spectrum[selecti][selectj].re; } else if (currentGrid == spectrumIm) { v = spectrum[selecti][selectj].im; } vField.setText ("" + v); } void showValues () { signalRe.showValuesToggle (); signalIm.showValuesToggle (); spectrumRe.showValuesToggle (); spectrumIm.showValuesToggle (); apply (); } void clear () { for (int i=0; i