[Frubar Paste] Hosted by SkyLime - Chat with us at XChannel IRC

Posted by appelhenka on Wed 1st Jul 12:36
download

  1. package view2;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Dimension;
  5. import java.awt.ScrollPane;
  6. import java.awt.Scrollbar;
  7. import java.awt.Toolkit;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.WindowEvent;
  11. import java.awt.event.WindowListener;
  12. import java.io.File;
  13. import java.util.Date;
  14. import java.util.LinkedList;
  15.  
  16. import javax.swing.*;
  17. import javax.swing.event.TreeSelectionEvent;
  18. import javax.swing.event.TreeSelectionListener;
  19. import javax.swing.tree.TreePath;
  20.  
  21. import model.Instruction;
  22. import model.Ship;
  23.  
  24. import control.Controller;
  25.  
  26. public class ChannelGUI extends JFrame implements ActionListener, WindowListener {
  27.        
  28.         private static final long serialVersionUID = 1L;
  29.         private String filename;
  30.         private Controller controller;
  31.        
  32.         public ChannelGUI(String filename)
  33.         {  
  34.                 super("Nord-Ostsee-Kanal");
  35.         addWindowListener(this);
  36.                
  37.                 this.filename = filename;
  38.                 this.controller = new Controller(filename);
  39.         int endTime =0;
  40.                 final int algoStart = controller.getShips().get(0).getStartTime();
  41.                 for (Ship ship : controller.getShips()) {
  42.                         LinkedList<Instruction> timetable = ship.getTimetable();
  43.                         for (int i = 0; i < timetable.size(); i++) {
  44.                                 Instruction curr = timetable.get(i);
  45.                                 long begInSec = (curr.getInterval().getStart() - algoStart) /1000;
  46.                                 // first y value = time after algo started in pixel. 30 seconds per 1 pixel
  47.                                 int yStart = (int) begInSec / 30;      
  48.                                 int durationInSec = (int) (curr.getInterval().getLength()/1000);
  49.                                 // second y value
  50.                                 int yEnd = yStart + (int) durationInSec / 30;
  51.                                 if(yEnd>endTime){
  52.                                         endTime = yEnd;
  53.                                 }
  54.                         }
  55.                 }
  56.        
  57.         setSize(Toolkit.getDefaultToolkit().getScreenSize());
  58.         getContentPane().setLayout(new BorderLayout());
  59.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  60.                    
  61.         //Links
  62.         ChannelTree shipTree = new ChannelTree(this.controller);
  63.         shipTree.addTreeSelectionListener(new ShipTreeListener(this.controller));
  64.         JScrollPane TreePane = new JScrollPane(shipTree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  65.         getContentPane().add(TreePane, BorderLayout.WEST);
  66.        
  67.                 //Mitte
  68.         GuiDiagram gd = new GuiDiagram(this.controller);
  69.         gd.setSize(940, endTime + 80);
  70.         Dimension d = new Dimension(940, endTime);
  71.         gd.setMinimumSize(d);
  72.         JScrollPane scrollPane = new JScrollPane(gd,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  73.         getContentPane().add(scrollPane, BorderLayout.CENTER);
  74.        
  75.         //Unten
  76. //        View2D gd2 = new View2D(this.controller);
  77. //        ScrollPane bottomPane = new ScrollPane();
  78. //        bottomPane.add(gd2);
  79. //        bottomPane.setSize(940, 100);
  80. //        getContentPane().add(bottomPane, BorderLayout.SOUTH);
  81.        
  82.         //Menu
  83.         ChannelMenu channelBar = new ChannelMenu(this);
  84.         setJMenuBar(channelBar);
  85.         setVisible(true);
  86.         }
  87.        
  88.         public ChannelGUI()
  89.         {  
  90.                 super("Nord-Ostsee-Kanal");
  91.         addWindowListener(this);
  92.                
  93.         setSize(Toolkit.getDefaultToolkit().getScreenSize());
  94.         getContentPane().setLayout(new BorderLayout());
  95.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  96.                    
  97.         //Links
  98.         ChannelTree shipTree = new ChannelTree();
  99.         shipTree.addTreeSelectionListener(new TreeSelectionListener()
  100.         {
  101.                 @Override public void valueChanged( TreeSelectionEvent e )
  102.             {
  103.               TreePath path = e.getNewLeadSelectionPath();
  104.               System.out.println(e);
  105.               System.out.println(path.toString());
  106.             }
  107.         });
  108.         JScrollPane TreePane = new JScrollPane(shipTree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  109.         getContentPane().add(TreePane, BorderLayout.WEST);
  110.        
  111.                 //Mitte
  112.         GuiDiagram gd = new GuiDiagram();
  113.         gd.setSize(940, 1080);
  114.         Dimension d = new Dimension(940, 2080);
  115.         gd.setMinimumSize(d);
  116.         JScrollPane scrollPane = new JScrollPane(gd,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  117.         scrollPane.setMinimumSize(d);
  118.         getContentPane().add(scrollPane, BorderLayout.CENTER);
  119.        
  120.         //Unten
  121.         View2D gd2 = new View2D(this.controller);
  122.         ScrollPane bottomPane = new ScrollPane();
  123.         bottomPane.add(gd2);
  124.         bottomPane.setSize(940, 100);
  125.         getContentPane().add(bottomPane, BorderLayout.SOUTH);
  126.        
  127.         //Menu
  128.         ChannelMenu channelBar = new ChannelMenu(this);
  129.         setJMenuBar(channelBar);
  130.         setVisible(true);
  131.         }
  132.        
  133.         public void actionPerformed(ActionEvent event) {
  134.                 String cmd = event.getActionCommand();
  135.         if(cmd == "parse")
  136.         {
  137.             JFileChooser fc = new JFileChooser("Import");
  138.             int state = fc.showOpenDialog( null );
  139.             if ( state == JFileChooser.APPROVE_OPTION )
  140.             {
  141.                 File file = fc.getSelectedFile();
  142.                 System.out.println(file.getPath());
  143. //                this.controller = new Controller(file.getPath());
  144.             }
  145.             else
  146.             {
  147.                 System.out.println("cancel");
  148.                 repaint();
  149.             }
  150.         }
  151.         else if(cmd == "quit")
  152.         {
  153.             System.exit(0);
  154.         }
  155.         else
  156.         {
  157.                 System.out.println(cmd);
  158.             throw new UnsupportedOperationException("Not supported yet.");
  159.         }
  160.         repaint();
  161.         }
  162.        
  163.         /**
  164.          * @param args
  165.          */
  166.         public static void main(String[] args) {
  167.                 if(args.length > 0)
  168.                         new ChannelGUI(args[0]);
  169.                 else
  170.                         new ChannelGUI();
  171.         }
  172.  
  173.         public void windowActivated(WindowEvent e) {
  174.                 repaint();
  175.         }
  176.  
  177.         public void windowClosed(WindowEvent e) {
  178.                 // TODO Auto-generated method stub
  179.                
  180.         }
  181.  
  182.         public void windowClosing(WindowEvent e) {
  183.                 // TODO Auto-generated method stub
  184.                
  185.         }
  186.  
  187.         public void windowDeactivated(WindowEvent e) {
  188.                 // TODO Auto-generated method stub
  189.                
  190.         }
  191.  
  192.         public void windowDeiconified(WindowEvent e) {
  193.                 repaint();
  194.         }
  195.  
  196.         public void windowIconified(WindowEvent e) {
  197.                 // TODO Auto-generated method stub
  198.                
  199.         }
  200.  
  201.         public void windowOpened(WindowEvent e) {
  202.                 // TODO Auto-generated method stub
  203.                
  204.         }
  205.  
  206. }


Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.



Remember my name in a cookie


Code: To highlight particular lines, prefix each line with @@.
Include comments to indicate what you need feedback on.