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
The TrueLicense Swing module provides a graphical user interface for
consuming license keys.
/*
* Copyright (C) 2005-2015 Schlichtherle IT Services.
* All rights reserved. Use is subject to license terms.
*/
package net.java.truelicense.swing;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import net.java.truelicense.core.LicenseConsumerManager;
import net.java.truelicense.core.util.Message;
import net.java.truelicense.swing.util.ComponentEnabler;
import net.java.truelicense.swing.util.Enabler;
import static net.java.truelicense.ui.LicenseWizardMessage.uninstall_failure;
import static net.java.truelicense.ui.LicenseWizardMessage.uninstall_prompt;
import static net.java.truelicense.ui.LicenseWizardMessage.uninstall_success;
import static net.java.truelicense.ui.LicenseWizardMessage.uninstall_uninstall;
import net.java.truelicense.ui.LicenseWizardState;
/**
* @author Christian Schlichtherle
*/
final class UninstallPanel extends LicenseWorkerPanel {
private static final long serialVersionUID = 1L;
private final LicenseConsumerManager manager;
UninstallPanel(final LicenseWizard wizard) {
super(wizard);
final Enabler uninstallButtonProxy = new ComponentEnabler() {
static final long serialVersionUID = 0L;
@Override protected JButton component() { return uninstallButton; }
};
this.manager = new EnablingLicenseConsumerManager(wizard.nextButtonProxy(),
new DisablingLicenseConsumerManager(uninstallButtonProxy,
wizard.manager()));
initComponents();
}
@Override LicenseConsumerManager manager() { return manager; }
@Override public LicenseWizardState nextState() {
return LicenseWizardState.uninstall;
}
@Override public void onAfterStateSwitch() {
assert SwingUtilities.isEventDispatchThread();
assert isVisible();
wizard().disableNextButton();
setStatusMessage(EMPTY_MESSAGE);
final boolean installed = licenseInstalled();
uninstallButton.setEnabled(installed);
if (installed) uninstallButton.requestFocusInWindow();
}
@Override void setStatusMessage(Message message) {
status.setText(message.toString());
}
@Override Message successMessage() {
return uninstall_success.format(subject());
}
@Override Message failureMessage(Throwable throwable) {
return uninstall_failure.format(subject());
}
/** 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;
javax.swing.JTextArea prompt = new javax.swing.JTextArea();
uninstallButton = new net.java.truelicense.swing.util.EnhancedButton();
status = new javax.swing.JTextArea();
setName(UninstallPanel.class.getSimpleName());
setLayout(new java.awt.GridBagLayout());
prompt.setEditable(false);
prompt.setFont(getFont());
prompt.setLineWrap(true);
prompt.setText(format(uninstall_prompt)); // NOI18N
prompt.setWrapStyleWord(true);
prompt.setBorder(null);
prompt.setName(uninstall_prompt.name());
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;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 15, 0);
add(prompt, gridBagConstraints);
uninstallButton.setText(format(uninstall_uninstall)); // NOI18N
uninstallButton.setName(uninstall_uninstall.name());
uninstallButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
uninstallActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
add(uninstallButton, gridBagConstraints);
status.setEditable(false);
status.setFont(getFont());
status.setBorder(null);
status.setName("status"); // NOI18N
status.setOpaque(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(15, 0, 0, 0);
add(status, gridBagConstraints);
}// //GEN-END:initComponents
private void uninstallActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uninstallActionPerformed
new LicenseWorker() {
@Override protected Void doInBackground() throws Exception {
manager().uninstall();
return null;
}
}.execute();
}//GEN-LAST:event_uninstallActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea status;
private net.java.truelicense.swing.util.EnhancedButton uninstallButton;
// End of variables declaration//GEN-END:variables
}