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 (+45 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.image=Image File
18
19
# New Image
20
LBL_ImageProperties=Image Properties
21
16
# ImageDataObject.ImageNode
22
# ImageDataObject.ImageNode
17
HINT_Thumbnail=Shows thumbnail.
23
HINT_Thumbnail=Shows thumbnail.
18
PROP_Thumbnail=Thumbnail
24
PROP_Thumbnail=Thumbnail
Lines 20-25 Link Here
20
# Failure to load an image
26
# Failure to load an image
21
MSG_CouldNotLoad=Could not load the image
27
MSG_CouldNotLoad=Could not load the image
22
MSG_ErrorWhileLoading=Error while loading the image (corrupted image?)
28
MSG_ErrorWhileLoading=Error while loading the image (corrupted image?)
29
# Save Image
30
LBL_CompressionLevel=Compression Level
31
MSG_CompressionLevel=Select a compression level:
32
# Convert Image
33
LBL_Format=Format
34
MSG_Format=Select a format:
35
LBL_CouldNotConvert=Convert Error
36
MSG_CouldNotConvert=Could not convert the image
37
38
# Failure to load an image
39
MSG_UserAbortSave=User aborted saving of file {0}
40
LBL_NoSaveSupport=No Save Support
41
MSG_NoSaveSupportConfirm=There is currently no save support for {0} type.\nWould you like to convert to a different format?
42
MSG_NoSaveSupport=There is currently no save support for {0} type
43
MSG_CouldNotLoad=Could not load the image
44
MSG_ErrorWhileLoading=Error while loading the image (corrupted image?)
23
# External change happened.
45
# External change happened.
24
MSG_ExternalChange=The file {0} was modified externally. Reload it?
46
MSG_ExternalChange=The file {0} was modified externally. Reload it?
25
47
Lines 31-36 Link Here
31
LBL_EnlargeFactor_Mnem=E
53
LBL_EnlargeFactor_Mnem=E
32
LBL_DecreaseFactor=Decrease Factor:
54
LBL_DecreaseFactor=Decrease Factor:
33
LBL_DecreaseFactor_Mnem=D
55
LBL_DecreaseFactor_Mnem=D
56
LBL_ConvertTo=Convert To...
57
58
# Tool labels
59
LBL_Ellipse=Ellipse
60
LBL_Rectangle=Rectangle
61
LBL_Fill=Fill
62
LBL_Line=Line
63
LBL_Select=Select
64
LBL_Polygon=Polygon
65
LBL_Pen=Pen
66
LBL_Brush=Brush
67
LBL_Arc=Arc
68
LBL_Spray=Spray
69
LBL_SetLineColor=Set Line Color
70
LBL_SetFillColor=Set Fill Color
71
72
# ColorChooser Labels
73
LBL_ForegroundColor=Choose Foreground Color
74
LBL_BackgroundColor=Choose Background Color
34
75
35
# Show/Hide grid action label
76
# Show/Hide grid action label
36
LBL_ShowHideGrid=Toggle grid
77
LBL_ShowHideGrid=Toggle grid
Lines 51-59 Link Here
51
92
52
ACS_Zoom_BTN=N/A
93
ACS_Zoom_BTN=N/A
53
94
95
ACS_Convert_BTN=N/A
96
54
ACSD_Toolbar=N/A
97
ACSD_Toolbar=N/A
55
98
56
ACSN_Toolbar=Zoom Toolbar
99
ACSN_Toolbar=Zoom Toolbar
100
101
ACSN_EditToolbar=Edit Toolbar
57
102
58
ACS_Grid_BTN=N/A
103
ACS_Grid_BTN=N/A
59
104
(-)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 40-49 Link Here
40
56
41
/** 
57
/** 
42
 * Object that represents one file containing an image.
58
 * Object that represents one file containing an image.
43
 * @author Petr Hamernik, Jaroslav Tulach, Ian Formanek, Michael Wever
59
 * @author Petr Hamernik, Jaroslav Tulach, Ian Formanek, Michael Wever, Jason Solomon
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 135-140 Link Here
135
            return new byte[0];
219
            return new byte[0];
136
        }
220
        }
137
    }
221
    }
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
    }
138
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 
Lines 142-148 Link Here
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
    }
272
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
    }
418
    
273
}
419
}
(-)image/src/org/netbeans/modules/image/ImageDisplayEdit.java (+349 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
    
349
}
(-)image/src/org/netbeans/modules/image/ImageHelp.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 image file. You can edit the file in the IDE's Image Editor.
16
</BODY></HTML>
(-)image/src/org/netbeans/modules/image/ImageSaveSupport.java (+138 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Component;
4
import java.awt.Image;
5
import java.awt.image.RenderedImage;
6
import java.io.IOException;
7
import java.io.File;
8
import java.util.Iterator;
9
import java.util.List;
10
import javax.imageio.IIOImage;
11
import javax.imageio.ImageIO;
12
import javax.imageio.ImageWriteParam;
13
import javax.imageio.ImageWriter;
14
import javax.imageio.metadata.IIOMetadata;
15
import javax.imageio.stream.FileImageOutputStream;
16
import javax.swing.JOptionPane;
17
18
import org.openide.cookies.SaveCookie;
19
import org.openide.util.NbBundle;
20
import org.openide.windows.TopComponent;
21
22
23
/**
24
 * ImageSaveSupport
25
 * @author Jason Solomon
26
 */
27
public class ImageSaveSupport implements SaveCookie {
28
    
29
    private ImageDataObject imageDataObject;
30
    
31
    private Image image;
32
33
    private String format;
34
    
35
    /** Creates a new instance of ImageSaveSupport */
36
    public ImageSaveSupport(ImageDataObject ido) {
37
        imageDataObject = ido;
38
    }
39
    
40
    /** Invoke the save operation.
41
     * @throws IOException if the object could not be saved
42
     */
43
    public void save () throws java.io.IOException {
44
        format = imageDataObject.getFormat();
45
        image = imageDataObject.getImage();
46
47
        if(saveFile()) {
48
            imageDataObject.reloadImage();
49
            imageDataObject.notifyUnmodified();
50
        }
51
        else {
52
            IOException ex = new IOException(NbBundle.getMessage(ImageSaveSupport.class, "MSG_UserAbortSave", imageDataObject.getPath()));
53
            throw ex;
54
        }
55
    }
56
    
57
    private boolean saveFile() throws IOException {
58
        boolean compressionSupported;
59
        Iterator writers = ImageIO.getImageWritersByFormatName(format);
60
        if(!writers.hasNext()) {
61
            if(JOptionPane.showConfirmDialog(null, NbBundle.getMessage(ImageSaveSupport.class, "MSG_NoSaveSupportConfirm", format), NbBundle.getMessage(ImageSaveSupport.class, "LBL_NoSaveSupport"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
62
                TopComponent curComponent = TopComponent.getRegistry().getActivated();
63
                if(curComponent instanceof ImageViewer) {
64
                    ImageViewer currComponent = (ImageViewer) TopComponent.getRegistry().getActivated();
65
                    imageDataObject.convertTo(currComponent);
66
                }
67
            }
68
            IOException ex = new IOException(NbBundle.getMessage(ImageSaveSupport.class, "MSG_NoSaveSupport", format));
69
            throw ex;
70
        }
71
        ImageWriter writer = (ImageWriter)writers.next();
72
        ImageWriteParam iwp = writer.getDefaultWriteParam();
73
74
        try {
75
            compressionSupported = true;
76
            iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
77
        } catch (UnsupportedOperationException e) {
78
            compressionSupported = false;
79
            iwp = writer.getDefaultWriteParam();
80
        }
81
82
        if(compressionSupported) {
83
            return getCompression(writer, iwp);
84
        }
85
        else {
86
            return writeFile(writer, iwp, (float)0.00);
87
        }
88
    }
89
90
    private boolean getCompression(ImageWriter writer, ImageWriteParam iwp) throws IOException {
91
        String compressionStr;
92
        float compression;
93
        String dialogTitle = new String(NbBundle.getMessage(ImageSaveSupport.class, "LBL_CompressionLevel"));
94
        String dialogLabel = new String(NbBundle.getMessage(ImageSaveSupport.class, "MSG_CompressionLevel"));
95
        int i;
96
97
        String[] qualityDescTemp = iwp.getCompressionQualityDescriptions();
98
        float qualityValsTemp[] = iwp.getCompressionQualityValues();
99
        String[] qualityDesc = new String[qualityDescTemp.length + 1];
100
        float qualityVals[] = new float[qualityValsTemp.length + 1];
101
        for(i = 0; i < qualityDescTemp.length; i++) {
102
            qualityDesc[i] = qualityDescTemp[i];
103
            qualityVals[i] = qualityValsTemp[i];
104
        }
105
        qualityDesc[qualityDesc.length - 1] = "Default";
106
        qualityVals[qualityVals.length - 1] = (float)0.00;
107
108
        compressionStr = (String)JOptionPane.showInputDialog((Component)null, dialogLabel,
109
            dialogTitle, JOptionPane.QUESTION_MESSAGE, null, qualityDesc, qualityDesc[qualityDesc.length - 1]);
110
111
        if(compressionStr != null) {
112
            for(i = 0; i < qualityDesc.length; i++) {
113
                if(compressionStr.equals(qualityDesc[i]))
114
                    break;
115
            }
116
117
            compression = qualityVals[i];
118
119
            return writeFile(writer, iwp, compression);
120
        }
121
        return false;
122
    }
123
124
    private boolean writeFile(ImageWriter writer, ImageWriteParam iwp, float compression) throws IOException {
125
        String filePath = imageDataObject.getPath();
126
        IIOImage iioImage;
127
        FileImageOutputStream output;
128
129
        if(compression != (float)0.00) {
130
            iwp.setCompressionQuality(compression);
131
        }
132
        iioImage = new IIOImage((RenderedImage)image, (List)null, (IIOMetadata)null);
133
        output = new FileImageOutputStream(new File(filePath));
134
        writer.setOutput(output);
135
        writer.write((IIOMetadata)null, iioImage, iwp);
136
        return true;
137
    }
138
}
(-)image/src/org/netbeans/modules/image/ImageViewer.java (-51 / +659 lines)
Lines 17-22 Link Here
17
import java.awt.Color;
17
import java.awt.Color;
18
import java.awt.Component;
18
import java.awt.Component;
19
import java.awt.Dimension;
19
import java.awt.Dimension;
20
import java.awt.Font;
20
import java.awt.Graphics;
21
import java.awt.Graphics;
21
import java.awt.Image;
22
import java.awt.Image;
22
import java.awt.Toolkit;
23
import java.awt.Toolkit;
Lines 32-46 Link Here
32
import java.util.HashSet;
33
import java.util.HashSet;
33
import java.util.Iterator;
34
import java.util.Iterator;
34
import java.util.Set;
35
import java.util.Set;
36
import java.util.Observable;
37
import java.util.Observer;
35
import javax.swing.Action;
38
import javax.swing.Action;
39
import javax.swing.ButtonGroup;
36
import javax.swing.Icon;
40
import javax.swing.Icon;
37
import javax.swing.ImageIcon;
41
import javax.swing.ImageIcon;
38
import javax.swing.JButton;
42
import javax.swing.JButton;
43
import javax.swing.JColorChooser;
44
import javax.swing.JFormattedTextField;
39
import javax.swing.JLabel;
45
import javax.swing.JLabel;
46
import javax.swing.JOptionPane;
40
import javax.swing.JPanel;
47
import javax.swing.JPanel;
41
import javax.swing.JScrollPane;
48
import javax.swing.JScrollPane;
49
import javax.swing.JSpinner;
50
import javax.swing.JTextField;
42
import javax.swing.JToggleButton;
51
import javax.swing.JToggleButton;
43
import javax.swing.JToolBar;
52
import javax.swing.JToolBar;
53
import javax.swing.SpinnerModel;
54
import javax.swing.SpinnerNumberModel;
44
55
45
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileObject;
46
import org.openide.filesystems.FileUtil;
57
import org.openide.filesystems.FileUtil;
Lines 60-66 Link Here
60
 * @author Petr Hamernik, Ian Formanek, Lukas Tadial
71
 * @author Petr Hamernik, Ian Formanek, Lukas Tadial
61
 * @author Marian Petras
72
 * @author Marian Petras
62
 */
73
 */
63
public class ImageViewer extends CloneableTopComponent {
74
public class ImageViewer extends CloneableTopComponent implements Observer {
64
75
65
    /** Serialized version UID. */
76
    /** Serialized version UID. */
66
    static final long serialVersionUID =6960127954234034486L;
77
    static final long serialVersionUID =6960127954234034486L;
Lines 72-91 Link Here
72
    private NBImageIcon storedImage;
83
    private NBImageIcon storedImage;
73
    
84
    
74
    /** Component showing image. */
85
    /** Component showing image. */
75
    private JPanel panel;
86
    private ImageDisplayEdit panel;
76
    
87
    
77
    /** Scale of image. */
88
    /** Scale of image. */
78
    private double scale = 1.0D;
89
    private double scale = 1.0D;
79
    
90
    
80
    /** On/off grid. */
81
    private boolean showGrid = false;
82
    
83
    /** Increase/decrease factor. */
91
    /** Increase/decrease factor. */
84
    private final double changeFactor = Math.sqrt(2.0D);
92
    private final double changeFactor = Math.sqrt(2.0D);
85
    
93
    
86
    /** Grid color. */
87
    private final Color gridColor = Color.black;
88
    
89
    /** Listens for name changes. */
94
    /** Listens for name changes. */
90
    private PropertyChangeListener nameChangeL;
95
    private PropertyChangeListener nameChangeL;
91
    
96
    
Lines 93-98 Link Here
93
    private final Collection/*<JButton>*/ toolbarButtons
98
    private final Collection/*<JButton>*/ toolbarButtons
94
                                          = new ArrayList/*<JButton>*/(11);
99
                                          = new ArrayList/*<JButton>*/(11);
95
    
100
    
101
    /** The tool selected */
102
    private int Tool = 1;   
103
    
104
    /** The line width selection */
105
    private int lineWidth = 1;
106
    
107
    /** The fill type selection for rectangle and ellipse tools */
108
    private int fillType = 1;
109
    
110
    private JToggleButton oneptLine;
111
    private JToggleButton threeptLine;      
112
    private JToggleButton sixptLine; 
113
    
114
    private JToggleButton noFillRect;
115
    private JToggleButton fillRect;      
116
    private JToggleButton noLineRect;     
117
    
118
    private JToggleButton noFillEllipse;
119
    private JToggleButton fillEllipse;      
120
    private JToggleButton noLineEllipse;       
121
    
122
    private JSpinner cornerRounding;
123
    
124
    private JColorChooser fgColor = new JColorChooser();
125
    private JColorChooser bgColor = new JColorChooser();
96
    
126
    
97
    /** Default constructor. Must be here, used during de-externalization */
127
    /** Default constructor. Must be here, used during de-externalization */
98
    public ImageViewer () {
128
    public ImageViewer () {
Lines 124-129 Link Here
124
        
154
        
125
        storedObject = obj;
155
        storedObject = obj;
126
            
156
            
157
        /* Add an observer */
158
        storedObject.addObserver(this);
159
        
127
        // force closing panes in all workspaces, default is in current only
160
        // force closing panes in all workspaces, default is in current only
128
        setCloseOperation(TopComponent.CLOSE_EACH);
161
        setCloseOperation(TopComponent.CLOSE_EACH);
129
        
162
        
Lines 132-137 Link Here
132
        
165
        
133
        /* compose the whole panel: */
166
        /* compose the whole panel: */
134
        JToolBar toolbar = createToolBar();
167
        JToolBar toolbar = createToolBar();
168
        JToolBar edittoolbar = createEditToolBar();
135
        Component view;
169
        Component view;
136
        if (storedImage != null) {
170
        if (storedImage != null) {
137
            view = createImageView();
171
            view = createImageView();
Lines 142-147 Link Here
142
        setLayout(new BorderLayout());
176
        setLayout(new BorderLayout());
143
        add(view, BorderLayout.CENTER);
177
        add(view, BorderLayout.CENTER);
144
        add(toolbar, BorderLayout.NORTH);
178
        add(toolbar, BorderLayout.NORTH);
179
        add(edittoolbar, BorderLayout.WEST);
145
180
146
        getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_ImageViewer"));        
181
        getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_ImageViewer"));        
147
        
182
        
Lines 160-207 Link Here
160
    /**
195
    /**
161
     */
196
     */
162
    private Component createImageView() {
197
    private Component createImageView() {
163
        panel = new JPanel() {
198
        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);
199
        storedImage.setImageObserver(panel);
206
        panel.setPreferredSize(new Dimension(storedImage.getIconWidth(), storedImage.getIconHeight() ));
200
        panel.setPreferredSize(new Dimension(storedImage.getIconWidth(), storedImage.getIconHeight() ));
207
        JScrollPane scroll = new JScrollPane(panel);
201
        JScrollPane scroll = new JScrollPane(panel);
Lines 344-353 Link Here
344
        toolBar.addSeparator(new Dimension(11,2));
338
        toolBar.addSeparator(new Dimension(11,2));
345
        toolBar.add(button = getGridButton());
339
        toolBar.add(button = getGridButton());
346
        toolbarButtons.add(button);
340
        toolbarButtons.add(button);
341
        toolBar.addSeparator(new Dimension(11,2));
342
        toolBar.add(button = getConvertButton());
343
        toolbarButtons.add(button);
344
        
347
        
345
        
348
        return toolBar;
346
        return toolBar;
349
    }
347
    }
350
    
348
    
349
    //** Creates edittoolbar. */
350
    private JToolBar createEditToolBar() 
351
    {                
352
        /*
353
            BTN_Select=1
354
            BTN_Polygon=2
355
            BTN_Pen=3
356
            BTN_Brush=4
357
            BTN_Arc=5
358
            BTN_Line=6
359
            BTN_Rectangle=7
360
            BTN_Ellipse=8
361
            BTN_Fill=9
362
            BTN_Spray=10
363
         */
364
        
365
        ButtonGroup bgGroup = new javax.swing.ButtonGroup();
366
        ButtonGroup bgLineWidth = new javax.swing.ButtonGroup();    
367
        ButtonGroup bgRect = new javax.swing.ButtonGroup();
368
        ButtonGroup bgEllipse = new javax.swing.ButtonGroup();
369
        JToolBar editToolBar = new javax.swing.JToolBar();    
370
        editToolBar.setName (NbBundle.getBundle(ImageViewer.class).getString("ACSN_EditToolbar"));
371
        editToolBar.setOrientation(1);
372
        
373
        setLayout(null);
374
        
375
        editToolBar.setFloatable (false);
376
        
377
        JToggleButton selectTButton = new JToggleButton();
378
        editToolBar.add(selectTButton = getSelectTButton());
379
        selectTButton.setSelected(true);
380
        bgGroup.add(selectTButton);
381
        
382
        JToggleButton polygonTButton = new JToggleButton();
383
        editToolBar.add(polygonTButton = getPolygonTButton());
384
        bgGroup.add(polygonTButton);
385
        
386
        JToggleButton penTButton = new JToggleButton();
387
        editToolBar.add(penTButton = getPenTButton());
388
        bgGroup.add(penTButton);
389
390
        JToggleButton brushTButton = new JToggleButton();
391
        editToolBar.add(brushTButton = getBrushTButton());
392
        bgGroup.add(brushTButton);
393
        
394
        JToggleButton arcTButton = new JToggleButton();
395
        editToolBar.add(arcTButton = getArcTButton());
396
        bgGroup.add(arcTButton);
397
        
398
        JToggleButton lineTButton = new JToggleButton();
399
        editToolBar.add(lineTButton = getLineTButton());
400
        bgGroup.add(lineTButton);
401
402
        JToggleButton rectangleTButton = new JToggleButton();
403
        editToolBar.add(rectangleTButton = getRectangleTButton());
404
        bgGroup.add(rectangleTButton);
405
        
406
        JToggleButton ovalTButton = new JToggleButton();
407
        editToolBar.add(ovalTButton = getEllipseTButton());
408
        bgGroup.add(ovalTButton);
409
                
410
        JToggleButton fillTButton = new JToggleButton();
411
        editToolBar.add(fillTButton = getFillTButton());
412
        bgGroup.add(fillTButton);
413
414
        JToggleButton sprayTButton = new JToggleButton();
415
        editToolBar.add(sprayTButton = getSprayTButton());
416
        bgGroup.add(sprayTButton);
417
        
418
        JButton foregroundButton = new JButton();
419
        editToolBar.add(foregroundButton = getForegroundButton());
420
421
        editToolBar.addSeparator(new Dimension(2,2));        
422
        
423
        JButton backgroundButton = new JButton();
424
        editToolBar.add(backgroundButton = getBackgroundButton());
425
426
        editToolBar.addSeparator(new Dimension(2,10));                
427
        
428
        oneptLine = new JToggleButton();
429
        editToolBar.add(oneptLine = getOneptLineTButton());
430
        bgLineWidth.add(oneptLine); 
431
        oneptLine.setSelected(true);
432
        oneptLine.setVisible(false);
433
        
434
        threeptLine = new JToggleButton();
435
        editToolBar.add(threeptLine = getThreeptLineTButton());                
436
        bgLineWidth.add(threeptLine);
437
        threeptLine.setVisible(false);               
438
        
439
        sixptLine = new JToggleButton();
440
        editToolBar.add(sixptLine = getSixptLineTButton());
441
        bgLineWidth.add(sixptLine); 
442
        sixptLine.setVisible(false);               
443
        
444
        editToolBar.addSeparator(new Dimension(2,6));   
445
        
446
        noFillRect = new JToggleButton();
447
        editToolBar.add(noFillRect = getNoFillRectTButton());
448
        bgRect.add(noFillRect); 
449
        noFillRect.setSelected(true);
450
        noFillRect.setVisible(false);
451
        
452
        fillRect = new JToggleButton();
453
        editToolBar.add(fillRect = getFillRectTButton());                
454
        bgRect.add(fillRect);
455
        fillRect.setVisible(false);               
456
        
457
        noLineRect = new JToggleButton();
458
        editToolBar.add(noLineRect = getNoLineRectTButton());
459
        bgRect.add(noLineRect); 
460
        noLineRect.setVisible(false);   
461
        
462
        editToolBar.addSeparator(new Dimension(2,6));   
463
        
464
        noFillEllipse = new JToggleButton();
465
        editToolBar.add(noFillEllipse = getNoFillEllipseTButton());
466
        bgEllipse.add(noFillEllipse); 
467
        noFillEllipse.setSelected(true);
468
        noFillEllipse.setVisible(false);
469
        
470
        fillEllipse = new JToggleButton();
471
        editToolBar.add(fillEllipse = getFillEllipseTButton());                
472
        bgEllipse.add(fillEllipse);
473
        fillEllipse.setVisible(false);               
474
        
475
        noLineEllipse = new JToggleButton();
476
        editToolBar.add(noLineEllipse = getNoLineEllipseTButton());
477
        bgEllipse.add(noLineEllipse); 
478
        noLineEllipse.setVisible(false);           
479
        
480
        editToolBar.addSeparator(new Dimension(2,6));            
481
        
482
        JPanel textPanel = new JPanel();
483
        textPanel.setLayout(null);
484
        SpinnerModel cornerRoundingModel = new SpinnerNumberModel(0, 0, 100, 5);
485
        cornerRounding = new JSpinner(cornerRoundingModel);
486
        cornerRounding.setSize(32,17);
487
        
488
        JFormattedTextField tf = ((JSpinner.DefaultEditor)cornerRounding.getEditor()).getTextField();
489
        tf.setEditable(false);
490
        tf.setFont(new Font("Arial Narrow", 0, 10));
491
        tf.setBackground(Color.white);
492
493
        cornerRounding.setVisible(false);
494
        
495
        textPanel.add(cornerRounding);                     
496
        editToolBar.add(textPanel);                     
497
        
498
        add(editToolBar);                                  
499
500
        return editToolBar;
501
    }
502
    
351
    /** Updates the name and tooltip of this top component according to associated data object. */
503
    /** Updates the name and tooltip of this top component according to associated data object. */
352
    private void updateName () {
504
    private void updateName () {
353
        // update name
505
        // update name
Lines 541-546 Link Here
541
            SystemAction.get(ZoomInAction.class),
693
            SystemAction.get(ZoomInAction.class),
542
            SystemAction.get(ZoomOutAction.class),
694
            SystemAction.get(ZoomOutAction.class),
543
            SystemAction.get(CustomZoomAction.class),
695
            SystemAction.get(CustomZoomAction.class),
696
            SystemAction.get(ConvertToAction.class),
544
            null},
697
            null},
545
            oldValue);
698
            oldValue);
546
    }
699
    }
Lines 609-614 Link Here
609
        
762
        
610
        resizePanel();
763
        resizePanel();
611
        panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
764
        panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
765
        panel.setScale(scale);
612
    }
766
    }
613
    
767
    
614
    /** Return zooming factor.*/
768
    /** Return zooming factor.*/
Lines 619-624 Link Here
619
    /** Change proportion "out"*/
773
    /** Change proportion "out"*/
620
    private void scaleOut() {
774
    private void scaleOut() {
621
        scale = scale / changeFactor;
775
        scale = scale / changeFactor;
776
        panel.setScale(scale);
622
    }
777
    }
623
    
778
    
624
    /** Change proportion "in"*/
779
    /** Change proportion "in"*/
Lines 632-637 Link Here
632
        if (newComputedScale == oldComputedScale)
787
        if (newComputedScale == oldComputedScale)
633
            // Has to increase.
788
            // Has to increase.
634
            scale = newComputedScale + 1.0D;
789
            scale = newComputedScale + 1.0D;
790
        
791
        panel.setScale(scale);
792
    }
793
    
794
    public void convertTo() {
795
        try {
796
          storedObject.convertTo(this);
797
        } catch(IOException e) {
798
            JOptionPane.showMessageDialog(null, NbBundle.getMessage(ImageViewer.class, "MSG_CouldNotConvert"), NbBundle.getMessage(ImageViewer.class, "LBL_CouldNotConvert"), JOptionPane.ERROR_MESSAGE);
799
        }
800
    }
801
    
802
    public void update(Observable o, Object arg){
803
        updateView(storedObject);
804
        panel.reload(storedImage);
635
    }
805
    }
636
    
806
    
637
    /** Gets zoom button. */
807
    /** Gets zoom button. */
Lines 676-687 Link Here
676
        button.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Grid_BTN_Mnem").charAt(0));
846
        button.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Grid_BTN_Mnem").charAt(0));
677
        button.addActionListener(new ActionListener() {
847
        button.addActionListener(new ActionListener() {
678
            public void actionPerformed(ActionEvent evt) {
848
            public void actionPerformed(ActionEvent evt) {
679
                showGrid = !showGrid;
849
                panel.toggleGrid();
680
                panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
850
                panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
681
            }
851
            }
682
        });
852
        });
683
        
853
        
684
        return button;
854
        return button;
855
    }
856
    
857
    private JButton getConvertButton() {
858
        // PENDING buttons should have their own icons.
859
        JButton button = new JButton(NbBundle.getMessage(CustomZoomAction.class, "LBL_ConvertTo"));
860
        button.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_Convert_BTN"));
861
        button.addActionListener(new ActionListener() {
862
            public void actionPerformed(ActionEvent evt) {
863
                ConvertToAction sa = (ConvertToAction) SystemAction.get(ConvertToAction.class);
864
                sa.performAction();
865
            }
866
        });
867
        
868
        return button;
869
    }
870
    
871
    /** Gets ellipse button.*/
872
    private JToggleButton getEllipseTButton() {
873
        JToggleButton ellipseTButton = new JToggleButton();
874
        ellipseTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Ellipse"));
875
        ellipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/oval.gif")));
876
        ellipseTButton.setLabel("");
877
878
        ellipseTButton.addActionListener(new ActionListener() {
879
            public void actionPerformed(ActionEvent evt) {          
880
                setTool(8);
881
                setSubtoolsVisible();                
882
            }
883
        });
884
        
885
        return ellipseTButton;
886
    }        
887
    
888
    /** Gets rectangle button.*/    
889
    private JToggleButton getRectangleTButton(){
890
        JToggleButton rectangleTButton = new JToggleButton();
891
        rectangleTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Rectangle"));
892
        rectangleTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/rect.gif")));
893
        rectangleTButton.setLabel("");
894
        
895
        rectangleTButton.addActionListener(new ActionListener() {
896
            public void actionPerformed(ActionEvent evt) {                      
897
                setTool(7);
898
                setSubtoolsVisible();                
899
            }
900
        });  
901
        
902
        return rectangleTButton;
903
    }
904
905
    /** Gets fill button.*/        
906
    private JToggleButton getFillTButton(){
907
        JToggleButton fillTButton = new JToggleButton();
908
        fillTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Fill"));
909
        fillTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fill.gif")));
910
        fillTButton.setLabel("");
911
        
912
        fillTButton.addActionListener(new ActionListener() {
913
            public void actionPerformed(ActionEvent evt) {                         
914
                setTool(9);
915
                setSubtoolsVisible();                
916
            }
917
        });  
918
        
919
        return fillTButton;        
920
    }
921
922
    /** Gets line button.*/        
923
    private JToggleButton getLineTButton(){
924
        JToggleButton lineTButton = new JToggleButton();
925
        lineTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Line"));
926
        lineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/line.gif")));
927
        lineTButton.setLabel("");        
928
        lineTButton.addActionListener(new ActionListener() {
929
            public void actionPerformed(ActionEvent evt) {          
930
                setTool(6);
931
                setSubtoolsVisible();                
932
            }
933
        });  
934
        
935
        return lineTButton;        
936
    }   
937
938
    /** Gets select button.*/    
939
    private JToggleButton getSelectTButton(){
940
        JToggleButton selectTButton = new JToggleButton();        
941
        selectTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Select"));
942
        selectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/arrow.gif")));
943
        selectTButton.setLabel("");
944
945
        selectTButton.addActionListener(new ActionListener() {
946
            public void actionPerformed(ActionEvent evt) {                 
947
                setTool(1);
948
                setSubtoolsVisible();                
949
            }
950
        });  
951
        
952
        return selectTButton;
953
    }
954
    
955
    /** Gets polygon button.*/        
956
    private JToggleButton getPolygonTButton(){
957
        JToggleButton polygonTButton = new JToggleButton();
958
        polygonTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Polygon"));
959
        polygonTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/polygon.gif")));
960
        polygonTButton.setLabel("");
961
        
962
        polygonTButton.addActionListener(new ActionListener() {
963
            public void actionPerformed(ActionEvent evt) {                      
964
                setTool(2);
965
                setSubtoolsVisible();                
966
            }
967
        });  
968
        
969
        return polygonTButton;
970
    }
971
972
    /** Gets pen button.*/        
973
    private JToggleButton getPenTButton(){
974
        JToggleButton penTButton = new JToggleButton();
975
        penTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Pen"));
976
        penTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/pen.gif")));
977
        penTButton.setLabel("");
978
        
979
        penTButton.addActionListener(new ActionListener() {
980
            public void actionPerformed(ActionEvent evt) {
981
                setTool(3);
982
                setSubtoolsVisible();                
983
            }
984
        });  
985
986
        return penTButton;
987
    }
988
    
989
    /** Gets brush button.*/        
990
    private JToggleButton getBrushTButton(){
991
        JToggleButton brushTButton = new JToggleButton();
992
        brushTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Brush"));
993
        brushTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/brush.gif")));
994
        brushTButton.setLabel("");    
995
996
        brushTButton.addActionListener(new ActionListener() {
997
            public void actionPerformed(ActionEvent evt) {                            
998
                setTool(4);
999
                setSubtoolsVisible();                
1000
            }
1001
        });  
1002
1003
        return brushTButton;
1004
    }
1005
1006
    /** Gets arc button.*/        
1007
    private JToggleButton getArcTButton(){
1008
        JToggleButton arcTButton = new JToggleButton();
1009
        arcTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Arc"));
1010
        arcTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/arc.gif")));
1011
        arcTButton.setLabel("");
1012
1013
        arcTButton.addActionListener(new ActionListener() {
1014
            public void actionPerformed(ActionEvent evt) {
1015
                setTool(5);
1016
                setSubtoolsVisible();                
1017
            }
1018
        });  
1019
1020
        return arcTButton;
1021
    }
1022
    
1023
    /** Gets spray button.*/           
1024
    private JToggleButton getSprayTButton(){
1025
        JToggleButton sprayTButton = new JToggleButton();
1026
        sprayTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Spray"));
1027
        sprayTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/spray.gif")));
1028
        sprayTButton.setLabel("");
1029
1030
        sprayTButton.addActionListener(new ActionListener() {
1031
            public void actionPerformed(ActionEvent evt) {
1032
                setTool(10);
1033
                setSubtoolsVisible();                
1034
            }
1035
        });          
1036
                            
1037
        return sprayTButton;
1038
    }
1039
1040
    /** Gets foreground button.*/        
1041
    private JButton getForegroundButton(){
1042
        final JButton foregroundButton = new JButton("       ");
1043
        foregroundButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_SetLineColor"));
1044
        foregroundButton.setBackground(new Color(0, 0, 0));
1045
        foregroundButton.addActionListener(new ActionListener() 
1046
        {
1047
            public void actionPerformed(ActionEvent evt) 
1048
            {
1049
                Color newColor = fgColor.showDialog(null,NbBundle.getMessage(ImageViewer.class, "LBL_ForegroundColor"), foregroundButton.getForeground());                                
1050
                foregroundButton.setBackground(newColor);
1051
                
1052
                panel.setPrimaryColor(newColor);
1053
            }
1054
        }); 
1055
        
1056
        return foregroundButton;        
1057
    }
1058
    
1059
    /** Gets background button.*/        
1060
    private JButton getBackgroundButton(){
1061
        final JButton backgroundButton = new JButton("       "); 
1062
        backgroundButton.setBackground(new Color(128, 128, 255));       
1063
        backgroundButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_SetFillColor"));
1064
        backgroundButton.addActionListener(new ActionListener() 
1065
        {
1066
            public void actionPerformed(ActionEvent evt) 
1067
            {
1068
                Color newColor = bgColor.showDialog(null,NbBundle.getMessage(ImageViewer.class, "LBL_BackgroundColor"), backgroundButton.getBackground());                                
1069
                backgroundButton.setBackground(newColor);
1070
                                                                
1071
                panel.setSecondayColor(newColor);
1072
            }
1073
        });
1074
        
1075
        return backgroundButton;        
1076
    }
1077
    
1078
    /** Gets oneptLine button */
1079
    private JToggleButton getOneptLineTButton(){
1080
        JToggleButton oneptLineTButton = new JToggleButton();
1081
//        oneptLineTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Spray"));
1082
        oneptLineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/1ptLine.gif")));
1083
        oneptLineTButton.setLabel("");
1084
1085
        oneptLineTButton.addActionListener(new ActionListener() {
1086
            public void actionPerformed(ActionEvent evt) {
1087
                setLineWidth(1);
1088
            }
1089
        });          
1090
                            
1091
        return oneptLineTButton; 
1092
    }        
1093
    
1094
    /** Gets threeptLine button */
1095
    private JToggleButton getThreeptLineTButton(){
1096
        JToggleButton threeptLineTButton = new JToggleButton();
1097
//        threeptLineTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Spray"));
1098
        threeptLineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/3ptLine.gif")));
1099
        threeptLineTButton.setLabel("");
1100
1101
        threeptLineTButton.addActionListener(new ActionListener() {
1102
            public void actionPerformed(ActionEvent evt) {
1103
                setLineWidth(3);
1104
            }
1105
        });          
1106
                            
1107
        return threeptLineTButton; 
1108
    }    
1109
    
1110
    /** Gets sixptLine button */
1111
    private JToggleButton getSixptLineTButton(){
1112
        JToggleButton sixptLineTButton = new JToggleButton();
1113
        sixptLineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/6ptLine.gif")));
1114
        sixptLineTButton.setLabel("");
1115
1116
        sixptLineTButton.addActionListener(new ActionListener() {
1117
            public void actionPerformed(ActionEvent evt) {
1118
                setLineWidth(6);
1119
            }
1120
        });          
1121
                            
1122
        return sixptLineTButton; 
1123
    }                
1124
    
1125
    /** Gets noFillRect button */
1126
    private JToggleButton getNoFillRectTButton(){
1127
        JToggleButton noFillRectTButton = new JToggleButton();
1128
        noFillRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noFillRect.gif")));        
1129
        noFillRectTButton.setLabel("");
1130
1131
        noFillRectTButton.addActionListener(new ActionListener() {
1132
            public void actionPerformed(ActionEvent evt) {
1133
                setFillType(1);
1134
            }
1135
        });          
1136
                            
1137
        return noFillRectTButton; 
1138
    }      
1139
    
1140
    /** Gets fillRect button */
1141
    private JToggleButton getFillRectTButton(){
1142
        JToggleButton fillRectTButton = new JToggleButton();
1143
        fillRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fillRect.gif")));
1144
        fillRectTButton.setLabel("");
1145
1146
        fillRectTButton.addActionListener(new ActionListener() {
1147
            public void actionPerformed(ActionEvent evt) {
1148
                setFillType(2);
1149
            }
1150
        });          
1151
                            
1152
        return fillRectTButton; 
1153
    }        
1154
    
1155
    /** Gets noLineRect button */
1156
    private JToggleButton getNoLineRectTButton(){
1157
        JToggleButton noLineRectTButton = new JToggleButton();
1158
        noLineRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noLineRect.gif")));
1159
        noLineRectTButton.setLabel("");
1160
1161
        noLineRectTButton.addActionListener(new ActionListener() {
1162
            public void actionPerformed(ActionEvent evt) {
1163
                setFillType(3);
1164
            }
1165
        });          
1166
                            
1167
        return noLineRectTButton; 
1168
    }        
1169
    
1170
    /** Gets noFillEllipse button */
1171
    private JToggleButton getNoFillEllipseTButton(){
1172
        JToggleButton noFillEllipseTButton = new JToggleButton();
1173
        noFillEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noFillEllipse.gif")));        
1174
        noFillEllipseTButton.setLabel("");
1175
1176
        noFillEllipseTButton.addActionListener(new ActionListener() {
1177
            public void actionPerformed(ActionEvent evt) {
1178
                setFillType(1);
1179
            }
1180
        });          
1181
                            
1182
        return noFillEllipseTButton; 
1183
    }      
1184
    
1185
    /** Gets fillEllipse button */
1186
    private JToggleButton getFillEllipseTButton(){
1187
        JToggleButton fillEllipseTButton = new JToggleButton();
1188
        fillEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fillEllipse.gif")));
1189
        fillEllipseTButton.setLabel("");
1190
1191
        fillEllipseTButton.addActionListener(new ActionListener() {
1192
            public void actionPerformed(ActionEvent evt) {
1193
                setFillType(2);
1194
            }
1195
        });          
1196
                            
1197
        return fillEllipseTButton; 
1198
    }        
1199
    
1200
    /** Gets noLineEllipse button */
1201
    private JToggleButton getNoLineEllipseTButton(){
1202
        JToggleButton noLineEllipseTButton = new JToggleButton();
1203
        noLineEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noLineEllipse.gif")));
1204
        noLineEllipseTButton.setLabel("");
1205
1206
        noLineEllipseTButton.addActionListener(new ActionListener() {
1207
            public void actionPerformed(ActionEvent evt) {
1208
                setFillType(3);
1209
            }
1210
        });          
1211
                            
1212
        return noLineEllipseTButton; 
1213
    }        
1214
    
1215
    /** set the lines widths visible */
1216
    private void setSubtoolsVisible(){
1217
        switch (getTool()){
1218
            case 2:
1219
            case 5: 
1220
            case 6:
1221
            case 7:
1222
            case 8:                
1223
                oneptLine.setVisible(true);
1224
                threeptLine.setVisible(true);
1225
                sixptLine.setVisible(true);        
1226
                break;
1227
            default:
1228
                oneptLine.setVisible(false);
1229
                threeptLine.setVisible(false);
1230
                sixptLine.setVisible(false);        
1231
                break;
1232
        }
1233
        
1234
        if (getTool() == 7){ 
1235
            noFillRect.setVisible(true);
1236
            fillRect.setVisible(true);
1237
            noLineRect.setVisible(true);            
1238
            cornerRounding.setVisible(true);
1239
            setFillType(1);
1240
            noFillRect.setSelected(true);
1241
        }else{
1242
            noFillRect.setVisible(false);
1243
            fillRect.setVisible(false);
1244
            noLineRect.setVisible(false);
1245
            cornerRounding.setVisible(false);
1246
        }
1247
        
1248
        if (getTool() == 8){ 
1249
            noFillEllipse.setVisible(true);
1250
            fillEllipse.setVisible(true);
1251
            noLineEllipse.setVisible(true);
1252
            setFillType(1);
1253
            noFillEllipse.setSelected(true);
1254
        }else{
1255
            noFillEllipse.setVisible(false);
1256
            fillEllipse.setVisible(false);
1257
            noLineEllipse.setVisible(false);
1258
        }        
1259
    }
1260
    
1261
    /** Set the tool. */
1262
    public void setTool(int selection){
1263
        Tool = selection;
1264
    }
1265
    
1266
    /** Get the tool. */
1267
    public int getTool(){
1268
        return Tool;
1269
    }    
1270
    
1271
    /** Set the sub tool */
1272
    public void setLineWidth(int selection){
1273
        lineWidth = selection;
1274
    }
1275
1276
    /** Get the sub tool */    
1277
    public int getLineWidth(){
1278
        return lineWidth;
1279
    }
1280
    
1281
    /** Set the sub tool */
1282
    public void setFillType(int selection){
1283
        fillType = selection;
1284
    }
1285
1286
    /** Get the sub tool */    
1287
    public int getFillType(){
1288
        return fillType;
1289
    }    
1290
    
1291
    public int getCornerRoundingFactor() {
1292
        return ((Integer)(cornerRounding.getValue())).intValue();
685
    }
1293
    }
686
    
1294
    
687
}
1295
}
(-)image/src/org/netbeans/modules/image/ImageWizardPanel.java (+335 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Component;
6
import java.awt.Dimension;
7
import java.awt.GridBagConstraints;
8
import java.awt.GridBagLayout;
9
import java.awt.Insets;
10
import java.awt.event.ActionEvent;
11
import java.awt.event.ActionListener;
12
import java.io.File;
13
import java.util.HashSet;
14
import java.util.Iterator;
15
import java.util.Set;
16
import javax.imageio.ImageIO;
17
import javax.swing.JButton;
18
import javax.swing.JColorChooser;
19
import javax.swing.JComboBox;
20
import javax.swing.JFileChooser;
21
import javax.swing.JLabel;
22
import javax.swing.JPanel;
23
import javax.swing.JTextField;
24
import javax.swing.border.LineBorder;
25
import javax.swing.event.ChangeEvent;
26
import javax.swing.event.ChangeListener;
27
import javax.swing.event.DocumentEvent;
28
import javax.swing.event.DocumentListener;
29
30
import org.openide.WizardDescriptor;
31
import org.openide.filesystems.FileObject;
32
import org.openide.filesystems.FileUtil;
33
import org.openide.util.HelpCtx;
34
import org.openide.util.NbBundle;
35
36
import javax.swing.JOptionPane;
37
38
/**
39
 * JPanel used by the NewImageFileWizardIterator
40
 * @author Jason Solomon
41
 */
42
43
final public class ImageWizardPanel extends JPanel implements WizardDescriptor.FinishablePanel, DocumentListener {
44
    
45
    private transient Set listeners = new HashSet(1);
46
    
47
    private Color bgColor = Color.white;
48
    
49
    // Swing Components
50
    private JButton btnBrowse;
51
    private JButton btnBackground;
52
    private JColorChooser chBackground;
53
    private JComboBox cmbExt;
54
    private JFileChooser chFolder;
55
    private JLabel lblFileName;
56
    private JLabel lblExt;
57
    private JLabel lblFolder;
58
    private JLabel lblWidth;
59
    private JLabel lblHeight;
60
    private JPanel pnlTop;
61
    private JPanel pnlMid;
62
    private JPanel pnlBottom;
63
    private JPanel pnlBackground;
64
    private JTextField jtfFileName;
65
    private JTextField jtfFolder;
66
    private JTextField jtfWidth;
67
    private JTextField jtfHeight;
68
    
69
    public ImageWizardPanel() {
70
        setName(NbBundle.getMessage(ImageWizardPanel.class, "LBL_ImageProperties"));
71
        initComponents();
72
    }
73
    
74
    public Component getComponent() {
75
        return this;
76
    }
77
    
78
    public boolean isFinishPanel() {
79
        return true;
80
    }
81
    
82
    public boolean isValid() {
83
        try {
84
            if(jtfFileName.getText().equals(""))
85
                return false;
86
            
87
            File tempFile = new File(jtfFolder.getText());
88
            if (!tempFile.isDirectory())
89
                return false;
90
            
91
            int testWidth = Integer.parseInt(jtfWidth.getText());
92
            int testHeight = Integer.parseInt(jtfHeight.getText());
93
            if(testWidth <= 0 || testHeight <= 0)
94
                return false;
95
            
96
            return true;
97
        } catch(IllegalArgumentException e) {
98
            return false;
99
        }
100
    }
101
    
102
    public HelpCtx getHelp() {
103
        return null;
104
    }
105
    
106
    public void addChangeListener(ChangeListener l) {
107
        synchronized(listeners) {
108
            listeners.add(l);
109
        }
110
    }
111
    
112
    public void removeChangeListener(ChangeListener l) {
113
        synchronized(listeners) {
114
            listeners.remove(l);
115
        }
116
    }
117
    
118
    public void storeSettings(Object settings) {
119
    }
120
    
121
    public void readSettings(Object settings) {
122
    }
123
    
124
    public String getFileName() {
125
        return jtfFileName.getText();
126
    }
127
    
128
    public String getExt() {
129
        return (String)cmbExt.getSelectedItem();
130
    }
131
    
132
    public File getFolder() {
133
        return new File(jtfFolder.getText());
134
    }
135
    
136
    public int getImageWidth() {
137
        return Integer.parseInt(jtfWidth.getText());
138
    }
139
    
140
    public int getImageHeight() {
141
        return Integer.parseInt(jtfHeight.getText());
142
    }
143
    
144
    public Color getBackground() {
145
        return bgColor;
146
    }
147
    
148
    private void initComponents() {
149
        GridBagConstraints gridBagConstraints;
150
        
151
        String writerTypes[] = ImageIO.getWriterFormatNames();
152
        
153
        chBackground = new JColorChooser();
154
        
155
        chFolder = new JFileChooser();
156
        chFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
157
        chFolder.setDialogTitle("Target Folder");// Localize
158
        
159
        pnlTop = new JPanel();
160
        lblFileName = new JLabel();
161
        jtfFileName = new JTextField();
162
        lblExt = new JLabel();
163
        cmbExt = new JComboBox(writerTypes);
164
        lblFolder = new JLabel();
165
        jtfFolder = new JTextField();
166
        btnBrowse = new JButton();
167
        pnlMid = new JPanel();
168
        lblWidth = new JLabel();
169
        jtfWidth = new JTextField();
170
        lblHeight = new JLabel();
171
        jtfHeight = new JTextField();
172
        pnlBottom = new JPanel();
173
        btnBackground = new JButton();
174
        pnlBackground = new JPanel();
175
        
176
        jtfFileName.getDocument().addDocumentListener(this);
177
        jtfFolder.getDocument().addDocumentListener(this);
178
        jtfWidth.getDocument().addDocumentListener(this);
179
        jtfHeight.getDocument().addDocumentListener(this);
180
        
181
        btnBackground.addActionListener(
182
            new ActionListener() {
183
                public void actionPerformed(ActionEvent e) {
184
                    Color newBGColor = chBackground.showDialog(null, "Background Color"/*Localize*/, Color.white);
185
                    if(newBGColor != null) {
186
                        bgColor = newBGColor;
187
                    }
188
                    pnlBackground.setBackground(bgColor);
189
                }
190
            }
191
        );
192
        
193
        btnBrowse.addActionListener(
194
            new ActionListener() {
195
                public void actionPerformed(ActionEvent e) {
196
                    if(chFolder.showDialog(null, "Select"/*Localize*/) == JFileChooser.APPROVE_OPTION) {
197
                        File tempFolder = chFolder.getSelectedFile();
198
                        jtfFolder.setText(tempFolder.getPath());
199
                    }
200
                }
201
            }
202
        );
203
        
204
        setLayout(new BorderLayout());
205
        
206
        pnlTop.setLayout(new GridBagLayout());
207
208
        lblFileName.setText("File Name:"); //Localize
209
        gridBagConstraints = new GridBagConstraints();
210
        gridBagConstraints.anchor = GridBagConstraints.WEST;
211
        gridBagConstraints.insets = new Insets(30, 12, 0, 0);
212
        pnlTop.add(lblFileName, gridBagConstraints);
213
214
        jtfFileName.setText("newImage");
215
        jtfFileName.setPreferredSize(new Dimension(200, 23));
216
        jtfFileName.setMinimumSize(new Dimension(200, 23));
217
        gridBagConstraints = new GridBagConstraints();
218
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
219
        gridBagConstraints.weightx = 1.0;
220
        gridBagConstraints.insets = new Insets(29, 11, 0, 11);
221
        pnlTop.add(jtfFileName, gridBagConstraints);
222
223
        lblExt.setText("Ext:"); // Localize
224
        gridBagConstraints = new GridBagConstraints();
225
        gridBagConstraints.insets = new Insets(30, 12, 0, 0);
226
        pnlTop.add(lblExt, gridBagConstraints);
227
228
        cmbExt.setPreferredSize(new Dimension(60, 22));
229
        cmbExt.setMinimumSize(new Dimension(60, 22));
230
        gridBagConstraints = new GridBagConstraints();
231
        gridBagConstraints.insets = new Insets(29, 11, 0, 11);
232
        pnlTop.add(cmbExt, gridBagConstraints);
233
234
        lblFolder.setText("Folder:"); //Localize
235
        gridBagConstraints = new GridBagConstraints();
236
        gridBagConstraints.gridx = 0;
237
        gridBagConstraints.gridy = 1;
238
        gridBagConstraints.anchor = GridBagConstraints.WEST;
239
        gridBagConstraints.insets = new Insets(12, 12, 0, 0);
240
        pnlTop.add(lblFolder, gridBagConstraints);
241
242
        jtfFolder.setPreferredSize(new Dimension(250, 23));
243
        jtfFolder.setMinimumSize(new Dimension(250, 23));
244
        gridBagConstraints = new GridBagConstraints();
245
        gridBagConstraints.gridx = 1;
246
        gridBagConstraints.gridy = 1;
247
        gridBagConstraints.gridwidth = 2;
248
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
249
        gridBagConstraints.weightx = 2.0;
250
        gridBagConstraints.insets = new Insets(12, 11, 0, 11);
251
        pnlTop.add(jtfFolder, gridBagConstraints);
252
253
        btnBrowse.setText("Browse"); //Localize
254
        btnBrowse.setPreferredSize(new Dimension(75, 27));
255
        gridBagConstraints = new GridBagConstraints();
256
        gridBagConstraints.gridx = 3;
257
        gridBagConstraints.gridy = 1;
258
        gridBagConstraints.insets = new Insets(12, 11, 0, 11);
259
        pnlTop.add(btnBrowse, gridBagConstraints);
260
261
        add(pnlTop, BorderLayout.NORTH);
262
        
263
        pnlMid.setLayout(new GridBagLayout());
264
265
        lblWidth.setText("Width:"); //Localize
266
        gridBagConstraints = new GridBagConstraints();
267
        gridBagConstraints.anchor = GridBagConstraints.WEST;
268
        gridBagConstraints.insets = new Insets(20, 100, 0, 0);
269
        pnlMid.add(lblWidth, gridBagConstraints);
270
271
        jtfWidth.setText("200");
272
        jtfWidth.setPreferredSize(new Dimension(60, 23));
273
        jtfWidth.setMinimumSize(new Dimension(60, 23));
274
        gridBagConstraints = new GridBagConstraints();
275
        gridBagConstraints.insets = new Insets(19, 11, 0, 11);
276
        pnlMid.add(jtfWidth, gridBagConstraints);
277
278
        lblHeight.setText("Height:"); //Localize
279
        gridBagConstraints = new GridBagConstraints();
280
        gridBagConstraints.insets = new Insets(20, 12, 0, 0);
281
        pnlMid.add(lblHeight, gridBagConstraints);
282
283
        jtfHeight.setText("200");
284
        jtfHeight.setPreferredSize(new Dimension(60, 23));
285
        jtfHeight.setMinimumSize(new Dimension(60, 23));
286
        gridBagConstraints = new GridBagConstraints();
287
        gridBagConstraints.insets = new Insets(19, 11, 0, 100);
288
        pnlMid.add(jtfHeight, gridBagConstraints);
289
290
        add(pnlMid, BorderLayout.CENTER);
291
        
292
        pnlBottom.setLayout(new GridBagLayout());
293
294
        btnBackground.setText("Background"); //Localize
295
        gridBagConstraints = new GridBagConstraints();
296
        gridBagConstraints.insets = new Insets(30, 11, 30, 11);
297
        pnlBottom.add(btnBackground, gridBagConstraints);
298
299
        pnlBackground.setLayout(null);
300
301
        pnlBackground.setBackground(Color.white);
302
        pnlBackground.setBorder(new LineBorder(Color.black));
303
        pnlBackground.setPreferredSize(new Dimension(40, 40));
304
        gridBagConstraints = new GridBagConstraints();
305
        gridBagConstraints.insets = new Insets(0, 0, 2, 0);
306
        pnlBottom.add(pnlBackground, gridBagConstraints);
307
308
        add(pnlBottom, BorderLayout.SOUTH);
309
    }
310
    
311
    public void insertUpdate(DocumentEvent e) {
312
        ChangeEvent ce = new ChangeEvent(this);
313
        Iterator it = listeners.iterator();
314
        while (it.hasNext()) {
315
            ((ChangeListener)it.next()).stateChanged(ce);
316
        }
317
    }
318
    
319
    public void removeUpdate(DocumentEvent e) {
320
        ChangeEvent ce = new ChangeEvent(this);
321
        Iterator it = listeners.iterator();
322
        while (it.hasNext()) {
323
            ((ChangeListener)it.next()).stateChanged(ce);
324
        }
325
    }
326
    
327
    public void changedUpdate(DocumentEvent e) {
328
        ChangeEvent ce = new ChangeEvent(this);
329
        Iterator it = listeners.iterator();
330
        while (it.hasNext()) {
331
            ((ChangeListener)it.next()).stateChanged(ce);
332
        }
333
    }
334
    
335
}
(-)image/src/org/netbeans/modules/image/Layer.xml (-2 / +17 lines)
Lines 19-33 Link Here
19
        <folder name="View">
19
        <folder name="View">
20
            <file name="org.netbeans.modules.image.ZoomInAction.instance" />
20
            <file name="org.netbeans.modules.image.ZoomInAction.instance" />
21
            <file name="org.netbeans.modules.image.ZoomOutAction.instance" />
21
            <file name="org.netbeans.modules.image.ZoomOutAction.instance" />
22
	    <file name="org.netbeans.modules.image.CustomZoomAction.instance"/>
22
            <file name="org.netbeans.modules.image.CustomZoomAction.instance"/>
23
            <file name="org.netbeans.modules.image.ConvertToAction.instance" />
23
        </folder>
24
        </folder>
24
    </folder>
25
    </folder>
25
26
    
26
    <folder name="Services">
27
    <folder name="Services">
27
        <folder name="MIMEResolver">
28
        <folder name="MIMEResolver">
28
            <file name="org-netbeans-modules-image-mime-resolver.xml" url="mime-resolver.xml">
29
            <file name="org-netbeans-modules-image-mime-resolver.xml" url="mime-resolver.xml">
29
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.image.Bundle"/>
30
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.image.Bundle"/>
30
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/image/imageObject.gif"/>
31
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/image/imageObject.gif"/>
32
            </file>
33
        </folder>
34
    </folder>
35
    
36
    <folder name="Templates">
37
        <attr name="API_Support/Other" boolvalue="true"/>
38
        <folder name="Other">
39
            <file name="image.image" url="image.image">
40
                <attr name="template" boolvalue="true" />
41
                <attr name="templateWizardURL" urlvalue="nbresloc:/org/netbeans/modules/image/ImageHelp.html" />
42
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.image.Bundle" />
43
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/image/imageObject.gif"/>
44
                <attr name="instantiatingIterator" methodValue="org.netbeans.modules.image.NewImageFileWizardIterator.createImageTemplateIterator" />
45
                <attr name="templateCategory" stringvalue="simple-files"/>
31
            </file>
46
            </file>
32
        </folder>
47
        </folder>
33
    </folder>
48
    </folder>
(-)image/src/org/netbeans/modules/image/NBImageIcon.java (+5 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
    }
103
    
99
}
104
}
(-)image/src/org/netbeans/modules/image/NewImageFileWizardIterator.java (+155 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Component;
4
import java.awt.Color;
5
import java.awt.Graphics;
6
import java.awt.image.BufferedImage;
7
import java.awt.image.RenderedImage;
8
import java.io.File;
9
import java.io.IOException;
10
import java.util.Collections;
11
import java.util.HashSet;
12
import java.util.Iterator;
13
import java.util.NoSuchElementException;
14
import java.util.Set;
15
import javax.imageio.ImageIO;
16
import javax.imageio.ImageWriter;
17
import javax.imageio.stream.FileImageOutputStream;
18
import javax.swing.JComponent;
19
import javax.swing.event.ChangeListener;
20
21
import org.openide.WizardDescriptor;
22
import org.openide.filesystems.FileObject;
23
import org.openide.filesystems.FileUtil;
24
25
/**
26
 * Wizard to create a new Image file.
27
 * @author Jason Solomon
28
 */
29
public class NewImageFileWizardIterator implements WizardDescriptor.InstantiatingIterator {
30
    
31
    private transient WizardDescriptor wizard;
32
    
33
    private transient WizardDescriptor.Panel[] panels;
34
    
35
    private transient int index;
36
    
37
    private transient Set listeners = new HashSet(1);
38
    
39
    /** Create a new wizard iterator. */
40
    public NewImageFileWizardIterator() {
41
    }
42
    
43
    public void initialize(WizardDescriptor wizard) {        
44
        this.wizard = wizard;
45
        index = 0;
46
        
47
        panels = new ImageWizardPanel[1];
48
        panels[0] = new ImageWizardPanel();
49
        
50
        // Make sure list of steps is accurate.
51
        String[] beforeSteps = null;
52
        Object prop = wizard.getProperty ("WizardPanel_contentData");
53
        if (prop != null && prop instanceof String[]) {
54
            beforeSteps = (String[])prop;
55
        }
56
        
57
        assert panels != null;
58
        
59
        int diff = 0;
60
        if (beforeSteps == null) {
61
            beforeSteps = new String[0];
62
        } else if (beforeSteps.length > 0) {
63
            diff = ("...".equals(beforeSteps[beforeSteps.length - 1])) ? 1 : 0;
64
        }
65
        String[] steps = new String[(beforeSteps.length - diff) + panels.length];
66
        for (int i = 0; i < steps.length; i++) {
67
            if (i < (beforeSteps.length - diff)) {
68
                steps[i] = beforeSteps[i];
69
            } else {
70
                steps[i] = panels[i - beforeSteps.length + diff].getComponent().getName();
71
            }
72
        }
73
        for (int i = 0; i < panels.length; i++) {
74
            Component c = panels[i].getComponent();
75
            if (steps[i] == null) {
76
                steps[i] = c.getName();
77
            }
78
            if (c instanceof JComponent) {
79
                JComponent jc = (JComponent)c;
80
                jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i));
81
                jc.putClientProperty("WizardPanel_contentData", steps);
82
            }
83
        }
84
    }
85
    
86
    public Set instantiate() throws IOException {
87
        String fileName = ((ImageWizardPanel)(panels[index])).getFileName();
88
        String ext = ((ImageWizardPanel)(panels[index])).getExt();
89
        File folder = ((ImageWizardPanel)(panels[index])).getFolder();
90
        int width = ((ImageWizardPanel)(panels[index])).getImageWidth();
91
        int height = ((ImageWizardPanel)(panels[index])).getImageHeight();
92
        Color bgColor = ((ImageWizardPanel)(panels[index])).getBackground();
93
        
94
        File newFile =  new File(folder, fileName + "." + ext);
95
        BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
96
        Graphics g = newImage.getGraphics();
97
        g.setColor(bgColor);
98
        g.fillRect(0, 0, width, height);
99
        Iterator writers = ImageIO.getImageWritersByFormatName(ext);
100
        ImageWriter writer = (ImageWriter)writers.next();
101
        FileImageOutputStream output = new FileImageOutputStream(newFile);
102
        writer.setOutput(output);
103
        writer.write((RenderedImage)newImage);
104
        FileObject pf = FileUtil.toFileObject(newFile);
105
        
106
        return Collections.singleton(pf);
107
    }
108
    
109
    public void uninitialize(WizardDescriptor wizard) {
110
        this.wizard = null;
111
    }
112
    
113
    public String name() {
114
        return "";
115
    }
116
    
117
    public final void addChangeListener(ChangeListener l) {
118
        synchronized(listeners) {
119
            listeners.add(l);
120
        }
121
    }
122
    
123
    public final void removeChangeListener(ChangeListener l) {
124
        synchronized(listeners) {
125
            listeners.remove(l);
126
        }
127
    }
128
    
129
    public boolean hasNext() {
130
        return index < panels.length - 1;
131
    }
132
    
133
    public boolean hasPrevious() {
134
        return index > 0;
135
    }
136
    
137
    public void nextPanel() {
138
        if (!hasNext()) throw new NoSuchElementException();
139
        index++;
140
    }
141
    
142
    public void previousPanel() {
143
        if (!hasPrevious()) throw new NoSuchElementException();
144
        index--;
145
    }
146
    
147
    public WizardDescriptor.Panel current() {
148
        return panels[index];
149
    }
150
    
151
    public static WizardDescriptor.InstantiatingIterator createImageTemplateIterator() {
152
        return new NewImageFileWizardIterator ();
153
    }
154
    
155
}
(-)image/src/org/netbeans/modules/image/ObservableImage.java (+13 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.util.Observable;
4
5
/**
6
 * Allows a public call to the setChanged() method of Observable
7
 * @author Jason Solomon
8
 */
9
public class ObservableImage extends Observable {
10
    public void setChanged() {
11
        super.setChanged();
12
    }
13
}
(-)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());
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