Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 5th, 2020 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package pcd.ass01.view;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.WindowAdapter;
  7. import java.awt.event.WindowEvent;
  8. import java.io.Serializable;
  9. import java.lang.reflect.InvocationTargetException;
  10. import java.util.ArrayList;
  11. import java.util.Collection;
  12.  
  13. import javax.swing.JButton;
  14. import javax.swing.JFrame;
  15. import javax.swing.JPanel;
  16. import javax.swing.SwingUtilities;
  17.  
  18. import pcd.ass01.controller.ConcurrentSimulator;
  19. import pcd.ass01.model.Body;
  20.  
  21. public class SimulationViewerControllable extends JFrame implements SimulationViewer {
  22.  
  23.     /**
  24.      * A unique serial version identifier
  25.      *
  26.      * @see Serializable#serialVersionUID
  27.      */
  28.     private static final long serialVersionUID = 943153832894696460L;
  29.  
  30.     private JPanel buttonPanel;
  31.     private InfoPanel infoPanel;
  32.     private SimulationPanel visualizerPanel;
  33.     private ConcurrentSimulator simulator;
  34.  
  35.     public SimulationViewerControllable(int w, int h) {
  36.         setTitle("Bodies simulation");
  37.         setResizable(false);
  38.         visualizerPanel = new SimulationPanel(w, h);
  39.         JButton start = new JButton("Start");
  40.         start.addActionListener(new ActionListener() {
  41.  
  42.             @Override
  43.             public void actionPerformed(ActionEvent e) {
  44.                 simulator.handleStart();
  45.             }
  46.            
  47.         });
  48.         JButton stop = new JButton("Stop");
  49.         stop.addActionListener(new ActionListener() {
  50.  
  51.             @Override
  52.             public void actionPerformed(ActionEvent e) {
  53.                 simulator.handleStop();
  54.             }
  55.            
  56.         });
  57.         JButton step = new JButton("Step");
  58.         step.addActionListener(new ActionListener() {
  59.  
  60.             @Override
  61.             public void actionPerformed(ActionEvent e) {
  62.                 simulator.handleStep();
  63.             }
  64.            
  65.         });
  66.         buttonPanel = new JPanel();
  67.         buttonPanel.add(start, BorderLayout.WEST);
  68.         buttonPanel.add(stop, BorderLayout.CENTER);
  69.         buttonPanel.add(step, BorderLayout.EAST);
  70.         infoPanel = new InfoPanel();
  71.         getContentPane().add(buttonPanel, BorderLayout.NORTH);
  72.         getContentPane().add(infoPanel, BorderLayout.AFTER_LAST_LINE);
  73.         getContentPane().add(visualizerPanel, BorderLayout.AFTER_LAST_LINE);
  74.        
  75.         setSize(w, h + 3 * start.getHeight());
  76.         addWindowListener(new WindowAdapter() {
  77.             public void windowClosing(WindowEvent ev) {
  78.                 System.exit(-1);
  79.             }
  80.  
  81.             public void windowClosed(WindowEvent ev) {
  82.                 System.exit(-1);
  83.             }
  84.         });
  85.         setVisible(true);
  86.     }
  87.  
  88.     @Override
  89.     public void display(Collection<Body> bodies, double virtualTime, long iteration) {
  90.  
  91.         try {
  92.             SwingUtilities.invokeAndWait(() -> {
  93.                 visualizerPanel.display(new ArrayList<Body>(bodies));
  94.                 infoPanel.display(bodies.size(), virtualTime, iteration);
  95.             });
  96.         } catch (InvocationTargetException e) {
  97.             e.printStackTrace();
  98.         } catch (InterruptedException e) {
  99.             e.printStackTrace();
  100.         }
  101.  
  102.     }
  103.    
  104.     public void setSimulator(ConcurrentSimulator simulator) {
  105.         this.simulator = simulator;
  106.     }
  107.  
  108. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top