Commit 27e7b4f9 authored by coman's avatar coman
Browse files

Hide/Display checkbox

parent fd114105
......@@ -15,6 +15,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
......@@ -27,6 +29,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.Vector;
......@@ -87,12 +90,15 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
private double maxDistance = 100;
private Data data = null;
private BufferedImage imagePoints = null;
/** Source image */
private BufferedImage imageSource = null;
private BufferedImage imageSourceTemp = null;
/** Image with constraints displayed */
private BufferedImage imagePoints = null;
/** Image displayed */
private BufferedImage mNew = null;
private JLabel labelImage;
public JPanel mainPanel;
......@@ -141,6 +147,9 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
/**
* Colors and buttons linked to Must Link, Cannot Link and Label constraints
**/
/** Hide/Display constraints related components */
private JCheckBox check;
/** Dialog for choosing colors for the constraints*/
JDialog jd_colorsChooser;
......@@ -167,16 +176,14 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
/** Images and constraints zoom */
/** Constraints images */
/** Constraint images related components */
File inputImage = new File(getClass().getResource("/icons/icon-pince.png").getFile());
private BufferedImage imagePixel;
private BufferedImage imagePixelML;
private BufferedImage imagePixelCL;
private BufferedImage imagePixelMLTemp;
private BufferedImage imagePixelCLTemp;
private BufferedImage mNew;
/** Constraints images construction */
private int classID;
private int classIndex;
......@@ -193,6 +200,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
public ConstraintsSelectionDialog(RawImage img, Data data) {
super();
mainPanel = new JPanel(new BorderLayout());
if (data != null) {
// case of Data provided
......@@ -210,6 +218,30 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
this.labelImage = new JLabel();
this.labelImage.setHorizontalAlignment(SwingConstants.CENTER);
panelImage.add(this.labelImage, BorderLayout.CENTER);
// key listener for the key "h" which hides/displays the current constraints on the image
labelImage.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_H) {
// active JCheckBox check
check.doClick();
}
}
@Override
public void keyReleased(KeyEvent e) {
}
});
labelImage.setFocusable(true);
this.labelImage.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
......@@ -224,10 +256,12 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
this.labelImage.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int x = (int) ((e.getX()
- (int) ((labelImage.getWidth() - (labelImage.getIcon().getIconWidth())) / 2.0)) / mZoomRate);
int y = (int) ((e.getY()
- (int) ((labelImage.getHeight() - (labelImage.getIcon().getIconHeight())) / 2.0)) / mZoomRate);
// mouse focus on the window
labelImage.requestFocusInWindow();
int x = (int) ((e.getX() - (int) ((labelImage.getWidth()
- (labelImage.getIcon().getIconWidth())) / 2.0)) / mZoomRate);
int y = (int) ((e.getY() - (int) ((labelImage.getHeight()
- (labelImage.getIcon().getIconHeight())) / 2.0)) / mZoomRate);
if (x >= 0 && y >= 0 && x < imageSource.getWidth() /** mZoomRate*/
......@@ -250,9 +284,9 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
}
});
setImage(img);
JPanel panelButton = new JPanel();
JButton buttonOk = new JButton(Messages.getString("ConstraintsSelectionDialog.50")); //$NON-NLS-1$
buttonOk.addActionListener(new ActionListener() {
......@@ -277,7 +311,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
panelButton.add(buttonCancel);
otherComponentList.add(buttonCancel);
JButton importButton = new JButton(Messages.getString("ConstraintsSelectionDialog.51"));
JButton importButton = new JButton(Messages.getString("ConstraintsSelectionDialog.51")); //$NON-NLS-1$
importButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
......@@ -287,7 +321,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
panelButton.add(importButton);
otherComponentList.add(importButton);
JButton exportButton = new JButton(Messages.getString("ConstraintsSelectionDialog.52"));
JButton exportButton = new JButton(Messages.getString("ConstraintsSelectionDialog.52")); //$NON-NLS-1$
exportButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
......@@ -298,10 +332,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
otherComponentList.add(exportButton);
JButton constraintsColorChooser = new JButton(
"Constraints Colors"/*
* Messages.getString(
* "ConstraintsSelectionDialog.52"
*/);
Messages.getString("ConstraintsSelectionDialog.56")); //$NON-NLS-1$
constraintsColorChooser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
......@@ -311,6 +342,24 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
});
panelButton.add(constraintsColorChooser);
/** Displays or hides current constraints on the image */
check = new JCheckBox(Messages.getString("ConstraintsSelectionDialog.57")); //$NON-NLS-1$
check.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(check.isSelected()) {
doZoomedOp();
}
else {
displayPixels();
}
}
});
panelButton.add(check);
initializeConstraintsColors();
JScrollPane jpane = new JScrollPane(panelImage);
......@@ -321,7 +370,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
// mainPanel.add(buildInfoPanel(), BorderLayout.WEST);
// mainPanel.add(jpane, BorderLayout.CENTER);
mainPanel.add(panelButton, BorderLayout.SOUTH);
if (data != null && data.getConstraints() != null) {
setConstraints(data.getConstraints(), false);
}
......@@ -339,8 +388,8 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
private void initializeConstraintsColors() {
try {
imagePixel = ImageIO.read(inputImage);
imagePixelML = ImageIO.read(inputImage);
imagePixelCL = ImageIO.read(inputImage);
imagePixelML = clone(imagePixel);
imagePixelCL = clone(imagePixel);
} catch (IOException e1) {
e1.printStackTrace();
}
......@@ -389,6 +438,8 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
jb_labelConstraintClassChooseColor.get(0).setBackground(labelConstraintColor.get(0));
createLabelColorConstraintsPanel();
}
protected void exportConstraints() {
......@@ -558,6 +609,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
jb_labelConstraintClassChooseColor.get(i).setBackground( labelConstraintColor.get(i));
}
}
// update Vector imageLabelPixelTemp with copies of the original map-image(imagePixel)
imageLabelPixelTemp = new Vector<BufferedImage>();
for(int i = 0; i<labelClassesCount; i++) {
imageLabelPixelTemp.add(ConstraintsSelectionDialog.this.clone(imagePixel));
......@@ -734,32 +786,34 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
e.printStackTrace();
}
break;
}
}
/**
* This method allow to get the image related index given a data or an image
* related index
* This method allow to get the image index given a data related index
* or an image related index
*
* @param index
* the index
* @param isImageRelated
* true if related
*
* to the image, false if related to the data
* 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
// 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$
panelInfos.setBorder(BorderFactory.createTitledBorder(
Messages.getString("ConstraintsSelectionDialog.0"))); //$NON-NLS-1$
panelInfos.setPreferredSize(new Dimension(370, 300));
JTaskPane taskPane = new JTaskPane();
......@@ -955,8 +1009,6 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
this.width = img.getWidth();
this.imageSource = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
this.imagePoints = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
this.imageSourceTemp = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
double data[][][] = img.load(0, 0, img.getWidth(), img.getHeight());
double[] max = new double[data.length];
......@@ -975,8 +1027,8 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
}
}
short[][][] dataView = new short[data.length][data[0].length][data[0][0].length];
; // the values to display
short[][][] dataView = new short[data.length][data[0]
.length][data[0][0].length]; // the values to display
double values[][] = data[0];
/*
* max contains the max value for r g b, we can create a valid
......@@ -1004,7 +1056,8 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
if (max[i] <= 255 && min[b] >= 0) {
dataView[i][x][y] = (short) data[b][x][y];
} else {
dataView[i][x][y] = (short) (255 * (data[i][x][y] - min[b]) / (max[b] - min[b]));
dataView[i][x][y] = (short) (255 *
(data[i][x][y] - min[b]) / (max[b] - min[b]));
}
} else {
dataView[i][x][y] = 0;
......@@ -1016,20 +1069,17 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
for (int x = 0; x < values.length; x++) {
for (int y = 0; y < values[0].length; y++) {
int pixel = (int) values[x][y] << 24 | dataView[bands[0]][x][y] << 16 | dataView[bands[1]][x][y] << 8
| dataView[bands[2]][x][y];
int pixel = (int) values[x][y] << 24 | dataView[bands[0]][x][y] << 16
| dataView[bands[1]][x][y] << 8 | dataView[bands[2]][x][y];
imageSource.setRGB(x, y, pixel);
imagePoints.setRGB(x, y, pixel);
imageSourceTemp.setRGB(x, y, pixel);
}
}
AffineTransform trans = AffineTransform.getScaleInstance(this.mZoomRate, this.mZoomRate);
AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
mNew = op.filter(this.imagePoints, null);
this.labelImage.setIcon(new ImageIcon(this.imagePoints));
this.image = img;
displayPixels();
doZoomedOp();
}
protected void addSecondPixel(int x, int y) {
......@@ -1044,9 +1094,11 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
default:
return;
}
currentStep = -1;
previousIndex = -1;
((JTextField) constraintsPanels.get(constraintsPanels.size() - 1).getComponent(3)).setText("" + index);
((JTextField) constraintsPanels.get(constraintsPanels.size() - 1)
.getComponent(3)).setText("" + index);
enableAllComponents();
}
......@@ -1068,8 +1120,10 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
possibilities[i] = "" + (i + 1);
}
possibilities[labelClassesCount] = Messages.getString("ConstraintsSelectionDialog.35");
String s = (String) JOptionPane.showInputDialog(this, Messages.getString("ConstraintsSelectionDialog.33"),
Messages.getString("ConstraintsSelectionDialog.34"), JOptionPane.PLAIN_MESSAGE, null, possibilities,
String s = (String) JOptionPane.showInputDialog(this,
Messages.getString("ConstraintsSelectionDialog.33"),
Messages.getString("ConstraintsSelectionDialog.34"),
JOptionPane.PLAIN_MESSAGE, null, possibilities,
"1");
// If a string was returned, say so.
......@@ -1079,11 +1133,10 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
if (s.equals(Messages.getString("ConstraintsSelectionDialog.35"))) {
labelClassesCount++;
//imageCounter = labelClassesCount;
classIndex = labelClassesCount;
// generate a random color for label constraints of the same
// class
Random rand = new Random();
Random rand = new Random(new Date().getTime());
float r = rand.nextFloat();
float g = rand.nextFloat();
float b = rand.nextFloat();
......@@ -1092,8 +1145,10 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
// initialize button color linked to the new label class
// constraint
jb_labelConstraintClassChooseColor.add(new JButton());
jb_labelConstraintClassChooseColor.get(classIndex - 1).putClientProperty("index", classIndex - 1);
jb_labelConstraintClassChooseColor.get(classIndex - 1).setBackground(labelConstraintColor.get(classIndex - 1));
jb_labelConstraintClassChooseColor.get(classIndex - 1)
.putClientProperty("index", classIndex - 1);
jb_labelConstraintClassChooseColor.get(classIndex - 1)
.setBackground(labelConstraintColor.get(classIndex - 1));
createLabelColorConstraintsPanel();
copy = clone(imagePixel);
......@@ -1115,7 +1170,9 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
default:
return;
}
((JTextField) constraintsPanels.get(constraintsPanels.size() - 1).getComponent(1)).setText("" + index);
}
private void displayPixels() {
......@@ -1127,28 +1184,30 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
for (int i = 0; i < constraints.size(); i++) {
if (constraints.get(i) instanceof MustLinkConstraint) {
drawPixel(((MustLinkConstraint) constraints.get(i)).getFirstIndex(),
mustLinkColor/* constraintsColors.get(i) */, "",imagePixelML);
mustLinkColor, imagePixelML);
drawPixel(((MustLinkConstraint) constraints.get(i)).getSecondIndex(),
mustLinkColor/* constraintsColors.get(i) */, "",imagePixelML);
mustLinkColor, imagePixelML);
linkPixel(((MustLinkConstraint) constraints.get(i)).getFirstIndex(),
((MustLinkConstraint) constraints.get(i)).getSecondIndex(),
mustLinkColor/* constraintsColors.get(i) */, "");
mustLinkColor, "");
} else if (constraints.get(i) instanceof CannotLinkConstraint) {
drawPixel(((CannotLinkConstraint) constraints.get(i)).getFirstIndex(),
cannotLinkColor/* constraintsColors.get(i) */, "",imagePixelCL);
cannotLinkColor, imagePixelCL);
drawPixel(((CannotLinkConstraint) constraints.get(i)).getSecondIndex(),
cannotLinkColor/* constraintsColors.get(i) */, "",imagePixelCL);
cannotLinkColor, imagePixelCL);
linkPixel(((CannotLinkConstraint) constraints.get(i)).getFirstIndex(),
((CannotLinkConstraint) constraints.get(i)).getSecondIndex(),
cannotLinkColor/* constraintsColors.get(i) */, "");
cannotLinkColor, "");
} else if (constraints.get(i) instanceof LabelConstraint ) {
classID = ((LabelConstraint) constraints.get(i)).getClassID();
drawPixel(((LabelConstraint) constraints.get(i)).getIndex(),labelConstraintColor.get(classID-1),"",imageLabelPixel.get(classID-1));
drawPixel(((LabelConstraint) constraints.get(i)).getIndex(),labelConstraintColor.get(classID-1),imageLabelPixel.get(classID-1));
}
}
this.labelImage.setIcon(new ImageIcon(mNew));
/*if (previousIndex > 0) {
// it matches the last colour added
......@@ -1159,42 +1218,20 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
private void linkPixel(int firstIndex, int secondIndex, Color c, String name) {
Graphics2D g = (Graphics2D) mNew.getGraphics();
g.setStroke(
new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 4 }, 0.0f));
g.setColor(c);
int x1 = (int) ((firstIndex % this.width)*mZoomRate);
int y1 = (int) ((firstIndex / this.width)*mZoomRate);
int x2 = (int) ((secondIndex % this.width)*mZoomRate);
int y2 = (int) ((secondIndex / this.width)*mZoomRate);
g.drawString(name, x1 + 4, y1 - 4); // $NON-NLS-1$
g.drawLine(x1, y1, x2, y2);
if(!check.isSelected()) {
Graphics2D g = (Graphics2D) mNew.getGraphics();
g.setStroke(
new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 4 }, 0.0f));
g.setColor(c);
int x1 = (int) ((firstIndex % this.width)*mZoomRate);
int y1 = (int) ((firstIndex / this.width)*mZoomRate);
int x2 = (int) ((secondIndex % this.width)*mZoomRate);
int y2 = (int) ((secondIndex / this.width)*mZoomRate);
g.drawString(name, x1 + 4, y1 - 4); // $NON-NLS-1$
g.drawLine(x1, y1, x2, y2);
}
}
/**
* Color Chooser for Must-Link constraints\n Sets the temporary color and
* button.
**/
/*
* private Color chooseMustLinkColor() { Color mlColor =
* JColorChooser.showDialog(ConstraintsSelectionDialog.this,
* "Must-Link Color Chooser", mustLinkColor); //$NON-NLS-1$ if (mlColor ==
* null) return mustLinkColor; else return mlColor;
* //this.jb_mustLinkChooseColor.setBackground(mustLinkColor); }
*/
/**
* Color Chooser for Cannot-Link constraints\n Sets the temporary color and
* button.
**/
/*
* private Color chooseCannotLinkColor() { Color clColor =
* JColorChooser.showDialog(ConstraintsSelectionDialog.this,
* "Cannot-Link Color Chooser", cannotLinkColor); //$NON-NLS-1$ if (clColor
* == null) return cannotLinkColor; else return clColor;
* //this.jb_cannotLinkChooseColor.setBackground(cannotLinkColor); }
*/
/**
* Color Chooser for Must-Link constraints\n Sets the temporary color and
* button indicating the chosen color.
......@@ -1257,15 +1294,16 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
* @brief Draws an image
* @param index
*/
private void drawPixel(int index, Color c, String name, BufferedImage img) {
Graphics g = mNew.getGraphics();
g.setColor(c);
int x = (int) ((index % this.width) * mZoomRate);
int y = (int) ((index / this.width)* mZoomRate);
g.drawString(name, x + 4, y - 4); // $NON-NLS-1$
g.drawImage(img, x-23, y-35,100,100, null);
private void drawPixel(int index, Color c, BufferedImage img) {
if(!check.isSelected()) {
Graphics g = mNew.getGraphics();
g.setColor(c);
int x = (int) ((index % this.width) * mZoomRate);
int y = (int) ((index / this.width)* mZoomRate);
g.drawImage(img, x-23, y-35,100,100, null);
}
}
/**
* @brief Changes the pixels color of an image
......@@ -1310,7 +1348,6 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
displayPixels();
}
@SuppressWarnings("unchecked")
public Vector<Constraint> getConstraints() {
Vector<Constraint> fullConstraints = (Vector<Constraint>) constraints.clone();
......@@ -1483,5 +1520,6 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
this.container = container;
}
}
}
......@@ -62,5 +62,7 @@ ConstraintsSelectionDialog.526=Export
ConstraintsSelectionDialog.53=Unknown file format for import
ConstraintsSelectionDialog.54=Error
ConstraintsSelectionDialog.55=Cancel
ConstraintsSelectionDialog.56=Constraints Colors
ConstraintsSelectionDialog.57=Hide Constraints
ConstraintsSelectionDialog.7=Image
ConstraintsSelectionDialog.8=Constraint selection
......@@ -62,5 +62,7 @@ ConstraintsSelectionDialog.526=Export
ConstraintsSelectionDialog.53=Format de fichier inconnu lors de l'import
ConstraintsSelectionDialog.54=Erreur
ConstraintsSelectionDialog.55=Annuler
ConstraintsSelectionDialog.56=Couleurs de contraintes
ConstraintsSelectionDialog.57=Cacher les contraintes
ConstraintsSelectionDialog.7=Image
ConstraintsSelectionDialog.8=Slection des contraintes
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment