[Imagetools-commit] SF.net SVN: imagetools:[8] trunk/imagetools/src/net/codebuilders/desktop/ image
Status: Beta
Brought to you by:
cmarcum
|
From: <cm...@us...> - 2009-04-09 00:00:58
|
Revision: 8
http://imagetools.svn.sourceforge.net/imagetools/?rev=8&view=rev
Author: cmarcum
Date: 2009-04-09 00:00:53 +0000 (Thu, 09 Apr 2009)
Log Message:
-----------
Added setupRectangleMouseListeners() for drawing a rectangle. Renamed constant DRAW_RECTANGLE to DRAW_CROP_RECTANGLE which is what it was for and added a new constant for DRAW_RECTANGLE to avoid confusion. Modified other methods accordingly.
Modified Paths:
--------------
trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java
Modified: trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java
===================================================================
--- trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-04-08 00:33:05 UTC (rev 7)
+++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-04-09 00:00:53 UTC (rev 8)
@@ -93,9 +93,10 @@
// var to hold current mouse listener
private int mouseEvtType;
// constants for mouse events
- public static final int DRAW_RECTANGLE = 0;
+ public static final int DRAW_CROP_RECTANGLE = 0;
public static final int DRAW_LINE = 1;
public static final int DRAW_TEXT = 2;
+ public static final int DRAW_RECTANGLE = 3;
MouseListener ml;
MouseMotionListener mml;
@@ -138,7 +139,7 @@
// Install a mouse listener that sets things up for a selection drag.
// setup crop by default
// this.setupCropMouseListeners();
- this.setMouseEvtType(ImageArea.DRAW_RECTANGLE);
+ this.setMouseEvtType(ImageArea.DRAW_CROP_RECTANGLE);
} // end constructor
@@ -239,7 +240,7 @@
switch (getMouseEvtType()) {
- case DRAW_RECTANGLE:
+ case DRAW_CROP_RECTANGLE:
this.paintRectangle(g);
break;
@@ -251,6 +252,10 @@
;
break;
+ case DRAW_RECTANGLE:
+ this.paintRectangle(g);
+ break;
+
} // end switch
}
@@ -448,6 +453,95 @@
}
+ private void setupRectangleMouseListeners() {
+
+ // remove existing mouse listeners
+ this.tearDownMouseListeners();
+
+ this.ml = new MouseAdapter() {
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ // When you start Capture, there is no captured image.
+ // Therefore, it makes no sense to try to draw.
+ // This is the reason for the if (image == null) test.
+
+ if (image == null) {
+ return;
+ }
+
+ destx = srcx = e.getX();
+ desty = srcy = e.getY();
+
+ repaint();
+ }
+
+ // TEST to crop on release or fire event
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ System.out.println("Mouse released.");
+
+ int width = image.getWidth(null);
+ int height = image.getHeight(null);
+
+ BufferedImage biNew = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D g2d = biNew.createGraphics();
+
+ // Copy current image to old
+ try {
+ BufferedImage biOld = (BufferedImage) image;
+ // should copy image
+ // BufferedImage bi2 = bi.getSubimage(0, 0, width, height);
+ g2d.drawImage(biOld, null, 0, 0);
+
+ } catch (RasterFormatException rfe) {
+ // TODO fix this error
+ System.out.println("raster format exception" + rfe.toString());
+
+ }
+
+
+ // draw the real rectangle
+ g2d.setStroke(bsAnnotate);
+ // g2d.setPaint(gpAnnotate);
+ g2d.setColor(Color.RED);
+ g2d.draw(rectSelection);
+
+ // set the image
+ setImage(biNew, true);
+
+ }
+ };
+ this.addMouseListener(ml);
+
+ // Install a mouse motion listener to update the selection rectangle
+ // during drag operations.
+
+ // MouseMotionListener mml;
+ this.mml = new MouseMotionAdapter() {
+
+ public void mouseDragged(MouseEvent e) {
+ // When you start Capture, there is no captured image.
+ // Therefore, it makes no sense to try and select a
+ // subimage. This is the reason for the if (image == null)
+ // test.
+
+ if (image == null) {
+ return;
+ }
+
+ destx = e.getX();
+ desty = e.getY();
+
+ repaint();
+ }
+ };
+ this.addMouseMotionListener(mml);
+
+
+ }
+
private void setupLineMouseListeners() {
// this.removeMouseListener(ml);
@@ -632,7 +726,7 @@
// setup the proper mouse listener
switch (getMouseEvtType()) {
- case DRAW_RECTANGLE:
+ case DRAW_CROP_RECTANGLE:
this.setupCropMouseListeners();
break;
@@ -644,6 +738,9 @@
this.setupTextMouseListeners();
break;
+ case DRAW_RECTANGLE:
+ this.setupRectangleMouseListeners();
+ break;
} // end switch
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|