source: tmcsimulator-scriptbuilder/branches/ScriptBuilder4/src/old/MouseWatcherPainter.java @ 6

Revision 6, 5.4 KB checked in by jdalbey, 9 years ago (diff)

Add original prototype to branch

Line 
1package old;
2
3///*
4// * To change this template, choose Tools | Templates
5// * and open the template in the editor.
6// */
7//
8//package scriptbuilder.gui.timeline;
9//
10//import java.awt.event.MouseEvent;
11//import javax.swing.JPanel;
12//import javax.swing.event.MouseInputAdapter;
13//import scriptbuilder.structures.TimelineSlice;
14//import scriptbuilder.structures.ScriptIncident;
15//import scriptbuilder.structures.ScriptEvent;
16//
17///**
18// *
19// * @author Greg
20// */
21//public class MouseWatcherPainter extends JPanel
22//{
23//    private boolean active = true;
24//    private int mx, my;
25//    private float zoom;
26//    private TimelinePanel tp;
27//
28//    public void setActive(boolean active)
29//    {
30//        this.active = active;
31//    }
32//
33//    public void setTimelinePanel(TimelinePanel panel)
34//    {
35//        tp = panel;
36//    }
37//
38//    public void setZoom(float zoom)
39//    {
40//        this.zoom = zoom;
41//    }
42//
43//    private class TimelineMouseListener extends MouseInputAdapter
44//    {
45//        @Override
46//        public void mouseMoved(MouseEvent e)
47//        {
48//            // Record the new mouse coordinates
49//            int x = e.getX();
50//            int y = e.getY();
51//
52//            setToolTipText("");
53//            for (ScriptIncident i : tp.getIncidents())
54//            {
55//                for (TimelineSlice c : i.slices)
56//                {
57//                    if (c.getShape().contains(x / zoom, y / zoom))
58//                    {
59//                        String toolTip = "<html>" + i.name + "@" +
60//                                getCursorTimeString(x, zoom);
61//                        for (ScriptEvent v : c.events)
62//                        {
63//                             toolTip += "<br>" + v.getToolTip();
64//                        }
65//                        toolTip += "</html>";
66//                        setToolTipText(toolTip);
67//                    }
68//                }
69//            }
70//
71//            int snappedY = snapY(my, zoom);
72//            if (    active                                                &&
73//                    x / zoom > TimelinePanel.TIMELINE_LEFT_PADDING        &&
74//                    y / zoom > TimelinePanel.TIMELINE_TOP_PADDING -
75//                               TimelinePanel.TIMELINE_VERTICAL_STEP/2     &&
76//                    y / zoom <= (TimelinePanel.TIMELINE_TOP_PADDING +
77//                                (tp.getIncidents().size()-1) *
78//                                TimelinePanel.TIMELINE_VERTICAL_STEP) +
79//                                TimelinePanel.TIMELINE_VERTICAL_STEP/2    &&
80//                    x / zoom <= tp.getIncidents().get(snappedY /
81//                                TimelinePanel.TIMELINE_VERTICAL_STEP).length /
82//                                30 * TimelinePanel.TIMELINE_30_SECOND_STEP
83//                                + TimelinePanel.TIMELINE_LEFT_PADDING
84//               )
85//            {
86//                mx = x;
87//                my = y;
88//                tp.setCursorLocation(snapX(mx, zoom), snappedY);
89//                tp.setTimeString(getCursorTimeString(mx, zoom));
90//                tp.setIncident(snappedY /
91//                        TimelinePanel.TIMELINE_VERTICAL_STEP);
92//            }
93//
94//            tp.repaint();
95//        }
96//
97//        @Override
98//        public void mouseClicked(MouseEvent e)
99//        {
100//            mouseMoved(e);
101//
102//            if (e.getButton() == MouseEvent.BUTTON1)
103//            {
104//                active = !active;
105//
106//                tp.setCursorActive(active);
107//            }
108//            else if (e.getButton() == MouseEvent.BUTTON3)
109//            {
110//                int snappedY = snapY(my, zoom);
111//
112//                tp.addIcon(snappedY, new TimelineSlice(snapX(mx, zoom) - 5, snappedY - 10,
113//                        TimelinePanel.TIMELINE_30_SECOND_STEP,
114//                        TimelinePanel.TIMELINE_30_SECOND_STEP));
115//
116//                tp.repaint();
117//            }
118//
119//            mouseMoved(e);
120//        }
121//    }
122//
123//    public static String getCursorTimeString(int x, float zoom)
124//    {
125//        int seconds = (((int)((float)x / zoom) -
126//            TimelinePanel.TIMELINE_LEFT_PADDING)
127//            + (TimelinePanel.TIMELINE_30_SECOND_STEP / 2)) /
128//            TimelinePanel.TIMELINE_30_SECOND_STEP * 30;
129//        int hours = seconds / 3600;
130//        int minutes = seconds / 60 % 60;
131//        seconds = seconds % 60;
132//
133//        return hours + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" +
134//             ((seconds == 0) ? "00" : seconds);
135//    }
136//
137//    public MouseWatcherPainter()
138//    {
139//        super();
140//
141//        // Add the mouse listener
142//        TimelineMouseListener mouseListener = new TimelineMouseListener();
143//        addMouseMotionListener(mouseListener);
144//        addMouseListener(mouseListener);
145//
146//        zoom = 1.0f;
147//    }
148//
149//    public static int snapX(int mx, float zoom)
150//    {
151//        return ( ( (int)((float)mx / zoom) -
152//            TimelinePanel.TIMELINE_30_SECOND_STEP / 2 )
153//            / TimelinePanel.TIMELINE_30_SECOND_STEP
154//            * TimelinePanel.TIMELINE_30_SECOND_STEP) +
155//            TimelinePanel.TIMELINE_30_SECOND_STEP;
156//    }
157//
158//    public static int snapY(int my, float zoom)
159//    {
160//        return ((int)((float)my / zoom) -
161//                TimelinePanel.TIMELINE_TOP_PADDING/2) /
162//                TimelinePanel.TIMELINE_VERTICAL_STEP *
163//                TimelinePanel.TIMELINE_VERTICAL_STEP +
164//                TimelinePanel.TIMELINE_TOP_PADDING;
165//    }
166//}
Note: See TracBrowser for help on using the repository browser.