1 19 20 21 package org.netbeans.modules.image; 22 23 24 import java.awt.Dialog ; 25 import java.awt.event.ActionEvent ; 26 import java.awt.event.ActionListener ; 27 28 import org.openide.DialogDescriptor; 29 import org.openide.NotifyDescriptor; 30 import org.openide.NotifyDescriptor.Message; 31 import org.openide.DialogDisplayer; 32 import org.openide.util.actions.CallableSystemAction; 33 import org.openide.util.HelpCtx; 34 import org.openide.util.NbBundle; 35 import org.openide.windows.TopComponent; 36 37 38 42 public class CustomZoomAction extends CallableSystemAction { 43 44 45 46 static final long serialVersionUID = 8247068408606777895L; 47 48 49 50 public void performAction () { 51 final Dialog [] dialogs = new Dialog [1]; 52 final CustomZoomPanel zoomPanel = new CustomZoomPanel(); 53 54 zoomPanel.setEnlargeFactor(1); 55 zoomPanel.setDecreaseFactor(1); 56 57 DialogDescriptor dd = new DialogDescriptor( 58 zoomPanel, 59 NbBundle.getBundle(CustomZoomAction.class).getString("LBL_CustomZoomAction"), 60 true, 61 DialogDescriptor.OK_CANCEL_OPTION, 62 DialogDescriptor.OK_OPTION, 63 new ActionListener () { 64 public void actionPerformed(ActionEvent ev) { 65 if (ev.getSource() == DialogDescriptor.OK_OPTION) { 66 int enlargeFactor = 1, decreaseFactor = 1; 67 68 try { 69 enlargeFactor = zoomPanel.getEnlargeFactor(); 70 decreaseFactor = zoomPanel.getDecreaseFactor(); 71 } catch (NumberFormatException nfe) { 72 notifyInvalidInput(); 73 return; 74 } 75 76 if(enlargeFactor == 0 || decreaseFactor == 0) { 78 notifyInvalidInput(); 79 return; 80 } 81 82 performZoom(enlargeFactor, decreaseFactor); 83 84 dialogs[0].setVisible(false); 85 dialogs[0].dispose(); 86 } else { 87 dialogs[0].setVisible(false); 88 dialogs[0].dispose(); 89 } 90 } 91 92 private void notifyInvalidInput() { 93 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( 94 NbBundle.getBundle(CustomZoomAction.class).getString("MSG_InvalidValues"), 95 NotifyDescriptor.ERROR_MESSAGE 96 )); 97 } 98 99 } ); 101 dialogs[0] = DialogDisplayer.getDefault().createDialog(dd); 102 dialogs[0].setVisible(true); 103 104 } 105 106 107 private void performZoom(int enlargeFactor, int decreaseFactor) { 108 TopComponent currentComponent = TopComponent.getRegistry().getActivated(); 109 if(currentComponent instanceof ImageViewer) 110 ((ImageViewer)currentComponent).customZoom(enlargeFactor, decreaseFactor); 111 } 112 113 114 public String getName () { 115 return NbBundle.getBundle(CustomZoomAction.class).getString("LBL_CustomZoom"); 116 } 117 118 119 public HelpCtx getHelpCtx () { 120 return new HelpCtx(CustomZoomAction.class); 121 } 122 123 124 protected String iconResource() { 125 return "org/netbeans/modules/image/customZoom.gif"; } 127 128 } 129 | Popular Tags |