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;
}
......
This diff is collapsed.
......@@ -5,11 +5,14 @@ import java.awt.Container;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import mustic.gui.MainFrame;
/*
* Class for display the Progress of loading the RawImage DataMatrix
*
......@@ -37,7 +40,7 @@ public class ProgressChargeImageOTB extends JFrame implements IObserver {
taskOutput.setEditable(false);
JPanel panel = new JPanel();
panel.add(progressBar);
panel.add(progressBar);
content.add(panel, BorderLayout.PAGE_START);
content.add(new JScrollPane(taskOutput), BorderLayout.CENTER);
......@@ -46,7 +49,6 @@ public class ProgressChargeImageOTB extends JFrame implements IObserver {
this.setLocation(500, 500);
this.pack();
this.setVisible(true);
}
@Override
......
......@@ -20,8 +20,10 @@ import jsl.Segmentation;
import jsl.io.ObjetImage;
import jsl.utils.PointDiscret;
import mustic.gui.DesktopFrame;
import mustic.gui.ImageDesktopFrame;
import mustic.gui.MainFrame;
import mustic.gui.panels.ImageResultPanel;
import mustic.io.ImageData;
import mustic.io.RawImage;
import mustic.models.gui.ClassificationModel;
import mustic.models.gui.panels.ClassConfigPanel;
......@@ -62,7 +64,7 @@ public class SegmentationResultPanel extends ImageResultPanel {
* @param session
* @param s
*/
public SegmentationResultPanel(Classification classification, ClassificationModel frame, RawImage mRawImage, Segmentation s,
public SegmentationResultPanel(Classification classification, ClassificationModel frame, ImageData mRawImage, Segmentation s,
BufferedImage imageLabel, int indSessionSeg) {
this.s = s;
......@@ -70,11 +72,11 @@ public class SegmentationResultPanel extends ImageResultPanel {
if (!(classification.isMultiresolution())) {
System.out.println("Classif non multires");
this.imageInitiale = MainFrame.getInstance().getCurrentSession().getImagePanel().getImage();
this.imageInitiale = MainFrame.getInstance().getCurrentImageSession().getImagePanel().getImage();
}
else {
// On recherche l'image dans les sessions
DesktopFrame[] desktopFrames = MainFrame.getInstance().getDesktop().getAllDesktopFrames();
ImageDesktopFrame[] desktopFrames = MainFrame.getInstance().getDesktop().getAllImageDesktopFrames();
Vector<SegmentationPanel> sps = desktopFrames[indSessionSeg].getImageSession().getSegPanels();
SegmentationPanel sp = sps.get(0);
......@@ -108,14 +110,14 @@ public class SegmentationResultPanel extends ImageResultPanel {
}
protected void computeMapContours() {
int width = this.mRawImage.getWidth() + 1;
int height = this.mRawImage.getHeight() + 1;
int width = this.getImgData().getWidth() + 1;
int height = this.getImgData().getHeight() + 1;
mapContoursBlanc = new int[width * height];
for (ObjetImage oi : this.s.getResultat().getObjectsImage()) {
for (PointDiscret p : oi.getBound()) {
mapContoursBlanc[p.x + (this.mRawImage.getHeight() - p.y) * width] = 1;
mapContoursBlanc[p.x + (this.getImgData().getHeight() - p.y) * width] = 1;
}
}
......@@ -124,20 +126,20 @@ public class SegmentationResultPanel extends ImageResultPanel {
public void constructImageFrontiere() {
// Construction de l'image contour
imageContours = new BufferedImage(this.mRawImage.getWidth(), this.mRawImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
imageContours = new BufferedImage(this.getImgData().getWidth(), this.getImgData().getHeight(), BufferedImage.TYPE_INT_ARGB);
// Calcul de l'image contour
computeMapContours();
int width = this.mRawImage.getWidth() + 1;
int height = this.mRawImage.getHeight() + 1;
int width = this.getImgData().getWidth() + 1;
int height = this.getImgData().getHeight() + 1;
for (int i = 0; i < width * height; i++) {
int x = (i % width);
int y = (i / width);
if (x >= 0 && x < this.mRawImage.getWidth()) {
if (y >= 0 && y < this.mRawImage.getHeight()) {
if (x >= 0 && x < this.getImgData().getWidth()) {
if (y >= 0 && y < this.getImgData().getHeight()) {
if (mapContoursBlanc[i] == 1) {
imageContours.setRGB(x, y, Color.WHITE.getRGB());
}
......@@ -151,15 +153,15 @@ public class SegmentationResultPanel extends ImageResultPanel {
int[] mapC2 = getMapContours2();
int width = this.mRawImage.getWidth() + 1;
int height = this.mRawImage.getHeight() + 1;
int width = this.getImgData().getWidth() + 1;
int height = this.getImgData().getHeight() + 1;
for (int i = 0; i < width * height; i++) {
int x = (i % width);
int y = (i / width);
if (x >= 0 && x < this.mRawImage.getWidth()) {
if (y >= 0 && y < this.mRawImage.getHeight()) {
if (x >= 0 && x < this.getImgData().getWidth()) {
if (y >= 0 && y < this.getImgData().getHeight()) {
// Si le pixel appartient à la région selectionné
if (mapC2[i] == 1) {
imageContours.setRGB(x, y, Color.RED.getRGB());
......@@ -187,17 +189,17 @@ public class SegmentationResultPanel extends ImageResultPanel {
SegmentationPanel segP = new SegmentationPanel(s, image);
MainFrame
.getInstance()
.getCurrentSession()
.getCurrentImageSession()
.getWorkSpace()
.setSelectedTab(MainFrame.getInstance().getCurrentSession().getWorkSpace()
.getTabAt(MainFrame.getInstance().getCurrentSession().getWorkSpace().getTabCount() - 1));
.setSelectedTab(MainFrame.getInstance().getCurrentImageSession().getWorkSpace()
.getTabAt(MainFrame.getInstance().getCurrentImageSession().getWorkSpace().getTabCount() - 1));
}