package Data;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.Serializable;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
public class DataProcessing extends JFrame implements Serializable, PropertyChangeListener
{
private JProgressBar progressBar = null;
private GridBagConstraints m_c = new GridBagConstraints();
private JPanel m_optionPanel = new JPanel();
private Task task = null;
private float[][][] afNorm = null;
private float fMin = 0.0f;
private float fMax = 0.0f;
private float[][] afPeaksOut = null;
private int[][]abPosOut = null;
class Task extends SwingWorker<Void, Void> {
/*
* Main task. Executed in background thread.
*/
@Override
public Void doInBackground() {
setProgress(0);
float fPeak;
for (int x = 0; x < afNorm.length; x++) {
for (int y = 0; y < afNorm[x].length; y++)
{
fPeak = 0.0f;
for (int z = 0; z < afNorm[x][y].length; z++) {
if (afNorm[x][y][z] >= fMin && afNorm[x][y][z] <= fMax){
if (fPeak < afNorm[x][y][z]) {
fPeak = afNorm[x][y][z];
abPosOut[x][y] = z;
}
}
}
afPeaksOut[x][y] = fPeak;
}
setProgress(x);
}
return null;
}
/*
* Executed in event dispatching thread
*/
@Override
public void done() {
// nothing!
}
}
/**
* Create the GUI and show it. As with all GUI code, this must run
* on the event-dispatching thread.
*/
private void createAndShowGUI(int maximum) {
//setup the look and feel to the local computer
try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);}
catch (Exception e) {System.err.println("L&F Error: " + e);}
this.setBounds(400, 400, 0, 0);
this.setPreferredSize(new Dimension(300, 100));
this.setResizable(false);
// PROGRESS BAR
progressBar = new JProgressBar(0, maximum);
progressBar.setValue(0);
// setup layout
m_optionPanel.setLayout(new GridBagLayout());
// add components to the pane!
m_c.anchor = GridBagConstraints.LINE_START;
m_c.weighty = 0.0;
// DISPLAY
m_c.gridx = 0;
m_c.gridy = 0;
m_c.gridwidth = 20;
m_optionPanel.add(progressBar, m_c);
// Setup the JFrame
setContentPane(m_optionPanel);
setBackground(Color.white);
setTitle("Processing ...");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
pack();
System.out.println("created");
}
public DataProcessing(final int maximum) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI(maximum);
}
});
}
/*Self Contained function to derive peaks in window from all correls*/
public void getPeaks(float[][][] afNormIn, float fMinIn, float fMaxIn,
float[][] afPeaksOutIn, int[][] abPosOutIn)
{
afNorm = afNormIn;
fMin = fMinIn;
fMax = fMaxIn;
afPeaksOut = afPeaksOutIn;
abPosOut = abPosOutIn;
task = new Task();
task.addPropertyChangeListener(this);
task.execute();
}
public void propertyChange(PropertyChangeEvent evt) {
if ("progress" == evt.getPropertyName()) {
int progress = (Integer) evt.getNewValue();
progressBar.setValue(progress);
}
}
}
ASKER
ASKER
package Data;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.Serializable;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
public class DataProcessing extends JFrame implements Serializable, PropertyChangeListener
{
private JProgressBar progressBar = null;
private GridBagConstraints m_c = new GridBagConstraints();
private JPanel m_optionPanel = new JPanel();
private Task task = null;
private float[][][] afNorm = null;
private float fMin = 0.0f;
private float fMax = 0.0f;
private float[][] afPeaksOut = null;
private int[][]abPosOut = null;
private int m_maximum = 100;
class Task extends SwingWorker<Void, Void> {
/*
* Main task. Executed in background thread.
*/
@Override
public Void doInBackground() {
setProgress(0);
float fPeak;
for (int x = 0; x < afNorm.length; x++) {
for (int y = 0; y < afNorm[x].length; y++)
{
fPeak = 0.0f;
for (int z = 0; z < afNorm[x][y].length; z++) {
if (afNorm[x][y][z] >= fMin && afNorm[x][y][z] <= fMax){
if (fPeak < afNorm[x][y][z]) {
fPeak = afNorm[x][y][z];
abPosOut[x][y] = z;
}
}
}
afPeaksOut[x][y] = fPeak;
}
setProgress(x);
}
return null;
}
/*
* Executed in event dispatching thread
*/
@Override
public void done() {
// nothing!
}
}
/**
* Create the GUI and show it. As with all GUI code, this must run
* on the event-dispatching thread.
*/
public void createAndShowGUI() {
//setup the look and feel to the local computer
try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);}
catch (Exception e) {System.err.println("L&F Error: " + e);}
this.setBounds(400, 400, 0, 0);
this.setPreferredSize(new Dimension(300, 100));
this.setResizable(false);
// PROGRESS BAR
progressBar = new JProgressBar(0, m_maximum);
progressBar.setValue(0);
// setup layout
m_optionPanel.setLayout(new GridBagLayout());
// add components to the pane!
m_c.anchor = GridBagConstraints.LINE_START;
m_c.weighty = 0.0;
// DISPLAY
m_c.gridx = 0;
m_c.gridy = 0;
m_c.gridwidth = 20;
m_optionPanel.add(progressBar, m_c);
// Setup the JFrame
setContentPane(m_optionPanel);
setBackground(Color.white);
setTitle("Processing ...");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
pack();
}
public DataProcessing() { }
public void setMaximum(int maximum) {
progressBar.setMaximum(maximum);
}
public void propertyChange(PropertyChangeEvent evt) {
System.out.println("changed");
if ("progress" == evt.getPropertyName()) {
int progress = (Integer) evt.getNewValue();
progressBar.setValue(progress);
}
}
}
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.
TRUSTED BY