Example usage for java.awt Frame Frame

List of usage examples for java.awt Frame Frame

Introduction

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

Prototype

public Frame() throws HeadlessException 

Source Link

Document

Constructs a new instance of Frame that is initially invisible.

Usage

From source file:forseti.JUtil.java

public static synchronized Image generarImagenMensaje(String mensaje, String nombreFuente, int tamanioFuente) {
    Frame f = new Frame();
    f.addNotify();//from ww  w .j av a  2 s.  c  o  m
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    env.getAvailableFontFamilyNames();
    Font fuente = new Font(nombreFuente, Font.PLAIN, tamanioFuente);
    FontMetrics medidas = f.getFontMetrics(fuente);
    int anchoMensaje = medidas.stringWidth(mensaje);
    int lineaBaseX = anchoMensaje / 10;
    int ancho = anchoMensaje + 2 * (lineaBaseX + tamanioFuente);
    int alto = tamanioFuente * 7 / 2;
    int lineaBaseY = alto * 8 / 10;
    Image imagenMensaje = f.createImage(ancho, alto);
    Graphics2D g2d = (Graphics2D) imagenMensaje.getGraphics();
    g2d.setFont(fuente);
    g2d.translate(lineaBaseX, lineaBaseY);
    g2d.setPaint(Color.lightGray);
    AffineTransform origTransform = g2d.getTransform();
    g2d.shear(-0.95, 0);
    g2d.scale(1, 3);
    g2d.drawString(mensaje, 0, 0);
    g2d.setTransform(origTransform);
    g2d.setPaint(Color.black);
    g2d.drawString(mensaje, 0, 0);

    return (imagenMensaje);
}

From source file:pipeline.GUI_utils.ListOfPointsView.java

private void reloadUserFormulasFromFile() {
    FileDialog dialog = new FileDialog(new Frame(), "Choose a tab-separated file to load formulas from.",
            FileDialog.LOAD);//from  w w  w. j av  a2s .c  om
    dialog.setVisible(true);
    String filePath = dialog.getDirectory();
    if (filePath == null)
        return;
    filePath += "/" + dialog.getFile();

    silenceUpdates.incrementAndGet();

    try (BufferedReader r = new BufferedReader(new FileReader(filePath))) {
        List<Integer> userColumns = getUserColumnList();
        int nUserColumns = userColumns.size();
        int row = 0;
        boolean firstLine = true;// the first line contains column names
        while (true) {
            String line = r.readLine();
            if (line == null)
                break;
            StringTokenizer stok = new java.util.StringTokenizer(line);

            int currentColumn = 0;
            while (stok.hasMoreTokens()) {
                String element = stok.nextToken("\t");
                if (firstLine) {
                    // name columns
                    tableModel.setColumnName(userColumns.get(currentColumn), element);
                    modelForColumnDescriptions.setValueAt(element, 0, userColumns.get(currentColumn));
                } else {
                    SpreadsheetCell cell = (SpreadsheetCell) tableModel.getValueAt(row,
                            userColumns.get(currentColumn));
                    if (cell == null) {
                        cell = new SpreadsheetCell("", "", new Object[] { "", element }, true, this, null);
                        tableModel.setValueAt(cell, row, userColumns.get(currentColumn));
                    } else {
                        cell.setFormula(element);
                    }
                }
                currentColumn++;
                if (currentColumn == nUserColumns) {
                    Utils.log("File has more columns than user columns; discarding remaining columns from file",
                            LogLevel.WARNING);
                    break;
                }
            }
            if (!firstLine)
                row++;
            else
                firstLine = false;
        }
    } catch (IOException e) {
        Utils.printStack(e);
    } finally {
        silenceUpdates.decrementAndGet();
    }

    tableModel.fireTableStructureChanged();
    setSpreadsheetColumnEditorAndRenderer();
}

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:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Manages events./* ww  w.  ja va2  s  . com*/
 */
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;
            if (location != NONE) {
                // Local File.
                // E.B : FileSelector added as M.S did.
                if (acEject.getMouseButton() == MouseEvent.BUTTON1_MASK) {
                    String fsFile = null;
                    if (location == ALL) {
                        Frame f = new Frame();
                        f.setLocation(this.getBounds().x, this.getBounds().y + 10);
                        FileSelector.setWindow(f);
                        fsFile = FileSelector.selectFile(FileSelector.OPEN, config.getExtensions(),
                                config.getLastDir());
                        fsFile = FileSelector.getFile();
                    } else if (location == URL) {
                        UrlDialog UD = new UrlDialog("Open location", this.getBounds().x,
                                this.getBounds().y + 10, 280, 120, config.getLastURL());
                        UD.show();
                        if (UD.getFile() != null) {
                            config.setLastURL(UD.getURL());
                            fsFile = UD.getURL();
                        }
                    }
                    if (fsFile != null) {
                        if (location == ALL)
                            config.setLastDir(FileSelector.getDirectory());
                        else
                            config.setLastDir("");
                        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 {
                                if (location == ALL)
                                    pli = new PlaylistItem(fsFile, config.getLastDir() + fsFile, -1, true);
                                else
                                    pli = new PlaylistItem(fsFile, fsFile, -1, false);
                            }
                        }
                    }
                }
                // 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();
            }
            this.setCurrentSong(pli);
            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();
        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();
        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 {
        // Unknown action.
    }
}

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void songDeleteDB() throws SQLException, BasicPlayerException, IOException {
        int[] songLocations = songData_Table.getSelectedRows();
        String deleteLocation;/*w  ww  .  jav a  2 s .co  m*/

        ArrayUtils.reverse(songLocations);
        int currentlyPlaying = 0;
        for (int temp : songLocations) {
            deleteLocation = songData[temp];
            for (ObjectBean list1 : list) {
                if (deleteLocation.equals(list1.getMpg().songLocation)) {
                    currentlyPlaying = 1;
                }
            }
            if (currentlyPlaying != 0) {
                int reply = JOptionPane.showConfirmDialog(new Frame(),
                        "Song is currently playing. \n Do you still want to delete it from library?", "Delete file",
                        JOptionPane.YES_NO_OPTION);
                if (reply == JOptionPane.YES_OPTION) {
                    if (lastOpen.equals("library")) {
                        sd.deleteSong(deleteLocation, temp, columnName);
                        for (ObjectBean list1 : list) {
                            list1.getMpg().addJmenuItemsToRecentSongs();
                        }
                    } else {
                        sd.deleteSongWhenNotLibrary(deleteLocation);
                        for (ObjectBean list1 : list) {
                            list1.getMpg().addJmenuItemsToRecentSongs();
                        }
                    }
                    for (ObjectBean list1 : list) {
                        if (deleteLocation.equals(list1.getMpg().songLocation)) {
                            list1.getMpg().stop();
                            list1.getMpg().setDefaultClipArt();
                            list1.getMpg().songLocation = null;
                            list1.getMpg().songLabel.setText("No Song");
                            list1.getMpg().totaltimeLabel.setText("00:00:00");
                        }
                    }
                }
            } else {
                if (lastOpen.equals("library")) {
                    sd.deleteSong(deleteLocation, temp, columnName);
                    for (ObjectBean list1 : list) {
                        list1.getMpg().addJmenuItemsToRecentSongs();
                    }
                } else {
                    sd.deleteSongWhenNotLibrary(deleteLocation);
                    for (ObjectBean list1 : list) {
                        list1.getMpg().addJmenuItemsToRecentSongs();
                    }
                }
            }

        }

        for (ObjectBean list1 : list) {
            if (!list1.getTitle().equals("library")) {
                list1.getMpg().getSongTable(list1.getTitle());
            } else {
                list1.getMpg().getSongTable(list1.getLastOpen());
            }
        }
    }