ItEr17S07RFComportamentoGraficoPlanificadorItEr16S09: Auto adjust horizontal scroll position when changing zoom level

This commit is contained in:
Lorenzo Tilve 2009-07-14 00:26:39 +02:00 committed by Javier Moran Rua
parent 6620329c55
commit 104b0be12d
10 changed files with 129 additions and 22 deletions

View file

@ -1,6 +1,9 @@
package org.zkoss.ganttz;
import org.zkoss.ganttz.util.DependencyRegistry;
import org.zkoss.zk.au.AuRequest;
import org.zkoss.zk.au.Command;
import org.zkoss.zk.au.ComponentCommand;
import org.zkoss.zk.ui.ext.AfterCompose;
import org.zkoss.zul.impl.XulElement;
@ -16,7 +19,7 @@ public class GanttPanel extends XulElement implements AfterCompose {
public GanttPanel(DependencyRegistry dependencyRegistry) {
this.dependencyRegistry = dependencyRegistry;
timeTracker = new TimeTracker();
timeTracker = new TimeTracker(this);
appendChild(timeTracker);
tasksLists = TaskList.createFor(dependencyRegistry.getTopLevelTasks());
dependencyList = new DependencyList();
@ -49,4 +52,36 @@ public class GanttPanel extends XulElement implements AfterCompose {
return (Planner) getParent();
}
private Command _onincreasecmd = new ComponentCommand("onIncrease", 0) {
protected void process(AuRequest request) {
String[] requestData = request.getData();
int offset = Integer.parseInt(requestData[0]);
getTimeTracker().onIncrease(offset);
}
};
private Command _ondecreasecmd = new ComponentCommand("onDecrease", 0) {
protected void process(AuRequest request) {
String[] requestData = request.getData();
int offset = Integer.parseInt(requestData[0]);
getTimeTracker().onDecrease(offset);
}
};
public Command getCommand(String cmdId) {
Command c = null;
if ("onIncrease".equals(cmdId))
c = _onincreasecmd;
else if ("onDecrease".equals(cmdId))
c = _ondecreasecmd;
return c;
}
}

View file

@ -16,6 +16,7 @@ import org.zkoss.ganttz.util.zoom.TimeTrackerState;
import org.zkoss.ganttz.util.zoom.ZoomLevel;
import org.zkoss.ganttz.util.zoom.ZoomLevelChangedListener;
import org.zkoss.ganttz.util.zoom.TimeTrackerState.DetailItem;
import org.zkoss.zk.au.out.AuInvoke;
import org.zkoss.zk.ui.HtmlMacroComponent;
/**
@ -29,8 +30,6 @@ public class TimeTracker extends HtmlMacroComponent {
.year(2012));
}
// private AbstractComponent fakeRow;
private List<WeakReference<ZoomLevelChangedListener>> zoomListeners = new LinkedList<WeakReference<ZoomLevelChangedListener>>();
private DatesMapper datesMapper = null;
@ -41,7 +40,14 @@ public class TimeTracker extends HtmlMacroComponent {
private ZoomLevel detailLevel;
public TimeTracker() {
private final GanttPanel ganttPanel;
public GanttPanel getGanttPanel() {
return ganttPanel;
}
public TimeTracker(GanttPanel ganttPanel) {
this.ganttPanel = ganttPanel;
this.detailLevel = ZoomLevel.DETAIL_ONE;
}
@ -50,6 +56,11 @@ public class TimeTracker extends HtmlMacroComponent {
.add(new WeakReference<ZoomLevelChangedListener>(listener));
}
public void scrollHorizontalPercentage(int displacement) {
response("scroll_horizontal", new AuInvoke(this.getParent(),
"scroll_horizontal", "" + displacement));
}
private void fireZoomChanged(ZoomLevel detailLevel) {
ListIterator<WeakReference<ZoomLevelChangedListener>> listIterator = zoomListeners
.listIterator();
@ -98,21 +109,26 @@ public class TimeTracker extends HtmlMacroComponent {
return result;
}
public void onIncrease() {
changeDetailLevel(getDetailLevel().next());
public void onIncrease(int offset) {
changeDetailLevel(getDetailLevel().next(), offset
* getDetailLevel().getTimeTrackerState().pixelsPerDay());
}
private void changeDetailLevel(ZoomLevel d) {
public void onDecrease(int offset) {
changeDetailLevel(getDetailLevel().previous(), offset
* getDetailLevel().getTimeTrackerState().pixelsPerDay());
}
private void changeDetailLevel(ZoomLevel d, double days) {
this.detailLevel = d;
datesMapper = null;
detailsFirstLevelCached = null;
detailsSecondLevelCached = null;
recreate();
fireZoomChanged(d);
}
public void onDecrease() {
changeDetailLevel(getDetailLevel().previous());
scrollHorizontalPercentage((int) Math.floor(days
/ d.getTimeTrackerState().pixelsPerDay()));
}
private ZoomLevel getDetailLevel() {
@ -127,4 +143,4 @@ public class TimeTracker extends HtmlMacroComponent {
return datesMapper;
}
}
}

View file

@ -13,6 +13,7 @@ import org.zkoss.ganttz.util.Interval;
/**
* Zoom level for weeks in the first level and days in the second level
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
*/
public class DetailFiveTimeTrackerState extends TimeTrackerStateUsingJodaTime {
@ -22,6 +23,10 @@ public class DetailFiveTimeTrackerState extends TimeTrackerStateUsingJodaTime {
public static final DetailFiveTimeTrackerState INSTANCE = new DetailFiveTimeTrackerState();
public final double pixelsPerDay() {
return ((double) 1 / SECOND_LEVEL_SIZE);
}
private DetailFiveTimeTrackerState() {
}

View file

@ -9,6 +9,7 @@ import org.joda.time.Weeks;
/**
* Zoom level for months and years and weeks in the second level
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
*/
public class DetailFourTimeTrackerState extends TimeTrackerStateUsingJodaTime {
@ -17,6 +18,10 @@ public class DetailFourTimeTrackerState extends TimeTrackerStateUsingJodaTime {
private static final int FIRST_LEVEL_SIZE = 200;
private static final int SECOND_LEVEL_SIZE = 50;
public final double pixelsPerDay() {
return ((double) 7 / SECOND_LEVEL_SIZE);
}
@Override
protected IDetailItemCreator getDetailItemCreatorFirstLevel() {
return new IDetailItemCreator() {

View file

@ -9,13 +9,12 @@ import java.util.Collection;
import java.util.Vector;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.zkoss.ganttz.util.Interval;
/**
*
* Zoom level with years in the first level and semesters in the second level
* @author Francisco Javier Moran Rúa
*
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
*/
public class DetailOneTimeTrackerState extends TimeTrackerState {
@ -23,6 +22,10 @@ public class DetailOneTimeTrackerState extends TimeTrackerState {
private static final int FIRST_LEVEL_ITEM_SIZE = 200;
private static final int SECOND_LEVEL_ITEM_SIZE = 100;
public final double pixelsPerDay() {
return ((double) 365 / FIRST_LEVEL_ITEM_SIZE);
}
private DetailOneTimeTrackerState() {
};

View file

@ -9,6 +9,7 @@ import org.zkoss.util.Locales;
/**
* Zoom level with semesters in the first level and months in the second level
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
*/
public class DetailThreeTimeTrackerState extends TimeTrackerStateUsingJodaTime {
@ -17,6 +18,10 @@ public class DetailThreeTimeTrackerState extends TimeTrackerStateUsingJodaTime {
private static final int FIRST_LEVEL_SIZE = 300;
protected static final int SECOND_LEVEL_SIZE = 50;
public final double pixelsPerDay() {
return ((double) 182.5 / FIRST_LEVEL_SIZE);
}
private DetailThreeTimeTrackerState() {
}

View file

@ -1,8 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.zkoss.ganttz.util.zoom;
import java.util.ArrayList;
@ -15,7 +10,9 @@ import org.joda.time.DateTime;
import org.zkoss.ganttz.util.Interval;
/**
* Zoom level with years in the first level and quarters in the second level
* @author Francisco Javier Moran Rúa
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
*/
public class DetailTwoTimeTrackerState extends TimeTrackerState {
@ -23,6 +20,10 @@ public class DetailTwoTimeTrackerState extends TimeTrackerState {
private static final int FIRST_LEVEL_ITEM_SIZE = 400;
private static final int SECOND_LEVEL_ITEM_SIZE = 100;
public final double pixelsPerDay() {
return ((double) 365 / FIRST_LEVEL_ITEM_SIZE);
}
public Interval getRealIntervalFor(Interval interval) {
int[] pairYears = calculateInitialEndYear(interval.getStart(), interval
.getFinish());

View file

@ -208,4 +208,6 @@ public abstract class TimeTrackerState {
public abstract Interval getRealIntervalFor(Interval testInterval);
public abstract double pixelsPerDay();
}

View file

@ -2,17 +2,41 @@
<zk xmlns:n="http://www.zkoss.org/2005/zk/native">
<zscript><![CDATA[
top = self;
ganttPanel= self.ganttPanel;
]]>
</zscript>
<div>
<n:script language="javascript">
function getHorizontalScroll() {
return document.getElementById('ganttpanel_scroller_x').scrollLeft;
}
function onIncrease(id) {
zkau.send( {
uuid : id.id,
cmd : "onIncrease",
data : [ getHorizontalScroll() ]
});
}
function onDecrease(id) {
zkau.send( {
uuid : id.id,
cmd : "onDecrease",
data : [ getHorizontalScroll() ]
});
}
</n:script>
<n:div id="timetracker">
<vbox>
<n:div id="zoom_buttons">
<hbox>
<button image="/zkau/web/ganttz/img/zoom_in.gif" forward="onIncrease"/>
<button image="/zkau/web/ganttz/img/zoom_out.gif" forward="onDecrease"/>
<button image="/zkau/web/ganttz/img/zoom_in.gif" action="onClick: onIncrease(#{ganttPanel})"/>
<button image="/zkau/web/ganttz/img/zoom_out.gif" action="onClick: onDecrease(#{ganttPanel})"/>
</hbox>
</n:div>

View file

@ -1,5 +1,16 @@
/**
* Javascript behaviuor for GanttPanel element
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
*/
zkGanttPanel = {};
zkGanttPanel.init = function(cmp){
}
/**
* Scrolls horizontally the ganttpanel when the zoom has resized the component
* width.
*/
zkGanttPanel.scroll_horizontal = function(cmp, offsetInPx) {
document.getElementById('ganttpanel_scroller_x').scrollLeft = offsetInPx;
}