Example usage for javax.swing JFileChooser showSaveDialog

List of usage examples for javax.swing JFileChooser showSaveDialog

Introduction

In this page you can find the example usage for javax.swing JFileChooser showSaveDialog.

Prototype

public int showSaveDialog(Component parent) throws HeadlessException 

Source Link

Document

Pops up a "Save File" file chooser dialog.

Usage

From source file:com.mirth.connect.client.ui.Frame.java

/**
 * Creates a File with the default defined file filter type, but does not yet write to it.
 * //from  w  w w.jav  a2  s .  c  om
 * @param defaultFileName
 * @param fileExtension
 * @return
 */
public File createFileForExport(String defaultFileName, String fileExtension) {
    JFileChooser exportFileChooser = new JFileChooser();

    if (defaultFileName != null) {
        exportFileChooser.setSelectedFile(new File(defaultFileName));
    }

    if (fileExtension != null) {
        exportFileChooser.setFileFilter(new MirthFileFilter(fileExtension));
    }

    File currentDir = new File(userPreferences.get("currentDirectory", ""));

    if (currentDir.exists()) {
        exportFileChooser.setCurrentDirectory(currentDir);
    }

    if (exportFileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        userPreferences.put("currentDirectory", exportFileChooser.getCurrentDirectory().getPath());
        File exportFile = exportFileChooser.getSelectedFile();

        if ((exportFile.getName().length() < 4)
                || !FilenameUtils.getExtension(exportFile.getName()).equalsIgnoreCase(fileExtension)) {
            exportFile = new File(exportFile.getAbsolutePath() + "." + fileExtension.toLowerCase());
        }

        if (exportFile.exists()) {
            if (!alertOption(this, "This file already exists.  Would you like to overwrite it?")) {
                return null;
            }
        }

        return exportFile;
    } else {
        return null;
    }
}

From source file:com.pianobakery.complsa.MainGui.java

public void createNewProjectFolder() {

    try {//  w  w w.j a v a2s .co  m
        JFrame frame = new JFrame();
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(openFolder);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        //chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home")));
        chooser.setDialogTitle("Create Folder");
        chooser.setFileHidingEnabled(Boolean.TRUE);
        chooser.setMultiSelectionEnabled(false);
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setDialogType(JFileChooser.SAVE_DIALOG);
        chooser.setSelectedFile(new File("Workingfile"));
        frame.getContentPane().add(chooser);
        chooser.setApproveButtonText("Choose");

        //Disable Save as
        ArrayList<JPanel> jpanels = new ArrayList<JPanel>();
        for (Component c : chooser.getComponents()) {
            if (c instanceof JPanel) {
                jpanels.add((JPanel) c);
            }

        }
        jpanels.get(0).getComponent(0).setVisible(false);
        frame.pack();
        frame.setLocationRelativeTo(null);

        int whatChoose = chooser.showSaveDialog(null);
        if (whatChoose == JFileChooser.APPROVE_OPTION) {
            File selFile = chooser.getSelectedFile();
            File currDir = chooser.getCurrentDirectory();
            Path parentDir = Paths.get(chooser.getCurrentDirectory().getParent());
            String parentDirName = parentDir.getFileName().toString();

            logger.debug("Chooser SelectedFile: " + selFile.toString());
            logger.debug("getCurrentDirectory(): " + currDir.toString());
            logger.debug("Chooser parentdir: " + parentDir);
            logger.debug("Parentdirname: " + parentDirName);

            if (selFile.getName().equals(parentDirName)) {
                wDir = currDir;
            } else {
                wDir = chooser.getSelectedFile();
            }

            logger.debug("WDIR is: " + wDir.toString());
            wDirText.setText(wDir.toString());
            enableUIElements(true);
        }

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Falsche Eingabe");
        logger.debug("Exeption: " + ex.toString());
    }
}

From source file:interfaces.InterfazPrincipal.java

private void TablaDeBuscarFacturaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaDeBuscarFacturaMouseClicked
    int fila = TablaDeBuscarFactura.getSelectedRow();
    int identificacion = (int) TablaDeBuscarFactura.getValueAt(fila, 1);

    Object opciones[] = { "Imprimir", "Guardar", " Eliminar", "Cancelar" };

    int opcion = JOptionPane.showOptionDialog(this,
            "Que operacin desea realizar con la factura  " + identificacion + "?", "Mensaje del sistema",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opciones, null);
    GenerarFactura generarFactura = new GenerarFactura();
    switch (opcion) {
    case 0:/*from   w ww  .j a v a  2s. c o  m*/
        generarFactura.imprimirFactura(identificacion, this);
        break;
    case 1:
        PDDocument documento = generarFactura.crearFactura(identificacion, this);
        JFileChooser fc = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivo PDF", "pdf", "text");
        fc.setFileFilter(filter);
        fc.showSaveDialog(this);
        if (fc.getSelectedFile() != null) {
            File selectedFile = fc.getSelectedFile();
            try {

                documento.save(selectedFile + ".pdf");
                JOptionPane.showMessageDialog(this, "El archivo ha sido guardado en disco");

            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this,
                        "El Archivo no se puede leer!\nInformacin tcnica\n" + ex.toString());
            }
            break;
        }

    case 2:
        int confirmacion = JOptionPane.showConfirmDialog(this,
                "Quieres eliminar la factura " + identificacion + " factura?");

        if (confirmacion == JOptionPane.YES_OPTION) {
            ControladorFactura controladorFactura = new ControladorFactura();
            controladorFactura.deleteFactura(" where factura_id = " + identificacion);
        }
        break;
    case 3:
        break;
    default:
        break;

    }

}

From source file:interfaces.InterfazPrincipal.java

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura();
    ArrayList<String[]> listado = controladorFlujoFactura.getTodosFlujo_Factura("");
    DefaultTableModel modelo = (DefaultTableModel) TablaDeReporteDiario.getModel();

    if (modelo.getRowCount() > 0) {
        for (int k = modelo.getRowCount() - 1; k > -1; k--) {
            modelo.removeRow(k);//ww  w . j a  v a2  s. c  o m
        }
    }
    int contador = 1;
    double abono = 0;
    double deuda = 0;
    for (int i = 0; i < listado.size(); i++) {
        String[] fila = listado.get(i);

        String[] partirEspacios = fila[3].split("\\s");
        //El primer string es la fecha sin hora
        //Ahora esparamos por -
        String[] tomarAgeMesDia = partirEspacios[0].split("-");

        //Realizar filtro
        int ageConsulta = Integer.parseInt(tomarAgeMesDia[0]);
        int mesConsulta = Integer.parseInt(tomarAgeMesDia[1]);
        int diaConsulta = Integer.parseInt(tomarAgeMesDia[2]);
        Calendar fechaDeLaBD = new GregorianCalendar(ageConsulta, mesConsulta, diaConsulta);

        int anioInicial = fechaReporteDiario.getSelectedDate().get(Calendar.YEAR);
        int mesInicial = fechaReporteDiario.getSelectedDate().get(Calendar.MONTH) + 1;
        int diaInicial = fechaReporteDiario.getSelectedDate().get(Calendar.DAY_OF_MONTH);
        Calendar fechaInicialRango = new GregorianCalendar(anioInicial, mesInicial, diaInicial);

        //fechaReporteDiarioHasta
        int anioFinal = fechaReporteDiarioHasta.getSelectedDate().get(Calendar.YEAR);
        int mesFinal = fechaReporteDiarioHasta.getSelectedDate().get(Calendar.MONTH) + 1;
        int diaFinal = fechaReporteDiarioHasta.getSelectedDate().get(Calendar.DAY_OF_MONTH);
        Calendar fechaFinalRango = new GregorianCalendar(anioFinal, mesFinal, diaFinal);

        //System.out.println("antes");
        //System.out.println("Va a comparar" + fechaDeLaBD.toString());
        //System.out.println(" con " + fechaInicialRango.toString());
        if (fechaDeLaBD.compareTo(fechaInicialRango) >= 0 && fechaDeLaBD.compareTo(fechaFinalRango) <= 0) {
            //System.out.println("Entra");
            Object[] row = new Object[5];
            row[0] = (contador);
            contador++;
            row[1] = fila[1];
            row[2] = fila[3];
            row[3] = fila[2];
            row[4] = fila[4];
            modelo.addRow(row);
            //flujo_id","factura_id","tipo_flujo","fecha","valor"
            /*System.out.println("fila 0" + fila[0]);
             System.out.println("fila 1" + fila[1]);
             System.out.println("fila 2" + fila[2]);
             System.out.println("fila 3" + fila[3]);*/
            if (fila[2].equals("abono")) {
                abono += Double.parseDouble(fila[4]);
            } else {
                deuda += Double.parseDouble(fila[4]);
            }
            ;
        }

    }
    ReporteDiarioAbono.setText(abono + "");
    ReporteDiarioDeuda.setText(deuda + "");
    TablaDeReporteDiario.setModel(modelo);
    Object opciones[] = { "Cerrar", "Imprimir", "Guardar en disco" };
    int opcion = JOptionPane.showOptionDialog(this, "Se ha generado el diario solicitado\nQue desea hacer?",
            "Elija una opcin", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opciones,
            null);
    GenerarReporteDiario generarReporteDiario = new GenerarReporteDiario();
    switch (opcion) {
    case 1:
        generarReporteDiario.imprimiDiario(fechaReporteDiario.getSelectedDate(),
                fechaReporteDiarioHasta.getSelectedDate(), modelo, this);
        break;
    case 2:
        PDDocument documento = generarReporteDiario.crearDiario(fechaReporteDiario.getSelectedDate(),
                fechaReporteDiarioHasta.getSelectedDate(), modelo, this);
        JFileChooser fc = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivo PDF", "pdf", "text");
        fc.setFileFilter(filter);
        fc.showSaveDialog(this);
        if (fc.getSelectedFile() != null) {
            File selectedFile = fc.getSelectedFile();
            try {

                documento.save(selectedFile + ".pdf");
                JOptionPane.showMessageDialog(this, "El archivo ha sido guardado en disco");

            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "EL Archivo no se puede leer!");
            }
        }
        break;

    default:
        break;
    }
}

From source file:interfaces.InterfazPrincipal.java

private void botonGuardarFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarFacturaActionPerformed
    // TODO add your handling code here:

    String id_cliente = jTextField_Factura_Cliente_Id.getText();

    if (id_cliente.equals("") || valorActualFactura.equals("0.0")) {
        JOptionPane.showMessageDialog(this,
                "Por favor indique el monto de la factura o ingrese los productos a ella");

    } else {//from  w  w  w  .j  a  v  a  2s  .  c  o m
        //System.err.println("Numero de filas" + TablaDeFacturaProducto.getRowCount());
        ArrayList<String> lineaCodigoProductos = new ArrayList<String>();
        ArrayList<String> lineaUnidadesProductos = new ArrayList<String>();
        ArrayList<String> lineaMontoProductos = new ArrayList<String>();
        double monto = 0d;
        try {
            double pago = Double.parseDouble(
                    (String) JOptionPane.showInputDialog("Ingrese por favor el monto pagado por el cliente"));
            while (pago < 0.0) {
                pago = Double.parseDouble((String) JOptionPane.showInputDialog(
                        "El pago debe ser positivo \nIngrese por favor el monto pagado por el cliente"));

            }

            double prestamo = Double.parseDouble(valorActualPrestamo.getText());
            double montoFactura = Double.parseDouble(valorActualFactura.getText());
            while (montoFactura - pago < 0.0) {
                pago = Double.parseDouble((String) JOptionPane.showInputDialog(
                        "El pago no debe ser superior al monto de la factura \nIngrese por favor el monto pagado por el cliente"));

            }
            if (prestamo - montoFactura <= 0.0) {
                int opcion = JOptionPane.showConfirmDialog(this,
                        "Con este prstamo el cliente excede su limite de prestamos. \n Desea continuar?",
                        "Mensaje del sistema", JOptionPane.YES_NO_OPTION);
                if (opcion != JOptionPane.YES_OPTION) {
                    return;
                }

            }

            for (int i = 0; i < TablaDeFacturaProducto.getRowCount(); i++) {
                /*
                 * Fila 0: ID producto
                 * Fila 4: Cantidad
                 */
                String ProductoId = String.valueOf(TablaDeFacturaProducto.getValueAt(i, 0));
                lineaCodigoProductos.add(ProductoId);

                int numeroUnidades = Integer.parseInt(String.valueOf(TablaDeFacturaProducto.getValueAt(i, 4)));

                String unidades = String.valueOf(numeroUnidades);
                lineaUnidadesProductos.add(unidades);

                double valorUnitario = Double
                        .parseDouble(String.valueOf(TablaDeFacturaProducto.getValueAt(i, 5)));
                double valorProductoTotal = numeroUnidades * valorUnitario;
                lineaMontoProductos.add(String.valueOf(valorProductoTotal));

                monto += valorProductoTotal;
            }

            if (TablaDeFacturaProducto.getRowCount() == 0) {
                monto = Double.parseDouble(valorActualFactura.getText());
            }

            String estado = "";
            if (monto == pago) {
                estado = "pagado";
            } else {
                estado = "fiado";
            }

            ControladorFactura controladorFactura = new ControladorFactura();
            //String[] selection = {"cliente_id", "fecha", "estado", "identificacionCliente"};
            Calendar calendario = Calendar.getInstance();
            String dia = Integer.toString(calendario.get(Calendar.DATE));
            String mes = Integer.toString(calendario.get(Calendar.MONTH)) + 1;
            String annio = Integer.toString(calendario.get(Calendar.YEAR));
            Date date = new Date();
            DateFormat hourFormat = new SimpleDateFormat("HH:mm:ss");
            String hora = hourFormat.format(date);

            String fecha = annio + "-" + mes + "-" + dia + " " + hora;
            String[] selection = { id_cliente, fecha, estado, String.valueOf(monto) };
            ArrayList<String[]> facturaActual = controladorFactura.insertFactura(selection);

            //Ingresar productos
            if (TablaDeFacturaProducto.getRowCount() > 0) {
                ControladorFactura_Productos controladorFactura_Productos = new ControladorFactura_Productos();
                for (int i = 0; i < lineaCodigoProductos.size(); i++) {
                    //        String [] selection = {"factura_id","producto_id","unidades","precio"};
                    String[] insertarLineaProducto = { facturaActual.get(0)[0], lineaCodigoProductos.get(i),
                            lineaUnidadesProductos.get(i), lineaMontoProductos.get(i) };
                    controladorFactura_Productos.insertFactura_Productos(insertarLineaProducto);
                }
            }
            //Ingresar flujo factura
            ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura();
            // String [] selection = {"factura_id","tipo_flujo","fecha","identificacionCliente"};

            String value[] = { facturaActual.get(0)[0], "abono", fecha, String.valueOf(pago) };
            controladorFlujoFactura.insertFlujo_Factura(value);

            String value2[] = { facturaActual.get(0)[0], "deuda", fecha, String.valueOf(monto) };
            controladorFlujoFactura.insertFlujo_Factura(value2);

            botonEstablecerMontoFactura.setEnabled(false);
            botonAgregarProducto.setEnabled(false);
            botonGuardarFactura.setEnabled(false);
            jTextField_Factura_Cliente_Id.setText("");

            DefaultTableModel modeloTabla = (DefaultTableModel) TablaDeFacturaProducto.getModel();

            for (int i = 0; i < modeloTabla.getRowCount(); i++) {
                modeloTabla.removeRow(i);
            }

            modeloTabla.setRowCount(0);
            TablaDeFacturaProducto.setModel(modeloTabla);

            Object opciones[] = { "Cerrar", "Imprimir", "Guardar en disco" };
            GenerarFactura generarFactura = new GenerarFactura();
            int opcion = JOptionPane.showOptionDialog(this,
                    "Se ha guardado la factura con xito\nQue desea hacer?", "Elija una opcin",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opciones, null);

            switch (opcion) {
            case 1:
                generarFactura.imprimirFactura(Integer.parseInt(facturaActual.get(0)[0]), this);
                break;
            case 2:
                PDDocument documento = generarFactura.crearFactura(Integer.parseInt(facturaActual.get(0)[0]),
                        this);
                JFileChooser fc = new JFileChooser();
                FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivo PDF", "pdf", "text");
                fc.setFileFilter(filter);
                fc.showSaveDialog(this);
                if (fc.getSelectedFile() != null) {
                    File selectedFile = fc.getSelectedFile();
                    try {

                        documento.save(selectedFile + ".pdf");
                        JOptionPane.showMessageDialog(this, "El archivo ha sido guardado en disco");

                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(this, "EL Archivo no se puede leer!");
                    }
                }
                break;

            default:
                break;
            }

            nombreClienteCrearFactura.setText("");
            IdentificacionClienteBuscarFactura.setText("");
            valorActualPrestamo.setText("");
            jTextField_Factura_Cliente_Id.setText("");
            jTextField_Factura_Producto_Nombre.setText("");
            jTextField_Factura_Producto_Descripcion.setText("");
            valorMontoFactura.setText("");
            valorActualFactura.setText("0.0");
            valorActualPrestamo.setText("0.0");
            botonGuardarFactura.setEnabled(false);
            botonEstablecerMontoFactura.setEnabled(false);
            botonAgregarProducto.setEnabled(false);
        } catch (Exception e) {
        }

    }

}

From source file:org.nuclos.client.ui.collect.Chart.java

private void actionCommandSave() {
    try {/* w ww .ja v  a 2s . co  m*/
        JFileChooser fileChooser = new JFileChooser();
        FileFilter filter = new FileNameExtensionFilter(
                SpringLocaleDelegate.getInstance().getMessage("filenameextensionfilter.1", "Bildformate")
                        + " (*.svg, *.png, *.jpg, *.jpeg)",
                "svg", "png", "jpg", "jpeg"); // @todo i18n
        fileChooser.addChoosableFileFilter(filter);

        int option = fileChooser.showSaveDialog(this);
        if (option == JFileChooser.APPROVE_OPTION) {
            String filename = fileChooser.getSelectedFile().getPath();
            if (fileChooser.getSelectedFile().getName().lastIndexOf(".") == -1) {
                filename = filename + ".png";
            }

            if (filename.toLowerCase().endsWith(".png"))
                ChartUtilities.saveChartAsPNG(new File(filename), getChartPanel().getChart(),
                        getChartPanel().getWidth(), getChartPanel().getHeight());
            else if (filename.toLowerCase().endsWith(".jpg") || filename.toLowerCase().endsWith(".jpeg"))
                ChartUtilities.saveChartAsJPEG(new File(filename), getChartPanel().getChart(),
                        getChartPanel().getWidth(), getChartPanel().getHeight());
            else if (filename.toLowerCase().endsWith(".svg")) {
                // Get a DOMImplementation and create an XML document
                DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
                Document document = domImpl.createDocument(null, "svg", null);

                // Create an instance of the SVG Generator
                SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

                // draw the chart in the SVG generator
                JFreeChart chart = getChartPanel().getChart();
                chart.draw(svgGenerator, getChartPanel().getBounds());

                // Write svg file
                OutputStream outputStream = new FileOutputStream(filename);
                Writer out = new OutputStreamWriter(outputStream, "UTF-8");
                svgGenerator.stream(out, true /* use css */);
                outputStream.flush();
                outputStream.close();
            }
        }
    } catch (Exception e) {
        throw new NuclosFatalException(e.getMessage());
    }
}

From source file:lu.fisch.unimozer.Diagram.java

public void exportPNG() {
    selectClass(null);//ww  w  . ja v a2s .  c  o m

    JFileChooser dlgSave = new JFileChooser("Export diagram as PNG ...");
    // propose name
    String uniName = directoryName.substring(directoryName.lastIndexOf('/') + 1).trim();
    dlgSave.setSelectedFile(new File(uniName));

    dlgSave.addChoosableFileFilter(new PNGFilter());
    int result = dlgSave.showSaveDialog(frame);
    if (result == JFileChooser.APPROVE_OPTION) {
        String filename = dlgSave.getSelectedFile().getAbsoluteFile().toString();
        if (!filename.substring(filename.length() - 4, filename.length()).toLowerCase().equals(".png")) {
            filename += ".png";
        }

        File file = new File(filename);
        BufferedImage bi = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
        paint(bi.getGraphics());
        try {
            ImageIO.write(bi, "png", file);
        } catch (Exception e) {
            JOptionPane.showOptionDialog(frame, "Error while saving the image!", "Error", JOptionPane.OK_OPTION,
                    JOptionPane.ERROR_MESSAGE, null, null, null);
        }
    }
}

From source file:InternalFrame.InternalFrameproject.java

private void saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveActionPerformed
    String userhome = System.getProperty(constants.getProgrampath()); //userhome is home folder of program

    // ak je zadan pec lokaciakde uklada tak tam ak nide default prie?ion kde existuje
    JFileChooser chooser = new JFileChooser(userhome + "\\" + constants.getProject_input_folder());

    //key files are stored in resources
    FileNameExtensionFilter txtfilter = new FileNameExtensionFilter("emft files (*.Emft)", "Emft"); // whitch type of files are we looking for
    chooser.setDialogTitle(language_internal_frame.LangLabel(constants.getLanguage_option(), 9)); // title for Jfile chooser window
    chooser.setFileFilter(txtfilter); // Txt filter for choosing file
    chooser.showSaveDialog(null);
    File f = chooser.getSelectedFile();
    String project_filename = f.getName() + ".Emft";
    String project_filepath = f.getParent();

    File subor = new File(project_filepath + "\\" + project_filename);

    PrintWriter fw;/*from  ww w .  ja  v a  2  s  .co m*/
    try {
        fw = new PrintWriter(subor);

        fw.println(basicInfoPanel.jTextField_mano.getText());
        fw.println(basicInfoPanel.jTextField_mano_projektu.getText());
        fw.println(basicSettingsPanel.jTextField_A.getText() + " " + basicSettingsPanel.jTextField_Z.getText()
                + " " + basicSettingsPanel.jTextField_H.getText() + " "
                + basicSettingsPanel.jTextField_krok.getText() + " "
                + basicSettingsPanel.jTextField_krok_pozorovatela.getText() + " ");
        fw.println(observerPanel1.Table.getRowCount() - 1);

        for (int i = 0; i < observerPanel1.Table.getRowCount() - 1; i++) {

            fw.println(observerPanel1.DTMTable.getValueAt(i, 0));

        }

        fw.println(catenaryPanel1.Table.getRowCount() - 1);

        for (int i = 0; i < catenaryPanel1.Table.getRowCount() - 1; i++) {

            double V1 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 0));
            double V2 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 1));
            double I1 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 2));
            double I2 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 3));
            double W1 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 4));
            double W2 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 5));
            double X1 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 6));
            double X2 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 7));
            int zvazok = (int) help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 8));
            double alpha = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 9));
            double d = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 10));
            int CH = 0;
            boolean ch = help.Object_To_Boolean(catenaryPanel1.DTMTable.getValueAt(i, 11));
            if (ch == true) {
                CH = 1;
            }
            double val = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 12));
            double r = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 13));
            double U = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 14));
            double I = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 15));
            double Phi = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 16));
            int poc = 0;
            boolean pocitaj = help.Object_To_Boolean(catenaryPanel1.DTMTable.getValueAt(i, 20));
            if (pocitaj == true) {
                poc = 1;
            }

            String lano = String.valueOf(catenaryPanel1.DTMTable.getValueAt(i, 22));

            fw.println(V1 + " " + V2 + " " + I1 + " " + I2 + " " + W1 + " " + W2 + " " + X1 + " " + X2 + " "
                    + zvazok + " " + alpha + " " + d + " " + CH + " " + val + " " + r + " " + U + " " + I + " "
                    + Phi + " " + poc + " " + lano);

        }

        Date todaysDate = new Date();
        DateFormat df2 = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        fw.println("END of file");
        fw.println("time of creation :" + df2.format(todaysDate));
        fw.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(InternalFrameproject.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Setup the environment to save the current model to a file.
 * /*from   w  w w.  j av  a2s.com*/
 * @see #writeOntologyModel(File)
 */
private void setupToWriteOntologyModel() {
    JFileChooser fileChooser;
    File destinationFile;
    int choice;

    if (lastDirectoryUsed == null) {
        lastDirectoryUsed = new File(".");
    }

    fileChooser = new JFileChooser();

    if (rdfFileSource != null && rdfFileSource.isFile()) {
        fileChooser.setSelectedFile(rdfFileSource.getBackingFile());
    } else {
        fileChooser.setSelectedFile(lastDirectoryUsed);
    }

    fileChooser.setDialogTitle("Save Ontology Model to File (" + getSelectedOutputLanguage() + ")");
    choice = fileChooser.showSaveDialog(this);
    destinationFile = fileChooser.getSelectedFile();

    // Did not click save, did not select a file or chose a directory
    // So do not write anything
    if (choice != JFileChooser.APPROVE_OPTION || destinationFile == null
            || (destinationFile.exists() && !destinationFile.isFile())) {
        return; // EARLY EXIT!
    }

    if (okToOverwriteFile(destinationFile)) {
        modelExportFile = destinationFile;
        runModelExport();
    }
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Save the text from the assertions text area to a file Note that this is
 * not the model and it may not be in an legal syntax for RDF triples. It is
 * simply storing what the user has placed in the text area.
 * //from   w ww  .j  a v  a2 s .co  m
 * @see writeOntologyModel
 */
private void saveAssertionsToFile() {
    FileWriter out;
    JFileChooser fileChooser;
    File destinationFile;
    int choice;

    out = null;

    if (lastDirectoryUsed == null) {
        lastDirectoryUsed = new File(".");
    }

    fileChooser = new JFileChooser();

    if (rdfFileSource != null && rdfFileSource.isFile()) {
        fileChooser.setSelectedFile(rdfFileSource.getBackingFile());
    } else {
        fileChooser.setSelectedFile(lastDirectoryUsed);
    }

    fileChooser.setDialogTitle("Save Assertions to File");
    choice = fileChooser.showSaveDialog(this);
    destinationFile = fileChooser.getSelectedFile();

    // Did not click save, did not select a file or chose a directory
    // So do not write anything
    if (choice != JFileChooser.APPROVE_OPTION || destinationFile == null
            || (destinationFile.exists() && !destinationFile.isFile())) {
        return; // EARLY EXIT!
    }

    if (okToOverwriteFile(destinationFile)) {

        LOGGER.info("Write assertions to file, " + destinationFile);

        try {
            out = new FileWriter(destinationFile, false);
            out.write(assertionsInput.getText());
            setRdfFileSource(new FileSource(destinationFile));
            addRecentAssertedTriplesFile(new FileSource(destinationFile));
        } catch (IOException ioExc) {
            final String errorMessage = "Unable to write to file: " + destinationFile;
            LOGGER.error(errorMessage, ioExc);
            throw new RuntimeException(errorMessage, ioExc);
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (Throwable throwable) {
                    final String errorMessage = "Failed to close output file: " + destinationFile;
                    LOGGER.error(errorMessage, throwable);
                    throw new RuntimeException(errorMessage, throwable);
                }
            }
        }
    }
}