MainFrame.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package gui.frames;
  2. import gui.menubar.MenuBar;
  3. import gui.panels.agenda.AgendaPane;
  4. import gui.panels.edit.EditPane;
  5. import gui.panels.table.Table;
  6. import gui.simulator.SimulatorPane;
  7. import java.awt.BorderLayout;
  8. import java.awt.Color;
  9. import java.awt.Window;
  10. import java.lang.reflect.InvocationTargetException;
  11. import java.lang.reflect.Method;
  12. import javax.swing.JFrame;
  13. import javax.swing.JPanel;
  14. import agenda.Agenda;
  15. @SuppressWarnings("serial")
  16. public class MainFrame extends JFrame{
  17. public enum Views{EDITOR, SIMULATOR, AGENDA, TABLE};
  18. private Agenda agenda;
  19. private JPanel currentPanel, simulatorpanel;
  20. private int length;
  21. private int terainwidth;
  22. private SimulatorPane.Terrains terrain;
  23. public MainFrame(){
  24. this.agenda = new Agenda();
  25. this.currentPanel = new EditPane(this.agenda);
  26. this.add(currentPanel);
  27. this.setResizable(true);
  28. this.setBounds(100,100,1440,900);
  29. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  30. this.setUndecorated(false);
  31. this.setJMenuBar(new MenuBar(this));
  32. this.setVisible(true);
  33. this.length = 100000;
  34. this.terainwidth = 10000;
  35. this.terrain = SimulatorPane.Terrains.UNDEFINED;
  36. this.getContentPane().setBackground( Color.WHITE );
  37. if(System.getProperties().getProperty("os.name").equals("Mac OS X")) {
  38. try {
  39. Class c = Class.forName("com.apple.eawt.FullScreenUtilities");
  40. Method m = c.getMethod("setWindowCanFullScreen", Window.class, Boolean.TYPE);
  41. m.invoke(c, this, true);
  42. } catch (ClassNotFoundException e) {
  43. e.printStackTrace();
  44. } catch (NoSuchMethodException e) {
  45. e.printStackTrace();
  46. } catch (InvocationTargetException e) {
  47. e.printStackTrace();
  48. } catch (IllegalAccessException e) {
  49. e.printStackTrace();
  50. }
  51. }
  52. }
  53. public void changeView(Views view){
  54. switch(view){
  55. case EDITOR:
  56. this.updateView(new EditPane(this.agenda));
  57. break;
  58. case AGENDA:
  59. this.updateView(new AgendaPane(this.agenda));
  60. break;
  61. case SIMULATOR:
  62. if(simulatorpanel == null){
  63. simulatorpanel = new SimulatorPane(this.agenda, this.length, this.terainwidth, this.terrain);
  64. this.updateView(simulatorpanel);
  65. }else{
  66. this.updateView(simulatorpanel);
  67. }
  68. break;
  69. case TABLE:
  70. this.updateView(new Table(this.agenda));
  71. break;
  72. }
  73. }
  74. public void setTerrain(SimulatorPane.Terrains terrain){
  75. this.terrain = terrain;
  76. }
  77. public void setLength(int length){
  78. this.length = length;
  79. }
  80. public void setTerainWidth(int width){
  81. this.terainwidth = width;
  82. }
  83. public int getTerainWidth(){
  84. return terainwidth;
  85. }
  86. public int getLength(){
  87. return length;
  88. }
  89. public SimulatorPane.Terrains getTerrain(){
  90. return terrain;
  91. }
  92. private void updateView(JPanel panel){
  93. this.currentPanel = panel;
  94. this.setContentPane(this.currentPanel);
  95. this.revalidate();
  96. }
  97. public Agenda getAgenda() {
  98. return agenda;
  99. }
  100. public void setAgenda(Agenda agenda) {
  101. this.agenda = agenda;
  102. updateView(currentPanel);
  103. }
  104. public JPanel getSimulatorpanel() {
  105. return simulatorpanel;
  106. }
  107. public void setSimulatorpanel(JPanel simulatorpanel) {
  108. this.simulatorpanel = simulatorpanel;
  109. }
  110. }