예제 #1
0
  private void initializeComponents() {
    backButton = new JButton(lang.translationForKey(GUIConstants.BUTTON_BACK));
    backButton.setActionCommand(GUIConstants.BUTTON_BACK);
    backButton.setVisible(false);

    nextButton = new JButton(lang.translationForKey(GUIConstants.BUTTON_NEXT));
    nextButton.setActionCommand(GUIConstants.BUTTON_NEXT);
    // if there is only one step set next button to finished
    if (numSteps == 1) {
      nextButton.setText(lang.translationForKey(GUIConstants.BUTTON_FINISH));
    }

    cancelButton = new JButton(lang.translationForKey(GUIConstants.BUTTON_CANCEL));
    cancelButton.setActionCommand(GUIConstants.BUTTON_CANCEL);
  }
예제 #2
0
  /**
   * Updates the buttons according to the position of the user consent.
   *
   * @param nextIdx Index of the step that is to be displayed.
   */
  public void selectIdx(int nextIdx) {
    // Don't show the back button on the first step
    if (nextIdx == 0) {
      backButton.setVisible(false);
    } else {
      backButton.setVisible(true);
    }

    // Change the forward button on the last step to "finished"
    if (nextIdx == (numSteps - 1)) {
      nextButton.setText(lang.translationForKey(GUIConstants.BUTTON_FINISH));
    } else {
      nextButton.setText(lang.translationForKey(GUIConstants.BUTTON_NEXT));
    }
  }
예제 #3
0
  public void setup() {
    GUIDefaults.initialize();

    MessageDialog dialog = new MessageDialog();
    dialog.setHeadline(lang.translationForKey("client.startup.failed.headline"));

    try {
      tray = new AppTray(this);
      tray.beginSetup();

      // Set up client environment
      env = new ClientEnv();

      // Set up Management
      TinyManagement management = new TinyManagement(env);
      env.setManagement(management);

      // Set up the IFD
      ifd = new IFD();
      ifd.addProtocol(ECardConstants.Protocol.PACE, new PACEProtocolFactory());
      env.setIFD(ifd);

      // Set up the Dispatcher
      MessageDispatcher dispatcher = new MessageDispatcher(env);
      env.setDispatcher(dispatcher);
      ifd.setDispatcher(dispatcher);

      // Perform an EstablishContext to get a ContextHandle
      EstablishContext establishContext = new EstablishContext();
      EstablishContextResponse establishContextResponse = ifd.establishContext(establishContext);
      WSHelper.checkResult(establishContextResponse);
      contextHandle = ifd.establishContext(establishContext).getContextHandle();

      // Set up CardRecognition
      recognition = new CardRecognition(ifd, contextHandle);

      // Set up EventManager
      em = new EventManager(recognition, env, contextHandle);
      env.setEventManager(em);

      // Set up SALStateCallback
      cardStates = new CardStateMap();
      SALStateCallback salCallback = new SALStateCallback(recognition, cardStates);
      em.registerAllEvents(salCallback);

      // Set up SAL
      sal = new TinySAL(env, cardStates);
      env.setSAL(sal);

      // Set up GUI
      SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
      sal.setGUI(gui);
      ifd.setGUI(gui);
      recognition.setGUI(gui);

      // Start up control interface
      try {
        binding = new HTTPBinding(HTTPBinding.DEFAULT_PORT);
        manager = new AddonManager(dispatcher, gui, cardStates, recognition, em);
        sal.setAddonManager(manager);
        binding.setAddonManager(manager);
        binding.start();
      } catch (BindException e) {
        dialog.setMessage(lang.translationForKey("client.startup.failed.portinuse"));
        throw e;
      }

      tray.endSetup(recognition, manager);

      // Initialize the EventManager
      em.registerAllEvents(tray.status());
      em.initialize();

    } catch (Exception e) {
      _logger.error(e.getMessage(), e);

      if (dialog.getMessage() == null || dialog.getMessage().isEmpty()) {
        // Add exception message if no custom message is set
        dialog.setMessage(e.getMessage());
      }

      // Show dialog to the user and shut down the client
      JOptionPane.showMessageDialog(null, dialog, "Open eCard App", JOptionPane.PLAIN_MESSAGE);
      teardown();
    }
  }
예제 #4
0
/**
 * @author Moritz Horsch <*****@*****.**>
 * @author Johannes Schmölz <*****@*****.**>
 */
public final class RichClient {

  private static final Logger _logger = LoggerFactory.getLogger(RichClient.class.getName());
  private static final I18n lang = I18n.getTranslation("richclient");

  // Tray icon
  private AppTray tray;
  // Control interface
  private HTTPBinding binding;
  // Client environment
  private ClientEnv env = new ClientEnv();
  // Interface Device Layer (IFD)
  private IFD ifd;
  // Service Access Layer (SAL)
  private TinySAL sal;
  // AddonManager
  private AddonManager manager;
  // Event manager
  private EventManager em;
  // Card recognition
  private CardRecognition recognition;
  // card states
  private CardStateMap cardStates;
  // ContextHandle determines a specific IFD layer context
  private byte[] contextHandle;

  static {
    try {
      // load logger config from HOME if set
      LogbackConfig.load();
    } catch (IOException ex) {
      _logger.error("Failed to load logback config from user config.", ex);
    } catch (JoranException ex) {
      _logger.error("Failed to load logback config from user config.", ex);
    }
  }

  public static void main(String[] args) {
    RichClient client = new RichClient();
    client.setup();
  }

  public void setup() {
    GUIDefaults.initialize();

    MessageDialog dialog = new MessageDialog();
    dialog.setHeadline(lang.translationForKey("client.startup.failed.headline"));

    try {
      tray = new AppTray(this);
      tray.beginSetup();

      // Set up client environment
      env = new ClientEnv();

      // Set up Management
      TinyManagement management = new TinyManagement(env);
      env.setManagement(management);

      // Set up the IFD
      ifd = new IFD();
      ifd.addProtocol(ECardConstants.Protocol.PACE, new PACEProtocolFactory());
      env.setIFD(ifd);

      // Set up the Dispatcher
      MessageDispatcher dispatcher = new MessageDispatcher(env);
      env.setDispatcher(dispatcher);
      ifd.setDispatcher(dispatcher);

      // Perform an EstablishContext to get a ContextHandle
      EstablishContext establishContext = new EstablishContext();
      EstablishContextResponse establishContextResponse = ifd.establishContext(establishContext);
      WSHelper.checkResult(establishContextResponse);
      contextHandle = ifd.establishContext(establishContext).getContextHandle();

      // Set up CardRecognition
      recognition = new CardRecognition(ifd, contextHandle);

      // Set up EventManager
      em = new EventManager(recognition, env, contextHandle);
      env.setEventManager(em);

      // Set up SALStateCallback
      cardStates = new CardStateMap();
      SALStateCallback salCallback = new SALStateCallback(recognition, cardStates);
      em.registerAllEvents(salCallback);

      // Set up SAL
      sal = new TinySAL(env, cardStates);
      env.setSAL(sal);

      // Set up GUI
      SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
      sal.setGUI(gui);
      ifd.setGUI(gui);
      recognition.setGUI(gui);

      // Start up control interface
      try {
        binding = new HTTPBinding(HTTPBinding.DEFAULT_PORT);
        manager = new AddonManager(dispatcher, gui, cardStates, recognition, em);
        sal.setAddonManager(manager);
        binding.setAddonManager(manager);
        binding.start();
      } catch (BindException e) {
        dialog.setMessage(lang.translationForKey("client.startup.failed.portinuse"));
        throw e;
      }

      tray.endSetup(recognition, manager);

      // Initialize the EventManager
      em.registerAllEvents(tray.status());
      em.initialize();

    } catch (Exception e) {
      _logger.error(e.getMessage(), e);

      if (dialog.getMessage() == null || dialog.getMessage().isEmpty()) {
        // Add exception message if no custom message is set
        dialog.setMessage(e.getMessage());
      }

      // Show dialog to the user and shut down the client
      JOptionPane.showMessageDialog(null, dialog, "Open eCard App", JOptionPane.PLAIN_MESSAGE);
      teardown();
    }
  }

  public void teardown() {
    try {
      // TODO shutdown addon manager and related components?

      // shutdown control modules
      binding.stop();

      // shutdwon event manager
      em.terminate();

      // shutdown SAL
      Terminate terminate = new Terminate();
      sal.terminate(terminate);

      // shutdown IFD
      ReleaseContext releaseContext = new ReleaseContext();
      releaseContext.setContextHandle(contextHandle);
      ifd.releaseContext(releaseContext);
    } catch (Exception ex) {
      _logger.error("Failed to stop Richclient.", ex);
    }

    System.exit(0);
  }
}
예제 #5
0
/**
 * Component of the Swing GUI with navigation buttons. Depending on whether the first, the last or
 * an intermediate step is displayed, the visible buttons are:
 *
 * <ul>
 *   <li>Back
 *   <li>Next
 *   <li>Finish
 *   <li>Cancel
 * </ul>
 *
 * @author Tobias Wich <*****@*****.**>
 * @author Moritz Horsch <*****@*****.**>
 */
public class NavigationBar extends JPanel {

  private static final Logger logger = LoggerFactory.getLogger(NavigationBar.class);
  private static final long serialVersionUID = 1L;

  private final I18n lang = I18n.getTranslation("gui");
  private JButton backButton;
  private JButton nextButton;
  private JButton cancelButton;

  private int numSteps;

  /**
   * Create and initialize the navigation panel for the given number of steps. The step number is
   * important, because the panel needs to know when it is finished.
   *
   * @param numSteps Number of steps in this user consent.
   */
  public NavigationBar(int numSteps) {
    this.numSteps = numSteps;
    initializeComponents();
    initializeLayout();
  }

  /**
   * Register the provided listener for all navigation (button) events.
   *
   * @param eventSink Listener for button events.
   */
  public void registerEvents(ActionListener eventSink) {
    backButton.addActionListener(eventSink);
    nextButton.addActionListener(eventSink);
    cancelButton.addActionListener(eventSink);
  }

  private void initializeComponents() {
    backButton = new JButton(lang.translationForKey(GUIConstants.BUTTON_BACK));
    backButton.setActionCommand(GUIConstants.BUTTON_BACK);
    backButton.setVisible(false);

    nextButton = new JButton(lang.translationForKey(GUIConstants.BUTTON_NEXT));
    nextButton.setActionCommand(GUIConstants.BUTTON_NEXT);
    // if there is only one step set next button to finished
    if (numSteps == 1) {
      nextButton.setText(lang.translationForKey(GUIConstants.BUTTON_FINISH));
    }

    cancelButton = new JButton(lang.translationForKey(GUIConstants.BUTTON_CANCEL));
    cancelButton.setActionCommand(GUIConstants.BUTTON_CANCEL);
  }

  private void initializeLayout() {
    GroupLayout layout = new GroupLayout(this);
    setLayout(layout);

    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(false);

    GroupLayout.SequentialGroup hg = layout.createSequentialGroup();
    hg.addComponent(backButton, 60, 60, 150);
    hg.addComponent(nextButton, 60, 60, 150);
    hg.addComponent(cancelButton, 60, 60, 150);
    layout.setHorizontalGroup(hg);

    GroupLayout.ParallelGroup vg = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
    vg.addComponent(backButton);
    vg.addComponent(nextButton);
    vg.addComponent(cancelButton);
    layout.setVerticalGroup(vg);
  }

  /** Locks buttons except the cancel button. */
  public void lockControls() {
    // lock buttons
    backButton.setEnabled(false);
    nextButton.setEnabled(false);
  }
  /** Unlocks all buttons. */
  public void unlockControls() {
    // unlock buttons
    backButton.setEnabled(true);
    nextButton.setEnabled(true);
  }

  /**
   * Updates the buttons according to the position of the user consent.
   *
   * @param nextIdx Index of the step that is to be displayed.
   */
  public void selectIdx(int nextIdx) {
    // Don't show the back button on the first step
    if (nextIdx == 0) {
      backButton.setVisible(false);
    } else {
      backButton.setVisible(true);
    }

    // Change the forward button on the last step to "finished"
    if (nextIdx == (numSteps - 1)) {
      nextButton.setText(lang.translationForKey(GUIConstants.BUTTON_FINISH));
    } else {
      nextButton.setText(lang.translationForKey(GUIConstants.BUTTON_NEXT));
    }
  }

  @Override
  public boolean hasFocus() {
    return backButton.hasFocus() || nextButton.hasFocus() || cancelButton.hasFocus();
  }
}