예제 #1
0
 public PodaPresu4() {
   JFileChooser chooser = new JFileChooser();
   chooser.setFileFilter(new FileNameExtensionFilter("Trabajos XML", "xml"));
   if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
     try {
       SAXBuilder builder = new SAXBuilder();
       Document d = builder.build(chooser.getSelectedFile());
       tx = new TrabajoXml(d);
       jt = new JfTrabajo();
       jt.addWindowListener(
           new WindowAdapter() {
             @Override
             public void windowClosing(WindowEvent e) {
               checkSave();
               super.windowClosing(
                   e); // To change body of generated methods, choose Tools | Templates.
             }
           });
       jt.setTrabajo(tx.readTrabajo());
       jt.setVisible(true);
     } catch (JDOMException | IOException ex) {
       Logger.getLogger(PodaPresu4.class.getName()).log(Level.SEVERE, null, ex);
     }
   }
 }
예제 #2
0
 private void checkSave() {
   if (jt.getTrabajo().isDirty()) {
     int result =
         JOptionPane.showConfirmDialog(
             null,
             "Desea guardar los cambios?",
             "Guardar los cambios?",
             JOptionPane.YES_NO_OPTION);
     if (result == JOptionPane.YES_OPTION) {
       try {
         XMLOutputter xmlo = new XMLOutputter(Format.getPrettyFormat());
         URI uri = new URI(tx.getDocument().getBaseURI());
         File file = new File(uri);
         tx.writeTrabajo(jt.getTrabajo());
         xmlo.output(tx.getDocument(), new FileWriter(file));
       } catch (URISyntaxException | IOException ex) {
         Logger.getLogger(PodaPresu4.class.getName()).log(Level.SEVERE, null, ex);
       }
     }
   }
 }