This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 59527
Collapse All | Expand All

(-)image/src/org/netbeans/modules/image/BitmapAirbrush.java (+64 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.BasicStroke;
6
import java.awt.Point;
7
import java.awt.Shape;
8
9
import java.awt.geom.Ellipse2D;
10
import java.awt.geom.GeneralPath;
11
12
import java.util.Enumeration;
13
14
import java.lang.Math;
15
16
class BitmpapAirbrush extends BitmapTool {
17
    protected GeneralPath brushShape;
18
    Ellipse2D.Float brushArea;
19
    protected int brushSize;
20
    protected int brushSparcity;
21
    
22
    public BitmpapAirbrush(int xVal, int yVal, Color c, int size, int sparcity){
23
        super(xVal, yVal, c);
24
        
25
        brushSize = size;
26
        brushSparcity = sparcity;
27
    }
28
    
29
    public void writeToGraphic(Graphics2D g){
30
        g.setStroke(new BasicStroke(1));
31
        g.setColor(getFillColor());
32
        g.setPaintMode();
33
        
34
        Enumeration e = pathTrace.elements();
35
        Point p = null;
36
        Point l = null;
37
        Point x = null;
38
        
39
        while(e.hasMoreElements()){
40
            p = (Point)e.nextElement();
41
            moveBrush(p);
42
            g.draw(brushShape);
43
        }
44
        
45
        pathTrace.removeAllElements();
46
        if(p != null)    pathTrace.addElement(p);
47
    }
48
    
49
    private void moveBrush(Point p){
50
        brushShape = new GeneralPath();
51
        brushArea = new Ellipse2D.Float(((float)p.x - (brushSize/2)),(float)(p.y - (brushSize/2)), (float)brushSize, (float)brushSize);
52
        
53
        /* Choose random pixils in the area */
54
        int i;
55
        for(i=0; i<Math.abs(brushSparcity); i++){
56
            Point randomPoint = new Point((int)(brushArea.getX() + (Math.random() * brushSize)), (int)(brushArea.getY() + (Math.random() * brushSize)));
57
            while(!brushArea.contains(randomPoint.x, randomPoint.y))
58
                randomPoint = new Point((int)(brushArea.getX() + (Math.random() * brushSize)), (int)(brushArea.getY() + (Math.random() * brushSize)));
59
                
60
            brushShape.moveTo(randomPoint.x, randomPoint.y);
61
            brushShape.lineTo(randomPoint.x, randomPoint.y);
62
        }
63
    }        
64
}
(-)image/src/org/netbeans/modules/image/BitmapFill.java (+106 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Color;
4
import java.awt.image.BufferedImage;
5
import java.awt.Graphics2D;
6
import java.awt.Point;
7
import java.util.Stack;
8
9
/** Implimentation of the Paint Bucket Edit Tool
10
 @author Timothy Boyce */
11
12
class BitmapFill implements EditTool{
13
    
14
    /** The Color of the selected pixel */
15
    int SrcRGBColor;
16
    
17
    /** The color that the pixels will be changed to */
18
    int DstRGBColor;
19
    
20
    /** The image object to edit */
21
    BufferedImage imageObject;
22
    
23
    /** The pixels that are still to be scanned */
24
    Stack pixelStack;
25
    
26
    /** Constructor */
27
    public BitmapFill(int xVal, int yVal, Color c, BufferedImage b){
28
        imageObject = b;
29
        
30
        SrcRGBColor = imageObject.getRGB(xVal, yVal);
31
        DstRGBColor = c.getRGB();
32
        
33
        /* If the Src and Destination color are the same, take no action */
34
        if(SrcRGBColor == DstRGBColor)
35
            return;
36
        
37
        pixelStack = new Stack();
38
        
39
        seedStack(xVal, yVal);
40
    }
41
    
42
    /** Starts the paint action with the specified point */
43
    private void seedStack(int xVal, int yVal){
44
        Point currentPixel;
45
        pixelStack.push(new Point(xVal, yVal));
46
        
47
        try{
48
            while(!pixelStack.empty()){
49
                    currentPixel = (Point)pixelStack.pop();
50
                    setPixel(currentPixel.x, currentPixel.y);
51
            }
52
        } catch (OutOfMemoryError e){
53
            dumpStack();
54
        }
55
    }
56
    
57
    /** Sets the passed pixel to the destination color, 
58
    and checks the surrounding pixels to see if they
59
    should be added to the stack for colouring */
60
    private void setPixel(int xVal, int yVal){
61
        imageObject.setRGB(xVal, yVal, DstRGBColor);
62
63
        /** Push any pixils that surround it that are also the same color
64
        onto the stack to be painted */
65
        if(isValidPoint(xVal + 1, yVal) && SrcRGBColor == imageObject.getRGB(xVal + 1, yVal))
66
            pixelStack.push(new Point(xVal + 1, yVal));
67
        if(isValidPoint(xVal - 1, yVal) && SrcRGBColor == imageObject.getRGB(xVal - 1, yVal))
68
            pixelStack.push(new Point(xVal - 1, yVal));
69
        if(isValidPoint(xVal, yVal + 1) && SrcRGBColor == imageObject.getRGB(xVal, yVal + 1))
70
            pixelStack.push(new Point(xVal, yVal + 1));
71
        if(isValidPoint(xVal, yVal - 1) && SrcRGBColor == imageObject.getRGB(xVal, yVal - 1))
72
            pixelStack.push(new Point(xVal, yVal - 1));
73
    }
74
75
    private boolean isValidPoint(int xVal, int yVal){
76
        return (xVal >= 0 && yVal >= 0 && xVal < imageObject.getWidth() && yVal < imageObject.getHeight());
77
    }
78
    
79
    private void dumpStack(){
80
        while(!pixelStack.empty()){
81
            Point p = (Point)pixelStack.pop();
82
            imageObject.setRGB(p.x, p.y, DstRGBColor);
83
        }
84
    }
85
86
    public void setDragPoint(int xVal, int yVal){
87
    }
88
    
89
    public void setReleasePoint(int xVal, int yVal){
90
    }
91
    
92
    public void setClickPoint(int xVal, int yVal){
93
    }
94
    
95
    /* Return the tool status */
96
    public boolean getToolStatus(){
97
        return true;
98
    }
99
    
100
    public boolean getMemoryless(){
101
        return false;
102
    }
103
    
104
    public void writeToGraphic(Graphics2D g){
105
    }
106
}
(-)image/src/org/netbeans/modules/image/BitmapFreehandBrush.java (+105 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.Point;
6
import java.awt.Shape;
7
import java.awt.Rectangle;
8
import java.awt.BasicStroke;
9
10
import java.awt.geom.Ellipse2D;
11
import java.awt.geom.Line2D;
12
13
import java.util.Enumeration;
14
15
class BitmpapFreehandBrush extends BitmapTool {
16
    protected Shape brushShape;
17
    protected int brushSize;
18
    protected int brushSlant;
19
    protected int brushType;
20
    
21
    public static final int BRUSH_BOX = 1;
22
    public static final int BRUSH_CIRC = 2;
23
    public static final int BRUSH_LINE = 3;
24
    
25
    public static final int SLANT_45 = 1;
26
    public static final int SLANT_135 = 2;
27
28
    public BitmpapFreehandBrush(int xVal, int yVal, Color c, int size){
29
        super(xVal, yVal, c);
30
        
31
        brushSlant = SLANT_45;
32
        brushSize = size;
33
        brushType = BRUSH_BOX;
34
    }
35
36
    public BitmpapFreehandBrush(int xVal, int yVal, Color c, int size, int type){
37
        super(xVal, yVal, c);
38
        
39
        brushSlant = SLANT_45;
40
        brushSize = size;
41
        brushType = type;
42
    }
43
44
    public BitmpapFreehandBrush(int xVal, int yVal, Color c, int size, int type, int slant){
45
        super(xVal, yVal, c);
46
        
47
        brushSlant = slant;
48
        brushSize = size;
49
        brushType = type;
50
    }
51
    
52
    public void writeToGraphic(Graphics2D g){
53
        g.setStroke(new BasicStroke(1));
54
        g.setColor(getFillColor());
55
        g.setPaintMode();
56
        
57
        Enumeration e = pathTrace.elements();
58
        Point p = null;
59
        Point l = null;
60
        Point x = null;
61
        
62
        while(e.hasMoreElements()){
63
            p = (Point)e.nextElement();
64
            
65
            Enumeration subPoints = joinPoints(p, l).elements();
66
            
67
            while(subPoints.hasMoreElements()){
68
                x = (Point)subPoints.nextElement();
69
                moveBrush(x);
70
                g.fill(brushShape);
71
                g.draw(brushShape);
72
            }
73
            
74
            l = new Point(p.x, p.y);
75
        }
76
        
77
        pathTrace.removeAllElements();
78
        if(p != null)    pathTrace.addElement(p);
79
    }
80
    
81
    private void moveBrush(Point p){
82
        switch(brushType){
83
            case BRUSH_BOX:
84
                brushShape = new Rectangle(p.x - (brushSize/2), p.y - (brushSize/2), brushSize, brushSize);
85
            return;
86
            
87
            case BRUSH_CIRC:
88
                brushShape = new Ellipse2D.Float(((float)p.x - (brushSize/2)),(float)(p.y - (brushSize/2)), (float)brushSize, (float)brushSize);
89
            return;
90
            
91
            case BRUSH_LINE:
92
                BasicStroke b = new BasicStroke(2);
93
                if(brushSlant == SLANT_135)
94
                    brushShape = b.createStrokedShape(new Line2D.Float((float)(p.x - brushSize/2), (float)(p.y - brushSize/2), (float)(p.x + brushSize/2), (float)(p.y + brushSize/2)));
95
                else
96
                    brushShape = b.createStrokedShape(new Line2D.Float((float)(p.x + brushSize/2), (float)(p.y - brushSize/2), (float)(p.x - brushSize/2), (float)(p.y + brushSize/2)));
97
            return;
98
            
99
            default:
100
                brushType = BRUSH_BOX;
101
                brushShape = new Rectangle(p.x - (brushSize/2), p.y - (brushSize/2), brushSize, brushSize);
102
            return;
103
        }
104
    }
105
}
(-)image/src/org/netbeans/modules/image/BitmapFreehandLine.java (+88 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Graphics2D;
4
import java.awt.BasicStroke;
5
import java.awt.Point;
6
import java.awt.Color;
7
import java.awt.geom.GeneralPath;
8
import java.util.Vector;
9
10
/** Implimentation of the Pencil Edit Tool
11
 @author Timothy Boyce */
12
class BitmapFreehandLine implements EditTool{
13
14
	/** Vector containing the last 3 points of the freehand line */
15
    protected Vector linePoints = new Vector(){
16
        public void addElement(Object obj){
17
            if(this.size() >= 3)
18
                this.removeElementAt(0);
19
            super.addElement(obj);
20
        }
21
    };
22
    
23
    /** General Path used for drawing */
24
    protected GeneralPath linePath;    
25
    
26
    /** Line Color used */
27
    protected Color lineColor;
28
    
29
    /** Tool status boolean */
30
    protected boolean toolStatus = false;
31
    
32
    /** Use the default super class constructior */
33
    public BitmapFreehandLine(int xVal, int yVal, Color c){
34
        linePoints.addElement(new Point(xVal, yVal));
35
        lineColor = c;
36
    }
37
    
38
    public boolean getToolStatus(){
39
        return toolStatus;
40
    }
41
    
42
    public boolean getMemoryless(){
43
        return true;
44
    }
45
    
46
    public void setDragPoint(int xVal, int yVal){
47
        linePoints.addElement(new Point(xVal, yVal));
48
    }
49
    
50
    public void setClickPoint(int xVal, int yVal){
51
        linePoints.addElement(new Point(xVal, yVal));
52
    }
53
    
54
    public void setReleasePoint(int xVal, int yVal){
55
        linePoints.addElement(new Point(xVal, yVal));
56
        toolStatus = true;
57
    }
58
    
59
    
60
    public void writeToGraphic(Graphics2D g){
61
        Point p1, p2, p3;
62
        
63
        g.setStroke(new BasicStroke(1));
64
        g.setPaintMode();
65
        g.setColor(lineColor);
66
        
67
        linePath = new GeneralPath();
68
        
69
        p1 = (Point)linePoints.firstElement();
70
        linePath.moveTo(p1.x, p1.y);
71
        
72
        if(linePoints.size() == 3)
73
            p2 = (Point)linePoints.get(1);
74
        else
75
            p2 = (Point)linePoints.lastElement();
76
        
77
        linePath.lineTo(p2.x, p2.y);
78
        
79
        if(linePoints.size()  == 2)
80
            p3 = (Point)linePoints.firstElement();
81
        else
82
            p3 = (Point)linePoints.lastElement();
83
            
84
        linePath.lineTo(p3.x, p3.y);
85
        
86
        g.draw(linePath);
87
    }
88
}
(-)image/src/org/netbeans/modules/image/BitmapTool.java (+107 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.Point;
6
7
import java.util.Vector;
8
9
import java.lang.Math;
10
11
abstract class BitmapTool implements EditTool{
12
    protected Color fillColor;
13
    protected Vector pathTrace;
14
    
15
    protected boolean toolStatus = false;
16
    
17
    public BitmapTool(int xVal, int yVal, Color c){
18
        pathTrace = new Vector();
19
        pathTrace.addElement(new Point(xVal, yVal));
20
        
21
        fillColor = c;
22
    }
23
    
24
    public void setDragPoint(int xVal, int yVal){
25
        pathTrace.addElement(new Point(xVal, yVal));
26
    }
27
    
28
    /* Default action taken on a release */
29
    public void setReleasePoint(int xVal, int yVal){
30
        pathTrace.addElement(new Point(xVal, yVal));
31
        toolStatus = true;
32
    }
33
    
34
    /* Default action taken on a Click */
35
    public void setClickPoint(int xVal, int yVal){
36
    }
37
    
38
    /* Return the tool status */
39
    public boolean getToolStatus(){
40
        return toolStatus;
41
    }
42
    
43
    protected Color getFillColor(){
44
        return fillColor;
45
    }
46
    
47
    public boolean getMemoryless(){
48
        return true;
49
    }
50
    
51
    /* Writes the current tool to the graphis object */
52
    public abstract void writeToGraphic(Graphics2D g);
53
    
54
    protected Vector joinPoints(Point p1, Point p2){
55
        Point start, end;
56
        Vector subPath = new Vector();
57
        float m;
58
        int b;
59
        int tx, ty;
60
        
61
        if(p1 == null)
62
            return subPath;
63
        
64
        if(p2 == null){
65
            subPath.addElement(p1);
66
            return subPath;
67
        }
68
        
69
        if(p1.x - p2.x == 0){
70
            /* Vertical Line */
71
            start = (p1.y < p2.y) ? p1 : p2;
72
            end = (p1.y > p2.y) ? p1 : p2;
73
            tx = start.x;
74
            
75
            for(ty=start.y+1; ty<end.y; ty++){
76
                subPath.addElement(new Point(tx, ty));
77
            }
78
        }
79
        else{
80
            /* Calculate Garidient */
81
            m = (float)(p1.y - p2.y) / (float)(p1.x - p2.x);
82
            b = (int)(p1.y - m * p1.x); 
83
            
84
            if(Math.abs(m) > 1){
85
                /* Use Y Method */
86
                start = (p1.y < p2.y) ? p1 : p2;
87
                end = (p1.y > p2.y) ? p1 : p2;
88
                
89
                for(ty=start.y+1; ty<end.y; ty++){
90
                    tx = (int)((ty - b)/ m );
91
                    subPath.addElement(new Point(tx, ty));
92
                }
93
            }
94
            else{
95
                /* Use X Method */
96
                start = (p1.x < p2.x) ? p1 : p2;
97
                end = (p1.x > p2.x) ? p1 : p2;
98
                
99
                for(tx=start.x+1; tx<end.x; tx++){
100
                    ty = (int)(m * tx + b);
101
                    subPath.addElement(new Point(tx, ty));
102
                }
103
            }
104
        }
105
        return subPath;
106
    }
107
}
(-)image/src/org/netbeans/modules/image/Bundle.properties (+39 lines)
Lines 13-18 Link Here
13
PROP_ImageLoader_Name=Image Objects
13
PROP_ImageLoader_Name=Image Objects
14
Services/MIMEResolver/org-netbeans-modules-image-mime-resolver.xml=Image Files
14
Services/MIMEResolver/org-netbeans-modules-image-mime-resolver.xml=Image Files
15
15
16
# Filenames
17
Templates/Other/Image/png.png=PNG File
18
Templates/Other/Image/jpeg.jpeg=JPEG File
19
16
# ImageDataObject.ImageNode
20
# ImageDataObject.ImageNode
17
HINT_Thumbnail=Shows thumbnail.
21
HINT_Thumbnail=Shows thumbnail.
18
PROP_Thumbnail=Thumbnail
22
PROP_Thumbnail=Thumbnail
Lines 20-25 Link Here
20
# Failure to load an image
24
# Failure to load an image
21
MSG_CouldNotLoad=Could not load the image
25
MSG_CouldNotLoad=Could not load the image
22
MSG_ErrorWhileLoading=Error while loading the image (corrupted image?)
26
MSG_ErrorWhileLoading=Error while loading the image (corrupted image?)
27
# Save Image
28
LBL_CompressionLevel=Compression Level
29
MSG_CompressionLevel=Select a compression level:
30
# Convert Image
31
LBL_Format=Format
32
MSG_Format=Select a format:
33
LBL_CouldNotConvert=Convert Error
34
MSG_CouldNotConvert=Could not convert the image
35
36
# Failure to save an image
37
MSG_UserAbortSave=User aborted saving of file {0}
38
LBL_NoSaveSupport=No Save Support
39
MSG_NoSaveSupportConfirm=There is currently no save support for {0} type.\nWould you like to convert to a different format?
40
MSG_NoSaveSupport=There is currently no save support for {0} type
23
# External change happened.
41
# External change happened.
24
MSG_ExternalChange=The file {0} was modified externally. Reload it?
42
MSG_ExternalChange=The file {0} was modified externally. Reload it?
25
43
Lines 31-36 Link Here
31
LBL_EnlargeFactor_Mnem=E
49
LBL_EnlargeFactor_Mnem=E
32
LBL_DecreaseFactor=Decrease Factor:
50
LBL_DecreaseFactor=Decrease Factor:
33
LBL_DecreaseFactor_Mnem=D
51
LBL_DecreaseFactor_Mnem=D
52
LBL_ConvertTo=Con&vert To...
53
54
# Tool labels
55
LBL_Ellipse=Ellipse
56
LBL_Rectangle=Rectangle
57
LBL_Fill=Fill
58
LBL_Line=Line
59
LBL_Select=Select
60
LBL_Polygon=Polygon
61
LBL_Pen=Pen
62
LBL_Brush=Brush
63
LBL_Arc=Arc
64
LBL_Spray=Spray
65
LBL_SetLineColor=Set Line Color
66
LBL_SetFillColor=Set Fill Color
67
68
# ColorChooser Labels
69
LBL_ForegroundColor=Choose Foreground Color
70
LBL_BackgroundColor=Choose Background Color
34
71
35
# Show/Hide grid action label
72
# Show/Hide grid action label
36
LBL_ShowHideGrid=Toggle grid
73
LBL_ShowHideGrid=Toggle grid
Lines 54-59 Link Here
54
ACSD_Toolbar=N/A
91
ACSD_Toolbar=N/A
55
92
56
ACSN_Toolbar=Zoom Toolbar
93
ACSN_Toolbar=Zoom Toolbar
94
95
ACSN_EditToolbar=Edit Toolbar
57
96
58
ACS_Grid_BTN=N/A
97
ACS_Grid_BTN=N/A
59
98
(-)image/src/org/netbeans/modules/image/ConvertToAction.java (+44 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.io.IOException;
4
5
import org.openide.util.actions.CallableSystemAction;
6
import org.openide.util.HelpCtx;
7
import org.openide.windows.TopComponent;
8
import org.openide.util.NbBundle;
9
10
11
/**
12
 * Action which converts an image to a different format.
13
 *
14
 * @author  Jason Solomon
15
 */
16
public class ConvertToAction extends CallableSystemAction {
17
18
    public void performAction() {
19
        TopComponent curComponent = TopComponent.getRegistry().getActivated();
20
        if(curComponent instanceof ImageViewer) {
21
            ImageViewer currComponent = (ImageViewer) TopComponent.getRegistry().getActivated();
22
            currComponent.convertTo();
23
        }
24
    }
25
26
    /** Gets name of action. Implements superclass abstract method. */
27
    public String getName() {
28
        return NbBundle.getBundle(ConvertToAction.class).getString("LBL_ConvertTo");
29
    }
30
31
    /** Gets help context for action. Implements superclass abstract method. */
32
    public org.openide.util.HelpCtx getHelpCtx() {
33
        return HelpCtx.DEFAULT_HELP;
34
    }
35
36
    /** Overrides superclass method. */
37
    public boolean isEnabled() {
38
        TopComponent curComponent = TopComponent.getRegistry().getActivated();
39
        if(curComponent instanceof ImageViewer)
40
            return true;
41
        else
42
            return false;
43
    }
44
}
(-)image/src/org/netbeans/modules/image/EditTool.java (+12 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Graphics2D;
4
5
interface EditTool {
6
    public void setDragPoint(int xVal, int yVal);
7
    public void setClickPoint(int xVal, int yVal);
8
    public void setReleasePoint(int xVal, int yVal);
9
    public boolean getToolStatus();
10
    public boolean getMemoryless();
11
    public void writeToGraphic(Graphics2D g);
12
}
(-)image/src/org/netbeans/modules/image/ImageDataObject.java (-3 / +149 lines)
Lines 15-35 Link Here
15
package org.netbeans.modules.image;
15
package org.netbeans.modules.image;
16
16
17
17
18
import java.awt.Component;
18
import java.awt.Graphics;
19
import java.awt.Graphics;
19
import java.awt.Image;
20
import java.awt.Image;
21
import java.awt.image.BufferedImage;
22
import java.awt.image.RenderedImage;
20
import java.awt.Rectangle;
23
import java.awt.Rectangle;
21
import java.beans.PropertyEditor;
24
import java.beans.PropertyEditor;
22
import java.beans.PropertyEditorSupport;
25
import java.beans.PropertyEditorSupport;
23
import java.io.BufferedInputStream;
26
import java.io.BufferedInputStream;
27
import java.io.File;
24
import java.io.IOException;
28
import java.io.IOException;
25
import java.lang.reflect.InvocationTargetException;
29
import java.lang.reflect.InvocationTargetException;
26
import java.net.URL;
30
import java.net.URL;
31
import java.util.Iterator;
32
import java.util.Observable;
33
import java.util.Observer;
34
import javax.imageio.ImageIO;
35
import javax.imageio.ImageWriter;
36
import javax.imageio.stream.FileImageOutputStream;
27
import javax.swing.Icon;
37
import javax.swing.Icon;
28
import javax.swing.ImageIcon;
38
import javax.swing.ImageIcon;
39
import javax.swing.JFileChooser;
40
import javax.swing.JOptionPane;
41
import javax.swing.SwingUtilities;
29
42
30
import org.openide.actions.OpenAction;
43
import org.openide.actions.OpenAction;
44
import org.openide.actions.SaveAction;
45
import org.openide.cookies.OpenCookie;
31
import org.openide.filesystems.FileObject;
46
import org.openide.filesystems.FileObject;
32
import org.openide.filesystems.FileStateInvalidException;
47
import org.openide.filesystems.FileStateInvalidException;
48
import org.openide.filesystems.FileUtil;
33
import org.openide.loaders.*;
49
import org.openide.loaders.*;
34
import org.openide.nodes.*;
50
import org.openide.nodes.*;
35
import org.openide.ErrorManager;
51
import org.openide.ErrorManager;
Lines 43-49 Link Here
43
 * @author Petr Hamernik, Jaroslav Tulach, Ian Formanek, Michael Wever
59
 * @author Petr Hamernik, Jaroslav Tulach, Ian Formanek, Michael Wever
44
 * @author  Marian Petras
60
 * @author  Marian Petras
45
 */
61
 */
46
public class ImageDataObject extends MultiDataObject implements CookieSet.Factory {
62
public class ImageDataObject extends MultiDataObject implements CookieSet.Factory, Observer {
47
    
63
    
48
    /** Generated serialized version UID. */
64
    /** Generated serialized version UID. */
49
    static final long serialVersionUID = -6035788991669336965L;
65
    static final long serialVersionUID = -6035788991669336965L;
Lines 51-60 Link Here
51
    /** Base for image resource. */
67
    /** Base for image resource. */
52
    private static final String IMAGE_ICON_BASE = "org/netbeans/modules/image/imageObject"; // NOI18N
68
    private static final String IMAGE_ICON_BASE = "org/netbeans/modules/image/imageObject"; // NOI18N
53
    
69
    
70
    /** Image held in DataObject **/
71
    private Image image;
72
    
73
    /** Subclass of java.util.Observable */
74
    private ObservableImage obs = new ObservableImage();
75
    
54
    /** Open support for this image data object. */
76
    /** Open support for this image data object. */
55
    private transient ImageOpenSupport openSupport;
77
    private transient ImageOpenSupport openSupport;
56
    /** Print support for this image data object **/
78
    /** Print support for this image data object **/
57
    private transient ImagePrintSupport printSupport;
79
    private transient ImagePrintSupport printSupport;
80
    /** Save support for this image data object **/
81
    private transient ImageSaveSupport saveSupport;
58
 
82
 
59
    /** Constructor.
83
    /** Constructor.
60
     * @param pf primary file object for this data object
84
     * @param pf primary file object for this data object
Lines 75-80 Link Here
75
            return getOpenSupport();
99
            return getOpenSupport();
76
        else if( clazz.isAssignableFrom(ImagePrintSupport.class))
100
        else if( clazz.isAssignableFrom(ImagePrintSupport.class))
77
            return getPrintSupport();        
101
            return getPrintSupport();        
102
        else if( clazz.isAssignableFrom(ImageSaveSupport.class))
103
            return getSaveSupport();
78
        else
104
        else
79
            return null;
105
            return null;
80
    }
106
    }
Lines 101-106 Link Here
101
        return printSupport;
127
        return printSupport;
102
    }
128
    }
103
    
129
    
130
    /** Gets image save support. */
131
    private ImageSaveSupport getSaveSupport() {
132
        if(saveSupport == null) {
133
            synchronized(this) {
134
                if(saveSupport == null)
135
                    saveSupport = new ImageSaveSupport( this );
136
            }
137
        }
138
        return saveSupport;
139
    }
140
    
141
    /** Adds save cookie and sets the modified flag. */
142
    protected void notifyModified() {
143
        String asterisk = new String(" *");
144
        
145
        getNodeDelegate().setDisplayName(getPrimaryFile().getNameExt() + asterisk);
146
        addSaveCookie();
147
        setModified(true);
148
    }
149
    
150
    /** Removes save cookie and unsets the modified flag. */
151
    protected void notifyUnmodified () {
152
        getNodeDelegate().setDisplayName(getPrimaryFile().getNameExt());
153
        removeSaveCookie();
154
        setModified(false);
155
        obs.setChanged();
156
        obs.notifyObservers();
157
    }
158
    
159
    /** Helper method. Adds save cookie to the data object. */
160
    private void addSaveCookie() {
161
        if(getCookie(ImageSaveSupport.class) == null) {
162
            getCookieSet().add(ImageSaveSupport.class, this);
163
        }
164
    }
165
    
166
    /** Helper method. Removes save cookie from the data object. */
167
    private void removeSaveCookie() {
168
        if(getCookie(ImageSaveSupport.class) != null) {
169
            getCookieSet().remove(ImageSaveSupport.class, this);
170
        }
171
    }
172
173
    /** Getter of the full path of the image file. */
174
    public String getPath() {
175
        return getPrimaryFile().getPath();
176
    }
177
178
    /** Getter of the file extension. */
179
    public String getFormat() {
180
        return getPrimaryFile().getExt().toLowerCase();
181
    }
182
183
    /** Adds Observer o to ObservableImage obs */
184
    public void addObserver(Observer o) {
185
        obs.addObserver(o);
186
    }
187
    
104
    /** Help context for this object.
188
    /** Help context for this object.
105
     * @return the help context
189
     * @return the help context
106
     */
190
     */
Lines 136-148 Link Here
136
        }
220
        }
137
    }
221
    }
138
222
223
    /** Clears the stored image and reloads it from the file */
224
    public Image reloadImage() throws IOException {
225
        image = null;
226
        return getImage();
227
    }
228
139
    // Michael Wever 26/09/2001
229
    // Michael Wever 26/09/2001
140
    /** Gets image for the image data 
230
    /** Gets image for the image data 
141
     * @return the image or <code>null</code> if image could not be created
231
     * @return the image
142
     * @return  java.io.IOException  if an error occurs during reading
232
     * @return  java.io.IOException  if an error occurs during reading
143
     */
233
     */
144
    public Image getImage() throws IOException {
234
    public Image getImage() throws IOException {
145
        return javax.imageio.ImageIO.read(getPrimaryFile().getInputStream());
235
        if(image == null) {
236
            image = javax.imageio.ImageIO.read(getPrimaryFile().getInputStream());
237
        }
238
        return image;
146
    }
239
    }
147
240
148
241
Lines 269-273 Link Here
269
            } // End of class ThumbnailPropertyEditor.
362
            } // End of class ThumbnailPropertyEditor.
270
        } // End of class ThumbnailProperty.
363
        } // End of class ThumbnailProperty.
271
    } // End of class ImageNode.
364
    } // End of class ImageNode.
365
366
    public void update(Observable o, Object arg) {
367
        notifyModified();
368
    }
369
370
    protected void convertTo(final ImageViewer thisViewer) throws IOException {
371
        String bName = getNodeDelegate().getName();
372
        String ext;
373
        String dialogTitle = new String(NbBundle.getMessage(ImageDataObject.class, "LBL_Format"));
374
        String dialogLabel = new String(NbBundle.getMessage(ImageDataObject.class, "MSG_Format"));
375
        String writerTypes[] = ImageIO.getWriterFormatNames();
376
        
377
        ext = (String)JOptionPane.showInputDialog((Component)null, dialogLabel,
378
            dialogTitle, JOptionPane.QUESTION_MESSAGE, null, writerTypes, writerTypes[0]);
379
        
380
        if(ext != null) {
381
            File newFile =  new File(getPrimaryFile().getParent().getPath() + "/" + bName + "." + ext);
382
            BufferedImage newImage = new BufferedImage(((BufferedImage)image).getWidth(), ((BufferedImage)image).getHeight(), BufferedImage.TYPE_INT_RGB);
383
            Graphics g = newImage.getGraphics();
384
            g.drawImage(image, 0, 0, null);
385
            Iterator writers = ImageIO.getImageWritersByFormatName(ext);
386
            ImageWriter writer = (ImageWriter)writers.next();
387
            FileImageOutputStream    output = new FileImageOutputStream(newFile);
388
            writer.setOutput(output);
389
            writer.write((RenderedImage)newImage);
390
            FileObject pf = FileUtil.toFileObject(newFile);
391
            ImageDataObject newIDO = (ImageDataObject)DataObject.find(pf);
392
            final OpenCookie openCookie = (OpenCookie)newIDO.getCookie(OpenCookie.class);
393
            if (openCookie == null) {
394
                // cannot open
395
                throw new IOException(NbBundle.getMessage(ImageDataObject.class, "MSG_CouldNotConvert"));
396
            }
397
            else {
398
                if(!SwingUtilities.isEventDispatchThread()) {
399
                    Runnable doOpenClose = new Runnable() {
400
                        public void run() {
401
                            openCookie.open();
402
                            thisViewer.close();
403
                        }
404
                    };
405
                    try {
406
                        SwingUtilities.invokeAndWait(doOpenClose);
407
                    } catch(Exception e) {
408
                        JOptionPane.showMessageDialog(null, NbBundle.getMessage(ImageDataObject.class, "MSG_CouldNotConvert"), NbBundle.getMessage(ImageDataObject.class, "LBL_CouldNotConvert"), JOptionPane.ERROR_MESSAGE);
409
                    }
410
                }
411
                else {
412
                    openCookie.open();
413
                    thisViewer.close();
414
                }
415
            }
416
        }
417
    }
272
418
273
}
419
}
(-)image/src/org/netbeans/modules/image/ImageDisplayEdit.java (+348 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.event.MouseAdapter;
4
import java.awt.event.MouseMotionAdapter;
5
import java.awt.event.MouseEvent;
6
import java.awt.Color;
7
import java.awt.Cursor;
8
import java.awt.Graphics;
9
import java.awt.Graphics2D;
10
import java.awt.image.BufferedImage;
11
import java.awt.geom.AffineTransform;
12
import java.awt.AlphaComposite;
13
import java.awt.image.WritableRaster;
14
import javax.swing.JPanel;
15
import java.util.Observable;
16
import java.io.IOException;
17
18
import org.openide.windows.TopComponent;
19
20
21
/** Implimentation of the Paint Bucket Edit Tool
22
 @author Timothy Boyce */
23
class ImageDisplayEdit extends JPanel{
24
	
25
    /** Currently selected editTool object */
26
    private EditTool currentTool;
27
    
28
    /** Offscreen Image Objects */
29
    protected BufferedImage offScreenImage;
30
    
31
    /** Double buffer used for memoryless edit tools */
32
    protected BufferedImage memOScreenImage;
33
    
34
    /** Double buffer user for non-memoryless edit tools */
35
    protected BufferedImage nonOScreenImage;
36
    
37
    /** Primary Image Object */
38
    private BufferedImage imageObject;
39
    
40
    /** Boolean flag to ingore left clicks of the mouse */
41
    private boolean ignoreButton1 = false;
42
    
43
    /** The current scale that the image is being viewed at */
44
    private double currentScale;
45
    
46
    /** On/Off Grid */
47
    private boolean showGrid = false;
48
    
49
    /** Grid color. */
50
    private final Color gridColor = Color.black;
51
    
52
    /** The primary or foreground color, defaulted to black */
53
    private Color primary = new Color(0, 0, 0);
54
    
55
    /** The secondary, background, or fill colour, defaulted to white */
56
    private Color secondary = new Color(128, 128, 255);
57
    
58
    /** Mouse pointer to be used in the image editor */
59
    private Cursor editCursor = new Cursor(Cursor.CROSSHAIR_CURSOR);
60
    
61
    /** Image Observer Object */
62
    private ObservableImage obs = new ObservableImage();
63
    
64
    /* Line width for vector tools */
65
    private int lineWidth;
66
       
67
    /* Fill type for the rectangle and ellipse tools */
68
    private int fillType;
69
        
70
    /* Tool selected */
71
    private int toolSelected;
72
    
73
    /* Primary color based on the rectangle type */
74
    private Color prim;
75
        
76
    /* Secondary color based on the rectangle type */        
77
    private Color sec;
78
        
79
    /* Corner rounding factor for the rectangle */
80
    private int cornerRoundingFactor;
81
    
82
    /** Class constructor
83
        sets current scale, gets acces to storedImage, and adds various
84
        action listeners */
85
    ImageDisplayEdit(NBImageIcon storedImage, double imageScale){
86
        currentScale = imageScale;
87
        
88
        imageObject = (BufferedImage)storedImage.getImage();
89
        
90
        nonOScreenImage = new BufferedImage(imageObject.getColorModel(), (WritableRaster)imageObject.getData(), false, null);
91
        memOScreenImage = new BufferedImage(imageObject.getWidth(), imageObject.getHeight(), BufferedImage.TYPE_INT_ARGB);
92
        
93
        
94
        this.addMouseListener(new MouseAdapter(){
95
            public void mouseEntered(MouseEvent thisEvent){
96
                setCursor(editCursor);
97
            }
98
        
99
            /** Set the mouse pressed event to create a new edit tool object
100
            and setup correct imag buffers */
101
            public void mousePressed(MouseEvent thisEvent){
102
                if(currentTool == null 
103
                && thisEvent.getButton() == MouseEvent.BUTTON1
104
                && getScaledValue(thisEvent.getX(), currentScale) < imageObject.getWidth()
105
                && getScaledValue(thisEvent.getY(), currentScale) < imageObject.getHeight()
106
                )
107
                {
108
                    int sx = getScaledValue(thisEvent.getX(), currentScale);
109
                    int sy = getScaledValue(thisEvent.getY(), currentScale);
110
                    ignoreButton1 = false;
111
                    
112
                    TopComponent curComponent = TopComponent.getRegistry().getActivated();
113
114
                    /*
115
                        BTN_Select=1
116
                        BTN_Polygon=2
117
                        BTN_Pen=3
118
                        BTN_Brush=4
119
                        BTN_Arc=5
120
                        BTN_Line=6
121
                        BTN_Rectangle=7
122
                        BTN_Ellipse=8
123
                        BTN_Fill=9
124
                        BTN_Spray=10
125
                    */                                        
126
                    /* Switch Here */   
127
                    toolSelected = ((ImageViewer) curComponent).getTool();
128
                    lineWidth = ((ImageViewer) curComponent).getLineWidth();
129
                    fillType = ((ImageViewer) curComponent).getFillType();
130
                    cornerRoundingFactor = ((ImageViewer) curComponent).getCornerRoundingFactor();                                        
131
                    
132
                    switch (fillType){
133
                        case 1: prim = primary; sec = null; break;
134
                        case 2: prim = primary; sec = secondary; break;
135
                        case 3: prim = null; sec = secondary; break;
136
                    }       
137
                    
138
                    switch (toolSelected){
139
                        case 1: currentTool = null; break;
140
                        case 2: currentTool = new VectorPolygon(sx, sy, primary, lineWidth, VectorPolygon.FREEHAND_POLY); break;
141
                        case 3: currentTool = new BitmapFreehandLine(sx, sy, primary); break;
142
                        case 4: currentTool = new BitmpapFreehandBrush(sx, sy, primary, 1, 1); break;
143
                        case 5: currentTool = new VectorArc(sx, sy, primary, lineWidth); break;
144
                        case 6: currentTool = new VectorLine(sx, sy, primary, lineWidth); break;
145
                        case 7: currentTool = new VectorRectangle(sx, sy, prim, sec, lineWidth, cornerRoundingFactor); break;
146
                        case 8: currentTool = new VectorEllipse(sx, sy, prim, sec, lineWidth); break;
147
                        case 9: currentTool = new BitmapFill(sx, sy, primary, imageObject); break;
148
                        case 10: currentTool = new BitmpapAirbrush(sx, sy, primary, 70, 40); break;
149
                        case 11: currentTool = new VectorRectangle(sx, sy, primary, null, 10, 10); break;
150
                    }
151
                    /* End Switch */
152
153
                    /* Setup memoryless or non-memoryless buffer */
154
                    offScreenImage = (currentTool != null && currentTool.getMemoryless())  ? nonOScreenImage : memOScreenImage;
155
                    repaint(0, 0, getWidth(), getHeight());
156
                }
157
                else if(currentTool != null && thisEvent.getButton() == MouseEvent.BUTTON3){
158
                    nonOScreenImage.setData(imageObject.getData());
159
                }
160
            }
161
            
162
            /** If an edit tool is in use, send it the mouse released event, and let it
163
            take actions, as are appropriate for it */
164
            public void mouseReleased(MouseEvent thisEvent){
165
                if(currentTool != null && thisEvent.getButton() == MouseEvent.BUTTON1){
166
                    int sx = getScaledValue(thisEvent.getX(), currentScale);
167
                    int sy = getScaledValue(thisEvent.getY(), currentScale);
168
                    
169
                    currentTool.setReleasePoint(sx, sy);
170
     
171
                    repaint(0, 0, getWidth(), getHeight());
172
                }
173
                if(thisEvent.getButton() == MouseEvent.BUTTON3){
174
                    currentTool = null;
175
                    repaint(0, 0, getWidth(), getHeight());
176
                }
177
            }
178
            
179
            public void mouseClicked(MouseEvent thisEvent){
180
                if(currentTool != null && thisEvent.getButton() == MouseEvent.BUTTON1){
181
                    int sx = getScaledValue(thisEvent.getX(), currentScale);
182
                    int sy = getScaledValue(thisEvent.getY(), currentScale);
183
                    
184
                    currentTool.setClickPoint(sx, sy);
185
                    
186
                    repaint(0, 0, getWidth(), getHeight());
187
                }
188
            }
189
        });
190
            
191
        this.addMouseMotionListener(new MouseMotionAdapter(){
192
            public void mouseDragged(MouseEvent thisEvent){
193
                if(currentTool != null && (thisEvent.getButton() == MouseEvent.BUTTON1 || thisEvent.getButton() == MouseEvent.NOBUTTON)){
194
                    int sx = getScaledValue(thisEvent.getX(), currentScale);
195
                    int sy = getScaledValue(thisEvent.getY(), currentScale);
196
                    
197
                    currentTool.setDragPoint(sx, sy);
198
                    repaint(0, 0, getWidth(), getHeight());
199
                }
200
            }
201
        });
202
203
        obs.addObserver(storedImage.getIDO());
204
    }
205
    
206
    /** Toggle the grid on and off */
207
    public void toggleGrid(){
208
        showGrid = !showGrid;
209
    }
210
    
211
    public void setPrimaryColor(Color newColor){
212
        primary = newColor;
213
    }
214
    
215
    public void setSecondayColor(Color newColor){
216
        secondary = newColor;
217
    }
218
    
219
    public void setCursor(int CursorType){
220
        /* Set the cursor for the tool here */
221
    };
222
    
223
    /** Set the scaling factor of the image */
224
    public void setScale(double newScale){
225
        this.currentScale = newScale;
226
        repaint(0, 0, getHeight(), getWidth());
227
    };
228
    
229
    public double getScale(){
230
        return currentScale;    
231
    }
232
    
233
    /* Return the pixel value after applying the current
234
    zoom scale */
235
    protected int getScaledValue(int value, double scale){
236
        return (int)(value/scale);
237
    }
238
239
    public void paint(Graphics g){
240
        /** Paint the component before anything else occurs */
241
        this.paintComponent(g);
242
        
243
        Graphics2D g2D = (Graphics2D)g;
244
        
245
        if (getSize().width <= 0 || getSize().height <= 0) 
246
        return; 
247
248
        /** Draw this edit tool if the is one in use */     
249
      if(currentTool != null){
250
           Graphics2D offScreenGraphics = (Graphics2D)offScreenImage.getGraphics();
251
           AffineTransform oldTransform = g2D.getTransform();
252
           g2D.transform(AffineTransform.getScaleInstance(currentScale, currentScale));
253
           
254
           /** Drawing method for non-memoryless tools */
255
        if(!currentTool.getMemoryless()){    
256
            currentTool.writeToGraphic(offScreenGraphics);
257
            
258
            g2D.drawImage(offScreenImage, 0, 0, null);
259
            
260
            offScreenGraphics.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0));
261
            offScreenGraphics.fillRect(0, 0, offScreenImage.getWidth(), offScreenImage.getHeight());
262
            
263
            if(currentTool.getToolStatus()){
264
                    currentTool.writeToGraphic((Graphics2D)imageObject.getGraphics());
265
                    nonOScreenImage.setData(imageObject.getData());
266
                    currentTool = null;
267
                    obs.setChanged();
268
                    obs.notifyObservers();
269
                }
270
        }
271
        else{
272
        /** Drawing method for memoryless tools */
273
            currentTool.writeToGraphic(offScreenGraphics);
274
            
275
            g2D.drawImage(offScreenImage,
276
              0,
277
              0,
278
              (int)(imageObject.getWidth()),
279
              (int)(imageObject.getHeight()),
280
              0,
281
              0,
282
              imageObject.getWidth(),
283
              imageObject.getHeight(),
284
              this
285
            );
286
            
287
            if(currentTool.getToolStatus()){
288
                imageObject.setData(offScreenImage.getData());
289
                currentTool = null;
290
                obs.setChanged();
291
                obs.notifyObservers();
292
            }     
293
        }    
294
        g2D.setTransform(oldTransform);
295
    }
296
    
297
    /* Draw the grid onto the screen, if it is visable */
298
    if(showGrid)
299
        drawGrid(g, imageObject.getWidth(), imageObject.getHeight());    
300
     }
301
     
302
     /** Paint the currently visable, unedited image to the component */
303
     public void paintComponent(Graphics g) {
304
      super.paintComponent(g);
305
      g.drawImage(
306
          imageObject,
307
          0,
308
          0,
309
          (int)(getScale() * imageObject.getWidth()),
310
          (int)(getScale() *imageObject.getHeight()),
311
          0,
312
          0,
313
          imageObject.getWidth(),
314
          imageObject.getHeight(),
315
          this
316
      );
317
    }
318
    
319
    /** Attempt to draw a grid to the graphics object */
320
    private void drawGrid(Graphics g, int iconWidth, int iconHeight){
321
      int x = (int)(getScale () * iconWidth);
322
      int y = (int)(getScale () * iconHeight);
323
324
      double gridDistance = getScale();
325
326
      if(gridDistance < 2) 
327
        // Disable painting of grid if no image pixels would be visible.
328
        return;
329
330
      g.setColor(gridColor);
331
332
      double actualDistance = gridDistance;
333
      for(int i = (int)actualDistance; i < x ;actualDistance += gridDistance, i = (int)actualDistance) {
334
          g.drawLine(i,0,i,(y-1));
335
      }
336
337
      actualDistance = gridDistance;
338
      for(int j = (int)actualDistance; j < y; actualDistance += gridDistance, j = (int)actualDistance) {
339
        g.drawLine(0,j,(x-1),j);
340
      }
341
   }
342
  
343
  /** Replace the Image object in the image display editor, with a new image object */
344
  public void reload(NBImageIcon newImage){
345
        this.imageObject = (BufferedImage)newImage.getImage();
346
        repaint(0, 0, getWidth(), getHeight());
347
    }
348
}
(-)image/src/org/netbeans/modules/image/ImageSaveSupport.java (+144 lines)
Added Link Here
1
/*
2
 * ImageSaveSupport.java
3
 *
4
 * Created on 2 May 2005, 11:19
5
 */
6
7
package org.netbeans.modules.image;
8
9
import java.awt.Component;
10
import java.awt.Image;
11
import java.awt.image.RenderedImage;
12
import java.io.IOException;
13
import java.io.File;
14
import java.util.Iterator;
15
import java.util.List;
16
import javax.imageio.IIOImage;
17
import javax.imageio.ImageIO;
18
import javax.imageio.ImageWriteParam;
19
import javax.imageio.ImageWriter;
20
import javax.imageio.metadata.IIOMetadata;
21
import javax.imageio.stream.FileImageOutputStream;
22
import javax.swing.JOptionPane;
23
24
import org.openide.cookies.SaveCookie;
25
import org.openide.util.NbBundle;
26
import org.openide.windows.TopComponent;
27
28
29
/**
30
 *
31
 * @author Jason Solomon
32
 */
33
public class ImageSaveSupport implements SaveCookie {
34
    
35
    private ImageDataObject imageDataObject;
36
    
37
    private Image image;
38
39
    private String format;
40
    
41
    /** Creates a new instance of ImageSaveSupport */
42
    public ImageSaveSupport(ImageDataObject ido) {
43
        imageDataObject = ido;
44
    }
45
    
46
    /** Invoke the save operation.
47
     * @throws IOException if the object could not be saved
48
     */
49
    public void save () throws java.io.IOException {
50
        format = imageDataObject.getFormat();
51
        image = imageDataObject.getImage();
52
53
        if(saveFile()) {
54
            imageDataObject.reloadImage();
55
            imageDataObject.notifyUnmodified();
56
        }
57
        else {
58
            IOException ex = new IOException(NbBundle.getMessage(ImageSaveSupport.class, "MSG_UserAbortSave", imageDataObject.getPath()));
59
            throw ex;
60
        }
61
    }
62
    
63
    private boolean saveFile() throws IOException {
64
        boolean compressionSupported;
65
        Iterator writers = ImageIO.getImageWritersByFormatName(format);
66
        if(!writers.hasNext()) {
67
            if(JOptionPane.showConfirmDialog(null, NbBundle.getMessage(ImageSaveSupport.class, "MSG_NoSaveSupportConfirm", format), NbBundle.getMessage(ImageSaveSupport.class, "LBL_NoSaveSupport"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
68
                TopComponent curComponent = TopComponent.getRegistry().getActivated();
69
                if(curComponent instanceof ImageViewer) {
70
                    ImageViewer currComponent = (ImageViewer) TopComponent.getRegistry().getActivated();
71
                    imageDataObject.convertTo(currComponent);
72
                }
73
            }
74
            IOException ex = new IOException(NbBundle.getMessage(ImageSaveSupport.class, "MSG_NoSaveSupport", format));
75
            throw ex;
76
        }
77
        ImageWriter writer = (ImageWriter)writers.next();
78
        ImageWriteParam iwp = writer.getDefaultWriteParam();
79
80
        try {
81
            compressionSupported = true;
82
            iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
83
        } catch (UnsupportedOperationException e) {
84
            compressionSupported = false;
85
            iwp = writer.getDefaultWriteParam();
86
        }
87
88
        if(compressionSupported) {
89
            return getCompression(writer, iwp);
90
        }
91
        else {
92
            return writeFile(writer, iwp, (float)0.00);
93
        }
94
    }
95
96
    private boolean getCompression(ImageWriter writer, ImageWriteParam iwp) throws IOException {
97
        String compressionStr;
98
        float compression;
99
        String dialogTitle = new String(NbBundle.getMessage(ImageSaveSupport.class, "LBL_CompressionLevel"));
100
        String dialogLabel = new String(NbBundle.getMessage(ImageSaveSupport.class, "MSG_CompressionLevel"));
101
        int i;
102
103
        String[] qualityDescTemp = iwp.getCompressionQualityDescriptions();
104
        float qualityValsTemp[] = iwp.getCompressionQualityValues();
105
        String[] qualityDesc = new String[qualityDescTemp.length + 1];
106
        float qualityVals[] = new float[qualityValsTemp.length + 1];
107
        for(i = 0; i < qualityDescTemp.length; i++) {
108
            qualityDesc[i] = qualityDescTemp[i];
109
            qualityVals[i] = qualityValsTemp[i];
110
        }
111
        qualityDesc[qualityDesc.length - 1] = "Default";
112
        qualityVals[qualityVals.length - 1] = (float)0.00;
113
114
        compressionStr = (String)JOptionPane.showInputDialog((Component)null, dialogLabel,
115
            dialogTitle, JOptionPane.QUESTION_MESSAGE, null, qualityDesc, qualityDesc[qualityDesc.length - 1]);
116
117
        if(compressionStr != null) {
118
            for(i = 0; i < qualityDesc.length; i++) {
119
                if(compressionStr.equals(qualityDesc[i]))
120
                    break;
121
            }
122
123
            compression = qualityVals[i];
124
125
            return writeFile(writer, iwp, compression);
126
        }
127
        return false;
128
    }
129
130
    private boolean writeFile(ImageWriter writer, ImageWriteParam iwp, float compression) throws IOException {
131
        String filePath = imageDataObject.getPath();
132
        IIOImage iioImage;
133
        FileImageOutputStream output;
134
135
        if(compression != (float)0.00) {
136
            iwp.setCompressionQuality(compression);
137
        }
138
        iioImage = new IIOImage((RenderedImage)image, (List)null, (IIOMetadata)null);
139
        output = new FileImageOutputStream(new File(filePath));
140
        writer.setOutput(output);
141
        writer.write((IIOMetadata)null, iioImage, iwp);
142
        return true;
143
    }
144
}
(-)image/src/org/netbeans/modules/image/ImageViewer.java (-51 / +637 lines)
Lines 32-46 Link Here
32
import java.util.HashSet;
32
import java.util.HashSet;
33
import java.util.Iterator;
33
import java.util.Iterator;
34
import java.util.Set;
34
import java.util.Set;
35
import java.util.Observer;
36
import java.util.Observable;
35
import javax.swing.Action;
37
import javax.swing.Action;
38
import javax.swing.ButtonGroup;
36
import javax.swing.Icon;
39
import javax.swing.Icon;
37
import javax.swing.ImageIcon;
40
import javax.swing.ImageIcon;
38
import javax.swing.JButton;
41
import javax.swing.JButton;
42
import javax.swing.JColorChooser;
43
import javax.swing.JFormattedTextField;
39
import javax.swing.JLabel;
44
import javax.swing.JLabel;
45
import javax.swing.JOptionPane;
40
import javax.swing.JPanel;
46
import javax.swing.JPanel;
41
import javax.swing.JScrollPane;
47
import javax.swing.JScrollPane;
48
import javax.swing.JSpinner;
49
import javax.swing.JTextField;
42
import javax.swing.JToggleButton;
50
import javax.swing.JToggleButton;
43
import javax.swing.JToolBar;
51
import javax.swing.JToolBar;
52
import javax.swing.SpinnerModel;
53
import javax.swing.SpinnerNumberModel;
44
54
45
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
46
import org.openide.filesystems.FileUtil;
56
import org.openide.filesystems.FileUtil;
Lines 60-66 Link Here
60
 * @author Petr Hamernik, Ian Formanek, Lukas Tadial
70
 * @author Petr Hamernik, Ian Formanek, Lukas Tadial
61
 * @author Marian Petras
71
 * @author Marian Petras
62
 */
72
 */
63
public class ImageViewer extends CloneableTopComponent {
73
public class ImageViewer extends CloneableTopComponent implements Observer {
64
74
65
    /** Serialized version UID. */
75
    /** Serialized version UID. */
66
    static final long serialVersionUID =6960127954234034486L;
76
    static final long serialVersionUID =6960127954234034486L;
Lines 72-91 Link Here
72
    private NBImageIcon storedImage;
82
    private NBImageIcon storedImage;
73
    
83
    
74
    /** Component showing image. */
84
    /** Component showing image. */
75
    private JPanel panel;
85
    private ImageDisplayEdit panel;
76
    
86
    
77
    /** Scale of image. */
87
    /** Scale of image. */
78
    private double scale = 1.0D;
88
    private double scale = 1.0D;
79
    
89
    
80
    /** On/off grid. */
81
    private boolean showGrid = false;
82
    
83
    /** Increase/decrease factor. */
90
    /** Increase/decrease factor. */
84
    private final double changeFactor = Math.sqrt(2.0D);
91
    private final double changeFactor = Math.sqrt(2.0D);
85
    
92
    
86
    /** Grid color. */
87
    private final Color gridColor = Color.black;
88
    
89
    /** Listens for name changes. */
93
    /** Listens for name changes. */
90
    private PropertyChangeListener nameChangeL;
94
    private PropertyChangeListener nameChangeL;
91
    
95
    
Lines 93-98 Link Here
93
    private final Collection/*<JButton>*/ toolbarButtons
97
    private final Collection/*<JButton>*/ toolbarButtons
94
                                          = new ArrayList/*<JButton>*/(11);
98
                                          = new ArrayList/*<JButton>*/(11);
95
    
99
    
100
    /** The tool selected */
101
    private int Tool = 1;   
102
    
103
    /** The line width selection */
104
    private int lineWidth = 1;
105
    
106
    /** The fill type selection for rectangle and ellipse tools */
107
    private int fillType = 1;
108
    
109
    private JToggleButton oneptLine;
110
    private JToggleButton threeptLine;      
111
    private JToggleButton sixptLine; 
112
    
113
    private JToggleButton noFillRect;
114
    private JToggleButton fillRect;      
115
    private JToggleButton noLineRect;     
116
    
117
    private JToggleButton noFillEllipse;
118
    private JToggleButton fillEllipse;      
119
    private JToggleButton noLineEllipse;       
120
    
121
    private JSpinner cornerRounding;
122
    
123
    private JColorChooser fgColor = new JColorChooser();
124
    private JColorChooser bgColor = new JColorChooser();
96
    
125
    
97
    /** Default constructor. Must be here, used during de-externalization */
126
    /** Default constructor. Must be here, used during de-externalization */
98
    public ImageViewer () {
127
    public ImageViewer () {
Lines 123-128 Link Here
123
        TopComponent.NodeName.connect (this, obj.getNodeDelegate ());
152
        TopComponent.NodeName.connect (this, obj.getNodeDelegate ());
124
        
153
        
125
        storedObject = obj;
154
        storedObject = obj;
155
        
156
        /* Add an observer */
157
        storedObject.addObserver(this);
126
            
158
            
127
        // force closing panes in all workspaces, default is in current only
159
        // force closing panes in all workspaces, default is in current only
128
        setCloseOperation(TopComponent.CLOSE_EACH);
160
        setCloseOperation(TopComponent.CLOSE_EACH);
Lines 132-137 Link Here
132
        
164
        
133
        /* compose the whole panel: */
165
        /* compose the whole panel: */
134
        JToolBar toolbar = createToolBar();
166
        JToolBar toolbar = createToolBar();
167
        JToolBar edittoolbar = createEditToolBar();
135
        Component view;
168
        Component view;
136
        if (storedImage != null) {
169
        if (storedImage != null) {
137
            view = createImageView();
170
            view = createImageView();
Lines 142-147 Link Here
142
        setLayout(new BorderLayout());
175
        setLayout(new BorderLayout());
143
        add(view, BorderLayout.CENTER);
176
        add(view, BorderLayout.CENTER);
144
        add(toolbar, BorderLayout.NORTH);
177
        add(toolbar, BorderLayout.NORTH);
178
        add(edittoolbar, BorderLayout.WEST);
145
179
146
        getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_ImageViewer"));        
180
        getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_ImageViewer"));        
147
        
181
        
Lines 160-207 Link Here
160
    /**
194
    /**
161
     */
195
     */
162
    private Component createImageView() {
196
    private Component createImageView() {
163
        panel = new JPanel() {
197
        panel = new ImageDisplayEdit(storedImage, getScale());
164
            protected void paintComponent(Graphics g) {
165
                super.paintComponent(g);
166
                g.drawImage(
167
                    storedImage.getImage(),
168
                    0,
169
                    0,
170
                    (int)(getScale () * storedImage.getIconWidth ()),
171
                    (int)(getScale () * storedImage.getIconHeight ()),
172
                    0,
173
                    0,
174
                    storedImage.getIconWidth(),
175
                    storedImage.getIconHeight(),
176
                    this
177
                );
178
179
                if(showGrid) {
180
                    int x = (int)(getScale () * storedImage.getIconWidth ());
181
                    int y = (int)(getScale () * storedImage.getIconHeight ());
182
183
                    double gridDistance = getScale();
184
185
                    if(gridDistance < 2) 
186
                        // Disable painting of grid if no image pixels would be visible.
187
                        return;
188
189
                    g.setColor(gridColor);
190
191
                    double actualDistance = gridDistance;
192
                    for(int i = (int)actualDistance; i < x ;actualDistance += gridDistance, i = (int)actualDistance) {
193
                        g.drawLine(i,0,i,(y-1));
194
                    }
195
196
                    actualDistance = gridDistance;
197
                    for(int j = (int)actualDistance; j < y; actualDistance += gridDistance, j = (int)actualDistance) {
198
                        g.drawLine(0,j,(x-1),j);
199
                    }
200
                }
201
202
            }
203
204
        };
205
        storedImage.setImageObserver(panel);
198
        storedImage.setImageObserver(panel);
206
        panel.setPreferredSize(new Dimension(storedImage.getIconWidth(), storedImage.getIconHeight() ));
199
        panel.setPreferredSize(new Dimension(storedImage.getIconWidth(), storedImage.getIconHeight() ));
207
        JScrollPane scroll = new JScrollPane(panel);
200
        JScrollPane scroll = new JScrollPane(panel);
Lines 348-353 Link Here
348
        return toolBar;
341
        return toolBar;
349
    }
342
    }
350
    
343
    
344
    //** Creates edittoolbar. */
345
    private JToolBar createEditToolBar() 
346
    {                
347
        /*
348
            BTN_Select=1
349
            BTN_Polygon=2
350
            BTN_Pen=3
351
            BTN_Brush=4
352
            BTN_Arc=5
353
            BTN_Line=6
354
            BTN_Rectangle=7
355
            BTN_Ellipse=8
356
            BTN_Fill=9
357
            BTN_Spray=10
358
         */     
359
        
360
        ButtonGroup bgGroup = new javax.swing.ButtonGroup();
361
        ButtonGroup bgLineWidth = new javax.swing.ButtonGroup();    
362
        ButtonGroup bgRect = new javax.swing.ButtonGroup();
363
        ButtonGroup bgEllipse = new javax.swing.ButtonGroup();
364
        JToolBar editToolBar = new javax.swing.JToolBar();    
365
        editToolBar.setName (NbBundle.getBundle(ImageViewer.class).getString("ACSN_EditToolbar"));
366
        editToolBar.setOrientation(1);
367
        
368
        setLayout(null);
369
        
370
        editToolBar.setFloatable (false);
371
        
372
        JToggleButton selectTButton = new JToggleButton();
373
        editToolBar.add(selectTButton = getSelectTButton());
374
        selectTButton.setSelected(true);
375
        bgGroup.add(selectTButton);
376
        
377
        JToggleButton polygonTButton = new JToggleButton();
378
        editToolBar.add(polygonTButton = getPolygonTButton());
379
        bgGroup.add(polygonTButton);
380
        
381
        JToggleButton penTButton = new JToggleButton();
382
        editToolBar.add(penTButton = getPenTButton());
383
        bgGroup.add(penTButton);
384
385
        JToggleButton brushTButton = new JToggleButton();
386
        editToolBar.add(brushTButton = getBrushTButton());
387
        bgGroup.add(brushTButton);
388
        
389
        JToggleButton arcTButton = new JToggleButton();
390
        editToolBar.add(arcTButton = getArcTButton());
391
        bgGroup.add(arcTButton);
392
        
393
        JToggleButton lineTButton = new JToggleButton();
394
        editToolBar.add(lineTButton = getLineTButton());
395
        bgGroup.add(lineTButton);
396
397
        JToggleButton rectangleTButton = new JToggleButton();
398
        editToolBar.add(rectangleTButton = getRectangleTButton());
399
        bgGroup.add(rectangleTButton);
400
        
401
        JToggleButton ovalTButton = new JToggleButton();
402
        editToolBar.add(ovalTButton = getEllipseTButton());
403
        bgGroup.add(ovalTButton);
404
                
405
        JToggleButton fillTButton = new JToggleButton();
406
        editToolBar.add(fillTButton = getFillTButton());
407
        bgGroup.add(fillTButton);
408
409
        JToggleButton sprayTButton = new JToggleButton();
410
        editToolBar.add(sprayTButton = getSprayTButton());
411
        bgGroup.add(sprayTButton);
412
        
413
        JButton foregroundButton = new JButton();
414
        editToolBar.add(foregroundButton = getForegroundButton());
415
416
        editToolBar.addSeparator(new Dimension(2,2));        
417
        
418
        JButton backgroundButton = new JButton();
419
        editToolBar.add(backgroundButton = getBackgroundButton());
420
421
        editToolBar.addSeparator(new Dimension(2,10));                
422
        
423
        oneptLine = new JToggleButton();
424
        editToolBar.add(oneptLine = getOneptLineTButton());
425
        bgLineWidth.add(oneptLine); 
426
        oneptLine.setSelected(true);
427
        oneptLine.setVisible(false);
428
        
429
        threeptLine = new JToggleButton();
430
        editToolBar.add(threeptLine = getThreeptLineTButton());                
431
        bgLineWidth.add(threeptLine);
432
        threeptLine.setVisible(false);               
433
        
434
        sixptLine = new JToggleButton();
435
        editToolBar.add(sixptLine = getSixptLineTButton());
436
        bgLineWidth.add(sixptLine); 
437
        sixptLine.setVisible(false);               
438
        
439
        editToolBar.addSeparator(new Dimension(2,6));   
440
        
441
        noFillRect = new JToggleButton();
442
        editToolBar.add(noFillRect = getNoFillRectTButton());
443
        bgRect.add(noFillRect); 
444
        noFillRect.setSelected(true);
445
        noFillRect.setVisible(false);
446
        
447
        fillRect = new JToggleButton();
448
        editToolBar.add(fillRect = getFillRectTButton());                
449
        bgRect.add(fillRect);
450
        fillRect.setVisible(false);               
451
        
452
        noLineRect = new JToggleButton();
453
        editToolBar.add(noLineRect = getNoLineRectTButton());
454
        bgRect.add(noLineRect); 
455
        noLineRect.setVisible(false);   
456
        
457
        editToolBar.addSeparator(new Dimension(2,6));   
458
        
459
        noFillEllipse = new JToggleButton();
460
        editToolBar.add(noFillEllipse = getNoFillEllipseTButton());
461
        bgEllipse.add(noFillEllipse); 
462
        noFillEllipse.setSelected(true);
463
        noFillEllipse.setVisible(false);
464
        
465
        fillEllipse = new JToggleButton();
466
        editToolBar.add(fillEllipse = getFillEllipseTButton());                
467
        bgEllipse.add(fillEllipse);
468
        fillEllipse.setVisible(false);               
469
        
470
        noLineEllipse = new JToggleButton();
471
        editToolBar.add(noLineEllipse = getNoLineEllipseTButton());
472
        bgEllipse.add(noLineEllipse); 
473
        noLineEllipse.setVisible(false);           
474
        
475
        editToolBar.addSeparator(new Dimension(2,6));            
476
        
477
        //JPanel textPanel = new JPanel();
478
        SpinnerModel cornerRoundingModel = new SpinnerNumberModel(0, 0, 100, 5);
479
        cornerRounding = new JSpinner(cornerRoundingModel);
480
        cornerRounding.setSize(100,100);
481
        
482
        JFormattedTextField tf = ((JSpinner.DefaultEditor)cornerRounding.getEditor()).getTextField();
483
        tf.setEditable(false);
484
        tf.setBackground(Color.white);
485
486
        cornerRounding.setVisible(false);
487
        
488
        editToolBar.add(cornerRounding);                     
489
        
490
        add(editToolBar);                                  
491
492
        return editToolBar;
493
    }
494
    
351
    /** Updates the name and tooltip of this top component according to associated data object. */
495
    /** Updates the name and tooltip of this top component according to associated data object. */
352
    private void updateName () {
496
    private void updateName () {
353
        // update name
497
        // update name
Lines 541-546 Link Here
541
            SystemAction.get(ZoomInAction.class),
685
            SystemAction.get(ZoomInAction.class),
542
            SystemAction.get(ZoomOutAction.class),
686
            SystemAction.get(ZoomOutAction.class),
543
            SystemAction.get(CustomZoomAction.class),
687
            SystemAction.get(CustomZoomAction.class),
688
            SystemAction.get(ConvertToAction.class),
544
            null},
689
            null},
545
            oldValue);
690
            oldValue);
546
    }
691
    }
Lines 609-614 Link Here
609
        
754
        
610
        resizePanel();
755
        resizePanel();
611
        panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
756
        panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
757
        panel.setScale(scale);
612
    }
758
    }
613
    
759
    
614
    /** Return zooming factor.*/
760
    /** Return zooming factor.*/
Lines 619-624 Link Here
619
    /** Change proportion "out"*/
765
    /** Change proportion "out"*/
620
    private void scaleOut() {
766
    private void scaleOut() {
621
        scale = scale / changeFactor;
767
        scale = scale / changeFactor;
768
        panel.setScale(scale);
622
    }
769
    }
623
    
770
    
624
    /** Change proportion "in"*/
771
    /** Change proportion "in"*/
Lines 632-637 Link Here
632
        if (newComputedScale == oldComputedScale)
779
        if (newComputedScale == oldComputedScale)
633
            // Has to increase.
780
            // Has to increase.
634
            scale = newComputedScale + 1.0D;
781
            scale = newComputedScale + 1.0D;
782
        
783
        panel.setScale(scale);
784
    }
785
    
786
    public void convertTo() {
787
        try {
788
          storedObject.convertTo(this);
789
        } catch(IOException e) {
790
            JOptionPane.showMessageDialog(null, NbBundle.getMessage(ImageViewer.class, "MSG_CouldNotConvert"), NbBundle.getMessage(ImageViewer.class, "LBL_CouldNotConvert"), JOptionPane.ERROR_MESSAGE);
791
        }
792
    }
793
    
794
    public void update(Observable o, Object arg){
795
        updateView(storedObject);
796
        panel.reload(storedImage);
635
    }
797
    }
636
    
798
    
637
    /** Gets zoom button. */
799
    /** Gets zoom button. */
Lines 676-687 Link Here
676
        button.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Grid_BTN_Mnem").charAt(0));
838
        button.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Grid_BTN_Mnem").charAt(0));
677
        button.addActionListener(new ActionListener() {
839
        button.addActionListener(new ActionListener() {
678
            public void actionPerformed(ActionEvent evt) {
840
            public void actionPerformed(ActionEvent evt) {
679
                showGrid = !showGrid;
841
                panel.toggleGrid();
680
                panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
842
                panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
681
            }
843
            }
682
        });
844
        });
683
        
845
        
684
        return button;
846
        return button;
847
    }       
848
    
849
    /** Gets ellipse button.*/
850
    private JToggleButton getEllipseTButton() {
851
        JToggleButton ellipseTButton = new JToggleButton();
852
        ellipseTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Ellipse"));
853
        ellipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/oval.gif")));
854
        ellipseTButton.setLabel("");
855
856
        ellipseTButton.addActionListener(new ActionListener() {
857
            public void actionPerformed(ActionEvent evt) {          
858
                setTool(8);
859
                setSubtoolsVisible();                
860
            }
861
        });
862
        
863
        return ellipseTButton;
864
    }        
865
    
866
    /** Gets rectangle button.*/    
867
    private JToggleButton getRectangleTButton(){
868
        JToggleButton rectangleTButton = new JToggleButton();
869
        rectangleTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Rectangle"));
870
        rectangleTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/rect.gif")));
871
        rectangleTButton.setLabel("");
872
        
873
        rectangleTButton.addActionListener(new ActionListener() {
874
            public void actionPerformed(ActionEvent evt) {                      
875
                setTool(7);
876
                setSubtoolsVisible();                
877
            }
878
        });  
879
        
880
        return rectangleTButton;
881
    }
882
883
    /** Gets fill button.*/        
884
    private JToggleButton getFillTButton(){
885
        JToggleButton fillTButton = new JToggleButton();
886
        fillTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Fill"));
887
        fillTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fill.gif")));
888
        fillTButton.setLabel("");
889
        
890
        fillTButton.addActionListener(new ActionListener() {
891
            public void actionPerformed(ActionEvent evt) {                         
892
                setTool(9);
893
                setSubtoolsVisible();                
894
            }
895
        });  
896
        
897
        return fillTButton;        
898
    }
899
900
    /** Gets line button.*/        
901
    private JToggleButton getLineTButton(){
902
        JToggleButton lineTButton = new JToggleButton();
903
        lineTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Line"));
904
        lineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/line.gif")));
905
        lineTButton.setLabel("");        
906
        lineTButton.addActionListener(new ActionListener() {
907
            public void actionPerformed(ActionEvent evt) {          
908
                setTool(6);
909
                setSubtoolsVisible();                
910
            }
911
        });  
912
        
913
        return lineTButton;        
914
    }   
915
916
    /** Gets select button.*/    
917
    private JToggleButton getSelectTButton(){
918
        JToggleButton selectTButton = new JToggleButton();        
919
        selectTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Select"));
920
        selectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/arrow.gif")));
921
        selectTButton.setLabel("");
922
923
        selectTButton.addActionListener(new ActionListener() {
924
            public void actionPerformed(ActionEvent evt) {                 
925
                setTool(1);
926
                setSubtoolsVisible();                
927
            }
928
        });  
929
        
930
        return selectTButton;
931
    }
932
    
933
    /** Gets polygon button.*/        
934
    private JToggleButton getPolygonTButton(){
935
        JToggleButton polygonTButton = new JToggleButton();
936
        polygonTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Polygon"));
937
        polygonTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/polygon.gif")));
938
        polygonTButton.setLabel("");
939
        
940
        polygonTButton.addActionListener(new ActionListener() {
941
            public void actionPerformed(ActionEvent evt) {                      
942
                setTool(2);
943
                setSubtoolsVisible();                
944
            }
945
        });  
946
        
947
        return polygonTButton;
948
    }
949
950
    /** Gets pen button.*/        
951
    private JToggleButton getPenTButton(){
952
        JToggleButton penTButton = new JToggleButton();
953
        penTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Pen"));
954
        penTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/pen.gif")));
955
        penTButton.setLabel("");
956
        
957
        penTButton.addActionListener(new ActionListener() {
958
            public void actionPerformed(ActionEvent evt) {
959
                setTool(3);
960
                setSubtoolsVisible();                
961
            }
962
        });  
963
964
        return penTButton;
965
    }
966
    
967
    /** Gets brush button.*/        
968
    private JToggleButton getBrushTButton(){
969
        JToggleButton brushTButton = new JToggleButton();
970
        brushTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Brush"));
971
        brushTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/brush.gif")));
972
        brushTButton.setLabel("");    
973
974
        brushTButton.addActionListener(new ActionListener() {
975
            public void actionPerformed(ActionEvent evt) {                            
976
                setTool(4);
977
                setSubtoolsVisible();                
978
            }
979
        });  
980
981
        return brushTButton;
982
    }
983
984
    /** Gets arc button.*/        
985
    private JToggleButton getArcTButton(){
986
        JToggleButton arcTButton = new JToggleButton();
987
        arcTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Arc"));
988
        arcTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/arc.gif")));
989
        arcTButton.setLabel("");
990
991
        arcTButton.addActionListener(new ActionListener() {
992
            public void actionPerformed(ActionEvent evt) {
993
                setTool(5);
994
                setSubtoolsVisible();                
995
            }
996
        });  
997
998
        return arcTButton;
999
    }
1000
    
1001
    /** Gets spray button.*/           
1002
    private JToggleButton getSprayTButton(){
1003
        JToggleButton sprayTButton = new JToggleButton();
1004
        sprayTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Spray"));
1005
        sprayTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/spray.gif")));
1006
        sprayTButton.setLabel("");
1007
1008
        sprayTButton.addActionListener(new ActionListener() {
1009
            public void actionPerformed(ActionEvent evt) {
1010
                setTool(10);
1011
                setSubtoolsVisible();                
1012
            }
1013
        });          
1014
                            
1015
        return sprayTButton;
1016
    }
1017
1018
    /** Gets foreground button.*/        
1019
    private JButton getForegroundButton(){
1020
        final JButton foregroundButton = new JButton("     ");
1021
        foregroundButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_SetLineColor"));
1022
        foregroundButton.setBackground(new Color(0, 0, 0));
1023
        foregroundButton.addActionListener(new ActionListener() 
1024
        {
1025
            public void actionPerformed(ActionEvent evt) 
1026
            {
1027
                Color newColor = fgColor.showDialog(null,NbBundle.getMessage(ImageViewer.class, "LBL_ForegroundColor"), foregroundButton.getForeground());                                
1028
                foregroundButton.setBackground(newColor);
1029
                
1030
                panel.setPrimaryColor(newColor);
1031
            }
1032
        }); 
1033
        
1034
        return foregroundButton;        
1035
    }
1036
    
1037
    /** Gets background button.*/        
1038
    private JButton getBackgroundButton(){
1039
        final JButton backgroundButton = new JButton("     "); 
1040
        backgroundButton.setBackground(new Color(128, 128, 255));       
1041
        backgroundButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_SetFillColor"));
1042
        backgroundButton.addActionListener(new ActionListener() 
1043
        {
1044
            public void actionPerformed(ActionEvent evt) 
1045
            {
1046
                Color newColor = bgColor.showDialog(null,NbBundle.getMessage(ImageViewer.class, "LBL_BackgroundColor"), backgroundButton.getBackground());                                
1047
                backgroundButton.setBackground(newColor);
1048
                                                                
1049
                panel.setSecondayColor(newColor);
1050
            }
1051
        });
1052
        
1053
        return backgroundButton;        
1054
    }
1055
    
1056
    /** Gets oneptLine button */
1057
    private JToggleButton getOneptLineTButton(){
1058
        JToggleButton oneptLineTButton = new JToggleButton();
1059
//        oneptLineTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Spray"));
1060
        oneptLineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/1ptLine.gif")));
1061
        oneptLineTButton.setLabel("");
1062
1063
        oneptLineTButton.addActionListener(new ActionListener() {
1064
            public void actionPerformed(ActionEvent evt) {
1065
                setLineWidth(1);
1066
            }
1067
        });          
1068
                            
1069
        return oneptLineTButton; 
1070
    }        
1071
    
1072
    /** Gets threeptLine button */
1073
    private JToggleButton getThreeptLineTButton(){
1074
        JToggleButton threeptLineTButton = new JToggleButton();
1075
//        threeptLineTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Spray"));
1076
        threeptLineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/3ptLine.gif")));
1077
        threeptLineTButton.setLabel("");
1078
1079
        threeptLineTButton.addActionListener(new ActionListener() {
1080
            public void actionPerformed(ActionEvent evt) {
1081
                setLineWidth(3);
1082
            }
1083
        });          
1084
                            
1085
        return threeptLineTButton; 
1086
    }    
1087
    
1088
    /** Gets sixptLine button */
1089
    private JToggleButton getSixptLineTButton(){
1090
        JToggleButton sixptLineTButton = new JToggleButton();
1091
        sixptLineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/6ptLine.gif")));
1092
        sixptLineTButton.setLabel("");
1093
1094
        sixptLineTButton.addActionListener(new ActionListener() {
1095
            public void actionPerformed(ActionEvent evt) {
1096
                setLineWidth(6);
1097
            }
1098
        });          
1099
                            
1100
        return sixptLineTButton; 
1101
    }                
1102
    
1103
    /** Gets noFillRect button */
1104
    private JToggleButton getNoFillRectTButton(){
1105
        JToggleButton noFillRectTButton = new JToggleButton();
1106
        noFillRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noFillRect.gif")));        
1107
        noFillRectTButton.setLabel("");
1108
1109
        noFillRectTButton.addActionListener(new ActionListener() {
1110
            public void actionPerformed(ActionEvent evt) {
1111
                setFillType(1);
1112
            }
1113
        });          
1114
                            
1115
        return noFillRectTButton; 
1116
    }      
1117
    
1118
    /** Gets fillRect button */
1119
    private JToggleButton getFillRectTButton(){
1120
        JToggleButton fillRectTButton = new JToggleButton();
1121
        fillRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fillRect.gif")));
1122
        fillRectTButton.setLabel("");
1123
1124
        fillRectTButton.addActionListener(new ActionListener() {
1125
            public void actionPerformed(ActionEvent evt) {
1126
                setFillType(2);
1127
            }
1128
        });          
1129
                            
1130
        return fillRectTButton; 
1131
    }        
1132
    
1133
    /** Gets noLineRect button */
1134
    private JToggleButton getNoLineRectTButton(){
1135
        JToggleButton noLineRectTButton = new JToggleButton();
1136
        noLineRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noLineRect.gif")));
1137
        noLineRectTButton.setLabel("");
1138
1139
        noLineRectTButton.addActionListener(new ActionListener() {
1140
            public void actionPerformed(ActionEvent evt) {
1141
                setFillType(3);
1142
            }
1143
        });          
1144
                            
1145
        return noLineRectTButton; 
1146
    }        
1147
    
1148
    /** Gets noFillEllipse button */
1149
    private JToggleButton getNoFillEllipseTButton(){
1150
        JToggleButton noFillEllipseTButton = new JToggleButton();
1151
        noFillEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noFillEllipse.gif")));        
1152
        noFillEllipseTButton.setLabel("");
1153
1154
        noFillEllipseTButton.addActionListener(new ActionListener() {
1155
            public void actionPerformed(ActionEvent evt) {
1156
                setFillType(1);
1157
            }
1158
        });          
1159
                            
1160
        return noFillEllipseTButton; 
1161
    }      
1162
    
1163
    /** Gets fillEllipse button */
1164
    private JToggleButton getFillEllipseTButton(){
1165
        JToggleButton fillEllipseTButton = new JToggleButton();
1166
        fillEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fillEllipse.gif")));
1167
        fillEllipseTButton.setLabel("");
1168
1169
        fillEllipseTButton.addActionListener(new ActionListener() {
1170
            public void actionPerformed(ActionEvent evt) {
1171
                setFillType(2);
1172
            }
1173
        });          
1174
                            
1175
        return fillEllipseTButton; 
1176
    }        
1177
    
1178
    /** Gets noLineEllipse button */
1179
    private JToggleButton getNoLineEllipseTButton(){
1180
        JToggleButton noLineEllipseTButton = new JToggleButton();
1181
        noLineEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noLineEllipse.gif")));
1182
        noLineEllipseTButton.setLabel("");
1183
1184
        noLineEllipseTButton.addActionListener(new ActionListener() {
1185
            public void actionPerformed(ActionEvent evt) {
1186
                setFillType(3);
1187
            }
1188
        });          
1189
                            
1190
        return noLineEllipseTButton; 
1191
    }        
1192
    
1193
    /** set the lines widths visible */
1194
    private void setSubtoolsVisible(){
1195
        switch (getTool()){
1196
            case 2:
1197
            case 5: 
1198
            case 6:
1199
            case 7:
1200
            case 8:                
1201
                oneptLine.setVisible(true);
1202
                threeptLine.setVisible(true);
1203
                sixptLine.setVisible(true);        
1204
                break;
1205
            default:
1206
                oneptLine.setVisible(false);
1207
                threeptLine.setVisible(false);
1208
                sixptLine.setVisible(false);        
1209
                break;
1210
        }
1211
        
1212
        if (getTool() == 7){ 
1213
            noFillRect.setVisible(true);
1214
            fillRect.setVisible(true);
1215
            noLineRect.setVisible(true);            
1216
            cornerRounding.setVisible(true);
1217
            setFillType(1);
1218
            noFillRect.setSelected(true);
1219
        }else{
1220
            noFillRect.setVisible(false);
1221
            fillRect.setVisible(false);
1222
            noLineRect.setVisible(false);
1223
            cornerRounding.setVisible(false);
1224
        }
1225
        
1226
        if (getTool() == 8){ 
1227
            noFillEllipse.setVisible(true);
1228
            fillEllipse.setVisible(true);
1229
            noLineEllipse.setVisible(true);
1230
            setFillType(1);
1231
            noFillEllipse.setSelected(true);
1232
        }else{
1233
            noFillEllipse.setVisible(false);
1234
            fillEllipse.setVisible(false);
1235
            noLineEllipse.setVisible(false);
1236
        }        
1237
    }
1238
    
1239
    /** Set the tool. */
1240
    public void setTool(int selection){
1241
        Tool = selection;
1242
    }
1243
    
1244
    /** Get the tool. */
1245
    public int getTool(){
1246
        return Tool;
1247
    }    
1248
    
1249
    /** Set the sub tool */
1250
    public void setLineWidth(int selection){
1251
        lineWidth = selection;
1252
    }
1253
1254
    /** Get the sub tool */    
1255
    public int getLineWidth(){
1256
        return lineWidth;
1257
    }
1258
    
1259
    /** Set the sub tool */
1260
    public void setFillType(int selection){
1261
        fillType = selection;
1262
    }
1263
1264
    /** Get the sub tool */    
1265
    public int getFillType(){
1266
        return fillType;
1267
    }    
1268
    
1269
    public int getCornerRoundingFactor(){        
1270
        return ((Integer)(cornerRounding.getValue())).intValue();
685
    }
1271
    }
686
    
1272
    
687
}
1273
}
(-)image/src/org/netbeans/modules/image/JpegHelp.html (+16 lines)
Added Link Here
1
<!--
2
                Sun Public License Notice
3
4
The contents of this file are subject to the Sun Public License
5
Version 1.0 (the "License"). You may not use this file except in
6
compliance with the License. A copy of the License is available at
7
http://www.sun.com/
8
9
The Original Code is NetBeans. The Initial Developer of the Original
10
Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
Microsystems, Inc. All Rights Reserved.
12
-->
13
14
<HTML><BODY>
15
Creates a new JPEG file. You can edit the file in the IDE's Image Editor.
16
</BODY></HTML>
(-)image/src/org/netbeans/modules/image/Layer.xml (+28 lines)
Lines 23-34 Link Here
23
        </folder>
23
        </folder>
24
    </folder>
24
    </folder>
25
25
26
    <folder name="Menu">
27
        <folder name="Edit">
28
            <file name="org.netbeans.modules.image.ConvertToAction.instance" />
29
        </folder>
30
    </folder>
31
26
    <folder name="Services">
32
    <folder name="Services">
27
        <folder name="MIMEResolver">
33
        <folder name="MIMEResolver">
28
            <file name="org-netbeans-modules-image-mime-resolver.xml" url="mime-resolver.xml">
34
            <file name="org-netbeans-modules-image-mime-resolver.xml" url="mime-resolver.xml">
29
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.image.Bundle"/>
35
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.image.Bundle"/>
30
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/image/imageObject.gif"/>
36
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/image/imageObject.gif"/>
31
            </file>
37
            </file>
38
        </folder>
39
    </folder>
40
41
    <folder name="Templates">
42
        <attr name="API_Support/Other" boolvalue="true"/>
43
        <folder name="Other">
44
            <folder name="Image">
45
                <file name="png.png" url="templates/png.png">
46
                    <attr name="template" boolvalue="true" />
47
                    <attr name="templateWizardURL" urlvalue="nbresloc:/org/netbeans/modules/image/PngHelp.html" />
48
                    <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.image.Bundle" />
49
                    <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/image/imageObject.gif"/>
50
                    <attr name="templateCategory" stringvalue="simple-files"/>
51
                </file>
52
                <file name="jpeg.jpeg" url="templates/jpeg.jpeg">
53
                    <attr name="template" boolvalue="true" />
54
                    <attr name="templateWizardURL" urlvalue="nbresloc:/org/netbeans/modules/image/JpegHelp.html" />
55
                    <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.image.Bundle" />
56
                    <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/image/imageObject.gif"/>
57
                    <attr name="templateCategory" stringvalue="simple-files"/>
58
                </file>
59
            </folder>
32
        </folder>
60
        </folder>
33
    </folder>
61
    </folder>
34
62
(-)image/src/org/netbeans/modules/image/NBImageIcon.java (+4 lines)
Lines 96-99 Link Here
96
                    (image != null) ? image : new ImageIcon().getImage());
96
                    (image != null) ? image : new ImageIcon().getImage());
97
        }
97
        }
98
    } // End of nested class ResolvableHelper.
98
    } // End of nested class ResolvableHelper.
99
    
100
    protected ImageDataObject getIDO() {
101
        return obj;
102
    }
99
}
103
}
(-)image/src/org/netbeans/modules/image/ObservableImage.java (+9 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.util.Observable;
4
5
public class ObservableImage extends Observable {
6
    public void setChanged() {
7
        super.setChanged();
8
    }
9
}
(-)image/src/org/netbeans/modules/image/PngHelp.html (+16 lines)
Added Link Here
1
<!--
2
                Sun Public License Notice
3
4
The contents of this file are subject to the Sun Public License
5
Version 1.0 (the "License"). You may not use this file except in
6
compliance with the License. A copy of the License is available at
7
http://www.sun.com/
8
9
The Original Code is NetBeans. The Initial Developer of the Original
10
Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
Microsystems, Inc. All Rights Reserved.
12
-->
13
14
<HTML><BODY>
15
Creates a new PNG file. You can edit the file in the IDE's Image Editor.
16
</BODY></HTML>
(-)image/src/org/netbeans/modules/image/VectorArc.java (+52 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.BasicStroke;
6
import java.awt.Point;
7
import java.awt.Dimension;
8
import java.awt.Shape;
9
import java.awt.Rectangle;
10
import java.awt.geom.Arc2D;
11
import java.lang.Math;
12
13
/** Implimentation of the Vector Arc tool.  Draws a 
14
90 degree line joining both points
15
 @author Timothy Boyce */
16
 
17
class VectorArc extends VectorTool{
18
19
    /** Simply use the supercalss default constructor */
20
    public VectorArc(int xVal, int yVal, Color c, int w){
21
        super(xVal, yVal, c, w);
22
    }
23
    
24
    /** Draw an arc on the graphics context
25
    between the start and end clicks */
26
    public void writeToGraphic(Graphics2D g){
27
        g.setStroke(new BasicStroke(getLineWidth()));
28
        g.setPaintMode();
29
        g.setColor(getLineColor());
30
        
31
        Arc2D.Float thisArc = new Arc2D.Float();
32
        
33
        /* Calculate the bounding rectangle */
34
        double top, left, direction;
35
        top = (getStart().getY() < getEnd().getY()) ? getTopLeft().getY() - getDimension().getHeight() : getTopLeft().getY();
36
        left = (getStart().getX() > getEnd().getX()) ? getTopLeft().getX() - getDimension().getWidth() : getTopLeft().getX();
37
        direction = (getStart().getX() - getEnd().getX()) * (getStart().getY() - getEnd().getY());
38
        direction = -(Math.abs(direction) / direction);
39
        
40
        Point topLeft = new Point((int)left, (int)top);
41
        Dimension rectDim = new Dimension((int)(2 * getDimension().getWidth()),(int)(2 * getDimension().getHeight()));
42
        
43
        /* Sets the arcs bounds */
44
        thisArc.setFrame(new Rectangle(topLeft, rectDim));
45
        
46
        /* Set the angle extent and start */
47
        thisArc.setAngleStart((getEnd().getY() < getStart().getY()) ? 90 : 270);
48
        thisArc.setAngleExtent(direction * 90);
49
    
50
        g.draw(thisArc);
51
    }
52
}
(-)image/src/org/netbeans/modules/image/VectorEllipse.java (+42 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Graphics2D;
4
import java.awt.BasicStroke;
5
import java.awt.Color;
6
import java.awt.Shape;
7
import java.awt.geom.Ellipse2D;
8
9
/** Implimentation of the Ellipse Edit Tool
10
 @author Timothy Boyce */
11
12
class VectorEllipse extends VectorTool{
13
    /** The fill color of the Ellipse */
14
    private Color fillColor;
15
16
    /** Constructor for a line ellipse */
17
    public VectorEllipse(int xVal, int yVal, Color c, int w){
18
        super(xVal, yVal, c, w);
19
        fillColor = null;
20
    }
21
    
22
    /** Constructor for a filled ellipse */
23
    public VectorEllipse(int xVal, int yVal, Color line, Color fill, int w){
24
        super(xVal, yVal, line, w);
25
        fillColor = fill;
26
    }
27
28
    public void writeToGraphic(Graphics2D g){
29
        g.setStroke(new BasicStroke(getLineWidth()));
30
        g.setPaintMode();
31
            
32
        Ellipse2D.Float thisEllipse = new Ellipse2D.Float((float)getTopLeft().getX(), (float)getTopLeft().getY(), (float)getDimension().getWidth(), (float)getDimension().getHeight());
33
            
34
        if(fillColor != null){
35
            g.setColor(fillColor);
36
            g.fill(thisEllipse);
37
        }
38
        
39
        g.setColor(getLineColor());
40
        g.draw(thisEllipse);
41
    }
42
}
(-)image/src/org/netbeans/modules/image/VectorLine.java (+26 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Graphics2D;
4
import java.awt.BasicStroke;
5
import java.awt.geom.Line2D;
6
import java.awt.Color;
7
8
/** Implimentation of the Line tool.
9
 @author Timothy Boyce */
10
 
11
class VectorLine extends VectorTool{
12
13
    /** Use the superclass constructor */
14
    public VectorLine(int xVal, int yVal, Color c, int w){
15
        super(xVal, yVal, c, w);
16
    }
17
18
    /** Draw a line between the start and end points, 
19
    to the specified graphics object */
20
    public void writeToGraphic(Graphics2D g){
21
        g.setStroke(new BasicStroke(getLineWidth()));
22
        g.setPaintMode();
23
        g.setColor(getLineColor());
24
        g.draw(new Line2D.Float(getStart(), getEnd()));
25
    }
26
}
(-)image/src/org/netbeans/modules/image/VectorPolygon.java (+131 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Graphics2D;
4
import java.awt.BasicStroke;
5
import java.awt.Point;
6
import java.awt.Color;
7
import java.awt.geom.GeneralPath;
8
import java.util.Vector;
9
10
/** Implimentation of the Polygon Edit Tool
11
 @author Timothy Boyce */
12
13
class VectorPolygon implements EditTool{
14
15
    /** The start point of the polygon */
16
    protected Point startPoint;
17
    
18
    /** The end point of the polygon */
19
    protected Point lastPoint;
20
    
21
    /** Vector containing the last 3 polygon points */
22
    protected Vector polygonSegPoints = new Vector(){
23
        public void addElement(Object obj){
24
            if(this.size() >= 3)
25
                this.removeElementAt(0);
26
            super.addElement(obj);
27
        }
28
    };
29
    
30
    /** General path used for drawing polygon segments */
31
    protected GeneralPath polygonSegPath;    
32
    
33
    /** The line color */
34
    protected Color lineColor;
35
    
36
    /** The width of the line */
37
    protected float lineWidth;
38
    
39
    /** The status of the tool, true = complete, false = incomplete */
40
    protected boolean toolStatus = false;
41
    
42
    /** The type of the polgon, points only, or freehand and points */
43
    protected boolean polyType;
44
    
45
    /** Static polygon type varibles used in the constructor */
46
    public static final boolean FREEHAND_POLY = true;
47
    public static final boolean POINT_POLY = false;
48
49
    /** Constructor, set the start point of the polygon, and other various 
50
    variables. */
51
    public VectorPolygon(int xVal, int yVal, Color c, int w, boolean f){
52
        startPoint = new Point(xVal, yVal);
53
        polygonSegPoints.addElement(startPoint);
54
        lastPoint = new Point(-1, -1);
55
        lineColor = c;
56
        lineWidth = (float)w;
57
        polyType = false;
58
    }
59
    
60
    public boolean getToolStatus(){
61
        return toolStatus;
62
    }
63
    
64
    public boolean getMemoryless(){
65
        return true;
66
    }
67
    
68
    /** When the image display editor invokes the setDragPoint
69
    command, only set a new polygone point if the user has selected a
70
    freehand polygon type */
71
    public void setDragPoint(int xVal, int yVal){
72
        if(polyType == VectorPolygon.FREEHAND_POLY){
73
            polygonSegPoints.addElement(new Point(xVal, yVal));
74
            lastPoint.setLocation(xVal, yVal);
75
        }
76
    }
77
    
78
    public void setClickPoint(int xVal, int yVal){
79
        lastPoint.setLocation(xVal, yVal);    
80
        polygonSegPoints.addElement(new Point(xVal, yVal));
81
    }
82
    
83
    public void setReleasePoint(int xVal, int yVal){
84
        /** Finish the polygon if the user clicks in the same spot twice */
85
        if((xVal == lastPoint.x) && (yVal == lastPoint.y)){
86
            toolStatus = true;
87
        }
88
        
89
        lastPoint.setLocation(xVal, yVal);    
90
        polygonSegPoints.addElement(new Point(xVal, yVal));
91
    }
92
    
93
    
94
    /** Write the last 2 polgon segments to the graphics context:
95
    Since this is a non-memoryless tool, all preceding points will
96
    still be held in the buffer.  Only the last 2 segments need to
97
    be drawn in order to get the new line, and the proper segment
98
    joining at the newly created corner. */
99
    public void writeToGraphic(Graphics2D g){
100
        Point p1, p2, p3;
101
        
102
        g.setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
103
        g.setPaintMode();
104
        g.setColor(lineColor);
105
        
106
        polygonSegPath = new GeneralPath();
107
        
108
        p1 = (Point)polygonSegPoints.firstElement();
109
        polygonSegPath.moveTo(p1.x, p1.y);
110
        
111
        if(polygonSegPoints.size() == 3)
112
            p2 = (Point)polygonSegPoints.get(1);
113
        else
114
            p2 = (Point)polygonSegPoints.lastElement();
115
        
116
        polygonSegPath.lineTo(p2.x, p2.y);
117
        
118
        if(polygonSegPoints.size()  == 2)
119
            p3 = (Point)polygonSegPoints.firstElement();
120
        else
121
            p3 = (Point)polygonSegPoints.lastElement();
122
            
123
        polygonSegPath.lineTo(p3.x, p3.y);
124
        
125
        if(getToolStatus()){
126
            polygonSegPath.lineTo(startPoint.x, startPoint.y);
127
        }
128
        
129
        g.draw(polygonSegPath);
130
    }
131
}
(-)image/src/org/netbeans/modules/image/VectorRectangle.java (+81 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Graphics2D;
4
import java.awt.Shape;
5
import java.awt.Rectangle;
6
import java.awt.BasicStroke;
7
import java.awt.Color;
8
import java.awt.GradientPaint;
9
10
import java.awt.geom.RoundRectangle2D;
11
12
class VectorRectangle extends VectorTool{
13
    private Color fillColor;
14
    private float roundingFactor;
15
16
    public VectorRectangle(int xVal, int yVal, Color c, int w){
17
        super(xVal, yVal, c, w);
18
        
19
        /* Set the fill colour to null,
20
        and corner rounding to 0 */
21
        fillColor = null;
22
        roundingFactor = 0;
23
    }
24
    
25
    public VectorRectangle(int xVal, int yVal, Color c, int w, float r){
26
        super(xVal, yVal, c, w);
27
        
28
        /* Set the fill to null */
29
        fillColor = null;
30
        
31
        /* Set CornerRounding */
32
        roundingFactor = r;
33
    }
34
    
35
    public VectorRectangle(int xVal, int yVal, Color line, Color fill, int w){
36
        super(xVal, yVal, line, w);
37
        
38
        /* Set the fill colour to null */
39
        fillColor = fill;
40
        roundingFactor = 0;
41
    }
42
    
43
    public VectorRectangle(int xVal, int yVal, Color line, Color fill, int w, float r){
44
        super(xVal, yVal, line, w);
45
        
46
        /* Set the fill colour to null */
47
        fillColor = fill;
48
        roundingFactor = r;
49
    }
50
51
    /* Returns null if there is no fill, the
52
    color if the tool is complete, or the XOR
53
    mode color if the tool is not yet complete */
54
    protected Color getFillColor(){
55
        return fillColor;
56
    }
57
58
    public void writeToGraphic(Graphics2D g){
59
        g.setStroke(new BasicStroke(getLineWidth(), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER));
60
        g.setPaintMode();
61
        
62
        Shape thisRectangle;
63
        
64
        if(roundingFactor == 0)
65
            thisRectangle = new Rectangle(getTopLeft(), getDimension());
66
        else
67
            thisRectangle = new RoundRectangle2D.Float((float)getTopLeft().getX(), (float)getTopLeft().getY(), (float)getDimension().getWidth(), (float)getDimension().getHeight(), roundingFactor, roundingFactor);
68
            
69
        /* Fill it if the user chose a filled variation */
70
        if(fillColor != null){
71
            g.setColor(getFillColor());        // Could get null pointer exception here
72
            g.fill(thisRectangle);
73
        }
74
        
75
        /* Paint the line */
76
        g.setColor(getLineColor());
77
        g.draw(thisRectangle);
78
        
79
    }
80
    
81
}
(-)image/src/org/netbeans/modules/image/VectorTool.java (+119 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.Dimension;
6
import java.awt.Point;
7
import java.awt.Rectangle;
8
9
abstract class VectorTool implements EditTool{
10
    protected Point startPoint;
11
    protected Point endPoint;
12
    private Color lineColor;
13
    private float lineWidth;
14
    private Rectangle BoundingRectangle;
15
    private Rectangle OldBoundingRectangle;
16
    
17
    protected boolean toolStatus = false;
18
    
19
    public VectorTool(int xVal, int yVal, Color c, int w){
20
        /* Set the start points */
21
        startPoint = new Point(xVal, yVal);
22
        
23
        /* Default the end points to the start points */
24
        endPoint = new Point(xVal, yVal);
25
        
26
        /* Set the Line Colour */
27
        lineColor = c;
28
        
29
        /* Sets the Line Width */
30
        lineWidth = (float)w;
31
    }
32
    
33
    /* Default Action to be performed on a drag */
34
    public void setDragPoint(int xVal, int yVal){
35
        endPoint.setLocation(xVal, yVal);
36
    }
37
    
38
    /* Default action taken on a release */
39
    public void setReleasePoint(int xVal, int yVal){
40
        endPoint.setLocation(xVal, yVal);
41
        
42
        /* Most Edit tools are complete when the user releases
43
        the mouse */
44
        toolStatus = true;
45
    }
46
    
47
    /* Default action taken on a Click */
48
    public void setClickPoint(int xVal, int yVal){
49
    }
50
    
51
    /* Return the tool status */
52
    public boolean getToolStatus(){
53
        return toolStatus;
54
    }
55
    
56
    /* Return the shape height */
57
    private int getHeight(){
58
        return Math.abs((int)startPoint.getY() - (int)endPoint.getY());
59
    }
60
    
61
    /* Return the shape width */
62
    private int getWidth(){
63
        return Math.abs((int)startPoint.getX() - (int)endPoint.getX());
64
    }
65
    
66
    /* Retern the top-left point */
67
    protected Point getTopLeft(){
68
        double left = (startPoint.getX() < endPoint.getX()) ? startPoint.getX() : endPoint.getX();
69
        double top = (startPoint.getY() < endPoint.getY()) ? startPoint.getY() : endPoint.getY();
70
        
71
        return new Point((int)left, (int)top);
72
    }
73
    
74
    /* Return the bottom-right point */
75
    protected Point getBottomRight(){
76
        double right = (startPoint.getX() > endPoint.getX()) ? startPoint.getX() : endPoint.getX();
77
        double bottom = (startPoint.getY() > endPoint.getY()) ? startPoint.getY() : endPoint.getY();
78
        
79
        return new Point((int)right, (int)bottom);
80
    }
81
    
82
    /* Return the start point object */
83
    protected Point getStart(){
84
        return startPoint;
85
    }
86
    
87
    /*Return the end point object */
88
    protected Point getEnd(){
89
        return endPoint;
90
    }
91
    
92
    /* Return the width and height as a dimension object */
93
    protected Dimension getDimension(){
94
        return new Dimension(getWidth(), getHeight());
95
    }
96
    
97
    /* Returns a rectangle that bounds this object */
98
    public Rectangle getBounds(){
99
        return new Rectangle(getTopLeft(), getDimension());
100
    }
101
    
102
    /* Returns the line colour if the tool
103
    is complete, otherwise it returns the colour
104
    black to be used in XOR mode */
105
    protected  Color getLineColor(){
106
        return lineColor;
107
    }
108
    
109
    protected float getLineWidth(){
110
        return lineWidth;
111
    }
112
    
113
    public boolean getMemoryless(){
114
        return false;
115
    };
116
    
117
    /* Writes the current tool to the graphis object */
118
    public abstract void writeToGraphic(Graphics2D g);
119
}

Return to bug 59527