package old;

///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//
//package scriptbuilder.gui.timeline;
//
//import java.awt.event.MouseEvent;
//import javax.swing.JPanel;
//import javax.swing.event.MouseInputAdapter;
//import scriptbuilder.structures.TimelineSlice;
//import scriptbuilder.structures.ScriptIncident;
//import scriptbuilder.structures.ScriptEvent;
//
///**
// *
// * @author Greg
// */
//public class MouseWatcherPainter extends JPanel
//{
//    private boolean active = true;
//    private int mx, my;
//    private float zoom;
//    private TimelinePanel tp;
//
//    public void setActive(boolean active)
//    {
//        this.active = active;
//    }
//
//    public void setTimelinePanel(TimelinePanel panel)
//    {
//        tp = panel;
//    }
//
//    public void setZoom(float zoom)
//    {
//        this.zoom = zoom;
//    }
//
//    private class TimelineMouseListener extends MouseInputAdapter
//    {
//        @Override
//        public void mouseMoved(MouseEvent e)
//        {
//            // Record the new mouse coordinates
//            int x = e.getX();
//            int y = e.getY();
//
//            setToolTipText("");
//            for (ScriptIncident i : tp.getIncidents())
//            {
//                for (TimelineSlice c : i.slices)
//                {
//                    if (c.getShape().contains(x / zoom, y / zoom))
//                    {
//                        String toolTip = "<html>" + i.name + "@" +
//                                getCursorTimeString(x, zoom);
//                        for (ScriptEvent v : c.events)
//                        {
//                             toolTip += "<br>" + v.getToolTip();
//                        }
//                        toolTip += "</html>";
//                        setToolTipText(toolTip);
//                    }
//                }
//            }
//
//            int snappedY = snapY(my, zoom);
//            if (    active                                                &&
//                    x / zoom > TimelinePanel.TIMELINE_LEFT_PADDING        &&
//                    y / zoom > TimelinePanel.TIMELINE_TOP_PADDING -
//                               TimelinePanel.TIMELINE_VERTICAL_STEP/2     &&
//                    y / zoom <= (TimelinePanel.TIMELINE_TOP_PADDING +
//                                (tp.getIncidents().size()-1) *
//                                TimelinePanel.TIMELINE_VERTICAL_STEP) +
//                                TimelinePanel.TIMELINE_VERTICAL_STEP/2    &&
//                    x / zoom <= tp.getIncidents().get(snappedY /
//                                TimelinePanel.TIMELINE_VERTICAL_STEP).length /
//                                30 * TimelinePanel.TIMELINE_30_SECOND_STEP
//                                + TimelinePanel.TIMELINE_LEFT_PADDING
//               )
//            {
//                mx = x;
//                my = y;
//                tp.setCursorLocation(snapX(mx, zoom), snappedY);
//                tp.setTimeString(getCursorTimeString(mx, zoom));
//                tp.setIncident(snappedY /
//                        TimelinePanel.TIMELINE_VERTICAL_STEP);
//            }
//
//            tp.repaint();
//        }
//
//        @Override
//        public void mouseClicked(MouseEvent e)
//        {
//            mouseMoved(e);
//
//            if (e.getButton() == MouseEvent.BUTTON1)
//            {
//                active = !active;
//
//                tp.setCursorActive(active);
//            }
//            else if (e.getButton() == MouseEvent.BUTTON3)
//            {
//                int snappedY = snapY(my, zoom);
//
//                tp.addIcon(snappedY, new TimelineSlice(snapX(mx, zoom) - 5, snappedY - 10,
//                        TimelinePanel.TIMELINE_30_SECOND_STEP,
//                        TimelinePanel.TIMELINE_30_SECOND_STEP));
//
//                tp.repaint();
//            }
//
//            mouseMoved(e);
//        }
//    }
//
//    public static String getCursorTimeString(int x, float zoom)
//    {
//        int seconds = (((int)((float)x / zoom) -
//            TimelinePanel.TIMELINE_LEFT_PADDING)
//            + (TimelinePanel.TIMELINE_30_SECOND_STEP / 2)) /
//            TimelinePanel.TIMELINE_30_SECOND_STEP * 30;
//        int hours = seconds / 3600;
//        int minutes = seconds / 60 % 60;
//        seconds = seconds % 60;
//
//        return hours + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" +
//             ((seconds == 0) ? "00" : seconds);
//    }
//
//    public MouseWatcherPainter()
//    {
//        super();
//
//        // Add the mouse listener
//        TimelineMouseListener mouseListener = new TimelineMouseListener();
//        addMouseMotionListener(mouseListener);
//        addMouseListener(mouseListener);
//
//        zoom = 1.0f;
//    }
//
//    public static int snapX(int mx, float zoom)
//    {
//        return ( ( (int)((float)mx / zoom) -
//            TimelinePanel.TIMELINE_30_SECOND_STEP / 2 )
//            / TimelinePanel.TIMELINE_30_SECOND_STEP
//            * TimelinePanel.TIMELINE_30_SECOND_STEP) +
//            TimelinePanel.TIMELINE_30_SECOND_STEP;
//    }
//
//    public static int snapY(int my, float zoom)
//    {
//        return ((int)((float)my / zoom) -
//                TimelinePanel.TIMELINE_TOP_PADDING/2) /
//                TimelinePanel.TIMELINE_VERTICAL_STEP *
//                TimelinePanel.TIMELINE_VERTICAL_STEP +
//                TimelinePanel.TIMELINE_TOP_PADDING;
//    }
//}
