Commit 33fe6b92 authored by smorgenthaler's avatar smorgenthaler

Progress bar/status fix, transparence image

parent 98c46d20
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;
......@@ -68,7 +69,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();
......@@ -77,7 +78,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 */
......@@ -1424,13 +1425,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 ================
......@@ -1438,7 +1447,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();
......@@ -1551,13 +1560,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 ================
......@@ -1565,7 +1579,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();
......@@ -2316,8 +2330,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() {
......@@ -2626,7 +2640,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++) {
......@@ -2643,6 +2658,7 @@ public class MainFrame extends JFrame {
ex.printStackTrace();
}
this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
MainFrame.getProgressStatus().reset();
}
......@@ -3161,7 +3177,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;
......@@ -3179,7 +3195,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$
}
......
......@@ -3,31 +3,30 @@ package mustic.gui;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
public class ProgressBarPropertyChangeListener implements PropertyChangeListener
/**
* Observes changes to the properties of a progress bar
*
* @author MEYER Adrien
*
*/
public class ProgressPropertyChangeListener implements PropertyChangeListener
{
// The loading bar progresses from 10 to 10
static public int incrementation = 10;
static public int jalon = incrementation;
/**
*
/**
* 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();
if(progress >= ProgressBarPropertyChangeListener.jalon)
{
MainFrame.getProgressBar().setValue((Math.min(/*ProgressBarPropertyChangeListener.jalon*/progress, 100)));
ProgressBarPropertyChangeListener.jalon += ProgressBarPropertyChangeListener.incrementation;
}
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;
......@@ -21,10 +20,7 @@ import java.awt.event.MouseWheelListener;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
......@@ -60,7 +56,8 @@ import jcl.clustering.constraints.MustLinkConstraint;
import jcl.clustering.constraints.NbClusterConstraint;
import jcl.data.Data;
import jcl.utils.Images.StreamedImageReaderWrapper;
import mustic.gui.ProgressBarPropertyChangeListener;
import mustic.gui.MainFrame;
import mustic.gui.ProgressPropertyChangeListener;
import mustic.io.RawImage;
/**
......@@ -261,18 +258,19 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
this.setVisible(true);
}
protected void exportConstraints() {
protected void exportConstraints()
{
ExportConstraintsTask exportConstraintsTask = new ExportConstraintsTask(this);
exportConstraintsTask.addPropertyChangeListener(new ProgressBarPropertyChangeListener());
exportConstraintsTask.addPropertyChangeListener(new ProgressPropertyChangeListener());
exportConstraintsTask.execute();
}
protected void importConstraints()
{
ImportConstraintsTask importConstraintsTask = new ImportConstraintsTask(this);
importConstraintsTask.addPropertyChangeListener(new ProgressBarPropertyChangeListener());
importConstraintsTask.execute();
}
importConstraintsTask.addPropertyChangeListener(new ProgressPropertyChangeListener());
importConstraintsTask.execute();
}
public int countLines(File aFile) throws IOException {
LineNumberReader reader = null;
......@@ -292,63 +290,6 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
{
return this.data;
}
// boolean openFile(File file) throws IOException {
//
// 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(this.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;
// int i=1;
// int nbrL = countLines(file);
//
//
// while((line = reader.readNext()) != null)
// {
// this.addConstraint(line, isImageRelated);
// try {
// Thread.sleep(500);
// System.out.println(i + " sur " + nbrL);
// i++;
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// this.enableAllComponents();
// this.displayPixels();
// this.updateUI();
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// MainFrame.getProgressBar().setValue(0);
// return false;
// }
//
// MainFrame.getProgressBar().setValue(0);
// return true;
// }
void addConstraint(List<String> line, boolean isImageRelated) {
switch (Integer.parseInt(line.get(line.size()-1))) {
......
......@@ -14,10 +14,10 @@ import javax.swing.SwingWorker;
import jcl.clustering.constraints.Constraint;
import mustic.gui.MainFrame;
import mustic.gui.ProgressBarPropertyChangeListener;
import mustic.utils.filters.CSVFileFilter;
/**
* Loading exported constraints' data into a separate thread
*
* @author Adrien MEYER
*
......@@ -25,14 +25,15 @@ import mustic.utils.filters.CSVFileFilter;
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;
}
static public int progress = 0;
/*
* Main task. Executed in background thread.
*/
......@@ -91,41 +92,24 @@ public class ExportConstraintsTask extends SwingWorker<Void, Void>
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 >= ProgressBarPropertyChangeListener.jalon))
if(!(progress >= ExportConstraintsTask.jalon))
{
continue;
}
////
try
{
Thread.sleep(250);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
// progress += progressImprove;
setProgress(Math.min(progress, 100));
ExportConstraintsTask.jalon += incrementation;
setProgress(Math.min(progress, 100));
}
if(progress<100)
{
try
{
Thread.sleep(250);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
setProgress(100);
}
setProgress(100);
writer.close();
out.close();
......@@ -146,11 +130,9 @@ public class ExportConstraintsTask extends SwingWorker<Void, Void>
dialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
ProgressBarPropertyChangeListener.jalon=10;
progress=0;
MainFrame.getProgressBar().setValue(0);
setProgress(0);
ImportConstraintsTask.jalon=10;
ImportConstraintsTask.progress=0;
setProgress(0);
return null;
}
}
......@@ -10,28 +10,27 @@ import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import mustic.gui.MainFrame;
import mustic.gui.ProgressBarPropertyChangeListener;
import mustic.utils.filters.CSVFileFilter;
import mustic.utils.io.CSVUtils;
/**
* Loading imported constraints' data into a separate thread
*
* @author Adrien MEYER
*
*/
class ImportConstraintsTask extends SwingWorker<Void, Void>
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;
}
static public int progress = 0;
/*
* Main task. Executed in background thread.
*/
......@@ -89,36 +88,22 @@ class ImportConstraintsTask extends SwingWorker<Void, Void>
int nbrL = dialog.countLines(file);
int progressImprove = 100/nbrL;
MainFrame.getProgressStatus().setMessage("Importing constraints...");
while((line = reader.readNext()) != null)
{
dialog.addConstraint(line, isImageRelated);
progress += progressImprove;
if(!(progress >= ProgressBarPropertyChangeListener.jalon))
if(!(progress >= ImportConstraintsTask.jalon))
{
continue;
}
try
{
Thread.sleep(250);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
ImportConstraintsTask.jalon += incrementation;
setProgress(Math.min(progress, 100));
}
if(progress<100)
{
try
{
Thread.sleep(250);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
setProgress(100);
}
......@@ -156,10 +141,9 @@ class ImportConstraintsTask extends SwingWorker<Void, Void>
}
dialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
ProgressBarPropertyChangeListener.jalon=10;
progress=0;
MainFrame.getProgressBar().setValue(0);
setProgress(0);
ImportConstraintsTask.jalon=10;
ImportConstraintsTask.progress=0;
setProgress(0);;
return null;
}
......
......@@ -29,8 +29,14 @@ import jcl.learning.*;
import jcl.learning.methods.monostrategy.SingleClassification;
import jcl.learning.methods.monostrategy.ahc.LearningResultAHC;
import jcl.learning.methods.monostrategy.ahc.ParametersAHC;
//<<<< TRANSPARENCE
//import jcl.utils.Images.StreamedImageReaderWrapper;
//>>>> TRANSPARENCE
import jsl.Segmentation;
import jsl.regionalisation.vectorisation.Filters;
//<<<< TRANSPARENCE
//import loci.formats.FormatException;
//>>>> TRANSPARENCE
import mustic.gui.*;
import mustic.gui.dialog.FilterDialog;
import mustic.gui.segmentation.SegmentationPanel;
......@@ -122,6 +128,24 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
/** */
protected BufferedImage zoomed;
//<<<< TRANSPARENCE
// clusters' opacity
// up to 0 - 1
// public static float opacity = 1;
//
// public static float opacityCluster = 1;
//
// public float getOpacity()
// {
// return opacity;
// }
//
// public float getOpacityCluster()
// {
// return opacityCluster;
// }
//>>>> TRANSPARENCE
/**
*
*
......@@ -142,6 +166,7 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
init(classification, frame, imgData, false);
this.ImageResultPanel = this;
}
@Override
......@@ -344,7 +369,7 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
File file = new File(path + "ceva.kml");
Writer output = new BufferedWriter(new FileWriter(file));
output.write(this.writeKMLFile("result.kml", "image.tif",
imgData.getRawImages().get(0).kmlCoordinates()));
getImgData().getRawImages().get(0).kmlCoordinates()));
output.close();
// Writer output = new BufferedWriter(new FileWriter(file));
FileInputStream fin = new FileInputStream(path + "ceva.kml");
......@@ -357,6 +382,8 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
file.delete();
out.close();
fin.close();
JOptionPane.showInternalMessageDialog(this, "The export to KML has been successful", "Information", JOptionPane.INFORMATION_MESSAGE);
......@@ -395,7 +422,7 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
// TODO
}
Filters f = new Filters(this.classification.getClusteringResult().getClusterMap(false), imgData.getWidth());
Filters f = new Filters(this.classification.getClusteringResult().getClusterMap(false), getImgData().getWidth());
classif.getClusteringResult().setClusterMap(f.applyMedianFilter());
// Affichage du resultat
......@@ -419,28 +446,29 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
this.map = this.classification.getClusteringResult().getClusterMap(false);
if (this.map == null) {
System.out.println("Cluster map null");
int width = this.imgData.getWidth();
int height = this.imgData.getHeight();
int width = this.getImgData().getWidth();
int height = this.getImgData().getHeight();
this.map = new int[width * height];
LearningResult result = this.classification.getClusteringResult().getLearningResult();
// le clustering est fait ligne par ligne pour l'image
for (int y = 0; y < height; y++) {
double[][][] buffer = this.imgData.getRawImages().get(0).load(0, y, width, 1);
Mask mask = this.imgData.getRawImages().get(0).getMask();
double[][][] buffer = this.getImgData().getRawImages().get(0).load(0, y, width, 1);
Mask mask = this.getImgData().getRawImages().get(0).getMask();
int nbObjects = width;
if (mask != null)
nbObjects -= mask.getCardinalityInInterval(y*width, (y+1)*width -1);
@SuppressWarnings("deprecation")
Data dataPart = new SimpleData(nbObjects);
for (int x2 = 0, cur = 0; x2 < buffer[0].length; x2++) {
// si l'objet n'est pas masque on l'ajoute e la liste a