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:eu.apenet.dpt.standalone.gui.XsltAdderActionListener.java

public void actionPerformed(ActionEvent e) {
    JFileChooser xsltChooser = new JFileChooser();
    xsltChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    if (xsltChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
        File file = xsltChooser.getSelectedFile();
        if (isXSLT(file)) {
            if (saveXslt(file)) {
                JRadioButton newButton = new JRadioButton(file.getName());
                newButton.addActionListener(new XsltSelectorListener(dataPreparationToolGUI));
                dataPreparationToolGUI.getGroupXslt().add(newButton);
                dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsltPanel(newButton);
                dataPreparationToolGUI.getAPEPanel().getApeTabbedPane()
                        .addToXsltPanel(Box.createRigidArea(new Dimension(0, 10)));
                JOptionPane.showMessageDialog(parent, labels.getString("xsltSaved") + ".",
                        labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon);
            } else {
                JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".",
                        labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon);
            }//from ww  w.  j  av a2 s.c  om
        } else {
            JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".",
                    labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon);
        }
    }
}

From source file:ImageViewer.java

public ImageViewerFrame() {
    setTitle("ImageViewer");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // use a label to display the images
    label = new JLabel();
    add(label);//from  w  w w.  j a  v  a2s.  co m

    // set up the file chooser
    chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));

    // set up the menu bar
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu menu = new JMenu("File");
    menuBar.add(menu);

    JMenuItem openItem = new JMenuItem("Open");
    menu.add(openItem);
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            // show file chooser dialog
            int result = chooser.showOpenDialog(null);

            // if file selected, set it as icon of the label
            if (result == JFileChooser.APPROVE_OPTION) {
                String name = chooser.getSelectedFile().getPath();
                label.setIcon(new ImageIcon(name));
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
}

From source file:net.mitnet.tools.pdf.book.publisher.ui.gui.BaseBookPublisherGUI.java

protected void browseDir(JTextField dirField) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = fileChooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        String selectedFilePath = selectedFile.getAbsolutePath();
        dirField.setText(selectedFilePath);
    }/*from w ww  .j a v  a  2s  .c  o  m*/
}

From source file:com.devbury.mkremote.server.QuickLaunchServiceImpl.java

public ArrayList<LaunchItem> list(String dir) {
    Base64 base64 = new Base64();
    JFileChooser chooser = new JFileChooser();
    File new_dir = newFileDir(dir);
    logger.debug("Looking for files in {}", new_dir.getAbsolutePath());
    ArrayList<LaunchItem> items = new ArrayList<LaunchItem>();
    if (isSupported()) {
        if (new_dir.isDirectory()) {
            FilenameFilter filter = new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return !name.startsWith(".");
                }/*from   ww  w .  ja  va 2  s  . c o  m*/
            };
            for (File f : new_dir.listFiles(filter)) {
                if (!f.isHidden()) {
                    LaunchItem item = new LaunchItem();
                    item.setName(f.getName());
                    item.setPath(dir);
                    if (f.isDirectory()) {
                        if (isMac() && f.getName().endsWith(".app")) {
                            item.setType(LaunchItem.FILE_TYPE);
                            item.setName(f.getName().substring(0, f.getName().length() - 4));
                        } else {
                            item.setType(LaunchItem.DIR_TYPE);
                        }
                    } else {
                        item.setType(LaunchItem.FILE_TYPE);
                    }
                    Icon icon = chooser.getIcon(f);
                    BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
                            BufferedImage.TYPE_INT_RGB);
                    icon.paintIcon(null, bi.createGraphics(), 0, 0);
                    ByteArrayOutputStream os = new ByteArrayOutputStream();
                    try {
                        ImageIO.write(bi, "png", os);
                        item.setIcon(base64.encodeToString(os.toByteArray()));
                    } catch (IOException e) {
                        logger.debug("could not write image {}", e);
                        item.setIcon(null);
                    }
                    logger.debug("Adding LaunchItem : {}", item);
                    items.add(item);
                } else {
                    logger.debug("Skipping hidden file {}", f.getName());
                }
            }
        }
    } else {
        new Thread() {
            @Override
            public void run() {
                JOptionPane.showMessageDialog(null,
                        "We are sorry but quick launch is not supported on your platform",
                        "Quick Launch Not Supported", JOptionPane.ERROR_MESSAGE);
            }
        }.start();
    }
    return items;
}

From source file:com.swg.parse.docx.OpenWord.java

@Override
public void actionPerformed(ActionEvent e) {

    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File("C:/"));
    fc.setAcceptAllFileFilterUsed(false);
    //this authorize only .docx selection
    fc.addChoosableFileFilter(new DocxFileFilter());
    if (selectedFile != null) {
        fc.setSelectedFile(selectedFile);
    }/*from w w w.  j  av a 2s.  co  m*/
    int returnVal = fc.showDialog(WindowManager.getDefault().getMainWindow(), "Extract Data");

    if (returnVal == JFileChooser.APPROVE_OPTION) {

        File file = fc.getSelectedFile();
        selectedFile = file;

        pathToTxtFile = selectedFile.getAbsolutePath().replace(".docx", ".txt");
        TxtFile = new File(pathToTxtFile);

        String zipFilePath = "C:\\Users\\KXK3\\Documents\\ZipTest\\test.zip";
        String destDirectory = "C:\\Users\\KXK3\\Documents\\ZipTest\\temp";
        UnzipUtility unzipper = new UnzipUtility();
        try {
            File zip = new File(zipFilePath);
            File directory = new File(destDirectory);
            FileUtils.copyFile(selectedFile, zip);
            unzipper.UnzipUtility(zip, directory);

            String mediaPath = destDirectory + "/word/media/";
            File mediaDir = new File(mediaPath);

            for (File fil : mediaDir.listFiles()) {
                FileUtils.copyFile(fil,
                        new File("C:\\Users\\KXK3\\Documents\\ZipTest\\Pictures\\" + fil.getName()));
            }

            zip.delete();
            FileUtils.deleteDirectory(directory);

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        //if the txt file doesn't exist, it tries to convert whatever 
        //can be the txt into the actual txt.
        if (!TxtFile.exists()) {
            pathToTxtFile = selectedFile.getAbsolutePath().replace(".docx", "");
            TxtFile = new File(pathToTxtFile);
            pathToTxtFile += ".txt";
            TxtFile.renameTo(new File(pathToTxtFile));
            TxtFile = new File(pathToTxtFile);
        }

        String content;
        String POIContent;

        try {
            content = readTxtFile();
            version = DetermineVersion(content);
            NewExtract ext = new NewExtract();
            ext.extract(content, selectedFile.getAbsolutePath(), version, 1);

        } catch (FileNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        } catch (ParseException ex) {
            Exceptions.printStackTrace(ex);
        }

    } else {
        //do nothing
    }

}

From source file:com.itd.dbmrgdao.TestTime3_backup.java

@Ignore
@org.junit.Test//from   www  . j a  v a2  s. c om
public void test() throws ParseException {
    String newTab = "\t";
    String[] sysidLine;

    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Text File", "txt");
    chooser.setFileFilter(filter);
    chooser.showOpenDialog(null);
    File f = chooser.getSelectedFile();

    String filename = f.getAbsolutePath();
    try {
        FileReader reader = new FileReader(filename);
        BufferedReader br = new BufferedReader(reader);
        String strLine;

        String sysid = null, p1Start = null, p1End = null, p2Start = null, p2End = null, otStart = null,
                otEnd = null;
        Date scdate = null;

        // read from select file
        while ((strLine = br.readLine()) != null) {
            String[] parts = strLine.split(" ");

            // check if not first record or sysid change will save in table scandata 
            if (sysid != null && !sysid.equals(parts[0])) {
                // rule if whatever employee register will get standard hour 8 hrs
                if (p1Start != null || p2End != null) {
                    ScanRule scanRule = scanDao.findScanRuleBySysId(sysid);
                    p1Start = scanRule.getP1start();
                    p2End = scanRule.getP2end();
                }

                // set up data in entity
                ScanDataKey scanDataKey = new ScanDataKey(sysid, scdate);
                ScanData scanData = new ScanData(scanDataKey, "1985", p1Start, p1End, p2Start, p2End, otStart,
                        otEnd);
                // remove old record (key is sysid and scdate)
                gennericDao.remove(scanData);
                gennericDao.create(scanData);

                //clear 
                p1Start = null;
                p1End = null;
                p2Start = null;
                p2End = null;
                otStart = null;
                otEnd = null;

            }

            sysid = parts[0];
            scdate = new SimpleDateFormat("yyyyMMdd", Locale.US).parse(parts[1]);

            if (parts[6].equals("01")) {
                p1Start = CompareTime(p1Start, parts[5], "01");
            } else {
                p2End = CompareTime(p2End, parts[5], "04");
            }

        }
        //last line

        if (p1Start != null || p2End != null) {
            ScanRule scanRule = scanDao.findScanRuleBySysId(sysid);
            p1Start = scanRule.getP1start();
            p2End = scanRule.getP2end();
        }

        ScanDataKey scanDataKey = new ScanDataKey(sysid, scdate);
        ScanData scanData = new ScanData(scanDataKey, "1985", p1Start, p1End, p2Start, p2End, otStart, otEnd);
        gennericDao.remove(scanData);
        gennericDao.create(scanData);

        br.close();

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

}

From source file:com.bright.json.PGS.java

public static void main(String[] args) throws FileNotFoundException {

    String fileBasename = null;//from  www.ja v  a 2 s . c  om

    JFileChooser chooser = new JFileChooser();
    try {
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel Spreadsheets", "xls", "xlsx");
        chooser.setFileFilter(filter);
        chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home")));
        chooser.setDialogTitle("Select the Excel file");

        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
            System.out.println("getSelectedFile() : " + chooser.getSelectedFile());

            // String fileBasename =
            // chooser.getSelectedFile().toString().substring(chooser.getSelectedFile().toString().lastIndexOf(File.separator)+1,chooser.getSelectedFile().toString().lastIndexOf("."));
            fileBasename = chooser.getSelectedFile().toString()
                    .substring(chooser.getSelectedFile().toString().lastIndexOf(File.separator) + 1);
            System.out.println("Base name: " + fileBasename);

        } else {
            System.out.println("No Selection ");

        }
    } catch (Exception e) {

        System.out.println(e.toString());

    }
    String fileName = chooser.getSelectedFile().toString();
    InputStream inp = new FileInputStream(fileName);
    Workbook workbook = null;
    if (fileName.toLowerCase().endsWith("xlsx")) {
        try {
            workbook = new XSSFWorkbook(inp);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if (fileName.toLowerCase().endsWith("xls")) {
        try {
            workbook = new HSSFWorkbook(inp);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    Sheet nodeSheet = workbook.getSheet("Devices");
    Sheet interfaceSheet = workbook.getSheet("Interfaces");
    System.out.println("Read nodes sheet.");
    // Row nodeRow = nodeSheet.getRow(1);
    // System.out.println(row.getCell(0).toString());
    // System.exit(0);

    JTextField uiHost = new JTextField("demo.brightcomputing.com");
    // TextPrompt puiHost = new
    // TextPrompt("demo.brightcomputing.com",uiHost);
    JTextField uiUser = new JTextField("root");
    // TextPrompt puiUser = new TextPrompt("root", uiUser);
    JTextField uiPass = new JPasswordField("");
    // TextPrompt puiPass = new TextPrompt("x5deix5dei", uiPass);

    JPanel myPanel = new JPanel(new GridLayout(5, 1));
    myPanel.add(new JLabel("Bright HeadNode hostname:"));
    myPanel.add(uiHost);
    // myPanel.add(Box.createHorizontalStrut(1)); // a spacer
    myPanel.add(new JLabel("Username:"));
    myPanel.add(uiUser);
    myPanel.add(new JLabel("Password:"));
    myPanel.add(uiPass);

    int result = JOptionPane.showConfirmDialog(null, myPanel, "Please fill in all the fields.",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.OK_OPTION) {
        System.out.println("Input received.");

    }

    String rhost = uiHost.getText();
    String ruser = uiUser.getText();
    String rpass = uiPass.getText();

    String cmURL = "https://" + rhost + ":8081/json";
    List<Cookie> cookies = doLogin(ruser, rpass, cmURL);
    chkVersion(cmURL, cookies);

    Map<String, Long> categories = UniqueKeyMap(cmURL, "cmdevice", "getCategories", cookies);
    Map<String, Long> networks = UniqueKeyMap(cmURL, "cmnet", "getNetworks", cookies);
    Map<String, Long> partitions = UniqueKeyMap(cmURL, "cmpart", "getPartitions", cookies);
    Map<String, Long> racks = UniqueKeyMap(cmURL, "cmpart", "getRacks", cookies);
    Map<String, Long> switches = UniqueKeyMap(cmURL, "cmdevice", "getEthernetSwitches", cookies);
    // System.out.println(switches.get("switch01"));
    // System.out.println("Size of the map: "+ switches.size());
    // System.exit(0);
    cmDevice newnode = new cmDevice();
    cmDevice.deviceObject devObj = new cmDevice.deviceObject();
    cmDevice.switchObject switchObj = new cmDevice.switchObject();
    // cmDevice.netObject netObj = new cmDevice.netObject();

    List<String> emptyslist = new ArrayList<String>();

    // Row nodeRow = nodeSheet.getRow(1);
    // Row ifRow = interfaceSheet.getRow(1);
    // System.out.println(nodeRow.getCell(0).toString());
    // nodeRow.getCell(3).getStringCellValue()
    Map<String, ArrayList<cmDevice.netObject>> ifmap = new HashMap<String, ArrayList<cmDevice.netObject>>();
    // Map<String,netObject> helperMap = new HashMap<String,netObject>();
    // Iterator<Row> rows = interfaceSheet.rowIterator ();
    // while (rows. < interfaceSheet.getPhysicalNumberOfRows()) {

    // List<netObject> netList = new ArrayList<netObject>();
    for (int i = 0; i < interfaceSheet.getPhysicalNumberOfRows(); i++) {
        Row ifRow = interfaceSheet.getRow(i);
        if (ifRow.getRowNum() == 0) {
            continue; // just skip the rows if row number is 0
        }

        System.out.println("Row nr: " + ifRow.getRowNum());
        cmDevice.netObject netObj = new cmDevice.netObject();
        ArrayList<cmDevice.netObject> helperList = new ArrayList<cmDevice.netObject>();
        netObj.setBaseType("NetworkInterface");
        netObj.setCardType(ifRow.getCell(3).getStringCellValue());
        netObj.setChildType(ifRow.getCell(4).getStringCellValue());
        netObj.setDhcp((ifRow.getCell(5).getNumericCellValue() > 0.1) ? true : false);
        netObj.setIp(ifRow.getCell(7).getStringCellValue());
        // netObj.setMac(ifRow.getCell(0).toString());
        //netObj.setModified(true);
        netObj.setName(ifRow.getCell(1).getStringCellValue());
        netObj.setNetwork(networks.get(ifRow.getCell(6).getStringCellValue()));
        //netObj.setOldLocalUniqueKey(0L);
        netObj.setRevision("");
        netObj.setSpeed(ifRow.getCell(8, Row.CREATE_NULL_AS_BLANK).getStringCellValue());
        netObj.setStartIf("ALWAYS");
        netObj.setToBeRemoved(false);
        netObj.setUniqueKey((long) ifRow.getCell(2).getNumericCellValue());
        //netObj.setAdditionalHostnames(new ArrayList<String>(Arrays.asList(ifRow.getCell(9, Row.CREATE_NULL_AS_BLANK).getStringCellValue().split("\\s*,\\s*"))));
        //netObj.setMac(ifRow.getCell(10, Row.CREATE_NULL_AS_BLANK).getStringCellValue());
        netObj.setMode((int) ifRow.getCell(11, Row.CREATE_NULL_AS_BLANK).getNumericCellValue());
        netObj.setOptions(ifRow.getCell(12, Row.CREATE_NULL_AS_BLANK).getStringCellValue());
        netObj.setMembers(new ArrayList<String>(Arrays
                .asList(ifRow.getCell(13, Row.CREATE_NULL_AS_BLANK).getStringCellValue().split("\\s*,\\s*"))));
        // ifmap.put(ifRow.getCell(0).getStringCellValue(), new
        // HashMap<String, cmDevice.netObject>());
        // helperMap.put(ifRow.getCell(1).getStringCellValue(), netObj) ;
        // ifmap.get(ifRow.getCell(0).getStringCellValue()).putIfAbsent(ifRow.getCell(1).getStringCellValue(),
        // netObj);
        // ifmap.put(ifRow.getCell(0).getStringCellValue(), helperMap);

        if (!ifmap.containsKey(ifRow.getCell(0).getStringCellValue())) {
            ifmap.put(ifRow.getCell(0).getStringCellValue(), new ArrayList<cmDevice.netObject>());
        }
        helperList = ifmap.get(ifRow.getCell(0).getStringCellValue());
        helperList.add(netObj);
        ifmap.put(ifRow.getCell(0).getStringCellValue(), helperList);

        continue;
    }

    for (int i = 0; i < nodeSheet.getPhysicalNumberOfRows(); i++) {
        Row nodeRow = nodeSheet.getRow(i);
        if (nodeRow.getRowNum() == 0) {
            continue; // just skip the rows if row number is 0
        }

        newnode.setService("cmdevice");
        newnode.setCall("addDevice");

        Map<String, Long> ifmap2 = new HashMap<String, Long>();
        for (cmDevice.netObject j : ifmap.get(nodeRow.getCell(0).getStringCellValue()))
            ifmap2.put(j.getName(), j.getUniqueKey());

        switchObj.setEthernetSwitch(switches.get(nodeRow.getCell(8).getStringCellValue()));
        System.out.println(nodeRow.getCell(8).getStringCellValue());
        System.out.println(switches.get(nodeRow.getCell(8).getStringCellValue()));
        switchObj.setPrt((int) nodeRow.getCell(9).getNumericCellValue());
        switchObj.setBaseType("SwitchPort");

        devObj.setBaseType("Device");
        // devObj.setCreationTime(0L);
        devObj.setCustomPingScript("");
        devObj.setCustomPingScriptArgument("");
        devObj.setCustomPowerScript("");
        devObj.setCustomPowerScriptArgument("");
        devObj.setCustomRemoteConsoleScript("");
        devObj.setCustomRemoteConsoleScriptArgument("");
        devObj.setDisksetup("");
        devObj.setBmcPowerResetDelay(0L);
        devObj.setBurning(false);
        devObj.setEthernetSwitch(switchObj);
        devObj.setExcludeListFull("");
        devObj.setExcludeListGrab("");
        devObj.setExcludeListGrabnew("");
        devObj.setExcludeListManipulateScript("");
        devObj.setExcludeListSync("");
        devObj.setExcludeListUpdate("");
        devObj.setFinalize("");
        devObj.setRack(racks.get(nodeRow.getCell(10).getStringCellValue()));
        devObj.setRackHeight((long) nodeRow.getCell(11).getNumericCellValue());
        devObj.setRackPosition((long) nodeRow.getCell(12).getNumericCellValue());
        devObj.setIndexInsideContainer(0L);
        devObj.setInitialize("");
        devObj.setInstallBootRecord(false);
        devObj.setInstallMode("");
        devObj.setIoScheduler("");
        devObj.setLastProvisioningNode(0L);
        devObj.setMac(nodeRow.getCell(6).getStringCellValue());

        devObj.setModified(true);
        devObj.setCategory(categories.get(nodeRow.getCell(1).getStringCellValue()));
        devObj.setChildType("PhysicalNode");
        //devObj.setDatanode((nodeRow.getCell(5).getNumericCellValue() > 0.1) ? true
        //      : false);
        devObj.setHostname(nodeRow.getCell(0).getStringCellValue());
        devObj.setModified(true);
        devObj.setPartition(partitions.get(nodeRow.getCell(2).getStringCellValue()));
        devObj.setUseExclusivelyFor("Category");

        devObj.setNextBootInstallMode("");
        devObj.setNotes("");
        devObj.setOldLocalUniqueKey(0L);

        devObj.setPowerControl(nodeRow.getCell(7).getStringCellValue());

        // System.out.println(ifmap.get("excelnode001").size());
        // System.out.println(ifmap.get(nodeRow.getCell(0).getStringCellValue()).get(nodeRow.getCell(3).getStringCellValue()).getUniqueKey());

        devObj.setManagementNetwork(networks.get(nodeRow.getCell(3).getStringCellValue()));

        devObj.setProvisioningNetwork(ifmap2.get(nodeRow.getCell(4).getStringCellValue()));
        devObj.setProvisioningTransport("RSYNCDAEMON");
        devObj.setPxelabel("");
        // "rack": 90194313218,
        // "rackHeight": 1,
        // "rackPosition": 4,
        devObj.setRaidconf("");
        devObj.setRevision("");

        devObj.setSoftwareImageProxy(null);
        devObj.setStartNewBurn(false);

        devObj.setTag("00000000a000");
        devObj.setToBeRemoved(false);
        // devObj.setUcsInfoConfigured(null);
        // devObj.setUniqueKey(12345L);

        devObj.setUserdefined1("");
        devObj.setUserdefined2("");

        ArrayList<Object> mylist = new ArrayList<Object>();

        ArrayList<cmDevice.netObject> mylist2 = new ArrayList<cmDevice.netObject>();
        ArrayList<Object> emptylist = new ArrayList<Object>();

        devObj.setFsexports(emptylist);
        devObj.setFsmounts(emptylist);
        devObj.setGpuSettings(emptylist);
        devObj.setFspartAssociations(emptylist);

        devObj.setPowerDistributionUnits(emptyslist);

        devObj.setRoles(emptylist);
        devObj.setServices(emptylist);
        devObj.setStaticRoutes(emptylist);

        mylist2 = ifmap.get(nodeRow.getCell(0).getStringCellValue());

        devObj.setNetworks(mylist2);
        mylist.add(devObj);
        mylist.add(1);
        newnode.setArgs(mylist);

        GsonBuilder builder = new GsonBuilder();
        builder.enableComplexMapKeySerialization();

        // Gson g = new Gson();
        Gson g = builder.create();

        String json2 = g.toJson(newnode);

        // To be used from a real console and not Eclipse

        String message = JSonRequestor.doRequest(json2, cmURL, cookies);
        continue;
    }

    JOptionPane optionPaneF = new JOptionPane("The nodes have been added!");
    JDialog myDialogF = optionPaneF.createDialog(null, "Complete:  ");
    myDialogF.setModal(false);
    myDialogF.setVisible(true);
    doLogout(cmURL, cookies);
    // System.exit(0);
}

From source file:cloud.gui.DistributionSelectionActionListener.java

@SuppressWarnings("static-access")
@Override/*from   w  w w. ja  v a2s  . co  m*/
public void actionPerformed(ActionEvent e) {
    String name = (String) gui.getDistributions().getSelectedItem();
    if (DistributionName.EXPONENTIAL.getName().equals(name)) {
        gui.decorateExponentialDistribution();
    } else if (DistributionName.UNIFORM.getName().equals(name)) {
        gui.decorateForUniformDistribution();
    } else if (DistributionName.CONSTANT.getName().equals(name)) {
        gui.decorateForConstantDistribution();
    } else if (DistributionName.CUSTOM.getName().equals(name)) {
        JFileChooser fileChooser = new JFileChooser();
        int returnVal = fileChooser.showOpenDialog(gui);
        if (returnVal == fileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();
            try {
                List<String> lines = FileUtils.readLines(file);
                boolean result = validate(lines);
                if (!result) {
                    gui.decorateForInValidDistribution();
                    logger.error("Invalid Distribution file " + file.getName());
                } else {
                    gui.decorateForCustomDistribution(lines);
                    logger.info("File " + file.getName() + " is imported to generate the distribution from");
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        } else {
            gui.getDistributions().setSelectedIndex(0);
            gui.decorateForUniformDistribution();
        }
    }
}

From source file:edu.smc.mediacommons.panels.SecurityPanel.java

public SecurityPanel() {
    setLayout(null);/*from  w w  w  . j ava 2 s . co  m*/

    FILE_CHOOSER = new JFileChooser();

    JButton openFile = Utils.createButton("Open File", 10, 20, 100, 30, null);
    add(openFile);

    JButton saveFile = Utils.createButton("Save File", 110, 20, 100, 30, null);
    add(saveFile);

    JButton decrypt = Utils.createButton("Decrypt", 210, 20, 100, 30, null);
    add(decrypt);

    JButton encrypt = Utils.createButton("Encrypt", 310, 20, 100, 30, null);
    add(encrypt);

    JTextField path = Utils.createTextField(10, 30, 300, 20);
    path.setText("No file selected");

    final JTextArea viewer = new JTextArea();
    JScrollPane pastePane = new JScrollPane(viewer);
    pastePane.setBounds(15, 60, 400, 200);
    add(pastePane);

    openFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (FILE_CHOOSER.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) {
                File toRead = FILE_CHOOSER.getSelectedFile();

                if (toRead == null) {
                    JOptionPane.showMessageDialog(getParent(), "The input file does not exist!",
                            "Opening Failed...", JOptionPane.WARNING_MESSAGE);
                } else {
                    try {
                        List<String> lines = IOUtils.readLines(new FileInputStream(toRead), "UTF-8");

                        viewer.setText("");

                        for (String line : lines) {
                            viewer.append(line);
                        }
                    } catch (IOException ex) {

                    }
                }
            }
        }
    });

    saveFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (FILE_CHOOSER.showSaveDialog(getParent()) == JFileChooser.APPROVE_OPTION) {
                File toWrite = FILE_CHOOSER.getSelectedFile();

                Utils.writeToFile(viewer.getText(), toWrite);
                JOptionPane.showMessageDialog(getParent(),
                        "The file has now been saved to\n" + toWrite.getPath());
            }
        }
    });

    encrypt.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String password = Utils.getPasswordInput(getParent());

            if (password != null) {
                try {
                    BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
                    basicTextEncryptor.setPassword(password);

                    String text = basicTextEncryptor.encrypt(viewer.getText());
                    viewer.setText(text);
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(getParent(),
                            "Could not encrypt the text, an unexpected error occurred.", "Encryption Failed...",
                            JOptionPane.WARNING_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(getParent(),
                        "Could not encrypt the text, as no\npassword has been specified.",
                        "Encryption Failed...", JOptionPane.WARNING_MESSAGE);
            }
        }
    });

    decrypt.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String password = Utils.getPasswordInput(getParent());

            if (password != null) {
                try {
                    BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
                    basicTextEncryptor.setPassword(password);

                    String text = basicTextEncryptor.decrypt(viewer.getText());
                    viewer.setText(text);
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(getParent(),
                            "Could not decrypt the text, an unexpected error occurred.", "Decryption Failed...",
                            JOptionPane.WARNING_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(getParent(),
                        "Could not decrypt the text, as no\npassword has been specified.",
                        "Decryption Failed...", JOptionPane.WARNING_MESSAGE);
            }
        }
    });
}

From source file:com.dieterholvoet.scoutsapp.util.CSVParser.java

public CSVParser(WerkstukGUI WerkstukGUI) {
    this.parent = WerkstukGUI;
    this.c = new ColumnHolder();

    this.filter = new FileNameExtensionFilter("CSV Files", "csv");
    this.chooser = new JFileChooser();
    this.chooser.setFileFilter(this.filter);
}