Commit a1c233f6 authored by lafabregue's avatar lafabregue
Browse files

update currentview to ArrayList

parent fd23a4b8
This diff is collapsed.
......@@ -2163,10 +2163,12 @@ public class MainFrame extends JFrame {
*/
protected void createConstraints() {
try {
ConstraintsSelectionDialog dialog = new ConstraintsSelectionDialog(this.currentImageSession.getRawImage());
ConstraintsSelectionDialog dialog = new ConstraintsSelectionDialog(
this.currentImageSession.getRawImage(), null);
MainFrame.getInstance().getDesktop().addFrame(dialog);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, Messages.getString("MainFrame.128"), Messages.getString("MainFrame.129"), //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.showMessageDialog(this, Messages.getString("MainFrame.128"),
Messages.getString("MainFrame.129"), //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.WARNING_MESSAGE);
}
}
......
......@@ -58,6 +58,7 @@ import jcl.clustering.constraints.LabelConstraint;
import jcl.clustering.constraints.MustLinkConstraint;
import jcl.clustering.constraints.NbClusterConstraint;
import jcl.data.Data;
import jcl.utils.Images.StreamedImageReaderWrapper;
import mustic.io.RawImage;
import mustic.utils.CSVUtils;
import mustic.utils.filters.CSVFileFilter;
......@@ -77,6 +78,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
private int width = -1;
private double minDistance = 0;
private double maxDistance = 100;
private Data data = null;
private BufferedImage imagePoints = null;
......@@ -143,8 +145,15 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
mainPanel = new JPanel(new BorderLayout());
if (data != null) {
// case of Data provided
minDistance = data.getEstimatedMinDistance();
maxDistance = data.getEstimatedMaxDistance();
this.data = data;
} else {
// otherwise we base our estimation on the image
StreamedImageReaderWrapper reader = new StreamedImageReaderWrapper(img.getPath());
minDistance = 0;
maxDistance = reader.getMaxValue() - reader.getMinValue();
}
// display the image
......@@ -191,12 +200,25 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
buttonOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ConstraintsSelectionDialog.this.data != null) {
ConstraintsSelectionDialog.this.data.updateAndSetConstraintsToSample(getConstraints());
}
ConstraintsSelectionDialog.this.dispose();
}
});
panelButton.add(buttonOk);
otherComponentList.add(buttonOk);
JButton buttonCancel = new JButton(Messages.getString("ConstraintsSelectionDialog.55")); //$NON-NLS-1$
buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ConstraintsSelectionDialog.this.dispose();
}
});
panelButton.add(buttonCancel);
otherComponentList.add(buttonCancel);
JButton importButton = new JButton(Messages.getString("ConstraintsSelectionDialog.51"));
importButton.addActionListener(new ActionListener() {
@Override
......@@ -227,12 +249,35 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
// mainPanel.add(jpane, BorderLayout.CENTER);
mainPanel.add(panelButton, BorderLayout.SOUTH);
if( data != null && data.getConstraints() != null) {
setConstraints(data.getConstraints(), false);
}
this.setContentPane(mainPanel);
this.setTitle(Messages.getString("ConstraintsSelectionDialog.8")); //$NON-NLS-1$
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";
......@@ -240,16 +285,26 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
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 : getConstraints()) {
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) {
......@@ -259,6 +314,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
protected void importConstraints() {
try {
JFileChooser fileChooser = new JFileChooser();
CSVFileFilter filter = new CSVFileFilter();
......@@ -275,9 +331,15 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
boolean imageOuvre = openFile(file);
if (!imageOuvre)
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"),
......@@ -293,13 +355,32 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
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);
addConstraint(line, isImageRelated);
}
enableAllComponents();
updateUI();
......@@ -311,47 +392,108 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
return true;
}
private void addConstraint(List<String> line) {
private void addConstraint(List<String> line, boolean isImageRelated) {
switch (Integer.parseInt(line.get(0))) {
case Constraint.MUST_LINK_TYPE :
try {
createMustLinkConstraint();
constraints.add(new MustLinkConstraint(Integer.parseInt(line.get(1)),
Integer.parseInt(line.get(2))));
int index1 = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
int index2 = getIndex(Integer.parseInt(line.get(2)), isImageRelated);
constraints.add(new MustLinkConstraint(index1, index2));
currentStep = -1;
// we update text fields
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(1)).setText(""+Integer.parseInt(line.get(1)));
.getComponent(1)).setText(""+index1);
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(3)).setText(""+Integer.parseInt(line.get(2)));
.getComponent(3)).setText(""+index2);
} catch(Exception e) {
e.printStackTrace();
}
break;
case Constraint.CANNOT_LINK_TYPE :
try {
int index1 = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
int index2 = getIndex(Integer.parseInt(line.get(2)), isImageRelated);
createCannotLinkConstraint();
constraints.add(new CannotLinkConstraint(Integer.parseInt(line.get(1)),
Integer.parseInt(line.get(2))));
constraints.add(new CannotLinkConstraint(index1, index2));
currentStep = -1;
// we update text fields
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(1)).setText(""+Integer.parseInt(line.get(1)));
.getComponent(1)).setText(""+index1);
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(3)).setText(""+Integer.parseInt(line.get(2)));
.getComponent(3)).setText(""+index2);
} catch(Exception e) {
e.printStackTrace();
}
break;
case Constraint.LABEL_TYPE :
try {
int index = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
createLabelConstraint();
constraints.add(new LabelConstraint(Integer.parseInt(line.get(1)),
constraints.add(new LabelConstraint(index,
Integer.parseInt(line.get(2))));
currentStep = -1;
// we update text fields
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(1)).setText(""+Integer.parseInt(line.get(1)));
.getComponent(1)).setText(""+index);
} catch(Exception e) {
e.printStackTrace();
}
break;
}
}
private void addConstraint(Constraint constraint, boolean isImageRelated) {
switch (constraint.getType()) {
case Constraint.MUST_LINK_TYPE :
try {
createMustLinkConstraint();
int index1 = getIndex(((MustLinkConstraint) constraint).getFirstIndex(),
isImageRelated);
int index2 = getIndex(((MustLinkConstraint) constraint).getSecondIndex(),
isImageRelated);
constraints.add(new MustLinkConstraint(index1, index2));
currentStep = -1;
enableAllComponents();
// we update text fields
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(1)).setText(""+index1);
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(3)).setText(""+index2);
} catch(Exception e) {
e.printStackTrace();
}
break;
case Constraint.CANNOT_LINK_TYPE :
try {
int index1 = getIndex(((CannotLinkConstraint) constraint).getFirstIndex(),
isImageRelated);
int index2 = getIndex(((CannotLinkConstraint) constraint).getSecondIndex(),
isImageRelated);
createCannotLinkConstraint();
constraints.add(new CannotLinkConstraint(index1, index2));
currentStep = -1;
enableAllComponents();
// we update text fields
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(1)).setText(""+index1);
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(3)).setText(""+index2);
} catch(Exception e) {
e.printStackTrace();
}
break;
case Constraint.LABEL_TYPE :
try {
int index = getIndex(((LabelConstraint) constraint).getIndex(), isImageRelated);
createLabelConstraint();
constraints.add(new LabelConstraint(index,
((LabelConstraint) constraint).getClassID()));
currentStep = -1;
enableAllComponents();
// we update text fields
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(1)).setText(""+index);
} catch(Exception e) {
e.printStackTrace();
}
......@@ -359,6 +501,25 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
}
/**
* This method allow to get the image related index
* given a data or an image related index
*
* @param index
* the index
* @param isImageRelated
* true if related
*
* to the image, false if related to the data
* @return the image related index
*/
private int getIndex(int index, boolean isImageRelated) {
if(isImageRelated || data.getSampler() == null)
return index;
//TODo take in consideration the geotranslate vectors to have the coorest index
return data.getSampler().getSampleIndexes().get(index);
}
private JPanel buildInfoPanel() {
JPanel panelInfos = new JPanel(new BorderLayout());
panelInfos.setBorder(BorderFactory.createTitledBorder(Messages.getString("ConstraintsSelectionDialog.0"))); //$NON-NLS-1$
......@@ -446,10 +607,12 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
ncInner.setLayout(new FlowLayout());
ncInner.add(new JLabel(Messages.getString("ConstraintsSelectionDialog.16")));
nbClusterMinTextField = new JTextField(3);
nbClusterMinTextField.setText("1");
nbClusterMinTextField.setEnabled(false);
ncInner.add(nbClusterMinTextField);
ncInner.add(new JLabel(Messages.getString("ConstraintsSelectionDialog.17")));
nbClusterMaxTextField = new JTextField(3);
nbClusterMaxTextField.setText("1");
nbClusterMaxTextField.setEnabled(false);
ncInner.add(nbClusterMaxTextField);
......@@ -549,6 +712,9 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
private void setImage(RawImage img) {
if(img == null) {
return;
}
if (this.image!=null && !this.image.getPath().equals(img.getPath()))
this.clear();
this.width = img.getWidth();
......@@ -807,8 +973,12 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
return fullConstraints;
}
public void setConstraints(Vector<Constraint> constraints) {
this.constraints = constraints;
private void setConstraints(Vector<Constraint> constraints, boolean isImageRelated) {
this.constraints = new Vector<Constraint>();
for(Constraint c : constraints) {
addConstraint(c, isImageRelated);
}
displayPixels();
}
protected void createMustLinkConstraint() {
......
......@@ -49,8 +49,18 @@ ConstraintsSelectionDialog.35=New class
ConstraintsSelectionDialog.36=class
ConstraintsSelectionDialog.50=OK
ConstraintsSelectionDialog.51=Import
ConstraintsSelectionDialog.510=The file was successfully imported.
ConstraintsSelectionDialog.511=Import
ConstraintsSelectionDialog.52=Export
ConstraintsSelectionDialog.520=From which source do you want to link the exported index ?
ConstraintsSelectionDialog.521=Image
ConstraintsSelectionDialog.522=Data
ConstraintsSelectionDialog.523=Select source
ConstraintsSelectionDialog.524=From which source are these constraints linked ?
ConstraintsSelectionDialog.525=Constraints were successfully exported.
ConstraintsSelectionDialog.526=Export
ConstraintsSelectionDialog.53=Unknown file format for import
ConstraintsSelectionDialog.54=Error
ConstraintsSelectionDialog.55=Cancel
ConstraintsSelectionDialog.7=Image
ConstraintsSelectionDialog.8=Constraint selection
......@@ -49,8 +49,18 @@ ConstraintsSelectionDialog.35=Nouvelle classe
ConstraintsSelectionDialog.36=classe
ConstraintsSelectionDialog.50=OK
ConstraintsSelectionDialog.51=Importer
ConstraintsSelectionDialog.510=Le fichier a t import avec succs
ConstraintsSelectionDialog.511=Import
ConstraintsSelectionDialog.52=Exporter
ConstraintsSelectionDialog.520=A quelle source voulez vous associer les indexes des contraintes ?
ConstraintsSelectionDialog.521=Image
ConstraintsSelectionDialog.522=Data
ConstraintsSelectionDialog.523=Slectionner source
ConstraintsSelectionDialog.524=A quelle source voulez vous associer les indexes des contraintes ?
ConstraintsSelectionDialog.525=Les contraintes ont t exportes avec succs.
ConstraintsSelectionDialog.526=Export
ConstraintsSelectionDialog.53=Format de fichier inconnu lors de l'import
ConstraintsSelectionDialog.54=Erreur
ConstraintsSelectionDialog.55=Annuler
ConstraintsSelectionDialog.7=Image
ConstraintsSelectionDialog.8=Slection des contraintes
......@@ -14,11 +14,14 @@ import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
......@@ -26,6 +29,9 @@ import jcl.data.Data;
import jcl.utils.Histogram;
import mustic.gui.ClassificationFrame;
import mustic.gui.MainFrame;
import mustic.gui.dialog.classifier.ConstraintsSelectionDialog;
import mustic.io.ImageData;
import mustic.io.RawImage;
import mustic.models.gui.dialogs.FilterDataDialog;
import mustic.models.gui.panels.DataViewPanel;
import mustic.models.gui.panels.ScatterPlotPanel;
......@@ -56,60 +62,63 @@ import org.jfree.ui.RefineryUtilities;
* @author Germain Forestier
* @see Data
*/
public class DataPanel extends JPanel {
public class DataPanel extends JPanel implements ChangeListener {
/** Necessaire */
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
JFreeChart attrChart = null;
JFreeChart attrChart = null;
/** Pour mettre a jour le chart */
ChartPanel attrChartPanel = null;
ChartPanel attrChartPanel = null;
/** Affichage dynamique selon la selection dans la table */
JLabel attrNameLabel = null;
JLabel attrNameLabel = null;
/** Table des attributs */
JTable attrTable = null;
JTable attrTable = null;
JLabel attrTypeLabel = null;
JLabel attrTypeLabel = null;
/** Affichage des classes du resultat connu s'il existe */
JPanel classesPanel = null;
JPanel classesPanel = null;
/** Table des classes */
JTable classesTable = null;
JTable classesTable = null;
/** Reference vers les donnees */
Data data = null;
Data data = null;
JButton deleteAttributeButton = new JButton("Delete Attribute");
JButton deleteAttributeButton = new JButton("Delete Attribute");
JButton doOp = new JButton("doOp");
JButton doOp = new JButton("doOp");
JButton filterButton = new JButton("Filter Attributes");
JButton filterButton = new JButton("Filter Attributes");
JLabel nbattrLabel = null;
JLabel nbattrLabel = null;
JLabel nbobjLabel = null;
JLabel nbobjLabel = null;
/** Affichage dynamique en cas de suppression d'un attr/objet */
JLabel relationLabel = null;
JLabel relationLabel = null;
/** Table des statistiques */
JTable statsTable = null;
JTable statsTable = null;
JButton viewCommentsButton = new JButton("View Comments");
JButton viewCommentsButton = new JButton("View Comments");
JButton viewDataButton = new JButton("View Data (text)");
JButton viewDataButton = new JButton("View Data (text)");
/** Boutons de choix */
JButton visualizeDataButton = new JButton("Visualize Data (chart)");
JButton visualizeDataButton = new JButton("Visualize Data (chart)");
/** Button to classify the Data */
JButton classifyButton = new JButton("Classify");
JButton classifyButton = new JButton("Classify");
/** Button to classify the Data */
JButton constraintButton = new JButton(Messages.getString("DataPanel.01"));
/** La liste des onglets */
public TabbedPanel tabbedPane = new TabbedPanel();
public TabbedPanel tabbedPane = new TabbedPanel();
/**
* <p>
......@@ -296,6 +305,7 @@ public class DataPanel extends JPanel {
buttonPanel.add(this.viewCommentsButton);
buttonPanel.add(this.filterButton);
buttonPanel.add(this.classifyButton);
buttonPanel.add(this.constraintButton);
// buttonPanel.add(doOp);
container.add(buttonPanel, BorderLayout.SOUTH);
......@@ -417,6 +427,25 @@ public class DataPanel extends JPanel {
}
}
});
this.constraintButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
RawImage img = null;
if(data instanceof ImageData) {
img = ((ImageData)data).getRawImages().get(0);
}
ConstraintsSelectionDialog dialog = new ConstraintsSelectionDialog(img, data);
MainFrame.getInstance().getDesktop().addFrame(dialog);
} catch (Exception ex) {
JOptionPane.showMessageDialog(tabbedPane, Messages.getString("ConstraintsSelectionDialog.53"),
Messages.getString("ConstraintsSelectionDialog.54"), JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
}
}
});
}
/**
......@@ -569,4 +598,13 @@ public class DataPanel extends JPanel {
this.statsTable.setModel(new ClarffxTableModel(init, initName));
}
@Override
public void stateChanged(ChangeEvent e) {
if(e.getSource() instanceof ConstraintsSelectionDialog) {
this.data.updateAndSetConstraintsToSample(
((ConstraintsSelectionDialog) e.getSource()).getConstraints());
}
}
}
......@@ -15,6 +15,7 @@ import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.text.PlainDocument;
import jcl.data.sampling.Sampler;
import mustic.gui.panels.data.DataConstructPanel;
import mustic.gui.panels.data.Messages;
import mustic.utils.documentFilter.DoubleDocumentFilter;
......@@ -42,9 +43,12 @@ public class SamplingSelectionPanel extends JPanel implements ToUpdateObject {
/** all components related to the sampling mode used */
private ButtonGroup sampleModeSelection = new ButtonGroup();