Esempio n. 1
0
  public Clock() {

    main_panel.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            System.exit(0);
          }
        });

    Timer timer =
        new Timer(
            1000,
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                Calendar curTime = Calendar.getInstance();
                curTime.setTimeInMillis(System.currentTimeMillis());

                hour.setText(setTimeString(curTime.get(Calendar.HOUR_OF_DAY) + ""));
                minutes.setText(setTimeString(curTime.get(Calendar.MINUTE) + ""));
                second.setText(setTimeString(curTime.get(Calendar.SECOND) + ""));
              }
            });
    timer.setInitialDelay(0);
    timer.start();
  }
Esempio n. 2
0
  @Override
  @SuppressWarnings("deprecation")
  public void hide() {
    if (isExperimentalSheet()) {
      OSXSheetSupport.hideSheet(this);
      hide0();
      uninstallSheet();
    } else if (isAnimated() && isShowAsSheet() && !isNativeSheetSupported()) {
      getContentPane().setVisible(false);

      final Rectangle startBounds = getBounds();
      int parentWidth = getParent().getWidth();
      final Rectangle endBounds =
          new Rectangle(
              (parentWidth < startBounds.width)
                  ? startBounds.x + (startBounds.width - parentWidth) / 2
                  : startBounds.x,
              startBounds.y,
              Math.min(startBounds.width, parentWidth),
              0);
      final Timer timer = new Timer(20, null);
      timer.addActionListener(
          new ActionListener() {

            long startTime;
            long endTime;

            public void actionPerformed(ActionEvent evt) {
              long now = System.currentTimeMillis();
              if (startTime == 0) {
                startTime = now;
                endTime = startTime + 200;
              }
              if (now > endTime) {
                timer.stop();
                hide0();
                setBounds(startBounds);
                getContentPane().setVisible(true);
                uninstallSheet();
              } else {
                float ratio = (now - startTime) / (float) (endTime - startTime);
                setBounds(
                    (int) (startBounds.x * (1f - ratio) + endBounds.x * ratio),
                    (int) (startBounds.y * (1f - ratio) + endBounds.y * ratio),
                    (int) (startBounds.width * (1f - ratio) + endBounds.width * ratio),
                    (int) (startBounds.height * (1f - ratio) + endBounds.height * ratio));
              }
            }
          });
      timer.setRepeats(true);
      timer.setInitialDelay(5);
      timer.start();
    } else {
      hide0();
      uninstallSheet();
    }
  }
 /**
  * Sets the parameters controlling the animation
  *
  * @param params
  * @throws IllegalArgumentException if params is null
  */
 private void setAnimationParams(AnimationParams params) {
   if (params == null) {
     throw new IllegalArgumentException("params can't be null");
   }
   if (animateTimer != null) {
     animateTimer.stop();
   }
   animationParams = params;
   animateTimer = new Timer(animationParams.waitTime, animator);
   animateTimer.setInitialDelay(0);
 }
Esempio n. 4
0
  public JLabel DateTimeProperties(JLabel timeLabel) {

    final DateFormat timeFormat = new SimpleDateFormat("hh:mm:ssa MM-dd-yyyy");
    ActionListener timerListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            Date date = new Date();
            String time = timeFormat.format(date);
            timeLabel.setText(time);
          }
        };

    Timer timer = new Timer(1000, timerListener);
    timer.setInitialDelay(0);
    timer.start();

    return timeLabel;
  }
    /** Reacts to the timer's action events. */
    public void actionPerformed(ActionEvent e) {
      if (ADJUSTTIMER) {
        long time = System.currentTimeMillis();

        if (lastCall > 0) { // adjust nextDelay
          // XXX maybe should cache this after a while
          // actual = time - lastCall
          // difference = actual - interval
          // nextDelay = previousDelay - difference
          //          = previousDelay - (time - lastCall - interval)
          int nextDelay = (int) (previousDelay - time + lastCall + getRepaintInterval());
          if (nextDelay < MINIMUM_DELAY) {
            nextDelay = MINIMUM_DELAY;
          }
          timer.setInitialDelay(nextDelay);
          previousDelay = nextDelay;
        }
        timer.start();
        lastCall = time;
      }

      incrementAnimationIndex(); // paint next frame
    }
Esempio n. 6
0
 static {
   caretTimer = new Timer(500, new CaretBlinker());
   caretTimer.setInitialDelay(500);
   caretTimer.start();
 }
  public JMovieControlAqua() {
    // Set the background color to the border color of the buttons.
    // This way the toolbar won't look too ugly when the buttons
    // are displayed before they have been loaded completely.
    // setBackground(new Color(118, 118, 118));
    setBackground(Color.WHITE);

    Dimension buttonSize = new Dimension(16, 16);
    GridBagLayout gridbag = new GridBagLayout();
    Insets margin = new Insets(0, 0, 0, 0);
    setLayout(gridbag);
    GridBagConstraints c;

    ResourceBundle labels = ResourceBundle.getBundle("org.monte.media.Labels");
    colorCyclingButton = new JToggleButton();
    colorCyclingButton.setToolTipText(labels.getString("colorCycling.toolTipText"));
    colorCyclingButton.addActionListener(this);
    colorCyclingButton.setPreferredSize(buttonSize);
    colorCyclingButton.setMinimumSize(buttonSize);
    colorCyclingButton.setVisible(false);
    colorCyclingButton.setMargin(margin);
    c = new GridBagConstraints();
    // c.gridx = 0;
    // c.gridy = 0;
    gridbag.setConstraints(colorCyclingButton, c);
    add(colorCyclingButton);

    audioButton = new JToggleButton();
    audioButton.setToolTipText(labels.getString("audio.toolTipText"));
    audioButton.addActionListener(this);
    audioButton.setPreferredSize(buttonSize);
    audioButton.setMinimumSize(buttonSize);
    audioButton.setVisible(false);
    audioButton.setMargin(margin);
    c = new GridBagConstraints();
    // c.gridx = 0;
    // c.gridy = 0;
    gridbag.setConstraints(audioButton, c);
    add(audioButton);

    startButton = new JToggleButton();
    startButton.setToolTipText(labels.getString("play.toolTipText"));
    startButton.addActionListener(this);
    startButton.setPreferredSize(buttonSize);
    startButton.setMinimumSize(buttonSize);
    startButton.setMargin(margin);
    c = new GridBagConstraints();
    // c.gridx = 1;
    // c.gridy = 0;
    gridbag.setConstraints(startButton, c);
    add(startButton);

    slider = new JMovieSliderAqua();
    c = new GridBagConstraints();
    // c.gridx = 2;
    // c.gridy = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    gridbag.setConstraints(slider, c);
    add(slider);

    rewindButton = new JButton();
    rewindButton.setToolTipText(labels.getString("previous.toolTipText"));
    rewindButton.setPreferredSize(buttonSize);
    rewindButton.setMinimumSize(buttonSize);
    rewindButton.setMargin(margin);
    c = new GridBagConstraints();
    // c.gridx = 3;
    // c.gridy = 0;

    gridbag.setConstraints(rewindButton, c);
    add(rewindButton);
    rewindButton.addActionListener(this);

    forwardButton = new JButton();
    forwardButton.setToolTipText(labels.getString("next.toolTipText"));
    buttonSize = new Dimension(17, 16);
    forwardButton.setPreferredSize(buttonSize);
    forwardButton.setMinimumSize(buttonSize);
    forwardButton.setMargin(margin);
    c = new GridBagConstraints();
    // c.gridx = 4;
    // c.gridy = 0;
    gridbag.setConstraints(forwardButton, c);
    add(forwardButton);
    forwardButton.addActionListener(this);

    // The spacer is used when the play controls are hidden
    spacer = new JPanel(new BorderLayout());
    spacer.setVisible(false);
    spacer.setPreferredSize(new Dimension(16, 16));
    spacer.setMinimumSize(new Dimension(16, 16));
    spacer.setOpaque(false);
    c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    gridbag.setConstraints(spacer, c);
    add(spacer);

    Border border =
        new BackdropBorder(
            new ButtonStateBorder(
                new ImageBevelBorder(
                    Images.createImage(getClass(), "images/Player.border.png"),
                    new Insets(1, 1, 1, 1),
                    new Insets(0, 4, 1, 4)),
                new ImageBevelBorder(
                    Images.createImage(getClass(), "images/Player.borderP.png"),
                    new Insets(1, 1, 1, 1),
                    new Insets(0, 4, 1, 4))));

    Border westBorder =
        new BackdropBorder(
            new ButtonStateBorder(
                new ImageBevelBorder(
                    Images.createImage(getClass(), "images/Player.borderWest.png"),
                    new Insets(1, 1, 1, 0),
                    new Insets(0, 4, 1, 4)),
                new ImageBevelBorder(
                    Images.createImage(getClass(), "images/Player.borderWestP.png"),
                    new Insets(1, 1, 1, 0),
                    new Insets(0, 4, 1, 4))));

    startButton.setBorder(westBorder);
    colorCyclingButton.setBorder(westBorder);
    audioButton.setBorder(westBorder);
    rewindButton.setBorder(westBorder);
    forwardButton.setBorder(border);
    startButton.setUI((ButtonUI) CustomButtonUI.createUI(startButton));
    colorCyclingButton.setUI((ButtonUI) CustomButtonUI.createUI(audioButton));
    audioButton.setUI((ButtonUI) CustomButtonUI.createUI(audioButton));
    rewindButton.setUI((ButtonUI) CustomButtonUI.createUI(rewindButton));
    forwardButton.setUI((ButtonUI) CustomButtonUI.createUI(forwardButton));

    colorCyclingButton.setIcon(
        new ImageIcon(Images.createImage(getClass(), "images/PlayerStartColorCycling.png")));
    colorCyclingButton.setSelectedIcon(
        new ImageIcon(Images.createImage(getClass(), "images/PlayerStartColorCycling.png")));
    colorCyclingButton.setDisabledIcon(
        new ImageIcon(
            Images.createImage(getClass(), "images/PlayerStartColorCycling.disabled.png")));
    audioButton.setIcon(
        new ImageIcon(Images.createImage(getClass(), "images/PlayerStartAudio.png")));
    audioButton.setSelectedIcon(
        new ImageIcon(Images.createImage(getClass(), "images/PlayerStopAudio.png")));
    audioButton.setDisabledIcon(
        new ImageIcon(Images.createImage(getClass(), "images/PlayerStartAudio.disabled.png")));
    startButton.setIcon(new ImageIcon(Images.createImage(getClass(), "images/PlayerStart.png")));
    startButton.setSelectedIcon(
        new ImageIcon(Images.createImage(getClass(), "images/PlayerStop.png")));
    startButton.setDisabledIcon(
        new ImageIcon(Images.createImage(getClass(), "images/PlayerStart.disabled.png")));
    rewindButton.setIcon(new ImageIcon(Images.createImage(getClass(), "images/PlayerBack.png")));
    rewindButton.setDisabledIcon(
        new ImageIcon(Images.createImage(getClass(), "images/PlayerBack.disabled.png")));
    forwardButton.setIcon(new ImageIcon(Images.createImage(getClass(), "images/PlayerNext.png")));
    forwardButton.setDisabledIcon(
        new ImageIcon(Images.createImage(getClass(), "images/PlayerNext.disabled.png")));

    // Automatic scrolling
    scrollHandler = new ScrollHandler();
    scrollTimer = new Timer(60, scrollHandler);
    scrollTimer.setInitialDelay(300); // default InitialDelay?
    forwardButton.addMouseListener(scrollHandler);
    rewindButton.addMouseListener(scrollHandler);
  }
Esempio n. 8
0
  @Override
  @SuppressWarnings("deprecation")
  public void show() {
    if (isExperimentalSheet()) {
      // Install the sheet
      installSheet();
      // Create the native peer - maybe not supported
      addNotify();
      if (OSXSheetSupport.showAsSheet(this)) {
        // Tell lightweight components to be visible
        show0();
        return;
      } else {
        isExperimentalSheet = false;
      }
    }
    if (isAnimated() && isShowAsSheet() && !isNativeSheetSupported()) {
      installSheet();
      getContentPane().setVisible(false);

      final Rectangle endBounds = getBounds();
      int parentWidth = getParent().getWidth();
      final Rectangle startBounds =
          new Rectangle(
              (parentWidth < endBounds.width)
                  ? endBounds.x + (endBounds.width - parentWidth) / 2
                  : endBounds.x,
              endBounds.y,
              Math.min(endBounds.width, parentWidth),
              0);
      setBounds(startBounds);
      if (!isDocumentModalitySupported()) {
        ((Window) getParent()).toFront();
      }
      final Timer timer = new Timer(20, null);
      timer.addActionListener(
          new ActionListener() {

            long startTime;
            long endTime;

            public void actionPerformed(ActionEvent evt) {
              long now = System.currentTimeMillis();
              if (startTime == 0) {
                startTime = now;
                endTime = startTime + 200;
              }
              if (now > endTime) {
                timer.stop();
                setBounds(endBounds);
                getContentPane().setVisible(true);

                Component c = getFocusTraversalPolicy().getInitialComponent(JSheet.this);
                if (c != null) {
                  c.requestFocus();
                } else {
                  getContentPane().requestFocus();
                }
              } else {
                float ratio = (now - startTime) / (float) (endTime - startTime);
                setBounds(
                    (int) (startBounds.x * (1f - ratio) + endBounds.x * ratio),
                    (int) (startBounds.y * (1f - ratio) + endBounds.y * ratio),
                    (int) (startBounds.width * (1f - ratio) + endBounds.width * ratio),
                    (int) (startBounds.height * (1f - ratio) + endBounds.height * ratio));
              }
            }
          });
      timer.setRepeats(true);
      timer.setInitialDelay(5);
      timer.start();
      show0();
    } else {
      installSheet();
      show0();
    }
    OSXApplication.requestUserAttention(true);
  }
Esempio n. 9
0
 private void initTimer() {
   Timer timer;
   timer = new Timer(timeLeft, this);
   timer.setInitialDelay(0);
   timer.start();
 }