/*
 * The MIT License
 *
 * Copyright 2014 mkdr <makedir@gmail.com>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package gui;

import java.awt.AWTException;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author mkdr <makedir@gmail.com>
 */
public class SettingsOverlayGui extends javax.swing.JFrame {

    private GW2EventerGui mainGui;
    
    /**
     * Creates new form SettingsOverlayGui
     */
    public SettingsOverlayGui(GW2EventerGui mainGui) {
        
        this.mainGui = mainGui;
        
        initComponents();
    }

    public void setSound(boolean sound) {
        
        this.jCheckBoxSound.setSelected(sound);
    }
    
    public void setEvents(boolean events) {
        
        this.jCheckBoxEvents.setSelected(events);
    }
    
    public void setWvW(boolean wvw) {
        
        this.jCheckBoxWvW.setEnabled(true);
        this.jCheckBoxWvW.setSelected(wvw);
    }
    
    public void setWvWEnabled(boolean enabled) {
        
        this.jCheckBoxWvW.setEnabled(enabled);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelMenu = new javax.swing.JLabel();
        jToolBarMenu = new javax.swing.JToolBar();
        jLabel1 = new javax.swing.JLabel();
        jCheckBoxEvents = new javax.swing.JCheckBox();
        jCheckBoxSound = new javax.swing.JCheckBox();
        jCheckBoxWvW = new javax.swing.JCheckBox();
        jButtonMove = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setAlwaysOnTop(true);
        setFocusable(false);
        setFocusableWindowState(false);
        setUndecorated(true);
        setPreferredSize(new java.awt.Dimension(400, 50));
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabelMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/media/settings.png"))); // NOI18N
        jLabelMenu.setToolTipText("Menu");
        jLabelMenu.setFocusable(false);
        jLabelMenu.setInheritsPopupMenu(false);
        jLabelMenu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jLabelMenuMousePressed(evt);
            }
        });
        getContentPane().add(jLabelMenu, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 20, -1, -1));

        jToolBarMenu.setFloatable(false);
        jToolBarMenu.setBorderPainted(false);
        jToolBarMenu.setFocusable(false);
        jToolBarMenu.setOpaque(false);
        jToolBarMenu.setRequestFocusEnabled(false);

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Settings ");
        jToolBarMenu.add(jLabel1);

        jCheckBoxEvents.setForeground(new java.awt.Color(255, 255, 255));
        jCheckBoxEvents.setText("Events ");
        jCheckBoxEvents.setFocusable(false);
        jCheckBoxEvents.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jCheckBoxEvents.setOpaque(false);
        jCheckBoxEvents.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jCheckBoxEvents.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxEventsActionPerformed(evt);
            }
        });
        jToolBarMenu.add(jCheckBoxEvents);

        jCheckBoxSound.setForeground(new java.awt.Color(255, 255, 255));
        jCheckBoxSound.setSelected(true);
        jCheckBoxSound.setText("Sounds ");
        jCheckBoxSound.setFocusable(false);
        jCheckBoxSound.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jCheckBoxSound.setOpaque(false);
        jCheckBoxSound.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jCheckBoxSound.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxSoundActionPerformed(evt);
            }
        });
        jToolBarMenu.add(jCheckBoxSound);

        jCheckBoxWvW.setForeground(new java.awt.Color(255, 255, 255));
        jCheckBoxWvW.setText("WvW ");
        jCheckBoxWvW.setToolTipText("");
        jCheckBoxWvW.setEnabled(false);
        jCheckBoxWvW.setFocusable(false);
        jCheckBoxWvW.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jCheckBoxWvW.setOpaque(false);
        jCheckBoxWvW.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jCheckBoxWvW.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxWvWActionPerformed(evt);
            }
        });
        jToolBarMenu.add(jCheckBoxWvW);

        jButtonMove.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jButtonMove.setForeground(new java.awt.Color(255, 255, 255));
        jButtonMove.setText("move");
        jButtonMove.setFocusable(false);
        jButtonMove.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonMove.setOpaque(false);
        jButtonMove.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonMove.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                jButtonMoveMouseDragged(evt);
            }
        });
        jToolBarMenu.add(jButtonMove);

        getContentPane().add(jToolBarMenu, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 320, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jLabelMenuMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelMenuMousePressed

        if (this.jToolBarMenu.isVisible()) {
            this.jToolBarMenu.setVisible(false);
        } else {
            this.jToolBarMenu.setVisible(true);
        }
    }//GEN-LAST:event_jLabelMenuMousePressed

    private void jCheckBoxSoundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxSoundActionPerformed

        this.mainGui.setSoundPlaying(this.jCheckBoxSound.isSelected());
    }//GEN-LAST:event_jCheckBoxSoundActionPerformed

    private void jCheckBoxEventsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxEventsActionPerformed
        
        this.mainGui.setOverlayVisible(this.jCheckBoxEvents.isSelected());
    }//GEN-LAST:event_jCheckBoxEventsActionPerformed

    private void jCheckBoxWvWActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxWvWActionPerformed

        this.mainGui.setWvWOverlayVisible(this.jCheckBoxWvW.isSelected());
    }//GEN-LAST:event_jCheckBoxWvWActionPerformed

    private void jButtonMoveMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonMoveMouseDragged

        int x = this.getX();
        int y = this.getY();

        Point mouseLoc;
        Robot rob;

        try {
            rob = new Robot();
            mouseLoc = MouseInfo.getPointerInfo().getLocation();
            
            int newx = mouseLoc.x - 250;
            int newy = mouseLoc.y - 11;
            
            if (x <= 0) {
                newx = 20;
            }

            if (x >= 1620) {
                newx = 1600;
            }

            if (y <= 0) {
                newy = 20;
            }

            if (y >= 1050) {
                newy = 1030;
            }
            
            this.setLocation(newx, newy);
        } catch (AWTException ex) {
            Logger.getLogger(OverlayGui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButtonMoveMouseDragged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonMove;
    private javax.swing.JCheckBox jCheckBoxEvents;
    private javax.swing.JCheckBox jCheckBoxSound;
    private javax.swing.JCheckBox jCheckBoxWvW;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelMenu;
    private javax.swing.JToolBar jToolBarMenu;
    // End of variables declaration//GEN-END:variables
}
