Commit b59a342a authored by kirandjiska's avatar kirandjiska

Fixed merging conlicts

parents f1057248 4588e9b0
......@@ -5,10 +5,12 @@ import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.beans.PropertyVetoException;
import java.io.*;
import java.net.URI;
import java.util.List;
import java.util.Vector;
import java.util.zip.ZipEntry;
......@@ -598,7 +600,9 @@ public class MainFrame extends JFrame {
menuConstraints.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// createPanelFromOther(currentImageSession);
createConstraints();
}
});
toolsMenu.add(menuConstraints);
......@@ -1340,7 +1344,7 @@ public class MainFrame extends JFrame {
JPanel westPanel = new JPanel(new BorderLayout());
/** Panel West : default */
// Cereation of the Project Tree Interface for datas
// Creation of the Project Tree Interface for datas
JPanel treeDataPanel = new JPanel(new BorderLayout());
JScrollPane treeDataScrollPane = new JScrollPane(this.mDataProjectTree);
treeDataScrollPane.setPreferredSize(new Dimension(180, 100));
......@@ -1350,7 +1354,7 @@ public class MainFrame extends JFrame {
sif_treeDataPanel.setPreferredSize(new Dimension(160, 50));
sif_treeDataPanel.add(treeDataPanel);
// Cereation of the Project Tree Interface for images
// Creation of the Project Tree Interface for images
JPanel treeImagePanel = new JPanel(new BorderLayout());
JScrollPane treeImageScrollPane = new JScrollPane(this.mImageProjectTree);
treeImageScrollPane.setPreferredSize(new Dimension(180, 100));
......@@ -1367,7 +1371,7 @@ public class MainFrame extends JFrame {
sif_infosPanel.setPreferredSize(new Dimension(160, 180));
sif_infosPanel.add(this.infosPanel);
// Creation of the Bitd View Interface
// Creation of the Bird View Interface
this.birdPanel = new JPanel(new BorderLayout());
this.birdPanel.setPreferredSize(new Dimension(160, 100));
......@@ -1446,6 +1450,37 @@ public class MainFrame extends JFrame {
// Selection par defaut
this.birdPanel.requestFocus();
}
// method for resizing an image while keeping aspect ratio
private static BufferedImage resizeImage(BufferedImage originalImage, int type, int frameWidth, int frameHeight) {
double height = originalImage.getHeight();
double width = originalImage.getWidth();
int newWidth, newHeight;
// if image size smaller than window size, do not resize
if (height < frameHeight && width < frameWidth) {
newWidth = (int) width;
newHeight = (int) height;
}
// else resize
else {
double scaleX = (frameWidth / width);
double scaleY = (frameHeight / height);
double scale = Math.min(scaleX, scaleY);
newWidth = (int) (width * scale);
newHeight = (int) (height * scale);
}
BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
g.dispose();
return resizedImage;
}
// 20120309_MBH-Test-Fin
/**
......@@ -1465,7 +1500,7 @@ public class MainFrame extends JFrame {
JPanel westPanel = new JPanel(new BorderLayout());
/** Panel West : default */
// Cereation of the Project Tree Interface for datas
// Creation of the Project Tree Interface for datas
JPanel treeDataPanel = new JPanel(new BorderLayout());
JScrollPane treeDataScrollPane = new JScrollPane(this.mDataProjectTree);
treeDataScrollPane.setPreferredSize(new Dimension(180, 100));
......@@ -1475,7 +1510,7 @@ public class MainFrame extends JFrame {
sif_treeDataPanel.setPreferredSize(new Dimension(160, 50));
sif_treeDataPanel.add(treeDataPanel);
// Cereation of the Project Tree Interface for images
// Creation of the Project Tree Interface for images
JPanel treeImagePanel = new JPanel(new BorderLayout());
JScrollPane treeImageScrollPane = new JScrollPane(this.mImageProjectTree);
treeImageScrollPane.setPreferredSize(new Dimension(180, 100));
......@@ -1484,6 +1519,7 @@ public class MainFrame extends JFrame {
sif_treeImagePanel = new SimpleInternalFrame(Messages.getString("MainFrame.691")); //$NON-NLS-1$
sif_treeImagePanel.setPreferredSize(new Dimension(160, 50));
sif_treeImagePanel.add(treeImagePanel);
// Creation of the Informations Panel Interface
this.infosPanel = new JPanel(new BorderLayout());
......@@ -1492,7 +1528,7 @@ public class MainFrame extends JFrame {
sif_infosPanel.setPreferredSize(new Dimension(160, 180));
sif_infosPanel.add(this.infosPanel);
// Creation of the Bitd View Interface
// Creation of the Bird View Interface
this.birdPanel = new JPanel(new BorderLayout());
this.birdPanel.setPreferredSize(new Dimension(160, 100));
......@@ -1512,7 +1548,7 @@ public class MainFrame extends JFrame {
JSplitPane pane4 = Factory.createStrippedSplitPane(JSplitPane.VERTICAL_SPLIT,
pane3, sif_birdPanel, 1f);
pane3.setOpaque(false);
westPanel.add(pane4, BorderLayout.CENTER);
/** End of operation => Panel West : default */
......
package mustic.gui.tools;
import java.awt.Color;
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.image.BufferedImage;
import javax.swing.JPanel;
/**
* Creates a zoom box over a displayed image
*
* @author Marija Kirandjiska
*
*/
public class ZoomBoxPanel extends JPanel{
/** */
private static final long serialVersionUID = 1L;
private Point zoomPoint;
private Zoomable dialog;
private float zoom = 2.0f;
private int zoomArea = 120;
private boolean zoomBoxEnabled = false;
public ZoomBoxPanel(Zoomable dialog, float zoom, int zoomArea) {
this(dialog);
this.zoom = zoom;
this.zoomArea = zoomArea;
}
public ZoomBoxPanel(Zoomable dialog) {
this.dialog = dialog;
addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
zoomPoint = e.getPoint();
// method paintComponent() called
repaint();
}
});
addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
// method paintComponent() called
repaint();
}
@Override
public void mouseExited(MouseEvent e) {
zoomPoint = null;
// method paintComponent() called
repaint();
}
});
}
/**
* This method paints the image and the zoom box.
* If the mouse point is out of the image bounds the zoom box is not displayed
*/
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (dialog.getDisplayedImage() != null) {
Graphics2D g2d = (Graphics2D) g.create();
Point offset = getOffset();
g2d.drawImage(dialog.getDisplayedImage(), offset.x, offset.y, this);
if (zoomBoxEnabled && zoomPoint != null) {
BufferedImage zoomBuffer = updateBuffer(zoomPoint);
if (zoomBuffer != null) {
Rectangle bounds = getZoomBounds();
Rectangle imgBounds = getImageBounds();
if(zoomPoint.x > imgBounds.x && zoomPoint.x < offset.x + imgBounds.width && zoomPoint.y > offset.y && zoomPoint.y < offset.y + imgBounds.height) {
g2d.drawImage(zoomBuffer, bounds.x, bounds.y, this);
g2d.setColor(Color.RED);
g2d.draw(bounds);
}
}
}
g2d.dispose();
}
}
/**
* Getter of the zoom box visibility
* @return true if the zoom box is enabled,
* false otherwise
*/
public boolean zoomBoxEnabled() {
return zoomBoxEnabled;
}
/**
* Setter for the visibility of the zoom box.
*/
public void setZoomBoxEnabled(boolean zoomBoxEnabled) {
this.zoomBoxEnabled = zoomBoxEnabled;
repaint();
}
/**
* @return the offset of the image displayed in the panel
*/
protected Point getOffset() {
if (dialog.getDisplayedImage() == null) {
return new Point(0, 0);
}
int x = (getWidth() - dialog.getDisplayedImage().getWidth()) / 2;
int y = (getHeight() - dialog.getDisplayedImage().getHeight()) / 2;
return new Point(x, y);
}
/**
* @return the bounds around the image displayed in the panel
*/
protected Rectangle getImageBounds() {
Rectangle bounds = new Rectangle(0, 0, 0, 0);
if (dialog.getDisplayedImage() != null) {
bounds.setLocation(getOffset());
bounds.setSize(dialog.getDisplayedImage().getWidth(), dialog.getDisplayedImage().getHeight());
}
return bounds;
}
/**
* This method creates the zoomed image around the mouse point.
*
* @param p
* mouse point coordinates relative to the panel
*
* @return the zoomed image that fits the zoom box
*/
protected BufferedImage updateBuffer(Point p) {
if (zoomPoint == null) {
return null;
}
Rectangle bounds = getZoomBounds();
Point offset = getOffset();
bounds.x = bounds.x - offset.x;
bounds.y = bounds.y - offset.y;
// if out of bounds
if (bounds.x < 0 || bounds.y < 0 || bounds.width <= 0 || bounds.height <= 0) {
return null;
}
BufferedImage zoomBuffer = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = zoomBuffer.createGraphics();
Image sample = dialog.getMatchingImage(bounds.x, bounds.y, bounds.width, bounds.height, zoom);
// if the zoom box is within image area
if(bounds.width == zoomArea && bounds.height == zoomArea) {
int srcx = (sample.getWidth(null)-bounds.width)/2;
int srcy = (sample.getHeight(null)-bounds.height)/2;
g2d.drawImage(sample, 0,0, bounds.width, bounds.height, srcx, srcy, srcx +bounds.width, srcy + bounds.height, this);
}
// if the zoom box intersects with image area
else {
// mouse point coordinates relative to image
int p1x = p.x - offset.x;
int p1y = p.y - offset.y;
int p2x;
int p2y;
// left
if(bounds.x == 0) {
// mouse point coordinates relative to subimage
p2x = p1x;
p2y = p1y - bounds.y;
}
// down
else if(bounds.y + bounds.height == dialog.getDisplayedImage().getHeight()) {
// mouse point coordinates relative to subimage
p2x = p1x - bounds.x;
p2y = p1y - bounds.y;
}
// right
else if(bounds.x + bounds.width == dialog.getDisplayedImage().getWidth()) {
// mouse point coordinates relative to subimage
p2x = p1x - bounds.x;
p2y = p1y - bounds.y;
}
// up
else {
// mouse point coordinates relative to subimage
p2x = p1x - bounds.x;
p2y = p1y;
}
// mouse point coordinates relative to zoomed subimage
int p3x = (int) (p2x*zoom);
int p3y = (int) (p2y*zoom);
// top left point of cropped area of the zoomed image
int p4x = p3x - (p2x);
int p4y = p3y - (p2y);
// specify the area of the zoomed image that needs to be drawn over the zoom box area
g2d.drawImage(sample, 0,0, bounds.width, bounds.height, p4x, p4y, p4x + bounds.width, p4y + bounds.height, this);
}
g2d.dispose();
return zoomBuffer;
}
/**
* @return the bounds around the zoom box relative to the panel
*/
protected Rectangle getZoomBounds() {
Rectangle bounds = null;
if (zoomPoint != null && dialog.getDisplayedImage() != null) {
// zoom area created in such way so that mouse point is centered in the zoom box
int xPos = zoomPoint.x - (zoomArea / 2);
int yPos = zoomPoint.y - (zoomArea / 2);
Rectangle zoomBounds = new Rectangle(xPos, yPos, zoomArea, zoomArea);
Rectangle imageBounds = getImageBounds();
// create the zoom box as intersection of the image bounds and zoom bounds
bounds = imageBounds.intersection(zoomBounds);
}
return bounds;
}
}
package mustic.gui.tools;
import java.awt.Image;
import java.awt.image.BufferedImage;
/**
* Allow an object that displays a BufferedImage to add a ZoomBox to
* the BufferedImage
*
* @author Marija Kirandjiska
*
*/
public interface Zoomable {
/**
* Return the image displayed by the object
*
* @return the image
*/
public BufferedImage getDisplayedImage();
/**
* Return the corresponding area from the source image with
* displayed image relative coordinates
*
* @param x
* the x coordinate in the displayed Image
* @param y
* the y coordinate in the displayed Image
* @param width2
* the width value in the displayed Image
* @param height
* the height value in the displayed Image
* @param zoom
* the requested zoom level relative to the displayed image
* @return the BufferedImage from the origin image
*/
public Image getMatchingImage(int x, int y, int width, int height, float zoom);
}
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