Exemplo n.º 1
0
  public void Load() {
    gui.setBtnVisible(true);
    try {
      loadLudoFromFile();
      // lst.getLstFromXml();
    } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    for (CategoryLudotheque p : lst.lst) {
      gui.addDataModel(p.getCategory(), new DataModel(p));
    }
  }
Exemplo n.º 2
0
  /**
   * Create the GUI and show it. For thread safety, this method should be invoked from the event
   * dispatch thread.
   */
  public static void createAndShowGUI() {
    java.io.File file = new java.io.File("marau.properties");
    final java.util.Properties properties = new java.util.Properties();
    try {
      file.createNewFile();
      properties.load(new java.io.FileInputStream(file));
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if (properties.getProperty("XMLFile") == null || properties.getProperty("XMLFile").isEmpty()) {
      properties.setProperty("XMLFile", "test.xml");
    }

    // Create and set up the window.
    JFrame frame = new JFrame("Marau");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // Add contents to the window.
    final GuiMainApp win = new GuiMainApp(properties);
    win.setOpaque(true); // content panes must be opaque
    frame.setContentPane(win);
    // GuiMainApp win = new GuiMainApp();
    // frame.add(win);
    final int defaultWidth = 800;
    final int defaultHeight = 400;
    frame.setSize(defaultWidth, defaultHeight);
    frame.setLocationRelativeTo(null);

    URL imgPath = win.getClass().getClassLoader().getResource("fr/marau/gui/velo2.jpg");
    Image img = Toolkit.getDefaultToolkit().getImage(imgPath);
    frame.setIconImage(img);

    // Display the window.
    frame.setVisible(true);

    MenuBar test = new MenuBar();
    Menu menu1 = new Menu("Fichier");
    MenuItem item1 = new MenuItem("Ouvrir");
    item1.setActionCommand("Open");
    menu1.add(item1);
    item1 = new MenuItem("Load");
    item1.setActionCommand("Load");
    menu1.add(item1);
    item1 = new MenuItem("Save");
    item1.setActionCommand("save");
    menu1.add(item1);
    item1 = new MenuItem("Save As");
    item1.setActionCommand("saveAs");
    menu1.add(item1);
    menu1.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            if (arg0.getActionCommand().equals("save")) {
              new CreateXMLFile(win.getLudo(), properties.getProperty("XMLFile"), properties);
            } else if (arg0.getActionCommand().equals("Open")) {
              final JFileChooser fc = new JFileChooser();
              int returnVal = fc.showOpenDialog(win);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                properties.setProperty("XMLFile", file.getPath());
              }
            } else if (arg0.getActionCommand().equals("saveAs")) {
              final JFileChooser fc = new JFileChooser();
              int returnVal = fc.showOpenDialog(win);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                new CreateXMLFile(win.getLudo(), file.getPath(), properties);
              }
            } else if (arg0.getActionCommand().equals("Load")) {
              win.Load();
            }
          }
        });

    test.add(menu1);
    frame.setMenuBar(test);
  }
Exemplo n.º 3
0
 public void addElement(TypeEl typeEl, ElementLudotheque l) {
   DataModel d = gui.getDataModel(typeEl);
   d.addLine(l);
 }
Exemplo n.º 4
0
 @Override
 public void actionPerformed(ActionEvent arg0) {
   presEl.initCategory(gui.getSelectedCategory());
   presEl.visible();
 }