Commit 24058a56 authored by kirandjiska's avatar kirandjiska

temporary commit

parent eb90488f
......@@ -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.dialog.classifier;
import java.awt.AWTException;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
......@@ -11,11 +12,20 @@ import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.LayoutManager;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
......@@ -32,6 +42,7 @@ import java.util.List;
import java.util.Random;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
......@@ -39,6 +50,7 @@ import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
......@@ -50,6 +62,7 @@ import javax.swing.JSlider;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JWindow;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.border.EtchedBorder;
......@@ -162,6 +175,22 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
/** dynamic JPanel Colors of Label Constraints Classes*/
JPanel labelColorConstraintPanel = new JPanel(new GridLayout(0,1));
/** Components of Lens Zoom*/
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;
/**
......@@ -203,6 +232,28 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
}
});
/** 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();
}
}
});*/
this.labelImage.addMouseListener(new MouseAdapter() {
@Override
......@@ -215,9 +266,17 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
&& y < imageSource.getHeight() * mZoomRate) {
switch (currentStep) {
case MustLink_step1:
addFirstPixel(x, y);
break;
case CannotLink_step1:
addFirstPixel(x, y);
break;
case Label_step1:
zoomBox.setZoomBoxVisibility(false);
addFirstPixel(x, y);
if(zoomBoxSelected) {
zoomBox.setZoomBoxVisibility(true);
}
break;
case MustLink_step2:
case CannotLink_step2:
......@@ -233,6 +292,24 @@ 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$
......@@ -279,7 +356,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
otherComponentList.add(exportButton);
JButton constraintsColorChooser = new JButton(
"Constraints Colors"/*
"Choose Constraints Colors"/*
* Messages.getString(
* "ConstraintsSelectionDialog.52"
*/);
......@@ -293,9 +370,50 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
});
panelButton.add(constraintsColorChooser);
otherComponentList.add(constraintsColorChooser);
JCheckBox zoomBoxChkBox = new JCheckBox("Zoom Box");
zoomBox = new ZoomBoxView(labelImage);
zoomBoxChkBox.setMnemonic(KeyEvent.VK_Z);
zoomBoxChkBox.setSelected(zoomBoxActivated);
zoomBoxChkBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
zoomBox.setZoomBoxVisibility(true);
zoomBoxSelected = true;
} else {
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);
......
package mustic.gui.dialog.classifier;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class ZoomBoxView extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
protected static final int ZOOM_AREA = 40;
private JComponent parent;
private JWindow popup;
private Boolean zoomBoxActivated = false;
private BufferedImage buffer;
private float zoomLevel = 4f;
public ZoomBoxView(JComponent parent) {
this.parent = parent;
popup = new JWindow();
popup.setLayout(new BorderLayout());
popup.add(this);
popup.pack();
popup.setAlwaysOnTop(true);
MouseAdapter ma = new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
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);
repaint();
}
@Override
public void mouseEntered(MouseEvent e) {
if (zoomBoxActivated) {
popup.setVisible(true);
}
}
@Override
public void mouseExited(MouseEvent e) {
popup.setVisible(false);
}
};
parent.addMouseListener(ma);
parent.addMouseMotionListener(ma);
}
/** p - cursor coordinates relative to parent window*/
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();
AffineTransform at = new AffineTransform();
int xPos = (ZOOM_AREA / 2) - p.x;
int yPos = (ZOOM_AREA / 2) - p.y;
if (xPos > 0) {
xPos = 0;
}
if (yPos > 0) {
yPos = 0;
}
// if outside the parent window
if ((xPos * -1) + ZOOM_AREA > parent.getWidth()) {
xPos = (parent.getWidth() - ZOOM_AREA) * -1;
}
if ((yPos * -1) + ZOOM_AREA > parent.getHeight()) {
yPos = (parent.getHeight()- ZOOM_AREA) * -1;
}
at.translate(xPos, yPos);
g2d.setTransform(at);
parent.paint(g2d);
g2d.dispose();
}
@Override
public Dimension getPreferredSize() {
return new Dimension(Math.round(ZOOM_AREA * zoomLevel), Math.round(ZOOM_AREA * zoomLevel));
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
if (buffer != null) {
AffineTransform at = g2d.getTransform();
g2d.setTransform(AffineTransform.getScaleInstance(zoomLevel, zoomLevel));
g2d.drawImage(buffer, 0, 0, this);
g2d.setTransform(at);
}
g2d.setColor(Color.RED);
g2d.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
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();
}
protected void setZoomBoxVisibility(boolean visibility) {
popup.setVisible(visibility);
zoomBoxActivated = visibility;
}
/** 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 {
}
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