[Imagetools-commit] SF.net SVN: imagetools:[16] trunk/imagetools/src/net/codebuilders/desktop/ imag
Status: Beta
Brought to you by:
cmarcum
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. |