Example usage for javax.swing JFileChooser JFileChooser

List of usage examples for javax.swing JFileChooser JFileChooser

Introduction

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

Prototype

public JFileChooser() 

Source Link

Document

Constructs a JFileChooser pointing to the user's default directory.

Usage

From source file:com.raddle.tools.MergeMain.java

private void initGUI() {
    try {/* ww  w .j a  v  a  2s.co  m*/
        {
            this.setBounds(0, 0, 1050, 600);
            getContentPane().setLayout(null);
            this.setTitle("\u5c5e\u6027\u6587\u4ef6\u6bd4\u8f83");
            {
                sourceTxt = new JTextField();
                getContentPane().add(sourceTxt);
                sourceTxt.setBounds(12, 12, 373, 22);
            }
            {
                sourceBtn = new JButton();
                getContentPane().add(sourceBtn);
                sourceBtn.setText("\u6253\u5f00");
                sourceBtn.setBounds(406, 12, 74, 22);
                sourceBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        JFileChooser fileChooser = new JFileChooser(); // 
                        fileChooser.addChoosableFileFilter(
                                new FileNameExtensionFilter("", "properties"));
                        File curFile = new File(sourceTxt.getText());
                        if (curFile.exists()) {
                            fileChooser.setCurrentDirectory(curFile.getParentFile());
                        }
                        int result = fileChooser.showOpenDialog(MergeMain.this);
                        if (result == JFileChooser.APPROVE_OPTION) {
                            File selected = fileChooser.getSelectedFile();
                            source = new PropertyHolder(selected, "utf-8");
                            sourceTxt.setText(selected.getAbsolutePath());
                            properties.setProperty("left.file", selected.getAbsolutePath());
                            savePropMergeFile();
                            compare();
                        }
                    }
                });
            }
            {
                targetTxt = new JTextField();
                getContentPane().add(targetTxt);
                targetTxt.setBounds(496, 12, 419, 22);
            }
            {
                targetBtn = new JButton();
                getContentPane().add(targetBtn);
                targetBtn.setText("\u6253\u5f00");
                targetBtn.setBounds(935, 12, 81, 22);
                targetBtn.setSize(74, 22);
                targetBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        JFileChooser fileChooser = new JFileChooser(); // 
                        fileChooser.addChoosableFileFilter(
                                new FileNameExtensionFilter("", "properties"));
                        File curFile = new File(targetTxt.getText());
                        if (curFile.exists()) {
                            fileChooser.setCurrentDirectory(curFile.getParentFile());
                        }
                        int result = fileChooser.showOpenDialog(MergeMain.this);
                        if (result == JFileChooser.APPROVE_OPTION) {
                            File selected = fileChooser.getSelectedFile();
                            target = new PropertyHolder(selected, "utf-8");
                            targetTxt.setText(selected.getAbsolutePath());
                            properties.setProperty("right.file", selected.getAbsolutePath());
                            savePropMergeFile();
                            compare();
                        }
                    }
                });
            }
            {
                jScrollPane1 = new JScrollPane();
                getContentPane().add(jScrollPane1);
                jScrollPane1.setBounds(12, 127, 373, 413);
                {
                    ListModel sourceListModel = new DefaultComboBoxModel(new String[] {});
                    sourceList = new JList();
                    jScrollPane1.setViewportView(sourceList);
                    sourceList.setAutoscrolls(true);
                    sourceList.setModel(sourceListModel);
                    sourceList.addKeyListener(new KeyAdapter() {
                        @Override
                        public void keyPressed(KeyEvent evt) {
                            if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
                                PropertyLine v = (PropertyLine) sourceList.getSelectedValue();
                                if (v != null) {
                                    int ret = JOptionPane.showConfirmDialog(MergeMain.this,
                                            "?" + v.getKey() + "?");
                                    if (ret == JOptionPane.YES_OPTION) {
                                        v.setState(LineState.deleted);
                                        compare();
                                        sourceList.setSelectedValue(v, true);
                                    }
                                }
                            }
                        }
                    });
                    sourceList.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent evt) {
                            if (evt.getClickCount() == 2) {
                                Object v = sourceList.getSelectedValue();
                                updatePropertyLine((PropertyLine) v);
                                sourceList.setSelectedValue(v, true);
                            }
                        }
                    });
                    sourceList.addListSelectionListener(new ListSelectionListener() {

                        @Override
                        public void valueChanged(ListSelectionEvent evt) {
                            if (sourceList.getSelectedValue() != null) {
                                PropertyLine pl = (PropertyLine) sourceList.getSelectedValue();
                                if (target != null) {
                                    PropertyLine p = target.getLine(pl.getKey());
                                    if (p != null) {
                                        TextDiffResult rt = TextdiffUtil.getDifferResult(p.toString(),
                                                pl.toString());
                                        diffResultPane.setText("" + rt.getTargetHtml() + "<br/>?"
                                                + rt.getSrcHtml());
                                        selectLine(targetList, p);
                                        return;
                                    }
                                }
                                TextDiffResult rt = TextdiffUtil.getDifferResult("", pl.toString());
                                diffResultPane.setText(
                                        "" + rt.getTargetHtml() + "<br/>?" + rt.getSrcHtml());

                            }
                        }
                    });
                }
            }
            {
                jScrollPane2 = new JScrollPane();
                getContentPane().add(jScrollPane2);
                jScrollPane2.setBounds(496, 127, 419, 413);
                {
                    ListModel targetListModel = new DefaultComboBoxModel(new String[] {});
                    targetList = new JList();
                    jScrollPane2.setViewportView(targetList);
                    targetList.setAutoscrolls(true);
                    targetList.setModel(targetListModel);
                    targetList.addKeyListener(new KeyAdapter() {
                        @Override
                        public void keyPressed(KeyEvent evt) {
                            if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
                                PropertyLine v = (PropertyLine) targetList.getSelectedValue();
                                if (v != null) {
                                    int ret = JOptionPane.showConfirmDialog(MergeMain.this,
                                            "?" + v.getKey() + "?");
                                    if (ret == JOptionPane.YES_OPTION) {
                                        v.setState(LineState.deleted);
                                        compare();
                                        targetList.setSelectedValue(v, true);
                                    }
                                }
                            }
                        }
                    });
                    targetList.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent evt) {
                            if (evt.getClickCount() == 2) {
                                Object v = targetList.getSelectedValue();
                                updatePropertyLine((PropertyLine) v);
                                targetList.setSelectedValue(v, true);
                            }
                        }
                    });
                    targetList.addListSelectionListener(new ListSelectionListener() {

                        @Override
                        public void valueChanged(ListSelectionEvent evt) {
                            if (targetList.getSelectedValue() != null) {
                                PropertyLine pl = (PropertyLine) targetList.getSelectedValue();
                                if (source != null) {
                                    PropertyLine s = source.getLine(pl.getKey());
                                    if (s != null) {
                                        TextDiffResult rt = TextdiffUtil.getDifferResult(pl.toString(),
                                                s.toString());
                                        diffResultPane.setText("" + rt.getTargetHtml() + "<br/>?"
                                                + rt.getSrcHtml());
                                        selectLine(sourceList, s);
                                        return;
                                    }
                                }
                                TextDiffResult rt = TextdiffUtil.getDifferResult(pl.toString(), "");
                                diffResultPane.setText(
                                        "" + rt.getTargetHtml() + "<br/>?" + rt.getSrcHtml());
                            }
                        }
                    });
                }
            }
            {
                sourceSaveBtn = new JButton();
                getContentPane().add(sourceSaveBtn);
                sourceSaveBtn.setText("\u4fdd\u5b58");
                sourceSaveBtn.setBounds(406, 45, 74, 22);
                sourceSaveBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        int result = JOptionPane.showConfirmDialog(MergeMain.this,
                                "???\n"
                                        + source.getPropertyFile().getAbsolutePath());
                        if (result == JOptionPane.YES_OPTION) {
                            source.saveFile();
                            JOptionPane.showMessageDialog(MergeMain.this, "??");
                            clearState(source);
                            compare();
                        }
                    }
                });
            }
            {
                targetSaveBtn = new JButton();
                getContentPane().add(targetSaveBtn);
                targetSaveBtn.setText("\u4fdd\u5b58");
                targetSaveBtn.setBounds(935, 45, 81, 22);
                targetSaveBtn.setSize(74, 22);
                targetSaveBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        int result = JOptionPane.showConfirmDialog(MergeMain.this,
                                "????\n"
                                        + target.getPropertyFile().getAbsolutePath());
                        if (result == JOptionPane.YES_OPTION) {
                            target.saveFile();
                            JOptionPane.showMessageDialog(MergeMain.this, "??");
                            clearState(target);
                            compare();
                        }
                    }
                });
            }
            {
                toTargetBtn = new JButton();
                getContentPane().add(toTargetBtn);
                toTargetBtn.setText("->");
                toTargetBtn.setBounds(406, 221, 74, 22);
                toTargetBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        Object[] oo = sourceList.getSelectedValues();
                        for (Object selected : oo) {
                            PropertyLine s = (PropertyLine) selected;
                            if (s != null && target != null) {
                                PropertyLine t = target.getLine(s.getKey());
                                if (t == null) {
                                    PropertyLine n = s.clone();
                                    n.setState(LineState.added);
                                    target.addPropertyLineAtSuitedPosition(n);
                                } else if (!t.getValue().equals(s.getValue())) {
                                    t.setState(LineState.updated);
                                    t.setValue(s.getValue());
                                } else if (t.getState() == LineState.deleted) {
                                    if (t.getValue().equals(t.getOriginalValue())) {
                                        t.setState(LineState.original);
                                    } else {
                                        t.setState(LineState.updated);
                                    }
                                }
                                compare();
                            }
                        }
                    }
                });
            }
            {
                toSourceBtn = new JButton();
                getContentPane().add(toSourceBtn);
                toSourceBtn.setText("<-");
                toSourceBtn.setBounds(406, 255, 74, 22);
                toSourceBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        Object[] oo = targetList.getSelectedValues();
                        for (Object selected : oo) {
                            PropertyLine t = (PropertyLine) selected;
                            if (t != null && source != null) {
                                PropertyLine s = source.getLine(t.getKey());
                                if (s == null) {
                                    PropertyLine n = t.clone();
                                    n.setState(LineState.added);
                                    source.addPropertyLineAtSuitedPosition(n);
                                } else if (!s.getValue().equals(t.getValue())) {
                                    s.setState(LineState.updated);
                                    s.setValue(t.getValue());
                                } else if (s.getState() == LineState.deleted) {
                                    if (s.getValue().equals(s.getOriginalValue())) {
                                        s.setState(LineState.original);
                                    } else {
                                        s.setState(LineState.updated);
                                    }
                                }
                                compare();
                            }
                        }
                    }
                });
            }
            {
                jScrollPane3 = new JScrollPane();
                getContentPane().add(jScrollPane3);
                jScrollPane3.setBounds(12, 73, 903, 42);
                {
                    diffResultPane = new JTextPane();
                    jScrollPane3.setViewportView(diffResultPane);
                    diffResultPane.setBounds(12, 439, 903, 63);
                    diffResultPane.setContentType("text/html");
                    diffResultPane.setPreferredSize(new java.awt.Dimension(901, 42));
                }
            }
            {
                compareBtn = new JButton();
                getContentPane().add(compareBtn);
                compareBtn.setText("\u6bd4\u8f83");
                compareBtn.setBounds(406, 139, 74, 22);
                compareBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        compare();
                    }
                });
            }
            {
                sourceReloadBtn = new JButton();
                getContentPane().add(sourceReloadBtn);
                sourceReloadBtn.setText("\u91cd\u65b0\u8f7d\u5165");
                sourceReloadBtn.setBounds(12, 40, 64, 29);
                sourceReloadBtn.setSize(90, 22);
                sourceReloadBtn.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        if (sourceTxt.getText().length() > 0) {
                            File curFile = new File(sourceTxt.getText().trim());
                            if (curFile.exists()) {
                                source = new PropertyHolder(curFile, "utf-8");
                                sourceTxt.setText(curFile.getAbsolutePath());
                                properties.setProperty("left.file", curFile.getAbsolutePath());
                                savePropMergeFile();
                                compare();
                            } else {
                                JOptionPane.showMessageDialog(MergeMain.this,
                                        "" + curFile.getAbsolutePath() + "?");
                            }
                        }
                    }
                });
            }
            {
                targetReloadBtn = new JButton();
                getContentPane().add(targetReloadBtn);
                targetReloadBtn.setText("\u91cd\u65b0\u8f7d\u5165");
                targetReloadBtn.setBounds(839, 45, 90, 22);
                targetReloadBtn.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        if (targetTxt.getText().length() > 0) {
                            File curFile = new File(targetTxt.getText().trim());
                            if (curFile.exists()) {
                                target = new PropertyHolder(curFile, "utf-8");
                                targetTxt.setText(curFile.getAbsolutePath());
                                properties.setProperty("right.file", curFile.getAbsolutePath());
                                savePropMergeFile();
                                compare();
                            } else {
                                JOptionPane.showMessageDialog(MergeMain.this,
                                        "" + curFile.getAbsolutePath() + "?");
                            }
                        }
                    }
                });
            }
            {
                helpBtn = new JButton();
                getContentPane().add(helpBtn);
                helpBtn.setText("\u5e2e\u52a9");
                helpBtn.setBounds(405, 338, 38, 29);
                helpBtn.setSize(74, 22);
                helpBtn.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        StringBuilder sb = new StringBuilder();
                        sb.append("?").append("\n");
                        sb.append("del").append("\n");
                        sb.append("??").append("\n");
                        sb.append(": /.prop-merge/prop-merge.properties").append("\n");
                        JOptionPane.showMessageDialog(MergeMain.this, sb.toString());
                    }
                });
            }
            {
                sourceEditBtn = new JButton();
                getContentPane().add(sourceEditBtn);
                sourceEditBtn.setText("\u7f16\u8f91\u6587\u4ef6");
                sourceEditBtn.setBounds(108, 40, 90, 22);
                sourceEditBtn.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        if (sourceTxt.getText().length() > 0) {
                            File curFile = new File(sourceTxt.getText());
                            editFile(curFile);
                        }
                    }
                });
            }
            {
                targetEditBtn = new JButton();
                getContentPane().add(targetEditBtn);
                targetEditBtn.setText("\u7f16\u8f91\u6587\u4ef6");
                targetEditBtn.setBounds(743, 45, 90, 22);
                targetEditBtn.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        if (targetTxt.getText().length() > 0) {
                            File curFile = new File(targetTxt.getText());
                            editFile(curFile);
                        }
                    }
                });
            }
        }
        pack();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.alvermont.terraj.util.ui.JNLPFileChooser.java

private void init() {
    try {/*from   ww w. j av  a 2 s.  c o m*/
        chooser = new JFileChooser();
    } catch (SecurityException se) {
        log.error("SecurityException creating JFileChooser assuming JNLP", se);
    }
}

From source file:com.intuit.tank.tools.script.ScriptFilterRunner.java

/**
 * @param loadChooser// w w  w  . ja va2 s  . co m
 * @return
 */
public Component createBottomPanel() {
    loadChooser = new JFileChooser();
    loadChooser.setFileFilter(new FileFilter() {

        @Override
        public String getDescription() {
            return "Script Files";
        }

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || ConfiguredLanguage.getConfiguredExtensions()
                    .contains(FilenameUtils.getExtension(f.getName()));
        }
    });
    runBT = new JButton("Run Script");
    runBT.setEnabled(false);
    runBT.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            runScript();
        }
    });
    JButton chooseBT = new JButton("Open Script...");
    chooseBT.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            loadScript();
        }
    });

    JButton saveScriptBT = new JButton("Save Script...");
    saveScriptBT.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveScript(false);
        }
    });

    JButton saveAsScriptBT = new JButton("Save Script As...");
    saveAsScriptBT.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveScript(true);
        }
    });

    JButton localBT = new JButton("Toggle Storage Mode");
    localBT.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            toggleStorageMode();
        }

    });
    localLB = new JLabel();
    setLocalLable();

    JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
    bottomPanel.add(runBT);
    bottomPanel.add(chooseBT);
    bottomPanel.add(saveScriptBT);
    bottomPanel.add(saveAsScriptBT);
    bottomPanel.add(localLB);
    bottomPanel.add(localBT);
    return bottomPanel;
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsOverviewPanel.java

public void refresh(final Instances dataSet, final int dateIdx) {
    final Instances gapsDescriptionsDataset = GapsUtil.buildGapsDescription(gcp, dataSet, dateIdx);

    final JXTable gapsDescriptionsTable = new JXTable();
    final InstanceTableModel gapsDescriptionsTableModel = new InstanceTableModel(false);
    gapsDescriptionsTableModel.setDataset(gapsDescriptionsDataset);
    gapsDescriptionsTable.setModel(gapsDescriptionsTableModel);
    gapsDescriptionsTable.setEditable(true);
    gapsDescriptionsTable.setShowHorizontalLines(false);
    gapsDescriptionsTable.setShowVerticalLines(false);
    gapsDescriptionsTable.setVisibleRowCount(5);
    gapsDescriptionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    gapsDescriptionsTable.setSortable(false);
    gapsDescriptionsTable.packAll();/*from   w w  w .  j  ava  2 s  .  c o m*/

    gapsDescriptionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    gapsDescriptionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int modelRow = gapsDescriptionsTable.getSelectedRow();
                if (modelRow < 0)
                    modelRow = 0;

                final String attrname = gapsDescriptionsTableModel.getValueAt(modelRow, 1).toString();
                final Attribute attr = dataSet.attribute(attrname);
                final int gapsize = (int) Double
                        .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 5).toString()).doubleValue();
                final int position = (int) Double
                        .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 6).toString()).doubleValue();

                try {
                    final ChartPanel cp = GapsUIUtil.buildGapChartPanel(dataSet, dateIdx, attr, gapsize,
                            position);

                    visualOverviewPanel.removeAll();
                    visualOverviewPanel.add(cp, BorderLayout.CENTER);

                    geomapPanel.removeAll();
                    geomapPanel.add(gcp.getMapPanel(Arrays.asList(attrname), new ArrayList<String>(), false));

                    jxp.updateUI();
                } catch (Exception ee) {
                    ee.printStackTrace();
                }
            }
        }
    });

    gapsDescriptionsTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(final MouseEvent e) {
            final InstanceTableModel instanceTableModel = (InstanceTableModel) gapsDescriptionsTable.getModel();
            final int row = gapsDescriptionsTable.rowAtPoint(e.getPoint());
            //final int row=gapsDescriptionsTable.getSelectedRow();
            final int modelRow = gapsDescriptionsTable.convertRowIndexToModel(row);
            //final int modelRow=(int)Double.valueOf(instanceTableModel.getValueAt(row,0).toString()).doubleValue();
            //System.out.println(row+" "+modelRow);

            final String attrname = instanceTableModel.getValueAt(modelRow, 1).toString();
            final Attribute attr = dataSet.attribute(attrname);
            final int gapsize = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 5).toString())
                    .doubleValue();
            final int position = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 6).toString())
                    .doubleValue();

            if (!e.isPopupTrigger()) {
                // nothing?
            } else {
                final JPopupMenu jPopupMenu = new JPopupMenu("feur");

                final JMenuItem interactiveFillMenuItem = new JMenuItem("Fill this gap (interactively)");
                interactiveFillMenuItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        final GapFillingFrame jxf = new GapFillingFrame(atv, dataSet, attr, dateIdx,
                                GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), position, gapsize, gcp,
                                false);
                        jxf.setSize(new Dimension(900, 700));
                        //jxf.setExtendedState(Frame.MAXIMIZED_BOTH);                        
                        jxf.setLocationRelativeTo(jPopupMenu);
                        jxf.setVisible(true);
                        //jxf.setResizable(false);
                    }
                });
                jPopupMenu.add(interactiveFillMenuItem);

                final JMenuItem lookupInKnowledgeDBMenuItem = new JMenuItem(
                        "Show the most similar cases from KnowledgeDB");
                lookupInKnowledgeDBMenuItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        final double x = gcp.getCoordinates(attrname)[0];
                        final double y = gcp.getCoordinates(attrname)[1];
                        final String season = instanceTableModel.getValueAt(modelRow, 3).toString()
                                .split("/")[0];
                        final boolean isDuringRising = instanceTableModel.getValueAt(modelRow, 11).toString()
                                .equals("true");
                        try {
                            final Calendar cal = Calendar.getInstance();
                            final String dateAsString = instanceTableModel.getValueAt(modelRow, 2).toString()
                                    .replaceAll("'", "");
                            cal.setTime(FormatterUtil.DATE_FORMAT.parse(dateAsString));
                            final int year = cal.get(Calendar.YEAR);

                            new SimilarCasesFrame(dataSet, dateIdx, gcp, attrname, gapsize, position, x, y,
                                    year, season, isDuringRising);
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                });
                jPopupMenu.add(lookupInKnowledgeDBMenuItem);

                final JMenuItem mExport = new JMenuItem("Export this table as CSV");
                mExport.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        final JFileChooser fc = new JFileChooser();
                        fc.setAcceptAllFileFilterUsed(false);
                        final int returnVal = fc.showSaveDialog(gapsDescriptionsTable);
                        if (returnVal == JFileChooser.APPROVE_OPTION) {
                            try {
                                final File file = fc.getSelectedFile();
                                WekaDataAccessUtil.saveInstancesIntoCSVFile(gapsDescriptionsDataset, file);
                            } catch (Exception ee) {
                                ee.printStackTrace();
                            }
                        }
                    }
                });
                jPopupMenu.add(mExport);

                jPopupMenu.show(gapsDescriptionsTable, e.getX(), e.getY());
            }
        }
    });

    final int tableWidth = (int) gapsDescriptionsTable.getPreferredSize().getWidth() + 30;
    final JScrollPane scrollPane = new JScrollPane(gapsDescriptionsTable);
    scrollPane.setPreferredSize(new Dimension(Math.min(tableWidth, 500), 500));
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    this.tablePanel.removeAll();
    this.tablePanel.add(scrollPane, BorderLayout.CENTER);

    this.visualOverviewPanel.removeAll();

    /* automatically compute the most similar series and the 'rising' flag */
    new AbstractSimpleAsync<Void>(false) {
        @Override
        public Void execute() throws Exception {
            final int rc = gapsDescriptionsTableModel.getRowCount();
            for (int i = 0; i < rc; i++) {
                final int modelRow = i;

                try {
                    final String attrname = gapsDescriptionsTableModel.getValueAt(modelRow, 1).toString();
                    final Attribute attr = dataSet.attribute(attrname);
                    final int gapsize = (int) Double
                            .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 5).toString())
                            .doubleValue();
                    final int position = (int) Double
                            .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 6).toString())
                            .doubleValue();

                    /* most similar */
                    gapsDescriptionsTableModel.setValueAt("...", modelRow, 7);
                    final int cvba = GapsUtil.getCountOfValuesBeforeAndAfter(gapsize);
                    Instances gapds = WekaDataProcessingUtil.buildFilteredDataSet(dataSet, 0,
                            dataSet.numAttributes() - 1, Math.max(0, position - cvba),
                            Math.min(position + gapsize + cvba, dataSet.numInstances() - 1));
                    final String mostsimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(gapds,
                            attr, WekaTimeSeriesUtil.getNamesOfAttributesWithoutGap(gapds), false);
                    gapsDescriptionsTableModel.setValueAt(mostsimilar, modelRow, 7);

                    /* 'rising' flag */
                    gapsDescriptionsTableModel.setValueAt("...", modelRow, 11);
                    final List<String> attributeNames = WekaDataStatsUtil.getAttributeNames(dataSet);
                    attributeNames.remove("timestamp");
                    final String nearestStationName = gcp.findNearestStation(attr.name(), attributeNames);
                    final Attribute nearestStationAttr = dataSet.attribute(nearestStationName);
                    //System.out.println(nearestStationName+" "+nearestStationAttr);
                    final boolean isDuringRising = GapsUtil.isDuringRising(dataSet, position, gapsize,
                            new int[] { dateIdx, attr.index(), nearestStationAttr.index() });
                    gapsDescriptionsTableModel.setValueAt(isDuringRising, modelRow, 11);

                    gapsDescriptionsTableModel.fireTableDataChanged();
                } catch (Exception e) {
                    gapsDescriptionsTableModel.setValueAt("n/a", modelRow, 7);
                    gapsDescriptionsTableModel.setValueAt("n/a", modelRow, 11);
                    e.printStackTrace();
                }
            }
            return null;
        }

        @Override
        public void onSuccess(Void result) {
        }

        @Override
        public void onFailure(Throwable caught) {
            caught.printStackTrace();
        }

    }.start();

    /* select the first row */
    gapsDescriptionsTable.setRowSelectionInterval(0, 0);
}

From source file:edu.harvard.mcz.imagecapture.jobs.JobAllImageFilesScan.java

@Override
public void start() {
    startTime = new Date();
    Singleton.getSingletonInstance().getJobList().addJob((RunnableJob) this);
    runStatus = RunStatus.STATUS_RUNNING;
    File imagebase = null; // place to start the scan from, imagebase directory for SCAN_ALL
    startPoint = null;/*from ww w  .j a v  a 2s .  c  om*/
    // If it isn't null, retrieve the image base directory from properties, and test for read access.
    if (Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_IMAGEBASE) == null) {
        JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                "Can't start scan.  Don't know where images are stored.  Set imagbase property.", "Can't Scan.",
                JOptionPane.ERROR_MESSAGE);
    } else {
        imagebase = new File(Singleton.getSingletonInstance().getProperties().getProperties()
                .getProperty(ImageCaptureProperties.KEY_IMAGEBASE));
        if (imagebase != null) {
            if (imagebase.canRead()) {
                startPoint = imagebase;
            } else {
                // If it can't be read, null out imagebase
                imagebase = null;
            }
        }
        if (scan == SCAN_SPECIFIC && startPointSpecific != null && startPointSpecific.canRead()) {
            // A scan start point has been provided, don't launch a dialog.
            startPoint = startPointSpecific;
        }
        if (imagebase == null || scan == SCAN_SELECT) {
            // launch a file chooser dialog to select the directory to scan
            final JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            if (scan == SCAN_SELECT && startPointSpecific != null && startPointSpecific.canRead()) {
                fileChooser.setCurrentDirectory(startPointSpecific);
            } else {
                if (Singleton.getSingletonInstance().getProperties().getProperties()
                        .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) {
                    fileChooser.setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties()
                            .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH)));
                }
            }
            int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame());
            if (returnValue == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                log.debug("Selected base directory: " + file.getName() + ".");
                startPoint = file;
            } else {
                //TODO: handle error condition
                log.error("Directory selection cancelled by user.");
            }
            //TODO: Filechooser to pick path, then save (if SCAN_ALL) imagebase property. 
            //Perhaps.  Might be undesirable behavior.
            //Probably better to warn that imagebase is null;
        }

        // TODO: Check that startPoint is or is within imagebase.
        // Check that fileToCheck is within imagebase.
        if (!ImageCaptureProperties.isInPathBelowBase(startPoint)) {
            String base = Singleton.getSingletonInstance().getProperties().getProperties()
                    .getProperty(ImageCaptureProperties.KEY_IMAGEBASE);
            log.error("Tried to scan directory (" + startPoint.getPath() + ") outside of base image directory ("
                    + base + ")");
            String message = "Can't scan and database files outside of base image directory (" + base + ")";
            JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message,
                    "Can't Scan outside image base directory.", JOptionPane.YES_NO_OPTION);
        } else {

            // run in separate thread and allow cancellation and status reporting

            // walk through directory tree

            if (!startPoint.canRead()) {
                JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                        "Can't start scan.  Unable to read selected directory: " + startPoint.getPath(),
                        "Can't Scan.", JOptionPane.YES_NO_OPTION);
            } else {
                Singleton.getSingletonInstance().getMainFrame()
                        .setStatusMessage("Scanning " + startPoint.getPath());
                Counter counter = new Counter();
                // count files to scan
                countFiles(startPoint, counter);
                setPercentComplete(0);
                Singleton.getSingletonInstance().getMainFrame().notifyListener(runStatus, this);
                counter.incrementDirectories();
                // scan
                if (runStatus != RunStatus.STATUS_TERMINATED) {
                    checkFiles(startPoint, counter);
                }
                // report
                String report = "Scanned " + counter.getDirectories() + " directories.\n";
                report += "Created thumbnails in " + thumbnailCounter + " directories";
                if (thumbnailCounter == 0) {
                    report += " (May still be in progress)";
                }
                report += ".\n";
                if (startPointSpecific == null) {
                    report += "Starting with the base image directory (Preprocess All).\n";
                } else {
                    report += "Starting with " + startPoint.getName() + " (" + startPoint.getPath() + ")\n";
                    report += "First file: " + firstFile + " Last File: " + lastFile + "\n";
                }
                report += "Scanned  " + counter.getFilesSeen() + " files.\n";
                report += "Created  " + counter.getFilesDatabased() + " new image records.\n";
                if (counter.getFilesUpdated() > 0) {
                    report += "Updated  " + counter.getFilesUpdated() + " image records.\n";

                }
                report += "Created  " + counter.getSpecimens() + " new specimen records.\n";
                if (counter.getSpecimensUpdated() > 0) {
                    report += "Updated  " + counter.getSpecimensUpdated() + " specimen records.\n";

                }
                report += "Found " + counter.getFilesFailed() + " files with problems.\n";
                //report += counter.getErrors();
                Singleton.getSingletonInstance().getMainFrame().setStatusMessage("Preprocess scan complete");
                setPercentComplete(100);
                Singleton.getSingletonInstance().getMainFrame().notifyListener(runStatus, this);
                RunnableJobReportDialog errorReportDialog = new RunnableJobReportDialog(
                        Singleton.getSingletonInstance().getMainFrame(), report, counter.getErrors(),
                        "Preprocess Results");
                errorReportDialog.setVisible(true);
                //JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), report, "Preprocess complete", JOptionPane.ERROR_MESSAGE);
            } // can read directory
        }

        SpecimenLifeCycle sls = new SpecimenLifeCycle();
        Singleton.getSingletonInstance().getMainFrame().setCount(sls.findSpecimenCount());
    } // Imagebase isn't null
    done();
}

From source file:com.xyphos.vmtgen.GUI.java

private void btnRootFolderBrowseActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnRootFolderBrowseActionPerformed
    JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int result = fc.showOpenDialog(this);
    if (JFileChooser.APPROVE_OPTION == result) {
        rootPath = fc.getSelectedFile().getAbsolutePath();
        txtRootFolder.setText(rootPath);
        preferences.put(pref_ROOT, rootPath);
        showTextureFiles();/*from ww w .ja  va2  s.co m*/
    }
}

From source file:com.simplexrepaginator.RepaginateFrame.java

protected JButton creatOutputButton() {
    JButton b = new JButton("Click or drag to set output file", PDF_1234);

    b.setHorizontalTextPosition(SwingConstants.LEFT);
    b.setIconTextGap(25);//from  w  w  w  .jav a 2  s  . c  o  m

    b.setTransferHandler(new OutputButtonTransferHandler());

    b.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(false);
            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            if (chooser.showOpenDialog(RepaginateFrame.this) != JFileChooser.APPROVE_OPTION)
                return;
            repaginator.setOutputFiles(Arrays.asList(chooser.getSelectedFiles()));
            output.setText("<html><center>" + StringUtils.join(repaginator.getOutputFiles(), "<br>"));
        }
    });

    return b;
}