Thread: [Imagetools-commit] SF.net SVN: imagetools:[3] trunk/imagetools/src/net/codebuilders/desktop/ image
Status: Beta
Brought to you by:
cmarcum
From: <cm...@us...> - 2009-04-05 23:17:55
|
Revision: 3 http://imagetools.svn.sourceforge.net/imagetools/?rev=3&view=rev Author: cmarcum Date: 2009-04-05 23:17:40 +0000 (Sun, 05 Apr 2009) Log Message: ----------- Added readyToCrop boolean and getter/setter methods so we can see if we can crop yet. Added mouseReleased method to crop listener to set the boolean. 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-05 23:13:33 UTC (rev 2) +++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-04-05 23:17:40 UTC (rev 3) @@ -87,6 +87,11 @@ */ private Point2D pointSelection; + /** + * Ready to crop, usually after rectangle selection + */ + private boolean readyToCrop; + // var to hold current mouse listener private int mouseEvtType; // constants for mouse events @@ -131,6 +136,7 @@ gpAnnotate = new GradientPaint(0.0f, 0.0f, Color.red, 1.0f, 1.0f, Color.white, true); + this.readyToCrop = false; // Install a mouse listener that sets things up for a selection drag. // setup crop by default // this.setupCropMouseListeners(); @@ -200,6 +206,7 @@ repaint(); } + setReadyToCrop(false); return succeeded; } @@ -395,6 +402,23 @@ repaint(); } + + // TEST to crop on release or fire event + @Override + public void mouseReleased(MouseEvent e) { + System.out.println("Mouse released."); + + // check for rectangle + if (srcx != destx || srcy != desty) { + setReadyToCrop(true); + System.out.println("Ready to crop."); + } else { + System.out.println("Not ready to crop."); + } + + } + + }; this.addMouseListener(ml); @@ -419,6 +443,8 @@ repaint(); } + + }; addMouseMotionListener(mml); @@ -598,4 +624,18 @@ } + + /** + * @return the readyToCrop + */ + public boolean isReadyToCrop() { + return readyToCrop; + } + + /** + * @param readyToCrop the readyToCrop to set + */ + public void setReadyToCrop(boolean readyToCrop) { + this.readyToCrop = readyToCrop; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cm...@us...> - 2009-04-05 23:20:09
|
Revision: 4 http://imagetools.svn.sourceforge.net/imagetools/?rev=4&view=rev Author: cmarcum Date: 2009-04-05 23:19:59 +0000 (Sun, 05 Apr 2009) Log Message: ----------- Added line to actual set readyToCrop false if we did not have a rectangle. Should have been part of last commit. 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-05 23:17:40 UTC (rev 3) +++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-04-05 23:19:59 UTC (rev 4) @@ -413,6 +413,7 @@ setReadyToCrop(true); System.out.println("Ready to crop."); } else { + setReadyToCrop(false); System.out.println("Not ready to crop."); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cm...@us...> - 2009-04-10 21:05:57
|
Revision: 16 http://imagetools.svn.sourceforge.net/imagetools/?rev=16&view=rev Author: cmarcum Date: 2009-04-10 21:05:49 +0000 (Fri, 10 Apr 2009) Log Message: ----------- Added mouseDragged method to textMouseListener and paintText method to allow dragging text before placement. 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-10 19:48:49 UTC (rev 15) +++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-04-10 21:05:49 UTC (rev 16) @@ -80,12 +80,21 @@ * for drawing a line */ private Line2D lineSelection; + /** * Location and extents of selection point. * for drawing text */ private Point2D pointSelection; + /** + * Location and extents of selection point. + * for drawing text + */ + private String drawText; + + + /** * Ready to crop, usually after rectangle selection */ private boolean readyToCrop; @@ -107,31 +116,26 @@ // Create a selection Rectangle. It's better to create one Rectangle // here than a Rectangle each time paintComponent() is called, to reduce // unnecessary object creation. - rectSelection = new Rectangle(); lineSelection = new Line2D.Float(); - + pointSelection = new Point2D.Float(); // Define the stroke for drawing selection rectangle outline. - bsSelect = new BasicStroke(5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[]{12, 12}, 0); // Define the gradient paint for coloring selection rectangle outline. - gpSelect = new GradientPaint(0.0f, 0.0f, Color.red, 1.0f, 1.0f, Color.white, true); // Define the stroke for drawing annotation. - bsAnnotate = new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); // Define the gradient paint for coloring annotation. - gpAnnotate = new GradientPaint(0.0f, 0.0f, Color.red, 1.0f, 1.0f, Color.white, true); @@ -249,7 +253,7 @@ break; case DRAW_TEXT: - ; + this.paintText(g); break; case DRAW_RECTANGLE: @@ -317,9 +321,24 @@ g2d.dispose(); + } // end if + } + // called by paintComponent + public void paintText(Graphics g) { + // paint text + // Draw the text if the mouse has moved. + if (srcx != destx || srcy != desty) { + + // Draw selection line. + Graphics2D g2d = (Graphics2D) g; + + g2d.setColor(Color.DARK_GRAY); + g2d.drawString(drawText, destx, desty); + g2d.dispose(); + } // end if } @@ -501,7 +520,7 @@ } - + // draw the real rectangle g2d.setStroke(bsAnnotate); // g2d.setPaint(gpAnnotate); @@ -649,6 +668,11 @@ if (image == null) { return; } + + // save a local copy of the text + // get the model to get text from + ImageToolsModel itModel = ImageToolsApp.getApplication().getItModel(); + drawText = itModel.getText(); destx = srcx = e.getX(); desty = srcy = e.getY(); @@ -658,7 +682,6 @@ @Override public void mouseReleased(MouseEvent e) { - // BufferedImage bi = (BufferedImage) getImage(); int width = image.getWidth(null); int height = image.getHeight(null); @@ -667,8 +690,6 @@ BufferedImage.TYPE_INT_RGB); Graphics2D g2d = biNew.createGraphics(); - //Graphics2D g2d = bi.createGraphics(); - // Copy current image to old try { BufferedImage biOld = (BufferedImage) image; @@ -682,26 +703,36 @@ } - - // get the model to get text from - ImageToolsModel itModel = ImageToolsApp.getApplication().getItModel(); - - - // draw the real line - // g2d.setStroke(bsAnnotate); - // g2d.setPaint(gpAnnotate); g2d.setColor(Color.RED); - // g2d.draw(lineSelection); // TODO add font info - g2d.drawString(itModel.getText(), srcx, srcy); + g2d.drawString(drawText, destx, desty); setImage(biNew, true); } }; this.addMouseListener(ml); + this.mml = new MouseMotionAdapter() { + @Override + 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); + } public void tearDownMouseListeners() { @@ -738,7 +769,7 @@ this.setupTextMouseListeners(); break; - case DRAW_RECTANGLE: + 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. |
From: <cm...@us...> - 2009-07-24 21:58:49
|
Revision: 73 http://imagetools.svn.sourceforge.net/imagetools/?rev=73&view=rev Author: cmarcum Date: 2009-07-24 21:58:37 +0000 (Fri, 24 Jul 2009) Log Message: ----------- comment spelling correction 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-07-03 22:22:17 UTC (rev 72) +++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-07-24 21:58:37 UTC (rev 73) @@ -801,7 +801,7 @@ // Get lines until the entire paragraph has been displayed. while (lineMeasurer.getPosition() < paragraphEnd) { - // Retrieve next layout. A cleverer program would also cache + // Retrieve next layout. A clever program would also cache // these layouts until the component is re-sized. TextLayout layout = lineMeasurer.nextLayout(breakWidth); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cm...@us...> - 2009-07-25 14:21:34
|
Revision: 74 http://imagetools.svn.sourceforge.net/imagetools/?rev=74&view=rev Author: cmarcum Date: 2009-07-25 14:21:26 +0000 (Sat, 25 Jul 2009) Log Message: ----------- ticket:13 - added white rounded rectangle background behind text annotations. 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-07-24 21:58:37 UTC (rev 73) +++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-07-25 14:21:26 UTC (rev 74) @@ -29,6 +29,7 @@ import java.awt.font.LineBreakMeasurer; import java.awt.font.TextAttribute; import java.awt.font.TextLayout; +import java.awt.geom.RoundRectangle2D; import java.text.AttributedCharacterIterator; import java.text.AttributedString; import java.beans.PropertyChangeEvent; @@ -86,7 +87,6 @@ * for drawing text */ private Point2D pointSelection; - /** * Ready to crop, usually after rectangle selection */ @@ -103,6 +103,9 @@ MouseMotionListener mml; // The LineBreakMeasurer used to line-break the paragraph. private LineBreakMeasurer lineMeasurer; + // The LineBreakMeasurer used to get the size the paragraph + // for the background rectangle + private LineBreakMeasurer rectMeasurer; private float breakWidth = (float) 200.0; // index of the first character in the paragraph. private int paragraphStart; @@ -763,6 +766,13 @@ int width = image.getWidth(null); int height = image.getHeight(null); + // variables for text background rectangle + double rectPosX = destx; + double rectPosY = desty; + double rectWidth = 0; + double rectHeight = 0; + + BufferedImage biNew = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = biNew.createGraphics(); @@ -780,6 +790,78 @@ } + // begin text background rectangle + + // color for background of text + g2d.setColor(Color.WHITE); + + // Create a new LineBreakMeasurer from the paragraph. + // It will be cached and re-used. + if (rectMeasurer == null) { + AttributedCharacterIterator paragraph = attStr.getIterator(); + paragraphStart = paragraph.getBeginIndex(); + paragraphEnd = paragraph.getEndIndex(); + FontRenderContext frc = g2d.getFontRenderContext(); + rectMeasurer = new LineBreakMeasurer(paragraph, frc); + } + + // Set break width to width of Component. + breakWidth = itModel.getTextBoxWidth(); + + // Set position to the index of the first character in the paragraph. + rectMeasurer.setPosition(paragraphStart); + + // make a copy of measurer and loop through to get dimensions + // calculate the rectangle size ant set variables + LineBreakMeasurer lmCopy = rectMeasurer; + // Get lines until the entire paragraph has been displayed. + while (lmCopy.getPosition() < paragraphEnd) { + + // Retrieve next layout. A cleverer program would also cache + // these layouts until the component is re-sized. + TextLayout layout = lmCopy.nextLayout(breakWidth); + + // Compute pen x position. If the paragraph is right-to-left we + // will align the TextLayouts to the right edge of the panel. + // Note: this won't occur for the English text in this sample. + // Note: drawPosX is always where the LEFT of the text is placed. + // TODO adjust the RightToLeft case with destx also + // LeftToRight has been fixed + rectPosX = layout.isLeftToRight() + ? (0 + destx) : breakWidth - layout.getAdvance(); + // Move y-coordinate by the ascent of the layout. + rectPosY += layout.getAscent(); + // Draw the TextLayout at (drawPosX, drawPosY). + // layout.draw(g2d, drawPosX, drawPosY); + // Move y-coordinate in preparation for next layout. + rectPosY += layout.getDescent() + layout.getLeading(); + // add the y move to rectangle height + System.out.println("rectHeight was " + rectHeight); + rectHeight += layout.getAscent() + layout.getDescent() + + layout.getLeading(); + System.out.println("rectHeight is now " + rectHeight); + // if text line width is greater than rectWidth + // set rectWidth to line width + if (layout.getAdvance() > rectWidth) { + rectWidth = layout.getAdvance(); + } + } + + System.out.println("rectangle position and size= " + + rectPosX + ", " + desty + ", " + + rectWidth + ", " + rectHeight); + // draw a rectangle around text with padding + g2d.fill(new RoundRectangle2D.Double((destx - 4) , (desty - 4), + (rectWidth + 8), + (rectHeight + 8), 10, 10)); + + // finish + lmCopy = null; + rectMeasurer = null; + + // end text rectangle + + // color for text g2d.setColor(itModel.getColor()); // Create a new LineBreakMeasurer from the paragraph. @@ -798,10 +880,12 @@ // Set position to the index of the first character in the paragraph. lineMeasurer.setPosition(paragraphStart); + + // Get lines until the entire paragraph has been displayed. while (lineMeasurer.getPosition() < paragraphEnd) { - // Retrieve next layout. A clever program would also cache + // Retrieve next layout. A cleverer program would also cache // these layouts until the component is re-sized. TextLayout layout = lineMeasurer.nextLayout(breakWidth); @@ -823,8 +907,12 @@ // Move y-coordinate in preparation for next layout. drawPosY += layout.getDescent() + layout.getLeading(); + + } + + setImage(biNew, true); g2d.dispose(); lineMeasurer = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cm...@us...> - 2009-04-07 23:45:38
|
Revision: 5 http://imagetools.svn.sourceforge.net/imagetools/?rev=5&view=rev Author: cmarcum Date: 2009-04-07 23:45:35 +0000 (Tue, 07 Apr 2009) Log Message: ----------- Added method to tear down mouse listeners. 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-05 23:19:59 UTC (rev 4) +++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-04-07 23:45:35 UTC (rev 5) @@ -384,7 +384,8 @@ private void setupCropMouseListeners() { - this.removeMouseListener(ml); + // this.removeMouseListener(ml); + this.tearDownMouseListeners(); this.ml = new MouseAdapter() { @Override @@ -454,7 +455,8 @@ private void setupLineMouseListeners() { - this.removeMouseListener(ml); + // this.removeMouseListener(ml); + this.tearDownMouseListeners(); this.ml = new MouseAdapter() { @Override @@ -523,7 +525,8 @@ private void setupTextMouseListeners() { - this.removeMouseListener(ml); + // this.removeMouseListener(ml); + this.tearDownMouseListeners(); // setupRectangleMouseListeners currently work // except for pemenently adding line to image this.ml = new MouseAdapter() { @@ -592,6 +595,11 @@ } + public void tearDownMouseListeners() { + this.removeMouseListener(ml); + this.removeMouseMotionListener(mml); + } + /** * @return the mouseEvtType */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cm...@us...> - 2009-04-08 00:27:14
|
Revision: 6 http://imagetools.svn.sourceforge.net/imagetools/?rev=6&view=rev Author: cmarcum Date: 2009-04-08 00:27:08 +0000 (Wed, 08 Apr 2009) Log Message: ----------- Added MouseMotionListener to setupLineMouseListeners method. Was using listener from cropMouseListener that was still active. Adding the tear down found this. 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-07 23:45:35 UTC (rev 5) +++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-04-08 00:27:08 UTC (rev 6) @@ -26,7 +26,6 @@ // http://www.javaworld.com/javaworld/jw-04-2006/jw-0424-funandgames.html // original was crop only // added the paint lines, text etc. - package net.codebuilders.desktop.imagetools; import java.awt.*; @@ -86,7 +85,6 @@ * for drawing text */ private Point2D pointSelection; - /** * Ready to crop, usually after rectangle selection */ @@ -386,6 +384,7 @@ // this.removeMouseListener(ml); this.tearDownMouseListeners(); + this.ml = new MouseAdapter() { @Override @@ -411,16 +410,14 @@ // check for rectangle if (srcx != destx || srcy != desty) { - setReadyToCrop(true); - System.out.println("Ready to crop."); + setReadyToCrop(true); + System.out.println("Ready to crop."); } else { setReadyToCrop(false); System.out.println("Not ready to crop."); } - + } - - }; this.addMouseListener(ml); @@ -428,7 +425,7 @@ // during drag operations. // MouseMotionListener mml; - mml = new MouseMotionAdapter() { + this.mml = new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { // When you start Capture, there is no captured image. @@ -445,10 +442,8 @@ repaint(); } - - }; - addMouseMotionListener(mml); + this.addMouseMotionListener(mml); } @@ -457,6 +452,7 @@ // this.removeMouseListener(ml); this.tearDownMouseListeners(); + this.ml = new MouseAdapter() { @Override @@ -519,8 +515,27 @@ }; this.addMouseListener(ml); + this.mml = new MouseMotionAdapter() { + @Override + 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 setupTextMouseListeners() { @@ -597,7 +612,7 @@ public void tearDownMouseListeners() { this.removeMouseListener(ml); - this.removeMouseMotionListener(mml); + this.removeMouseMotionListener(mml); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <cm...@us...> - 2009-05-23 22:19:03
|
Revision: 42 http://imagetools.svn.sourceforge.net/imagetools/?rev=42&view=rev Author: cmarcum Date: 2009-05-23 22:18:53 +0000 (Sat, 23 May 2009) Log Message: ----------- added logger for exceptions 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-26 16:00:48 UTC (rev 41) +++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-05-23 22:18:53 UTC (rev 42) @@ -20,11 +20,17 @@ import javax.swing.*; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * This class defines a specialized panel for displaying a captured image. */ public class ImageArea extends JPanel { + // logger + Logger logger = null; + /** * Stroke-defined outline of selection rectangle. */ @@ -97,6 +103,10 @@ * Construct an ImageArea component. */ public ImageArea() { + + // setup logger + logger = Logger.getLogger(ImageArea.class.getName()); + // Create a selection Rectangle. It's better to create one Rectangle // here than a Rectangle each time paintComponent() is called, to reduce // unnecessary object creation. @@ -457,7 +467,7 @@ } private void setupRectangleMouseListeners() { - + // remove existing mouse listeners this.tearDownMouseListeners(); @@ -482,6 +492,8 @@ // TEST to crop on release or fire event @Override public void mouseReleased(MouseEvent e) { + + System.out.println("Mouse released."); int width = image.getWidth(null); @@ -499,9 +511,10 @@ g2d.drawImage(biOld, null, 0, 0); } catch (RasterFormatException rfe) { - // TODO fix this error - System.out.println("raster format exception" + rfe.toString()); + // log error + logger.log(Level.SEVERE, null, rfe); + } @@ -587,8 +600,9 @@ g2d.drawImage(biOld, null, 0, 0); } catch (RasterFormatException rfe) { - // TODO fix this error - System.out.println("raster format exception" + rfe.toString()); + + // log error + logger.log(Level.SEVERE, null, rfe); } @@ -682,8 +696,8 @@ g2d.drawImage(biOld, null, 0, 0); } catch (RasterFormatException rfe) { - // TODO fix this error - System.out.println("raster format exception" + rfe.toString()); + /// log error + logger.log(Level.SEVERE, null, rfe); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cm...@us...> - 2009-05-24 01:14:34
|
Revision: 44 http://imagetools.svn.sourceforge.net/imagetools/?rev=44&view=rev Author: cmarcum Date: 2009-05-24 00:26:36 +0000 (Sun, 24 May 2009) Log Message: ----------- comment cleanup 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-05-23 22:40:24 UTC (rev 43) +++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageArea.java 2009-05-24 00:26:36 UTC (rev 44) @@ -300,7 +300,6 @@ // paint selection line - // Draw the selection line if present. if (srcx != destx || srcy != desty) { @@ -400,7 +399,6 @@ private void setupCropMouseListeners() { - // this.removeMouseListener(ml); this.tearDownMouseListeners(); this.ml = new MouseAdapter() { @@ -441,8 +439,6 @@ // Install a mouse motion listener to update the selection rectangle // during drag operations. - - // MouseMotionListener mml; this.mml = new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { @@ -489,7 +485,7 @@ repaint(); } - // TEST to crop on release or fire event + @Override public void mouseReleased(MouseEvent e) { @@ -506,8 +502,7 @@ // 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) { @@ -560,7 +555,6 @@ private void setupLineMouseListeners() { - // this.removeMouseListener(ml); this.tearDownMouseListeners(); this.ml = new MouseAdapter() { @@ -583,7 +577,6 @@ @Override public void mouseReleased(MouseEvent e) { - // BufferedImage bi = (BufferedImage) getImage(); int width = image.getWidth(null); int height = image.getHeight(null); @@ -595,8 +588,7 @@ // 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) { @@ -606,22 +598,14 @@ } - // Original - // Graphics2D g2d = bi.createGraphics(); - // draw the real line g2d.setStroke(bsAnnotate); // g2d.setPaint(gpAnnotate); g2d.setColor(Color.RED); g2d.draw(lineSelection); + setImage(biNew, true); - // this only added to undo using change listener - // after we created a new object - - // setImage(bi); // original - setImage(biNew, true); // new - } }; this.addMouseListener(ml); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |