
net.java.truelicense.swing.UninstallPanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truelicense-swing Show documentation
Show all versions of truelicense-swing Show documentation
Provides a Swing wizard to manage license keys in consumer applications.
/*
* Copyright (C) 2005-2013 Schlichtherle IT Services.
* All rights reserved. Use is subject to license terms.
*/
package net.java.truelicense.swing;
import java.security.GeneralSecurityException;
import javax.swing.JPanel;
import net.java.truelicense.core.LicenseValidationException;
import net.java.truelicense.core.util.Objects;
import static net.java.truelicense.swing.Messages.*;
import net.java.truelicense.swing.nexes.WizardPanelDescriptor;
/**
* @author Christian Schlichtherle
*/
public class UninstallPanel extends JPanel {
private static final long serialVersionUID = 1L;
private final ObservableLicenseConsumerManager ocm;
public UninstallPanel(final ObservableLicenseConsumerManager ocm) {
this.ocm = Objects.requireNonNull(ocm);
initComponents();
}
/** 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.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
prompt = new javax.swing.JTextArea();
uninstallButton = new net.java.truelicense.swing.util.EnhancedButton();
setLayout(new java.awt.GridBagLayout());
prompt.setEditable(false);
prompt.setLineWrap(true);
prompt.setText(message("UninstallPanel.prompt.text").toString()); // NOI18N
prompt.setWrapStyleWord(true);
prompt.setBorder(null);
prompt.setOpaque(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.ipady = 5;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
gridBagConstraints.weightx = 1.0;
add(prompt, gridBagConstraints);
uninstallButton.setText(message("UninstallPanel.uninstallButton.text").toString()); // NOI18N
uninstallButton.setName("uninstall"); // NOI18N
uninstallButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
uninstallButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
add(uninstallButton, gridBagConstraints);
}// //GEN-END:initComponents
private void uninstallButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uninstallButtonActionPerformed
try {
ocm.uninstall();
uninstallButton.setEnabled(false);
} catch (final GeneralSecurityException failure) {
assert !(failure instanceof LicenseValidationException);
Dialogs.showMessageDialog(
this,
failure instanceof LicenseValidationException
? failure.getLocalizedMessage()
: message("UninstallPanel.failure.message").toString(), // don't show details!
message("UninstallPanel.failure.title").toString(),
Dialogs.ERROR_MESSAGE);
}
}//GEN-LAST:event_uninstallButtonActionPerformed
/**
* Adds the given license consumer manager listener.
* It is safe to call this method from a listener implementation.
* The implementation uses a list, so adding the same listener multiple
* times will result in multiple notifications for each event.
*
* @param cml the license consumer manager listener to add.
*/
public void addLicenseConsumerManagerListener(
LicenseConsumerManagerListener cml) {
ocm.addLicenseConsumerManagerListener(cml);
}
/**
* Removes the given license consumer manager listener.
* It is safe to call this method from a listener implementation.
* Removing an listener which is not registered has no effect.
*
* @param cml the license consumer manager listener to remove.
*/
public void removeLicenseConsumerManagerListener(
LicenseConsumerManagerListener cml) {
ocm.removeLicenseConsumerManagerListener(cml);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea prompt;
private net.java.truelicense.swing.util.EnhancedButton uninstallButton;
// End of variables declaration//GEN-END:variables
public static class Descriptor extends WizardPanelDescriptor {
public static final String IDENTIFIER = "UNINSTALL_PANEL"; // NOI18N
public Descriptor(ObservableLicenseConsumerManager ocm) {
this(new UninstallPanel(ocm));
}
private Descriptor(final UninstallPanel panel) {
super(IDENTIFIER, panel);
panel.addLicenseConsumerManagerListener(new BasicLicenseConsumerManagerListener() {
@Override public void uninstalled(LicenseConsumerManagerEvent cme) {
getWizardModel().setNextButtonEnabled(Boolean.TRUE);
}
});
}
@Override public UninstallPanel getPanel() {
return (UninstallPanel) super.getPanel();
}
@Override
public String getBackPanelIdentifier() {
return WelcomePanel.Descriptor.IDENTIFIER;
}
@Override
public String getNextPanelIdentifier() { return FINISH; }
@Override
@SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
public void aboutToDisplayPanel() {
getPanel().uninstallButton.setEnabled(true);
getWizardModel().setNextButtonEnabled(Boolean.FALSE);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy