Example usage for java.awt Frame ICONIFIED

List of usage examples for java.awt Frame ICONIFIED

Introduction

In this page you can find the example usage for java.awt Frame ICONIFIED.

Prototype

int ICONIFIED

To view the source code for java.awt Frame ICONIFIED.

Click Source Link

Document

This state bit indicates that frame is iconified.

Usage

From source file:javazoom.jlgui.player.amp.Player.java

/**
 * Manages events./*from ww  w  .  j av  a 2  s . c  om*/
 */
public void actionPerformed(ActionEvent e) {

    /*------------------------------------*/
    /*--        Interact on Seek        --*/
    /*------------------------------------*/
    if (e.getActionCommand().equals("Seek")) {
        if (acPosBar.isMousePressed() == false) {
            FirstPosBarDrag = true;
            posValueJump = true;
            processSeek();
            repaint();
        } else {
            int DeltaX = 0;
            if (FirstPosBarDrag == false) {
                DeltaX = acPosBar.getMouseX() - XPosBarDrag;
                XPosBarDrag = acPosBar.getMouseX() - DeltaX;
                if (posBarLocation[0] + DeltaX < posBarBounds[0])
                    posBarLocation[0] = posBarBounds[0];
                else if (posBarLocation[0] + DeltaX > posBarBounds[1])
                    posBarLocation[0] = posBarBounds[1];
                else
                    posBarLocation[0] = posBarLocation[0] + DeltaX;
                acPosBar.setLocation(posBarLocation[0], posBarLocation[1]);
                double a = (maxPos - minPos) / (posBarBounds[1] - posBarBounds[0]);
                posValue = (a * (posBarLocation[0] - posBarBounds[0]) + minPos);
            } else {
                FirstPosBarDrag = false;
                XPosBarDrag = acPosBar.getMouseX();
            }
        }
    }

    /*------------------------------------*/
    /*--       Interact on Volume       --*/
    /*------------------------------------*/
    else if (e.getActionCommand().equals("Volume")) {
        if (acVolume.isMousePressed() == false) {
            FirstVolumeDrag = true;
            offScreenGraphics.drawImage(clearImage, titleLocation[0], titleLocation[1], this);
            offScreenGraphics.drawImage(titleImage, titleLocation[0], titleLocation[1], this);
            repaint();
        } else {
            int DeltaX = 0;
            if (FirstVolumeDrag == false) {
                DeltaX = acVolume.getMouseX() - XVolumeDrag;
                XVolumeDrag = acVolume.getMouseX() - DeltaX;
                if (volumeLocation[0] + DeltaX < volumeBounds[0])
                    volumeLocation[0] = volumeBounds[0];
                else if (volumeLocation[0] + DeltaX > volumeBounds[1])
                    volumeLocation[0] = volumeBounds[1];
                else
                    volumeLocation[0] = volumeLocation[0] + DeltaX;
                acVolume.setLocation(volumeLocation[0], volumeLocation[1]);
                double a = (maxGain - minGain) / (volumeBounds[1] - volumeBounds[0]);
                gainValue = (int) (a * (volumeLocation[0] - volumeBounds[0]) + minGain);
                try {
                    if (gainValue == 0)
                        theSoundPlayer.setGain(0);
                    else
                        theSoundPlayer.setGain(((double) gainValue / (double) maxGain));
                } catch (BasicPlayerException e1) {
                    log.debug("Cannot set gain", e1);
                }
                String volumeText = "VOLUME: " + (int) Math.round(
                        (100 / (volumeBounds[1] - volumeBounds[0])) * (volumeLocation[0] - volumeBounds[0]))
                        + "%";
                Image volImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, volumeText))
                        .getBanner();
                offScreenGraphics.drawImage(
                        volumeImage[(int) Math
                                .round(((double) gainValue / (double) maxGain) * (volumeImage.length - 1))],
                        volumeBarLocation[0], volumeBarLocation[1], this);
                offScreenGraphics.drawImage(clearImage, titleLocation[0], titleLocation[1], this);
                offScreenGraphics.drawImage(volImage, titleLocation[0], titleLocation[1], this);
            } else {
                FirstVolumeDrag = false;
                XVolumeDrag = acVolume.getMouseX();
            }
        }
    }

    /*------------------------------------*/
    /*--       Interact on Balance       --*/
    /*------------------------------------*/
    else if (e.getActionCommand().equals("Balance")) {
        if (acBalance.isMousePressed() == false) {
            FirstBalanceDrag = true;
            offScreenGraphics.drawImage(clearImage, titleLocation[0], titleLocation[1], this);
            offScreenGraphics.drawImage(titleImage, titleLocation[0], titleLocation[1], this);
            repaint();
        } else {
            int DeltaX = 0;
            if (FirstBalanceDrag == false) {
                DeltaX = acBalance.getMouseX() - XBalanceDrag;
                XBalanceDrag = acBalance.getMouseX() - DeltaX;
                if (balanceLocation[0] + DeltaX < balanceBounds[0])
                    balanceLocation[0] = balanceBounds[0];
                else if (balanceLocation[0] + DeltaX > balanceBounds[1])
                    balanceLocation[0] = balanceBounds[1];
                else
                    balanceLocation[0] = balanceLocation[0] + DeltaX;
                acBalance.setLocation(balanceLocation[0], balanceLocation[1]);
                double a = (maxBalance - minBalance) / (balanceBounds[1] - balanceBounds[0]);
                balanceValue = (a * (balanceLocation[0] - balanceBounds[0]) + minBalance);
                try {
                    theSoundPlayer.setPan((float) balanceValue);
                } catch (BasicPlayerException e1) {
                    log.debug("Cannot set pan", e1);
                }
                String balanceText = "BALANCE: " + (int) Math.abs(balanceValue * 100) + "%";
                if (balanceValue > 0)
                    balanceText = balanceText + " RIGHT";
                else if (balanceValue < 0)
                    balanceText = balanceText + " LEFT";
                else
                    balanceText = "BALANCE: CENTER";
                Image balImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, balanceText))
                        .getBanner();
                offScreenGraphics.drawImage(
                        balanceImage[(int) Math.round(
                                ((double) Math.abs(balanceValue) / (double) 1) * (balanceImage.length - 1))],
                        balanceBarLocation[0], balanceBarLocation[1], this);
                offScreenGraphics.drawImage(clearImage, titleLocation[0], titleLocation[1], this);
                offScreenGraphics.drawImage(balImage, titleLocation[0], titleLocation[1], this);
            } else {
                FirstBalanceDrag = false;
                XBalanceDrag = acBalance.getMouseX();
            }
        }
    }

    /*------------------------------------*/
    /*-- Select Filename or URL to load --*/
    /*------------------------------------*/
    else if (e.getActionCommand().equals("Eject")) {
        if ((playerState == PLAY) || (playerState == PAUSE)) {
            try {
                theSoundPlayer.stop();
            } catch (BasicPlayerException e1) {
                log.info("Cannot stop", e1);
            }
            playerState = STOP;
        }
        if ((playerState == INIT) || (playerState == STOP) || (playerState == OPEN)) {
            System.gc();
            PlaylistItem pli = null;
            // Local File.
            // E.B : FileSelector added as M.S did.
            if (acEject.getMouseButton() == MouseEvent.BUTTON1_MASK) {
                Frame f = new Frame();
                f.setLocation(this.getBounds().x, this.getBounds().y + 10);
                FileSelector.setWindow(f);
                String fsFile = FileSelector.selectFile(FileSelector.OPEN, config.getExtensions(),
                        config.getLastDir());
                fsFile = FileSelector.getFile();
                if (fsFile != null) {
                    config.setLastDir(FileSelector.getDirectory());
                    if (fsFile != null) {
                        // Loads a new playlist.
                        if ((fsFile.toLowerCase().endsWith(".m3u"))
                                || (fsFile.toLowerCase().endsWith(".pls"))) {
                            if (loadPlaylist(config.getLastDir() + fsFile)) {
                                config.setPlaylistFilename(config.getLastDir() + fsFile);
                                playlist.begin();
                                fileList.initPlayList();
                                this.setCurrentSong(playlist.getCursor());
                                fileList.repaint();
                            }
                        } else if (fsFile.toLowerCase().endsWith(".wsz")) {
                            this.dispose();
                            loadSkin(config.getLastDir() + fsFile);
                            config.setDefaultSkin(config.getLastDir() + fsFile);
                        } else
                            pli = new PlaylistItem(fsFile, config.getLastDir() + fsFile, -1, true);
                    }
                }
            }
            // Remote File.
            else if (acEject.getMouseButton() == MouseEvent.BUTTON3_MASK) {
                UrlDialog UD = new UrlDialog("Open location", this.getBounds().x, this.getBounds().y + 10, 280,
                        130, config.getLastURL());
                UD.show();
                if (UD.getFile() != null) {
                    showTitle("PLEASE WAIT ... LOADING ...");
                    displayAll();
                    if (fileList != null)
                        fileList.displayAll();
                    if (equalizer != null)
                        equalizer.displayAll();
                    // Remote playlist ?
                    if ((UD.getURL().toLowerCase().endsWith(".m3u"))
                            || (UD.getURL().toLowerCase().endsWith(".pls"))) {
                        if (loadPlaylist(UD.getURL())) {
                            config.setPlaylistFilename(UD.getURL());
                            playlist.begin();
                            fileList.initPlayList();
                            this.setCurrentSong(playlist.getCursor());
                            fileList.repaint();
                        }
                    }
                    // Remote file or stream.
                    else {
                        pli = new PlaylistItem(UD.getFile(), UD.getURL(), -1, false);
                    }
                    config.setLastURL(UD.getURL());
                }
            }

            if (pli != null) {
                playlist.removeAllItems();
                playlist.appendItem(pli);
                playlist.nextCursor();
                fileList.initPlayList();
                this.setCurrentSong(pli);
            }
        }
        offScreenGraphics.drawImage(iconsImage[2], iconsLocation[0], iconsLocation[1], this);
        offScreenGraphics.drawImage(iconsImage[4], iconsLocation[2], iconsLocation[3], this);
        repaint();
    }

    /*---------------------------*/
    /*-- Play the current File --*/
    /*---------------------------*/
    else if (e.getActionCommand().equals("Play")) {
        if (playlist.isModified()) // playlist has been modified since we were last there, must update our cursor pos etc.
        {
            PlaylistItem pli = playlist.getCursor();
            if (pli == null) {
                playlist.begin();
                pli = playlist.getCursor();
                if (firstSong) {
                    String info = pli.getName();
                    info += " STARTED PLAYLIST";
                    tFrame.addText(info);
                    firstSong = false;
                }
            } else if (playlist.getSelectedIndex() == 0) {
                if (firstSong) {
                    String info = pli.getName();
                    info += " STARTED PLAYLIST";
                    tFrame.addText(info);
                    firstSong = false;
                }
            }
            this.setCurrentSong(pli);
            if (!isRepeat) {
                //String info = pli.getName();
                //info += " STARTED PLAYLIST";
                //tFrame.addText(info);
            } else
                isRepeat = false;
            playlist.setModified(false);
            fileList.repaint();
        }

        // Resume is paused.
        if (playerState == PAUSE) {
            try {
                theSoundPlayer.resume();
            } catch (BasicPlayerException e1) {
                log.error("Cannot resume", e1);
            }
            playerState = PLAY;
            offScreenGraphics.drawImage(iconsImage[0], iconsLocation[0], iconsLocation[1], this);
            offScreenGraphics.drawImage(iconsImage[3], iconsLocation[2], iconsLocation[3], this);
            repaint();
        }

        // Stop if playing.
        else if (playerState == PLAY) {
            try {
                theSoundPlayer.stop();
            } catch (BasicPlayerException e1) {
                log.error("Cannot stop", e1);
            }
            playerState = PLAY;
            secondsAmount = 0;
            offScreenGraphics.drawImage(timeImage[0], minuteDLocation[0], minuteDLocation[1], this);
            offScreenGraphics.drawImage(timeImage[0], minuteLocation[0], minuteLocation[1], this);
            offScreenGraphics.drawImage(timeImage[0], secondDLocation[0], secondDLocation[1], this);
            offScreenGraphics.drawImage(timeImage[0], secondLocation[0], secondLocation[1], this);
            repaint();
            if (currentFileOrURL != null) {
                try {
                    if (currentIsFile == true)
                        theSoundPlayer.open(openFile(currentFileOrURL));
                    else
                        theSoundPlayer.open(new URL(currentFileOrURL));
                    theSoundPlayer.play();
                } catch (Exception ex) {
                    log.error("Cannot read file : " + currentFileOrURL, ex);
                    showMessage("INVALID FILE");
                }
            }
        } else if ((playerState == STOP) || (playerState == OPEN)) {
            try {
                theSoundPlayer.stop();
            } catch (BasicPlayerException e1) {
                log.error("Stop failed", e1);
            }
            if (currentFileOrURL != null) {
                try {
                    if (currentIsFile == true)
                        theSoundPlayer.open(openFile(currentFileOrURL));
                    else
                        theSoundPlayer.open(new URL(currentFileOrURL));
                    theSoundPlayer.play();
                    titleText = currentSongName.toUpperCase();

                    // Get bitrate, samplingrate, channels, time in the following order :
                    // PlaylistItem, BasicPlayer (JavaSound SPI), Manual computation.
                    int bitRate = -1;
                    if (currentPlaylistItem != null)
                        bitRate = currentPlaylistItem.getBitrate();
                    if ((bitRate <= 0) && (audioInfo.containsKey("bitrate")))
                        bitRate = ((Integer) audioInfo.get("bitrate")).intValue();
                    if ((bitRate <= 0) && (audioInfo.containsKey("audio.framerate.fps"))
                            && (audioInfo.containsKey("audio.framesize.bytes"))) {
                        float FR = ((Float) audioInfo.get("audio.framerate.fps")).floatValue();
                        int FS = ((Integer) audioInfo.get("audio.framesize.bytes")).intValue();
                        bitRate = Math.round(FS * FR * 8);
                    }
                    int channels = -1;
                    if (currentPlaylistItem != null)
                        channels = currentPlaylistItem.getChannels();
                    if ((channels <= 0) && (audioInfo.containsKey("audio.channels")))
                        channels = ((Integer) audioInfo.get("audio.channels")).intValue();
                    float sampleRate = -1.0f;
                    if (currentPlaylistItem != null)
                        sampleRate = currentPlaylistItem.getSamplerate();
                    if ((sampleRate <= 0) && (audioInfo.containsKey("audio.samplerate.hz")))
                        sampleRate = ((Float) audioInfo.get("audio.samplerate.hz")).floatValue();
                    long lenghtInSecond = -1L;
                    if (currentPlaylistItem != null)
                        lenghtInSecond = currentPlaylistItem.getLength();
                    if ((lenghtInSecond <= 0) && (audioInfo.containsKey("duration")))
                        lenghtInSecond = ((Long) audioInfo.get("duration")).longValue() / 1000000;
                    if ((lenghtInSecond <= 0) && (audioInfo.containsKey("audio.length.bytes"))) {
                        // Try to compute time length.
                        lenghtInSecond = (long) Math.round(getTimeLengthEstimation(audioInfo) / 1000);
                        if (lenghtInSecond > 0) {
                            int minutes = (int) Math.floor(lenghtInSecond / 60);
                            int hours = (int) Math.floor(minutes / 60);
                            minutes = minutes - hours * 60;
                            int seconds = (int) (lenghtInSecond - minutes * 60 - hours * 3600);
                            if (seconds >= 10)
                                titleText = "(" + minutes + ":" + seconds + ") " + titleText;
                            else
                                titleText = "(" + minutes + ":0" + seconds + ") " + titleText;
                        }
                    }
                    bitRate = Math.round((bitRate / 1000));
                    sampleRateImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0,
                            "" + Math.round((sampleRate / 1000)))).getBanner();
                    if (bitRate > 999) {
                        bitRate = (int) (bitRate / 100);
                        bitsRateImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0,
                                "" + bitRate + "H")).getBanner();
                    } else
                        bitsRateImage = (new Taftb(fontIndex, imText, fontWidth, fontHeight, 0, "" + bitRate))
                                .getBanner();
                    offScreenGraphics.drawImage(sampleRateImage, sampleRateLocation[0], sampleRateLocation[1],
                            this);
                    offScreenGraphics.drawImage(bitsRateImage, bitsRateLocation[0], bitsRateLocation[1], this);
                    if (channels == 2) {
                        offScreenGraphics.drawImage(activeModeImage[0], stereoLocation[0], stereoLocation[1],
                                this);
                    } else if (channels == 1) {
                        offScreenGraphics.drawImage(activeModeImage[1], monoLocation[0], monoLocation[1], this);
                    }
                    showTitle(titleText);
                    offScreenGraphics.drawImage(timeImage[0], minuteDLocation[0], minuteDLocation[1], this);
                    offScreenGraphics.drawImage(timeImage[0], minuteLocation[0], minuteLocation[1], this);
                    offScreenGraphics.drawImage(timeImage[0], secondDLocation[0], secondDLocation[1], this);
                    offScreenGraphics.drawImage(timeImage[0], secondLocation[0], secondLocation[1], this);

                    offScreenGraphics.drawImage(iconsImage[0], iconsLocation[0], iconsLocation[1], this);
                    offScreenGraphics.drawImage(iconsImage[3], iconsLocation[2], iconsLocation[3], this);
                } catch (BasicPlayerException bpe) {
                    log.info("Stream error :" + currentFileOrURL, bpe);
                    showMessage("INVALID FILE");
                } catch (MalformedURLException mue) {
                    log.info("Stream error :" + currentFileOrURL, mue);
                    showMessage("INVALID FILE");
                }

                // Set pan/gain.
                try {
                    theSoundPlayer.setGain(((double) gainValue / (double) maxGain));
                    theSoundPlayer.setPan((float) balanceValue);
                } catch (BasicPlayerException e2) {
                    log.info("Cannot set control", e2);
                }

                playerState = PLAY;
                repaint();
                log.info(titleText);
            }
        }
    }

    /*-----------------------------------*/
    /*-- Pause/Resume the current File --*/
    /*-----------------------------------*/
    else if (e.getActionCommand().equals("Pause")) {
        if (playerState == PLAY) {
            try {
                theSoundPlayer.pause();
            } catch (BasicPlayerException e1) {
                log.error("Cannot pause", e1);
            }
            playerState = PAUSE;
            offScreenGraphics.drawImage(iconsImage[1], iconsLocation[0], iconsLocation[1], this);
            offScreenGraphics.drawImage(iconsImage[4], iconsLocation[2], iconsLocation[3], this);
            repaint();
        } else if (playerState == PAUSE) {
            try {
                theSoundPlayer.resume();
            } catch (BasicPlayerException e1) {
                log.info("Cannot resume", e1);
            }
            playerState = PLAY;
            offScreenGraphics.drawImage(iconsImage[0], iconsLocation[0], iconsLocation[1], this);
            offScreenGraphics.drawImage(iconsImage[3], iconsLocation[2], iconsLocation[3], this);
            repaint();
        }
    }

    /*------------------*/
    /*-- Stop to play --*/
    /*------------------*/
    else if (e.getActionCommand().equals("Stop")) {
        if ((playerState == PAUSE) || (playerState == PLAY)) {
            try {
                theSoundPlayer.stop();
            } catch (BasicPlayerException e1) {
                log.info("Cannot stop", e1);
            }
            playerState = STOP;
            secondsAmount = 0;
            acPosBar.setLocation(posBarBounds[0], posBarLocation[1]);
            offScreenGraphics.drawImage(iconsImage[2], iconsLocation[0], iconsLocation[1], this);
            offScreenGraphics.drawImage(iconsImage[4], iconsLocation[2], iconsLocation[3], this);
            repaint();
        }
    }

    /*----------*/
    /*-- Next --*/
    /*----------*/
    else if (e.getActionCommand().equals("Next")) {
        // Try to get next song from the playlist
        playlist.nextCursor();
        fileList.nextCursor();
        PlaylistItem pli = playlist.getCursor();
        String info = pli.getName();
        info += ", NEXT";
        if (tFrame != null)
            tFrame.addText(info);
        firstSong = false;
        this.setCurrentSong(pli);
    }

    /*--------------*/
    /*-- Previous --*/
    /*--------------*/
    else if (e.getActionCommand().equals("Previous")) {
        // Try to get previous song from the playlist
        playlist.previousCursor();
        fileList.nextCursor();
        PlaylistItem pli = playlist.getCursor();
        String info = pli.getName();
        info += ", PREVIOUS";
        if (tFrame != null)
            tFrame.addText(info);
        firstSong = false;
        this.setCurrentSong(pli);
    }

    /*--------------------------------------------*/
    /*--     Exit window through Exit Button    --*/
    /*--------------------------------------------*/
    else if (e.getActionCommand().equals("Exit")) {
        closePlayer();
    }

    /*----------------------------------------------------*/
    /*--     Minimize window through Minimize Button    --*/
    /*----------------------------------------------------*/
    else if (e.getActionCommand().equals("Minimize")) {
        // Iconify top frame.
        topFrame.setLocation(OrigineX, OrigineY);
        topFrame.setState(Frame.ICONIFIED);
        //topFrame.show();
    }

    /*--------------------------------------------*/
    /*-- Move full window through its Title Bar --*/
    /*--------------------------------------------*/
    else if (e.getActionCommand().equals("TitleBar")) {
        //log.info("X="+acTitle.getMouseX()+" Y="+acTitle.getMouseY());
        if (acTitleBar.isMousePressed() == false)
            FirstDrag = true;
        else {
            int DeltaX = 0;
            int DeltaY = 0;
            if (FirstDrag == false) {
                DeltaX = acTitleBar.getMouseX() - XDrag;
                DeltaY = acTitleBar.getMouseY() - YDrag;
                XDrag = acTitleBar.getMouseX() - DeltaX;
                YDrag = acTitleBar.getMouseY() - DeltaY;
                OrigineX = OrigineX + DeltaX;
                OrigineY = OrigineY + DeltaY;

                if (config.isScreenLimit()) {
                    // Keep player window in screen
                    if (OrigineX < 0)
                        OrigineX = 0;
                    if (OrigineY < 0)
                        OrigineY = 0;
                    if (screenWidth != -1) {
                        if (OrigineX > screenWidth - WinWidth)
                            OrigineX = screenWidth - WinWidth;
                    }
                    if (screenHeight != -1) {
                        if (OrigineY > screenHeight - WinHeight)
                            OrigineY = screenHeight - WinHeight;
                    }
                }
                // Moves top frame.
                topFrame.setLocation(OrigineX, OrigineY);
                topFrame.setSize(0, 0);
                // Moves the main window + playlist
                setLocation(OrigineX, OrigineY);
                fileList.setLocation(OrigineX, OrigineY + WinHeight);
                int factor = 1;
                if (config.isPlaylistEnabled())
                    factor = 2;
                equalizer.setLocation(OrigineX, OrigineY + WinHeight * factor);
            } else {
                FirstDrag = false;
                XDrag = acTitleBar.getMouseX();
                YDrag = acTitleBar.getMouseY();
            }
        }
    }
    /*-----------------------------------------*/
    /*--     Playlist window hide/display    --*/
    /*-----------------------------------------*/
    else if (e.getActionCommand().equals("Playlist")) {
        if (acPlaylist.getCheckboxState()) {
            config.setPlaylistEnabled(true);
            if (config.isEqualizerEnabled()) {
                equalizer.setLocation(OrigineX, OrigineY + WinHeight * 2);
            }
            fileList.setVisible(true);
        } else {
            config.setPlaylistEnabled(false);
            fileList.setVisible(false);
            if (config.isEqualizerEnabled()) {
                equalizer.setLocation(OrigineX, OrigineY + WinHeight);
            }
        }
    }

    /*--------------------------------------*/
    /*--     Playlist window equalizer    --*/
    /*--------------------------------------*/
    else if (e.getActionCommand().equals("Equalizer")) {
        if (acEqualizer.getCheckboxState()) {
            config.setEqualizerEnabled(true);
            int factor = 1;
            if (config.isPlaylistEnabled())
                factor = 2;
            equalizer.setLocation(OrigineX, OrigineY + WinHeight * factor);
            equalizer.setVisible(true);
        } else {
            config.setEqualizerEnabled(false);
            equalizer.setVisible(false);
        }
    }

    /*--------------------*/
    /*--     Shuffle    --*/
    /*--------------------*/
    else if (e.getActionCommand().equals("Shuffle")) {
        if (acShuffle.getCheckboxState()) {
            config.setShuffleEnabled(true);
            if (playlist != null) {
                playlist.shuffle();
                fileList.initPlayList();
                // Play from the top
                PlaylistItem pli = playlist.getCursor();
                this.setCurrentSong(pli);
            }
        } else {
            config.setShuffleEnabled(false);
        }
    }
    /*-------------------*/
    /*--     Repeat    --*/
    /*-------------------*/
    else if (e.getActionCommand().equals("Repeat")) {
        if (acRepeat.getCheckboxState()) {
            config.setRepeatEnabled(true);
        } else {
            config.setRepeatEnabled(false);
        }
    }
    /*----------------------*/
    /*--     Equalizer    --*/
    /*----------------------*/
    else if (e.getActionCommand().equals("Equalizer")) {
        if (acEqualizer.getCheckboxState()) {
            config.setEqualizerEnabled(true);
        } else {
            config.setEqualizerEnabled(false);
        }
    } else if (e.getActionCommand().equals("Load Skin")) {
        Frame f = new Frame("Select a skin");
        f.setLocation(this.getBounds().x, this.getBounds().y + 10);
        FileSelector.setWindow(f);
        String fsFile = FileSelector.selectFile(FileSelector.OPEN, "wsz", config.getLastDir());
        fsFile = FileSelector.getFile();
        String fsDir = FileSelector.getDirectory();
        if ((fsFile != null) && (fsDir != null)) {
            config.setLastDir(fsDir);
            loadSkin(config.getLastDir() + fsFile);
            config.setDefaultSkin(config.getLastDir() + fsFile);
        }
    } else {
        // Unknown action.
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Shows / Hides the Image Window. // ww w  .  j a v  a2  s .  c om
 */
public void setImageFrameVisible(final boolean visible, final JFrame imgFrame, final JButton toolBtn,
        final String ttHelpVisible, final String ttHelpHidden, final String helpContext) {
    if (visible == imgFrame.isVisible()) {
        return;
    }

    if (spreadSheet.getCellEditor() != null) {
        spreadSheet.getCellEditor().stopCellEditing();
    }

    // and add or remove the ListSelectionListener (to avoid loading images when not visible)
    if (!visible) {
        spreadSheet.setTransferHandler(null);

        // hide the image window

        // turn off alwaysOnTop for Swing repaint reasons (prevents a lock up)
        if (imgFrame.isAlwaysOnTop()) {
            imgFrame.setAlwaysOnTop(false);
        }
        // if the image frame is minimized or iconified, set it to fully visible before doing anything else
        if (imgFrame.getState() == Frame.ICONIFIED) {
            imgFrame.setState(Frame.NORMAL);
        }
        toolBtn.setToolTipText(getResourceString(ttHelpVisible));

        spreadSheet.getSelectionModel().removeListSelectionListener(workbenchRowChangeListener);

        // set the image window and the image column invisible
        imgFrame.setVisible(false);
        imageColExt.setVisible(false);
    } else {
        spreadSheet.setTransferHandler(new WBImageTransferable());

        // show the image window

        UIHelper.positionFrameRelativeToTopFrame(imgFrame);

        // when a user hits the "show image" button, for some reason the selection gets nullified
        // so we'll grab it here, then set it at the end of this method

        toolBtn.setToolTipText(getResourceString(ttHelpHidden));

        spreadSheet.getSelectionModel().addListSelectionListener(workbenchRowChangeListener);
        HelpMgr.setHelpID(this, helpContext);

        // set the image window and the image column visible
        imgFrame.setVisible(true);
        imageColExt.setVisible(true);

        // if the image frame is minimized or iconified, set it to fully visible before doing anything else
        if (imgFrame.getState() == Frame.ICONIFIED) {
            imgFrame.setState(Frame.NORMAL);
        }

        showCardImageForSelectedRow();

        // Without this code below the Image Column doesn't get selected
        // when toggling 
        if (currentPanelType == PanelType.Spreadsheet && currentRow != -1) {
            spreadSheet.setRowSelectionInterval(currentRow, currentRow);
            spreadSheet.setColumnSelectionInterval(0, spreadSheet.getColumnCount() - 1);
            spreadSheet.scrollToRow(Math.min(currentRow + 4, model.getRowCount()));
        }

        TableColumn column = spreadSheet.getTableHeader().getColumnModel()
                .getColumn(spreadSheet.getTableHeader().getColumnModel().getColumnCount() - 1);
        column.setCellRenderer(new WbCellRenderer());
        spreadSheet.repaint();
    }
}

From source file:corelyzer.ui.CorelyzerApp.java

@Override
public void windowIconified(final WindowEvent e) {
    // minimize the GL windows
    for (int i = 0; i < windowVec.size(); i++) {
        Window jf;/*from  w ww.  ja v  a2 s.com*/
        jf = windowVec.elementAt(i);
        if (jf != null) {
            jf.setVisible(false);
        }
    }

    // minimize the tool window
    toolFrame.setVisible(false);

    // iconify all plugin frames
    controller.iconifyAllPlugins();

    // 2/28/2012 brg: Unclear why this works, but it does. Possibly because
    // plug-in frame is associated with another thread?
    // to avoid missing application in taskbar under Windows
    if (!MAC_OS_X && usePluginUI) {
        getDefaultMainFrame().setVisible(true);
        getDefaultMainFrame().setExtendedState(Frame.ICONIFIED);
    }
}

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  a2s.  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);
                     
          }*/
}

From source file:net.technicpack.launcher.ui.LauncherFrame.java

protected void minimizeWindow() {
    this.setState(Frame.ICONIFIED);
}

From source file:org.ngrinder.recorder.Recorder.java

/**
 * Initialize global message handlers.//w  ww  .  j  ava2s  .c  o  m
 * 
 * @param tabbedPane
 *            tabbedPane
 */
protected void initMessageHandler(final TabbedPane tabbedPane) {
    final File home = recorderConfig.getHome().getDirectory();
    final MessageBus messageBusInstance = MessageBus.getInstance();
    MessageBusConnection connect = messageBusInstance.connect();
    connect.subscribe(Topics.HOME, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            Browser browser = cast(evt.getSource());
            browser.navigate(toURL(tempFile).toString());
        }
    });
    connect.subscribe(Topics.APPLICATION_CLOSE, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            proxy.stopProxy();
            frame.setExtendedState(Frame.NORMAL);
            File frameInfoFile = recorderConfig.getHome().getFile("last_frame");
            try {
                Pair<Dimension, Point> pair = Pair.of(frame.getSize(), frame.getLocation());
                String frameInfo = gson.toJson(pair);
                FileUtils.writeStringToFile(frameInfoFile, frameInfo);
            } catch (Exception e) {
                LOGGER.error("Failed to save the frame info", e);
            }

            messageBusInstance.getPublisher(Topics.PREPARE_TO_CLOSE)
                    .propertyChange(new PropertyChangeEvent(this, "PREPARE_TO_CLOSE", null, home));

            tabbedPane.disposeAllTabs();
            frame.setVisible(false);
            frame.dispose();

            System.exit(0);
        }
    });
    connect.subscribe(Topics.WINDOW_MAXIMIZE, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (frame.getExtendedState() == Frame.MAXIMIZED_BOTH) {
                frame.setExtendedState(Frame.NORMAL);
            } else {
                frame.setExtendedState(Frame.MAXIMIZED_BOTH);
            }
        }
    });

    connect.subscribe(Topics.WINDOW_MINIMIZE, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (frame.getExtendedState() == Frame.ICONIFIED) {
                frame.setExtendedState(Frame.NORMAL);
            } else {
                frame.setExtendedState(Frame.ICONIFIED);
            }
        }
    });

    connect.subscribe(Topics.SHOW_ABOUT_DIALOG, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            AboutDialog dialog = AboutDialog.getInstance(frame, recorderConfig);
            dialog.setVisible(true);
        }
    });
}

From source file:org.paxle.desktop.impl.DialogueServices.java

private static void show(final Frame frame) {
    final int extstate = frame.getExtendedState();
    if ((extstate & Frame.ICONIFIED) == Frame.ICONIFIED)
        frame.setExtendedState(extstate ^ Frame.ICONIFIED);
    if (!frame.isVisible())
        frame.setVisible(true);/*from  www  .  j  av a  2 s . co m*/
    frame.toFront();
}

From source file:picocash.Picocash.java

@Action
public void minimize() {
    getMainFrame().setState(Frame.ICONIFIED);
}

From source file:pl.edu.icm.visnow.lib.basic.viewers.Viewer2D.Display2DPanel.java

private void showControlsFrame() {
    if (!controlsFrame.isVisible()) {
        controlsFrame.setLocation(parentFrame.getLocation().x + 30, parentFrame.getLocation().y + 30);
        controlsFrame.setTitle(parentFrame.getTitle() + " Controls");
    }//  w  ww. j  av  a 2  s  .c o m

    if ((controlsFrame.getExtendedState() | Frame.ICONIFIED) == Frame.ICONIFIED) {
        controlsFrame.setExtendedState(Frame.NORMAL);
    }

    controlsFrame.setVisible(true);
}

From source file:tvbrowser.TVBrowser.java

private static void initUi(Splash splash, boolean startMinimized) {
    mainFrame = MainFrame.getInstance();
    PluginProxyManager.getInstance().setParentFrame(mainFrame);
    TvDataServiceProxyManager.getInstance().setParamFrame(mainFrame);

    // Set the program icon
    ArrayList<Image> iconImages = new ArrayList<Image>(2);
    iconImages.add(ImageUtilities.createImage("imgs/tvbrowser128.png"));
    iconImages.add(ImageUtilities.createImage("imgs/tvbrowser48.png"));
    iconImages.add(ImageUtilities.createImage("imgs/tvbrowser32.png"));
    iconImages.add(ImageUtilities.createImage("imgs/tvbrowser16.png"));
    mainFrame.setIconImages(iconImages);

    mTray = new SystemTray();

    if (mTray.initSystemTray()) {
        mTray.createMenus();//w  w  w . j  a va 2s .  c  o m
    } else {
        mLog.info("platform independent mode is ON");
        addTrayWindowListener();
    }

    // Set the right size
    mLog.info("Setting frame size and location");

    int windowWidth = Settings.propWindowWidth.getInt();
    int windowHeight = Settings.propWindowHeight.getInt();
    mainFrame.setSize(windowWidth, windowHeight);
    int windowX = Settings.propWindowX.getInt();
    int windowY = Settings.propWindowY.getInt();

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    if ((windowX == -1 && windowY == -1) || windowX + windowWidth < 0 || windowX > screen.width + 10
            || windowY + windowHeight < 0 || windowY > screen.height + 10 || windowWidth < 200
            || windowHeight < 200) {
        UiUtilities.centerAndShow(mainFrame);
    } else {
        mainFrame.setLocation(windowX, windowY);

    }

    mainFrame.setVisible(true);
    ErrorHandler.setFrame(mainFrame);

    splash.hideSplash();

    mainFrame.repaint();

    // maximize the frame if wanted
    if (Settings.propIsWindowMaximized.getBoolean()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                mainFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
            }
        });
    }

    // minimize the frame if wanted
    if (startMinimized) {
        mainFrame.setExtendedState(Frame.ICONIFIED);
    }

    if (mFullscreen || Settings.propIsUsingFullscreen.getBoolean()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                mainFrame.switchFullscreenMode();
            }
        });
    }

    if (Settings.propShowAssistant.getBoolean()) {
        mLog.info("Running setup assistant");
        mainFrame.runSetupAssistant();
    }
}