Beispiel #1
0
  protected SwingApp() {
    optionsStorage = new MemoryOptionsStorage();
    executor = Executors.newScheduledThreadPool(2);
    reminder = new Reminder(executor);
    messageSource = new ResourceBundleMessageSource("messages");

    workLabel = new JLabel(messageSource.getMessage("label.work"));
    workField = new JTextField(10);
    breakLabel = new JLabel(messageSource.getMessage("label.break"));
    breakField = new JTextField(10);
    messageLabel = new JLabel(messageSource.getMessage("label.message"));
    messageField = new JTextField(20);
    // todoLabel = new JLabel("What to do");
    startAutomaticallyCheckBox =
        new JCheckBox(messageSource.getMessage("label.start.automatically"));
    startButton = new JButton(messageSource.getMessage("label.start"));
    pauseButton = new JButton(messageSource.getMessage("label.pause"));

    statusLabel = new JLabel();
    mainFrame = new JFrame(TITLE);
  }
Beispiel #2
0
 void readOptions(String home) {
   Options options = optionsStorage.load();
   workField.setText(Integer.toString(options.getWorkDuration()));
   breakField.setText(Integer.toString(options.getBreakDuration()));
   startAutomaticallyCheckBox.setSelected(options.isStartAutomatically());
   String message = options.getMessage();
   if (message == null || message.isEmpty()) {
     message = messageSource.getMessage("default.message");
     options.setMessage(message);
   }
   messageField.setText(message);
 }
Beispiel #3
0
 private void startReminder() {
   Runnable command =
       new Runnable() {
         @Override
         public void run() {
           try {
             System.out.println("Time to break!");
             Runtime.getRuntime()
                 .exec(
                     new String[] {
                       "zenity", "--info", "--title=" + TITLE, "--text=" + messageField.getText()
                     });
             System.out.println("Message was shown");
           } catch (IOException e) {
             e.printStackTrace();
           }
         }
       };
   Options options = optionsStorage.load();
   reminder.start(options.getWorkDuration(), command);
   startButton.setEnabled(false);
   pauseButton.setText(messageSource.getMessage("label.pause"));
 }
 @Override
 public void sendMessage(MessageSource message) {
   JOptionPane.showMessageDialog(null, message.getMessage());
 }
Beispiel #5
0
 private void resumeReminder() {
   reminder.resume();
   startButton.setEnabled(false);
   pauseButton.setText(messageSource.getMessage("label.pause"));
 }
Beispiel #6
0
 private void pauseReminder() {
   reminder.pause();
   startButton.setEnabled(true);
   pauseButton.setText(messageSource.getMessage("label.resume"));
 }
Beispiel #7
0
  public void testMessageRegistration() {
    MessageSource source = new MessageSourceSupport(this);
    MessageListener[] ls = source.getMessageListeners();

    assertNotNull(ls);
    assertEquals("Number of listeners not 0", 0, ls.length);

    // test add and remove methods.

    // Add listeners. Ensure that they have been added
    for (int i = 0; i < listeners.length; i++) {
      source.addMessageListener(listeners[i]);
    }

    ls = source.getMessageListeners();
    assertEquals(listeners.length, ls.length);

    // Remove all listenters.
    for (int i = 0; i < listeners.length; i++) {
      source.removeMessageListener(listeners[i]);
    }

    ls = source.getMessageListeners();
    assertEquals(0, ls.length);

    // test to ensure that null adds and removes have no effect.
    for (int i = 0; i < COUNT; i++) {
      source.addMessageListener(null);
      ls = source.getMessageListeners();
      assertEquals(0, ls.length);
    }

    // repopulate the message source.
    for (int i = 0; i < listeners.length; i++) {
      source.addMessageListener(listeners[i]);
    }

    for (int i = 0; i < COUNT; i++) {
      source.removeMessageListener(null);
      ls = source.getMessageListeners();
      assertEquals(listeners.length, ls.length);
    }
  }