From 1e74123cfed4374b403574b6cd16bd8d4e73bf45 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Tue, 10 Jul 2018 22:17:11 -0400 Subject: [PATCH] Refactoring. --- timeflow/views/TimelineView.java | 94 +++++++++++++++++++++++++++++++++++----------- 1 files changed, 71 insertions(+), 23 deletions(-) diff --git a/timeflow/views/TimelineView.java b/timeflow/views/TimelineView.java index 778ece2..06190c6 100755 --- a/timeflow/views/TimelineView.java +++ b/timeflow/views/TimelineView.java @@ -1,21 +1,24 @@ package timeflow.views; import timeflow.app.ui.ComponentCluster; -import timeflow.data.db.*; +import timeflow.app.ui.EditRecordPanel; +import timeflow.data.db.DBUtils; import timeflow.data.time.*; import timeflow.model.*; -import timeflow.views.CalendarView.CalendarPanel; -import timeflow.views.CalendarView.ScrollingCalendar; -import timeflow.vis.*; +//import timeflow.views.CalendarView.CalendarPanel; +//import timeflow.views.CalendarView.ScrollingCalendar; +import timeflow.vis.Mouseover; +import timeflow.vis.TimeScale; +import timeflow.vis.VisualAct; import timeflow.vis.timeline.*; import java.awt.*; import java.awt.event.*; -import java.awt.image.*; +//import java.awt.image.*; import javax.swing.*; -import java.util.*; +import java.util.ArrayList; public class TimelineView extends AbstractView { @@ -67,12 +70,23 @@ // top part of grid: zoom buttons. ComponentCluster buttons = new ComponentCluster("Zoom"); - ImageIcon zoomOutIcon = new ImageIcon("images/zoom_out.gif"); - JButton zoomOut = new JButton(zoomOutIcon); + //ImageIcon zoomOutIcon = new ImageIcon("images/zoom_out.gif"); + JButton zoomIn = new JButton("In 1/2X"); + buttons.addContent(zoomIn); + zoomIn.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + Interval zoom = visuals.getViewInterval().subinterval(0.333, 0.667).intersection(visuals.getGlobalInterval()); + moveTime(zoom); + } + }); + + JButton zoomOut = new JButton("Out 2X"); buttons.addContent(zoomOut); zoomOut.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent e) { @@ -82,7 +96,7 @@ }); ImageIcon zoomOut100Icon = new ImageIcon("images/zoom_out_100.gif"); - JButton zoomOutAll = new JButton(zoomOut100Icon); + JButton zoomOutAll = new JButton("Fit 100%"); buttons.addContent(zoomOutAll); zoomOutAll.addActionListener(new ActionListener() { @@ -221,17 +235,27 @@ public void run() { - int n = 15; + int n = 8; for (int i = 0; i < n; i++) { - long start = ((n - i) * i1.start + i * i2.start) / n; - long end = ((n - i) * i1.end + i * i2.end) / n; + final long start = ((n - i) * i1.start + i * i2.start) / n; + final long end = ((n - i) * i1.end + i * i2.end) / n; try { - visuals.setTimeBounds(start, end); - redraw(); +// visuals.setTimeBounds(start, end); +// redraw(); + SwingUtilities.invokeAndWait(new Runnable() + { + + @Override + public void run() + { + visuals.setTimeBounds(start, end); + redraw(); + } + }); - sleep(20); + //sleep(20); } catch (Exception e) { } @@ -312,7 +336,20 @@ { if (e.getClickCount() == 2) { - moveTime(visuals.getViewInterval().subinterval(.333, .667)); + Point p = new Point(e.getX(), e.getY()); + Mouseover o = find(p); + //moveTime(visuals.getViewInterval().subinterval(.333, .667)); + boolean onAct = o != null && o.thing instanceof VisualAct; + if (onAct) + { + VisualAct v = (VisualAct) o.thing; + selectedAct = v.getAct(); + EditRecordPanel.edit(getModel(), selectedAct); + } else + { + selectedTime = getTime(p); + EditRecordPanel.add(getModel(), selectedTime); + } } } @@ -358,6 +395,11 @@ int a = firstMouse.x; int b = mouse.x; + if (a == b) + { + return; + } + long start = visuals.getTimeScale().toTime(a); long end = visuals.getTimeScale().toTime(b); if (b - a < 0) @@ -397,12 +439,18 @@ @Override public void mouseWheelMoved(MouseWheelEvent e) { - //bar.setValue(bar.getValue() + e.getWheelRotation() * 10); - visuals.scale *= Math.exp(e.getWheelRotation()/10.0); - visuals.scale = visuals.layout(); - //System.out.println(visuals.scale); - timelinePanel.drawVisualization(); - scroller.calibrate(); + if (e.isMetaDown()) + { + visuals.scale *= Math.exp(e.getWheelRotation()/10.0); + visuals.scale = visuals.layout(); + //System.out.println(visuals.scale); + timelinePanel.drawVisualization(); + scroller.calibrate(); + } + else + { + bar.setValue(bar.getValue() + e.getWheelRotation() * 40); + } repaint(); } }); -- Gitblit v1.6.2