Example usage for javax.swing.filechooser FileSystemView getSystemDisplayName

List of usage examples for javax.swing.filechooser FileSystemView getSystemDisplayName

Introduction

In this page you can find the example usage for javax.swing.filechooser FileSystemView getSystemDisplayName.

Prototype

public String getSystemDisplayName(File f) 

Source Link

Document

Name of a file, directory, or folder as it would be displayed in a system file browser.

Usage

From source file:mendeley2kindle.MainUIFrame.java

private File guessKindleRoot() {
    String os = System.getProperty("os.name");
    if (os.indexOf("Windows") >= 0) {
        FileSystemView fs = FileSystemView.getFileSystemView();
        Pattern pat = Pattern.compile("^Kindle \\(\\w:\\)$");
        for (File f : File.listRoots()) {
            String name = fs.getSystemDisplayName(f);
            if (pat.matcher(name).matches()) {
                return f;
            }/*w ww.  jav  a 2 s. c om*/
        }
    } else if (os.indexOf("Linux") >= 0) {
        File f = new File("/media/");
        return f.isDirectory() ? f : null;
    } else if (os.indexOf("Mac") >= 0) {
        File f = new File("/Volumes/Kindle/");
        return f.isDirectory() ? f : new File("/Volumes/");
    }
    return null;
}

From source file:base.BasePlayer.Main.java

public void openPleiades(String pleiadesurl) {
    boolean bamonly = false;
    String pleiades = pleiadesurl.trim();
    if (pleiades.toLowerCase().startsWith("bam")) {
        bamonly = true;/*from ww  w.  ja  v a2 s . c o m*/
        pleiades = pleiades.replace("bam", "").trim();
    }

    if (pleiades.contains("`")) {
        pleiades.replace("`", "?");
    }
    if (pleiades.contains(" ")) {
        pleiades.replace(" ", "%20");
    }
    if (pleiades.contains("pleiades")) {
        try {
            URL url = new URL(pleiadesurl.trim());
            //System.out.println(Main.chooserText);
            HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
            httpConn.connect();

            int responseCode = httpConn.getResponseCode();

            if (responseCode == HttpsURLConnection.HTTP_OK) {

                String loading = drawCanvas.loadingtext;
                InputStream inputStream = httpConn.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                Main.drawCanvas.loadingtext = loading + " 0MB";
                String line;
                StringBuffer buffer = new StringBuffer("");
                while ((line = reader.readLine()) != null) {

                    buffer.append(line);

                }
                inputStream.close();
                reader.close();
                String split2;
                String[] split = buffer.toString().split("dataUnit");
                String location;
                ArrayList<File> array = new ArrayList<File>();
                File[] paths;
                FileSystemView fsv = FileSystemView.getFileSystemView();
                paths = File.listRoots();
                String loc = "/mnt";
                boolean missingfiles = false;
                for (File path : paths) {
                    if (fsv.getSystemDisplayName(path).contains("merit")) {
                        loc = path.getCanonicalPath();
                    }
                }

                for (int i = 0; i < split.length; i++) {

                    if (!split[i].contains("lastLocation")) {

                        continue;
                    }

                    split2 = split[i].split("\"lastLocation\":\"")[1];
                    location = split2.substring(0, split2.indexOf("\"}"));
                    String filename = "";
                    String testloc = location.replace("/mnt", loc) + "/wgspipeline/";
                    File testDir = new File(testloc);
                    if (testDir.exists() && testDir.isDirectory()) {
                        if (bamonly) {
                            File[] addDir = testDir.listFiles(new FilenameFilter() {
                                public boolean accept(File dir, String name) {
                                    return name.toLowerCase().endsWith(".bam")
                                            || name.toLowerCase().endsWith(".cram");
                                }
                            });
                            if (addDir.length > 0) {
                                filename = addDir[0].getName();
                            }
                        } else {
                            File[] addDir = testDir.listFiles(new FilenameFilter() {
                                public boolean accept(File dir, String name) {
                                    return name.toLowerCase().endsWith(".vcf.gz");
                                }
                            });
                            if (addDir.length > 0) {
                                filename = addDir[0].getName();
                            }
                        }
                    }

                    location = testloc + "/" + filename;

                    if (!new File(location).exists()) {

                        if (!new File(location).exists()) {
                            missingfiles = true;
                            ErrorLog.addError("No sample files found in " + testloc);

                        } else {
                            array.add(new File(location));
                        }
                    } else {

                        array.add(new File(location));
                    }
                }

                File[] files = new File[array.size()];
                for (int i = 0; i < files.length; i++) {

                    files[i] = array.get(i);
                }
                FileRead filereader = new FileRead(files);
                filereader.start = (int) drawCanvas.selectedSplit.start;
                filereader.end = (int) drawCanvas.selectedSplit.end;
                if (bamonly) {
                    filereader.readBAM = true;
                } else {
                    filereader.readVCF = true;
                }
                filereader.execute();
                if (missingfiles) {
                    JOptionPane.showMessageDialog(Main.drawScroll, "Missing files. Check Tools->View log",
                            "Note", JOptionPane.INFORMATION_MESSAGE);
                }

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

    return;

}

From source file:base.BasePlayer.Main.java

public Main() {

    super(new GridBagLayout());
    try {/*from   w ww  . j  av a2  s  .co m*/

        //UIManager.put("PopupMenu.border", BorderFactory.createMatteBorder(0, 20, 0, 0, new Color(230,230,230)));
        //URL fontUrl = new URL("http://www.webpagepublicity.com/" +
        //       "free-fonts/a/Airacobra%20Condensed.ttf");
        //      URL fontUrl = new URL("C:/HY-Data/RKATAINE/WinPython-64bit-3.5.3.1Qt5/python-3.5.3.amd64/share/numdifftools/docs/_build/html/_static/fonts/Inconsolata-Regular.ttf");
        //   URL fonturl = this.getClass().getResource("OpenSans-Regular.ttf");
        //   menuFont = Font.createFont(Font.TRUETYPE_FONT, new File(fonturl.getFile()));
        //   C:\HY-Data\RKATAINE\WinPython-64bit-3.5.3.1Qt5\python-3.5.3.amd64\Lib\site-packages\reportlab\fonts
        Launcher.fromMain = true;
        Launcher.main(args);
        VariantHandler.main(argsit);
        glass = Toolkit.getDefaultToolkit().getImage(getClass().getResource("icons/glass.jpg"));
        ToolTipManager.sharedInstance().setInitialDelay(100);
        // ToolTipManager.sharedInstance().setDismissDelay(2000);
        UIManager.put("ToolTip.background", new Color(255, 255, 214));
        UIManager.put("ToolTip.border", BorderFactory.createCompoundBorder(
                UIManager.getBorder("ToolTip.border"), BorderFactory.createEmptyBorder(4, 4, 4, 4)));
        lineseparator = System.getProperty("line.separator");

        proxysettings = new ProxySettings();
        panel = new JPanel(new GridBagLayout());
        //menuFont = menuFont.deriveFont(Font.PLAIN,12);
        Draw.defaultFont = menuFont;

        gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        width = gd.getDisplayMode().getWidth();
        height = gd.getDisplayMode().getHeight();
        if (Launcher.fontSize.equals("")) {
            if (width < 1500) {
                defaultFontSize = 11;

                buttonHeight = Main.defaultFontSize * 2;
                buttonWidth = Main.defaultFontSize * 6;

            } else if (width < 2000) {
                defaultFontSize = 12;

                buttonHeight = Main.defaultFontSize * 2 + 4;
                buttonWidth = Main.defaultFontSize * 6 + 4;

            } else if (width < 3000) {
                defaultFontSize = 15;
                buttonHeight = Main.defaultFontSize * 2 + 4;
                buttonWidth = Main.defaultFontSize * 6 + 4;
            } else {
                defaultFontSize = 19;
                buttonHeight = Main.defaultFontSize * 2 + 4;
                buttonWidth = Main.defaultFontSize * 6 + 4;
            }
        } else {
            try {
                defaultFontSize = Integer.parseInt(Launcher.fontSize);
            } catch (Exception e) {
                defaultFontSize = 12;
            }
        }

        menuFont = new Font("SansSerif", Font.PLAIN, Main.defaultFontSize);
        menuFontBold = new Font("SansSerif", Font.BOLD, Main.defaultFontSize);
        //   menuFont = new Font("SansSerif", Font.BOLD, Main.defaultFontSize);
    } catch (Exception e) {
        e.printStackTrace();
    }
    FileSystemView fsv = FileSystemView.getFileSystemView();
    File[] paths = File.listRoots();

    for (File path : paths) {
        if (fsv.getSystemDisplayName(path).contains("merit")) {
            pleiades = true;
        }
    }

    screenSize = new Dimension(width, height);

    drawHeight = (int) (screenSize.getHeight() * 0.6);
    sidebarWidth = (int) (screenSize.getWidth() * 0.1);
    drawWidth = (int) (screenSize.getWidth() - sidebarWidth);
    thisMainListener = this;
    try {
        htsjdk.samtools.util.Log.setGlobalLogLevel(htsjdk.samtools.util.Log.LogLevel.ERROR);
        /*   for(int i=0;i<snow.length; i++) {
              snow[i][0] = (height*Math.random());
              snow[i][1] = (4*Math.random() +1);
              snow[i][2] = (12*Math.random() -6);
              snow[i][3] = (2*Math.random() +1);
           }*/
        frame.addWindowListener(new java.awt.event.WindowAdapter() {
            @Override
            public void windowClosing(java.awt.event.WindowEvent windowEvent) {
                /*if (JOptionPane.showConfirmDialog(frame, "Are you sure to close this window?", "Really Closing?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION){
                    System.exit(0);
                }*/
                if (configChanged) {

                    try {
                        BufferedWriter fileWriter = new BufferedWriter(new FileWriter(Launcher.configfile));
                        for (int i = 0; i < Launcher.config.size(); i++) {
                            fileWriter.write(Launcher.config.get(i) + lineseparator);
                        }
                        fileWriter.close();

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

            }
        });
        baseMap.put((byte) 'A', 1);
        baseMap.put((byte) 'C', 2);
        baseMap.put((byte) 'G', 3);
        baseMap.put((byte) 'T', 4);
        baseMap.put((byte) 'N', 5);
        baseMap.put((byte) 'I', 6);
        baseMap.put((byte) 'D', 7);
        mutTypes.put("TA", 0);
        mutTypes.put("AT", 0);
        mutTypes.put("TC", 1);
        mutTypes.put("AG", 1);
        mutTypes.put("TG", 2);
        mutTypes.put("AC", 2);
        mutTypes.put("CA", 3);
        mutTypes.put("GT", 3);
        mutTypes.put("CG", 4);
        mutTypes.put("GC", 4);
        mutTypes.put("CT", 5);
        mutTypes.put("GA", 5);

        getBase.put((byte) 'A', "A");
        getBase.put((byte) 'C', "C");
        getBase.put((byte) 'G', "G");
        getBase.put((byte) 'T', "T");
        getBase.put((byte) 'N', "N");
        getBase.put((byte) 'a', "A");
        getBase.put((byte) 'c', "C");
        getBase.put((byte) 'g', "G");
        getBase.put((byte) 't', "T");
        getBase.put((byte) 'n', "N");
        java.net.URL imgUrl = getClass().getResource("icons/save.gif");
        save = new ImageIcon(imgUrl);
        imgUrl = getClass().getResource("icons/open.gif");
        open = new ImageIcon(imgUrl);
        imgUrl = getClass().getResource("icons/settings.png");
        settingsIcon = new ImageIcon(imgUrl);
        userDir = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent()
                .replace("%20", " ");
        settings = new JMenuItem("Settings", settingsIcon);

        //   Average.frame.setVisible(false);

        try {

            savedir = Launcher.defaultSaveDir;
            path = Launcher.defaultDir;
            gerp = Launcher.gerpfile;
            defaultGenome = Launcher.defaultGenome;
            defaultAnnotation = Launcher.defaultAnnotation;
            isProxy = Launcher.isProxy;
            proxyHost = Launcher.proxyHost;
            proxyPort = Launcher.proxyPort;
            proxyType = Launcher.proxyType;
            if (isProxy) {
                ProxySettings.useProxy.setSelected(true);
            }
            if (!proxyHost.equals("")) {
                ProxySettings.hostField.setText(proxyHost);
            }
            if (!proxyPort.equals("")) {
                ProxySettings.portField.setText(proxyPort);
            }
            if (!Launcher.proxyType.equals("")) {
                ProxySettings.proxytypes.setSelectedItem(proxyType);
            }
            if (Launcher.backColor.equals("")) {
                Draw.backColor = new Color(90, 90, 90);
            }

            else {

                Draw.backColor = new Color(Integer.parseInt(Launcher.backColor),
                        Integer.parseInt(Launcher.backColor), Integer.parseInt(Launcher.backColor));
                Settings.graySlider.setValue(Integer.parseInt(Launcher.backColor));
            }

            if (Launcher.genomeDir.equals("")) {

                genomeDir = new File(userDir + "/genomes/");
            } else {
                if (new File(Launcher.genomeDir).exists()) {

                    genomeDir = new File(Launcher.genomeDir);
                } else {
                    genomeDir = new File(userDir + "/genomes/");
                }
            }

            annotationfile = defaultAnnotation;
            controlDir = Launcher.ctrldir;
            trackDir = Launcher.trackDir;
            projectDir = Launcher.projectDir;
            downloadDir = Launcher.downloadDir;
        } catch (Exception e) {
            e.printStackTrace();
        }
        File[] genomes = genomeDir.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return !name.contains(".txt") && !name.startsWith(".");
            }
        });
        chromHeight = (int) (drawHeight * 0.1);
        drawDimensions = new Dimension(drawWidth, drawHeight - chromHeight);
        bedDimensions = new Dimension(drawWidth, bedHeight);
        chromDimensions = new Dimension(drawWidth - Main.sidebarWidth - 1, drawHeight);
        drawCanvas = new Draw((int) drawDimensions.getWidth(), (int) drawDimensions.getHeight());
        controlDraw = new ControlCanvas((int) bedDimensions.getWidth(), (int) bedDimensions.getHeight());
        iconImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("icons/icon.png"));
        frame.setIconImage(iconImage);
        /*   if(args.length > 0) {
               for(int i = 0; i<args.length; i++) {
                  if(args[i].startsWith("-opendir")) {
                     path = args[i].substring(9).replace(" ", "");
                  }
                  else if(args[i].startsWith("-ctrldir")) {
                     Control.path = args[i].substring(9).replace(" ", "");
                  }             
               }       
            }*/

        //   BGZIPInputStream in = this.getClass().getResourceAsStream("SELEX_1505_representative_matrices.bedhead.gz");
        searchField.getDocument().addDocumentListener(new DocumentListener() {
            private String searchstring;

            public void changedUpdate(DocumentEvent e) {
                if (searchField.getText().contains(";")) {
                    searchList = searchField.getText().split(";");
                    for (int i = 0; i < searchList.length; i++) {
                        warn(searchList[i].replace(" ", ""));
                    }
                } else {
                    warn(searchField.getText().replace(" ", ""));
                }

            }

            public void removeUpdate(DocumentEvent e) {
                if (searchField.getText().contains(";")) {
                    searchList = searchField.getText().split(";");
                    for (int i = 0; i < searchList.length; i++) {
                        warn(searchList[i].replace(" ", ""));
                    }
                } else {
                    warn(searchField.getText().replace(" ", ""));
                }
            }

            public void insertUpdate(DocumentEvent e) {
                if (searchField.getText().contains(";")) {
                    searchList = searchField.getText().split(";");
                    for (int i = 0; i < searchList.length; i++) {
                        warn(searchList[i].replace(" ", ""));
                    }
                } else {
                    warn(searchField.getText().replace(" ", ""));
                }
            }

            public void warn(String searchtext) {

                if (searchTable.containsKey(searchtext.toUpperCase())) {
                    if (searchTable.get(searchtext.toUpperCase())[0]
                            .equals(Main.chromosomeDropdown.getSelectedItem())) {
                        searchChrom = searchTable.get(searchtext.toUpperCase())[0];
                        searchStart = Integer.parseInt(searchTable.get(searchtext.toUpperCase())[1]);
                        searchEnd = Integer.parseInt(searchTable.get(searchtext.toUpperCase())[2]);
                    } else {
                        chromDraw.repaint();
                        searchStart = -1;
                        searchEnd = -1;
                    }
                    chromDraw.repaint();
                    searchField.setForeground(Color.black);
                } else if (searchField.getText().toUpperCase().matches("CHR.{1,2}(?!:)")) {

                    if (Main.chromnamevector.contains(searchtext.toUpperCase().substring(3))) {
                        searchField.setForeground(Color.black);

                    } else {
                        chromDraw.repaint();
                        searchField.setForeground(Color.red);
                    }
                } else if (searchtext.toUpperCase().replace(",", "").matches("(CHR)?(.+:)?\\d+(-\\d+)?")) {

                    searchField.setForeground(Color.black);
                    if (searchtext.contains(":")) {
                        searchstring = searchtext.substring(searchtext.indexOf(":") + 1).replace(",", "");
                    } else {
                        chromDraw.repaint();
                        searchstring = searchtext.replace(",", "");
                    }

                    if (!searchstring.contains("-")) {
                        try {
                            searchStart = Integer.parseInt(searchstring);
                        } catch (Exception ex) {

                        }
                        searchEnd = -1;
                    } else {
                        try {
                            searchStart = Integer
                                    .parseInt(searchstring.substring(0, searchstring.indexOf("-")));
                            searchEnd = Integer.parseInt(searchstring.substring(searchstring.indexOf("-") + 1));
                        } catch (Exception ex) {

                        }
                    }
                    chromDraw.repaint();

                } else {
                    chromDraw.repaint();
                    searchField.setForeground(Color.red);
                    searchStart = -1;
                    searchEnd = -1;
                }
            }
        });

        try {

            A = Toolkit.getDefaultToolkit().getImage(getClass().getResource("SELEX/A.png"));
            C = Toolkit.getDefaultToolkit().getImage(getClass().getResource("SELEX/C.png"));
            G = Toolkit.getDefaultToolkit().getImage(getClass().getResource("SELEX/G.png"));
            T = Toolkit.getDefaultToolkit().getImage(getClass().getResource("SELEX/T.png"));

        } catch (Exception e) {
            e.printStackTrace();
        }
        ErrorLog.main(args);

        this.setBackground(Color.black);
        UIManager.put("FileChooser.readOnly", Boolean.TRUE);

        panel.setBackground(Draw.sidecolor);
        panel.setBorder(BorderFactory.createLineBorder(Color.white));
        searchField.addKeyListener(this);

        frame.addKeyListener(this);
        frame.getContentPane().setBackground(Color.black);

        glassPane.addMouseListener(this);
        glassPane.addMouseMotionListener(new MouseMotionListener() {

            @Override
            public void mouseDragged(MouseEvent arg0) {

            }

            @Override
            public void mouseMoved(MouseEvent event) {

                // g.drawRect(drawScroll.getWidth()/2-Main.canceltextwidth/2-Main.defaultFontSize/2, Main.drawScroll.getViewport().getHeight()*2/3+Draw.loadingFont.getSize()*3-Main.defaultFontSize/4, Main.canceltextwidth+Main.defaultFontSize, Draw.loadingFont.getSize()+Main.defaultFontSize/2);                

                if (drawCanvas.loading
                        && event.getX() > drawScroll.getWidth() / 2 - Main.canceltextwidth / 2
                                - Main.defaultFontSize / 2
                        && event.getX() < drawScroll.getWidth() / 2 + Main.canceltextwidth / 2
                                + Main.defaultFontSize / 2
                        && event.getY() > frame.getHeight() * 1 / 3 + Draw.loadingFont.getSize() * 3
                                - Main.defaultFontSize / 4
                        && event.getY() < frame.getHeight() * 1 / 3 + Draw.loadingFont.getSize() * 4
                                + Main.defaultFontSize / 2) {
                    if (!Main.cancelhover) {
                        Main.cancelhover = true;
                        Main.glassPane.requestFocus();
                    }
                } else {
                    if (Main.cancelhover) {
                        Main.cancelhover = false;
                        Main.glassPane.requestFocus(false);
                    }
                }
            }
        });

        background.put((byte) 'A', 0.3);
        background.put((byte) 'C', 0.2);
        background.put((byte) 'G', 0.2);
        background.put((byte) 'T', 0.3);

        bases = new Hashtable<String, String>();
        bases.put("A", "A");
        bases.put("C", "C");
        bases.put("G", "G");
        bases.put("T", "T");
        bases.put("N", "N");
        bases.put("delA", "delA");
        bases.put("delC", "delC");
        bases.put("delG", "delG");
        bases.put("delT", "delT");
        bases.put("insA", "insA");
        bases.put("insC", "insC");
        bases.put("insG", "insG");
        bases.put("insT", "insT");

        chromDraw = new ChromDraw(drawWidth, chromHeight);

        VariantCaller.main(argsit);
        PeakCaller.main(argsit);
        tablebrowser = new TableBrowser();
        bedconverter = new BEDconvert();

        try {

            File annodir;

            File[] annotations;
            addGenome.addMouseListener(this);
            genome = new JMenu("Genomes");
            genome.setName("genomeMenu");
            genome.add(addGenome);
            genome.addComponentListener(this);
            File[] fastadir;
            String[] empty = {};

            refModel = new DefaultComboBoxModel<String>(empty);

            refDropdown = new SteppedComboBox(refModel);
            refDropdown.addMouseListener(this);
            String[] emptygenes = {};
            refDropdown.addActionListener(refDropActionListener);

            geneModel = new DefaultComboBoxModel<String>(emptygenes);
            geneDropdown = new SteppedComboBox(geneModel);
            geneDropdown.addMouseListener(this);
            if (genomes != null) {
                for (int i = 0; i < genomes.length; i++) {
                    if (!genomes[i].isDirectory()) {
                        continue;
                    }
                    annodir = new File(genomes[i].getAbsolutePath() + "/annotation/");
                    if (genomes[i].isDirectory()) {
                        fastadir = genomes[i].listFiles();
                        for (int f = 0; f < fastadir.length; f++) {
                            if (fastadir[f].isDirectory()) {
                                continue;
                            }
                            if (fastadir[f].getName().contains(".fai")) {
                                continue;
                            } else if (fastadir[f].getName().contains(".fa")) {
                                fastahash.put(genomes[i].getName(), fastadir[f]);
                            }
                        }
                    }

                    annotations = annodir.listFiles();
                    genomehash.put(genomes[i].getName(), new ArrayList<File>());

                    refModel.addElement(genomes[i].getName());
                    if (genomes[i].getName().length() > reflength) {
                        reflength = genomes[i].getName().length();
                    }
                    JMenu addMenu = new JMenu(genomes[i].getName());
                    addMenu.addMouseListener(this);
                    addMenu.setName(genomes[i].getName());
                    JMenuItem addAnnotation = new JMenuItem("Add new annotation file...");
                    addAnnotation.addMouseListener(this);
                    addAnnotation.setName("add_annotation");
                    addMenu.add(addAnnotation);
                    JLabel addLabel = new JLabel("  Select annotation: ");
                    labels.add(addLabel);
                    addMenu.add(addLabel);
                    addMenu.add(new JSeparator());

                    genome.add(addMenu);
                    addMenu.addComponentListener(this);
                    if (annotations != null) {
                        for (int j = 0; j < annotations.length; j++) {
                            annofiles = annotations[j].listFiles();
                            for (int f = 0; f < annofiles.length; f++) {
                                if (annofiles[f].getName().endsWith(".bed.gz")) {
                                    if (annofiles[f].getName()
                                            .substring(0, annofiles[f].getName().indexOf(".bed.gz"))
                                            .length() > annolength) {
                                        annolength = annofiles[f].getName().length();
                                    }

                                    genomehash.get(genomes[i].getName()).add(annofiles[f].getAbsoluteFile());
                                    JMenuItem additem = new JMenuItem(annofiles[f].getName().substring(0,
                                            annofiles[f].getName().indexOf(".bed.gz")));
                                    additem.setName(annofiles[f].getName().substring(0,
                                            annofiles[f].getName().indexOf(".bed.gz")));
                                    additem.addMouseListener(this);
                                    addMenu.add(additem);
                                    additem.addComponentListener(this);
                                    break;
                                }
                            }
                        }
                    }
                }
                refModel.addElement("Add new reference...");

            }

            if (genomes.length == 0) {
                /*if(Launcher.firstStart) {
                   Main.writeToConfig("FirstStart=false");
                }*/
                AddGenome.createAndShowGUI();
                AddGenome.frame.setTitle("Add new genome");

                AddGenome.remove.setEnabled(false);
                AddGenome.download.setEnabled(false);

                AddGenome.frame.setLocation((int) (screenSize.getWidth() / 2 - AddGenome.frame.getWidth() / 2),
                        (int) (screenSize.getHeight() / 6));

                AddGenome.frame.setState(JFrame.NORMAL);
                AddGenome.frame.setVisible(true);
                AddGenome.frame.setAlwaysOnTop(true);
                /*
                WelcomeScreen.main(args);
                WelcomeScreen.frame.setVisible(true);
                WelcomeScreen.frame.setLocation(frame.getLocationOnScreen().x+frame.getWidth()/2 - WelcomeScreen.frame.getWidth()/2, frame.getLocationOnScreen().y+frame.getHeight()/6);
                */
                if (genomes.length != 0) {
                    if (!genomehash.containsKey(defaultGenome)) {

                        setChromDrop(genomes[0].getName());
                        defaultGenome = genomes[0].getName();
                    } else {

                        setChromDrop(defaultGenome);
                    }
                    getBands();
                    getExons();
                } else {
                    setChromDrop(null);
                }
            } else {
                if (!genomehash.containsKey(defaultGenome)) {

                    setChromDrop(genomes[0].getName());
                    defaultGenome = genomes[0].getName();

                } else {

                    setChromDrop(defaultGenome);
                }
                getBands();
                getExons();
            }

            if (Launcher.firstStart) {

                WelcomeScreen.createAndShowGUI();
                WelcomeScreen.frame.setLocation(
                        (int) (screenSize.getWidth() / 2 - WelcomeScreen.frame.getWidth() / 2),
                        (int) (screenSize.getHeight() / 6));
                WelcomeScreen.frame.setVisible(true);
            }
            setMenuBar();
            setButtons();
            Settings.main(args);

            // Settings.main(args);
            frame.requestFocus();

            drawCanvas.addKeyListener(this);
            bedCanvas.addKeyListener(this);
            setFonts();
            chromLabel.setText("Chromosome " + chromosomeDropdown.getSelectedItem().toString());
            CheckUpdates check = new CheckUpdates();
            check.execute();
            //   Main.drawCanvas.loading("test");
            Main.drawCanvas.splits.get(0)
                    .setCytoImage(Main.chromDraw.createBands(Main.drawCanvas.splits.get(0)));
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        Main.showError(ex.getMessage(), "Error");

    }

}

From source file:base.BasePlayer.Main.java

public void actionPerformed(ActionEvent e) {
    //Logo.frame.setVisible(false);
    if (e.getSource() == pleiadesButton) {
        gotoURL("http://kaptah.local.lab.helsinki.fi/pleiades/");

    } else if (e.getSource() == manage) {

        if (VariantHandler.frame == null) {
            VariantHandler.main(argsit);
        }/*  w w  w .j  a  v  a2  s  . c o  m*/
        VariantHandler.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantHandler.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);

        VariantHandler.frame.setState(JFrame.NORMAL);
        VariantHandler.frame.setVisible(true);
        Draw.calculateVars = true;
        Draw.updatevars = true;
        drawCanvas.repaint();

    } else if (e.getSource() == tbrowser) {
        tablebrowser.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);
        tablebrowser.frame.setState(JFrame.NORMAL);

        tablebrowser.frame.setVisible(true);
    } else if (e.getSource() == bconvert) {
        bedconverter.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);
        bedconverter.frame.setState(JFrame.NORMAL);

        bedconverter.frame.setVisible(true);
    } else if (e.getSource() == peakCaller) {
        if (PeakCaller.frame == null) {

            PeakCaller.main(argsit);

        }
        PeakCaller.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);
        PeakCaller.frame.setState(JFrame.NORMAL);
        PeakCaller.frame.setVisible(true);
    } else if (e.getSource() == variantCaller) {

        //FileRead.checkSamples();

        if (VariantCaller.frame == null) {

            VariantCaller.main(argsit);

        }
        VariantCaller.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);
        VariantCaller.frame.setState(JFrame.NORMAL);
        VariantCaller.frame.setVisible(true);
    } else if (e.getSource() == average) {
        if (Average.frame == null) {
            Average.createAndShowGUI();
        }
        Average.setSamples();

        Average.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - Average.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);

        Average.frame.setState(JFrame.NORMAL);
        Average.frame.setVisible(true);
    } else if (e.getSource() == errorlog) {

        ErrorLog.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - ErrorLog.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);

        //      VariantHandler.frame.setAlwaysOnTop(true);   
        ErrorLog.frame.setState(JFrame.NORMAL);
        ErrorLog.frame.setVisible(true);

    }
    /*   else if(e.getSource() == help) {
          JOptionPane.showMessageDialog(Main.chromDraw, "This is pre-release version of BasePlayer\nContact: help@baseplayer.fi\nUniversity of Helsinki", "Help", JOptionPane.INFORMATION_MESSAGE);
       }*/
    else if (e.getSource() == settings) {

        Settings.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - Settings.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);

        Settings.frame.setState(JFrame.NORMAL);
        Settings.frame.setVisible(true);
    } else if (e.getSource() == update) {
        try {
            Updater update = new Updater();
            update.execute();

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

    } else if (e.getSource() == clearMemory) {
        FileRead.nullifyVarNodes();

        //FileRead.removeNonListVariants();f
        System.gc();
        chromDraw.repaint();
    } else if (e.getSource() == zoomout) {

        zoomout();
    } else if (e.getSource() == dosomething) {

        BedNode currentbed = bedCanvas.bedTrack.get(0).getHead().getNext();
        VarNode currentvar = FileRead.head.getNext();

        while (currentbed != null) {

            while (currentvar != null && currentvar.getPosition() < currentbed.getPosition()) {
                currentvar = currentvar.getNext();
            }
            while (currentbed != null
                    && currentvar.getPosition() > currentbed.getPosition() + currentbed.getLength()) {
                currentbed = currentbed.getNext();
            }

            if (currentvar != null && currentvar.getPosition() >= currentbed.getPosition()
                    && currentvar.getPosition() < currentbed.getPosition() + currentbed.getLength()) {
                currentvar.setBedhit(true);
                currentvar = currentvar.getNext();
            }
            if (currentvar == null) {
                break;
            }
            currentbed = currentbed.getNext();
        }

    } else if (e.getSource() == clear) {
        clearData();
    } else if (e.getSource() == exit) {

        System.exit(0);
    } else if (e.getSource() == openbams) {
        try {
            if (!checkGenome())
                return;
            if (VariantHandler.frame != null) {
                VariantHandler.frame.setState(Frame.ICONIFIED);
            }

            FileDialog fc = new FileDialog(frame, "Choose BAM file(s)", FileDialog.LOAD);
            fc.setDirectory(path);
            fc.setFile("*.bam;*.cram;*.link");
            fc.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".bam") || name.toLowerCase().endsWith(".cram")
                            || name.toLowerCase().endsWith(".link");
                }
            });
            fc.setMultipleMode(true);
            fc.setVisible(true);
            File[] openfiles = fc.getFiles();

            if (openfiles != null && openfiles.length > 0) {

                path = openfiles[0].getParent();
                writeToConfig("DefaultDir=" + path);
                FileRead filereader = new FileRead(openfiles);

                filereader.start = (int) drawCanvas.selectedSplit.start;
                filereader.end = (int) drawCanvas.selectedSplit.end;
                filereader.readBAM = true;
                filereader.execute();

            } else {
                //Main.showError("File(s) does not exist.", "Error");
            }

        } catch (Exception ex) {
            Main.showError(ex.getMessage(), "Error");
        }
    } else if (e.getSource() == openvcfs) {
        try {
            if (!checkGenome())
                return;
            if (VariantHandler.frame != null) {
                VariantHandler.frame.setState(Frame.ICONIFIED);
            }

            FileDialog fc = new FileDialog(frame, "Choose VCF file(s)", FileDialog.LOAD);
            fc.setDirectory(path);
            fc.setFile("*.vcf");
            fc.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".vcf") || name.toLowerCase().endsWith(".vcf.gz");
                }
            });

            fc.setMultipleMode(true);
            fc.setVisible(true);
            File[] openfiles = fc.getFiles();

            if (openfiles != null && openfiles.length > 0) {

                path = openfiles[0].getParent();
                writeToConfig("DefaultDir=" + path);
                FileRead filereader = new FileRead(openfiles);

                filereader.start = (int) drawCanvas.selectedSplit.start;
                filereader.end = (int) drawCanvas.selectedSplit.end;
                filereader.readVCF = true;
                filereader.execute();

            } else {
                //Main.showError("File(s) does not exist.", "Error");
            }

            if (1 == 1) {
                return;
            }

            JFileChooser chooser = new JFileChooser(path);
            getText(chooser.getComponents());
            chooser.setMultiSelectionEnabled(true);
            //chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);
            chooser.addChoosableFileFilter(vcfFilter);
            chooser.addChoosableFileFilter(bamFilter);
            chooser.addChoosableFileFilter(linkFilter);
            if (defaultSelectType == "vcf") {
                chooser.setFileFilter(vcfFilter);
            } else if (defaultSelectType == "bam") {
                chooser.setFileFilter(bamFilter);
            } else {
                chooser.setFileFilter(linkFilter);
            }
            chooser.setDialogTitle("Add samples");
            chooser.setPreferredSize(
                    new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3));
            int returnVal = chooser.showOpenDialog((Component) this.getParent());

            if (returnVal == JFileChooser.APPROVE_OPTION) {

                File vcffiles[] = chooser.getSelectedFiles();
                if (vcffiles.length == 1 && !vcffiles[0].exists() && pleiades) {

                    if (Main.chooserText.contains("`")) {
                        Main.chooserText.replace("`", "?");
                    }
                    if (Main.chooserText.contains(" ")) {
                        Main.chooserText.replace(" ", "%20");
                    }
                    if (Main.chooserText.contains("pleiades")) {
                        try {
                            URL url = new URL(Main.chooserText);
                            //System.out.println(Main.chooserText);
                            HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
                            httpConn.connect();

                            int responseCode = httpConn.getResponseCode();

                            if (responseCode == HttpsURLConnection.HTTP_OK) {

                                String loading = drawCanvas.loadingtext;
                                InputStream inputStream = httpConn.getInputStream();
                                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                                Main.drawCanvas.loadingtext = loading + " 0MB";
                                String line;
                                StringBuffer buffer = new StringBuffer("");
                                while ((line = reader.readLine()) != null) {

                                    buffer.append(line);

                                }
                                inputStream.close();
                                reader.close();
                                String split2;
                                String[] split = buffer.toString().split("dataUnit");
                                String location;
                                ArrayList<File> array = new ArrayList<File>();
                                File[] paths;
                                FileSystemView fsv = FileSystemView.getFileSystemView();
                                paths = File.listRoots();
                                String loc = "/mnt";
                                boolean missingfiles = false;
                                for (File path : paths) {
                                    if (fsv.getSystemDisplayName(path).contains("merit")) {
                                        loc = path.getCanonicalPath();
                                    }
                                }

                                for (int i = 0; i < split.length; i++) {

                                    if (!split[i].contains("lastLocation")) {

                                        continue;
                                    }

                                    split2 = split[i].split("\"lastLocation\":\"")[1];
                                    location = split2.substring(0, split2.indexOf("\"}"));
                                    String filename = "";
                                    String testloc = location.replace("/mnt", loc) + "/wgspipeline/";
                                    File testDir = new File(testloc);
                                    if (testDir.exists() && testDir.isDirectory()) {
                                        if (chooser.getFileFilter()
                                                .equals(chooser.getChoosableFileFilters()[1])) {
                                            File[] addDir = testDir.listFiles(new FilenameFilter() {
                                                public boolean accept(File dir, String name) {
                                                    return name.toLowerCase().endsWith(".bam")
                                                            || name.toLowerCase().endsWith(".cram");
                                                }
                                            });
                                            if (addDir.length > 0) {
                                                filename = addDir[0].getName();
                                            }
                                        } else {
                                            File[] addDir = testDir.listFiles(new FilenameFilter() {
                                                public boolean accept(File dir, String name) {
                                                    return name.toLowerCase().endsWith(".vcf.gz");
                                                }
                                            });
                                            if (addDir.length > 0) {
                                                filename = addDir[0].getName();
                                            }
                                        }
                                    }

                                    location = testloc + "/" + filename;

                                    if (!new File(location).exists()) {

                                        if (!new File(location).exists()) {
                                            missingfiles = true;
                                            ErrorLog.addError("No sample files found in " + testloc);

                                        } else {
                                            array.add(new File(location));
                                        }
                                    } else {

                                        array.add(new File(location));
                                    }
                                }

                                File[] files = new File[array.size()];
                                for (int i = 0; i < files.length; i++) {

                                    files[i] = array.get(i);
                                }
                                FileRead filereader = new FileRead(files);
                                filereader.start = (int) drawCanvas.selectedSplit.start;
                                filereader.end = (int) drawCanvas.selectedSplit.end;
                                if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[1])) {
                                    filereader.readBAM = true;
                                } else {
                                    filereader.readVCF = true;
                                }
                                filereader.execute();
                                if (missingfiles) {
                                    JOptionPane.showMessageDialog(Main.drawScroll,
                                            "Missing files. Check Tools->View log", "Note",
                                            JOptionPane.INFORMATION_MESSAGE);
                                }

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

                    return;
                }

                if (vcffiles.length > 0) {
                    path = vcffiles[0].getParent();
                    writeToConfig("DefaultDir=" + path);
                    FileRead filereader = new FileRead(vcffiles);

                    if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[0])) {
                        defaultSelectType = "vcf";
                        filereader.start = (int) drawCanvas.selectedSplit.start;
                        filereader.end = (int) drawCanvas.selectedSplit.end;
                        filereader.readVCF = true;
                        filereader.execute();
                    } else if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[1])) {
                        defaultSelectType = "bam";
                        filereader.readBAM = true;
                        filereader.execute();
                    } else if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[2])) {

                        defaultSelectType = "link";
                        filereader.readBAM = true;
                        filereader.execute();
                    }
                } else {

                    JOptionPane.showMessageDialog(Main.drawScroll,
                            "The file does not exist. The file link may be broken.\nThe problem may also be the Java run time version in Linux.",
                            "Note", JOptionPane.INFORMATION_MESSAGE);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    } else if (e.getSource() == addcontrols) {
        if (!checkGenome())
            return;
        if (VariantHandler.frame != null) {
            VariantHandler.frame.setState(Frame.ICONIFIED);
        }
        FileDialog fc = new FileDialog(frame, "Choose control file(s)", FileDialog.LOAD);
        fc.setDirectory(Main.controlDir);
        fc.setFile("*.vcf.gz");
        fc.setFilenameFilter(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(".vcf.gz");
            }
        });
        fc.setMultipleMode(true);
        fc.setVisible(true);
        File[] openfiles = fc.getFiles();

        if (openfiles != null && openfiles.length > 0) {

            controlDir = openfiles[0].getParent();
            writeToConfig("DefaultControlDir=" + controlDir);

            Control.addFiles(openfiles);
        }
        if (1 == 1) {
            return;
        }
        JFileChooser chooser = new JFileChooser(controlDir);
        //        JFileChooser chooser = new JFileChooser(path);            
        chooser.setMultiSelectionEnabled(true);
        chooser.setAcceptAllFileFilterUsed(false);
        Control.MyFilter vcfFilter = new Control.MyFilter();
        chooser.addChoosableFileFilter(vcfFilter);

        chooser.setDialogTitle("Add controls");
        chooser.setPreferredSize(
                new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3));
        int returnVal = chooser.showOpenDialog((Component) this.getParent());

        if (returnVal == JFileChooser.APPROVE_OPTION) {

            File vcffiles[] = chooser.getSelectedFiles();
            controlDir = vcffiles[0].getParent();
            writeToConfig("DefaultControlDir=" + controlDir);

            if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[0])) {
                Control.addFiles(vcffiles);
            }
        }
    } else if (e.getSource() == addtracks) {
        if (!checkGenome())
            return;
        try {
            if (!checkGenome())
                return;
            if (VariantHandler.frame != null) {
                VariantHandler.frame.setState(Frame.ICONIFIED);
            }

            FileDialog fc = new FileDialog(frame, "Choose track file(s)", FileDialog.LOAD);
            fc.setDirectory(Main.trackDir);
            fc.setFile(
                    "*.bed;*.bedgraph.gz;*.gff.gz;*.gff3.gz;*.bigwig;*.bw;*.bigbed;*.bb;*.tsv.gz;*.tsv.bgz;*.txt");
            fc.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".bed") || name.toLowerCase().endsWith(".bed.gz")
                            || name.toLowerCase().endsWith(".bedgraph.gz")
                            || name.toLowerCase().endsWith(".bedgraph.gz")
                            || name.toLowerCase().endsWith(".bedgraph.gz")
                            || name.toLowerCase().endsWith(".gff.gz") || name.toLowerCase().endsWith(".gff3.gz")
                            || name.toLowerCase().endsWith(".bigwig") || name.toLowerCase().endsWith(".bw")
                            || name.toLowerCase().endsWith(".bigbed") || name.toLowerCase().endsWith(".bb")
                            || name.toLowerCase().endsWith(".tsv.gz") || name.toLowerCase().endsWith(".tsv.bgz")
                            || name.toLowerCase().endsWith(".txt");
                }
            });
            fc.setMultipleMode(true);
            fc.setVisible(true);
            File[] openfiles = fc.getFiles();

            if (openfiles != null && openfiles.length > 0) {

                trackDir = openfiles[0].getParent();
                writeToConfig("DefaultTrackDir=" + trackDir);
                FileRead filereader = new FileRead(openfiles);
                filereader.readBED = true;
                filereader.execute();

            } else {
                //Main.showError("File(s) does not exist.", "Error");
            }

        } catch (Exception ex) {
            Main.showError(ex.getMessage(), "Error");
        }
        if (1 == 1) {
            return;
        }
        if (VariantHandler.frame != null) {
            VariantHandler.frame.setState(Frame.ICONIFIED);
        }
        JFileChooser chooser = new JFileChooser(Main.trackDir);
        getText(chooser.getComponents());
        chooser.setMultiSelectionEnabled(true);
        chooser.setAcceptAllFileFilterUsed(false);
        MyFilterBED bedFilter = new MyFilterBED();
        MyFilterTXT txtFilter = new MyFilterTXT();
        chooser.addChoosableFileFilter(bedFilter);
        chooser.addChoosableFileFilter(txtFilter);
        chooser.setDialogTitle("Add tracks");
        chooser.setPreferredSize(
                new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3));
        int returnVal = chooser.showOpenDialog((Component) this.getParent());

        try {

            if (returnVal == JFileChooser.APPROVE_OPTION) {

                File bedfiles[] = chooser.getSelectedFiles();
                if (bedfiles[0].exists()) {

                    trackDir = bedfiles[0].getParent();
                    writeToConfig("DefaultTrackDir=" + trackDir);
                    FileRead filereader = new FileRead(bedfiles);
                    filereader.readBED(bedfiles);

                } else {

                    if (Main.chooserText.length() > 5 && Main.chooserText.endsWith(".bed.gz")
                            || Main.chooserText.endsWith(".gff.gz") || Main.chooserText.endsWith(".gff3.gz")
                            || Main.chooserText.endsWith(".bedgraph.gz")) {

                        if (Main.chooserText.startsWith("http://") || Main.chooserText.startsWith("ftp://")) {

                            URL url = new URL(Main.chooserText);
                            SeekableStream stream = SeekableStreamFactory.getInstance().getStreamFor(url);
                            TabixReader tabixReader = null;
                            String index = null;

                            try {
                                tabixReader = new TabixReader(Main.chooserText, Main.chooserText + ".tbi",
                                        stream);
                                index = Main.chooserText + ".tbi";
                            } catch (Exception ex) {
                                try {
                                    tabixReader = new TabixReader(Main.chooserText,
                                            Main.chooserText.substring(0, Main.chooserText.indexOf(".gz"))
                                                    + ".tbi",
                                            stream);
                                    index = Main.chooserText.substring(0, Main.chooserText.indexOf(".gz"))
                                            + ".tbi";
                                } catch (Exception exc) {
                                    exc.printStackTrace();
                                }
                            }
                            if (tabixReader != null && index != null) {

                                FileRead filereader = new FileRead(bedfiles);
                                filereader.readBED(Main.chooserText, index, false);

                                tabixReader.close();
                            }
                        }
                    } else {
                        if (Main.chooserText.contains("://")) {

                            try {
                                //        bbreader = new BBFileReader(Main.chooserText, stream);

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

                            //  if(bbreader != null) {

                            FileRead filereader = new FileRead(bedfiles);
                            filereader.readBED(Main.chooserText, "nan", false);

                            //     }
                            //     stream.close();
                        }
                    }
                }
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (e.getSource() == openProject) {
        if (!checkGenome())
            return;
        if (VariantHandler.frame != null) {
            VariantHandler.frame.setState(Frame.ICONIFIED);
        }
        openProject();
    } else if (e.getSource() == saveProjectAs) {
        if (VariantHandler.frame != null) {
            VariantHandler.frame.setState(Frame.ICONIFIED);
        }
        try {
            File savefile = null;
            FileDialog fs = new FileDialog(frame, "Save project as...", FileDialog.SAVE);
            fs.setDirectory(projectDir);
            fs.setFile("*.ses");
            fs.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".ses");
                }
            });
            fs.setVisible(true);

            while (true) {
                String filename = fs.getFile();

                if (filename != null) {
                    savefile = new File(fs.getDirectory() + "/" + filename);
                    projectDir = fs.getDirectory();
                    writeToConfig("DefaultProjectDir=" + projectDir);

                    /* if(!Files.isWritable(Paths.get(savefile.getParent()))) {
                       Main.showError("No permission to write.", "Error");
                       continue;
                     }*/

                    if (!savefile.getAbsolutePath().endsWith(".ses")) {
                        savefile = new File(savefile.getAbsolutePath() + ".ses");
                    }

                    Serializer ser = new Serializer();
                    ser.serialize(savefile);
                    break;
                } else {
                    break;
                }
            }
            if (1 == 1) {
                return;
            }
            JFileChooser chooser = new JFileChooser();
            chooser.setAcceptAllFileFilterUsed(false);
            MyFilterSES sesFilter = new MyFilterSES();
            chooser.addChoosableFileFilter(sesFilter);
            chooser.setDialogTitle("Save project as...");
            int returnVal = chooser.showSaveDialog((Component) this.getParent());

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File outfile = chooser.getSelectedFile();
                if (!outfile.getAbsolutePath().endsWith(".ses")) {
                    outfile = new File(outfile.getAbsolutePath() + ".ses");
                }

                Serializer ser = new Serializer();
                ser.serialize(outfile);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    } else if (e.getSource() == saveProject) {
        if (drawCanvas.drawVariables.projectName.equals("Untitled")) {
            saveProjectAs.doClick();
        } else {

            Serializer ser = new Serializer();
            ser.serialize(drawCanvas.drawVariables.projectFile);
        }
    }
    /*      else if(e.getSource() == welcome) {
             WelcomeScreen.main(args);
             WelcomeScreen.frame.setVisible(true);
             WelcomeScreen.frame.setLocation(frame.getLocationOnScreen().x+frame.getWidth()/2 - WelcomeScreen.frame.getWidth()/2, frame.getLocationOnScreen().y+frame.getHeight()/6);
                     
          }*/
}