Lines 47-55
Link Here
|
47 |
import javax.swing.JToolBar; |
47 |
import javax.swing.JToolBar; |
48 |
import javax.swing.event.ChangeEvent; |
48 |
import javax.swing.event.ChangeEvent; |
49 |
import javax.swing.event.ChangeListener; |
49 |
import javax.swing.event.ChangeListener; |
|
|
50 |
import org.netbeans.api.settings.ConvertAsProperties; |
50 |
import org.netbeans.swing.colorchooser.ColorChooser; |
51 |
import org.netbeans.swing.colorchooser.ColorChooser; |
51 |
import org.openide.DialogDisplayer; |
52 |
import org.openide.DialogDisplayer; |
52 |
import org.openide.NotifyDescriptor; |
53 |
import org.openide.NotifyDescriptor; |
|
|
54 |
import org.openide.awt.ActionID; |
55 |
import org.openide.awt.ActionReference; |
56 |
import org.openide.awt.ActionReferences; |
57 |
import org.openide.awt.ActionRegistration; |
53 |
import org.openide.awt.StatusDisplayer; |
58 |
import org.openide.awt.StatusDisplayer; |
54 |
import org.openide.cookies.SaveCookie; |
59 |
import org.openide.cookies.SaveCookie; |
55 |
import org.openide.filesystems.FileChooserBuilder; |
60 |
import org.openide.filesystems.FileChooserBuilder; |
Lines 62-68
Link Here
|
62 |
import org.openide.util.lookup.InstanceContent; |
67 |
import org.openide.util.lookup.InstanceContent; |
63 |
import org.openide.windows.TopComponent; |
68 |
import org.openide.windows.TopComponent; |
64 |
|
69 |
|
|
|
70 |
@ConvertAsProperties(dtd = "-//org.netbeans.paint//PaintTopComponent//EN", autostore = false) |
71 |
@TopComponent.Description(preferredID = "PaintTopComponent", iconBase = "/org/netbeans/paint/new_icon.png", persistenceType = TopComponent.PERSISTENCE_ALWAYS) |
72 |
@TopComponent.Registration(mode = "editor", openAtStartup = true) |
73 |
@ActionID(category = "Window", id = "org.netbeans.paint.PaintTopComponent") |
74 |
@ActionRegistration(displayName = "#CTL_NewCanvasAction", iconBase = "/org/netbeans/paint/new_icon.png") |
75 |
@ActionReferences({ |
76 |
@ActionReference(path = "Menu/Window", position = 0), |
77 |
@ActionReference(path = "Toolbars/File", position = 0) |
78 |
}) |
79 |
@TopComponent.OpenActionRegistration(displayName = "#CTL_NewCanvasAction") |
65 |
public final class PaintTopComponent extends TopComponent implements ActionListener, ChangeListener { |
80 |
public final class PaintTopComponent extends TopComponent implements ActionListener, ChangeListener { |
|
|
81 |
|
66 |
private static int ct = 0; //A counter you use to provide names for new images |
82 |
private static int ct = 0; //A counter you use to provide names for new images |
67 |
private final PaintCanvas canvas = new PaintCanvas(); //The component the user draws on |
83 |
private final PaintCanvas canvas = new PaintCanvas(); //The component the user draws on |
68 |
private final JComponent preview = canvas.getBrushSizeView(); //A component in the toolbar that shows the paintbrush size |
84 |
private final JComponent preview = canvas.getBrushSizeView(); //A component in the toolbar that shows the paintbrush size |
Lines 73-80
Link Here
|
73 |
private final JLabel label = new JLabel( |
89 |
private final JLabel label = new JLabel( |
74 |
NbBundle.getMessage(PaintTopComponent.class, "LBL_Foreground")); //A label for the color chooser |
90 |
NbBundle.getMessage(PaintTopComponent.class, "LBL_Foreground")); //A label for the color chooser |
75 |
private final JLabel brushSizeLabel = new JLabel( |
91 |
private final JLabel brushSizeLabel = new JLabel( |
76 |
NbBundle.getMessage(PaintTopComponent.class, "LBL_BrushSize")); //A label for the brush size slider |
92 |
NbBundle.getMessage(PaintTopComponent.class, "LBL_BrushSize")); //A label for the brush size slider |
77 |
|
|
|
78 |
private final JSlider brushSizeSlider = new JSlider(1, 24); //A slider to set the brush size |
93 |
private final JSlider brushSizeSlider = new JSlider(1, 24); //A slider to set the brush size |
79 |
private InstanceContent content = new InstanceContent(); //The bag of stuff we add/remove the Saver from, and store the last-used file in |
94 |
private InstanceContent content = new InstanceContent(); //The bag of stuff we add/remove the Saver from, and store the last-used file in |
80 |
private Saver saver = new Saver(); |
95 |
private Saver saver = new Saver(); |
Lines 90-95
Link Here
|
90 |
//Connect our lookup to the rest of the system, so that |
105 |
//Connect our lookup to the rest of the system, so that |
91 |
//SaveAction will pay attention to whether or not the Saver is available |
106 |
//SaveAction will pay attention to whether or not the Saver is available |
92 |
associateLookup(new AbstractLookup(content)); |
107 |
associateLookup(new AbstractLookup(content)); |
|
|
108 |
//Enable the Print action for the canvas: |
109 |
putClientProperty("print.printable", true); |
110 |
//Disable the Save action by default: |
93 |
enableSaveAction(false); |
111 |
enableSaveAction(false); |
94 |
} |
112 |
} |
95 |
|
113 |
|
Lines 101-107
Link Here
|
101 |
brushSizeSlider.setValue(canvas.getBrushDiameter()); |
119 |
brushSizeSlider.setValue(canvas.getBrushDiameter()); |
102 |
brushSizeSlider.addChangeListener(this); |
120 |
brushSizeSlider.addChangeListener(this); |
103 |
color.setColor(canvas.getColor()); |
121 |
color.setColor(canvas.getColor()); |
104 |
color.setMaximumSize(new Dimension(16,16)); |
122 |
color.setMaximumSize(new Dimension(16, 16)); |
105 |
//Install the toolbar and the painting component: |
123 |
//Install the toolbar and the painting component: |
106 |
add(toolbar, BorderLayout.NORTH); |
124 |
add(toolbar, BorderLayout.NORTH); |
107 |
add(new JScrollPane(canvas), BorderLayout.CENTER); |
125 |
add(new JScrollPane(canvas), BorderLayout.CENTER); |
Lines 212-225
Link Here
|
212 |
} |
230 |
} |
213 |
} |
231 |
} |
214 |
|
232 |
|
215 |
//TopComponent boilerplate code |
233 |
void writeProperties(java.util.Properties p) { |
216 |
@Override |
234 |
// better to version settings since initial version as advocated at |
217 |
public int getPersistenceType() { |
235 |
// http://wiki.apidesign.org/wiki/PropertyFiles |
218 |
return PERSISTENCE_NEVER; |
236 |
p.setProperty("version", "1.0"); |
|
|
237 |
// TODO store your settings |
219 |
} |
238 |
} |
220 |
|
239 |
|
221 |
@Override |
240 |
void readProperties(java.util.Properties p) { |
222 |
public String preferredID() { |
241 |
String version = p.getProperty("version"); |
223 |
return "Image"; |
242 |
// TODO read your settings according to their version |
224 |
} |
243 |
} |
|
|
244 |
|
225 |
} |
245 |
} |