KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > image > ImageViewer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.image;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Color JavaDoc;
24 import java.awt.Component JavaDoc;
25 import java.awt.Dimension JavaDoc;
26 import java.awt.Graphics JavaDoc;
27 import java.awt.Image JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.beans.PropertyChangeEvent JavaDoc;
31 import java.beans.PropertyChangeListener JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.ObjectInput JavaDoc;
34 import java.io.ObjectOutput JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.HashSet JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.Set JavaDoc;
40 import javax.swing.JButton JavaDoc;
41 import javax.swing.JLabel JavaDoc;
42 import javax.swing.JPanel JavaDoc;
43 import javax.swing.JScrollPane JavaDoc;
44 import javax.swing.JToolBar JavaDoc;
45 import org.openide.filesystems.FileObject;
46 import org.openide.filesystems.FileUtil;
47 import org.openide.loaders.DataObject;
48 import org.openide.text.CloneableEditorSupport;
49 import org.openide.util.WeakListeners;
50 import org.openide.util.HelpCtx;
51 import org.openide.util.NbBundle;
52 import org.openide.util.Utilities;
53 import org.openide.util.actions.SystemAction;
54 import org.openide.windows.CloneableTopComponent;
55 import org.openide.windows.Mode;
56 import org.openide.windows.TopComponent;
57 import org.openide.windows.WindowManager;
58 import org.openide.windows.Workspace;
59
60 /**
61  * Top component providing a viewer for images.
62  * @author Petr Hamernik, Ian Formanek, Lukas Tadial
63  * @author Marian Petras
64  */

65 public class ImageViewer extends CloneableTopComponent {
66
67     /** Serialized version UID. */
68     static final long serialVersionUID =6960127954234034486L;
69     
70     /** <code>ImageDataObject</code> which image is viewed. */
71     private ImageDataObject storedObject;
72     
73     /** Viewed image. */
74     private NBImageIcon storedImage;
75     
76     /** Component showing image. */
77     private JPanel JavaDoc panel;
78     
79     /** Scale of image. */
80     private double scale = 1.0D;
81     
82     /** On/off grid. */
83     private boolean showGrid = false;
84     
85     /** Increase/decrease factor. */
86     private final double changeFactor = Math.sqrt(2.0D);
87     
88     /** Grid color. */
89     private final Color JavaDoc gridColor = Color.black;
90     
91     /** Listens for name changes. */
92     private PropertyChangeListener JavaDoc nameChangeL;
93     
94     /** collection of all buttons in the toolbar */
95     private final Collection JavaDoc/*<JButton>*/ toolbarButtons
96                                           = new ArrayList JavaDoc/*<JButton>*/(11);
97     
98     
99     /** Default constructor. Must be here, used during de-externalization */
100     public ImageViewer () {
101         super();
102     }
103     
104     /** Create a new image viewer.
105      * @param obj the data object holding the image
106      */

107     public ImageViewer(ImageDataObject obj) {
108         initialize(obj);
109     }
110     
111     /** Overriden to explicitely set persistence type of ImageViewer
112      * to PERSISTENCE_ONLY_OPENED */

113     public int getPersistenceType() {
114         return TopComponent.PERSISTENCE_ONLY_OPENED;
115     }
116     
117     /** Reloads icon. */
118     protected void reloadIcon() {
119         resizePanel();
120         panel.repaint();
121     }
122     
123     /** Initializes member variables and set listener for name changes on DataObject. */
124     private void initialize(ImageDataObject obj) {
125         TopComponent.NodeName.connect (this, obj.getNodeDelegate ());
126         setToolTipText(FileUtil.getFileDisplayName(obj.getPrimaryFile()));
127         
128         storedObject = obj;
129             
130         // force closing panes in all workspaces, default is in current only
131
setCloseOperation(TopComponent.CLOSE_EACH);
132         
133         /* try to load the image: */
134         String JavaDoc errMsg = loadImage(storedObject);
135         
136         /* compose the whole panel: */
137         JToolBar JavaDoc toolbar = createToolBar();
138         Component JavaDoc view;
139         if (storedImage != null) {
140             view = createImageView();
141         } else {
142             view = createMessagePanel(errMsg);
143             setToolbarButtonsEnabled(false);
144         }
145         setLayout(new BorderLayout JavaDoc());
146         add(view, BorderLayout.CENTER);
147         add(toolbar, BorderLayout.NORTH);
148
149         getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_ImageViewer"));
150         
151         nameChangeL = new PropertyChangeListener JavaDoc() {
152             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
153                 if (DataObject.PROP_COOKIE.equals(evt.getPropertyName()) ||
154                 DataObject.PROP_NAME.equals(evt.getPropertyName())) {
155                     updateName();
156                 }
157             }
158         };
159         
160         obj.addPropertyChangeListener(WeakListeners.propertyChange(nameChangeL, obj));
161     }
162     
163     /**
164      */

165     private Component JavaDoc createImageView() {
166         panel = new JPanel JavaDoc() {
167             protected void paintComponent(Graphics JavaDoc g) {
168                 super.paintComponent(g);
169                 g.drawImage(
170                     storedImage.getImage(),
171                     0,
172                     0,
173                     (int)(getScale () * storedImage.getIconWidth ()),
174                     (int)(getScale () * storedImage.getIconHeight ()),
175                     0,
176                     0,
177                     storedImage.getIconWidth(),
178                     storedImage.getIconHeight(),
179                     this
180                 );
181
182                 if(showGrid) {
183                     int x = (int)(getScale () * storedImage.getIconWidth ());
184                     int y = (int)(getScale () * storedImage.getIconHeight ());
185
186                     double gridDistance = getScale();
187
188                     if(gridDistance < 2)
189                         // Disable painting of grid if no image pixels would be visible.
190
return;
191
192                     g.setColor(gridColor);
193
194                     double actualDistance = gridDistance;
195                     for(int i = (int)actualDistance; i < x ;actualDistance += gridDistance, i = (int)actualDistance) {
196                         g.drawLine(i,0,i,(y-1));
197                     }
198
199                     actualDistance = gridDistance;
200                     for(int j = (int)actualDistance; j < y; actualDistance += gridDistance, j = (int)actualDistance) {
201                         g.drawLine(0,j,(x-1),j);
202                     }
203                 }
204
205             }
206
207         };
208         storedImage.setImageObserver(panel);
209         panel.setPreferredSize(new Dimension JavaDoc(storedImage.getIconWidth(), storedImage.getIconHeight() ));
210         JScrollPane JavaDoc scroll = new JScrollPane JavaDoc(panel);
211         
212         return scroll;
213     }
214     
215     /**
216      */

217     private Component JavaDoc createMessagePanel(final String JavaDoc msg) {
218         JPanel JavaDoc msgPanel = new JPanel JavaDoc(new java.awt.GridBagLayout JavaDoc());
219         msgPanel.add(new JLabel JavaDoc(msg),
220                      new java.awt.GridBagConstraints JavaDoc(
221                              0, 0, //gridx, gridy
222
1, 1, //gridwidth, gridheight
223
1.0d, 1.0d, //weightx, weighty
224
java.awt.GridBagConstraints.CENTER, //anchor
225
java.awt.GridBagConstraints.NONE, //fill
226
new java.awt.Insets JavaDoc(0, 0, 0, 0), //insets
227
10, 10)); //ipadx, ipady
228
return msgPanel;
229     }
230     
231     /**
232      */

233     void updateView(final ImageDataObject imageObj) {
234         boolean wasValid = (storedImage != null);
235         String JavaDoc errMsg = loadImage(imageObj);
236         boolean isValid = (storedImage != null);
237         
238         if (wasValid && isValid) {
239             reloadIcon();
240             return;
241         }
242         
243         Component JavaDoc view = (storedImage != null) ? createImageView()
244                                                : createMessagePanel(errMsg);
245         remove(0);
246         add(view, BorderLayout.CENTER, 0);
247         if (wasValid != isValid) {
248             setToolbarButtonsEnabled(isValid);
249         }
250     }
251     
252     /**
253      * Enables or disables all toolbar buttons.
254      *
255      * @param enabled <code>true</code> if all buttons should be enabled,
256      * <code>false</code> if all buttons should be disabled
257      */

258     private void setToolbarButtonsEnabled(final boolean enabled) {
259         assert toolbarButtons != null;
260         
261         final Iterator JavaDoc/*<JButton>*/ it = toolbarButtons.iterator();
262         while (it.hasNext()) {
263             ((JButton JavaDoc) it.next()).setEnabled(enabled);
264         }
265     }
266     
267     /**
268      * Loads an image from the given <code>ImageDataObject</code>.
269      * If the image is loaded successfully, it is stored
270      * to field {@link #storedImage}. The field is <code>null</code>ed
271      * in case of any failure.
272      *
273      * @param imageObj <code>ImageDataObject</code> to load the image from
274      * @return <code>null</code> if the image was loaded successfully,
275      * or a localized error message in case of failure
276      */

277     private String JavaDoc loadImage(final ImageDataObject imageObj) {
278         String JavaDoc errMsg;
279         try {
280             storedImage = NBImageIcon.load(imageObj);
281             if (storedImage != null) {
282                 errMsg = null;
283             } else {
284                 errMsg = NbBundle.getMessage(ImageViewer.class,
285                                              "MSG_CouldNotLoad"); //NOI18N
286
}
287         } catch (IOException JavaDoc ex) {
288             storedImage = null;
289             errMsg = NbBundle.getMessage(ImageViewer.class,
290                                          "MSG_ErrorWhileLoading"); //NOI18N
291
}
292         assert (storedImage == null) != (errMsg == null);
293         return errMsg;
294     }
295     
296     /** Creates toolbar. */
297     private JToolBar JavaDoc createToolBar() {
298         // Definition of toolbar.
299
JToolBar JavaDoc toolBar = new JToolBar JavaDoc();
300         toolBar.setFloatable (false);
301         toolBar.setName (NbBundle.getBundle(ImageViewer.class).getString("ACSN_Toolbar"));
302         toolBar.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACSD_Toolbar"));
303             JButton JavaDoc outButton = new JButton JavaDoc(SystemAction.get(ZoomOutAction.class));
304             outButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomOut"));
305             outButton.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Out_BTN_Mnem").charAt(0));
306             outButton.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACSD_Out_BTN"));
307             outButton.setText("");
308         toolBar.add(outButton);
309         toolbarButtons.add(outButton);
310         toolBar.addSeparator(new Dimension JavaDoc(2,2));
311             JButton JavaDoc inButton = new JButton JavaDoc(SystemAction.get(ZoomInAction.class));
312             inButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomIn"));
313             inButton.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_In_BTN_Mnem").charAt(0));
314             inButton.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACSD_In_BTN"));
315             inButton.setText("");
316         toolBar.add(inButton);
317         toolbarButtons.add(inButton);
318         toolBar.addSeparator(new Dimension JavaDoc(11,2));
319         
320         JButton JavaDoc button;
321         
322         toolBar.add(button = getZoomButton(1,1));
323         toolbarButtons.add(button);
324         toolBar.addSeparator(new Dimension JavaDoc(11,2));
325         toolBar.add(button = getZoomButton(1,3));
326         toolbarButtons.add(button);
327         toolBar.addSeparator(new Dimension JavaDoc(2,2));
328         toolBar.add(button = getZoomButton(1,5));
329         toolbarButtons.add(button);
330         toolBar.addSeparator(new Dimension JavaDoc(2,2));
331         toolBar.add(button = getZoomButton(1,7));
332         toolbarButtons.add(button);
333         toolBar.addSeparator(new Dimension JavaDoc(11,2));
334         toolBar.add(button = getZoomButton(3,1));
335         toolbarButtons.add(button);
336         toolBar.addSeparator(new Dimension JavaDoc(2,2));
337         toolBar.add(button = getZoomButton(5,1));
338         toolbarButtons.add(button);
339         toolBar.addSeparator(new Dimension JavaDoc(2,2));
340         toolBar.add(button = getZoomButton(7,1));
341         toolbarButtons.add(button);
342         toolBar.addSeparator(new Dimension JavaDoc(11,2));
343 // SystemAction sa = SystemAction.get(CustomZoomAction.class);
344
// sa.putValue (Action.SHORT_DESCRIPTION, NbBundle.getBundle(ImageViewer.class).getString("LBL_CustomZoom"));
345
toolBar.add (button = getZoomButton ());
346         toolbarButtons.add(button);
347         toolBar.addSeparator(new Dimension JavaDoc(11,2));
348         toolBar.add(button = getGridButton());
349         toolbarButtons.add(button);
350         
351         return toolBar;
352     }
353     
354     /** Updates the name and tooltip of this top component according to associated data object. */
355     private void updateName () {
356         // update name
357
String JavaDoc name = storedObject.getNodeDelegate().getDisplayName();
358         setName(name);
359         // update tooltip
360
FileObject fo = storedObject.getPrimaryFile();
361         setToolTipText(FileUtil.getFileDisplayName(fo));
362     }
363
364     /** Docks the table into the workspace if top component is valid.
365      * (Top component may become invalid after deserialization)
366      */

367     public void open(Workspace workspace){
368         if (discard()) return;
369
370         Workspace realWorkspace = (workspace == null)
371                                   ? WindowManager.getDefault().getCurrentWorkspace()
372                                   : workspace;
373         dockIfNeeded(realWorkspace);
374         boolean modeVisible = false;
375         TopComponent[] tcArray = editorMode(realWorkspace).getTopComponents();
376         for (int i = 0; i < tcArray.length; i++) {
377             if (tcArray[i].isOpened(realWorkspace)) {
378                 modeVisible = true;
379                 break;
380             }
381         }
382         if (!modeVisible) {
383             openOtherEditors(realWorkspace);
384         }
385         super.open(workspace);
386         openOnOtherWorkspaces(realWorkspace);
387     }
388     
389     /**
390      */

391     protected String JavaDoc preferredID() {
392         return getClass().getName();
393     }
394
395     private void superOpen(Workspace workspace) {
396         super.open(workspace);
397     }
398
399
400     /** Utility method, opens this top component on all workspaces
401      * where editor mode is visible and which differs from given
402      * workspace. */

403     private void openOnOtherWorkspaces(Workspace workspace) {
404         Workspace[] workspaces = WindowManager.getDefault().getWorkspaces();
405         Mode curEditorMode = null;
406         Mode tcMode = null;
407         for (int i = 0; i < workspaces.length; i++) {
408             // skip given workspace
409
if (workspaces[i].equals(workspace)) {
410                 continue;
411             }
412             curEditorMode = workspaces[i].findMode(CloneableEditorSupport.EDITOR_MODE);
413             tcMode = workspaces[i].findMode(this);
414             if (
415                 !isOpened(workspaces[i]) &&
416                 curEditorMode != null &&
417                 (
418                     tcMode == null ||
419                     tcMode.equals(curEditorMode)
420                 )
421             ) {
422                 // candidate for opening, but mode must be already visible
423
// (= some opened top component in it)
424
TopComponent[] tcArray = curEditorMode.getTopComponents();
425                 for (int j = 0; j < tcArray.length; j++) {
426                     if (tcArray[j].isOpened(workspaces[i])) {
427                         // yep, open this top component on found workspace too
428
pureOpen(this, workspaces[i]);
429                         break;
430                     }
431                 }
432             }
433         }
434     }
435
436     /** Utility method, opens top components which are opened
437      * in editor mode on some other workspace.
438      * This method should be called only if first top component is
439      * being opened in editor mode on given workspace */

440     private void openOtherEditors(Workspace workspace) {
441         // choose candidates for opening
442
Set JavaDoc topComps = new HashSet JavaDoc(15);
443         Workspace[] wsArray = WindowManager.getDefault().getWorkspaces();
444         Mode curEditorMode = null;
445         TopComponent[] tcArray = null;
446         for (int i = 0; i < wsArray.length; i++) {
447             curEditorMode = wsArray[i].findMode(CloneableEditorSupport.EDITOR_MODE);
448             if (curEditorMode != null) {
449                 tcArray = curEditorMode.getTopComponents();
450                 for (int j = 0; j < tcArray.length; j++) {
451                     if (tcArray[j].isOpened(wsArray[i])) {
452                         topComps.add(tcArray[j]);
453                     }
454                 }
455             }
456         }
457         // open choosed candidates
458
for (Iterator JavaDoc iter = topComps.iterator(); iter.hasNext(); ) {
459             pureOpen((TopComponent)iter.next(), workspace);
460         }
461     }
462         
463     /** Utility method, calls super version of open if given
464      * top component is of Editor type, or calls regular open otherwise.
465      * The goal is to prevent from cycle open call between
466      * Editor top components */

467     private void pureOpen(TopComponent tc,Workspace workspace) {
468         if (tc instanceof ImageViewer) {
469             ((ImageViewer)tc).dockIfNeeded(workspace);
470             ((ImageViewer)tc).superOpen(workspace);
471         } else {
472             tc.open(workspace);
473         }
474     }
475
476     /** Dock this top component to editor mode if it is not docked
477      * in some mode at this time */

478     private void dockIfNeeded(Workspace workspace) {
479         // dock into editor mode if possible
480
Mode ourMode = workspace.findMode(this);
481         if (ourMode == null) {
482             editorMode(workspace).dockInto(this);
483         }
484     }
485
486     private Mode editorMode(Workspace workspace) {
487         Mode ourMode = workspace.findMode(this);
488         if (ourMode == null) {
489             ourMode = workspace.createMode(
490                           CloneableEditorSupport.EDITOR_MODE, getName(),
491                           CloneableEditorSupport.class.getResource(
492                               "/org/openide/resources/editorMode.gif" // NOI18N
493
)
494                       );
495         }
496         return ourMode;
497     }
498     
499     /** Gets HelpContext. */
500     public HelpCtx getHelpCtx () {
501         return HelpCtx.DEFAULT_HELP;
502     }
503         
504     /** This component should be discarded if the associated environment
505      * is not valid.
506      */

507     private boolean discard () {
508         return storedObject == null;
509     }
510     
511     /** Serialize this top component. Serializes its data object in addition
512      * to common superclass behaviour.
513      * @param out the stream to serialize to
514      */

515     public void writeExternal (ObjectOutput JavaDoc out)
516     throws IOException JavaDoc {
517         super.writeExternal(out);
518         out.writeObject(storedObject);
519     }
520     
521     /** Deserialize this top component.
522      * Reads its data object and initializes itself in addition
523      * to common superclass behaviour.
524      * @param in the stream to deserialize from
525      */

526     public void readExternal (ObjectInput JavaDoc in)
527     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
528         super.readExternal(in);
529         storedObject = (ImageDataObject)in.readObject();
530         // to reset the listener for FileObject changes
531
((ImageOpenSupport)storedObject.getCookie(ImageOpenSupport.class)).prepareViewer();
532         initialize(storedObject);
533     }
534     
535     /** Creates cloned object which uses the same underlying data object. */
536     protected CloneableTopComponent createClonedObject () {
537         return new ImageViewer(storedObject);
538     }
539     
540     /** Overrides superclass method. Gets actions for this top component. */
541     public SystemAction[] getSystemActions() {
542         SystemAction[] oldValue = super.getSystemActions();
543         return SystemAction.linkActions(new SystemAction[] {
544             SystemAction.get(ZoomInAction.class),
545             SystemAction.get(ZoomOutAction.class),
546             SystemAction.get(CustomZoomAction.class),
547             null},
548             oldValue);
549     }
550     
551     /** Overrides superclass method. Gets <code>Icon</code>. */
552     public Image JavaDoc getIcon () {
553         return Utilities.loadImage("org/netbeans/modules/image/imageObject.png"); // NOI18N
554
}
555     
556     /** Draws zoom in scaled image. */
557     public void zoomIn() {
558         scaleIn();
559         resizePanel();
560         panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
561     }
562     
563     /** Draws zoom out scaled image. */
564     public void zoomOut() {
565         double oldScale = scale;
566         
567         scaleOut();
568         
569          // You can't still make picture smaller, but bigger why not?
570
if(!isNewSizeOK()) {
571             scale = oldScale;
572             
573             return;
574         }
575         
576         resizePanel();
577         panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
578     }
579     
580     /** Resizes panel. */
581     private void resizePanel() {
582         panel.setPreferredSize(new Dimension JavaDoc(
583             (int)(getScale () * storedImage.getIconWidth ()),
584             (int)(getScale () * storedImage.getIconHeight()))
585         );
586         panel.revalidate();
587     }
588     
589     /** Tests new size of image. If image is smaller than minimum
590      * size(1x1) zooming will be not performed.
591      */

592     private boolean isNewSizeOK() {
593         if (((getScale () * storedImage.getIconWidth ()) > 1) &&
594             ((getScale () * storedImage.getIconWidth ()) > 1)
595         ) return true;
596         return false;
597     }
598     
599     /** Perform zoom with specific proportion.
600      * @param fx numerator for scaled
601      * @param fy denominator for scaled
602      */

603     public void customZoom(int fx, int fy) {
604         double oldScale = scale;
605         
606         scale = (double)fx/(double)fy;
607         if(!isNewSizeOK()) {
608             scale = oldScale;
609             
610             return;
611         }
612         
613         resizePanel();
614         panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
615     }
616     
617     /** Return zooming factor.*/
618     private double getScale () {
619         return scale;
620     }
621     
622     /** Change proportion "out"*/
623     private void scaleOut() {
624         scale = scale / changeFactor;
625     }
626     
627     /** Change proportion "in"*/
628     private void scaleIn() {
629         double oldComputedScale = getScale ();
630         
631         scale = changeFactor * scale;
632         
633         double newComputedScale = getScale();
634         
635         if (newComputedScale == oldComputedScale)
636             // Has to increase.
637
scale = newComputedScale + 1.0D;
638     }
639     
640     /** Gets zoom button. */
641     private JButton JavaDoc getZoomButton(final int xf, final int yf) {
642         // PENDING buttons should have their own icons.
643
JButton JavaDoc button = new JButton JavaDoc(""+xf+":"+yf); // NOI18N
644
if (xf < yf)
645             button.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomOut") + " " + xf + " : " + yf);
646         else
647             button.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomIn") + " " + xf + " : " + yf);
648         button.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_Zoom_BTN"));
649         button.addActionListener(new ActionListener JavaDoc() {
650             public void actionPerformed(ActionEvent JavaDoc evt) {
651                 customZoom(xf, yf);
652             }
653         });
654         
655         return button;
656     }
657     
658     private JButton JavaDoc getZoomButton() {
659         // PENDING buttons should have their own icons.
660
JButton JavaDoc button = new JButton JavaDoc(NbBundle.getBundle(CustomZoomAction.class).getString("LBL_XtoY")); // NOI18N
661
button.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_CustomZoom"));
662         button.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_Zoom_BTN"));
663         button.addActionListener(new ActionListener JavaDoc() {
664             public void actionPerformed(ActionEvent JavaDoc evt) {
665                 CustomZoomAction sa = (CustomZoomAction) SystemAction.get(CustomZoomAction.class);
666                 sa.performAction ();
667             }
668         });
669         
670         return button;
671     }
672     
673     /** Gets grid button.*/
674     private JButton JavaDoc getGridButton() {
675         // PENDING buttons should have their own icons.
676
final JButton JavaDoc button = new JButton JavaDoc(" # "); // NOI18N
677
button.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ShowHideGrid"));
678         button.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_Grid_BTN"));
679         button.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Grid_BTN_Mnem").charAt(0));
680         button.addActionListener(new ActionListener JavaDoc() {
681             public void actionPerformed(ActionEvent JavaDoc evt) {
682                 showGrid = !showGrid;
683                 panel.repaint(0, 0, panel.getWidth(), panel.getHeight());
684             }
685         });
686         
687         return button;
688     }
689     
690 }
691
Popular Tags