package mixconfig.panels.smartcard; import groovy.swing.SwingBuilder; import net.miginfocom.swing.MigLayout; import mixconfig.tools.dataretention.smartcard.ISmartCard; import mixconfig.tools.dataretention.smartcard.ConnectionManager; import mixconfig.tools.dataretention.smartcard.commands.ErrorCodeException; import javax.swing.JOptionPane; import anon.util.JAPMessages; class SmartCardManagementConsole { private SwingBuilder swingBuilder; private static SmartCardManagementConsole instance; private SmartCardManagementConsole() { swingBuilder = new SwingBuilder(); } public static SmartCardManagementConsole getInstance() { if (instance == null) { instance = new SmartCardManagementConsole(); } return instance; } public static void show() { SmartCardManagementConsole instance = getInstance(); instance.display(); } public void display() { def frame = swingBuilder.frame(title: getLabel('title'), size:[300,300], pack: true, visible: true) { panel(layout: new MigLayout("fill", "grow", "top")) { button(text: getLabel('cardInitializationWizard'), actionPerformed: { cardInitializationWizard() } ) button(text: getLabel('changeCardSettings'), actionPerformed: { changeCardSettings() } ) button(text: getLabel('getSoftwareVersion'), constraints: "wrap", actionPerformed: { getVersion() } ) button(text: getLabel('viewLog'), actionPerformed: { viewLog() }) button(text: 'Initialize card with test data', actionPerformed: {testData()}) } } } private String getLabel(String label) { return JAPMessages.getString(SmartCardManagementConsole.class.getName() + '_' + label); } private void testData() { InstallationWizardFormModel model = new InstallationWizardFormModel() def admin1 = new Administrator(); admin1.name = "myname" admin1.password = "123456" model.administrators << admin1 def operator1 = new Operator(); operator1.name = "op1" operator1.password = "1234" model.operators << operator1 model.neededNumberOfAdministrators = 1 model.saveToCard() } private void changeCardSettings() { def installationWizard = new SmartCardSettingsPanel(); installationWizard.show() } private void cardInitializationWizard() { ISmartCard smartCard = ConnectionManager.getInstance().connect(); if (smartCard.isInitialized()) { JOptionPane.showMessageDialog(null, "The card is already initialized. Please use Change Card Settings.", "Error", JOptionPane.ERROR_MESSAGE) } else { def installationWizard = new SmartCardInitializationPanel(); installationWizard.show(); } } private void getVersion() { try { ISmartCard smartCard = SmartCardHelper.getISmartCardWithErrorHandling() JOptionPane.showMessageDialog(null, "The software running on the smart card is version " + smartCard.getVersion() + "."); } catch(Exception e) { // Errors are already displayed, thus we don't need to do anything. } } private void viewLog() { ISmartCard smartCard = ConnectionManager.getInstance().connect(); def frame = swingBuilder.frame(title:'Log', size: [300,300], pack: true, visible: true) { panel(layout: new MigLayout("fill", "grow", "top")) { table(constraints: "grow") { tableModel(list: smartCard.getLog()) { closureColumn(header: 'String', read: {logEntry -> logEntry.message}) } } } } } // For debugging purposes public static void main(String[] args) { if (!JAPMessages.init("MixConfigMessages")) { System.out.println("MixConfigMessages not found"); } SmartCardManagementConsole.show() } }