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 (+69 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
/**
17
 * Implementation of the airbrush tool
18
 *
19
 * @author Timothy Boyce
20
 */
21
class BitmapAirbrush extends BitmapTool {
22
    protected GeneralPath brushShape;
23
    Ellipse2D.Float brushArea;
24
    protected int brushSize;
25
    protected int brushSparcity;
26
    
27
    public BitmapAirbrush(int xVal, int yVal, Color c, int size, int sparcity){
28
        super(xVal, yVal, c);
29
        
30
        brushSize = size;
31
        brushSparcity = sparcity;
32
    }
33
    
34
    public void writeToGraphic(Graphics2D g){
35
        g.setStroke(new BasicStroke(1));
36
        g.setColor(getFillColor());
37
        g.setPaintMode();
38
        
39
        Enumeration e = pathTrace.elements();
40
        Point p = null;
41
        Point l = null;
42
        Point x = null;
43
        
44
        while(e.hasMoreElements()){
45
            p = (Point)e.nextElement();
46
            moveBrush(p);
47
            g.draw(brushShape);
48
        }
49
        
50
        pathTrace.removeAllElements();
51
        if(p != null)    pathTrace.addElement(p);
52
    }
53
    
54
    private void moveBrush(Point p){
55
        brushShape = new GeneralPath();
56
        brushArea = new Ellipse2D.Float(((float)p.x - (brushSize/2)),(float)(p.y - (brushSize/2)), (float)brushSize, (float)brushSize);
57
        
58
        /* Choose random pixils in the area */
59
        int i;
60
        for(i=0; i<Math.abs(brushSparcity); i++){
61
            Point randomPoint = new Point((int)(brushArea.getX() + (Math.random() * brushSize)), (int)(brushArea.getY() + (Math.random() * brushSize)));
62
            while(!brushArea.contains(randomPoint.x, randomPoint.y))
63
                randomPoint = new Point((int)(brushArea.getX() + (Math.random() * brushSize)), (int)(brushArea.getY() + (Math.random() * brushSize)));
64
                
65
            brushShape.moveTo(randomPoint.x, randomPoint.y);
66
            brushShape.lineTo(randomPoint.x, randomPoint.y);
67
        }
68
    }        
69
}
(-)image/src/org/netbeans/modules/image/BitmapFill.java (+114 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
import javax.swing.JOptionPane;
9
10
/**
11
 * Implimentation of the Paint Bucket Edit Tool
12
 *
13
 * @author Timothy Boyce
14
 */
15
class BitmapFill implements EditTool{
16
    
17
    /** The Color of the selected pixel */
18
    int SrcRGBColor;
19
    
20
    /** The color that the pixels will be changed to */
21
    int DstRGBColor;
22
    
23
    /** The image object to edit */
24
    BufferedImage imageObject;
25
    
26
    /** The pixels that are still to be scanned */
27
    Stack pixelStack;
28
    
29
    /** Constructor */
30
    public BitmapFill(int xVal, int yVal, Color c, BufferedImage b){
31
        imageObject = b;
32
        
33
        SrcRGBColor = imageObject.getRGB(xVal, yVal);
34
        DstRGBColor = c.getRGB();
35
        
36
        pixelStack = new Stack();
37
        
38
        seedStack(xVal, yVal);
39
    }
40
    
41
    /** Starts the paint action with the specified point */
42
    private void seedStack(int xVal, int yVal){
43
        Point currentPixel;
44
        imageObject.setRGB(xVal, yVal, DstRGBColor);
45
        /** Reset the DstRGBColor to account for web optimised images
46
        with internal colour changes */
47
        DstRGBColor = imageObject.getRGB(xVal, yVal);
48
        
49
        /* If the Src and Destination color are the same, take no action */
50
        if(SrcRGBColor == DstRGBColor)
51
            return;
52
        
53
        pixelStack.push(new Point(xVal, yVal));
54
        
55
        try{
56
            while(!pixelStack.empty()){
57
                    currentPixel = (Point)pixelStack.pop();
58
                    setPixel(currentPixel.x, currentPixel.y);
59
            }
60
        } catch (OutOfMemoryError e){
61
            dumpStack();
62
        }
63
    }
64
    
65
    /** Sets the passed pixel to the destination color, 
66
    and checks the surrounding pixels to see if they
67
    should be added to the stack for colouring */
68
    private void setPixel(int xVal, int yVal){
69
        imageObject.setRGB(xVal, yVal, DstRGBColor);
70
71
        /** Push any pixils that surround it that are also the same color
72
        onto the stack to be painted */
73
        if(isValidPoint(xVal + 1, yVal) && SrcRGBColor == imageObject.getRGB(xVal + 1, yVal))
74
            pixelStack.push(new Point(xVal + 1, yVal));
75
        if(isValidPoint(xVal - 1, yVal) && SrcRGBColor == imageObject.getRGB(xVal - 1, yVal))
76
            pixelStack.push(new Point(xVal - 1, yVal));
77
        if(isValidPoint(xVal, yVal + 1) && SrcRGBColor == imageObject.getRGB(xVal, yVal + 1))
78
            pixelStack.push(new Point(xVal, yVal + 1));
79
        if(isValidPoint(xVal, yVal - 1) && SrcRGBColor == imageObject.getRGB(xVal, yVal - 1))
80
            pixelStack.push(new Point(xVal, yVal - 1));
81
    }
82
83
    private boolean isValidPoint(int xVal, int yVal){
84
        return (xVal >= 0 && yVal >= 0 && xVal < imageObject.getWidth() && yVal < imageObject.getHeight());
85
    }
86
    
87
    private void dumpStack(){
88
        while(!pixelStack.empty()){
89
            Point p = (Point)pixelStack.pop();
90
            imageObject.setRGB(p.x, p.y, DstRGBColor);
91
        }
92
    }
93
94
    public void setDragPoint(int xVal, int yVal){
95
    }
96
    
97
    public void setReleasePoint(int xVal, int yVal){
98
    }
99
    
100
    public void setClickPoint(int xVal, int yVal){
101
    }
102
    
103
    /* Return the tool status */
104
    public boolean getToolStatus(){
105
        return true;
106
    }
107
    
108
    public boolean getMemoryless(){
109
        return false;
110
    }
111
    
112
    public void writeToGraphic(Graphics2D g){
113
    }
114
}
(-)image/src/org/netbeans/modules/image/BitmapFreehandBrush.java (+115 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
/**
16
 * Implementation of the brush tool
17
 *
18
 * @author Timothy Boyce
19
 */
20
class BitmapFreehandBrush extends BitmapTool {
21
    protected Shape brushShape;
22
    protected int brushSize;
23
    protected int brushSlant;
24
    protected int brushType;
25
    
26
    public static final int BRUSH_BOX = 1;
27
    public static final int BRUSH_CIRC = 2;
28
    public static final int BRUSH_LINE_135 = 3;
29
    public static final int BRUSH_LINE_45 = 4;
30
    
31
    private final int BRUSH_LINE = 5;
32
    private final int SLANT_135 = 1;
33
    private final int SLANT_45 = 2;
34
    
35
    public BitmapFreehandBrush(int xVal, int yVal, Color c, int size){
36
        super(xVal, yVal, c);
37
        
38
        brushSlant = SLANT_45;
39
        brushSize = size;
40
        brushType = BRUSH_BOX;
41
    }
42
43
    public BitmapFreehandBrush(int xVal, int yVal, Color c, int size, int type){
44
        super(xVal, yVal, c);
45
        
46
        if(type == BRUSH_LINE_135){
47
            brushSlant = SLANT_135;
48
            brushType = BRUSH_LINE;
49
        }
50
        else if(type == BRUSH_LINE_45){
51
            brushSlant = SLANT_45;
52
            brushType = BRUSH_LINE;
53
        }
54
        else{
55
            brushType = type;
56
            brushSlant = 0;
57
        }
58
59
        brushSize = size;
60
    }
61
    
62
    public void writeToGraphic(Graphics2D g){
63
        g.setStroke(new BasicStroke(1));
64
        g.setColor(getFillColor());
65
        g.setPaintMode();
66
        
67
        Enumeration e = pathTrace.elements();
68
        Point p = null;
69
        Point l = null;
70
        Point x = null;
71
        
72
        while(e.hasMoreElements()){
73
            p = (Point)e.nextElement();
74
            
75
            Enumeration subPoints = joinPoints(p, l).elements();
76
            
77
            while(subPoints.hasMoreElements()){
78
                x = (Point)subPoints.nextElement();
79
                moveBrush(x);
80
                g.fill(brushShape);
81
                g.draw(brushShape);
82
            }
83
            
84
            l = new Point(p.x, p.y);
85
        }
86
        
87
        pathTrace.removeAllElements();
88
        if(p != null)    pathTrace.addElement(p);
89
    }
90
    
91
    private void moveBrush(Point p){
92
        switch(brushType){
93
            case BRUSH_BOX:
94
                brushShape = new Rectangle(p.x - (brushSize/2), p.y - (brushSize/2), brushSize, brushSize);
95
            return;
96
            
97
            case BRUSH_CIRC:
98
                brushShape = new Ellipse2D.Float(((float)p.x - (brushSize/2)),(float)(p.y - (brushSize/2)), (float)brushSize, (float)brushSize);
99
            return;
100
            
101
            case BRUSH_LINE:
102
                BasicStroke b = new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
103
                if(brushSlant == SLANT_135)
104
                    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)));
105
                else
106
                    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)));
107
            return;
108
            
109
            default:
110
                brushType = BRUSH_BOX;
111
                brushShape = new Rectangle(p.x - (brushSize/2), p.y - (brushSize/2), brushSize, brushSize);
112
            return;
113
        }
114
    }
115
}
(-)image/src/org/netbeans/modules/image/BitmapFreehandLine.java (+91 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
/**
11
 * Implimentation of the Pencil Edit Tool
12
 *
13
 * @author Timothy Boyce
14
 */
15
class BitmapFreehandLine implements EditTool{
16
17
	/** Vector containing the last 3 points of the freehand line */
18
    protected Vector linePoints = new Vector(){
19
        public void addElement(Object obj){
20
            if(this.size() >= 3)
21
                this.removeElementAt(0);
22
            super.addElement(obj);
23
        }
24
    };
25
    
26
    /** General Path used for drawing */
27
    protected GeneralPath linePath;    
28
    
29
    /** Line Color used */
30
    protected Color lineColor;
31
    
32
    /** Tool status boolean */
33
    protected boolean toolStatus = false;
34
    
35
    /** Use the default super class constructior */
36
    public BitmapFreehandLine(int xVal, int yVal, Color c){
37
        linePoints.addElement(new Point(xVal, yVal));
38
        lineColor = c;
39
    }
40
    
41
    public boolean getToolStatus(){
42
        return toolStatus;
43
    }
44
    
45
    public boolean getMemoryless(){
46
        return true;
47
    }
48
    
49
    public void setDragPoint(int xVal, int yVal){
50
        linePoints.addElement(new Point(xVal, yVal));
51
    }
52
    
53
    public void setClickPoint(int xVal, int yVal){
54
        linePoints.addElement(new Point(xVal, yVal));
55
    }
56
    
57
    public void setReleasePoint(int xVal, int yVal){
58
        linePoints.addElement(new Point(xVal, yVal));
59
        toolStatus = true;
60
    }
61
    
62
    
63
    public void writeToGraphic(Graphics2D g){
64
        Point p1, p2, p3;
65
        
66
        g.setStroke(new BasicStroke(1));
67
        g.setPaintMode();
68
        g.setColor(lineColor);
69
        
70
        linePath = new GeneralPath();
71
        
72
        p1 = (Point)linePoints.firstElement();
73
        linePath.moveTo(p1.x, p1.y);
74
        
75
        if(linePoints.size() == 3)
76
            p2 = (Point)linePoints.get(1);
77
        else
78
            p2 = (Point)linePoints.lastElement();
79
        
80
        linePath.lineTo(p2.x, p2.y);
81
        
82
        if(linePoints.size()  == 2)
83
            p3 = (Point)linePoints.firstElement();
84
        else
85
            p3 = (Point)linePoints.lastElement();
86
            
87
        linePath.lineTo(p3.x, p3.y);
88
        
89
        g.draw(linePath);
90
    }
91
}
(-)image/src/org/netbeans/modules/image/BitmapTool.java (+112 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
/**
12
 * BitmapTool
13
 *
14
 * @author Timothy Boyce
15
 */
16
abstract class BitmapTool implements EditTool{
17
    protected Color fillColor;
18
    protected Vector pathTrace;
19
    
20
    protected boolean toolStatus = false;
21
    
22
    public BitmapTool(int xVal, int yVal, Color c){
23
        pathTrace = new Vector();
24
        pathTrace.addElement(new Point(xVal, yVal));
25
        
26
        fillColor = c;
27
    }
28
    
29
    public void setDragPoint(int xVal, int yVal){
30
        pathTrace.addElement(new Point(xVal, yVal));
31
    }
32
    
33
    /* Default action taken on a release */
34
    public void setReleasePoint(int xVal, int yVal){
35
        pathTrace.addElement(new Point(xVal, yVal));
36
        toolStatus = true;
37
    }
38
    
39
    /* Default action taken on a Click */
40
    public void setClickPoint(int xVal, int yVal){
41
    }
42
    
43
    /* Return the tool status */
44
    public boolean getToolStatus(){
45
        return toolStatus;
46
    }
47
    
48
    protected Color getFillColor(){
49
        return fillColor;
50
    }
51
    
52
    public boolean getMemoryless(){
53
        return true;
54
    }
55
    
56
    /* Writes the current tool to the graphis object */
57
    public abstract void writeToGraphic(Graphics2D g);
58
    
59
    protected Vector joinPoints(Point p1, Point p2){
60
        Point start, end;
61
        Vector subPath = new Vector();
62
        float m;
63
        int b;
64
        int tx, ty;
65
        
66
        if(p1 == null)
67
            return subPath;
68
        
69
        if(p2 == null){
70
            subPath.addElement(p1);
71
            return subPath;
72
        }
73
        
74
        if(p1.x - p2.x == 0){
75
            /* Vertical Line */
76
            start = (p1.y < p2.y) ? p1 : p2;
77
            end = (p1.y > p2.y) ? p1 : p2;
78
            tx = start.x;
79
            
80
            for(ty=start.y+1; ty<end.y; ty++){
81
                subPath.addElement(new Point(tx, ty));
82
            }
83
        }
84
        else{
85
            /* Calculate Garidient */
86
            m = (float)(p1.y - p2.y) / (float)(p1.x - p2.x);
87
            b = (int)(p1.y - m * p1.x); 
88
            
89
            if(Math.abs(m) > 1){
90
                /* Use Y Method */
91
                start = (p1.y < p2.y) ? p1 : p2;
92
                end = (p1.y > p2.y) ? p1 : p2;
93
                
94
                for(ty=start.y+1; ty<end.y; ty++){
95
                    tx = (int)((ty - b)/ m );
96
                    subPath.addElement(new Point(tx, ty));
97
                }
98
            }
99
            else{
100
                /* Use X Method */
101
                start = (p1.x < p2.x) ? p1 : p2;
102
                end = (p1.x > p2.x) ? p1 : p2;
103
                
104
                for(tx=start.x+1; tx<end.x; tx++){
105
                    ty = (int)(m * tx + b);
106
                    subPath.addElement(new Point(tx, ty));
107
                }
108
            }
109
        }
110
        return subPath;
111
    }
112
}
(-)image/src/org/netbeans/modules/image/Bundle.properties (+58 lines)
Lines 13-23 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
19
25
26
# ImageWizardPanel Labels
27
LBL_FolderChooser=Target Folder
28
LBL_FolderChooserBtn=Select
29
LBL_ColorChooser=Background Color
30
LBL_FileName=File Name:
31
LBL_Ext=Ext:
32
LBL_Folder=Folder:
33
LBL_BrowseBtn=Browse
34
LBL_Width=Width:
35
LBL_Height=Height:
36
LBL_BackgroundBtn=Background
37
38
# Failure to load an image
39
MSG_CouldNotLoad=Could not load the image
40
MSG_ErrorWhileLoading=Error while loading the image (corrupted image?)
41
# Save Image
42
LBL_CompressionLevel=Compression Level
43
MSG_CompressionLevel=Select a compression level:
44
# Convert Image
45
LBL_Format=Format
46
MSG_Format=Select a format:
47
LBL_CouldNotConvert=Convert Error
48
MSG_CouldNotConvert=Could not convert the image
49
20
# Failure to load an image
50
# Failure to load an image
51
MSG_UserAbortSave=User aborted saving of file {0}
52
LBL_NoSaveSupport=No Save Support
53
MSG_NoSaveSupportConfirm=There is currently no save support for {0} type.\nWould you like to convert to a different format?
54
MSG_NoSaveSupport=There is currently no save support for {0} type
21
MSG_CouldNotLoad=Could not load the image
55
MSG_CouldNotLoad=Could not load the image
22
MSG_ErrorWhileLoading=Error while loading the image (corrupted image?)
56
MSG_ErrorWhileLoading=Error while loading the image (corrupted image?)
23
# External change happened.
57
# External change happened.
Lines 31-36 Link Here
31
LBL_EnlargeFactor_Mnem=E
65
LBL_EnlargeFactor_Mnem=E
32
LBL_DecreaseFactor=Decrease Factor:
66
LBL_DecreaseFactor=Decrease Factor:
33
LBL_DecreaseFactor_Mnem=D
67
LBL_DecreaseFactor_Mnem=D
68
LBL_ConvertTo=Convert To...
69
70
# Tool labels
71
LBL_Ellipse=Ellipse
72
LBL_Eraser=Eraser
73
LBL_Rectangle=Rectangle
74
LBL_Fill=Fill
75
LBL_Line=Line
76
LBL_Select=Select
77
LBL_Polygon=Polygon
78
LBL_Pen=Pen
79
LBL_Brush=Brush
80
LBL_Arc=Arc
81
LBL_Spray=Spray
82
LBL_SetLineColor=Set Line Color
83
LBL_SetFillColor=Set Fill Color
84
85
# ColorChooser Labels
86
LBL_ForegroundColor=Choose Foreground Color
87
LBL_BackgroundColor=Choose Background Color
34
88
35
# Show/Hide grid action label
89
# Show/Hide grid action label
36
LBL_ShowHideGrid=Toggle grid
90
LBL_ShowHideGrid=Toggle grid
Lines 51-59 Link Here
51
105
52
ACS_Zoom_BTN=N/A
106
ACS_Zoom_BTN=N/A
53
107
108
ACS_Convert_BTN=N/A
109
54
ACSD_Toolbar=N/A
110
ACSD_Toolbar=N/A
55
111
56
ACSN_Toolbar=Zoom Toolbar
112
ACSN_Toolbar=Zoom Toolbar
113
114
ACSN_EditToolbar=Edit Toolbar
57
115
58
ACS_Grid_BTN=N/A
116
ACS_Grid_BTN=N/A
59
117
(-)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 (+17 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Graphics2D;
4
5
/**
6
 * Interface for all draw tools
7
 *
8
 * @author Timothy Boyce
9
 */
10
interface EditTool {
11
    public void setDragPoint(int xVal, int yVal);
12
    public void setClickPoint(int xVal, int yVal);
13
    public void setReleasePoint(int xVal, int yVal);
14
    public boolean getToolStatus();
15
    public boolean getMemoryless();
16
    public void writeToGraphic(Graphics2D g);
17
}
(-)image/src/org/netbeans/modules/image/ImageDataObject.java (-3 / +186 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;
29
import java.lang.reflect.Array;
25
import java.lang.reflect.InvocationTargetException;
30
import java.lang.reflect.InvocationTargetException;
26
import java.net.URL;
31
import java.net.URL;
32
import java.util.Iterator;
33
import java.util.Observable;
34
import java.util.Observer;
35
import javax.imageio.ImageIO;
36
import javax.imageio.ImageWriter;
37
import javax.imageio.stream.FileImageOutputStream;
27
import javax.swing.Icon;
38
import javax.swing.Icon;
28
import javax.swing.ImageIcon;
39
import javax.swing.ImageIcon;
40
import javax.swing.JFileChooser;
41
import javax.swing.JOptionPane;
42
import javax.swing.SwingUtilities;
29
43
30
import org.openide.actions.OpenAction;
44
import org.openide.actions.OpenAction;
45
import org.openide.actions.SaveAction;
46
import org.openide.cookies.OpenCookie;
31
import org.openide.filesystems.FileObject;
47
import org.openide.filesystems.FileObject;
32
import org.openide.filesystems.FileStateInvalidException;
48
import org.openide.filesystems.FileStateInvalidException;
49
import org.openide.filesystems.FileUtil;
33
import org.openide.loaders.*;
50
import org.openide.loaders.*;
34
import org.openide.nodes.*;
51
import org.openide.nodes.*;
35
import org.openide.ErrorManager;
52
import org.openide.ErrorManager;
Lines 40-49 Link Here
40
57
41
/** 
58
/** 
42
 * Object that represents one file containing an image.
59
 * Object that represents one file containing an image.
43
 * @author Petr Hamernik, Jaroslav Tulach, Ian Formanek, Michael Wever
60
 * @author Petr Hamernik, Jaroslav Tulach, Ian Formanek, Michael Wever, Jason Solomon
44
 * @author  Marian Petras
61
 * @author  Marian Petras
45
 */
62
 */
46
public class ImageDataObject extends MultiDataObject implements CookieSet.Factory {
63
public class ImageDataObject extends MultiDataObject implements CookieSet.Factory, Observer {
47
    
64
    
48
    /** Generated serialized version UID. */
65
    /** Generated serialized version UID. */
49
    static final long serialVersionUID = -6035788991669336965L;
66
    static final long serialVersionUID = -6035788991669336965L;
Lines 51-60 Link Here
51
    /** Base for image resource. */
68
    /** Base for image resource. */
52
    private static final String IMAGE_ICON_BASE = "org/netbeans/modules/image/imageObject"; // NOI18N
69
    private static final String IMAGE_ICON_BASE = "org/netbeans/modules/image/imageObject"; // NOI18N
53
    
70
    
71
    /** Image held in DataObject **/
72
    private Image image;
73
    
74
    /** Subclass of java.util.Observable */
75
    private ObservableImage obs = new ObservableImage();
76
    
54
    /** Open support for this image data object. */
77
    /** Open support for this image data object. */
55
    private transient ImageOpenSupport openSupport;
78
    private transient ImageOpenSupport openSupport;
56
    /** Print support for this image data object **/
79
    /** Print support for this image data object **/
57
    private transient ImagePrintSupport printSupport;
80
    private transient ImagePrintSupport printSupport;
81
    /** Save support for this image data object **/
82
    private transient ImageSaveSupport saveSupport;
58
 
83
 
59
    /** Constructor.
84
    /** Constructor.
60
     * @param pf primary file object for this data object
85
     * @param pf primary file object for this data object
Lines 75-80 Link Here
75
            return getOpenSupport();
100
            return getOpenSupport();
76
        else if( clazz.isAssignableFrom(ImagePrintSupport.class))
101
        else if( clazz.isAssignableFrom(ImagePrintSupport.class))
77
            return getPrintSupport();        
102
            return getPrintSupport();        
103
        else if( clazz.isAssignableFrom(ImageSaveSupport.class))
104
            return getSaveSupport();
78
        else
105
        else
79
            return null;
106
            return null;
80
    }
107
    }
Lines 101-106 Link Here
101
        return printSupport;
128
        return printSupport;
102
    }
129
    }
103
    
130
    
131
    /** Gets image save support. */
132
    protected ImageSaveSupport getSaveSupport() {
133
        if(saveSupport == null) {
134
            synchronized(this) {
135
                if(saveSupport == null)
136
                    saveSupport = new ImageSaveSupport( this );
137
            }
138
        }
139
        return saveSupport;
140
    }
141
    
142
    /** Adds save cookie and sets the modified flag. */
143
    protected void notifyModified() {
144
        String asterisk = new String(" *");
145
        
146
        getNodeDelegate().setDisplayName(getPrimaryFile().getNameExt() + asterisk);
147
        addSaveCookie();
148
        setModified(true);
149
    }
150
    
151
    /** Removes save cookie and unsets the modified flag. */
152
    protected void notifyUnmodified () {
153
        getNodeDelegate().setDisplayName(getPrimaryFile().getNameExt());
154
        removeSaveCookie();
155
        setModified(false);
156
        obs.setChanged();
157
        obs.notifyObservers();
158
    }
159
    
160
    /** Helper method. Adds save cookie to the data object. */
161
    private void addSaveCookie() {
162
        if(getCookie(ImageSaveSupport.class) == null) {
163
            getCookieSet().add(ImageSaveSupport.class, this);
164
        }
165
    }
166
    
167
    /** Helper method. Removes save cookie from the data object. */
168
    private void removeSaveCookie() {
169
        if(getCookie(ImageSaveSupport.class) != null) {
170
            getCookieSet().remove(ImageSaveSupport.class, this);
171
        }
172
    }
173
174
    /** Getter of the full path of the image file. */
175
    public String getPath() {
176
        return getPrimaryFile().getPath();
177
    }
178
179
    /** Getter of the file extension. */
180
    public String getFormat() {
181
        return getPrimaryFile().getExt().toLowerCase();
182
    }
183
184
    /** Adds Observer o to ObservableImage obs */
185
    public void addObserver(Observer o) {
186
        obs.addObserver(o);
187
    }
188
    
104
    /** Help context for this object.
189
    /** Help context for this object.
105
     * @return the help context
190
     * @return the help context
106
     */
191
     */
Lines 135-140 Link Here
135
            return new byte[0];
220
            return new byte[0];
136
        }
221
        }
137
    }
222
    }
223
    
224
    /** Clears the stored image and reloads it from the file */
225
    public Image reloadImage() throws IOException {
226
        image = null;
227
        return getImage();
228
    }
138
229
139
    // Michael Wever 26/09/2001
230
    // Michael Wever 26/09/2001
140
    /** Gets image for the image data 
231
    /** Gets image for the image data 
Lines 142-148 Link Here
142
     * @return  java.io.IOException  if an error occurs during reading
233
     * @return  java.io.IOException  if an error occurs during reading
143
     */
234
     */
144
    public Image getImage() throws IOException {
235
    public Image getImage() throws IOException {
145
        return javax.imageio.ImageIO.read(getPrimaryFile().getInputStream());
236
        if(image == null) {
237
            image = javax.imageio.ImageIO.read(getPrimaryFile().getInputStream());
238
        }
239
        return image;
146
    }
240
    }
147
241
148
242
Lines 269-273 Link Here
269
            } // End of class ThumbnailPropertyEditor.
363
            } // End of class ThumbnailPropertyEditor.
270
        } // End of class ThumbnailProperty.
364
        } // End of class ThumbnailProperty.
271
    } // End of class ImageNode.
365
    } // End of class ImageNode.
366
    
367
    public void update(Observable o, Object arg) {
368
        notifyModified();
369
    }
272
370
371
    protected void convertTo(final ImageViewer thisViewer) throws IOException {
372
        String bName = getNodeDelegate().getName();
373
        String ext;
374
        String dialogTitle = new String(NbBundle.getMessage(ImageDataObject.class, "LBL_Format"));
375
        String dialogLabel = new String(NbBundle.getMessage(ImageDataObject.class, "MSG_Format"));
376
        String tempWriterTypes[] = ImageIO.getWriterFormatNames();
377
        String writerTypes[] = new String[tempWriterTypes.length];
378
        
379
        for(int i = 0; i < writerTypes.length; i++)
380
            writerTypes[i] = new String("");
381
        
382
        int z = 0;
383
        boolean found = false;
384
        for(int x = 0; x < tempWriterTypes.length; x++) {
385
            if(x == 0 && !tempWriterTypes[x].toLowerCase().equals(getFormat())) {
386
                writerTypes[z] = tempWriterTypes[x].toLowerCase();
387
                z++;
388
            }
389
            else {
390
                for(int y = 0; y < writerTypes.length; y++) {
391
                    if(writerTypes[y].equals(tempWriterTypes[x].toLowerCase()) || tempWriterTypes[x].toLowerCase().equals(getFormat()))
392
                        found = true;
393
                }
394
                if(!found) {
395
                    writerTypes[z] = tempWriterTypes[x].toLowerCase();
396
                    z++;
397
                }
398
            }
399
            found = false;
400
        }
401
        
402
        int j = 0;
403
        while(!writerTypes[j].equals("")) {
404
            j++;
405
        }
406
        
407
        Class arrayClass = writerTypes.getClass();
408
        Class componentClass = arrayClass.getComponentType();
409
        String finalWriterTypes[] = ((String[])(Array.newInstance(componentClass, j)));
410
        
411
        for(int i = 0; i < j; i++)
412
            finalWriterTypes[i] = writerTypes[i];
413
        
414
        ext = (String)JOptionPane.showInputDialog((Component)null, dialogLabel,
415
            dialogTitle, JOptionPane.QUESTION_MESSAGE, null, finalWriterTypes, finalWriterTypes[0]);
416
        
417
        if(ext != null) {
418
            File newFile =  new File(getPrimaryFile().getParent().getPath() + "/" + bName + "." + ext);
419
            BufferedImage newImage = new BufferedImage(((BufferedImage)image).getWidth(), ((BufferedImage)image).getHeight(), BufferedImage.TYPE_INT_RGB);
420
            Graphics g = newImage.getGraphics();
421
            g.drawImage(image, 0, 0, null);
422
            Iterator writers = ImageIO.getImageWritersByFormatName(ext);
423
            ImageWriter writer = (ImageWriter)writers.next();
424
            FileImageOutputStream output = new FileImageOutputStream(newFile);
425
            writer.setOutput(output);
426
            writer.write((RenderedImage)newImage);
427
            FileObject pf = FileUtil.toFileObject(newFile);
428
            ImageDataObject newIDO = (ImageDataObject)DataObject.find(pf);
429
            final OpenCookie openCookie = (OpenCookie)newIDO.getCookie(OpenCookie.class);
430
            if (openCookie == null) {
431
                // cannot open
432
                throw new IOException(NbBundle.getMessage(ImageDataObject.class, "MSG_CouldNotConvert"));
433
            }
434
            else {
435
                if(!SwingUtilities.isEventDispatchThread()) {
436
                    Runnable doOpenClose = new Runnable() {
437
                        public void run() {
438
                            openCookie.open();
439
                            thisViewer.close();
440
                        }
441
                    };
442
                    try {
443
                        SwingUtilities.invokeAndWait(doOpenClose);
444
                    } catch(Exception e) {
445
                        JOptionPane.showMessageDialog(null, NbBundle.getMessage(ImageDataObject.class, "MSG_CouldNotConvert"), NbBundle.getMessage(ImageDataObject.class, "LBL_CouldNotConvert"), JOptionPane.ERROR_MESSAGE);
446
                    }
447
                }
448
                else {
449
                    openCookie.open();
450
                    thisViewer.close();
451
                }
452
            }
453
        }
454
    }
455
    
273
}
456
}
(-)image/src/org/netbeans/modules/image/ImageDisplayEdit.java (+430 lines)
Added Link Here
1
package org.netbeans.modules.image;
2
3
import java.awt.Color;
4
import java.awt.Cursor;
5
import java.awt.Graphics;
6
import java.awt.Graphics2D;
7
import java.awt.Point;
8
import java.awt.Dimension;
9
import java.awt.Image;
10
import java.awt.AlphaComposite;
11
import java.awt.geom.AffineTransform;
12
import java.awt.image.BufferedImage;
13
import java.awt.image.WritableRaster;
14
import java.awt.event.MouseAdapter;
15
import java.awt.event.MouseMotionAdapter;
16
import java.awt.event.MouseEvent;
17
import java.util.Observable;
18
import javax.swing.JPanel;
19
import javax.swing.ImageIcon;
20
21
import javax.swing.JOptionPane;
22
import org.openide.windows.TopComponent;
23
24
25
/**
26
 * ImageDisplayEdit
27
 * Interface between the ImageViewer and the draw tools
28
 *
29
 * @author Timothy Boyce
30
 */
31
class ImageDisplayEdit extends JPanel{
32
	
33
    /** Currently selected editTool object */
34
    private EditTool currentTool;
35
    
36
    /** Offscreen Image Objects */
37
    protected BufferedImage offScreenImage;
38
    
39
    /** Double buffer used for memoryless edit tools */
40
    protected BufferedImage memOScreenImage;
41
    
42
    /** Double buffer user for non-memoryless edit tools */
43
    protected BufferedImage nonOScreenImage;
44
    
45
    /** Primary Image Object */
46
    private BufferedImage imageObject;
47
    
48
    /** Boolean flag to ingore left clicks of the mouse */
49
    private boolean ignoreButton1 = false;
50
    
51
    /** The current scale that the image is being viewed at */
52
    private double currentScale;
53
    
54
    /** On/Off Grid */
55
    private boolean showGrid = false;
56
    
57
    /** Grid color. */
58
    private final Color gridColor = Color.black;
59
    
60
    /** Mouse pointer to be used in the image editor */
61
    private Cursor editCursor = new Cursor(Cursor.DEFAULT_CURSOR);
62
    
63
    /** Image Observer Object */
64
    private ObservableImage obs = new ObservableImage();
65
    
66
    /** The primary or foreground color, defaulted to black */
67
    private Color primary = getDefaultPrimaryColor();
68
    
69
    /** The secondary, background, or fill colour, defaulted to white */
70
    private Color secondary = getDefaultSecondaryColor();
71
       
72
    /** Line width for vector tools */
73
    private int lineWidth; 
74
           
75
    /** Static Tool Values */
76
    public static final int TOOL_DEFAULT = 1;
77
    public static final int TOOL_POLYGON = 2;
78
    public static final int TOOL_PEN = 3;
79
    public static final int TOOL_BRUSH = 4;
80
    public static final int TOOL_ARC = 5;
81
    public static final int TOOL_LINE = 6;
82
    public static final int TOOL_RECTANGLE = 7;
83
    public static final int TOOL_ELLIPSE = 8;
84
    public static final int TOOL_FILL = 9;
85
    public static final int TOOL_SPRAY = 10;
86
    public static final int TOOL_ERASER = 11;
87
    
88
    /** Tool selected */
89
    private int toolSelected = TOOL_DEFAULT;
90
    
91
    /** Static subtools for the TOOL_RECTANGLE tool
92
    and the TOOL_ELLIPSE */
93
    public static final int SUB_LINEONLY = 1;
94
    public static final int SUB_BOTH = 2;
95
    public static final int SUB_FILLONLY = 3;
96
    
97
    /** Subtool selection. Actual meaning changes depending upon
98
    the tool being used. */
99
    private int subTool = SUB_LINEONLY;
100
        
101
    /** The brush shape used */
102
    private int brushShape = BitmapFreehandBrush.BRUSH_BOX;
103
    
104
    /** The brush size */
105
    private int brushSize = 1;
106
        
107
    /** Corner rounding factor for the rectangle */
108
    private int roundingFactor;
109
    
110
    /** Class constructor
111
        sets current scale, gets acces to storedImage, and adds various
112
        action listeners */
113
    public ImageDisplayEdit(NBImageIcon storedImage, double imageScale){
114
        currentScale = imageScale;
115
        
116
        imageObject = (BufferedImage)storedImage.getImage();
117
        
118
        nonOScreenImage = new BufferedImage(imageObject.getColorModel(), (WritableRaster)imageObject.getData(), false, null);
119
        memOScreenImage = new BufferedImage(imageObject.getWidth(), imageObject.getHeight(), BufferedImage.TYPE_INT_ARGB);
120
        
121
        
122
        this.addMouseListener(new MouseAdapter(){
123
            public void mouseEntered(MouseEvent thisEvent){
124
                setCursor(editCursor);
125
            }
126
        
127
            /** Set the mouse pressed event to create a new edit tool object
128
            and setup correct imag buffers */
129
            public void mousePressed(MouseEvent thisEvent){
130
                if(currentTool == null 
131
                && thisEvent.getButton() == MouseEvent.BUTTON1
132
                && getScaledValue(thisEvent.getX(), currentScale) < imageObject.getWidth()
133
                && getScaledValue(thisEvent.getY(), currentScale) < imageObject.getHeight()
134
                )
135
                {
136
                    int sx = getScaledValue(thisEvent.getX(), currentScale);
137
                    int sy = getScaledValue(thisEvent.getY(), currentScale);
138
                    ignoreButton1 = false;
139
140
                                             
141
                    /* Switch Here */ 
142
                    switch (toolSelected){
143
                        case TOOL_DEFAULT: currentTool = null; break;
144
                        case TOOL_POLYGON: currentTool = new VectorPolygon(sx, sy, primary, lineWidth, VectorPolygon.FREEHAND_POLY); break;
145
                        case TOOL_PEN: currentTool = new BitmapFreehandLine(sx, sy, primary); break;
146
                        case TOOL_BRUSH: currentTool = new BitmapFreehandBrush(sx, sy, primary, lineWidth, brushShape); break;
147
                        case TOOL_ARC: currentTool = new VectorArc(sx, sy, primary, lineWidth); break;
148
                        case TOOL_LINE: currentTool = new VectorLine(sx, sy, primary, lineWidth); break;
149
                        case TOOL_RECTANGLE:
150
                          if(subTool == SUB_FILLONLY)
151
                            currentTool = new VectorRectangle(sx, sy, secondary, secondary, lineWidth, roundingFactor);
152
                          else if(subTool == SUB_BOTH)
153
                            currentTool = new VectorRectangle(sx, sy, primary, secondary, lineWidth, roundingFactor);
154
                          else
155
                            currentTool = new VectorRectangle(sx, sy, primary, lineWidth, roundingFactor);
156
                          break;
157
                        case TOOL_ELLIPSE: 
158
                          if(subTool == SUB_FILLONLY)
159
                            currentTool = new VectorEllipse(sx, sy, secondary, secondary, lineWidth);
160
                          else if(subTool == SUB_BOTH)
161
                            currentTool = new VectorEllipse(sx, sy, primary, secondary, lineWidth); 
162
                          else
163
                            currentTool = new VectorEllipse(sx, sy, primary, lineWidth);
164
                          break;
165
                        case TOOL_FILL: currentTool = new BitmapFill(sx, sy, primary, imageObject); break;
166
                        case TOOL_SPRAY: currentTool = new BitmapAirbrush(sx, sy, primary, lineWidth + 10, 40); break;
167
                        case TOOL_ERASER: currentTool = new BitmapFreehandBrush(sx, sy, secondary, lineWidth, BitmapFreehandBrush.BRUSH_BOX); break;
168
                        default: currentTool = null;
169
                    }
170
                    /* End Switch */
171
172
                    /* Setup memoryless or non-memoryless buffer */
173
                    offScreenImage = (currentTool != null && currentTool.getMemoryless())  ? nonOScreenImage : memOScreenImage;
174
                    repaint(0, 0, getWidth(), getHeight());
175
                }
176
                else if(currentTool != null && thisEvent.getButton() == MouseEvent.BUTTON3){
177
                    nonOScreenImage.setData(imageObject.getData());
178
                }
179
            }
180
            
181
            /** If an edit tool is in use, send it the mouse released event, and let it
182
            take actions, as are appropriate for it */
183
            public void mouseReleased(MouseEvent thisEvent){
184
                if(currentTool != null && thisEvent.getButton() == MouseEvent.BUTTON1){
185
                    int sx = getScaledValue(thisEvent.getX(), currentScale);
186
                    int sy = getScaledValue(thisEvent.getY(), currentScale);
187
                    
188
                    currentTool.setReleasePoint(sx, sy);
189
     
190
                    repaint(0, 0, getWidth(), getHeight());
191
                }
192
                if(thisEvent.getButton() == MouseEvent.BUTTON3){
193
                    currentTool = null;
194
                    repaint(0, 0, getWidth(), getHeight());
195
                }
196
            }
197
            
198
            public void mouseClicked(MouseEvent thisEvent){
199
                if(currentTool != null && thisEvent.getButton() == MouseEvent.BUTTON1){
200
                    int sx = getScaledValue(thisEvent.getX(), currentScale);
201
                    int sy = getScaledValue(thisEvent.getY(), currentScale);
202
                    
203
                    currentTool.setClickPoint(sx, sy);
204
                    
205
                    repaint(0, 0, getWidth(), getHeight());
206
                }
207
            }
208
        });
209
            
210
        this.addMouseMotionListener(new MouseMotionAdapter(){
211
            public void mouseDragged(MouseEvent thisEvent){
212
                if(currentTool != null && (thisEvent.getButton() == MouseEvent.BUTTON1 || thisEvent.getButton() == MouseEvent.NOBUTTON)){
213
                    int sx = getScaledValue(thisEvent.getX(), currentScale);
214
                    int sy = getScaledValue(thisEvent.getY(), currentScale);
215
                    
216
                    currentTool.setDragPoint(sx, sy);
217
                    repaint(0, 0, getWidth(), getHeight());
218
                }
219
            }
220
        });
221
222
        obs.addObserver(storedImage.getIDO());
223
    }
224
    
225
    /** Toggle the grid on and off */
226
    public void toggleGrid(){
227
        showGrid = !showGrid;
228
    }
229
    
230
    public void setPrimaryColor(Color newColor){
231
        primary = newColor;
232
    }
233
    
234
    public void setSecondayColor(Color newColor){
235
        secondary = newColor;
236
    };
237
    
238
    public static Color getDefaultPrimaryColor(){
239
        return new Color(0, 0, 0);
240
    };
241
    
242
    public static Color getDefaultSecondaryColor(){
243
        return new Color(255, 255, 255);
244
    };
245
    
246
    public void setToolType(int newTool){
247
      if(newTool < 1 || newTool > 11)
248
        toolSelected = TOOL_DEFAULT;
249
      else
250
        toolSelected = newTool;
251
    };
252
    
253
    public int getToolType(){
254
      return toolSelected; 
255
    }
256
    
257
    public void setRoundingFactor(int newFactor){
258
      if(newFactor < 0 || newFactor > 100)
259
        roundingFactor = 0;
260
      else
261
        roundingFactor = newFactor;
262
    }
263
    
264
    public int getRoundingFactor(){
265
        return roundingFactor;   
266
    }
267
    
268
    public void setSubTool(int newSubTool){
269
      if(newSubTool < 1 || newSubTool > 3)
270
        subTool = SUB_LINEONLY;
271
      else
272
        subTool = newSubTool; 
273
    }
274
    
275
    public int getSubTool(){
276
        return subTool;   
277
    }
278
    
279
    public void setLineWidth(int newWidth){
280
     lineWidth = newWidth; 
281
    }
282
    
283
    public int getLineWidth(){
284
        return lineWidth;   
285
    }
286
    
287
    public void setBrushType(int newType){
288
        if(newType < 1 || newType > 4)
289
            brushShape = BitmapFreehandBrush.BRUSH_BOX;
290
        else
291
            brushShape = newType;
292
    }
293
    
294
    public int getBrushType(){
295
        return brushShape;
296
    }
297
    
298
    public void setCustomCursor(Cursor newCursor){
299
        editCursor = newCursor;
300
        setCursor(editCursor);
301
    };
302
    
303
    /** Set the scaling factor of the image */
304
    public void setScale(double newScale){
305
        this.currentScale = newScale;
306
        repaint(0, 0, getHeight(), getWidth());
307
    };
308
    
309
    public double getScale(){
310
        return currentScale;    
311
    }
312
    
313
    /* Return the pixel value after applying the current
314
    zoom scale */
315
    protected int getScaledValue(int value, double scale){
316
        return (int)(value/scale);
317
    }
318
319
    public void paint(Graphics g){
320
        /** Paint the component before anything else occurs */
321
        this.paintComponent(g);
322
        
323
        Graphics2D g2D = (Graphics2D)g;
324
        
325
        if (getSize().width <= 0 || getSize().height <= 0) 
326
        return; 
327
328
        /** Draw this edit tool if the is one in use */     
329
      if(currentTool != null){
330
           Graphics2D offScreenGraphics = (Graphics2D)offScreenImage.getGraphics();
331
           AffineTransform oldTransform = g2D.getTransform();
332
           g2D.transform(AffineTransform.getScaleInstance(currentScale, currentScale));
333
           
334
           /** Drawing method for non-memoryless tools */
335
        if(!currentTool.getMemoryless()){    
336
            currentTool.writeToGraphic(offScreenGraphics);
337
            
338
            g2D.drawImage(offScreenImage, 0, 0, null);
339
            
340
            offScreenGraphics.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0));
341
            offScreenGraphics.fillRect(0, 0, offScreenImage.getWidth(), offScreenImage.getHeight());
342
            
343
            if(currentTool.getToolStatus()){
344
                    currentTool.writeToGraphic((Graphics2D)imageObject.getGraphics());
345
                    nonOScreenImage.setData(imageObject.getData());
346
                    currentTool = null;
347
                    obs.setChanged();
348
                    obs.notifyObservers();
349
                    g2D.setTransform(oldTransform);
350
                    this.paintComponent(g);
351
                }
352
        }
353
        else{
354
        /** Drawing method for memoryless tools */
355
            currentTool.writeToGraphic(offScreenGraphics);
356
            
357
            g2D.drawImage(offScreenImage,
358
              0,
359
              0,
360
              (int)(imageObject.getWidth()),
361
              (int)(imageObject.getHeight()),
362
              0,
363
              0,
364
              imageObject.getWidth(),
365
              imageObject.getHeight(),
366
              this
367
            );
368
            
369
            if(currentTool.getToolStatus()){
370
                imageObject.setData(offScreenImage.getData());
371
                currentTool = null;
372
                obs.setChanged();
373
                obs.notifyObservers();
374
            }     
375
        }    
376
        g2D.setTransform(oldTransform);
377
    }
378
    
379
    /* Draw the grid onto the screen, if it is visable */
380
    if(showGrid)
381
        drawGrid(g, imageObject.getWidth(), imageObject.getHeight());    
382
     }
383
     
384
     /** Paint the currently visable, unedited image to the component */
385
     protected void paintComponent(Graphics g) {
386
      super.paintComponent(g);
387
      g.drawImage(
388
          imageObject,
389
          0,
390
          0,
391
          (int)(getScale() * imageObject.getWidth()),
392
          (int)(getScale() *imageObject.getHeight()),
393
          0,
394
          0,
395
          imageObject.getWidth(),
396
          imageObject.getHeight(),
397
          this
398
      );
399
    }
400
    
401
    /** Attempt to draw a grid to the graphics object */
402
    private void drawGrid(Graphics g, int iconWidth, int iconHeight){
403
      int x = (int)(getScale () * iconWidth);
404
      int y = (int)(getScale () * iconHeight);
405
406
      double gridDistance = getScale();
407
408
      if(gridDistance < 2) 
409
        // Disable painting of grid if no image pixels would be visible.
410
        return;
411
412
      g.setColor(gridColor);
413
414
      double actualDistance = gridDistance;
415
      for(int i = (int)actualDistance; i < x ;actualDistance += gridDistance, i = (int)actualDistance) {
416
          g.drawLine(i,0,i,(y-1));
417
      }
418
419
      actualDistance = gridDistance;
420
      for(int j = (int)actualDistance; j < y; actualDistance += gridDistance, j = (int)actualDistance) {
421
        g.drawLine(0,j,(x-1),j);
422
      }
423
   }
424
  
425
  /** Replace the Image object in the image display editor, with a new image object */
426
  public void reload(NBImageIcon newImage){
427
        this.imageObject = (BufferedImage)newImage.getImage();
428
        repaint(0, 0, getWidth(), getHeight());
429
    }
430
}
(-)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/ImageOpenSupport.java (-1 lines)
Lines 172-175 Link Here
172
        }
172
        }
173
    } // End of nested Environment class.
173
    } // End of nested Environment class.
174
}
174
}
175
(-)image/src/org/netbeans/modules/image/ImageSaveSupport.java (+139 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
 * Support for saving images
25
 *
26
 * @author Jason Solomon
27
 */
28
public class ImageSaveSupport implements SaveCookie {
29
    
30
    private ImageDataObject imageDataObject;
31
    
32
    private Image image;
33
34
    private String format;
35
    
36
    /** Creates a new instance of ImageSaveSupport */
37
    public ImageSaveSupport(ImageDataObject ido) {
38
        imageDataObject = ido;
39
    }
40
    
41
    /** Invoke the save operation.
42
     * @throws IOException if the object could not be saved
43
     */
44
    public void save () throws java.io.IOException {
45
        format = imageDataObject.getFormat();
46
        image = imageDataObject.getImage();
47
48
        if(saveFile()) {
49
            imageDataObject.reloadImage();
50
            imageDataObject.notifyUnmodified();
51
        }
52
        else {
53
            IOException ex = new IOException(NbBundle.getMessage(ImageSaveSupport.class, "MSG_UserAbortSave", imageDataObject.getPath()));
54
            throw ex;
55
        }
56
    }
57
    
58
    private boolean saveFile() throws IOException {
59
        boolean compressionSupported;
60
        Iterator writers = ImageIO.getImageWritersByFormatName(format);
61
        if(!writers.hasNext()) {
62
            if(JOptionPane.showConfirmDialog(null, NbBundle.getMessage(ImageSaveSupport.class, "MSG_NoSaveSupportConfirm", format), NbBundle.getMessage(ImageSaveSupport.class, "LBL_NoSaveSupport"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
63
                TopComponent curComponent = TopComponent.getRegistry().getActivated();
64
                if(curComponent instanceof ImageViewer) {
65
                    ImageViewer currComponent = (ImageViewer) TopComponent.getRegistry().getActivated();
66
                    imageDataObject.convertTo(currComponent);
67
                }
68
            }
69
            IOException ex = new IOException(NbBundle.getMessage(ImageSaveSupport.class, "MSG_NoSaveSupport", format));
70
            throw ex;
71
        }
72
        ImageWriter writer = (ImageWriter)writers.next();
73
        ImageWriteParam iwp = writer.getDefaultWriteParam();
74
75
        try {
76
            compressionSupported = true;
77
            iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
78
        } catch (UnsupportedOperationException e) {
79
            compressionSupported = false;
80
            iwp = writer.getDefaultWriteParam();
81
        }
82
83
        if(compressionSupported) {
84
            return getCompression(writer, iwp);
85
        }
86
        else {
87
            return writeFile(writer, iwp, (float)0.00);
88
        }
89
    }
90
91
    private boolean getCompression(ImageWriter writer, ImageWriteParam iwp) throws IOException {
92
        String compressionStr;
93
        float compression;
94
        String dialogTitle = new String(NbBundle.getMessage(ImageSaveSupport.class, "LBL_CompressionLevel"));
95
        String dialogLabel = new String(NbBundle.getMessage(ImageSaveSupport.class, "MSG_CompressionLevel"));
96
        int i;
97
98
        String[] qualityDescTemp = iwp.getCompressionQualityDescriptions();
99
        float qualityValsTemp[] = iwp.getCompressionQualityValues();
100
        String[] qualityDesc = new String[qualityDescTemp.length + 1];
101
        float qualityVals[] = new float[qualityValsTemp.length + 1];
102
        for(i = 0; i < qualityDescTemp.length; i++) {
103
            qualityDesc[i] = qualityDescTemp[i];
104
            qualityVals[i] = qualityValsTemp[i];
105
        }
106
        qualityDesc[qualityDesc.length - 1] = "Default";
107
        qualityVals[qualityVals.length - 1] = (float)0.00;
108
109
        compressionStr = (String)JOptionPane.showInputDialog((Component)null, dialogLabel,
110
            dialogTitle, JOptionPane.QUESTION_MESSAGE, null, qualityDesc, qualityDesc[qualityDesc.length - 1]);
111
112
        if(compressionStr != null) {
113
            for(i = 0; i < qualityDesc.length; i++) {
114
                if(compressionStr.equals(qualityDesc[i]))
115
                    break;
116
            }
117
118
            compression = qualityVals[i];
119
120
            return writeFile(writer, iwp, compression);
121
        }
122
        return false;
123
    }
124
125
    private boolean writeFile(ImageWriter writer, ImageWriteParam iwp, float compression) throws IOException {
126
        String filePath = imageDataObject.getPath();
127
        IIOImage iioImage;
128
        FileImageOutputStream output;
129
130
        if(compression != (float)0.00) {
131
            iwp.setCompressionQuality(compression);
132
        }
133
        iioImage = new IIOImage((RenderedImage)image, (List)null, (IIOMetadata)null);
134
        output = new FileImageOutputStream(new File(filePath));
135
        writer.setOutput(output);
136
        writer.write((IIOMetadata)null, iioImage, iwp);
137
        return true;
138
    }
139
}
(-)image/src/org/netbeans/modules/image/ImageViewer.java (-52 / +723 lines)
Lines 13-27 Link Here
13
13
14
package org.netbeans.modules.image;
14
package org.netbeans.modules.image;
15
15
16
import java.awt.AlphaComposite;
17
import java.awt.BasicStroke;
16
import java.awt.BorderLayout;
18
import java.awt.BorderLayout;
17
import java.awt.Color;
19
import java.awt.Color;
18
import java.awt.Component;
20
import java.awt.Component;
21
import java.awt.Cursor;
19
import java.awt.Dimension;
22
import java.awt.Dimension;
23
import java.awt.FlowLayout;
24
import java.awt.Font;
20
import java.awt.Graphics;
25
import java.awt.Graphics;
26
import java.awt.Graphics2D;
27
import java.awt.Point;
28
import java.awt.GridLayout;
21
import java.awt.Image;
29
import java.awt.Image;
22
import java.awt.Toolkit;
30
import java.awt.Toolkit;
23
import java.awt.event.ActionListener;
31
import java.awt.event.ActionListener;
24
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionEvent;
33
import java.awt.geom.Line2D;
34
import java.awt.geom.Ellipse2D;
25
import java.beans.PropertyChangeEvent;
35
import java.beans.PropertyChangeEvent;
26
import java.beans.PropertyChangeListener;
36
import java.beans.PropertyChangeListener;
27
import java.io.IOException;
37
import java.io.IOException;
Lines 32-46 Link Here
32
import java.util.HashSet;
42
import java.util.HashSet;
33
import java.util.Iterator;
43
import java.util.Iterator;
34
import java.util.Set;
44
import java.util.Set;
45
import java.util.Observer;
46
import java.util.Observable;
35
import javax.swing.Action;
47
import javax.swing.Action;
48
import javax.swing.ButtonGroup;
49
import javax.swing.event.ChangeEvent;
50
import javax.swing.event.ChangeListener;
36
import javax.swing.Icon;
51
import javax.swing.Icon;
37
import javax.swing.ImageIcon;
52
import javax.swing.ImageIcon;
38
import javax.swing.JButton;
53
import javax.swing.JButton;
54
import javax.swing.JColorChooser;
55
import javax.swing.JFormattedTextField;
39
import javax.swing.JLabel;
56
import javax.swing.JLabel;
57
import javax.swing.JOptionPane;
40
import javax.swing.JPanel;
58
import javax.swing.JPanel;
41
import javax.swing.JScrollPane;
59
import javax.swing.JScrollPane;
60
import javax.swing.JSpinner;
61
import javax.swing.JTextField;
42
import javax.swing.JToggleButton;
62
import javax.swing.JToggleButton;
43
import javax.swing.JToolBar;
63
import javax.swing.JToolBar;
64
import javax.swing.SpinnerModel;
65
import javax.swing.SpinnerNumberModel;
44
66
45
import org.openide.filesystems.FileObject;
67
import org.openide.filesystems.FileObject;
46
import org.openide.filesystems.FileUtil;
68
import org.openide.filesystems.FileUtil;
Lines 57-66 Link Here
57
79
58
/**
80
/**
59
 * Top component providing a viewer for images.
81
 * Top component providing a viewer for images.
60
 * @author Petr Hamernik, Ian Formanek, Lukas Tadial
82
 * @author Petr Hamernik, Ian Formanek, Lukas Tadial, Dragan Mandic, Jason Solomon
61
 * @author Marian Petras
83
 * @author Marian Petras
62
 */
84
 */
63
public class ImageViewer extends CloneableTopComponent {
85
public class ImageViewer extends CloneableTopComponent implements Observer {
64
86
65
    /** Serialized version UID. */
87
    /** Serialized version UID. */
66
    static final long serialVersionUID =6960127954234034486L;
88
    static final long serialVersionUID =6960127954234034486L;
Lines 72-99 Link Here
72
    private NBImageIcon storedImage;
94
    private NBImageIcon storedImage;
73
    
95
    
74
    /** Component showing image. */
96
    /** Component showing image. */
75
    private JPanel panel;
97
    private ImageDisplayEdit panel;
76
    
98
    
77
    /** Scale of image. */
99
    /** Scale of image. */
78
    private double scale = 1.0D;
100
    private double scale = 1.0D;
79
    
101
    
80
    /** On/off grid. */
81
    private boolean showGrid = false;
82
    
83
    /** Increase/decrease factor. */
102
    /** Increase/decrease factor. */
84
    private final double changeFactor = Math.sqrt(2.0D);
103
    private final double changeFactor = Math.sqrt(2.0D);
85
    
104
    
86
    /** Grid color. */
87
    private final Color gridColor = Color.black;
88
    
89
    /** Listens for name changes. */
105
    /** Listens for name changes. */
90
    private PropertyChangeListener nameChangeL;
106
    private PropertyChangeListener nameChangeL;
91
    
107
    
92
    /** collection of all buttons in the toolbar */
108
    /** collection of all buttons in the toolbar */
93
    private final Collection/*<JButton>*/ toolbarButtons
109
    private final Collection/*<JButton>*/ toolbarButtons
94
                                          = new ArrayList/*<JButton>*/(11);
110
                                          = new ArrayList/*<JButton>*/(11);
111
    /** All the custom cursors used in the ImageViewer */
112
    private Cursor sprayCursor;
113
    private Cursor penCursor;
114
    private Cursor fillCursor;
115
    private Cursor brushCursor;
116
   
117
   
118
    private JToggleButton noFillRect;
119
    private JToggleButton fillRect;      
120
    private JToggleButton noLineRect;     
121
    
122
    private JToggleButton noFillEllipse;
123
    private JToggleButton fillEllipse;      
124
    private JToggleButton noLineEllipse;       
125
126
    private JToggleButton brushCircle;    
127
    private JToggleButton brushSquare;
128
    private JToggleButton brushLeft;    
129
    private JToggleButton brushRight;
130
    
131
    private JSpinner cornerRounding;
132
    private JSpinner toolSize;
95
    
133
    
134
    private JPanel cornerRoundingPanel;
135
    private JPanel linePanel;
96
    
136
    
137
    private JColorChooser fgColor = new JColorChooser();
138
    private JColorChooser bgColor = new JColorChooser();
139
97
    /** Default constructor. Must be here, used during de-externalization */
140
    /** Default constructor. Must be here, used during de-externalization */
98
    public ImageViewer () {
141
    public ImageViewer () {
99
        super();
142
        super();
Lines 123-128 Link Here
123
        TopComponent.NodeName.connect (this, obj.getNodeDelegate ());
166
        TopComponent.NodeName.connect (this, obj.getNodeDelegate ());
124
        
167
        
125
        storedObject = obj;
168
        storedObject = obj;
169
        
170
        /* Add an observer */
171
        storedObject.addObserver(this);
126
            
172
            
127
        // force closing panes in all workspaces, default is in current only
173
        // force closing panes in all workspaces, default is in current only
128
        setCloseOperation(TopComponent.CLOSE_EACH);
174
        setCloseOperation(TopComponent.CLOSE_EACH);
Lines 132-137 Link Here
132
        
178
        
133
        /* compose the whole panel: */
179
        /* compose the whole panel: */
134
        JToolBar toolbar = createToolBar();
180
        JToolBar toolbar = createToolBar();
181
        JToolBar edittoolbar = createEditToolBar();
135
        Component view;
182
        Component view;
136
        if (storedImage != null) {
183
        if (storedImage != null) {
137
            view = createImageView();
184
            view = createImageView();
Lines 142-147 Link Here
142
        setLayout(new BorderLayout());
189
        setLayout(new BorderLayout());
143
        add(view, BorderLayout.CENTER);
190
        add(view, BorderLayout.CENTER);
144
        add(toolbar, BorderLayout.NORTH);
191
        add(toolbar, BorderLayout.NORTH);
192
        add(edittoolbar, BorderLayout.WEST);
145
193
146
        getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_ImageViewer"));        
194
        getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_ImageViewer"));        
147
        
195
        
Lines 155-207 Link Here
155
        };
203
        };
156
        
204
        
157
        obj.addPropertyChangeListener(WeakListeners.propertyChange(nameChangeL, obj));
205
        obj.addPropertyChangeListener(WeakListeners.propertyChange(nameChangeL, obj));
206
        
207
        initialiseCustomCursors();
208
    }
209
    
210
    /** Laods all the custom cursors */
211
    private void initialiseCustomCursors(){
212
       Toolkit tk = Toolkit.getDefaultToolkit();
213
       sprayCursor = tk.createCustomCursor(new ImageIcon(getClass().getResource("/org/netbeans/modules/image/sprayCursor.gif")).getImage(), new Point(0, 13), "Airbrush"); // Local
214
       penCursor = tk.createCustomCursor(new ImageIcon(getClass().getResource("/org/netbeans/modules/image/penCursor.gif")).getImage(), new Point(1, 14), "Pencil"); // Local
215
       fillCursor = tk.createCustomCursor(new ImageIcon(getClass().getResource("/org/netbeans/modules/image/fillCursor.gif")).getImage(), new Point(1, 12), "Paint Bucket"); // Local
216
       brushCursor = tk.createCustomCursor(new ImageIcon(getClass().getResource("/org/netbeans/modules/image/brushCursor.gif")).getImage(), new Point(0, 14), "Brush"); // Local
158
    }
217
    }
159
    
218
    
160
    /**
219
    /**
161
     */
220
     */
162
    private Component createImageView() {
221
    private Component createImageView() {
163
        panel = new JPanel() {
222
        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);
223
        storedImage.setImageObserver(panel);
206
        panel.setPreferredSize(new Dimension(storedImage.getIconWidth(), storedImage.getIconHeight() ));
224
        panel.setPreferredSize(new Dimension(storedImage.getIconWidth(), storedImage.getIconHeight() ));
207
        JScrollPane scroll = new JScrollPane(panel);
225
        JScrollPane scroll = new JScrollPane(panel);
Lines 344-353 Link Here
344
        toolBar.addSeparator(new Dimension(11,2));
362
        toolBar.addSeparator(new Dimension(11,2));
345
        toolBar.add(button = getGridButton());
363
        toolBar.add(button = getGridButton());
346
        toolbarButtons.add(button);
364
        toolbarButtons.add(button);
365
        toolBar.addSeparator(new Dimension(11,2));
366
        toolBar.add(button = getConvertButton());
367
        toolbarButtons.add(button);
347
        
368
        
348
        return toolBar;
369
        return toolBar;
349
    }
370
    }
350
    
371
    
372
    //** Creates edittoolbar. */
373
    private JToolBar createEditToolBar() 
374
    {        
375
        ButtonGroup bgGroup = new javax.swing.ButtonGroup();
376
        ButtonGroup bgLineWidth = new javax.swing.ButtonGroup();    
377
        ButtonGroup bgRect = new javax.swing.ButtonGroup();
378
        ButtonGroup bgEllipse = new javax.swing.ButtonGroup();
379
        ButtonGroup bgBrush = new javax.swing.ButtonGroup();
380
        JToolBar editToolBar = new javax.swing.JToolBar();    
381
        editToolBar.setName (NbBundle.getBundle(ImageViewer.class).getString("ACSN_EditToolbar"));
382
        editToolBar.setOrientation(1);
383
        
384
        setLayout(null);
385
        
386
        editToolBar.setFloatable (false);
387
        
388
        JToggleButton selectTButton = new JToggleButton();
389
        editToolBar.add(selectTButton = getSelectTButton());
390
        selectTButton.setSelected(true);
391
        selectTButton.setSize(32,17);
392
        bgGroup.add(selectTButton);
393
        
394
        JToggleButton polygonTButton = new JToggleButton();
395
        editToolBar.add(polygonTButton = getPolygonTButton());
396
        bgGroup.add(polygonTButton);
397
        
398
        JToggleButton penTButton = new JToggleButton();
399
        editToolBar.add(penTButton = getPenTButton());
400
        bgGroup.add(penTButton);
401
402
        JToggleButton brushTButton = new JToggleButton();
403
        editToolBar.add(brushTButton = getBrushTButton());
404
        bgGroup.add(brushTButton);
405
406
        JToggleButton eraserTButton = new JToggleButton();
407
        editToolBar.add(eraserTButton = getEraserTButton());
408
        bgGroup.add(eraserTButton);        
409
        
410
        JToggleButton arcTButton = new JToggleButton();
411
        editToolBar.add(arcTButton = getArcTButton());
412
        bgGroup.add(arcTButton);
413
        
414
        JToggleButton lineTButton = new JToggleButton();
415
        editToolBar.add(lineTButton = getLineTButton());
416
        bgGroup.add(lineTButton);
417
418
        JToggleButton rectangleTButton = new JToggleButton();
419
        editToolBar.add(rectangleTButton = getRectangleTButton());
420
        bgGroup.add(rectangleTButton);
421
        
422
        JToggleButton ovalTButton = new JToggleButton();
423
        editToolBar.add(ovalTButton = getEllipseTButton());
424
        bgGroup.add(ovalTButton);
425
                
426
        JToggleButton fillTButton = new JToggleButton();
427
        editToolBar.add(fillTButton = getFillTButton());
428
        bgGroup.add(fillTButton);
429
430
        JToggleButton sprayTButton = new JToggleButton();
431
        editToolBar.add(sprayTButton = getSprayTButton());
432
        bgGroup.add(sprayTButton);
433
434
        editToolBar.addSeparator(new Dimension(2,4));     
435
        
436
        JButton foregroundButton = new JButton();
437
        editToolBar.add(foregroundButton = getForegroundButton());
438
439
        editToolBar.addSeparator(new Dimension(2,2));        
440
        
441
        JButton backgroundButton = new JButton();
442
        editToolBar.add(backgroundButton = getBackgroundButton());
443
444
        editToolBar.addSeparator(new Dimension(2,4));
445
446
        brushSquare = new JToggleButton();
447
        editToolBar.add(brushSquare = getBrushSquareTButton());
448
        brushSquare.setSelected(true);
449
        bgBrush.add(brushSquare);
450
        brushSquare.setVisible(false);
451
        
452
        brushCircle = new JToggleButton();
453
        editToolBar.add(brushCircle = getBrushCircleTButton());
454
        bgBrush.add(brushCircle);
455
        brushCircle.setVisible(false);           
456
457
        brushRight = new JToggleButton();
458
        editToolBar.add(brushRight = getBrushRightTButton());
459
        bgBrush.add(brushRight);
460
        brushRight.setVisible(false);
461
        
462
        brushLeft = new JToggleButton();
463
        editToolBar.add(brushLeft = getBrushLeftTButton());
464
        bgBrush.add(brushLeft);
465
        brushLeft.setVisible(false);                                 
466
        
467
        noFillRect = new JToggleButton();
468
        editToolBar.add(noFillRect = getNoFillRectTButton());
469
        bgRect.add(noFillRect); 
470
        noFillRect.setSelected(true);
471
        noFillRect.setVisible(false);
472
        
473
        fillRect = new JToggleButton();
474
        editToolBar.add(fillRect = getFillRectTButton());                
475
        bgRect.add(fillRect);
476
        fillRect.setVisible(false);               
477
        
478
        noLineRect = new JToggleButton();
479
        editToolBar.add(noLineRect = getNoLineRectTButton());
480
        bgRect.add(noLineRect); 
481
        noLineRect.setVisible(false);           
482
        
483
        noFillEllipse = new JToggleButton();
484
        editToolBar.add(noFillEllipse = getNoFillEllipseTButton());
485
        bgEllipse.add(noFillEllipse); 
486
        noFillEllipse.setSelected(true);
487
        noFillEllipse.setVisible(false);
488
        
489
        fillEllipse = new JToggleButton();
490
        editToolBar.add(fillEllipse = getFillEllipseTButton());                
491
        bgEllipse.add(fillEllipse);
492
        fillEllipse.setVisible(false);               
493
        
494
        noLineEllipse = new JToggleButton();
495
        editToolBar.add(noLineEllipse = getNoLineEllipseTButton());
496
        bgEllipse.add(noLineEllipse); 
497
        noLineEllipse.setVisible(false);           
498
        
499
        editToolBar.addSeparator(new Dimension(2,2));      
500
        
501
        linePanel = new JPanel();
502
        linePanel.setLayout(null);
503
        
504
        SpinnerModel lineWidthModel = new SpinnerNumberModel(1, 1, 40, 1);
505
        toolSize = new JSpinner(lineWidthModel);
506
        
507
        toolSize.addChangeListener(new ChangeListener() {
508
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
509
                panel.setLineWidth(((Integer)(toolSize.getValue())).intValue());
510
                changeLine();
511
            }
512
        });        
513
        toolSize.setSize(32,17);
514
        
515
        JFormattedTextField bs = ((JSpinner.DefaultEditor)toolSize.getEditor()).getTextField();
516
        bs.setEditable(false);
517
        bs.setFont(new Font("Arial Narrow", 0, 10));
518
        bs.setBackground(Color.white);
519
        
520
        linePanel.add(toolSize);
521
        linePanel.setVisible(false); 
522
        
523
        cornerRoundingPanel = new JPanel();
524
        cornerRoundingPanel.setLayout(null);
525
        
526
        SpinnerModel cornerRoundingModel = new SpinnerNumberModel(0, 0, 100, 5);
527
        cornerRounding = new JSpinner(cornerRoundingModel);
528
        cornerRounding.addChangeListener(new ChangeListener() {
529
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
530
                panel.setRoundingFactor(((Integer)(cornerRounding.getValue())).intValue());
531
            }
532
        });       
533
        cornerRounding.setSize(32,17);
534
        
535
        JFormattedTextField tf = ((JSpinner.DefaultEditor)cornerRounding.getEditor()).getTextField();
536
        tf.setEditable(false);
537
        tf.setFont(new Font("Arial Narrow", 0, 10));
538
        tf.setBackground(Color.white);       
539
540
        cornerRoundingPanel.add(cornerRounding);
541
        cornerRoundingPanel.setVisible(false);
542
        
543
        editToolBar.add(linePanel);        
544
        editToolBar.addSeparator(new Dimension(2,2));          
545
        editToolBar.add(cornerRoundingPanel);
546
        add(editToolBar);                                  
547
548
        return editToolBar;
549
    }
550
    
351
    /** Updates the name and tooltip of this top component according to associated data object. */
551
    /** Updates the name and tooltip of this top component according to associated data object. */
352
    private void updateName () {
552
    private void updateName () {
353
        // update name
553
        // update name
Lines 541-546 Link Here
541
            SystemAction.get(ZoomInAction.class),
741
            SystemAction.get(ZoomInAction.class),
542
            SystemAction.get(ZoomOutAction.class),
742
            SystemAction.get(ZoomOutAction.class),
543
            SystemAction.get(CustomZoomAction.class),
743
            SystemAction.get(CustomZoomAction.class),
744
            SystemAction.get(ConvertToAction.class),
544
            null},
745
            null},
545
            oldValue);
746
            oldValue);
546
    }
747
    }
Lines 609-614 Link Here
609
        
810
        
610
        resizePanel();
811
        resizePanel();
611
        panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
812
        panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
813
        panel.setScale(scale);
612
    }
814
    }
613
    
815
    
614
    /** Return zooming factor.*/
816
    /** Return zooming factor.*/
Lines 619-624 Link Here
619
    /** Change proportion "out"*/
821
    /** Change proportion "out"*/
620
    private void scaleOut() {
822
    private void scaleOut() {
621
        scale = scale / changeFactor;
823
        scale = scale / changeFactor;
824
        panel.setScale(scale);
622
    }
825
    }
623
    
826
    
624
    /** Change proportion "in"*/
827
    /** Change proportion "in"*/
Lines 632-637 Link Here
632
        if (newComputedScale == oldComputedScale)
835
        if (newComputedScale == oldComputedScale)
633
            // Has to increase.
836
            // Has to increase.
634
            scale = newComputedScale + 1.0D;
837
            scale = newComputedScale + 1.0D;
838
        
839
        panel.setScale(scale);
840
    }
841
    
842
    public void convertTo() {
843
        try {
844
          storedObject.convertTo(this);
845
        } catch(IOException e) {
846
            JOptionPane.showMessageDialog(null, NbBundle.getMessage(ImageViewer.class, "MSG_CouldNotConvert"), NbBundle.getMessage(ImageViewer.class, "LBL_CouldNotConvert"), JOptionPane.ERROR_MESSAGE);
847
        }
848
    }
849
    
850
    public void update(Observable o, Object arg){
851
        updateView(storedObject);
852
        panel.reload(storedImage);
635
    }
853
    }
636
    
854
    
637
    /** Gets zoom button. */
855
    /** Gets zoom button. */
Lines 676-687 Link Here
676
        button.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Grid_BTN_Mnem").charAt(0));
894
        button.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Grid_BTN_Mnem").charAt(0));
677
        button.addActionListener(new ActionListener() {
895
        button.addActionListener(new ActionListener() {
678
            public void actionPerformed(ActionEvent evt) {
896
            public void actionPerformed(ActionEvent evt) {
679
                showGrid = !showGrid;
897
                panel.toggleGrid();
680
                panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
898
                panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
681
            }
899
            }
682
        });
900
        });
683
        
901
        
684
        return button;
902
        return button;
903
    }       
904
    
905
    private JButton getConvertButton() {
906
        // PENDING buttons should have their own icons.
907
        JButton button = new JButton(NbBundle.getMessage(CustomZoomAction.class, "LBL_ConvertTo"));
908
        button.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_Convert_BTN"));
909
        button.addActionListener(new ActionListener() {
910
            public void actionPerformed(ActionEvent evt) {
911
                ConvertToAction sa = (ConvertToAction) SystemAction.get(ConvertToAction.class);
912
                sa.performAction();
913
            }
914
        });
915
        
916
        return button;
917
    }
918
    
919
    /** Gets ellipse button.*/
920
    private JToggleButton getEllipseTButton() {
921
        JToggleButton ellipseTButton = new JToggleButton();
922
        ellipseTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Ellipse"));
923
        ellipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/oval.gif")));
924
925
        ellipseTButton.addActionListener(new ActionListener() {
926
            public void actionPerformed(ActionEvent evt) {          
927
                panel.setToolType(ImageDisplayEdit.TOOL_ELLIPSE);
928
                panel.setCustomCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
929
                setSubtoolsVisible();                
930
            }
931
        });
932
        
933
        return ellipseTButton;
934
    }        
935
    
936
    /** Gets rectangle button.*/    
937
    private JToggleButton getRectangleTButton(){
938
        JToggleButton rectangleTButton = new JToggleButton();
939
        rectangleTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Rectangle"));
940
        rectangleTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/rect.gif")));
941
        
942
        rectangleTButton.addActionListener(new ActionListener() {
943
            public void actionPerformed(ActionEvent evt) {                      
944
                panel.setToolType(ImageDisplayEdit.TOOL_RECTANGLE);
945
                panel.setCustomCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
946
                setSubtoolsVisible();                
947
            }
948
        });  
949
        
950
        return rectangleTButton;
951
    }
952
953
    /** Gets fill button.*/        
954
    private JToggleButton getFillTButton(){
955
        JToggleButton fillTButton = new JToggleButton();
956
        fillTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Fill"));
957
        fillTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fill.gif")));
958
        
959
        fillTButton.addActionListener(new ActionListener() {
960
            public void actionPerformed(ActionEvent evt) {                         
961
                panel.setToolType(ImageDisplayEdit.TOOL_FILL);
962
                panel.setCustomCursor(fillCursor);
963
                setSubtoolsVisible();                
964
            }
965
        });  
966
        
967
        return fillTButton;        
968
    }
969
970
    /** Gets line button.*/        
971
    private JToggleButton getLineTButton(){
972
        JToggleButton lineTButton = new JToggleButton();
973
        lineTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Line"));
974
        lineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/line.gif")));
975
976
        lineTButton.addActionListener(new ActionListener() {
977
            public void actionPerformed(ActionEvent evt) {
978
                panel.setToolType(ImageDisplayEdit.TOOL_LINE);
979
                panel.setCustomCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
980
                setSubtoolsVisible();
981
            }
982
        });  
983
        
984
        return lineTButton;        
985
    }   
986
987
    /** Gets select button.*/    
988
    private JToggleButton getSelectTButton(){
989
        JToggleButton selectTButton = new JToggleButton();        
990
        selectTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Select"));
991
        selectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/arrow.gif")));
992
993
        selectTButton.addActionListener(new ActionListener() {
994
            public void actionPerformed(ActionEvent evt) {                 
995
                panel.setToolType(ImageDisplayEdit.TOOL_DEFAULT);
996
                panel.setCustomCursor(new Cursor(Cursor.DEFAULT_CURSOR));
997
                setSubtoolsVisible();                
998
            }
999
        });  
1000
        
1001
        return selectTButton;
1002
    }
1003
    
1004
    /** Gets polygon button.*/        
1005
    private JToggleButton getPolygonTButton(){
1006
        JToggleButton polygonTButton = new JToggleButton();
1007
        polygonTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Polygon"));
1008
        polygonTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/polygon.gif")));
1009
        
1010
        polygonTButton.addActionListener(new ActionListener() {
1011
            public void actionPerformed(ActionEvent evt) {                      
1012
                panel.setToolType(ImageDisplayEdit.TOOL_POLYGON);
1013
                panel.setCustomCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
1014
                setSubtoolsVisible();                
1015
            }
1016
        });  
1017
        
1018
        return polygonTButton;
1019
    }
1020
1021
    /** Gets pen button.*/        
1022
    private JToggleButton getPenTButton(){
1023
        JToggleButton penTButton = new JToggleButton();
1024
        penTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Pen"));
1025
        penTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/pen.gif")));
1026
        
1027
        penTButton.addActionListener(new ActionListener() {
1028
            public void actionPerformed(ActionEvent evt) {
1029
                panel.setToolType(ImageDisplayEdit.TOOL_PEN);
1030
                panel.setCustomCursor(penCursor);
1031
                setSubtoolsVisible();                
1032
            }
1033
        });  
1034
1035
        return penTButton;
1036
    }
1037
    
1038
    /** Gets eraser button.*/        
1039
    private JToggleButton getEraserTButton(){
1040
        JToggleButton eraserTButton = new JToggleButton();
1041
        eraserTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Eraser"));
1042
        eraserTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/eraser.gif")));
1043
        
1044
        eraserTButton.addActionListener(new ActionListener() {
1045
            public void actionPerformed(ActionEvent evt) {
1046
                panel.setToolType(ImageDisplayEdit.TOOL_ERASER);
1047
                panel.setCustomCursor (new Cursor(Cursor.CROSSHAIR_CURSOR));   
1048
                setSubtoolsVisible();                
1049
            }
1050
        });  
1051
1052
        return eraserTButton;
1053
    }    
1054
    
1055
    /** Gets brush button.*/        
1056
    private JToggleButton getBrushTButton(){
1057
        JToggleButton brushTButton = new JToggleButton();
1058
        brushTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Brush"));
1059
        brushTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/brush.gif"))); 
1060
1061
        brushTButton.addActionListener(new ActionListener() {
1062
            public void actionPerformed(ActionEvent evt) {                            
1063
                panel.setToolType(ImageDisplayEdit.TOOL_BRUSH);
1064
                panel.setCustomCursor(brushCursor);  
1065
                setSubtoolsVisible();                
1066
            }
1067
        });  
1068
1069
        return brushTButton;
1070
    }
1071
1072
    /** Gets arc button.*/        
1073
    private JToggleButton getArcTButton(){
1074
        JToggleButton arcTButton = new JToggleButton();
1075
        arcTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Arc"));
1076
        arcTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/arc.gif")));
1077
1078
        arcTButton.addActionListener(new ActionListener() {
1079
            public void actionPerformed(ActionEvent evt) {
1080
                panel.setToolType(ImageDisplayEdit.TOOL_ARC);
1081
                panel.setCustomCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
1082
                setSubtoolsVisible();                
1083
            }
1084
        });  
1085
1086
        return arcTButton;
685
    }
1087
    }
686
    
1088
    
1089
    /** Gets spray button.*/           
1090
    private JToggleButton getSprayTButton(){
1091
        JToggleButton sprayTButton = new JToggleButton();
1092
        sprayTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Spray"));
1093
        sprayTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/spray.gif")));
1094
1095
        sprayTButton.addActionListener(new ActionListener() {
1096
            public void actionPerformed(ActionEvent evt) {
1097
                panel.setToolType(ImageDisplayEdit.TOOL_SPRAY);
1098
                panel.setCustomCursor(sprayCursor);
1099
                setSubtoolsVisible();
1100
            }
1101
        });          
1102
                            
1103
        return sprayTButton;
1104
    }
1105
1106
    /** Gets foreground button.*/        
1107
    private JButton getForegroundButton(){
1108
        final JButton foregroundButton = new JButton("        ");
1109
        foregroundButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_SetLineColor"));
1110
        foregroundButton.setBackground(panel.getDefaultPrimaryColor());
1111
        foregroundButton.addActionListener(new ActionListener() 
1112
        {
1113
            public void actionPerformed(ActionEvent evt) 
1114
            {
1115
                Color newColor = fgColor.showDialog(null,"Choose Foreground Color", foregroundButton.getForeground());                                
1116
                foregroundButton.setBackground(newColor);
1117
                
1118
                panel.setPrimaryColor(newColor);
1119
            }
1120
        }); 
1121
        
1122
        return foregroundButton;        
1123
    }
1124
    
1125
    /** Gets background button.*/        
1126
    private JButton getBackgroundButton(){
1127
        final JButton backgroundButton = new JButton("        "); 
1128
        backgroundButton.setBackground(panel.getDefaultSecondaryColor());       
1129
        backgroundButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_SetFillColor"));
1130
        backgroundButton.addActionListener(new ActionListener() 
1131
        {
1132
            public void actionPerformed(ActionEvent evt) 
1133
            {
1134
                Color newColor = bgColor.showDialog(null,"Choose Background Color", backgroundButton.getBackground());
1135
                backgroundButton.setBackground(newColor);
1136
                                                                
1137
                panel.setSecondayColor(newColor);
1138
            }
1139
        });
1140
        
1141
        return backgroundButton;        
1142
    }
1143
                   
1144
    
1145
    /** Gets noFillRect button */
1146
    private JToggleButton getNoFillRectTButton(){
1147
        JToggleButton noFillRectTButton = new JToggleButton();
1148
        noFillRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noFillRect.gif")));        
1149
1150
        noFillRectTButton.addActionListener(new ActionListener() {
1151
            public void actionPerformed(ActionEvent evt) {
1152
                panel.setSubTool(ImageDisplayEdit.SUB_LINEONLY);
1153
            }
1154
        });          
1155
                            
1156
        return noFillRectTButton; 
1157
    }      
1158
    
1159
    /** Gets fillRect button */
1160
    private JToggleButton getFillRectTButton(){
1161
        JToggleButton fillRectTButton = new JToggleButton();
1162
        fillRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fillRect.gif")));
1163
1164
        fillRectTButton.addActionListener(new ActionListener() {
1165
            public void actionPerformed(ActionEvent evt) {
1166
                panel.setSubTool(ImageDisplayEdit.SUB_BOTH);
1167
            }
1168
        });          
1169
                            
1170
        return fillRectTButton; 
1171
    }        
1172
    
1173
    /** Gets noLineRect button */
1174
    private JToggleButton getNoLineRectTButton(){
1175
        JToggleButton noLineRectTButton = new JToggleButton();
1176
        noLineRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noLineRect.gif")));
1177
1178
        noLineRectTButton.addActionListener(new ActionListener() {
1179
            public void actionPerformed(ActionEvent evt) {
1180
                panel.setSubTool(ImageDisplayEdit.SUB_FILLONLY);
1181
            }
1182
        });          
1183
                            
1184
        return noLineRectTButton; 
1185
    }        
1186
    
1187
    /** Gets noFillEllipse button */
1188
    private JToggleButton getNoFillEllipseTButton(){
1189
        JToggleButton noFillEllipseTButton = new JToggleButton();
1190
        noFillEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noFillEllipse.gif")));        
1191
1192
        noFillEllipseTButton.addActionListener(new ActionListener() {
1193
            public void actionPerformed(ActionEvent evt) {
1194
                panel.setSubTool(ImageDisplayEdit.SUB_LINEONLY);
1195
            }
1196
        });          
1197
                            
1198
        return noFillEllipseTButton; 
1199
    }      
1200
    
1201
    /** Gets fillEllipse button */
1202
    private JToggleButton getFillEllipseTButton(){
1203
        JToggleButton fillEllipseTButton = new JToggleButton();
1204
        fillEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fillEllipse.gif")));
1205
1206
        fillEllipseTButton.addActionListener(new ActionListener() {
1207
            public void actionPerformed(ActionEvent evt) {
1208
                panel.setSubTool(ImageDisplayEdit.SUB_BOTH);
1209
            }
1210
        });          
1211
                            
1212
        return fillEllipseTButton; 
1213
    }        
1214
    
1215
    /** Gets noLineEllipse button */
1216
    private JToggleButton getNoLineEllipseTButton(){
1217
        JToggleButton noLineEllipseTButton = new JToggleButton();
1218
        noLineEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noLineEllipse.gif")));
1219
1220
        noLineEllipseTButton.addActionListener(new ActionListener() {
1221
            public void actionPerformed(ActionEvent evt) {
1222
                panel.setSubTool(ImageDisplayEdit.SUB_FILLONLY);
1223
            }
1224
        });          
1225
                            
1226
        return noLineEllipseTButton; 
1227
    }        
1228
1229
    /** Gets brushSquare button */
1230
    private JToggleButton getBrushSquareTButton(){
1231
        JToggleButton brushSquareTButton = new JToggleButton();
1232
        brushSquareTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/brushSquare.gif")));
1233
1234
        brushSquareTButton.addActionListener(new ActionListener() {
1235
            public void actionPerformed(ActionEvent evt) {
1236
                panel.setBrushType(BitmapFreehandBrush.BRUSH_BOX);
1237
            }
1238
        });          
1239
                            
1240
        return brushSquareTButton; 
1241
    } 
1242
    
1243
    /** Gets brushCircle button */
1244
    private JToggleButton getBrushCircleTButton(){
1245
        JToggleButton brushCircleTButton = new JToggleButton();
1246
        brushCircleTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/brushCircle.gif")));
1247
1248
        brushCircleTButton.addActionListener(new ActionListener() {
1249
            public void actionPerformed(ActionEvent evt) {
1250
                panel.setBrushType(BitmapFreehandBrush.BRUSH_CIRC);      
1251
            }
1252
        });          
1253
                            
1254
        return brushCircleTButton; 
1255
    }     
1256
    
1257
    /** Gets brushLongLeftTButton button */
1258
    private JToggleButton getBrushLeftTButton(){
1259
        JToggleButton brushLeftTButton = new JToggleButton();
1260
        brushLeftTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/brushLeft.gif")));
1261
1262
        brushLeftTButton.addActionListener(new ActionListener() {
1263
            public void actionPerformed(ActionEvent evt) {
1264
                panel.setBrushType(BitmapFreehandBrush.BRUSH_LINE_135);
1265
            }
1266
        });          
1267
                            
1268
        return brushLeftTButton; 
1269
    }         
1270
1271
    /** Gets brushLongRightTButton button */
1272
    private JToggleButton getBrushRightTButton(){
1273
        JToggleButton brushRightTButton = new JToggleButton();
1274
        brushRightTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/brushRight.gif")));
1275
1276
        brushRightTButton.addActionListener(new ActionListener() {
1277
            public void actionPerformed(ActionEvent evt) {
1278
                panel.setBrushType(BitmapFreehandBrush.BRUSH_LINE_45);
1279
            }
1280
        });          
1281
                            
1282
        return brushRightTButton; 
1283
    }            
1284
    
1285
    /** changes the line width display */
1286
    private void changeLine() {
1287
        Graphics2D g = (Graphics2D)linePanel.getGraphics();
1288
1289
        g.setColor(Color.WHITE);
1290
        g.fillRect(0, 20, 32, 40);
1291
        g.setClip(0, 20, 32, 40);                
1292
1293
        if (panel.getToolType() == ImageDisplayEdit.TOOL_SPRAY){
1294
            g.setColor(Color.BLACK);            
1295
            Ellipse2D testEllipse = new Ellipse2D.Float(10 - (panel.getLineWidth() / 2), 34 - (panel.getLineWidth() / 2), (float)panel.getLineWidth() + 10, (float)panel.getLineWidth() + 10);
1296
            g.draw(testEllipse);        
1297
        }else{
1298
            g.setColor(Color.BLACK);
1299
            Line2D testLine = new Line2D.Float(new Point(0, 40), new Point(32, 40));
1300
            g.setStroke(new BasicStroke(panel.getLineWidth()));
1301
            g.draw(testLine);                    
1302
        }
1303
    }    
1304
1305
    /** set the lines widths visible */
1306
    private void setSubtoolsVisible(){        
1307
        if (panel.getToolType() == ImageDisplayEdit.TOOL_RECTANGLE){ 
1308
            noFillRect.setVisible(true);
1309
            fillRect.setVisible(true);
1310
            noLineRect.setVisible(true);
1311
            cornerRoundingPanel.setVisible(true);
1312
        }else{
1313
            noFillRect.setVisible(false);
1314
            fillRect.setVisible(false);
1315
            noLineRect.setVisible(false);
1316
            cornerRoundingPanel.setVisible(false);            
1317
        }
1318
        
1319
        if (panel.getToolType() == ImageDisplayEdit.TOOL_ELLIPSE){ 
1320
            noFillEllipse.setVisible(true);
1321
            fillEllipse.setVisible(true);
1322
            noLineEllipse.setVisible(true);
1323
        }else{
1324
            noFillEllipse.setVisible(false);
1325
            fillEllipse.setVisible(false);
1326
            noLineEllipse.setVisible(false);
1327
        }        
1328
        
1329
        if (panel.getToolType() == ImageDisplayEdit.TOOL_BRUSH){
1330
            brushCircle.setVisible(true);
1331
            brushSquare.setVisible(true);;
1332
            brushLeft.setVisible(true);
1333
            brushRight.setVisible(true);
1334
        }else{
1335
            brushCircle.setVisible(false);
1336
            brushSquare.setVisible(false);;
1337
            brushLeft.setVisible(false);
1338
            brushRight.setVisible(false);            
1339
        }
1340
        
1341
        switch (panel.getToolType()){
1342
            case ImageDisplayEdit.TOOL_POLYGON:
1343
            case ImageDisplayEdit.TOOL_BRUSH:                
1344
            case ImageDisplayEdit.TOOL_ARC: 
1345
            case ImageDisplayEdit.TOOL_LINE:
1346
            case ImageDisplayEdit.TOOL_RECTANGLE:
1347
            case ImageDisplayEdit.TOOL_ELLIPSE:
1348
            case ImageDisplayEdit.TOOL_ERASER:
1349
            case ImageDisplayEdit.TOOL_SPRAY:
1350
                linePanel.setVisible(true);
1351
                changeLine();
1352
                break;
1353
            default:
1354
                linePanel.setVisible(false);                
1355
                break;
1356
        }        
1357
    }    
687
}
1358
}
(-)image/src/org/netbeans/modules/image/ImageWizardPanel.java (+365 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.DefaultComboBoxModel;
18
import javax.swing.JButton;
19
import javax.swing.JColorChooser;
20
import javax.swing.JComboBox;
21
import javax.swing.JFileChooser;
22
import javax.swing.JLabel;
23
import javax.swing.JPanel;
24
import javax.swing.JTextField;
25
import javax.swing.border.LineBorder;
26
import javax.swing.event.ChangeEvent;
27
import javax.swing.event.ChangeListener;
28
import javax.swing.event.DocumentEvent;
29
import javax.swing.event.DocumentListener;
30
31
import org.openide.WizardDescriptor;
32
import org.openide.filesystems.FileObject;
33
import org.openide.filesystems.FileUtil;
34
import org.openide.util.HelpCtx;
35
import org.openide.util.NbBundle;
36
37
/**
38
 * JPanel used by the NewImageFileWizardIterator
39
 * 
40
 * @author Jason Solomon
41
 */
42
final public class ImageWizardPanel extends JPanel implements WizardDescriptor.FinishablePanel, DocumentListener {
43
    
44
    private transient Set listeners = new HashSet(1);
45
    
46
    private Color bgColor = Color.white;
47
    
48
    // Swing Components
49
    private JButton btnBrowse;
50
    private JButton btnBackground;
51
    private JColorChooser chBackground;
52
    private JComboBox cmbExt;
53
    private JFileChooser chFolder;
54
    private JLabel lblFileName;
55
    private JLabel lblExt;
56
    private JLabel lblFolder;
57
    private JLabel lblWidth;
58
    private JLabel lblHeight;
59
    private JPanel pnlTop;
60
    private JPanel pnlMid;
61
    private JPanel pnlBottom;
62
    private JPanel pnlBackground;
63
    private JTextField jtfFileName;
64
    private JTextField jtfFolder;
65
    private JTextField jtfWidth;
66
    private JTextField jtfHeight;
67
    
68
    public ImageWizardPanel() {
69
        setName(NbBundle.getMessage(ImageWizardPanel.class, "LBL_ImageProperties"));
70
        initComponents();
71
    }
72
    
73
    public Component getComponent() {
74
        return this;
75
    }
76
    
77
    public boolean isFinishPanel() {
78
        return true;
79
    }
80
    
81
    public boolean isValid() {
82
        try {
83
            if(jtfFileName.getText().equals(""))
84
                return false;
85
            
86
            File tempFile = new File(jtfFolder.getText());
87
            if (!tempFile.isDirectory())
88
                return false;
89
            
90
            int testWidth = Integer.parseInt(jtfWidth.getText());
91
            int testHeight = Integer.parseInt(jtfHeight.getText());
92
            if(testWidth <= 0 || testHeight <= 0)
93
                return false;
94
            
95
            return true;
96
        } catch(IllegalArgumentException e) {
97
            return false;
98
        }
99
    }
100
    
101
    public HelpCtx getHelp() {
102
        return null;
103
    }
104
    
105
    public void addChangeListener(ChangeListener l) {
106
        synchronized(listeners) {
107
            listeners.add(l);
108
        }
109
    }
110
    
111
    public void removeChangeListener(ChangeListener l) {
112
        synchronized(listeners) {
113
            listeners.remove(l);
114
        }
115
    }
116
    
117
    public void storeSettings(Object settings) {
118
    }
119
    
120
    public void readSettings(Object settings) {
121
    }
122
    
123
    public String getFileName() {
124
        return jtfFileName.getText();
125
    }
126
    
127
    public String getExt() {
128
        return (String)cmbExt.getSelectedItem();
129
    }
130
    
131
    public File getFolder() {
132
        return new File(jtfFolder.getText());
133
    }
134
    
135
    public int getImageWidth() {
136
        return Integer.parseInt(jtfWidth.getText());
137
    }
138
    
139
    public int getImageHeight() {
140
        return Integer.parseInt(jtfHeight.getText());
141
    }
142
    
143
    public Color getBackground() {
144
        return bgColor;
145
    }
146
    
147
    private void initComponents() {
148
        GridBagConstraints gridBagConstraints;
149
        
150
        String tempWriterTypes[] = ImageIO.getWriterFormatNames();
151
        String writerTypes[] = new String[tempWriterTypes.length];
152
        
153
        for(int i = 0; i < writerTypes.length; i++)
154
            writerTypes[i] = new String("");
155
        
156
        int z = 0;
157
        boolean found = false;
158
        for(int x = 0; x < tempWriterTypes.length; x++) {
159
            if(x == 0) {
160
                writerTypes[z] = tempWriterTypes[x].toLowerCase();
161
                z++;
162
            }
163
            else {
164
                for(int y = 0; y < writerTypes.length; y++) {
165
                    if(writerTypes[y].equals(tempWriterTypes[x].toLowerCase()))
166
                        found = true;
167
                }
168
                if(!found) {
169
                    writerTypes[z] = tempWriterTypes[x].toLowerCase();
170
                    z++;
171
                }
172
            }
173
        }
174
        
175
        chBackground = new JColorChooser();
176
        
177
        chFolder = new JFileChooser();
178
        chFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
179
        chFolder.setDialogTitle(NbBundle.getMessage(ImageWizardPanel.class, "LBL_FolderChooser"));
180
        
181
        DefaultComboBoxModel cmbModel = new DefaultComboBoxModel();
182
        
183
        int j = 0;
184
        while(!writerTypes[j].equals("")) {
185
            cmbModel.addElement(writerTypes[j]);
186
            j++;
187
        }
188
        
189
        pnlTop = new JPanel();
190
        lblFileName = new JLabel();
191
        jtfFileName = new JTextField();
192
        lblExt = new JLabel();
193
        cmbExt = new JComboBox(cmbModel);
194
        lblFolder = new JLabel();
195
        jtfFolder = new JTextField();
196
        btnBrowse = new JButton();
197
        pnlMid = new JPanel();
198
        lblWidth = new JLabel();
199
        jtfWidth = new JTextField();
200
        lblHeight = new JLabel();
201
        jtfHeight = new JTextField();
202
        pnlBottom = new JPanel();
203
        btnBackground = new JButton();
204
        pnlBackground = new JPanel();
205
        
206
        jtfFileName.getDocument().addDocumentListener(this);
207
        jtfFolder.getDocument().addDocumentListener(this);
208
        jtfWidth.getDocument().addDocumentListener(this);
209
        jtfHeight.getDocument().addDocumentListener(this);
210
        
211
        btnBackground.addActionListener(
212
            new ActionListener() {
213
                public void actionPerformed(ActionEvent e) {
214
                    Color newBGColor = chBackground.showDialog(null, NbBundle.getMessage(ImageWizardPanel.class, "LBL_ColorChooser"), Color.white);
215
                    if(newBGColor != null) {
216
                        bgColor = newBGColor;
217
                    }
218
                    pnlBackground.setBackground(bgColor);
219
                }
220
            }
221
        );
222
        
223
        btnBrowse.addActionListener(
224
            new ActionListener() {
225
                public void actionPerformed(ActionEvent e) {
226
                    if(chFolder.showDialog(null, NbBundle.getMessage(ImageWizardPanel.class, "LBL_FolderChooserBtn")) == JFileChooser.APPROVE_OPTION) {
227
                        File tempFolder = chFolder.getSelectedFile();
228
                        jtfFolder.setText(tempFolder.getPath());
229
                    }
230
                }
231
            }
232
        );
233
        
234
        setLayout(new BorderLayout());
235
        
236
        pnlTop.setLayout(new GridBagLayout());
237
238
        lblFileName.setText(NbBundle.getMessage(ImageWizardPanel.class, "LBL_FileName"));
239
        gridBagConstraints = new GridBagConstraints();
240
        gridBagConstraints.anchor = GridBagConstraints.WEST;
241
        gridBagConstraints.insets = new Insets(30, 12, 0, 0);
242
        pnlTop.add(lblFileName, gridBagConstraints);
243
244
        jtfFileName.setText("newImage");
245
        jtfFileName.setPreferredSize(new Dimension(200, 23));
246
        jtfFileName.setMinimumSize(new Dimension(200, 23));
247
        gridBagConstraints = new GridBagConstraints();
248
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
249
        gridBagConstraints.weightx = 1.0;
250
        gridBagConstraints.insets = new Insets(29, 11, 0, 11);
251
        pnlTop.add(jtfFileName, gridBagConstraints);
252
253
        lblExt.setText(NbBundle.getMessage(ImageWizardPanel.class, "LBL_Ext"));
254
        gridBagConstraints = new GridBagConstraints();
255
        gridBagConstraints.insets = new Insets(30, 12, 0, 0);
256
        pnlTop.add(lblExt, gridBagConstraints);
257
258
        cmbExt.setPreferredSize(new Dimension(60, 22));
259
        cmbExt.setMinimumSize(new Dimension(60, 22));
260
        gridBagConstraints = new GridBagConstraints();
261
        gridBagConstraints.insets = new Insets(29, 11, 0, 11);
262
        pnlTop.add(cmbExt, gridBagConstraints);
263
264
        lblFolder.setText(NbBundle.getMessage(ImageWizardPanel.class, "LBL_Folder"));
265
        gridBagConstraints = new GridBagConstraints();
266
        gridBagConstraints.gridx = 0;
267
        gridBagConstraints.gridy = 1;
268
        gridBagConstraints.anchor = GridBagConstraints.WEST;
269
        gridBagConstraints.insets = new Insets(12, 12, 0, 0);
270
        pnlTop.add(lblFolder, gridBagConstraints);
271
272
        jtfFolder.setPreferredSize(new Dimension(250, 23));
273
        jtfFolder.setMinimumSize(new Dimension(250, 23));
274
        gridBagConstraints = new GridBagConstraints();
275
        gridBagConstraints.gridx = 1;
276
        gridBagConstraints.gridy = 1;
277
        gridBagConstraints.gridwidth = 2;
278
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
279
        gridBagConstraints.weightx = 2.0;
280
        gridBagConstraints.insets = new Insets(12, 11, 0, 11);
281
        pnlTop.add(jtfFolder, gridBagConstraints);
282
283
        btnBrowse.setText(NbBundle.getMessage(ImageWizardPanel.class, "LBL_BrowseBtn"));
284
        btnBrowse.setPreferredSize(new Dimension(75, 27));
285
        gridBagConstraints = new GridBagConstraints();
286
        gridBagConstraints.gridx = 3;
287
        gridBagConstraints.gridy = 1;
288
        gridBagConstraints.insets = new Insets(12, 11, 0, 11);
289
        pnlTop.add(btnBrowse, gridBagConstraints);
290
291
        add(pnlTop, BorderLayout.NORTH);
292
        
293
        pnlMid.setLayout(new GridBagLayout());
294
295
        lblWidth.setText(NbBundle.getMessage(ImageWizardPanel.class, "LBL_Width"));
296
        gridBagConstraints = new GridBagConstraints();
297
        gridBagConstraints.anchor = GridBagConstraints.WEST;
298
        gridBagConstraints.insets = new Insets(20, 100, 0, 0);
299
        pnlMid.add(lblWidth, gridBagConstraints);
300
301
        jtfWidth.setText("200");
302
        jtfWidth.setPreferredSize(new Dimension(60, 23));
303
        jtfWidth.setMinimumSize(new Dimension(60, 23));
304
        gridBagConstraints = new GridBagConstraints();
305
        gridBagConstraints.insets = new Insets(19, 11, 0, 11);
306
        pnlMid.add(jtfWidth, gridBagConstraints);
307
308
        lblHeight.setText(NbBundle.getMessage(ImageWizardPanel.class, "LBL_Height"));
309
        gridBagConstraints = new GridBagConstraints();
310
        gridBagConstraints.insets = new Insets(20, 12, 0, 0);
311
        pnlMid.add(lblHeight, gridBagConstraints);
312
313
        jtfHeight.setText("200");
314
        jtfHeight.setPreferredSize(new Dimension(60, 23));
315
        jtfHeight.setMinimumSize(new Dimension(60, 23));
316
        gridBagConstraints = new GridBagConstraints();
317
        gridBagConstraints.insets = new Insets(19, 11, 0, 100);
318
        pnlMid.add(jtfHeight, gridBagConstraints);
319
320
        add(pnlMid, BorderLayout.CENTER);
321
        
322
        pnlBottom.setLayout(new GridBagLayout());
323
324
        btnBackground.setText(NbBundle.getMessage(ImageWizardPanel.class, "LBL_BackgroundBtn"));
325
        gridBagConstraints = new GridBagConstraints();
326
        gridBagConstraints.insets = new Insets(30, 11, 30, 11);
327
        pnlBottom.add(btnBackground, gridBagConstraints);
328
329
        pnlBackground.setLayout(null);
330
331
        pnlBackground.setBackground(Color.white);
332
        pnlBackground.setBorder(new LineBorder(Color.black));
333
        pnlBackground.setPreferredSize(new Dimension(40, 40));
334
        gridBagConstraints = new GridBagConstraints();
335
        gridBagConstraints.insets = new Insets(0, 0, 2, 0);
336
        pnlBottom.add(pnlBackground, gridBagConstraints);
337
338
        add(pnlBottom, BorderLayout.SOUTH);
339
    }
340
    
341
    public void insertUpdate(DocumentEvent e) {
342
        ChangeEvent ce = new ChangeEvent(this);
343
        Iterator it = listeners.iterator();
344
        while (it.hasNext()) {
345
            ((ChangeListener)it.next()).stateChanged(ce);
346
        }
347
    }
348
    
349
    public void removeUpdate(DocumentEvent e) {
350
        ChangeEvent ce = new ChangeEvent(this);
351
        Iterator it = listeners.iterator();
352
        while (it.hasNext()) {
353
            ((ChangeListener)it.next()).stateChanged(ce);
354
        }
355
    }
356
    
357
    public void changedUpdate(DocumentEvent e) {
358
        ChangeEvent ce = new ChangeEvent(this);
359
        Iterator it = listeners.iterator();
360
        while (it.hasNext()) {
361
            ((ChangeListener)it.next()).stateChanged(ce);
362
        }
363
    }
364
    
365
}
(-)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 (-1 / +6 lines)
Lines 24-30 Link Here
24
/** 
24
/** 
25
 * ImageIcon with serialization.
25
 * ImageIcon with serialization.
26
 *
26
 *
27
 * @author Petr Hamernik, Michael Wever
27
 * @author Petr Hamernik, Michael Wever, Jason Solomon
28
 * @author  Marian Petras
28
 * @author  Marian Petras
29
 */
29
 */
30
class NBImageIcon extends ImageIcon implements Serializable {
30
class NBImageIcon extends ImageIcon implements Serializable {
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 (+156 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
 * 
28
 * @author Jason Solomon
29
 */
30
public class NewImageFileWizardIterator implements WizardDescriptor.InstantiatingIterator {
31
    
32
    private transient WizardDescriptor wizard;
33
    
34
    private transient WizardDescriptor.Panel[] panels;
35
    
36
    private transient int index;
37
    
38
    private transient Set listeners = new HashSet(1);
39
    
40
    /** Create a new wizard iterator. */
41
    public NewImageFileWizardIterator() {
42
    }
43
    
44
    public void initialize(WizardDescriptor wizard) {        
45
        this.wizard = wizard;
46
        index = 0;
47
        
48
        panels = new ImageWizardPanel[1];
49
        panels[0] = new ImageWizardPanel();
50
        
51
        // Make sure list of steps is accurate.
52
        String[] beforeSteps = null;
53
        Object prop = wizard.getProperty ("WizardPanel_contentData");
54
        if (prop != null && prop instanceof String[]) {
55
            beforeSteps = (String[])prop;
56
        }
57
        
58
        assert panels != null;
59
        
60
        int diff = 0;
61
        if (beforeSteps == null) {
62
            beforeSteps = new String[0];
63
        } else if (beforeSteps.length > 0) {
64
            diff = ("...".equals(beforeSteps[beforeSteps.length - 1])) ? 1 : 0;
65
        }
66
        String[] steps = new String[(beforeSteps.length - diff) + panels.length];
67
        for (int i = 0; i < steps.length; i++) {
68
            if (i < (beforeSteps.length - diff)) {
69
                steps[i] = beforeSteps[i];
70
            } else {
71
                steps[i] = panels[i - beforeSteps.length + diff].getComponent().getName();
72
            }
73
        }
74
        for (int i = 0; i < panels.length; i++) {
75
            Component c = panels[i].getComponent();
76
            if (steps[i] == null) {
77
                steps[i] = c.getName();
78
            }
79
            if (c instanceof JComponent) {
80
                JComponent jc = (JComponent)c;
81
                jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i));
82
                jc.putClientProperty("WizardPanel_contentData", steps);
83
            }
84
        }
85
    }
86
    
87
    public Set instantiate() throws IOException {
88
        String fileName = ((ImageWizardPanel)(panels[index])).getFileName();
89
        String ext = ((ImageWizardPanel)(panels[index])).getExt();
90
        File folder = ((ImageWizardPanel)(panels[index])).getFolder();
91
        int width = ((ImageWizardPanel)(panels[index])).getImageWidth();
92
        int height = ((ImageWizardPanel)(panels[index])).getImageHeight();
93
        Color bgColor = ((ImageWizardPanel)(panels[index])).getBackground();
94
        
95
        File newFile =  new File(folder, fileName + "." + ext);
96
        BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
97
        Graphics g = newImage.getGraphics();
98
        g.setColor(bgColor);
99
        g.fillRect(0, 0, width, height);
100
        Iterator writers = ImageIO.getImageWritersByFormatName(ext);
101
        ImageWriter writer = (ImageWriter)writers.next();
102
        FileImageOutputStream output = new FileImageOutputStream(newFile);
103
        writer.setOutput(output);
104
        writer.write((RenderedImage)newImage);
105
        FileObject pf = FileUtil.toFileObject(newFile);
106
        
107
        return Collections.singleton(pf);
108
    }
109
    
110
    public void uninitialize(WizardDescriptor wizard) {
111
        this.wizard = null;
112
    }
113
    
114
    public String name() {
115
        return "";
116
    }
117
    
118
    public final void addChangeListener(ChangeListener l) {
119
        synchronized(listeners) {
120
            listeners.add(l);
121
        }
122
    }
123
    
124
    public final void removeChangeListener(ChangeListener l) {
125
        synchronized(listeners) {
126
            listeners.remove(l);
127
        }
128
    }
129
    
130
    public boolean hasNext() {
131
        return index < panels.length - 1;
132
    }
133
    
134
    public boolean hasPrevious() {
135
        return index > 0;
136
    }
137
    
138
    public void nextPanel() {
139
        if (!hasNext()) throw new NoSuchElementException();
140
        index++;
141
    }
142
    
143
    public void previousPanel() {
144
        if (!hasPrevious()) throw new NoSuchElementException();
145
        index--;
146
    }
147
    
148
    public WizardDescriptor.Panel current() {
149
        return panels[index];
150
    }
151
    
152
    public static WizardDescriptor.InstantiatingIterator createImageTemplateIterator() {
153
        return new NewImageFileWizardIterator ();
154
    }
155
    
156
}
(-)image/src/org/netbeans/modules/image/ObservableImage.java (+14 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
 * 
8
 * @author Jason Solomon
9
 */
10
public class ObservableImage extends Observable {
11
    public void setChanged() {
12
        super.setChanged();
13
    }
14
}
(-)image/src/org/netbeans/modules/image/VectorArc.java (+54 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
/**
14
 * Implimentation of the Vector Arc tool.  Draws a
15
 * 90 degree line joining both points
16
 *
17
 * @author Timothy Boyce
18
 */
19
class VectorArc extends VectorTool{
20
21
    /** Simply use the supercalss default constructor */
22
    public VectorArc(int xVal, int yVal, Color c, int w){
23
        super(xVal, yVal, c, w);
24
    }
25
    
26
    /** Draw an arc on the graphics context
27
    between the start and end clicks */
28
    public void writeToGraphic(Graphics2D g){
29
        g.setStroke(new BasicStroke(getLineWidth()));
30
        g.setPaintMode();
31
        g.setColor(getLineColor());
32
        
33
        Arc2D.Float thisArc = new Arc2D.Float();
34
        
35
        /* Calculate the bounding rectangle */
36
        double top, left, direction;
37
        top = (getStart().getY() < getEnd().getY()) ? getTopLeft().getY() - getDimension().getHeight() : getTopLeft().getY();
38
        left = (getStart().getX() > getEnd().getX()) ? getTopLeft().getX() - getDimension().getWidth() : getTopLeft().getX();
39
        direction = (getStart().getX() - getEnd().getX()) * (getStart().getY() - getEnd().getY());
40
        direction = -(Math.abs(direction) / direction);
41
        
42
        Point topLeft = new Point((int)left, (int)top);
43
        Dimension rectDim = new Dimension((int)(2 * getDimension().getWidth()),(int)(2 * getDimension().getHeight()));
44
        
45
        /* Sets the arcs bounds */
46
        thisArc.setFrame(new Rectangle(topLeft, rectDim));
47
        
48
        /* Set the angle extent and start */
49
        thisArc.setAngleStart((getEnd().getY() < getStart().getY()) ? 90 : 270);
50
        thisArc.setAngleExtent(direction * 90);
51
    
52
        g.draw(thisArc);
53
    }
54
}
(-)image/src/org/netbeans/modules/image/VectorEllipse.java (+44 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
/**
10
 * Implimentation of the Ellipse Edit Tool
11
 *
12
 * @author Timothy Boyce
13
 */
14
class VectorEllipse extends VectorTool{
15
    /** The fill color of the Ellipse */
16
    private Color fillColor;
17
18
    /** Constructor for a line ellipse */
19
    public VectorEllipse(int xVal, int yVal, Color c, int w){
20
        super(xVal, yVal, c, w);
21
        fillColor = null;
22
    }
23
    
24
    /** Constructor for a filled ellipse */
25
    public VectorEllipse(int xVal, int yVal, Color line, Color fill, int w){
26
        super(xVal, yVal, line, w);
27
        fillColor = fill;
28
    }
29
30
    public void writeToGraphic(Graphics2D g){
31
        g.setStroke(new BasicStroke(getLineWidth()));
32
        g.setPaintMode();
33
            
34
        Ellipse2D.Float thisEllipse = new Ellipse2D.Float((float)getTopLeft().getX(), (float)getTopLeft().getY(), (float)getDimension().getWidth(), (float)getDimension().getHeight());
35
            
36
        if(fillColor != null){
37
            g.setColor(fillColor);
38
            g.fill(thisEllipse);
39
        }
40
        
41
        g.setColor(getLineColor());
42
        g.draw(thisEllipse);
43
    }
44
}
(-)image/src/org/netbeans/modules/image/VectorLine.java (+27 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
 *
10
 * @author Timothy Boyce
11
 */
12
class VectorLine extends VectorTool{
13
14
    /** Use the superclass constructor */
15
    public VectorLine(int xVal, int yVal, Color c, int w){
16
        super(xVal, yVal, c, w);
17
    }
18
19
    /** Draw a line between the start and end points, 
20
    to the specified graphics object */
21
    public void writeToGraphic(Graphics2D g){
22
        g.setStroke(new BasicStroke(getLineWidth()));
23
        g.setPaintMode();
24
        g.setColor(getLineColor());
25
        g.draw(new Line2D.Float(getStart(), getEnd()));
26
    }
27
}
(-)image/src/org/netbeans/modules/image/VectorPolygon.java (+133 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
/**
11
 * Implimentation of the Polygon Edit Tool
12
 *
13
 * @author Timothy Boyce
14
 */
15
class VectorPolygon implements EditTool{
16
17
    /** The start point of the polygon */
18
    protected Point startPoint;
19
    
20
    /** The end point of the polygon */
21
    protected Point lastPoint;
22
    
23
    /** Vector containing the last 3 polygon points */
24
    protected Vector polygonSegPoints = new Vector(){
25
        public void addElement(Object obj){
26
            if(this.size() >= 3)
27
                this.removeElementAt(0);
28
            super.addElement(obj);
29
        }
30
    };
31
    
32
    /** General path used for drawing polygon segments */
33
    protected GeneralPath polygonSegPath;    
34
    
35
    /** The line color */
36
    protected Color lineColor;
37
    
38
    /** The width of the line */
39
    protected float lineWidth;
40
    
41
    /** The status of the tool, true = complete, false = incomplete */
42
    protected boolean toolStatus = false;
43
    
44
    /** The type of the polgon, points only, or freehand and points */
45
    protected boolean polyType;
46
    
47
    /** Static polygon type varibles used in the constructor */
48
    public static final boolean FREEHAND_POLY = true;
49
    public static final boolean POINT_POLY = false;
50
51
    /** Constructor, set the start point of the polygon, and other various 
52
    variables. */
53
    public VectorPolygon(int xVal, int yVal, Color c, int w, boolean f){
54
        startPoint = new Point(xVal, yVal);
55
        polygonSegPoints.addElement(startPoint);
56
        lastPoint = new Point(-1, -1);
57
        lineColor = c;
58
        lineWidth = (float)w;
59
        polyType = false;
60
    }
61
    
62
    public boolean getToolStatus(){
63
        return toolStatus;
64
    }
65
    
66
    public boolean getMemoryless(){
67
        return true;
68
    }
69
    
70
    /** When the image display editor invokes the setDragPoint
71
    command, only set a new polygone point if the user has selected a
72
    freehand polygon type */
73
    public void setDragPoint(int xVal, int yVal){
74
        if(polyType == VectorPolygon.FREEHAND_POLY){
75
            polygonSegPoints.addElement(new Point(xVal, yVal));
76
            lastPoint.setLocation(xVal, yVal);
77
        }
78
    }
79
    
80
    public void setClickPoint(int xVal, int yVal){
81
        lastPoint.setLocation(xVal, yVal);    
82
        polygonSegPoints.addElement(new Point(xVal, yVal));
83
    }
84
    
85
    public void setReleasePoint(int xVal, int yVal){
86
        /** Finish the polygon if the user clicks in the same spot twice */
87
        if((xVal == lastPoint.x) && (yVal == lastPoint.y)){
88
            toolStatus = true;
89
        }
90
        
91
        lastPoint.setLocation(xVal, yVal);    
92
        polygonSegPoints.addElement(new Point(xVal, yVal));
93
    }
94
    
95
    
96
    /** Write the last 2 polgon segments to the graphics context:
97
    Since this is a non-memoryless tool, all preceding points will
98
    still be held in the buffer.  Only the last 2 segments need to
99
    be drawn in order to get the new line, and the proper segment
100
    joining at the newly created corner. */
101
    public void writeToGraphic(Graphics2D g){
102
        Point p1, p2, p3;
103
        
104
        g.setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
105
        g.setPaintMode();
106
        g.setColor(lineColor);
107
        
108
        polygonSegPath = new GeneralPath();
109
        
110
        p1 = (Point)polygonSegPoints.firstElement();
111
        polygonSegPath.moveTo(p1.x, p1.y);
112
        
113
        if(polygonSegPoints.size() == 3)
114
            p2 = (Point)polygonSegPoints.get(1);
115
        else
116
            p2 = (Point)polygonSegPoints.lastElement();
117
        
118
        polygonSegPath.lineTo(p2.x, p2.y);
119
        
120
        if(polygonSegPoints.size()  == 2)
121
            p3 = (Point)polygonSegPoints.firstElement();
122
        else
123
            p3 = (Point)polygonSegPoints.lastElement();
124
            
125
        polygonSegPath.lineTo(p3.x, p3.y);
126
        
127
        if(getToolStatus()){
128
            polygonSegPath.lineTo(startPoint.x, startPoint.y);
129
        }
130
        
131
        g.draw(polygonSegPath);
132
    }
133
}
(-)image/src/org/netbeans/modules/image/VectorRectangle.java (+86 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
/**
13
 * VectorRectangle
14
 *
15
 * @author Timothy Boyce
16
 */
17
class VectorRectangle extends VectorTool{
18
    private Color fillColor;
19
    private float roundingFactor;
20
21
    public VectorRectangle(int xVal, int yVal, Color c, int w){
22
        super(xVal, yVal, c, w);
23
        
24
        /* Set the fill colour to null,
25
        and corner rounding to 0 */
26
        fillColor = null;
27
        roundingFactor = 0;
28
    }
29
    
30
    public VectorRectangle(int xVal, int yVal, Color c, int w, float r){
31
        super(xVal, yVal, c, w);
32
        
33
        /* Set the fill to null */
34
        fillColor = null;
35
        
36
        /* Set CornerRounding */
37
        roundingFactor = r;
38
    }
39
    
40
    public VectorRectangle(int xVal, int yVal, Color line, Color fill, int w){
41
        super(xVal, yVal, line, w);
42
        
43
        /* Set the fill colour to null */
44
        fillColor = fill;
45
        roundingFactor = 0;
46
    }
47
    
48
    public VectorRectangle(int xVal, int yVal, Color line, Color fill, int w, float r){
49
        super(xVal, yVal, line, w);
50
        
51
        /* Set the fill colour to null */
52
        fillColor = fill;
53
        roundingFactor = r;
54
    }
55
56
    /* Returns null if there is no fill, the
57
    color if the tool is complete, or the XOR
58
    mode color if the tool is not yet complete */
59
    protected Color getFillColor(){
60
            return fillColor;
61
    }
62
63
    public void writeToGraphic(Graphics2D g){
64
        g.setStroke(new BasicStroke(getLineWidth(), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER));
65
        g.setPaintMode();
66
        
67
        Shape thisRectangle;
68
        
69
        if(roundingFactor == 0)
70
            thisRectangle = new Rectangle(getTopLeft(), getDimension());
71
        else
72
            thisRectangle = new RoundRectangle2D.Float((float)getTopLeft().getX(), (float)getTopLeft().getY(), (float)getDimension().getWidth(), (float)getDimension().getHeight(), roundingFactor, roundingFactor);
73
            
74
        /* Fill it if the user chose a filled variation */
75
        if(fillColor != null){
76
            g.setColor(getFillColor());
77
            g.fill(thisRectangle);
78
        }
79
        
80
        /* Paint the line */
81
        g.setColor(getLineColor());
82
        g.draw(thisRectangle);
83
        
84
    }
85
    
86
}
(-)image/src/org/netbeans/modules/image/VectorTool.java (+124 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
/**
10
 * VectorTool
11
 *
12
 * @author Timothy Boyce
13
 */
14
abstract class VectorTool implements EditTool{
15
    protected Point startPoint;
16
    protected Point endPoint;
17
    private Color lineColor;
18
    private float lineWidth;
19
    private Rectangle BoundingRectangle;
20
    private Rectangle OldBoundingRectangle;
21
    
22
    protected boolean toolStatus = false;
23
    
24
    public VectorTool(int xVal, int yVal, Color c, int w){
25
        /* Set the start points */
26
        startPoint = new Point(xVal, yVal);
27
        
28
        /* Default the end points to the start points */
29
        endPoint = new Point(xVal, yVal);
30
        
31
        /* Set the Line Colour */
32
        lineColor = c;
33
        
34
        /* Sets the Line Width */
35
        lineWidth = (float)w;
36
    }
37
    
38
    /* Default Action to be performed on a drag */
39
    public void setDragPoint(int xVal, int yVal){
40
        endPoint.setLocation(xVal, yVal);
41
    }
42
    
43
    /* Default action taken on a release */
44
    public void setReleasePoint(int xVal, int yVal){
45
        endPoint.setLocation(xVal, yVal);
46
        
47
        /* Most Edit tools are complete when the user releases
48
        the mouse */
49
        toolStatus = true;
50
    }
51
    
52
    /* Default action taken on a Click */
53
    public void setClickPoint(int xVal, int yVal){
54
    }
55
    
56
    /* Return the tool status */
57
    public boolean getToolStatus(){
58
        return toolStatus;
59
    }
60
    
61
    /* Return the shape height */
62
    private int getHeight(){
63
        return Math.abs((int)startPoint.getY() - (int)endPoint.getY());
64
    }
65
    
66
    /* Return the shape width */
67
    private int getWidth(){
68
        return Math.abs((int)startPoint.getX() - (int)endPoint.getX());
69
    }
70
    
71
    /* Retern the top-left point */
72
    protected Point getTopLeft(){
73
        double left = (startPoint.getX() < endPoint.getX()) ? startPoint.getX() : endPoint.getX();
74
        double top = (startPoint.getY() < endPoint.getY()) ? startPoint.getY() : endPoint.getY();
75
        
76
        return new Point((int)left, (int)top);
77
    }
78
    
79
    /* Return the bottom-right point */
80
    protected Point getBottomRight(){
81
        double right = (startPoint.getX() > endPoint.getX()) ? startPoint.getX() : endPoint.getX();
82
        double bottom = (startPoint.getY() > endPoint.getY()) ? startPoint.getY() : endPoint.getY();
83
        
84
        return new Point((int)right, (int)bottom);
85
    }
86
    
87
    /* Return the start point object */
88
    protected Point getStart(){
89
        return startPoint;
90
    }
91
    
92
    /*Return the end point object */
93
    protected Point getEnd(){
94
        return endPoint;
95
    }
96
    
97
    /* Return the width and height as a dimension object */
98
    protected Dimension getDimension(){
99
        return new Dimension(getWidth(), getHeight());
100
    }
101
    
102
    /* Returns a rectangle that bounds this object */
103
    public Rectangle getBounds(){
104
        return new Rectangle(getTopLeft(), getDimension());
105
    }
106
    
107
    /* Returns the line colour if the tool
108
    is complete, otherwise it returns the colour
109
    black to be used in XOR mode */
110
    protected  Color getLineColor(){
111
            return lineColor;
112
    }
113
    
114
    protected float getLineWidth(){
115
        return lineWidth;
116
    }
117
    
118
    public boolean getMemoryless(){
119
        return false;
120
    };
121
    
122
    /* Writes the current tool to the graphis object */
123
    public abstract void writeToGraphic(Graphics2D g);
124
}

Return to bug 59527