Lines 32-46
Link Here
|
32 |
import java.util.HashSet; |
32 |
import java.util.HashSet; |
33 |
import java.util.Iterator; |
33 |
import java.util.Iterator; |
34 |
import java.util.Set; |
34 |
import java.util.Set; |
|
|
35 |
import java.util.Observer; |
36 |
import java.util.Observable; |
35 |
import javax.swing.Action; |
37 |
import javax.swing.Action; |
|
|
38 |
import javax.swing.ButtonGroup; |
36 |
import javax.swing.Icon; |
39 |
import javax.swing.Icon; |
37 |
import javax.swing.ImageIcon; |
40 |
import javax.swing.ImageIcon; |
38 |
import javax.swing.JButton; |
41 |
import javax.swing.JButton; |
|
|
42 |
import javax.swing.JColorChooser; |
43 |
import javax.swing.JFormattedTextField; |
39 |
import javax.swing.JLabel; |
44 |
import javax.swing.JLabel; |
|
|
45 |
import javax.swing.JOptionPane; |
40 |
import javax.swing.JPanel; |
46 |
import javax.swing.JPanel; |
41 |
import javax.swing.JScrollPane; |
47 |
import javax.swing.JScrollPane; |
|
|
48 |
import javax.swing.JSpinner; |
49 |
import javax.swing.JTextField; |
42 |
import javax.swing.JToggleButton; |
50 |
import javax.swing.JToggleButton; |
43 |
import javax.swing.JToolBar; |
51 |
import javax.swing.JToolBar; |
|
|
52 |
import javax.swing.SpinnerModel; |
53 |
import javax.swing.SpinnerNumberModel; |
44 |
|
54 |
|
45 |
import org.openide.filesystems.FileObject; |
55 |
import org.openide.filesystems.FileObject; |
46 |
import org.openide.filesystems.FileUtil; |
56 |
import org.openide.filesystems.FileUtil; |
Lines 60-66
Link Here
|
60 |
* @author Petr Hamernik, Ian Formanek, Lukas Tadial |
70 |
* @author Petr Hamernik, Ian Formanek, Lukas Tadial |
61 |
* @author Marian Petras |
71 |
* @author Marian Petras |
62 |
*/ |
72 |
*/ |
63 |
public class ImageViewer extends CloneableTopComponent { |
73 |
public class ImageViewer extends CloneableTopComponent implements Observer { |
64 |
|
74 |
|
65 |
/** Serialized version UID. */ |
75 |
/** Serialized version UID. */ |
66 |
static final long serialVersionUID =6960127954234034486L; |
76 |
static final long serialVersionUID =6960127954234034486L; |
Lines 72-91
Link Here
|
72 |
private NBImageIcon storedImage; |
82 |
private NBImageIcon storedImage; |
73 |
|
83 |
|
74 |
/** Component showing image. */ |
84 |
/** Component showing image. */ |
75 |
private JPanel panel; |
85 |
private ImageDisplayEdit panel; |
76 |
|
86 |
|
77 |
/** Scale of image. */ |
87 |
/** Scale of image. */ |
78 |
private double scale = 1.0D; |
88 |
private double scale = 1.0D; |
79 |
|
89 |
|
80 |
/** On/off grid. */ |
|
|
81 |
private boolean showGrid = false; |
82 |
|
83 |
/** Increase/decrease factor. */ |
90 |
/** Increase/decrease factor. */ |
84 |
private final double changeFactor = Math.sqrt(2.0D); |
91 |
private final double changeFactor = Math.sqrt(2.0D); |
85 |
|
92 |
|
86 |
/** Grid color. */ |
|
|
87 |
private final Color gridColor = Color.black; |
88 |
|
89 |
/** Listens for name changes. */ |
93 |
/** Listens for name changes. */ |
90 |
private PropertyChangeListener nameChangeL; |
94 |
private PropertyChangeListener nameChangeL; |
91 |
|
95 |
|
Lines 93-98
Link Here
|
93 |
private final Collection/*<JButton>*/ toolbarButtons |
97 |
private final Collection/*<JButton>*/ toolbarButtons |
94 |
= new ArrayList/*<JButton>*/(11); |
98 |
= new ArrayList/*<JButton>*/(11); |
95 |
|
99 |
|
|
|
100 |
/** The tool selected */ |
101 |
private int Tool = 1; |
102 |
|
103 |
/** The line width selection */ |
104 |
private int lineWidth = 1; |
105 |
|
106 |
/** The fill type selection for rectangle and ellipse tools */ |
107 |
private int fillType = 1; |
108 |
|
109 |
private JToggleButton oneptLine; |
110 |
private JToggleButton threeptLine; |
111 |
private JToggleButton sixptLine; |
112 |
|
113 |
private JToggleButton noFillRect; |
114 |
private JToggleButton fillRect; |
115 |
private JToggleButton noLineRect; |
116 |
|
117 |
private JToggleButton noFillEllipse; |
118 |
private JToggleButton fillEllipse; |
119 |
private JToggleButton noLineEllipse; |
120 |
|
121 |
private JSpinner cornerRounding; |
122 |
|
123 |
private JColorChooser fgColor = new JColorChooser(); |
124 |
private JColorChooser bgColor = new JColorChooser(); |
96 |
|
125 |
|
97 |
/** Default constructor. Must be here, used during de-externalization */ |
126 |
/** Default constructor. Must be here, used during de-externalization */ |
98 |
public ImageViewer () { |
127 |
public ImageViewer () { |
Lines 123-128
Link Here
|
123 |
TopComponent.NodeName.connect (this, obj.getNodeDelegate ()); |
152 |
TopComponent.NodeName.connect (this, obj.getNodeDelegate ()); |
124 |
|
153 |
|
125 |
storedObject = obj; |
154 |
storedObject = obj; |
|
|
155 |
|
156 |
/* Add an observer */ |
157 |
storedObject.addObserver(this); |
126 |
|
158 |
|
127 |
// force closing panes in all workspaces, default is in current only |
159 |
// force closing panes in all workspaces, default is in current only |
128 |
setCloseOperation(TopComponent.CLOSE_EACH); |
160 |
setCloseOperation(TopComponent.CLOSE_EACH); |
Lines 132-137
Link Here
|
132 |
|
164 |
|
133 |
/* compose the whole panel: */ |
165 |
/* compose the whole panel: */ |
134 |
JToolBar toolbar = createToolBar(); |
166 |
JToolBar toolbar = createToolBar(); |
|
|
167 |
JToolBar edittoolbar = createEditToolBar(); |
135 |
Component view; |
168 |
Component view; |
136 |
if (storedImage != null) { |
169 |
if (storedImage != null) { |
137 |
view = createImageView(); |
170 |
view = createImageView(); |
Lines 142-147
Link Here
|
142 |
setLayout(new BorderLayout()); |
175 |
setLayout(new BorderLayout()); |
143 |
add(view, BorderLayout.CENTER); |
176 |
add(view, BorderLayout.CENTER); |
144 |
add(toolbar, BorderLayout.NORTH); |
177 |
add(toolbar, BorderLayout.NORTH); |
|
|
178 |
add(edittoolbar, BorderLayout.WEST); |
145 |
|
179 |
|
146 |
getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_ImageViewer")); |
180 |
getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_ImageViewer")); |
147 |
|
181 |
|
Lines 160-207
Link Here
|
160 |
/** |
194 |
/** |
161 |
*/ |
195 |
*/ |
162 |
private Component createImageView() { |
196 |
private Component createImageView() { |
163 |
panel = new JPanel() { |
197 |
panel = new ImageDisplayEdit(storedImage, getScale()); |
164 |
protected void paintComponent(Graphics g) { |
|
|
165 |
super.paintComponent(g); |
166 |
g.drawImage( |
167 |
storedImage.getImage(), |
168 |
0, |
169 |
0, |
170 |
(int)(getScale () * storedImage.getIconWidth ()), |
171 |
(int)(getScale () * storedImage.getIconHeight ()), |
172 |
0, |
173 |
0, |
174 |
storedImage.getIconWidth(), |
175 |
storedImage.getIconHeight(), |
176 |
this |
177 |
); |
178 |
|
179 |
if(showGrid) { |
180 |
int x = (int)(getScale () * storedImage.getIconWidth ()); |
181 |
int y = (int)(getScale () * storedImage.getIconHeight ()); |
182 |
|
183 |
double gridDistance = getScale(); |
184 |
|
185 |
if(gridDistance < 2) |
186 |
// Disable painting of grid if no image pixels would be visible. |
187 |
return; |
188 |
|
189 |
g.setColor(gridColor); |
190 |
|
191 |
double actualDistance = gridDistance; |
192 |
for(int i = (int)actualDistance; i < x ;actualDistance += gridDistance, i = (int)actualDistance) { |
193 |
g.drawLine(i,0,i,(y-1)); |
194 |
} |
195 |
|
196 |
actualDistance = gridDistance; |
197 |
for(int j = (int)actualDistance; j < y; actualDistance += gridDistance, j = (int)actualDistance) { |
198 |
g.drawLine(0,j,(x-1),j); |
199 |
} |
200 |
} |
201 |
|
202 |
} |
203 |
|
204 |
}; |
205 |
storedImage.setImageObserver(panel); |
198 |
storedImage.setImageObserver(panel); |
206 |
panel.setPreferredSize(new Dimension(storedImage.getIconWidth(), storedImage.getIconHeight() )); |
199 |
panel.setPreferredSize(new Dimension(storedImage.getIconWidth(), storedImage.getIconHeight() )); |
207 |
JScrollPane scroll = new JScrollPane(panel); |
200 |
JScrollPane scroll = new JScrollPane(panel); |
Lines 348-353
Link Here
|
348 |
return toolBar; |
341 |
return toolBar; |
349 |
} |
342 |
} |
350 |
|
343 |
|
|
|
344 |
//** Creates edittoolbar. */ |
345 |
private JToolBar createEditToolBar() |
346 |
{ |
347 |
/* |
348 |
BTN_Select=1 |
349 |
BTN_Polygon=2 |
350 |
BTN_Pen=3 |
351 |
BTN_Brush=4 |
352 |
BTN_Arc=5 |
353 |
BTN_Line=6 |
354 |
BTN_Rectangle=7 |
355 |
BTN_Ellipse=8 |
356 |
BTN_Fill=9 |
357 |
BTN_Spray=10 |
358 |
*/ |
359 |
|
360 |
ButtonGroup bgGroup = new javax.swing.ButtonGroup(); |
361 |
ButtonGroup bgLineWidth = new javax.swing.ButtonGroup(); |
362 |
ButtonGroup bgRect = new javax.swing.ButtonGroup(); |
363 |
ButtonGroup bgEllipse = new javax.swing.ButtonGroup(); |
364 |
JToolBar editToolBar = new javax.swing.JToolBar(); |
365 |
editToolBar.setName (NbBundle.getBundle(ImageViewer.class).getString("ACSN_EditToolbar")); |
366 |
editToolBar.setOrientation(1); |
367 |
|
368 |
setLayout(null); |
369 |
|
370 |
editToolBar.setFloatable (false); |
371 |
|
372 |
JToggleButton selectTButton = new JToggleButton(); |
373 |
editToolBar.add(selectTButton = getSelectTButton()); |
374 |
selectTButton.setSelected(true); |
375 |
bgGroup.add(selectTButton); |
376 |
|
377 |
JToggleButton polygonTButton = new JToggleButton(); |
378 |
editToolBar.add(polygonTButton = getPolygonTButton()); |
379 |
bgGroup.add(polygonTButton); |
380 |
|
381 |
JToggleButton penTButton = new JToggleButton(); |
382 |
editToolBar.add(penTButton = getPenTButton()); |
383 |
bgGroup.add(penTButton); |
384 |
|
385 |
JToggleButton brushTButton = new JToggleButton(); |
386 |
editToolBar.add(brushTButton = getBrushTButton()); |
387 |
bgGroup.add(brushTButton); |
388 |
|
389 |
JToggleButton arcTButton = new JToggleButton(); |
390 |
editToolBar.add(arcTButton = getArcTButton()); |
391 |
bgGroup.add(arcTButton); |
392 |
|
393 |
JToggleButton lineTButton = new JToggleButton(); |
394 |
editToolBar.add(lineTButton = getLineTButton()); |
395 |
bgGroup.add(lineTButton); |
396 |
|
397 |
JToggleButton rectangleTButton = new JToggleButton(); |
398 |
editToolBar.add(rectangleTButton = getRectangleTButton()); |
399 |
bgGroup.add(rectangleTButton); |
400 |
|
401 |
JToggleButton ovalTButton = new JToggleButton(); |
402 |
editToolBar.add(ovalTButton = getEllipseTButton()); |
403 |
bgGroup.add(ovalTButton); |
404 |
|
405 |
JToggleButton fillTButton = new JToggleButton(); |
406 |
editToolBar.add(fillTButton = getFillTButton()); |
407 |
bgGroup.add(fillTButton); |
408 |
|
409 |
JToggleButton sprayTButton = new JToggleButton(); |
410 |
editToolBar.add(sprayTButton = getSprayTButton()); |
411 |
bgGroup.add(sprayTButton); |
412 |
|
413 |
JButton foregroundButton = new JButton(); |
414 |
editToolBar.add(foregroundButton = getForegroundButton()); |
415 |
|
416 |
editToolBar.addSeparator(new Dimension(2,2)); |
417 |
|
418 |
JButton backgroundButton = new JButton(); |
419 |
editToolBar.add(backgroundButton = getBackgroundButton()); |
420 |
|
421 |
editToolBar.addSeparator(new Dimension(2,10)); |
422 |
|
423 |
oneptLine = new JToggleButton(); |
424 |
editToolBar.add(oneptLine = getOneptLineTButton()); |
425 |
bgLineWidth.add(oneptLine); |
426 |
oneptLine.setSelected(true); |
427 |
oneptLine.setVisible(false); |
428 |
|
429 |
threeptLine = new JToggleButton(); |
430 |
editToolBar.add(threeptLine = getThreeptLineTButton()); |
431 |
bgLineWidth.add(threeptLine); |
432 |
threeptLine.setVisible(false); |
433 |
|
434 |
sixptLine = new JToggleButton(); |
435 |
editToolBar.add(sixptLine = getSixptLineTButton()); |
436 |
bgLineWidth.add(sixptLine); |
437 |
sixptLine.setVisible(false); |
438 |
|
439 |
editToolBar.addSeparator(new Dimension(2,6)); |
440 |
|
441 |
noFillRect = new JToggleButton(); |
442 |
editToolBar.add(noFillRect = getNoFillRectTButton()); |
443 |
bgRect.add(noFillRect); |
444 |
noFillRect.setSelected(true); |
445 |
noFillRect.setVisible(false); |
446 |
|
447 |
fillRect = new JToggleButton(); |
448 |
editToolBar.add(fillRect = getFillRectTButton()); |
449 |
bgRect.add(fillRect); |
450 |
fillRect.setVisible(false); |
451 |
|
452 |
noLineRect = new JToggleButton(); |
453 |
editToolBar.add(noLineRect = getNoLineRectTButton()); |
454 |
bgRect.add(noLineRect); |
455 |
noLineRect.setVisible(false); |
456 |
|
457 |
editToolBar.addSeparator(new Dimension(2,6)); |
458 |
|
459 |
noFillEllipse = new JToggleButton(); |
460 |
editToolBar.add(noFillEllipse = getNoFillEllipseTButton()); |
461 |
bgEllipse.add(noFillEllipse); |
462 |
noFillEllipse.setSelected(true); |
463 |
noFillEllipse.setVisible(false); |
464 |
|
465 |
fillEllipse = new JToggleButton(); |
466 |
editToolBar.add(fillEllipse = getFillEllipseTButton()); |
467 |
bgEllipse.add(fillEllipse); |
468 |
fillEllipse.setVisible(false); |
469 |
|
470 |
noLineEllipse = new JToggleButton(); |
471 |
editToolBar.add(noLineEllipse = getNoLineEllipseTButton()); |
472 |
bgEllipse.add(noLineEllipse); |
473 |
noLineEllipse.setVisible(false); |
474 |
|
475 |
editToolBar.addSeparator(new Dimension(2,6)); |
476 |
|
477 |
//JPanel textPanel = new JPanel(); |
478 |
SpinnerModel cornerRoundingModel = new SpinnerNumberModel(0, 0, 100, 5); |
479 |
cornerRounding = new JSpinner(cornerRoundingModel); |
480 |
cornerRounding.setSize(100,100); |
481 |
|
482 |
JFormattedTextField tf = ((JSpinner.DefaultEditor)cornerRounding.getEditor()).getTextField(); |
483 |
tf.setEditable(false); |
484 |
tf.setBackground(Color.white); |
485 |
|
486 |
cornerRounding.setVisible(false); |
487 |
|
488 |
editToolBar.add(cornerRounding); |
489 |
|
490 |
add(editToolBar); |
491 |
|
492 |
return editToolBar; |
493 |
} |
494 |
|
351 |
/** Updates the name and tooltip of this top component according to associated data object. */ |
495 |
/** Updates the name and tooltip of this top component according to associated data object. */ |
352 |
private void updateName () { |
496 |
private void updateName () { |
353 |
// update name |
497 |
// update name |
Lines 541-546
Link Here
|
541 |
SystemAction.get(ZoomInAction.class), |
685 |
SystemAction.get(ZoomInAction.class), |
542 |
SystemAction.get(ZoomOutAction.class), |
686 |
SystemAction.get(ZoomOutAction.class), |
543 |
SystemAction.get(CustomZoomAction.class), |
687 |
SystemAction.get(CustomZoomAction.class), |
|
|
688 |
SystemAction.get(ConvertToAction.class), |
544 |
null}, |
689 |
null}, |
545 |
oldValue); |
690 |
oldValue); |
546 |
} |
691 |
} |
Lines 609-614
Link Here
|
609 |
|
754 |
|
610 |
resizePanel(); |
755 |
resizePanel(); |
611 |
panel.repaint(0, 0, panel.getWidth(), panel.getHeight()); |
756 |
panel.repaint(0, 0, panel.getWidth(), panel.getHeight()); |
|
|
757 |
panel.setScale(scale); |
612 |
} |
758 |
} |
613 |
|
759 |
|
614 |
/** Return zooming factor.*/ |
760 |
/** Return zooming factor.*/ |
Lines 619-624
Link Here
|
619 |
/** Change proportion "out"*/ |
765 |
/** Change proportion "out"*/ |
620 |
private void scaleOut() { |
766 |
private void scaleOut() { |
621 |
scale = scale / changeFactor; |
767 |
scale = scale / changeFactor; |
|
|
768 |
panel.setScale(scale); |
622 |
} |
769 |
} |
623 |
|
770 |
|
624 |
/** Change proportion "in"*/ |
771 |
/** Change proportion "in"*/ |
Lines 632-637
Link Here
|
632 |
if (newComputedScale == oldComputedScale) |
779 |
if (newComputedScale == oldComputedScale) |
633 |
// Has to increase. |
780 |
// Has to increase. |
634 |
scale = newComputedScale + 1.0D; |
781 |
scale = newComputedScale + 1.0D; |
|
|
782 |
|
783 |
panel.setScale(scale); |
784 |
} |
785 |
|
786 |
public void convertTo() { |
787 |
try { |
788 |
storedObject.convertTo(this); |
789 |
} catch(IOException e) { |
790 |
JOptionPane.showMessageDialog(null, NbBundle.getMessage(ImageViewer.class, "MSG_CouldNotConvert"), NbBundle.getMessage(ImageViewer.class, "LBL_CouldNotConvert"), JOptionPane.ERROR_MESSAGE); |
791 |
} |
792 |
} |
793 |
|
794 |
public void update(Observable o, Object arg){ |
795 |
updateView(storedObject); |
796 |
panel.reload(storedImage); |
635 |
} |
797 |
} |
636 |
|
798 |
|
637 |
/** Gets zoom button. */ |
799 |
/** Gets zoom button. */ |
Lines 676-687
Link Here
|
676 |
button.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Grid_BTN_Mnem").charAt(0)); |
838 |
button.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Grid_BTN_Mnem").charAt(0)); |
677 |
button.addActionListener(new ActionListener() { |
839 |
button.addActionListener(new ActionListener() { |
678 |
public void actionPerformed(ActionEvent evt) { |
840 |
public void actionPerformed(ActionEvent evt) { |
679 |
showGrid = !showGrid; |
841 |
panel.toggleGrid(); |
680 |
panel.repaint(0, 0, panel.getWidth(), panel.getHeight()); |
842 |
panel.repaint(0, 0, panel.getWidth(), panel.getHeight()); |
681 |
} |
843 |
} |
682 |
}); |
844 |
}); |
683 |
|
845 |
|
684 |
return button; |
846 |
return button; |
|
|
847 |
} |
848 |
|
849 |
/** Gets ellipse button.*/ |
850 |
private JToggleButton getEllipseTButton() { |
851 |
JToggleButton ellipseTButton = new JToggleButton(); |
852 |
ellipseTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Ellipse")); |
853 |
ellipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/oval.gif"))); |
854 |
ellipseTButton.setLabel(""); |
855 |
|
856 |
ellipseTButton.addActionListener(new ActionListener() { |
857 |
public void actionPerformed(ActionEvent evt) { |
858 |
setTool(8); |
859 |
setSubtoolsVisible(); |
860 |
} |
861 |
}); |
862 |
|
863 |
return ellipseTButton; |
864 |
} |
865 |
|
866 |
/** Gets rectangle button.*/ |
867 |
private JToggleButton getRectangleTButton(){ |
868 |
JToggleButton rectangleTButton = new JToggleButton(); |
869 |
rectangleTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Rectangle")); |
870 |
rectangleTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/rect.gif"))); |
871 |
rectangleTButton.setLabel(""); |
872 |
|
873 |
rectangleTButton.addActionListener(new ActionListener() { |
874 |
public void actionPerformed(ActionEvent evt) { |
875 |
setTool(7); |
876 |
setSubtoolsVisible(); |
877 |
} |
878 |
}); |
879 |
|
880 |
return rectangleTButton; |
881 |
} |
882 |
|
883 |
/** Gets fill button.*/ |
884 |
private JToggleButton getFillTButton(){ |
885 |
JToggleButton fillTButton = new JToggleButton(); |
886 |
fillTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Fill")); |
887 |
fillTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fill.gif"))); |
888 |
fillTButton.setLabel(""); |
889 |
|
890 |
fillTButton.addActionListener(new ActionListener() { |
891 |
public void actionPerformed(ActionEvent evt) { |
892 |
setTool(9); |
893 |
setSubtoolsVisible(); |
894 |
} |
895 |
}); |
896 |
|
897 |
return fillTButton; |
898 |
} |
899 |
|
900 |
/** Gets line button.*/ |
901 |
private JToggleButton getLineTButton(){ |
902 |
JToggleButton lineTButton = new JToggleButton(); |
903 |
lineTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Line")); |
904 |
lineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/line.gif"))); |
905 |
lineTButton.setLabel(""); |
906 |
lineTButton.addActionListener(new ActionListener() { |
907 |
public void actionPerformed(ActionEvent evt) { |
908 |
setTool(6); |
909 |
setSubtoolsVisible(); |
910 |
} |
911 |
}); |
912 |
|
913 |
return lineTButton; |
914 |
} |
915 |
|
916 |
/** Gets select button.*/ |
917 |
private JToggleButton getSelectTButton(){ |
918 |
JToggleButton selectTButton = new JToggleButton(); |
919 |
selectTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Select")); |
920 |
selectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/arrow.gif"))); |
921 |
selectTButton.setLabel(""); |
922 |
|
923 |
selectTButton.addActionListener(new ActionListener() { |
924 |
public void actionPerformed(ActionEvent evt) { |
925 |
setTool(1); |
926 |
setSubtoolsVisible(); |
927 |
} |
928 |
}); |
929 |
|
930 |
return selectTButton; |
931 |
} |
932 |
|
933 |
/** Gets polygon button.*/ |
934 |
private JToggleButton getPolygonTButton(){ |
935 |
JToggleButton polygonTButton = new JToggleButton(); |
936 |
polygonTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Polygon")); |
937 |
polygonTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/polygon.gif"))); |
938 |
polygonTButton.setLabel(""); |
939 |
|
940 |
polygonTButton.addActionListener(new ActionListener() { |
941 |
public void actionPerformed(ActionEvent evt) { |
942 |
setTool(2); |
943 |
setSubtoolsVisible(); |
944 |
} |
945 |
}); |
946 |
|
947 |
return polygonTButton; |
948 |
} |
949 |
|
950 |
/** Gets pen button.*/ |
951 |
private JToggleButton getPenTButton(){ |
952 |
JToggleButton penTButton = new JToggleButton(); |
953 |
penTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Pen")); |
954 |
penTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/pen.gif"))); |
955 |
penTButton.setLabel(""); |
956 |
|
957 |
penTButton.addActionListener(new ActionListener() { |
958 |
public void actionPerformed(ActionEvent evt) { |
959 |
setTool(3); |
960 |
setSubtoolsVisible(); |
961 |
} |
962 |
}); |
963 |
|
964 |
return penTButton; |
965 |
} |
966 |
|
967 |
/** Gets brush button.*/ |
968 |
private JToggleButton getBrushTButton(){ |
969 |
JToggleButton brushTButton = new JToggleButton(); |
970 |
brushTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Brush")); |
971 |
brushTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/brush.gif"))); |
972 |
brushTButton.setLabel(""); |
973 |
|
974 |
brushTButton.addActionListener(new ActionListener() { |
975 |
public void actionPerformed(ActionEvent evt) { |
976 |
setTool(4); |
977 |
setSubtoolsVisible(); |
978 |
} |
979 |
}); |
980 |
|
981 |
return brushTButton; |
982 |
} |
983 |
|
984 |
/** Gets arc button.*/ |
985 |
private JToggleButton getArcTButton(){ |
986 |
JToggleButton arcTButton = new JToggleButton(); |
987 |
arcTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Arc")); |
988 |
arcTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/arc.gif"))); |
989 |
arcTButton.setLabel(""); |
990 |
|
991 |
arcTButton.addActionListener(new ActionListener() { |
992 |
public void actionPerformed(ActionEvent evt) { |
993 |
setTool(5); |
994 |
setSubtoolsVisible(); |
995 |
} |
996 |
}); |
997 |
|
998 |
return arcTButton; |
999 |
} |
1000 |
|
1001 |
/** Gets spray button.*/ |
1002 |
private JToggleButton getSprayTButton(){ |
1003 |
JToggleButton sprayTButton = new JToggleButton(); |
1004 |
sprayTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Spray")); |
1005 |
sprayTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/spray.gif"))); |
1006 |
sprayTButton.setLabel(""); |
1007 |
|
1008 |
sprayTButton.addActionListener(new ActionListener() { |
1009 |
public void actionPerformed(ActionEvent evt) { |
1010 |
setTool(10); |
1011 |
setSubtoolsVisible(); |
1012 |
} |
1013 |
}); |
1014 |
|
1015 |
return sprayTButton; |
1016 |
} |
1017 |
|
1018 |
/** Gets foreground button.*/ |
1019 |
private JButton getForegroundButton(){ |
1020 |
final JButton foregroundButton = new JButton(" "); |
1021 |
foregroundButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_SetLineColor")); |
1022 |
foregroundButton.setBackground(new Color(0, 0, 0)); |
1023 |
foregroundButton.addActionListener(new ActionListener() |
1024 |
{ |
1025 |
public void actionPerformed(ActionEvent evt) |
1026 |
{ |
1027 |
Color newColor = fgColor.showDialog(null,NbBundle.getMessage(ImageViewer.class, "LBL_ForegroundColor"), foregroundButton.getForeground()); |
1028 |
foregroundButton.setBackground(newColor); |
1029 |
|
1030 |
panel.setPrimaryColor(newColor); |
1031 |
} |
1032 |
}); |
1033 |
|
1034 |
return foregroundButton; |
1035 |
} |
1036 |
|
1037 |
/** Gets background button.*/ |
1038 |
private JButton getBackgroundButton(){ |
1039 |
final JButton backgroundButton = new JButton(" "); |
1040 |
backgroundButton.setBackground(new Color(128, 128, 255)); |
1041 |
backgroundButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_SetFillColor")); |
1042 |
backgroundButton.addActionListener(new ActionListener() |
1043 |
{ |
1044 |
public void actionPerformed(ActionEvent evt) |
1045 |
{ |
1046 |
Color newColor = bgColor.showDialog(null,NbBundle.getMessage(ImageViewer.class, "LBL_BackgroundColor"), backgroundButton.getBackground()); |
1047 |
backgroundButton.setBackground(newColor); |
1048 |
|
1049 |
panel.setSecondayColor(newColor); |
1050 |
} |
1051 |
}); |
1052 |
|
1053 |
return backgroundButton; |
1054 |
} |
1055 |
|
1056 |
/** Gets oneptLine button */ |
1057 |
private JToggleButton getOneptLineTButton(){ |
1058 |
JToggleButton oneptLineTButton = new JToggleButton(); |
1059 |
// oneptLineTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Spray")); |
1060 |
oneptLineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/1ptLine.gif"))); |
1061 |
oneptLineTButton.setLabel(""); |
1062 |
|
1063 |
oneptLineTButton.addActionListener(new ActionListener() { |
1064 |
public void actionPerformed(ActionEvent evt) { |
1065 |
setLineWidth(1); |
1066 |
} |
1067 |
}); |
1068 |
|
1069 |
return oneptLineTButton; |
1070 |
} |
1071 |
|
1072 |
/** Gets threeptLine button */ |
1073 |
private JToggleButton getThreeptLineTButton(){ |
1074 |
JToggleButton threeptLineTButton = new JToggleButton(); |
1075 |
// threeptLineTButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_Spray")); |
1076 |
threeptLineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/3ptLine.gif"))); |
1077 |
threeptLineTButton.setLabel(""); |
1078 |
|
1079 |
threeptLineTButton.addActionListener(new ActionListener() { |
1080 |
public void actionPerformed(ActionEvent evt) { |
1081 |
setLineWidth(3); |
1082 |
} |
1083 |
}); |
1084 |
|
1085 |
return threeptLineTButton; |
1086 |
} |
1087 |
|
1088 |
/** Gets sixptLine button */ |
1089 |
private JToggleButton getSixptLineTButton(){ |
1090 |
JToggleButton sixptLineTButton = new JToggleButton(); |
1091 |
sixptLineTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/6ptLine.gif"))); |
1092 |
sixptLineTButton.setLabel(""); |
1093 |
|
1094 |
sixptLineTButton.addActionListener(new ActionListener() { |
1095 |
public void actionPerformed(ActionEvent evt) { |
1096 |
setLineWidth(6); |
1097 |
} |
1098 |
}); |
1099 |
|
1100 |
return sixptLineTButton; |
1101 |
} |
1102 |
|
1103 |
/** Gets noFillRect button */ |
1104 |
private JToggleButton getNoFillRectTButton(){ |
1105 |
JToggleButton noFillRectTButton = new JToggleButton(); |
1106 |
noFillRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noFillRect.gif"))); |
1107 |
noFillRectTButton.setLabel(""); |
1108 |
|
1109 |
noFillRectTButton.addActionListener(new ActionListener() { |
1110 |
public void actionPerformed(ActionEvent evt) { |
1111 |
setFillType(1); |
1112 |
} |
1113 |
}); |
1114 |
|
1115 |
return noFillRectTButton; |
1116 |
} |
1117 |
|
1118 |
/** Gets fillRect button */ |
1119 |
private JToggleButton getFillRectTButton(){ |
1120 |
JToggleButton fillRectTButton = new JToggleButton(); |
1121 |
fillRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fillRect.gif"))); |
1122 |
fillRectTButton.setLabel(""); |
1123 |
|
1124 |
fillRectTButton.addActionListener(new ActionListener() { |
1125 |
public void actionPerformed(ActionEvent evt) { |
1126 |
setFillType(2); |
1127 |
} |
1128 |
}); |
1129 |
|
1130 |
return fillRectTButton; |
1131 |
} |
1132 |
|
1133 |
/** Gets noLineRect button */ |
1134 |
private JToggleButton getNoLineRectTButton(){ |
1135 |
JToggleButton noLineRectTButton = new JToggleButton(); |
1136 |
noLineRectTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noLineRect.gif"))); |
1137 |
noLineRectTButton.setLabel(""); |
1138 |
|
1139 |
noLineRectTButton.addActionListener(new ActionListener() { |
1140 |
public void actionPerformed(ActionEvent evt) { |
1141 |
setFillType(3); |
1142 |
} |
1143 |
}); |
1144 |
|
1145 |
return noLineRectTButton; |
1146 |
} |
1147 |
|
1148 |
/** Gets noFillEllipse button */ |
1149 |
private JToggleButton getNoFillEllipseTButton(){ |
1150 |
JToggleButton noFillEllipseTButton = new JToggleButton(); |
1151 |
noFillEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noFillEllipse.gif"))); |
1152 |
noFillEllipseTButton.setLabel(""); |
1153 |
|
1154 |
noFillEllipseTButton.addActionListener(new ActionListener() { |
1155 |
public void actionPerformed(ActionEvent evt) { |
1156 |
setFillType(1); |
1157 |
} |
1158 |
}); |
1159 |
|
1160 |
return noFillEllipseTButton; |
1161 |
} |
1162 |
|
1163 |
/** Gets fillEllipse button */ |
1164 |
private JToggleButton getFillEllipseTButton(){ |
1165 |
JToggleButton fillEllipseTButton = new JToggleButton(); |
1166 |
fillEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/fillEllipse.gif"))); |
1167 |
fillEllipseTButton.setLabel(""); |
1168 |
|
1169 |
fillEllipseTButton.addActionListener(new ActionListener() { |
1170 |
public void actionPerformed(ActionEvent evt) { |
1171 |
setFillType(2); |
1172 |
} |
1173 |
}); |
1174 |
|
1175 |
return fillEllipseTButton; |
1176 |
} |
1177 |
|
1178 |
/** Gets noLineEllipse button */ |
1179 |
private JToggleButton getNoLineEllipseTButton(){ |
1180 |
JToggleButton noLineEllipseTButton = new JToggleButton(); |
1181 |
noLineEllipseTButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/image/noLineEllipse.gif"))); |
1182 |
noLineEllipseTButton.setLabel(""); |
1183 |
|
1184 |
noLineEllipseTButton.addActionListener(new ActionListener() { |
1185 |
public void actionPerformed(ActionEvent evt) { |
1186 |
setFillType(3); |
1187 |
} |
1188 |
}); |
1189 |
|
1190 |
return noLineEllipseTButton; |
1191 |
} |
1192 |
|
1193 |
/** set the lines widths visible */ |
1194 |
private void setSubtoolsVisible(){ |
1195 |
switch (getTool()){ |
1196 |
case 2: |
1197 |
case 5: |
1198 |
case 6: |
1199 |
case 7: |
1200 |
case 8: |
1201 |
oneptLine.setVisible(true); |
1202 |
threeptLine.setVisible(true); |
1203 |
sixptLine.setVisible(true); |
1204 |
break; |
1205 |
default: |
1206 |
oneptLine.setVisible(false); |
1207 |
threeptLine.setVisible(false); |
1208 |
sixptLine.setVisible(false); |
1209 |
break; |
1210 |
} |
1211 |
|
1212 |
if (getTool() == 7){ |
1213 |
noFillRect.setVisible(true); |
1214 |
fillRect.setVisible(true); |
1215 |
noLineRect.setVisible(true); |
1216 |
cornerRounding.setVisible(true); |
1217 |
setFillType(1); |
1218 |
noFillRect.setSelected(true); |
1219 |
}else{ |
1220 |
noFillRect.setVisible(false); |
1221 |
fillRect.setVisible(false); |
1222 |
noLineRect.setVisible(false); |
1223 |
cornerRounding.setVisible(false); |
1224 |
} |
1225 |
|
1226 |
if (getTool() == 8){ |
1227 |
noFillEllipse.setVisible(true); |
1228 |
fillEllipse.setVisible(true); |
1229 |
noLineEllipse.setVisible(true); |
1230 |
setFillType(1); |
1231 |
noFillEllipse.setSelected(true); |
1232 |
}else{ |
1233 |
noFillEllipse.setVisible(false); |
1234 |
fillEllipse.setVisible(false); |
1235 |
noLineEllipse.setVisible(false); |
1236 |
} |
1237 |
} |
1238 |
|
1239 |
/** Set the tool. */ |
1240 |
public void setTool(int selection){ |
1241 |
Tool = selection; |
1242 |
} |
1243 |
|
1244 |
/** Get the tool. */ |
1245 |
public int getTool(){ |
1246 |
return Tool; |
1247 |
} |
1248 |
|
1249 |
/** Set the sub tool */ |
1250 |
public void setLineWidth(int selection){ |
1251 |
lineWidth = selection; |
1252 |
} |
1253 |
|
1254 |
/** Get the sub tool */ |
1255 |
public int getLineWidth(){ |
1256 |
return lineWidth; |
1257 |
} |
1258 |
|
1259 |
/** Set the sub tool */ |
1260 |
public void setFillType(int selection){ |
1261 |
fillType = selection; |
1262 |
} |
1263 |
|
1264 |
/** Get the sub tool */ |
1265 |
public int getFillType(){ |
1266 |
return fillType; |
1267 |
} |
1268 |
|
1269 |
public int getCornerRoundingFactor(){ |
1270 |
return ((Integer)(cornerRounding.getValue())).intValue(); |
685 |
} |
1271 |
} |
686 |
|
1272 |
|
687 |
} |
1273 |
} |