Commit 927a9cbb authored by kirandjiska's avatar kirandjiska

tmp commit before modif

parent 24058a56
......@@ -106,7 +106,8 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
private BufferedImage imageSource = null;
private JLabel labelImage;
//private JLabel labelImage;
private JPanel displayPanel = null;
public JPanel mainPanel;
......@@ -180,18 +181,10 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
private Boolean zoomBoxActivated = false;
private Boolean zoomBoxSelected = false;
ZoomBoxView zoomBox;
protected static final int ZOOM_AREA = 40;
private JComponent parent;
private JWindow popup;
private JPanel zoomBoxPanel;
private BufferedImage buffer;
private float zoomLevel = 2f;
// ZoomBoxView zoomBox;
ZoomBoxWindow zoomBox;
/**
* Constructor to a dialog window to visualize and build a set of
......@@ -219,51 +212,63 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
// display the image
this.labelImage = new JLabel();
this.labelImage.setHorizontalAlignment(SwingConstants.CENTER);
panelImage.add(this.labelImage, BorderLayout.CENTER);
this.labelImage.addMouseWheelListener(new MouseWheelListener() {
// this.labelImage = new JLabel();
// this.labelImage.setHorizontalAlignment(SwingConstants.CENTER);
// panelImage.add(this.labelImage, BorderLayout.CENTER);
// this.labelImage.addMouseWheelListener(new MouseWheelListener() {
// @Override
// public void mouseWheelMoved(MouseWheelEvent e) {
// if (e.getUnitsToScroll() > 0) {
// zoomIn();
// } else {
// zoomOut();
// }
// }
// });
this.displayPanel = new JPanel() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getUnitsToScroll() > 0) {
zoomIn();
} else {
zoomOut();
}
}
});
/** this.labelImage.addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
BufferedImage zoomBox;
try {
zoomBox = ImageIO.read(new File("cursor_icon.png"));
Point squareCenterCoord = MouseInfo.getPointerInfo().getLocation();
System.out.println(squareCenterCoord);
Graphics g = imagePoints.getGraphics();
// repaint();
// g.drawRect(squareCenterCoord.x-100, squareCenterCoord.y+100,200,200);
g.drawImage(zoomBox,10,10, squareCenterCoord.x-zoomBox.getWidth()/2, squareCenterCoord.y+zoomBox.getHeight()/2,null);
repaint();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (img != null) {
Graphics2D g2d = (Graphics2D) g.create();
Point offset = getOffset();
g2d.drawImage(img, offset.x, offset.y, this);
if (zoomPoint != null) { // if clicked inside image bounds
BufferedImage zoomBuffer = updateBuffer(zoomPoint); // create the zoomed image
if (zoomBuffer != null) {
Rectangle bounds = getZoomBounds();
g2d.drawImage(zoomBuffer, bounds.x, bounds.y, this);
g2d.setColor(Color.RED);
g2d.draw(bounds); // draw a red rectangle frame around zoom box panel
}
}
g2d.dispose();
}
}
}
protected Point getOffset() {
if (imagePoints == null) {
return new Point(0, 0);
}
// image displayed at this offset, img centered in JPanel
int x = (displayPanel.getWidth() - imagePoints.getWidth()) / 2;
int y = (displayPanel.getHeight() - imagePoints.getHeight()) / 2;
return new Point(x, y);
}
});*/
this.labelImage.addMouseListener(new MouseAdapter() {
this.displayPanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// point coordinates relative to img
int x = (int) ((e.getX()
- (int) ((labelImage.getWidth() - (labelImage.getIcon().getIconWidth())) / 2.0)) / mZoomRate);
- (int) ((displayPanel.getWidth() - (displayPanel.getIcon().getIconWidth())) / 2.0)) / mZoomRate);
int y = (int) ((e.getY()
- (int) ((labelImage.getHeight() - (labelImage.getIcon().getIconHeight())) / 2.0)) / mZoomRate);
- (int) ((displayPanel.getHeight() - (displayPanel.getIcon().getIconHeight())) / 2.0)) / mZoomRate);
if (x >= 0 && y >= 0 && x < imageSource.getWidth() * mZoomRate
&& y < imageSource.getHeight() * mZoomRate) {
&& y < imageSource.getHeight() /* mZoomRate*/) {
switch (currentStep) {
case MustLink_step1:
addFirstPixel(x, y);
......@@ -272,11 +277,11 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
addFirstPixel(x, y);
break;
case Label_step1:
zoomBox.setZoomBoxVisibility(false);
// zoomBox.setZoomBoxVisibility(false);
addFirstPixel(x, y);
if(zoomBoxSelected) {
zoomBox.setZoomBoxVisibility(true);
}
// if(zoomBoxSelected) {
// zoomBox.setZoomBoxVisibility(true);
// }
break;
case MustLink_step2:
case CannotLink_step2:
......@@ -292,24 +297,6 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
});
setImage(img);
// change the cursor icon
/**this.labelImage.addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
Point cursorPosition = MouseInfo.getPointerInfo().getLocation();
// getScreenShot(cursorPosition.x-100, cursorPosition.y+100, 200,200);
buffer = imagePoints.getSubimage(cursorPosition.x, cursorPosition.y, 200,200);
Toolkit toolkit = Toolkit.getDefaultToolkit();
// Image cursorIcon = toolkit.getImage(buffer);
Cursor c = toolkit.createCustomCursor(buffer , new Point(labelImage.getX(),
labelImage.getY()), "img");
labelImage.setCursor (c);
repaint();
}
});*/
JPanel panelButton = new JPanel();
JButton buttonOk = new JButton(Messages.getString("ConstraintsSelectionDialog.50")); //$NON-NLS-1$
......@@ -372,7 +359,8 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
otherComponentList.add(constraintsColorChooser);
JCheckBox zoomBoxChkBox = new JCheckBox("Zoom Box");
zoomBox = new ZoomBoxView(labelImage);
// zoomBox = new ZoomBoxView(this);
zoomBox = new ZoomBoxWindow(this);
zoomBoxChkBox.setMnemonic(KeyEvent.VK_Z);
zoomBoxChkBox.setSelected(zoomBoxActivated);
zoomBoxChkBox.addItemListener(new ItemListener() {
......@@ -381,39 +369,21 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
zoomBox.setZoomBoxVisibility(true);
zoomBoxSelected = true;
// zoomBox.setZoomBoxVisibility(true);
// zoomBoxSelected = true;
} else {
zoomBox.setZoomBoxVisibility(false);
zoomBoxSelected = false;
// zoomBox.setZoomBoxVisibility(false);
// zoomBoxSelected = false;
}
}
});
// public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
// if ( e.getStateChange() == ItemEvent.SELECTED) {
// ZoomBoxView zoomBox = new ZoomBoxView(labelImage,true);
// @Override
// }
// else {
// ZoomBoxView zoomBox = new ZoomBoxView(labelImage,false);
// }
// }
// });
panelButton.add(zoomBoxChkBox);
otherComponentList.add(zoomBoxChkBox);
JScrollPane jpane = new JScrollPane(panelImage);
jpane.setBorder(BorderFactory.createTitledBorder(Messages.getString("ConstraintsSelectionDialog.7"))); //$NON-NLS-1$
// if(zoomBoxActivated) {
// ZoomBoxView zoomBox = new ZoomBoxView(this.labelImage);
// }
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(buildInfoPanel()), jpane);
splitPane.setDividerLocation(390);
mainPanel.add(splitPane, BorderLayout.CENTER);
......@@ -467,6 +437,22 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
this.setTitle(Messages.getString("ConstraintsSelectionDialog.8")); //$NON-NLS-1$
this.setVisible(true);
}
protected float getmZoomRate() {
return mZoomRate;
}
// protected JLabel getImgLabel() {
// return labelImage;
// }
protected JPanel getImgPanel() {
return panelImage;
}
protected BufferedImage getImage() {
return imagePoints;
}
protected void exportConstraints() {
boolean isImageRelated = true;
......@@ -1090,7 +1076,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
}
this.labelImage.setIcon(new ImageIcon(this.imagePoints));
// this.displayPanel.(this.imagePoints));
this.image = img;
displayPixels();
}
......@@ -1227,30 +1213,6 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
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.
......@@ -1325,7 +1287,8 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
AffineTransform trans = AffineTransform.getScaleInstance(this.mZoomRate, this.mZoomRate);
AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
BufferedImage mNew = op.filter(this.imagePoints, null);
ImageIcon i = new ImageIcon();
i.getImage().
this.labelImage.setIcon(new ImageIcon(mNew));
}
......
......@@ -15,6 +15,7 @@ import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.UIManager;
......@@ -29,16 +30,15 @@ public class ZoomBoxView extends JPanel {
protected static final int ZOOM_AREA = 40;
private JComponent parent;
// private BufferedImage originalImage;
private JWindow popup;
private Boolean zoomBoxActivated = false;
private ConstraintsSelectionDialog dialog = null;
private BufferedImage buffer;
private float zoomLevel = 4f;
public ZoomBoxView(JComponent parent) {
this.parent = parent;
public ZoomBoxView(ConstraintsSelectionDialog dialog) {
this.dialog = dialog;
popup = new JWindow();
popup.setLayout(new BorderLayout());
popup.add(this);
......@@ -48,10 +48,12 @@ public class ZoomBoxView extends JPanel {
@Override
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
// System.out.println(p);
Point pos = e.getLocationOnScreen();
updateBuffer(p);
popup.setLocation(pos.x + 16, pos.y + 16);
// popup.setLocation(pos.x - popup.getWidth()/2, pos.y - popup.getHeight()/2);
Point origPoint = getOriginalPointCoordinates(p); // get the original position of the point coordinate on the zoomed image
updateBuffer(origPoint);
// popup.setLocation(pos.x + 16, pos.y + 16);
popup.setLocation(pos.x - popup.getWidth()/2, pos.y - popup.getHeight()/2);
repaint();
}
......@@ -69,18 +71,19 @@ public class ZoomBoxView extends JPanel {
};
parent.addMouseListener(ma);
parent.addMouseMotionListener(ma);
dialog.getImgLabel().addMouseListener(ma);
dialog.getImgLabel().addMouseMotionListener(ma);
}
/** p - cursor coordinates relative to parent window*/
private void updateBuffer(Point p) {
/**private void updateBuffer(Point p) {
int width = Math.round(ZOOM_AREA);
int height = Math.round(ZOOM_AREA);
buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = buffer.createGraphics();
Graphics2D g2d =(Graphics2D) originalImage.getGraphics();
AffineTransform at = new AffineTransform();
// center cursor in the zoomBox
int xPos = (ZOOM_AREA / 2) - p.x;
int yPos = (ZOOM_AREA / 2) - p.y;
......@@ -92,6 +95,7 @@ public class ZoomBoxView extends JPanel {
}
// if outside the parent window
// fix parent size on original image size
if ((xPos * -1) + ZOOM_AREA > parent.getWidth()) {
xPos = (parent.getWidth() - ZOOM_AREA) * -1;
}
......@@ -103,6 +107,15 @@ public class ZoomBoxView extends JPanel {
g2d.setTransform(at);
parent.paint(g2d);
g2d.dispose();
}*/
private void updateBuffer(Point p) {
int width = Math.round(ZOOM_AREA);
int height = Math.round(ZOOM_AREA);
buffer = dialog.getImage().getSubimage(p.x - ZOOM_AREA/2, p.y - ZOOM_AREA/2, width, height);
//rajoute condition s'il sort dehors
}
@Override
......@@ -125,7 +138,7 @@ public class ZoomBoxView extends JPanel {
g2d.drawLine(getWidth()/2-1, 0, getWidth()/2-1, getHeight()-1);
g2d.drawLine(0,getHeight()/2-1,getWidth()-1,getHeight()/2-1 );
g2d.drawRect(getWidth()/2-1-4, getHeight()/2-1-4, 8, 8);
// g2d.dispose();
g2d.dispose();
}
......@@ -134,24 +147,18 @@ public class ZoomBoxView extends JPanel {
zoomBoxActivated = visibility;
}
private Point getOriginalPointCoordinates(Point p) {
//point coordinated relative to original image
int x = (int) ((p.getX()
- (int) ((dialog.getImgLabel().getWidth() - (dialog.getImgLabel().getIcon().getIconWidth())) / 2.0)) / dialog.getmZoomRate());
int y = (int) ((p.getY()
- (int) ((dialog.getImgLabel().getHeight() - (dialog.getImgLabel().getIcon().getIconHeight())) / 2.0)) / dialog.getmZoomRate());
// if (x >= 0 && y >= 0 && x < originalImage.getWidth() * zoomLevel
// && y < originalImage.getHeight() * zoomLevel) {
return new Point(x,y);
}
/** public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
// TestPane pane = new TestPane();
// ZoomPane zoomPane = new ZoomPane(pane);
}
});
}*/
}
}
package mustic.gui.dialog.classifier;
public class ZoomBoxWindow {
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
}
public class ZoomBoxWindow /*extends JPanel*/ {
private ConstraintsSelectionDialog dialog = null;
private Point zoomPoint; // cursor point relative to img panel
private boolean zoomEnabled = true; // a variable indicating if the zoom box panel is enabled
private int zoomArea = 80; // size of zoom box panel
private float zoom = 2.0f; // zoomRate
public ZoomBoxWindow(ConstraintsSelectionDialog dialog) {
this.dialog = dialog;
MouseAdapter ma = new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
zoomPoint = getOriginalPointCoordinates(e.getPoint()); // at every mouse motion get coordinates of cursor point and repaint the zoom box panel
// System.out.println("ZoomPoint on mouse motion " + zoomPoint);
paintZoomBox();
// repaint(); //calls paintComponent()
// dialog.getImgLabel().validate();
// dialog.getImgLabel().repaint();
}
@Override
public void mouseEntered(MouseEvent e) {
if (zoomEnabled) {
// repaint();
paintZoomBox();
// dialog.getImgLabel().repaint();
}
}
@Override
public void mouseExited(MouseEvent e) {
zoomPoint = null;
// repaint();
paintZoomBox();
// dialog.getImgLabel().repaint();
}
};
dialog.getImgLabel().addMouseListener(ma);
dialog.getImgLabel().addMouseMotionListener(ma);
}
public float getZoom() {
return zoom;
}
public void setZoom(float zoom) {
this.zoom = zoom;
paintZoomBox();
dialog.getImgLabel().repaint();
}
public int getZoomArea() {
return zoomArea;
}
public void setZoomArea(int zoomArea) {
this.zoomArea = zoomArea;
paintZoomBox();
dialog.getImgLabel().repaint();
}
public boolean isZoomEnabled() {
return zoomEnabled;
}
public void setZoomEnabled(boolean zoomEnabled) {
this.zoomEnabled = zoomEnabled;
paintZoomBox();
dialog.getImgLabel().repaint();
}
// @Override
// public Dimension getPreferredSize() {
// return new Dimension(Math.round(zoomArea * zoom), Math.round(zoomArea * zoom));
// }
//offset of image relative to JLabel
protected Point getOffset() {
if (dialog.getImage() == null) {
return new Point(0, 0);
}
int x = (dialog.getImgLabel().getWidth() - dialog.getImgLabel().getIcon().getIconWidth()) / 2;
int y = (dialog.getImgLabel().getHeight() - dialog.getImgLabel().getIcon().getIconHeight()) / 2;
return new Point(x, y);
}
// set a rectangle frame around image
// create bounds of image size, the offset needed is the offset of the getOffset function
// return this rectangle frame
protected Rectangle getImageBounds() {
Rectangle bounds = new Rectangle(0, 0, 0, 0);
if (dialog.getImage() != null) {
bounds.setLocation(getOffset());
bounds.setSize(dialog.getImage().getWidth(), dialog.getImage().getHeight());
}
return bounds;
}
//method called on mouse motion
protected void paintZoomBox() {
if(dialog.getImage() != null) {
Graphics g2d = dialog.getImage().getGraphics(); // get parent image graphics
if(zoomPoint != null) {
BufferedImage zoomBuffer = updateBuffer(zoomPoint); // create the zoomed image
if(zoomBuffer != null) {
Rectangle bounds = getZoomBounds();
System.out.println(zoomPoint);
System.out.println(bounds);
g2d.drawImage(zoomBuffer, bounds.x, bounds.y,100,100, null); // draw zoomed image on top of the another
g2d.setColor(Color.RED);
g2d.drawRect(bounds.x, bounds.y,bounds.width,bounds.height);
}
}
// g2d.dispose();
}
}
/** @Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (img != null) {
Graphics2D g2d = (Graphics2D) g.create();
Point offset = getOffset();
g2d.drawImage(img, offset.x, offset.y, this);
if (zoomPoint != null) { // if clicked inside image bounds
BufferedImage zoomBuffer = updateBuffer(zoomPoint); // create the zoomed image
if (zoomBuffer != null) {
Rectangle bounds = getZoomBounds();
g2d.drawImage(zoomBuffer, bounds.x, bounds.y, this);
g2d.setColor(Color.RED);
g2d.draw(bounds); // draw a red rectangle frame around zoom box panel
}
}
g2d.dispose();
}
}*/
protected Rectangle getZoomBounds() {