Commit 6fb33cca authored by coman's avatar coman

Premerge

parent 84a0ec3a
......@@ -15,6 +15,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
......@@ -79,10 +80,7 @@ import mustic.utils.io.CSVUtils;
*/
public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomable {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/** data related fields */
private RawImage image = null;
......@@ -202,36 +200,32 @@ public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomab
// display the image
this.displayPanel = (JPanel) new ZoomBoxPanel(this);
// key listener for the key "h" which hides/displays the current constraints on the image
this.displayPanel.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) {
}
});
this.displayPanel.setFocusable(true);
this.displayPanel.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getUnitsToScroll() > 0) {
zoomOut();
} else {
zoomIn();
// zoom in zoom box
if((e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
if (e.getUnitsToScroll() > 0) {
((ZoomBoxPanel) displayPanel).zoomInBox();
} else {
((ZoomBoxPanel) displayPanel).zoomOutBox();
}
}
// resize zoom box area
else if((e.getModifiers() & InputEvent.ALT_MASK) == InputEvent.ALT_MASK) {
if (e.getUnitsToScroll() > 0) {
((ZoomBoxPanel) displayPanel).increaseZoomBoxArea();
} else {
((ZoomBoxPanel) displayPanel).decreaseZoomBoxArea();
}
}
// zoom in image
else {
if (e.getUnitsToScroll() > 0) {
zoomOut();
} else {
zoomIn();
}
}
}
});
......@@ -353,9 +347,37 @@ public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomab
initializeConstraintsColors();
otherComponentList.add(constraintsColorChooser);
JCheckBox zoomBoxChkBox = new JCheckBox("Zoom Box");
zoomBoxChkBox.setMnemonic(KeyEvent.VK_Z);
// zoomBoxChkBox.setSelected(zoomBoxActivated);
JCheckBox zoomBoxChkBox = new JCheckBox(Messages.getString("ConstraintsSelectionDialog.58"));
// key listener for the keyJCheckBox
this.displayPanel.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
// enable zoom box
if(e.getKeyCode() == KeyEvent.VK_Z) {
zoomBoxChkBox.doClick();
}
// hide constraints
if(e.getKeyCode() == KeyEvent.VK_H) {
check.doClick();
}
}
@Override
public void keyReleased(KeyEvent e) {
}
});
this.displayPanel.setFocusable(true);
zoomBoxChkBox.addItemListener(new ItemListener() {
@Override
......@@ -1112,6 +1134,20 @@ public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomab
return clone;
}
/**
* @brief Draws an image
* @param index
*/
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
* @param img
......@@ -1138,21 +1174,6 @@ public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomab
}
}
/**
* @brief Draws an image
* @param index
*/
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);
}
}
// TODO check
private void clear() {
constraints = new Vector<Constraint>();
......@@ -1347,9 +1368,29 @@ public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomab
@Override
public Image getMatchingImage(int x, int y, int width, int height, float zoom) {
BufferedImage subImage = this.getDisplayedImage().getSubimage(x, y, width, height);
return subImage.getScaledInstance((int) (width * zoom), (int) (height *zoom ), Image.SCALE_SMOOTH);
// coordinates in original image
int xo = (int) (x/mZoomRate);
int yo = (int) (y/mZoomRate);
int widthOrigin = (int) (width/mZoomRate);
int heightOrigin= (int) (height/mZoomRate);
float zoomOrigin = zoom*mZoomRate ;
int widthSubImage=widthOrigin;
int heightSubImage=heightOrigin;
// manage integer precision rounding problem
if(widthSubImage + xo > this.getOriginalImage().getWidth()) {
widthSubImage=this.getOriginalImage().getWidth() - xo;
}
if(heightSubImage + yo > this.getOriginalImage().getHeight()) {
heightSubImage=this.getOriginalImage().getHeight() - yo;
}
BufferedImage subImage = this.getOriginalImage().getSubimage(xo, yo, widthSubImage, heightSubImage);
return subImage.getScaledInstance((int) (widthSubImage * zoomOrigin), (int) (heightSubImage * zoomOrigin ), Image.SCALE_SMOOTH);
}
public BufferedImage getOriginalImage() {
......
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