Example usage for javax.swing JFileChooser APPROVE_OPTION

List of usage examples for javax.swing JFileChooser APPROVE_OPTION

Introduction

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

Prototype

int APPROVE_OPTION

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

Click Source Link

Document

Return value if approve (yes, ok) is chosen.

Usage

From source file:fusion.Fusion.java

private static void setDatasetFile1() throws IOException {

    JFileChooser dialogue = new JFileChooser(new File("."));
    File fichier;//from w w w.  j  a  v  a  2s .c  om

    if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        fichier = dialogue.getSelectedFile();
        datasetFile1 = fichier.getPath();
    }
}

From source file:de.dmarcini.submatix.pclogger.gui.ProgramProperetysDialog.java

/**
 * Das exportverzeichis auswhlen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * //from   w ww.  j a  va2  s. co m
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 28.08.2012
 */
private void chooseExportDir() {
    JFileChooser fileChooser;
    int retVal;
    //
    // Einen Dateiauswahldialog Creieren
    //
    fileChooser = new JFileChooser();
    fileChooser.setLocale(Locale.getDefault());
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setDialogTitle(fileChooserExportDirTitle);
    fileChooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    fileChooser.setApproveButtonToolTipText(approveDirButtonTooltip);
    // das existierende Verzeichnis voreinstellen
    fileChooser.setSelectedFile(SpxPcloggerProgramConfig.exportDir);
    retVal = fileChooser.showDialog(this, approveDirButtonText);
    // Mal sehen, was der User gewollt hat
    if (retVal == JFileChooser.APPROVE_OPTION) {
        // Ja, ich wollte das so
        exportDirTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
        wasChangedParameter = true;
    }
}

From source file:App.java

/**
 * Initialize the contents of the frame.
 *//*  w w w . j av  a  2  s.  co m*/
private void initialize() {

    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(1000, 750);
    frame.getContentPane().setLayout(null);

    FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png");
    fc = new JFileChooser();
    fc.setFileFilter(filter);
    frame.getContentPane().add(fc);

    stepOne = new JLabel("");
    stepOne.setToolTipText("here comes something");
    stepOne.setIcon(new ImageIcon("img/stepOne.png"));
    stepOne.setBounds(266, -4, 67, 49);
    frame.getContentPane().add(stepOne);

    btnBrowse = new JButton("Browse");
    btnBrowse.setBounds(66, 6, 117, 29);
    frame.getContentPane().add(btnBrowse);

    btnTurnWebcamOn = new JButton("Take a picture with webcam");
    btnTurnWebcamOn.setBounds(66, 34, 212, 29);
    frame.getContentPane().add(btnTurnWebcamOn);

    JButton btnTakePictureWithWebcam = new JButton("Take a picture");
    btnTakePictureWithWebcam.setBounds(430, 324, 117, 29);
    frame.getContentPane().add(btnTakePictureWithWebcam);
    btnTakePictureWithWebcam.setVisible(false);

    JButton btnCancel = new JButton("Cancel");
    btnCancel.setBounds(542, 324, 117, 29);
    frame.getContentPane().add(btnCancel);
    btnCancel.setVisible(false);

    JButton btnSaveImage = new JButton("Save image");
    btnSaveImage.setBounds(497, 357, 117, 29);
    frame.getContentPane().add(btnSaveImage);
    btnSaveImage.setVisible(false);

    urlField = new JTextField();
    urlField.setBounds(66, 67, 220, 26);
    frame.getContentPane().add(urlField);
    urlField.setColumns(10);

    originalImageLabel = new JLabel();
    originalImageLabel.setHorizontalAlignment(SwingConstants.CENTER);
    originalImageLabel.setBounds(33, 98, 300, 300);
    frame.getContentPane().add(originalImageLabel);

    stepTwo = new JLabel("");
    stepTwo.setToolTipText("here comes something else");
    stepTwo.setIcon(new ImageIcon("img/stepTwo.png"));
    stepTwo.setBounds(266, 413, 67, 49);
    frame.getContentPane().add(stepTwo);

    btnAnalyse = new JButton("Analyse image");
    btnAnalyse.setBounds(68, 423, 196, 29);
    frame.getContentPane().add(btnAnalyse);

    tagsField = new JTextArea();
    tagsField.setBounds(23, 479, 102, 89);
    tagsField.setLineWrap(true);
    tagsField.setWrapStyleWord(true);
    frame.getContentPane().add(tagsField);
    tagsField.setColumns(10);

    lblTags = new JLabel("Tags:");
    lblTags.setBounds(46, 451, 61, 16);
    frame.getContentPane().add(lblTags);

    descriptionField = new JTextArea();
    descriptionField.setLineWrap(true);
    descriptionField.setWrapStyleWord(true);
    descriptionField.setBounds(137, 479, 187, 89);
    frame.getContentPane().add(descriptionField);
    descriptionField.setColumns(10);

    lblDescription = new JLabel("Description:");
    lblDescription.setBounds(163, 451, 77, 16);
    frame.getContentPane().add(lblDescription);

    stepThree = new JLabel("");
    stepThree.setToolTipText("here comes something different");
    stepThree.setIcon(new ImageIcon("img/stepThree.png"));
    stepThree.setBounds(266, 685, 67, 49);
    frame.getContentPane().add(stepThree);

    JLabel lblImageType = new JLabel("Image type");
    lblImageType.setBounds(23, 580, 102, 16);
    frame.getContentPane().add(lblImageType);

    String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" };
    JComboBox imageTypeBox = new JComboBox(imageTypes);
    imageTypeBox.setBounds(137, 580, 187, 23);
    frame.getContentPane().add(imageTypeBox);

    JLabel lblSizeType = new JLabel("Size");
    lblSizeType.setBounds(23, 608, 102, 16);
    frame.getContentPane().add(lblSizeType);

    String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" };
    JComboBox sizeBox = new JComboBox(sizeTypes);
    sizeBox.setBounds(137, 608, 187, 23);
    frame.getContentPane().add(sizeBox);

    JLabel lblLicenseType = new JLabel("License");
    lblLicenseType.setBounds(23, 636, 102, 16);
    frame.getContentPane().add(lblLicenseType);

    String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" };
    JComboBox licenseBox = new JComboBox(licenseTypes);
    licenseBox.setBounds(137, 636, 187, 23);
    frame.getContentPane().add(licenseBox);

    JLabel lblSafeSearchType = new JLabel("Safe search");
    lblSafeSearchType.setBounds(23, 664, 102, 16);
    frame.getContentPane().add(lblSafeSearchType);

    String[] safeSearchTypes = { "Strict", "Moderate", "Off" };
    JComboBox safeSearchBox = new JComboBox(safeSearchTypes);
    safeSearchBox.setBounds(137, 664, 187, 23);
    frame.getContentPane().add(safeSearchBox);

    btnSearchForSimilar = new JButton("Search for similar images");
    btnSearchForSimilar.setVisible(true);
    btnSearchForSimilar.setBounds(66, 695, 189, 29);
    frame.getContentPane().add(btnSearchForSimilar);

    // label to try urls to display images, not shown on the main frame
    labelTryLinks = new JLabel();
    labelTryLinks.setBounds(0, 0, 100, 100);

    foundImagesLabel1 = new JLabel();
    foundImagesLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel1.setBounds(400, 49, 250, 250);
    frame.getContentPane().add(foundImagesLabel1);

    foundImagesLabel2 = new JLabel();
    foundImagesLabel2.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel2.setBounds(400, 313, 250, 250);
    frame.getContentPane().add(foundImagesLabel2);

    foundImagesLabel3 = new JLabel();
    foundImagesLabel3.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel3.setBounds(673, 49, 250, 250);
    frame.getContentPane().add(foundImagesLabel3);

    foundImagesLabel4 = new JLabel();
    foundImagesLabel4.setHorizontalAlignment(SwingConstants.CENTER);
    foundImagesLabel4.setBounds(673, 313, 250, 250);
    frame.getContentPane().add(foundImagesLabel4);

    progressBar = new JProgressBar();
    progressBar.setIndeterminate(true);
    progressBar.setStringPainted(true);
    progressBar.setBounds(440, 602, 440, 29);

    Border border = BorderFactory
            .createTitledBorder("We are checking every image, pixel by pixel, it may take a while...");
    progressBar.setBorder(border);
    frame.getContentPane().add(progressBar);
    progressBar.setVisible(false);

    btnHelp = new JButton("");
    btnHelp.setBorderPainted(false);
    ImageIcon btnIcon = new ImageIcon("img/helpRed.png");
    btnHelp.setIcon(btnIcon);
    btnHelp.setBounds(917, 4, 77, 59);
    frame.getContentPane().add(btnHelp);

    // all action listeners
    btnBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
                openFilechooser();
            }
        }
    });

    btnTurnWebcamOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            setAllFoundImagesLabelsAndPreviewsToNull();
            btnTakePictureWithWebcam.setVisible(true);
            btnCancel.setVisible(true);
            turnCameraOn();
        }
    });

    btnTakePictureWithWebcam.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            btnSaveImage.setVisible(true);
            // take a photo with web camera
            imageWebcam = webcam.getImage();
            originalImage = imageWebcam;

            // to mirror the image we create a temporary file, flip it
            // horizontally and then delete

            // get user's name to store file in the user directory
            String user = System.getProperty("user.home");
            String fileName = user + "/webCamPhoto.jpg";
            File newFile = new File(fileName);

            try {
                ImageIO.write(originalImage, "jpg", newFile);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            try {
                originalImage = (BufferedImage) ImageIO.read(newFile);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            newFile.delete();
            originalImage = mirrorImage(originalImage);
            icon = scaleBufferedImage(originalImage, originalImageLabel);
            originalImageLabel.setIcon(icon);
        }
    });

    btnSaveImage.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                try {

                    file = fc.getSelectedFile();
                    File output = new File(file.toString());
                    // check if image already exists
                    if (output.exists()) {
                        int response = JOptionPane.showConfirmDialog(null, //
                                "Do you want to replace the existing file?", //
                                "Confirm", JOptionPane.YES_NO_OPTION, //
                                JOptionPane.QUESTION_MESSAGE);
                        if (response != JOptionPane.YES_OPTION) {
                            return;
                        }
                    }
                    ImageIO.write(toBufferedImage(originalImage), "jpg", output);
                    System.out.println("Your image has been saved in the folder " + file.getPath());
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    });

    btnCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            btnTakePictureWithWebcam.setVisible(false);
            btnCancel.setVisible(false);
            btnSaveImage.setVisible(false);
            webcam.close();
            panel.setVisible(false);
        }
    });

    urlField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (urlField.getText().length() > 0) {
                String linkNew = urlField.getText();
                getImageFromHttp(linkNew, originalImageLabel);
                originalImage = imageResponses;
            }
        }
    });

    btnAnalyse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            Token computerVisionToken = new Token();
            String computerVisionTokenFileName = "APIToken.txt";

            try {
                computerVisionImageToken = computerVisionToken.getApiToken(computerVisionTokenFileName);
                try {
                    analyse();
                } catch (NullPointerException e1) {
                    // if user clicks on "analyze" button without uploading
                    // image or posts a broken link
                    JOptionPane.showMessageDialog(null, "Please choose an image");
                    e1.printStackTrace();
                }
            } catch (NullPointerException e1) {
                e1.printStackTrace();
            }
        }
    });

    btnSearchForSimilar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            // clear labels in case there were results of previous search
            setAllFoundImagesLabelsAndPreviewsToNull();

            System.out.println("==========================================");
            System.out.println("new search");
            System.out.println("==========================================");

            Token bingImageToken = new Token();
            String bingImageTokenFileName = "SearchApiToken.txt";

            bingToken = bingImageToken.getApiToken(bingImageTokenFileName);

            // in case user edited description or tags, update it and
            // replace new line character, spaces and breaks with %20
            text = descriptionField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20");
            String tagsString = tagsField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n",
                    "%20");

            imageTypeString = imageTypeBox.getSelectedItem().toString();
            sizeTypeString = sizeBox.getSelectedItem().toString();
            licenseTypeString = licenseBox.getSelectedItem().toString();
            safeSearchTypeString = safeSearchBox.getSelectedItem().toString();

            searchParameters = tagsString + text;
            System.out.println("search parameters: " + searchParameters);

            if (searchParameters.length() != 0) {

                // add new thread for searching, so that progress bar and
                // searching could run simultaneously
                Thread t1 = new Thread(new Runnable() {
                    @Override
                    public void run() {

                        progressBar.setVisible(true);
                        searchForSimilarImages(searchParameters, imageTypeString, sizeTypeString,
                                licenseTypeString, safeSearchTypeString);
                    }

                });
                // start searching for similar images in a separate thread
                t1.start();
            } else {
                JOptionPane.showMessageDialog(null,
                        "Please choose first an image to analyse or insert search parameters");
            }
        }
    });

    foundImagesLabel1.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel1.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(firstImageUrl);
                }
            }
        }
    });

    foundImagesLabel2.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel2.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(secondImageUrl);
                }
            }
        }
    });

    foundImagesLabel3.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel3.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(thirdImageUrl);
                }
            }
        }
    });

    foundImagesLabel4.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (foundImagesLabel4.getIcon() != null) {
                if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    saveFileChooser(fourthImageUrl);
                }
            }
        }
    });

    btnHelp.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // TODO write help
            HelpFrame help = new HelpFrame();
        }
    });
}

From source file:ch.zhaw.ias.dito.ui.AnalysisPanel.java

@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser fileChooser = new JFileChooser();
    Integer dimensions = (Integer) dimensionsCombo.getSelectedItem();
    double[][] mdsValues = decomp.getReducedDimensions(dimensions);
    int returnVal = fileChooser.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        Matrix m = Matrix.createDoubleMatrix(mdsValues);
        try {//from  w  ww . j  a v  a2 s  .  co  m
            Matrix.writeToFile(m, file.getAbsolutePath(), ';', 5);
        } catch (IOException ex) {
            // TODO Auto-generated catch block
            ex.printStackTrace();
        }
    }
}

From source file:bio.gcat.gui.BDATool.java

public boolean openFile() {
    JFileChooser chooser = new FileNameExtensionFileChooser(BDA_EXTENSION_FILTER);
    chooser.setDialogTitle("Open");
    if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
        return false;

    return openFile(chooser.getSelectedFile());
}

From source file:fusion.Fusion.java

private static void setDatasetFile2() throws IOException {

    JFileChooser dialogue = new JFileChooser(new File("."));
    File fichier;//ww w . j  a va  2 s.c  om

    if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        fichier = dialogue.getSelectedFile();
        datasetFile2 = fichier.getPath();
    }
}

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

/**
 * //ww  w. j  ava  2  s .c  o  m
 */
protected void loadScript() {
    if (local) {

        // open script from file system
        int showOpenDialog = loadChooser.showOpenDialog(ScriptFilterRunner.this);
        if (showOpenDialog == JFileChooser.APPROVE_OPTION) {
            File file = loadChooser.getSelectedFile();
            ConfiguredLanguage languagebyExtension = ConfiguredLanguage.getLanguagebyExtension(file.getName());
            if (languagebyExtension != null) {
                try {
                    scriptEditorTA.setText(FileUtils.readFileToString(file));
                    currentExternalScript = null;
                    languageSelector.setSelectedItem(languagebyExtension);
                } catch (IOException e) {
                    JOptionPane.showMessageDialog(ScriptFilterRunner.this, e.getMessage(),
                            "Error loading script", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(ScriptFilterRunner.this,
                        "Script language extension not configured. valid extensions are: "
                                + ConfiguredLanguage.getConfiguredExtensions(),
                        "Error loading script", JOptionPane.ERROR_MESSAGE);
            }
        }

    } else {
        selectScript(new SelectDialog<ExternalScriptTO>(ScriptFilterRunner.this,
                scriptServiceClient.getExternalScripts()));

    }

}

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

/**
 * Constructor.//ww  w.j  a  v  a 2s. c  o m
 */
GapFillingKnowledgeDBExplorerFrame(final Instances ds, final int dateIdx, final StationsDataProvider gcp)
        throws Exception {
    LogoHelper.setLogo(this);
    this.setTitle("KnowledgeDB: explorer");

    this.gcp = gcp;

    this.tablePanel = new JXPanel();
    this.tablePanel.setBorder(new TitledBorder("Cases"));

    final JXPanel highPanel = new JXPanel();
    highPanel.setLayout(new BoxLayout(highPanel, BoxLayout.X_AXIS));
    highPanel.add(this.tablePanel);

    this.geomapPanel = new JXPanel();
    this.geomapPanel.add(buildGeoMapChart(new ArrayList<String>(), new ArrayList<String>()));
    highPanel.add(this.geomapPanel);

    this.caseChartPanel = new JXPanel();
    this.caseChartPanel.setBorder(new TitledBorder("Inspected fake gap"));

    this.mostSimilarChartPanel = new JXPanel();
    this.mostSimilarChartPanel.setBorder(new TitledBorder("Most similar"));
    this.nearestChartPanel = new JXPanel();
    this.nearestChartPanel.setBorder(new TitledBorder("Nearest"));
    this.downstreamChartPanel = new JXPanel();
    this.downstreamChartPanel.setBorder(new TitledBorder("Downstream"));
    this.upstreamChartPanel = new JXPanel();
    this.upstreamChartPanel.setBorder(new TitledBorder("Upstream"));

    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
    //getContentPane().add(new JCheckBox("Use incomplete series"));
    getContentPane().add(highPanel);
    //getContentPane().add(new JXButton("Export"));      
    getContentPane().add(caseChartPanel);
    getContentPane().add(mostSimilarChartPanel);
    getContentPane().add(nearestChartPanel);
    getContentPane().add(downstreamChartPanel);
    getContentPane().add(upstreamChartPanel);

    //final Instances kdbDS=GapFillingKnowledgeDB.getKnowledgeDBWithBestCasesOnly();      
    final Instances kdbDS = GapFillingKnowledgeDB.getKnowledgeDB();

    final JXTable gapsTable = buidJXTable(kdbDS);
    final JScrollPane tableScrollPane = new JScrollPane(gapsTable);
    tableScrollPane.setPreferredSize(
            new Dimension(COMPONENT_WIDTH - 100, 40 + (int) (tableScrollPane.getPreferredSize().getHeight())));
    this.tablePanel.add(tableScrollPane);

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

                final String attrname = gapsTable.getModel().getValueAt(modelRow, 1).toString();
                final int gapsize = (int) Double
                        .valueOf(gapsTable.getModel().getValueAt(modelRow, 4).toString()).doubleValue();
                final int position = (int) Double
                        .valueOf(gapsTable.getModel().getValueAt(modelRow, 5).toString()).doubleValue();

                final String mostSimilarFlag = gapsTable.getModel().getValueAt(modelRow, 14).toString();
                final String nearestFlag = gapsTable.getModel().getValueAt(modelRow, 15).toString();
                final String downstreamFlag = gapsTable.getModel().getValueAt(modelRow, 16).toString();
                final String upstreamFlag = gapsTable.getModel().getValueAt(modelRow, 17).toString();

                final String algoname = gapsTable.getModel().getValueAt(modelRow, 12).toString();
                final boolean useDiscretizedTime = Boolean
                        .valueOf(gapsTable.getModel().getValueAt(modelRow, 13).toString());

                try {
                    geomapPanel.removeAll();

                    caseChartPanel.removeAll();

                    mostSimilarChartPanel.removeAll();
                    nearestChartPanel.removeAll();
                    downstreamChartPanel.removeAll();
                    upstreamChartPanel.removeAll();

                    final Set<String> selected = new HashSet<String>();

                    final Instances tmpds = WekaDataProcessingUtil.buildFilteredDataSet(ds, 0,
                            ds.numAttributes() - 1,
                            Math.max(0, position - GapsUtil.getCountOfValuesBeforeAndAfter(gapsize)),
                            Math.min(position + gapsize + GapsUtil.getCountOfValuesBeforeAndAfter(gapsize),
                                    ds.numInstances() - 1));

                    final List<String> attributeNames = WekaTimeSeriesUtil
                            .getNamesOfAttributesWithoutGap(tmpds);
                    //final List<String> attributeNames=WekaDataStatsUtil.getAttributeNames(ds);
                    attributeNames.remove(attrname);
                    attributeNames.remove("timestamp");

                    if (Boolean.valueOf(mostSimilarFlag)) {
                        final String mostSimilarStationName = WekaTimeSeriesSimilarityUtil
                                .findMostSimilarTimeSerie(tmpds, tmpds.attribute(attrname), attributeNames,
                                        false);
                        selected.add(mostSimilarStationName);
                        final Attribute mostSimilarStationAttr = tmpds.attribute(mostSimilarStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx,
                                mostSimilarStationAttr, gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        mostSimilarChartPanel.add(cp0);
                    }

                    if (Boolean.valueOf(nearestFlag)) {
                        final String nearestStationName = gcp.findNearestStation(attrname, attributeNames);
                        selected.add(nearestStationName);
                        final Attribute nearestStationAttr = ds.attribute(nearestStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, nearestStationAttr,
                                gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        nearestChartPanel.add(cp0);
                    }

                    if (Boolean.valueOf(downstreamFlag)) {
                        final String downstreamStationName = gcp.findDownstreamStation(attrname,
                                attributeNames);
                        selected.add(downstreamStationName);
                        final Attribute downstreamStationAttr = ds.attribute(downstreamStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, downstreamStationAttr,
                                gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        downstreamChartPanel.add(cp0);
                    }

                    if (Boolean.valueOf(upstreamFlag)) {
                        final String upstreamStationName = gcp.findUpstreamStation(attrname, attributeNames);
                        selected.add(upstreamStationName);
                        final Attribute upstreamStationAttr = ds.attribute(upstreamStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, upstreamStationAttr,
                                gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        upstreamChartPanel.add(cp0);
                    }

                    final GapFiller gapFiller = GapFillerFactory.getGapFiller(algoname, useDiscretizedTime);
                    final ChartPanel cp = GapsUIUtil.buildGapChartPanelWithCorrection(ds, dateIdx,
                            ds.attribute(attrname), gapsize, position, gapFiller, selected);
                    cp.getChart().removeLegend();
                    cp.setPreferredSize(new Dimension((int) CHART_DIMENSION.getWidth(),
                            (int) (CHART_DIMENSION.getHeight() * 1.5)));
                    caseChartPanel.add(cp);

                    geomapPanel.add(buildGeoMapChart(Arrays.asList(attrname), selected));

                    getContentPane().repaint();
                    pack();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    });

    gapsTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(final MouseEvent e) {
            if (!e.isPopupTrigger()) {
                // nothing?
            } else {
                final JPopupMenu jPopupMenu = new JPopupMenu("feur");

                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(gapsTable);
                        if (returnVal == JFileChooser.APPROVE_OPTION) {
                            try {
                                final File file = fc.getSelectedFile();
                                WekaDataAccessUtil.saveInstancesIntoCSVFile(kdbDS, file);
                            } catch (Exception ee) {
                                ee.printStackTrace();
                            }
                        }
                    }
                });
                jPopupMenu.add(mExport);

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

    setPreferredSize(new Dimension(FRAME_WIDTH, 1000));

    pack();
    setVisible(true);

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

From source file:de.interactive_instruments.ShapeChange.UI.DefaultDialog.java

public void actionPerformed(ActionEvent e) {
    if (startButton == e.getSource()) {
        mdl = mdlField.getText().trim();
        startButton.setEnabled(false);//  w ww . j  av  a 2s. c  o m
        exitButton.setEnabled(false);
        try {
            options.setParameter("inputFile", mdl);
            if (mdl.toLowerCase().endsWith(".xmi") || mdl.toLowerCase().endsWith(".xml"))
                options.setParameter("inputModelType", "XMI10");
            else if (mdl.toLowerCase().endsWith(".eap"))
                options.setParameter("inputModelType", "EA7");
            else if (mdl.toLowerCase().endsWith(".mdb"))
                options.setParameter("inputModelType", "GSIP");

            options.setParameter("outputDirectory", outField.getText());
            options.setParameter("logFile", outField.getText() + "/log.xml");
            options.setParameter("appSchemaName", asField.getText());
            options.setParameter("reportLevel", reportGroup.getSelection().getActionCommand());
            options.setParameter(Options.TargetXmlSchemaClass, "defaultEncodingRule",
                    ruleGroup.getSelection().getActionCommand());
            if (docCB.isSelected())
                options.setParameter(Options.TargetXmlSchemaClass, "includeDocumentation", "true");
            else
                options.setParameter(Options.TargetXmlSchemaClass, "includeDocumentation", "false");
            if (!visCB.isSelected())
                options.setParameter("publicOnly", "true");
            else
                options.setParameter("publicOnly", "false");

            converter.convert();
        } catch (ShapeChangeAbortException ex) {
            Toolkit.getDefaultToolkit().beep();
        }
        logfile = new File(options.parameter("logFile").replace(".xml", ".html"));
        if (logfile != null && logfile.canRead())
            logButton.setEnabled(true);
        else {
            logfile = new File(options.parameter("logFile"));
            if (logfile != null && logfile.canRead())
                logButton.setEnabled(true);
        }
        exitButton.setEnabled(true);
    } else if (e.getSource() == logButton) {
        try {
            if (Desktop.isDesktopSupported())
                Desktop.getDesktop().open(logfile);
            else if (SystemUtils.IS_OS_WINDOWS)
                Runtime.getRuntime().exec("cmd /c start " + logfile.getPath());
            else
                Runtime.getRuntime().exec("open " + logfile.getPath());
        } catch (IOException e1) {
            e1.printStackTrace();
            System.exit(1);
        }
    } else if (e.getSource() == exitButton) {
        System.exit(0);
    } else if (e.getSource() == mdlButton) {
        int returnVal = fc.showOpenDialog(DefaultDialog.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            mdlField.setText(file.getAbsolutePath());
        }
    } else if (e.getSource() == cfgButton) {
        int returnVal = fc.showOpenDialog(DefaultDialog.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            cfgField.setText(file.getAbsolutePath());
        }
    } else if (e.getSource() == outButton) {
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showOpenDialog(DefaultDialog.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            outField.setText(file.getAbsolutePath());
        }
    }
}

From source file:com.philips.cn.hr.pps.App.java

private File chooseFile(FileNameExtensionFilter filter, int selectionMode) {

    if (filter != null) {
        fc.setFileFilter(filter);//  w w  w.jav a 2s.  co m
    }

    fc.setFileSelectionMode(selectionMode);

    if (this.perferredDir != null) {
        fc.setSelectedFile(new File(this.perferredDir));
    }

    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {

        File file = fc.getSelectedFile();
        this.perferredDir = file.getAbsolutePath();
        return file;
    }

    return null;

}