Commit 139de79d authored by lafabregue's avatar lafabregue

Merge branch 'ProgressBarModification' into 'master'

Progress bar modification

See merge request !1
parents 7da3f6fa a949300f
package mustic.gui;
import java.beans.PropertyVetoException;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.WindowConstants;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
......
......@@ -66,7 +66,7 @@ public class ImageSession {
public SSHParameters sshparameters = null;
/** enable the image to display the image or not, for a memory usage matter */
private boolean displayEnable = false;
private boolean displayEnable = true;
/**
* @param aImage
......
......@@ -5,6 +5,7 @@ import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.beans.PropertyVetoException;
......@@ -88,7 +89,7 @@ public class MainFrame extends JFrame {
/** l'instance unique de ce singleton */
private static MainFrame instance = null;
public final static boolean DEBUG_MODE = false;
public final static boolean DEBUG_MODE = true;
/** La barre de progression */
private static JProgressBar progressBar = new JProgressBar();
......@@ -97,7 +98,7 @@ public class MainFrame extends JFrame {
private static final long serialVersionUID = 1L;
/** barre d'etat */
private static StatusBar statusBar = new StatusBar();
private static ProgressStatus progressStatus = new ProgressStatus();
private static boolean targetMode = true;
/** panel pour l'affichage du birdview de l'image selectionnee */
......@@ -1497,13 +1498,21 @@ public class MainFrame extends JFrame {
// =============== Creation of the Progress Panel => South
// ================
JPanel progressPanel = new JPanel(new BorderLayout());
JPanel progressPanel = new JPanel(new GridLayout());
JPanel intermediatePanel = new JPanel(new BorderLayout());
MainFrame.progressBar.setStringPainted(true);
MainFrame.progressBar.setMaximum(100);
MainFrame.progressBar.setMinimum(0);
progressPanel.add(MainFrame.progressBar, BorderLayout.EAST);
progressPanel.add(MainFrame.progressStatus);
progressPanel.add(MainFrame.progressBar);
progressPanel.add(MainFrame.statusBar, BorderLayout.WEST);
intermediatePanel.add(progressPanel, BorderLayout.EAST);
// =============== Creation of the Final Panel = Content Pane of Main
// Frame ================
......@@ -1511,7 +1520,7 @@ public class MainFrame extends JFrame {
JPanel final_panel = new JPanel(new BorderLayout());
final_panel.add(panel, BorderLayout.CENTER);
final_panel.add(this.northPanel, BorderLayout.NORTH);
final_panel.add(progressPanel, BorderLayout.SOUTH);
final_panel.add(intermediatePanel, BorderLayout.SOUTH);
this.setContentPane(final_panel);
final_panel.updateUI();
......@@ -1624,13 +1633,18 @@ public class MainFrame extends JFrame {
// =============== Creation of the Progress Panel => South
// ================
JPanel progressPanel = new JPanel(new BorderLayout());
JPanel intermediatePanel = new JPanel(new BorderLayout());
JPanel progressPanel = new JPanel(new GridLayout());
MainFrame.progressBar.setStringPainted(true);
MainFrame.progressBar.setMaximum(100);
MainFrame.progressBar.setMinimum(0);
progressPanel.add(MainFrame.progressBar, BorderLayout.EAST);
progressPanel.add(MainFrame.statusBar, BorderLayout.WEST);
progressPanel.add(MainFrame.progressStatus);
progressPanel.add(MainFrame.progressBar);
intermediatePanel.add(progressPanel, BorderLayout.EAST);
// =============== Creation of the Final Panel = Content Pane of Main
// Frame ================
......@@ -1638,7 +1652,7 @@ public class MainFrame extends JFrame {
JPanel final_panel = new JPanel(new BorderLayout());
final_panel.add(panel, BorderLayout.CENTER);
final_panel.add(this.northPanel, BorderLayout.NORTH);
final_panel.add(progressPanel, BorderLayout.SOUTH);
final_panel.add(intermediatePanel, BorderLayout.SOUTH);
this.setContentPane(final_panel);
final_panel.updateUI();
......@@ -2389,8 +2403,8 @@ public class MainFrame extends JFrame {
* </p>
* @return la barre d'etat generale associee a la fenetre
*/
public static StatusBar getStatusBar() {
return MainFrame.statusBar;
public static ProgressStatus getProgressStatus() {
return MainFrame.progressStatus;
}
public JPanel getBirdPanel() {
......@@ -2699,7 +2713,8 @@ public class MainFrame extends JFrame {
File[] filesArray = fileChooser.getSelectedFiles();
this.currentDirectory = fileChooser.getCurrentDirectory();
MainFrame.getProgressStatus().setMessage("loading file...");
this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
for (int i = 0; i < filesArray.length; i++) {
......@@ -2716,6 +2731,7 @@ public class MainFrame extends JFrame {
ex.printStackTrace();
}
this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
MainFrame.getProgressStatus().reset();
}
......@@ -3234,7 +3250,7 @@ public class MainFrame extends JFrame {
String inputValue = JOptionPane.showInputDialog(Messages.getString("MainFrame.223")); //$NON-NLS-1$
if ((inputValue != null) && (inputValue.length() > 0)) {
this.getCurrentImageSession().getRawImage().save(path + "." + inputValue); //$NON-NLS-1$
MainFrame.getStatusBar().setMessage(Messages.getString("MainFrame.225") + path + "." + inputValue); //$NON-NLS-1$ //$NON-NLS-2$
MainFrame.getProgressStatus().setMessage(Messages.getString("MainFrame.225") + path + "." + inputValue); //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.showMessageDialog(this, Messages.getString("MainFrame.227"), Messages.getString("MainFrame.228"), //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.INFORMATION_MESSAGE);
return;
......@@ -3252,7 +3268,7 @@ public class MainFrame extends JFrame {
// path = fileChooser.getSelectedFile().getPath();
this.getCurrentImageSession().getRawImage().save(path + "." + s); //$NON-NLS-1$
MainFrame.getStatusBar().setMessage(Messages.getString("MainFrame.233") + path + "." + s); //$NON-NLS-1$ //$NON-NLS-2$
MainFrame.getProgressStatus().setMessage(Messages.getString("MainFrame.233") + path + "." + s); //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.showMessageDialog(this, Messages.getString("MainFrame.235"), //$NON-NLS-1$
Messages.getString("MainFrame.236"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$
}
......
package mustic.gui;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
/**
* Observes changes to the properties of a progress bar
*
* @author MEYER Adrien
*
*/
public class ProgressPropertyChangeListener implements PropertyChangeListener
{
/**
* Invoked when task's progress property changes.
* (each time progress' value changes)
*/
@Override
public void propertyChange(PropertyChangeEvent evt)
{
if (evt.getPropertyName() == "progress")
{
int progress = (Integer) evt.getNewValue();
MainFrame.getProgressBar().setValue((Math.min(progress, 100)));
if(progress >= 100)
{
MainFrame.getProgressStatus().reset();
}
}
}
}
......@@ -4,20 +4,20 @@ import java.awt.Dimension;
import javax.swing.JLabel;
public class StatusBar extends JLabel {
public class ProgressStatus extends JLabel {
private static final long serialVersionUID = 5772650506094263588L;
private String initMessage = Messages.getString("StatusBar.0"); //$NON-NLS-1$
/** Creates a new instance of StatusBar */
public StatusBar() {
public ProgressStatus() {
super();
this.init();
this.reset();
}
public StatusBar(String message) {
public ProgressStatus(String message) {
super();
this.init();
this.setMessage(message);
......
......@@ -4,7 +4,6 @@ import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
......@@ -22,10 +21,9 @@ import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.LineNumberReader;
import java.util.List;
import java.util.Random;
import java.util.Vector;
......@@ -34,7 +32,6 @@ import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
......@@ -59,9 +56,9 @@ import jcl.clustering.constraints.MustLinkConstraint;
import jcl.clustering.constraints.NbClusterConstraint;
import jcl.data.Data;
import jcl.utils.Images.StreamedImageReaderWrapper;
import mustic.gui.MainFrame;
import mustic.gui.ProgressPropertyChangeListener;
import mustic.io.RawImage;
import mustic.utils.filters.CSVFileFilter;
import mustic.utils.io.CSVUtils;
/**
* Dialog window that allow the user to generate a set of constraints
......@@ -72,6 +69,8 @@ import mustic.utils.io.CSVUtils;
public class ConstraintsSelectionDialog extends JInternalFrame {
private static final long serialVersionUID = 1L;
ImportConstraintsTask importConstraintsTask = null;
/** data related fields */
private RawImage image = null;
......@@ -261,147 +260,46 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
this.setVisible(true);
}
protected void exportConstraints() {
boolean isImageRelated = true;
if(data != null) {
// choose between image or data indexes
String[] possibilities = { Messages.getString("ConstraintsSelectionDialog.521"),
Messages.getString("ConstraintsSelectionDialog.522")};
String s = (String)JOptionPane.showInputDialog(
this,
Messages.getString("ConstraintsSelectionDialog.520"),
Messages.getString("ConstraintsSelectionDialog.523"),
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
Messages.getString("ConstraintsSelectionDialog.522"));
// if data is selected
if (s.equals(Messages.getString("ConstraintsSelectionDialog.522"))) {
isImageRelated = false;
}
}
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new CSVFileFilter());
String path = "~/constraints.csv";
fileChooser.setSelectedFile(new File(path));
int returnVal = fileChooser.showDialog(this, Messages.getString("ConstraintsSelectionDialog.52")); //$NON-NLS-1$
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
Vector<Constraint> constrainsToExport = null;
if(isImageRelated) {
constrainsToExport = getConstraints();
} else {
constrainsToExport = data.updateAndSetConstraintsToSample(getConstraints());
}
String filename = fileChooser.getSelectedFile().getPath();
if (!filename.endsWith(".csv") && !filename.endsWith(".CSV"))
filename += ".csv"; //$NON-NLS-1$
FileOutputStream out = new FileOutputStream(filename);
PrintWriter writer = new PrintWriter(out);
for(Constraint c : constrainsToExport) {
writer.println(c);
}
writer.close();
out.close();
JOptionPane.showMessageDialog(this,
Messages.getString("ConstraintsSelectionDialog.525"),
Messages.getString("ConstraintsSelectionDialog.526"), //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.INFORMATION_MESSAGE);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
protected void importConstraints() {
try {
JFileChooser fileChooser = new JFileChooser();
CSVFileFilter filter = new CSVFileFilter();
fileChooser.addChoosableFileFilter(filter);
fileChooser.setFileFilter(filter);
fileChooser.setAcceptAllFileFilterUsed(true);
fileChooser.setMultiSelectionEnabled(false);
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
protected void exportConstraints()
{
ExportConstraintsTask exportConstraintsTask = new ExportConstraintsTask(this);
exportConstraintsTask.addPropertyChangeListener(new ProgressPropertyChangeListener());
exportConstraintsTask.execute();
}
boolean imageOuvre = openFile(file);
if (!imageOuvre) {
JOptionPane.showMessageDialog(this, Messages.getString("ConstraintsSelectionDialog.53"),
Messages.getString("ConstraintsSelectionDialog.54"), JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(this,
Messages.getString("ConstraintsSelectionDialog.510"),
Messages.getString("ConstraintsSelectionDialog.511"), //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.INFORMATION_MESSAGE);
}
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, Messages.getString("ConstraintsSelectionDialog.53"),
Messages.getString("ConstraintsSelectionDialog.54"), JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
}
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
protected void importConstraints()
{
ImportConstraintsTask importConstraintsTask = new ImportConstraintsTask(this);
importConstraintsTask.addPropertyChangeListener(new ProgressPropertyChangeListener());
importConstraintsTask.execute();
}
private boolean openFile(File file) {
System.out.println("__________________________________________________________________________________________\n"); //$NON-NLS-1$
System.out.println("Opening file : " + file.getPath()); //$NON-NLS-1$
System.out.println("__________________________________________________________________________________________"); //$NON-NLS-1$
boolean isImageRelated = true;
if(data != null) {
// choose between image or data indexes
String[] possibilities = { Messages.getString("ConstraintsSelectionDialog.521"),
Messages.getString("ConstraintsSelectionDialog.522")};
String s = (String)JOptionPane.showInputDialog(
this,
Messages.getString("ConstraintsSelectionDialog.524"),
Messages.getString("ConstraintsSelectionDialog.523"),
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
Messages.getString("ConstraintsSelectionDialog.522"));
// if data is selected
if (s.equals(Messages.getString("ConstraintsSelectionDialog.522"))) {
isImageRelated = false;
}
}
CSVUtils reader = null;
try {
reader = new CSVUtils(file);
clear();
List<String> line;
while((line = reader.readNext()) != null) {
addConstraint(line, isImageRelated);
}
enableAllComponents();
displayPixels();
updateUI();
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
return true;
public int countLines(File aFile) throws IOException {
LineNumberReader reader = null;
try {
reader = new LineNumberReader(new FileReader(aFile));
while ((reader.readLine()) != null);
return reader.getLineNumber();
} catch (Exception ex) {
return -1;
} finally {
if(reader != null)
reader.close();
}
}
public Data getData()
{
return this.data;
}
private void addConstraint(List<String> line, boolean isImageRelated) {
void addConstraint(List<String> line, boolean isImageRelated) {
switch (Integer.parseInt(line.get(line.size()-1))) {
case Constraint.MUST_LINK_TYPE :
try {
createMustLinkConstraint();
int index1 = getIndex(Integer.parseInt(line.get(0)), isImageRelated)-1;
int index2 = getIndex(Integer.parseInt(line.get(1)), isImageRelated)-1;
int index1 = getIndex(Integer.parseInt(line.get(0)), isImageRelated);
int index2 = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
constraints.add(new MustLinkConstraint(index1, index2));
currentStep = -1;
// we update text fields
......@@ -415,8 +313,8 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
break;
case Constraint.CANNOT_LINK_TYPE :
try {
int index1 = getIndex(Integer.parseInt(line.get(0)), isImageRelated)-1;
int index2 = getIndex(Integer.parseInt(line.get(1)), isImageRelated)-1;
int index1 = getIndex(Integer.parseInt(line.get(0)), isImageRelated);
int index2 = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
createCannotLinkConstraint();
constraints.add(new CannotLinkConstraint(index1, index2));
currentStep = -1;
......@@ -431,7 +329,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
break;
case Constraint.LABEL_TYPE :
try {
int index = getIndex(Integer.parseInt(line.get(0)), isImageRelated)-1;
int index = getIndex(Integer.parseInt(line.get(0)), isImageRelated);
createLabelConstraint();
constraints.add(new LabelConstraint(index,
Integer.parseInt(line.get(2))));
......@@ -941,7 +839,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
g.drawLine(x, y-7, x, y+7);
}
private void clear() {
public void clear() {
constraints = new Vector<Constraint>();
constraintsColors = new Vector<Color>();
}
......
package mustic.gui.dialog.classifier;
import java.awt.Cursor;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import jcl.clustering.constraints.Constraint;
import mustic.gui.MainFrame;
import mustic.utils.filters.CSVFileFilter;
/**
* Loading exported constraints' data into a separate thread
*
* @author Adrien MEYER
*
*/
public class ExportConstraintsTask extends SwingWorker<Void, Void>
{
ConstraintsSelectionDialog dialog = null;
static final private int incrementation = 10;
static int progress = 0;
static int jalon = incrementation; // avoid too many progress update
public ExportConstraintsTask (ConstraintsSelectionDialog dialog)
{
this.dialog = dialog;
}
/*
* Main task. Executed in background thread.
*/
@Override
public Void doInBackground()
{
boolean isImageRelated = true;
if(dialog.getData() != null)
{
// choose between image or data indexes
String[] possibilities = { Messages.getString("ConstraintsSelectionDialog.521"),
Messages.getString("ConstraintsSelectionDialog.522")};
String s = (String)JOptionPane.showInputDialog(
dialog,
Messages.getString("ConstraintsSelectionDialog.520"),
Messages.getString("ConstraintsSelectionDialog.523"),
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
Messages.getString("ConstraintsSelectionDialog.522"));
// if data is selected
if (s.equals(Messages.getString("ConstraintsSelectionDialog.522")))
{
isImageRelated = false;
}
}
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new CSVFileFilter());
String path = "~/constraints.csv";
fileChooser.setSelectedFile(new File(path));
int returnVal = fileChooser.showDialog(dialog, Messages.getString("ConstraintsSelectionDialog.52")); //$NON-NLS-1$
if (returnVal == JFileChooser.APPROVE_OPTION)
{
try
{
Vector<Constraint> constrainsToExport = null;
if(isImageRelated)
{
constrainsToExport = dialog.getConstraints();
}
else
{
constrainsToExport = dialog.getData().updateAndSetConstraintsToSample(dialog.getConstraints());
}
String filename = fileChooser.getSelectedFile().getPath();
if (!filename.endsWith(".csv") && !filename.endsWith(".CSV"))
{
filename += ".csv"; //$NON-NLS-1$
}
FileOutputStream out = new FileOutputStream(filename);
PrintWriter writer = new PrintWriter(out);
int nbrL = constrainsToExport.size();
int progressImprove = 100/nbrL;
dialog.setCursor(new Cursor(Cursor.WAIT_CURSOR));
MainFrame.getProgressStatus().setMessage("Exporting constraints...");
for(Constraint c : constrainsToExport)
{
writer.println(c);
progress += progressImprove;
if(!(progress >= ExportConstraintsTask.jalon))
{
continue;
}
ExportConstraintsTask.jalon += incrementation;
setProgress(Math.min(progress, 100));
}
if(progress<100)
{
setProgress(100);
}
writer.close();
out.close();
JOptionPane.showMessageDialog(dialog,
Messages.getString("ConstraintsSelectionDialog.525"),
Messages.getString("ConstraintsSelectionDialog.526"), //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.INFORMATION_MESSAGE);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
dialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
ImportConstraintsTask.jalon=10;
ImportConstraintsTask.progress=0;
setProgress(0);
return null;
}
}
package mustic.gui.dialog.classifier;
import java.awt.Cursor;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import mustic.gui.MainFrame;
import mustic.utils.filters.CSVFileFilter;
import mustic.utils.io.CSVUtils;
/**
* Loading imported constraints' data into a separate thread
*
* @author Adrien MEYER
*
*/
public class ImportConstraintsTask extends SwingWorker<Void, Void>
{
ConstraintsSelectionDialog dialog = null;
static final private int incrementation = 10;
static int progress = 0;
static int jalon = incrementation; // avoid too many progress update
public ImportConstraintsTask (ConstraintsSelectionDialog dialog)
{
this.dialog = dialog;
}
/*
* Main task. Executed in background thread.
*/
@Override
public Void doInBackground()
{
try
{
JFileChooser fileChooser = new JFileChooser();
CSVFileFilter filter = new CSVFileFilter();
fileChooser.addChoosableFileFilter(filter);
fileChooser.setFileFilter(filter);
fileChooser.setAcceptAllFileFilterUsed(true);