
org.pepsoft.worldpainter.DonationDialog Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* DonationDialog.java
*
* Created on 5-nov-2011, 17:24:59
*/
package org.pepsoft.worldpainter;
import org.pepsoft.util.DesktopUtils;
import org.pepsoft.worldpainter.vo.EventVO;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
/**
*
* @author pepijn
*/
public final class DonationDialog extends WorldPainterDialog {
/** Creates new form DonationDialog */
public DonationDialog(Window parent) {
super(parent);
initComponents();
// Fix JTextArea font, which uses a butt ugly non-proportional font by
// default on Windows
jTextArea1.setFont(UIManager.getFont("TextField.font"));
try {
URL buttonURL = new URL("https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif");
try (InputStream in = buttonURL.openStream()) {
BufferedImage buttonImage = ImageIO.read(in);
// buttonImage is null if the image format is not supported:
if (buttonImage != null) {
jButton1.setIcon(new ImageIcon(buttonImage));
jButton1.setText(null);
jButton1.setBorder(new EmptyBorder(0, 0, 0, 0));
jButton1.setContentAreaFilled(false);
}
}
} catch (IOException e) {
// Do nothing
}
rootPane.setDefaultButton(jButton1);
pack();
}
public static void maybeShowDonationDialog(Window parent) {
Configuration config = Configuration.getInstance();
if ((config.getLaunchCount() >= 5) && (config.getDonationStatus() == null)) {
DonationDialog dialog = new DonationDialog(parent);
dialog.setLocationRelativeTo(parent);
dialog.setVisible(true);
if (dialog.isCancelled()) {
config.logEvent(new EventVO(Constants.EVENT_KEY_DONATION_CLOSED).addTimestamp());
}
}
}
private void donate() {
try {
DesktopUtils.open(new URL("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VZ7WNQVPXDZHY"));
Configuration.getInstance().setDonationStatus(Configuration.DonationStatus.DONATED);
JOptionPane.showMessageDialog(this, "The donation PayPal page has been opened in your browser.\n\nThank you very much for donating!", "Thank You", JOptionPane.INFORMATION_MESSAGE);
Configuration.getInstance().logEvent(new EventVO(Constants.EVENT_KEY_DONATION_DONATE).addTimestamp());
ok();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
private void alreadyDonated() {
Configuration.getInstance().setDonationStatus(Configuration.DonationStatus.DONATED);
JOptionPane.showMessageDialog(this, "Thank you very much for donating!", "Thank You", JOptionPane.INFORMATION_MESSAGE);
Configuration.getInstance().logEvent(new EventVO(Constants.EVENT_KEY_DONATION_ALREADY_DONATED).addTimestamp());
ok();
}
private void askLater() {
Configuration.getInstance().logEvent(new EventVO(Constants.EVENT_KEY_DONATION_ASK_LATER).addTimestamp());
ok();
}
private void noThanks() {
Configuration.getInstance().setDonationStatus(Configuration.DonationStatus.NO_THANK_YOU);
JOptionPane.showMessageDialog(this, "Alright, no problem. We will not ask you again.\nIf you ever change your mind, you can donate from the About screen!", "No Problem", JOptionPane.INFORMATION_MESSAGE);
Configuration.getInstance().logEvent(new EventVO(Constants.EVENT_KEY_DONATION_NO_THANKS).addTimestamp());
ok();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Please Donate");
setResizable(false);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/pepsoft/worldpainter/resources/banner.png"))); // NOI18N
jLabel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setText("Thank you for using WorldPainter!\n\nWorldPainter takes a lot of effort to create and maintain. You are free to keep using it without paying, but please consider helping out with a small donation of € 4.95.");
jTextArea1.setWrapStyleWord(true);
jTextArea1.setOpaque(false);
jButton1.setMnemonic('d');
jButton1.setText("Donate");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setMnemonic('a');
jButton2.setText("I have already donated");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setMnemonic('l');
jButton3.setText("Ask me later");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setMnemonic('n');
jButton4.setText("No thank you");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton4))
.addComponent(jTextArea1))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jTextArea1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButton4))
.addContainerGap())
);
pack();
}// //GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
donate();
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
alreadyDonated();
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
askLater();
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
noThanks();
}//GEN-LAST:event_jButton4ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration//GEN-END:variables
private static final long serialVersionUID = 1L;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy