| .. | .. |
|---|
| 1 | 1 | package timeflow.views; |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | import timeflow.app.ui.ComponentCluster; |
|---|
| 4 | | -import timeflow.data.db.*; |
|---|
| 4 | +import timeflow.app.ui.EditRecordPanel; |
|---|
| 5 | +import timeflow.data.db.DBUtils; |
|---|
| 5 | 6 | import timeflow.data.time.*; |
|---|
| 6 | 7 | import timeflow.model.*; |
|---|
| 7 | | -import timeflow.views.CalendarView.CalendarPanel; |
|---|
| 8 | | -import timeflow.views.CalendarView.ScrollingCalendar; |
|---|
| 9 | | -import timeflow.vis.*; |
|---|
| 8 | + |
|---|
| 9 | +//import timeflow.views.CalendarView.CalendarPanel; |
|---|
| 10 | +//import timeflow.views.CalendarView.ScrollingCalendar; |
|---|
| 11 | +import timeflow.vis.Mouseover; |
|---|
| 12 | +import timeflow.vis.TimeScale; |
|---|
| 13 | +import timeflow.vis.VisualAct; |
|---|
| 10 | 14 | import timeflow.vis.timeline.*; |
|---|
| 11 | 15 | |
|---|
| 12 | 16 | import java.awt.*; |
|---|
| 13 | 17 | import java.awt.event.*; |
|---|
| 14 | | -import java.awt.image.*; |
|---|
| 18 | +//import java.awt.image.*; |
|---|
| 15 | 19 | |
|---|
| 16 | 20 | import javax.swing.*; |
|---|
| 17 | 21 | |
|---|
| 18 | | -import java.util.*; |
|---|
| 22 | +import java.util.ArrayList; |
|---|
| 19 | 23 | |
|---|
| 20 | 24 | public class TimelineView extends AbstractView |
|---|
| 21 | 25 | { |
|---|
| .. | .. |
|---|
| 34 | 38 | return controls; |
|---|
| 35 | 39 | } |
|---|
| 36 | 40 | |
|---|
| 37 | | - public TimelineView(TFModel model) |
|---|
| 41 | + public TimelineView(TimeflowModel model) |
|---|
| 38 | 42 | { |
|---|
| 39 | 43 | super(model); |
|---|
| 44 | + |
|---|
| 40 | 45 | visuals = new TimelineVisuals(model); |
|---|
| 41 | 46 | grid = new AxisRenderer(visuals); |
|---|
| 42 | 47 | timeline = new TimelineRenderer(visuals); |
|---|
| .. | .. |
|---|
| 52 | 57 | |
|---|
| 53 | 58 | TimelineSlider slider = new TimelineSlider(visuals, 24 * 60 * 60 * 1000L, new Runnable() |
|---|
| 54 | 59 | { |
|---|
| 55 | | - |
|---|
| 56 | 60 | @Override |
|---|
| 57 | 61 | public void run() |
|---|
| 58 | 62 | { |
|---|
| 59 | 63 | redraw(); |
|---|
| 60 | 64 | } |
|---|
| 61 | 65 | }); |
|---|
| 66 | + |
|---|
| 62 | 67 | bottom.add(slider, BorderLayout.CENTER); |
|---|
| 63 | 68 | |
|---|
| 64 | 69 | controls = new JPanel(); |
|---|
| 65 | | - controls.setBackground(Color.white); |
|---|
| 70 | + controls.setBackground(Color.red); |
|---|
| 66 | 71 | controls.setLayout(new BorderLayout());//new GridLayout(2,1)); |
|---|
| 67 | 72 | |
|---|
| 68 | 73 | // top part of grid: zoom buttons. |
|---|
| 69 | 74 | ComponentCluster buttons = new ComponentCluster("Zoom"); |
|---|
| 70 | | - ImageIcon zoomOutIcon = new ImageIcon("images/zoom_out.gif"); |
|---|
| 71 | | - JButton zoomOut = new JButton(zoomOutIcon); |
|---|
| 75 | + |
|---|
| 76 | + //ImageIcon zoomOutIcon = new ImageIcon("images/zoom_out.gif"); |
|---|
| 77 | + JButton zoomIn = new JButton("In 1/2X"); |
|---|
| 78 | + buttons.addContent(zoomIn); |
|---|
| 79 | + zoomIn.addActionListener(new ActionListener() |
|---|
| 80 | + { |
|---|
| 81 | + @Override |
|---|
| 82 | + public void actionPerformed(ActionEvent e) |
|---|
| 83 | + { |
|---|
| 84 | + Interval zoom = visuals.getViewInterval().subinterval(0.333, 0.667).intersection(visuals.getGlobalInterval()); |
|---|
| 85 | + moveTime(zoom); |
|---|
| 86 | + } |
|---|
| 87 | + }); |
|---|
| 88 | + |
|---|
| 89 | + JButton zoomOut = new JButton("Out 2X"); |
|---|
| 72 | 90 | buttons.addContent(zoomOut); |
|---|
| 73 | 91 | zoomOut.addActionListener(new ActionListener() |
|---|
| 74 | 92 | { |
|---|
| 75 | | - |
|---|
| 76 | 93 | @Override |
|---|
| 77 | 94 | public void actionPerformed(ActionEvent e) |
|---|
| 78 | 95 | { |
|---|
| .. | .. |
|---|
| 82 | 99 | }); |
|---|
| 83 | 100 | |
|---|
| 84 | 101 | ImageIcon zoomOut100Icon = new ImageIcon("images/zoom_out_100.gif"); |
|---|
| 85 | | - JButton zoomOutAll = new JButton(zoomOut100Icon); |
|---|
| 102 | + JButton zoomOutAll = new JButton("Fit 100%"); |
|---|
| 86 | 103 | buttons.addContent(zoomOutAll); |
|---|
| 87 | 104 | zoomOutAll.addActionListener(new ActionListener() |
|---|
| 88 | 105 | { |
|---|
| .. | .. |
|---|
| 109 | 126 | moveTime(visuals.getFitToVisibleRange()); |
|---|
| 110 | 127 | }}); |
|---|
| 111 | 128 | */ |
|---|
| 112 | | - controls.add(buttons, BorderLayout.NORTH); |
|---|
| 129 | + controls.add(buttons, BorderLayout.SOUTH); |
|---|
| 113 | 130 | |
|---|
| 114 | 131 | // ok, now do second part of grid: layout style buttons. |
|---|
| 115 | 132 | ComponentCluster layoutPanel = new ComponentCluster("Layout"); |
|---|
| .. | .. |
|---|
| 137 | 154 | graph.addActionListener(new LayoutSetter(TimelineVisuals.Layout.GRAPH)); |
|---|
| 138 | 155 | layoutGroup.add(graph); |
|---|
| 139 | 156 | |
|---|
| 140 | | - controls.add(layoutPanel, BorderLayout.CENTER); |
|---|
| 157 | + //controls.add(layoutPanel, BorderLayout.CENTER); |
|---|
| 141 | 158 | } |
|---|
| 142 | 159 | |
|---|
| 143 | 160 | class LayoutSetter implements ActionListener |
|---|
| .. | .. |
|---|
| 221 | 238 | |
|---|
| 222 | 239 | public void run() |
|---|
| 223 | 240 | { |
|---|
| 224 | | - int n = 15; |
|---|
| 241 | + int n = 8; |
|---|
| 225 | 242 | for (int i = 0; i < n; i++) |
|---|
| 226 | 243 | { |
|---|
| 227 | | - long start = ((n - i) * i1.start + i * i2.start) / n; |
|---|
| 228 | | - long end = ((n - i) * i1.end + i * i2.end) / n; |
|---|
| 244 | + final long start = ((n - i) * i1.start + i * i2.start) / n; |
|---|
| 245 | + final long end = ((n - i) * i1.end + i * i2.end) / n; |
|---|
| 229 | 246 | try |
|---|
| 230 | 247 | { |
|---|
| 231 | | - visuals.setTimeBounds(start, end); |
|---|
| 232 | | - redraw(); |
|---|
| 248 | +// visuals.setTimeBounds(start, end); |
|---|
| 249 | +// redraw(); |
|---|
| 250 | + SwingUtilities.invokeAndWait(new Runnable() |
|---|
| 251 | + { |
|---|
| 252 | + |
|---|
| 253 | + @Override |
|---|
| 254 | + public void run() |
|---|
| 255 | + { |
|---|
| 256 | + visuals.setTimeBounds(start, end); |
|---|
| 257 | + redraw(); |
|---|
| 258 | + } |
|---|
| 259 | + }); |
|---|
| 233 | 260 | |
|---|
| 234 | | - sleep(20); |
|---|
| 261 | + //sleep(20); |
|---|
| 235 | 262 | } catch (Exception e) |
|---|
| 236 | 263 | { |
|---|
| 237 | 264 | } |
|---|
| .. | .. |
|---|
| 301 | 328 | |
|---|
| 302 | 329 | class TimelinePanel extends AbstractVisualizationView |
|---|
| 303 | 330 | { |
|---|
| 304 | | - public TimelinePanel(TFModel model) |
|---|
| 331 | + public TimelinePanel(TimeflowModel model) |
|---|
| 305 | 332 | { |
|---|
| 306 | 333 | super(model); |
|---|
| 307 | 334 | |
|---|
| .. | .. |
|---|
| 312 | 339 | { |
|---|
| 313 | 340 | if (e.getClickCount() == 2) |
|---|
| 314 | 341 | { |
|---|
| 315 | | - moveTime(visuals.getViewInterval().subinterval(.333, .667)); |
|---|
| 342 | + Point p = new Point(e.getX(), e.getY()); |
|---|
| 343 | + Mouseover o = find(p); |
|---|
| 344 | + //moveTime(visuals.getViewInterval().subinterval(.333, .667)); |
|---|
| 345 | + boolean onAct = o != null && o.thing instanceof VisualAct; |
|---|
| 346 | + if (onAct) |
|---|
| 347 | + { |
|---|
| 348 | + VisualAct v = (VisualAct) o.thing; |
|---|
| 349 | + selectedAct = v.getAct(); |
|---|
| 350 | + EditRecordPanel.edit(getModel(), selectedAct); |
|---|
| 351 | + } else |
|---|
| 352 | + { |
|---|
| 353 | + selectedTime = getTime(p); |
|---|
| 354 | + EditRecordPanel.add(getModel(), selectedTime); |
|---|
| 355 | + } |
|---|
| 316 | 356 | } |
|---|
| 317 | 357 | } |
|---|
| 318 | 358 | |
|---|
| .. | .. |
|---|
| 358 | 398 | int a = firstMouse.x; |
|---|
| 359 | 399 | int b = mouse.x; |
|---|
| 360 | 400 | |
|---|
| 401 | + if (a == b) |
|---|
| 402 | + { |
|---|
| 403 | + return; |
|---|
| 404 | + } |
|---|
| 405 | + |
|---|
| 361 | 406 | long start = visuals.getTimeScale().toTime(a); |
|---|
| 362 | 407 | long end = visuals.getTimeScale().toTime(b); |
|---|
| 363 | 408 | if (b - a < 0) |
|---|
| .. | .. |
|---|
| 397 | 442 | @Override |
|---|
| 398 | 443 | public void mouseWheelMoved(MouseWheelEvent e) |
|---|
| 399 | 444 | { |
|---|
| 400 | | - //bar.setValue(bar.getValue() + e.getWheelRotation() * 10); |
|---|
| 401 | | - visuals.scale *= Math.exp(e.getWheelRotation()/10.0); |
|---|
| 402 | | - visuals.scale = visuals.layout(); |
|---|
| 403 | | - //System.out.println(visuals.scale); |
|---|
| 404 | | - timelinePanel.drawVisualization(); |
|---|
| 405 | | - scroller.calibrate(); |
|---|
| 445 | + if (e.isMetaDown()) |
|---|
| 446 | + { |
|---|
| 447 | + visuals.scale *= Math.exp(e.getWheelRotation()/10.0); |
|---|
| 448 | + visuals.scale = visuals.layout(); |
|---|
| 449 | + //System.out.println(visuals.scale); |
|---|
| 450 | + timelinePanel.drawVisualization(); |
|---|
| 451 | + scroller.calibrate(); |
|---|
| 452 | + } |
|---|
| 453 | + else |
|---|
| 454 | + { |
|---|
| 455 | + bar.setValue(bar.getValue() + e.getWheelRotation() * 40); |
|---|
| 456 | + } |
|---|
| 406 | 457 | repaint(); |
|---|
| 407 | 458 | } |
|---|
| 408 | 459 | }); |
|---|