1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.net.URL ; 23 import java.awt.event.ActionListener ; 24 import java.awt.event.ActionEvent ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 import javax.swing.JButton ; 28 import javax.swing.JOptionPane ; 29 30 import org.openide.util.NbBundle; 31 import org.openide.DialogDescriptor; 32 import org.openide.DialogDisplayer; 33 import org.openide.awt.HtmlBrowser; 34 35 39 class Notification extends Object { 40 41 42 private static boolean accepted = false; 43 44 45 private static java.awt.Dialog dialog = null; 46 47 48 private Notification() { 49 } 50 51 55 56 static boolean performNotification( Updates updates, AutoupdateType at ) { 57 58 final String text = updates.getNotificationText(); 59 final URL url = updates.getNotificationURL(); 60 61 if ( text == null ) { 62 return false; 63 } 64 65 Settings settings = Settings.getShared (); 67 if (settings.getAcceptedNotifications () == null) { 68 settings.setAcceptedNotifications (new HashMap ()); 69 } 70 Map mapNotifications = settings.getAcceptedNotifications (); 71 Integer lastNotificationId = (Integer )mapNotifications.get (new Integer (at.getName ().hashCode ())); 72 if (lastNotificationId != null && lastNotificationId.intValue () == text.hashCode ()) { 73 return false; 75 } else { 76 mapNotifications.put (new Integer (at.getName ().hashCode ()), new Integer (text.hashCode ())); 77 settings.setAcceptedNotifications (mapNotifications); 78 } 79 80 final JButton closeButton = new JButton ( 81 getBundle("CTL_Notification_Close") 82 ); 83 closeButton.getAccessibleContext ().setAccessibleName (getBundle("ACS_Notification_Close")); 84 final JButton urlButton = new JButton ( 85 getBundle("CTL_Notification_URL") 86 ); 87 urlButton.getAccessibleContext ().setAccessibleName (getBundle("ACS_Notification_URL")); 88 89 JOptionPane pane = new JOptionPane ( 90 text, 91 JOptionPane.INFORMATION_MESSAGE, 92 JOptionPane.DEFAULT_OPTION 93 ); 94 95 pane.setOptions (new Object [] {}); 96 pane.getAccessibleContext ().setAccessibleName (getBundle( "ACS_Notification_Title" )); 97 98 DialogDescriptor dd = new DialogDescriptor ( 99 pane, 100 getBundle( "CTL_Notification_Title" ), 101 true, 102 DialogDescriptor.DEFAULT_OPTION, 103 DialogDescriptor.OK_OPTION, 104 new ActionListener () { 105 public void actionPerformed (ActionEvent ev) { 106 111 if (ev.getSource () == urlButton ) { 112 if ( url != null ) { 114 javax.swing.SwingUtilities.invokeLater( new Runnable () { 115 public void run() { 116 HtmlBrowser.URLDisplayer.getDefault ().showURL( url ); 117 } 118 } ); 119 } 120 } 121 } 122 } 123 ); 124 125 dd.setOptions( url != null ? new Object [] {closeButton, urlButton} : 126 new Object [] {closeButton} ); 127 dd.setClosingOptions( null ); 128 dialog = DialogDisplayer.getDefault().createDialog( dd ); 129 dialog.setVisible(true); 130 return true; 131 } 132 133 static boolean performModuleNotification( String text ) { 134 135 if ( text == null ) { 136 return false; 137 } 138 139 final JButton cancelButton = new JButton ( 140 getBundle("CTL_Notification_Cancel") 141 ); 142 cancelButton.getAccessibleContext ().setAccessibleName (getBundle("ACS_Notification_Cancel")); 143 144 final JButton okButton = new JButton ( 145 getBundle("CTL_Notification_OK") 146 ); 147 okButton.getAccessibleContext ().setAccessibleName (getBundle("ACS_Notification_OK")); 148 149 JOptionPane pane = new JOptionPane ( 150 text, 151 JOptionPane.INFORMATION_MESSAGE, 152 JOptionPane.DEFAULT_OPTION 153 ); 154 pane.getAccessibleContext ().setAccessibleName (getBundle( "ACS_Notification_Title" )); 155 156 pane.setOptions (new Object [] {}); 157 158 DialogDescriptor dd = new DialogDescriptor ( 159 pane, 160 getBundle( "CTL_Notification_Title" ), 161 true, 162 DialogDescriptor.DEFAULT_OPTION, 163 DialogDescriptor.OK_OPTION, 164 new ActionListener () { 165 public void actionPerformed (ActionEvent ev) { 166 if ( ev.getSource() == okButton ) 167 accepted = true; 168 else 169 accepted = false; 170 171 dialog.setVisible( false ); 172 } 173 } 174 ); 175 176 dd.setOptions( new Object [] {okButton, cancelButton} ); 177 dd.setClosingOptions( null ); 178 dialog = DialogDisplayer.getDefault().createDialog( dd ); 179 accepted = false; 180 dialog.setVisible(true); 181 182 return accepted; 183 } 184 185 private static String getBundle( String key ) { 186 return NbBundle.getMessage( Notification.class, key ); 187 } 188 } 189 | Popular Tags |