Example usage for javax.swing JFileChooser SAVE_DIALOG

List of usage examples for javax.swing JFileChooser SAVE_DIALOG

Introduction

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

Prototype

int SAVE_DIALOG

To view the source code for javax.swing JFileChooser SAVE_DIALOG.

Click Source Link

Document

Type value indicating that the JFileChooser supports a "Save" file operation.

Usage

From source file:net.sf.firemox.DeckBuilder.java

/**
 * Save the current deck. If the current deck has not been saved once, user
 * have to specify the file's name of this new deck
 * /*  w  ww.j a va 2  s.  c  om*/
 * @return true if the current deck has been correctly saved. false otherwise.
 */
private boolean saveCurrentDeck() {
    if (isNew || Configuration.getString("decks.deck(0)", "").length() == 0
            && MToolKit.getDeckFile(this, JFileChooser.SAVE_DIALOG) == null) {
        return false;
    }
    return MSaveDeck.saveDeck(Configuration.getString("decks.deck(0)"), rightListModel.getCards(), form);
}

From source file:me.paddingdun.gen.code.gui.view.dbtable.TableView.java

private void btnGenActionPerformed(java.awt.event.ActionEvent evt) {
    if (model != null) {
        fileChooser.setFileSelectionMode(JFileChooser.SAVE_DIALOG | JFileChooser.DIRECTORIES_ONLY);
        fileChooser.setCurrentDirectory(new File("D:\\home\\Desktop"));
        int opt = fileChooser.showSaveDialog(null);
        // ?;/*w  ww .  j  a  v  a 2s  .  c om*/
        if (JFileChooser.APPROVE_OPTION == opt) {
            TaskHelper.runInNonEDT(new Callable<Integer[]>() {
                public Integer[] call() throws Exception {
                    File saveFile = fileChooser.getSelectedFile();
                    if (!saveFile.exists())
                        saveFile.mkdirs();
                    // ;
                    // ModelHelper.complexGetAndSimpleSet(TableView.this,
                    // model);

                    //?EditViewModel;
                    EditView ev = perspective.getEditView();
                    ev.setModelValue();
                    EditViewModel evm = ev.getModel();

                    // model;ok
                    ModelHelper.processTableViewModel(model, evm);

                    String baseJavaContent = VelocityHelper.baseEntityBean(model);
                    // System.out.println(javaContent);
                    FileHelper.genBasePojoJavaFile(saveFile.getAbsolutePath(), model.getPojoFullPackageName(),
                            model.getEntity().getEntityBeanName(), baseJavaContent);

                    String javaContent = VelocityHelper.entityBean(model);
                    // System.out.println(javaContent);
                    FileHelper.genPojoJavaFile(saveFile.getAbsolutePath(), model.getPojoFullPackageName(),
                            model.getEntity().getEntityBeanName(), javaContent);

                    String sqlMapBaseContent = VelocityHelper.sqlBaseMap(model);
                    FileHelper.genSqlMapBaseXmlFile(saveFile.getAbsolutePath(),
                            model.getEntity().getEntityBeanName(), sqlMapBaseContent);

                    String sqlMapContent = VelocityHelper.sqlMap(model);
                    FileHelper.genSqlMapXmlFile(saveFile.getAbsolutePath(),
                            model.getEntity().getEntityBeanName(), sqlMapContent);
                    // System.out.println(sqlMapContent);

                    String sqlMapBaseIDaoContent = VelocityHelper.sqlMapIDao(model);
                    FileHelper.genSqlMapIDaoJavaFile(saveFile.getAbsolutePath(), model.getDaoFullPackageName(),
                            model.getEntity().getEntityBeanName(), sqlMapBaseIDaoContent);

                    String sqlMapIDaoContent = VelocityHelper.sqlMapBaseDao(model);
                    FileHelper.genSqlMapBaseDaoJavaFile(saveFile.getAbsolutePath(),
                            model.getDaoFullPackageName(), model.getEntity().getEntityBeanName(),
                            sqlMapIDaoContent);

                    if (!VelocityHelper.isMybtis()) {
                        String sqlMapDaoImplContent = VelocityHelper.sqlMapDaoImpl(model);
                        FileHelper.genSqlMapDaoImplJavaFile(saveFile.getAbsolutePath(),
                                model.getDaoImplFullPackageName(), model.getEntity().getEntityBeanName(),
                                sqlMapDaoImplContent);
                    }

                    String sqlMapBaseServiceContent = VelocityHelper.sqlMapBaseService(model);
                    FileHelper.genSqlMapBaseServiceJavaFile(saveFile.getAbsolutePath(),
                            model.getServiceFullPackageName(), model.getEntity().getEntityBeanName(),
                            sqlMapBaseServiceContent);

                    String sqlMapIServiceContent = VelocityHelper.sqlMapIService(model);
                    FileHelper.genSqlMapIServiceJavaFile(saveFile.getAbsolutePath(),
                            model.getServiceFullPackageName(), model.getEntity().getEntityBeanName(),
                            sqlMapIServiceContent);

                    String sqlMapBaseServiceImplContent = VelocityHelper.sqlMapBaseServiceImpl(model);
                    FileHelper.genSqlMapBaseServiceImplJavaFile(saveFile.getAbsolutePath(),
                            model.getServiceImplFullPackageName(), model.getEntity().getEntityBeanName(),
                            sqlMapBaseServiceImplContent);

                    String sqlMapServiceImplContent = VelocityHelper.sqlMapServiceImpl(model);
                    FileHelper.genSqlMapServiceImplJavaFile(saveFile.getAbsolutePath(),
                            model.getServiceImplFullPackageName(), model.getEntity().getEntityBeanName(),
                            sqlMapServiceImplContent);

                    String springWebActionContent = VelocityHelper.springWebAction(model);
                    FileHelper.genSpringWebActionJavaFile(saveFile.getAbsolutePath(),
                            model.getWebActionFullPackageName(), model.getEntity().getEntityBeanName(),
                            springWebActionContent);

                    //                   String bootstrapDataTableJspContent =
                    //                  VelocityHelper.bootstrapDataTableJsp(model);
                    //                  FileHelper.genBootstrapDataTableJspFile(saveFile.getAbsolutePath(),
                    //                  model.getJspWebinfAfterDir(),
                    //                  model.getEntity().getEntityBeanName(),
                    //                  bootstrapDataTableJspContent);

                    String easyuiListJspContent = VelocityHelper.easyuiListJsp(model);
                    FileHelper.genEasyuiListJspFile(saveFile.getAbsolutePath(), model.getJspWebinfAfterDir(),
                            model.getEntity().getEntityBeanName(), easyuiListJspContent);

                    String easyuiEditJspContent = VelocityHelper.easyuiEditJsp(model);
                    FileHelper.genEasyuiEditJspFile(saveFile.getAbsolutePath(), model.getJspWebinfAfterDir(),
                            model.getEntity().getEntityBeanName(), easyuiEditJspContent);

                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            JOptionPane.showMessageDialog(null, "??!");
                        }
                    });
                    return null;
                }
            });
        }
    }
}

From source file:net.sf.firemox.DeckBuilder.java

/**
 * Invoked when an action occurs./*from  www.j  a v  a2 s . co m*/
 * 
 * @param e
 *          attached event
 */
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if ("menu_help_about".equals(command)) {
        new About(form).setVisible(true);
    } else if ("menu_db_exit".equals(command)) {
        exitForm();
    } else if ("menu_db_new".equals(command)) {
        if (!verifyModification()) {
            return;
        }
        setTitle("DeckBuilder");
        deckNameTxt.setText("");
        rightListModel.getCards().clear();
        datasets.removeAll();
        modifiedSinceSave = false;
        updateChecker();
        setAsNew();
    } else if ("menu_convert_DCK_MP".equals(command)) {
        /*
         * Convert an entire directory from a format to MP one
         */
        try {
            Converter
                    .convertDCK(MToolKit
                            .showDialogFile("Choose a directory of DCK to convert", 'o', null, FILTER_DECK,
                                    this, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY)
                            .getCanonicalPath());
        } catch (IOException e1) {
            JOptionPane.showMessageDialog(this, "Error occurred reading the specified directory",
                    "File problem", JOptionPane.ERROR_MESSAGE);
        } catch (Exception e1) {
            // cancel of user;
        }
    } else if ("menu_db_constraints".equals(command)) {
        // Show the deck constraints applied on the current TBS
        new DeckRules(this).setVisible(true);
    } else if ("menu_help_help".equals(command)) {
        /*
         * This method is invoked when user has chosen to see the help file. <br>
         * TODO documentation is not yet done for this form
         */
        JOptionPane.showMessageDialog(form, "Sorry, no documentation available for deck builder",
                "Negative yet implemented", JOptionPane.INFORMATION_MESSAGE);
    } else if ("menu_db_load".equals(command)) {
        if (verifyModification()) {
            String deckFile = MToolKit.getDeckFile(this, JFileChooser.OPEN_DIALOG);
            if (deckFile != null) {
                loadDeck(deckFile, rightListModel.getCards());
            }
        }
    } else if ("menu_db_saveas".equals(command)) {
        String deckFile = MToolKit.getDeckFile(this, JFileChooser.SAVE_DIALOG);
        if (deckFile != null) {
            MSaveDeck.saveDeck(deckFile, rightListModel.getCards(), form);
            setAsSaved();
        }
    } else if ("menu_db_save".equals(command)) {
        saveCurrentDeck();
        setAsSaved();
    } else {
        // several implemented filters
        final MListModel<MCardCompare> model = (MListModel<MCardCompare>) leftList.getModel();

        final FileInputStream dbStream = MdbLoader.resetMdb();

        final List<MCardCompare> toRemove = new ArrayList<MCardCompare>();

        if ("clear".equals(command)) {
            // Reset the color filters
            for (Component component : toolBar.getComponents()) {
                if (component instanceof JToggleButton) {
                    ((JToggleButton) component).setSelected(true);
                }
            }
        }
        model.addAll(model.removedDelegate);

        final int cardType = CardFactory.getIdCard((String) idCardComboBox.getSelectedItem());
        if (cardType != -1) {
            // "All" is not selected in card type filter
            // we remove the cards that don't have the selected card id
            for (MCardCompare cardCompare : model.delegate) {
                try {
                    final CardModel cardModel = cardCompare.getModel(dbStream);
                    if (!MCard.hasIdCard(cardModel.getIdCard(), cardType)) {
                        toRemove.add(cardCompare);
                    }
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            model.removeAll(toRemove);
            toRemove.clear();
        }

        // property filter
        // we search for the property value, if it isn't found it's because "All"
        // is selected in the comboBox
        int property = CardFactory.getProperty((String) propertiesComboBox.getSelectedItem());

        if (property != -1) {
            // "All" is not selected in property filter
            // we remove the cards that don't have the selected property
            for (MCardCompare cardCompare : model.delegate) {
                try {
                    final CardModel cardModel = cardCompare.getModel(dbStream);
                    if (!MCard.hasProperty(cardModel.getProperties(), property)) {
                        toRemove.add(cardCompare);
                    }
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            model.removeAll(toRemove);
            toRemove.clear();
        }

        // color filters
        for (int i = 1; i < IdCardColors.CARD_COLOR_VALUES.length + 1; i++) {
            final JToggleButton colorButton = (JToggleButton) toolBar.getComponent(i);
            if (!colorButton.isSelected()) {
                for (MCardCompare cardCompare : model.delegate) {
                    try {
                        final CardModel cardModel = cardCompare.getModel(dbStream);
                        if (i == 1) {
                            if (cardModel.getIdColor() == 0) {
                                toRemove.add(cardCompare);
                            }
                        } else if ((cardModel.getIdColor()
                                & IdCardColors.CARD_COLOR_VALUES[i - 1]) == IdCardColors.CARD_COLOR_VALUES[i
                                        - 1]) {
                            toRemove.add(cardCompare);
                        }
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
                model.removeAll(toRemove);
                toRemove.clear();
            }
        }
        leftList.repaint();
        if (!model.isEmpty())
            leftList.setSelectedIndex(0);
    }
}

From source file:me.paddingdun.gen.code.gui.view.dbtable.TableView.java

/**
 * ?;/*from w w  w.  j  av a2  s  .  c o  m*/
 * @param evt
 */
private void btnWorkGenActionPerformed(java.awt.event.ActionEvent evt) {
    if (model != null) {
        fileChooser.setFileSelectionMode(JFileChooser.SAVE_DIALOG | JFileChooser.DIRECTORIES_ONLY);
        fileChooser.setCurrentDirectory(new File("D:\\home\\Desktop"));
        int opt = fileChooser.showSaveDialog(null);
        // ?;
        if (JFileChooser.APPROVE_OPTION == opt) {
            TaskHelper.runInNonEDT(new Callable<Integer[]>() {
                public Integer[] call() throws Exception {
                    File saveFile = fileChooser.getSelectedFile();
                    if (!saveFile.exists())
                        saveFile.mkdirs();
                    // ;
                    // ModelHelper.complexGetAndSimpleSet(TableView.this,
                    // model);

                    //?EditViewModel;
                    EditView ev = perspective.getEditView();
                    ev.setModelValue();
                    EditViewModel evm = ev.getModel();

                    // model;ok
                    ModelHelper.processTableViewModel(model, evm);

                    String java1 = VelocityHelper.commonJava(model, "template/velocity/work20170417/pojo.vm");
                    // System.out.println(javaContent);
                    FileHelper.genCommonJavaFile(saveFile.getAbsolutePath(), model.getPojoFullPackageName(),
                            model.getEntity().getEntityBeanName(), java1);

                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            JOptionPane.showMessageDialog(null, "??!");
                        }
                    });
                    return null;
                }
            });
        }
    }
}

From source file:cc.creativecomputing.io.CCIOUtil.java

static public String selectFolder(final String prompt, String theFolder) {

    fileChooser = new JFileChooser();
    fileChooser.setDialogTitle(prompt);/* www.j a  v a2 s  .c o m*/
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (theFolder != null)
        fileChooser.setCurrentDirectory(new File(theFolder));

    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    int returned = fileChooser.showSaveDialog(null);

    if (returned == JFileChooser.CANCEL_OPTION) {
        selectedFile = null;
    } else {
        selectedFile = fileChooser.getSelectedFile();
    }
    return (selectedFile == null) ? null : selectedFile.getAbsolutePath();
}

From source file:net.sf.jsignpdf.SignPdfForm.java

private void btnOutPdfFileActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnOutPdfFileActionPerformed
    showFileChooser(tfOutPdfFile, SignerFileChooser.FILEFILTER_PDF, JFileChooser.SAVE_DIALOG);
}

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

public void createNewProjectFolder() {

    try {/*from   www.j  a  v  a 2s. c om*/
        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:Creator.WidgetPanel.java

private void _Button_GenerateLinksActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__Button_GenerateLinksActionPerformed

    if (ws.wpl.links.isEmpty()) {
        return;/*  w  ww  . ja va  2  s  .  c om*/
    }

    _FileChooser_IoFile.setDialogTitle("Save Text Exports");
    _FileChooser_IoFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    _FileChooser_IoFile.setDialogType(JFileChooser.SAVE_DIALOG);
    _FileChooser_IoFile.setApproveButtonText("Save Here");

    int returnVal = _FileChooser_IoFile.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {

        File file = _FileChooser_IoFile.getSelectedFile();
        //System.out.println("File: " + file.getAbsolutePath());
        String filepath = file.getAbsolutePath();

        String outputCode = "[";

        WidgetCode wc = mf.wgPanel.getWidgetCode(widgetCodeName);
        for (Map.Entry<String, LinkInfo> entry : ws.wpl.getLinks().entrySet()) {

            // For each entry, format a code string based on the default positions
            // and the given panel name and ID's
            String panelID = String.valueOf(entry.getValue().getPanelID());
            String panelName = entry.getValue().getPanelName();

            String xPos = String.valueOf(entry.getValue().getXPos());
            String yPos = String.valueOf(entry.getValue().getYPos());

            String newCode = wc.getFullWidgetText().replace("`%XPOS%`", xPos).replace("`%YPOS%`", yPos)
                    .replace("`%PANELID%`", panelID).replace("`%PANELNAME%`", panelName);

            outputCode += newCode + ",";

        }

        outputCode = outputCode.substring(0, outputCode.length() - 1) + "]";

        String fp = filepath + "\\WidgetExports-Links.txt";
        //System.out.println("Writing " + fp);

        try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fp), "utf-8"))) {
            writer.write(outputCode);
            //System.out.println("Writing " + fp + " Completed");
        } catch (Exception e) {
            System.out.println("Failed writing to: " + fp);
        }

        System.out.println(outputCode);

    } else {
        System.out.println("Saving widgets exports cancelled.");
    }
}

From source file:Creator.WidgetPanel.java

public boolean writeOutExports(Map<String, List<String>> exports) {

    _FileChooser_IoFile.setDialogTitle("Save Text Exports");
    _FileChooser_IoFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    _FileChooser_IoFile.setDialogType(JFileChooser.SAVE_DIALOG);
    _FileChooser_IoFile.setApproveButtonText("Save Here");

    int returnVal = _FileChooser_IoFile.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {

        File file = _FileChooser_IoFile.getSelectedFile();
        //System.out.println("File: " + file.getAbsolutePath());
        String filepath = file.getAbsolutePath();

        for (Entry<String, List<String>> entry : exports.entrySet()) {

            // Use this to keep a maximum of 15 elements per text file to reduce the import lag
            List<String> importList = new ArrayList<>();
            // The string that will contain up to 15 json entries
            String jsonEntry = "[";
            int sizeCounter = 0;

            // For every json code generated for the entry (Main, Racks, Loads, etc)
            // we add the json code to a array list to contain up to 15 json codes
            // Importing more than 15 at a time can severely lag the system.
            for (String listString : entry.getValue()) {
                if (sizeCounter >= 90000) {
                    sizeCounter = 0;// w w w. j  av a  2 s .  co  m
                    jsonEntry = jsonEntry.substring(0, jsonEntry.length() - 1) + "]";
                    importList.add(jsonEntry);
                    jsonEntry = "[";
                }
                jsonEntry += listString + ",";
                sizeCounter += listString.length() + 2;
            }
            jsonEntry = jsonEntry.substring(0, jsonEntry.length() - 1) + "]";
            importList.add(jsonEntry);

            sizeCounter = 0;
            for (String imports : importList) {
                String fp = filepath + "\\WidgetExports-" + entry.getKey() + "-" + sizeCounter + ".txt";
                //System.out.println("Writing " + fp);

                try (Writer writer = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(fp), "utf-8"))) {
                    writer.write(imports);
                    sizeCounter++;
                    //System.out.println("Writing " + fp + " Completed");
                } catch (Exception e) {
                    System.out.println("Failed writing to: " + fp);
                }
            }
        }
    } else {
        System.out.println("Saving widgets exports cancelled.");
    }

    return true;
}

From source file:com.hexidec.ekit.EkitCore.java

/**
 * Method for saving text as a complete HTML document
 *//* w w w. j  a v  a  2s.c  o  m*/
public void writeOut(HTMLDocument doc, File whatFile) throws IOException, BadLocationException {
    if (whatFile == null) {
        whatFile = getFileFromChooser(".", JFileChooser.SAVE_DIALOG, extsHTML,
                Translatrix.getTranslationString("FiletypeHTML"));
    }
    if (whatFile != null) {
        FileWriter fw = new FileWriter(whatFile);
        htmlKit.write(fw, doc, 0, doc.getLength());
        fw.flush();
        fw.close();
        currentFile = whatFile;
        updateTitle();
    }
    refreshOnUpdate();
}