private void animate() { if (lastAnimationTime > targetTime) { removeTransitions(); animating = false; if (repeatAnimationCheckbox.isSelected()) { addAnimatedTransitions(); } } else { timeController.calculateCurrentTime(); lastAnimationTime = timeController.getCurrentTime(); diagramView.repaint(); // paint it again as time has past } }
private JPanel createControlsPanel() { addStaticTransitionsButton = new JButton("Show all transitions"); addStaticTransitionsButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { addFixedTransitions(); } }); startSteppingButton = new JButton("Start stepping"); startSteppingButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { startStepping(); } }); animateTransitionsButton = new JButton("Animate transitions"); animateTransitionsButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { addAnimatedTransitions(); } }); removeTransitionsButton = new JButton("Remove transitions"); removeTransitionsButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { removeTransitions(); } }); exportImagesButton = new JButton("Export all steps as images"); exportImagesButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { exportImages(); } }); repeatAnimationCheckbox = new JCheckBox("Repeat Animations"); repeatAnimationCheckbox.setSelected(false); final GridBagConstraints buttonConstraints = new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, DEFAULT_BUTTON_INSETS, 0, 0); final JPanel panel = new JPanel(new GridBagLayout()); panel.add(addStaticTransitionsButton, buttonConstraints); panel.add(removeTransitionsButton, buttonConstraints); panel.add(exportImagesButton, buttonConstraints); panel.add(animateTransitionsButton, buttonConstraints); panel.add(startSteppingButton, buttonConstraints); panel.add(repeatAnimationCheckbox, buttonConstraints); panel.add( createStepPanel(), new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, DEFAULT_SPACER_INSETS, 0, 0)); panel.add( new JPanel(), new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE, DEFAULT_SPACER_INSETS, 0, 0)); return panel; }