View Javadoc
1   /*
2    * Copyright (c) 2022 fbahle.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v2.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v20.html
7    * Contributors:
8    * fbahle - initial API and implementation and/or initial documentation
9    */
10  
11  package de.funfried.netbeans.plugins.external.formatter.ui.options;
12  
13  import java.net.MalformedURLException;
14  import java.net.URL;
15  
16  import javax.swing.Icon;
17  import javax.swing.JDialog;
18  import javax.swing.JLabel;
19  
20  import org.netbeans.api.annotations.common.StaticResource;
21  import org.openide.awt.HtmlBrowser;
22  import org.openide.util.Exceptions;
23  import org.openide.util.ImageUtilities;
24  
25  /**
26   *
27   * @author fbahle
28   */
29  public class ExternalFormatterSupportDialog extends JDialog {
30  	@StaticResource
31  	private static final String DONATE_ICON_PATH = "de/funfried/netbeans/plugins/external/formatter/ui/options/donate.gif";
32  
33  	private static final Icon DONATE_ICON = ImageUtilities.image2Icon(ImageUtilities.loadImage(DONATE_ICON_PATH));
34  
35  	@StaticResource
36  	private static final String BECOME_A_PATRON_ICON_PATH = "de/funfried/netbeans/plugins/external/formatter/ui/options/become_a_patron.png";
37  
38  	private static final Icon BECOME_A_PATRON_ICON = ImageUtilities.image2Icon(ImageUtilities.loadImage(BECOME_A_PATRON_ICON_PATH));
39  
40  	@StaticResource
41  	private static final String BUY_ME_A_DRINK_ICON_PATH = "de/funfried/netbeans/plugins/external/formatter/ui/options/buy_me_a_drink.png";
42  
43  	private static final Icon BUY_ME_A_DRINK_ICON = ImageUtilities.image2Icon(ImageUtilities.loadImage(BUY_ME_A_DRINK_ICON_PATH));
44  
45  	@StaticResource
46  	private static final String SAY_THANKS_ICON_PATH = "de/funfried/netbeans/plugins/external/formatter/ui/options/say_thanks.png";
47  
48  	private static final Icon SAY_THANKS_ICON = ImageUtilities.image2Icon(ImageUtilities.loadImage(SAY_THANKS_ICON_PATH));
49  
50  	/** Creates new form ExternalFormatterSupportDialog */
51  	public ExternalFormatterSupportDialog(java.awt.Frame parent, boolean modal) {
52  		super(parent, modal);
53  
54  		initComponents();
55  
56  		paypalBtn.setText("");
57  		patronBtn.setText("");
58  		buyMeACoffeeBtn.setText("");
59  		sayThanksBtn.setText("");
60  	}
61  
62  	/**
63  	 * This method is called from within the constructor to
64  	 * initialize the form.
65  	 * WARNING: Do NOT modify this code. The content of this method is
66  	 * always regenerated by the Form Editor.
67  	 */
68  	@SuppressWarnings("unchecked")
69      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
70      private void initComponents() {
71  
72          paypalBtn = new JLabel(DONATE_ICON);
73          patronBtn = new JLabel(BECOME_A_PATRON_ICON);
74          buyMeACoffeeBtn = new JLabel(BUY_ME_A_DRINK_ICON);
75          sayThanksBtn = new JLabel(SAY_THANKS_ICON);
76  
77          setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
78          setMinimumSize(new java.awt.Dimension(300, 250));
79  
80          paypalBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
81          org.openide.awt.Mnemonics.setLocalizedText(paypalBtn, org.openide.util.NbBundle.getMessage(ExternalFormatterSupportDialog.class, "ExternalFormatterSupportDialog.paypalBtn.text")); // NOI18N
82          paypalBtn.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
83          paypalBtn.addMouseListener(new java.awt.event.MouseAdapter() {
84              public void mouseClicked(java.awt.event.MouseEvent evt) {
85                  paypalBtnMouseClicked(evt);
86              }
87          });
88  
89          patronBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
90          org.openide.awt.Mnemonics.setLocalizedText(patronBtn, org.openide.util.NbBundle.getMessage(ExternalFormatterSupportDialog.class, "ExternalFormatterSupportDialog.patronBtn.text")); // NOI18N
91          patronBtn.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
92          patronBtn.addMouseListener(new java.awt.event.MouseAdapter() {
93              public void mouseClicked(java.awt.event.MouseEvent evt) {
94                  patronBtnMouseClicked(evt);
95              }
96          });
97  
98          buyMeACoffeeBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
99          org.openide.awt.Mnemonics.setLocalizedText(buyMeACoffeeBtn, org.openide.util.NbBundle.getMessage(ExternalFormatterSupportDialog.class, "ExternalFormatterSupportDialog.buyMeACoffeeBtn.text")); // NOI18N
100         buyMeACoffeeBtn.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
101         buyMeACoffeeBtn.addMouseListener(new java.awt.event.MouseAdapter() {
102             public void mouseClicked(java.awt.event.MouseEvent evt) {
103                 buyMeACoffeeBtnMouseClicked(evt);
104             }
105         });
106 
107         sayThanksBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
108         org.openide.awt.Mnemonics.setLocalizedText(sayThanksBtn, org.openide.util.NbBundle.getMessage(ExternalFormatterSupportDialog.class, "ExternalFormatterSupportDialog.sayThanksBtn.text")); // NOI18N
109         sayThanksBtn.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
110         sayThanksBtn.addMouseListener(new java.awt.event.MouseAdapter() {
111             public void mouseClicked(java.awt.event.MouseEvent evt) {
112                 sayThanksBtnMouseClicked(evt);
113             }
114         });
115 
116         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
117         getContentPane().setLayout(layout);
118         layout.setHorizontalGroup(
119             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
120             .addGroup(layout.createSequentialGroup()
121                 .addContainerGap()
122                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
123                     .addComponent(sayThanksBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
124                     .addComponent(paypalBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
125                     .addComponent(patronBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
126                     .addComponent(buyMeACoffeeBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
127                 .addContainerGap())
128         );
129         layout.setVerticalGroup(
130             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131             .addGroup(layout.createSequentialGroup()
132                 .addContainerGap()
133                 .addComponent(paypalBtn)
134                 .addGap(18, 18, 18)
135                 .addComponent(patronBtn)
136                 .addGap(18, 18, 18)
137                 .addComponent(buyMeACoffeeBtn)
138                 .addGap(18, 18, 18)
139                 .addComponent(sayThanksBtn)
140                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
141         );
142 
143         pack();
144     }// </editor-fold>//GEN-END:initComponents
145 
146     private void paypalBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_paypalBtnMouseClicked
147 		try {
148 			HtmlBrowser.URLDisplayer.getDefault().showURLExternal(new URL("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=926F5XBCTK2LQ&source=url"));
149 		} catch (MalformedURLException ex) {
150 			Exceptions.printStackTrace(ex);
151 		}
152     }//GEN-LAST:event_paypalBtnMouseClicked
153 
154     private void patronBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_patronBtnMouseClicked
155         try {
156 			HtmlBrowser.URLDisplayer.getDefault().showURLExternal(new URL("https://www.patreon.com/funfried"));
157 		} catch (MalformedURLException ex) {
158 			Exceptions.printStackTrace(ex);
159 		}
160     }//GEN-LAST:event_patronBtnMouseClicked
161 
162     private void buyMeACoffeeBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buyMeACoffeeBtnMouseClicked
163         try {
164 			HtmlBrowser.URLDisplayer.getDefault().showURLExternal(new URL("https://www.buymeacoffee.com/funfried"));
165 		} catch (MalformedURLException ex) {
166 			Exceptions.printStackTrace(ex);
167 		}
168     }//GEN-LAST:event_buyMeACoffeeBtnMouseClicked
169 
170     private void sayThanksBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sayThanksBtnMouseClicked
171         try {
172 			HtmlBrowser.URLDisplayer.getDefault().showURLExternal(new URL("https://saythanks.io/to/funfried"));
173 		} catch (MalformedURLException ex) {
174 			Exceptions.printStackTrace(ex);
175 		}
176     }//GEN-LAST:event_sayThanksBtnMouseClicked
177 
178 		/**
179 		 * @param args the command line arguments
180 		 */
181 		public static void main(String args[]) {
182 			/* Set the Nimbus look and feel */
183 			//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
184 			/*
185 			 * If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
186 			 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
187 			 */
188 			try {
189 				for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
190 					if ("Nimbus".equals(info.getName())) {
191 						javax.swing.UIManager.setLookAndFeel(info.getClassName());
192 						break;
193 					}
194 				}
195 			} catch (ClassNotFoundException ex) {
196 				java.util.logging.Logger.getLogger(ExternalFormatterSupportDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
197 			} catch (InstantiationException ex) {
198 				java.util.logging.Logger.getLogger(ExternalFormatterSupportDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
199 			} catch (IllegalAccessException ex) {
200 				java.util.logging.Logger.getLogger(ExternalFormatterSupportDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
201 			} catch (javax.swing.UnsupportedLookAndFeelException ex) {
202 				java.util.logging.Logger.getLogger(ExternalFormatterSupportDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
203 			}
204 			//</editor-fold>
205 
206 			/* Create and display the dialog */
207 			java.awt.EventQueue.invokeLater(new Runnable() {
208 				public void run() {
209 					ExternalFormatterSupportDialog dialog = new ExternalFormatterSupportDialog(new javax.swing.JFrame(), true);
210 					dialog.addWindowListener(new java.awt.event.WindowAdapter() {
211 						@Override
212 						public void windowClosing(java.awt.event.WindowEvent e) {
213 							System.exit(0);
214 						}
215 					});
216 					dialog.setVisible(true);
217 				}
218 			});
219 		}
220 
221     // Variables declaration - do not modify//GEN-BEGIN:variables
222     private javax.swing.JLabel buyMeACoffeeBtn;
223     private javax.swing.JLabel patronBtn;
224     private javax.swing.JLabel paypalBtn;
225     private javax.swing.JLabel sayThanksBtn;
226     // End of variables declaration//GEN-END:variables
227 
228 	}