Advertisement
Guest User

Sample Trident Animator

a guest
Mar 15th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. package util;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Dimension;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.util.UUID;
  9. import javax.swing.JButton;
  10. import javax.swing.JFrame;
  11. import javax.swing.JLabel;
  12. import javax.swing.JPanel;
  13. import javax.swing.JScrollPane;
  14. import javax.swing.JTextArea;
  15. import javax.swing.SwingUtilities;
  16. import org.pushingpixels.trident.Timeline;
  17. import org.pushingpixels.trident.ease.Spline;
  18.  
  19. public class ButtonFg extends JFrame {
  20.  
  21.     public ButtonFg() {
  22.         JButton button = new JButton("sample");
  23.         button.setForeground(Color.blue);
  24.  
  25. //        this.setLayout(new FlowLayout());
  26. //        this.add(button);
  27.        
  28.         JPanel panel = new JPanel(new BorderLayout());
  29. //        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
  30.         this.add(panel);
  31.        
  32.         String s = UUID.randomUUID().toString();
  33.         for (int i = 0; i < 20; i++) {
  34.             s += "\n" + UUID.randomUUID().toString();
  35.            
  36.         }
  37.         final JTextArea textArea = new JTextArea(s);
  38.         textArea.setLineWrap(true);
  39.         final JScrollPane jsp = new JScrollPane(textArea);
  40.         jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  41.        
  42.         final JButton label = new JButton("Show details...");
  43.         panel.add(label, BorderLayout.NORTH);
  44.        
  45.         panel.add(jsp, BorderLayout.CENTER);
  46.        
  47.         panel.add(new JLabel("End of panel"), BorderLayout.SOUTH);
  48.        
  49.         final Timeline rolloverTimeline = new Timeline(jsp);
  50.         rolloverTimeline.addPropertyToInterpolate("size", new Dimension(400, 15), new Dimension(400, 200));
  51.         rolloverTimeline.setEase(new Spline(0.8f));
  52.        
  53.         rolloverTimeline.setDuration(300);
  54.         rolloverTimeline.setInitialDelay(50);
  55.        
  56.         label.addActionListener(new ActionListener() {
  57.  
  58.             @Override
  59.             public void actionPerformed(ActionEvent e) {
  60.                 if (label.getText().toLowerCase().contains("show")) {
  61.                     rolloverTimeline.play();
  62.                     label.setText("Hide details...");
  63.                 } else {
  64.                     rolloverTimeline.playReverse();
  65.                     label.setText("Show details...");
  66.                 }
  67.             }
  68.         });
  69.        
  70.         rolloverTimeline.playReverse();
  71.  
  72.  
  73.         this.setSize(400, 500);
  74.         this.setLocationRelativeTo(null);
  75.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  76.     }
  77.  
  78.     public static void main(String[] args) {
  79.         SwingUtilities.invokeLater(new Runnable() {
  80.             @Override
  81.             public void run() {
  82.                 new ButtonFg().setVisible(true);
  83.             }
  84.         });
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement