Fix error when changing zoom

* adjust_height is removed from TaskList because the equivalent
  functionality is called from GanttPanel.

* GanttPanel.js receives the new methods for tracking the scroll. This
  should be simpler. It should be rewritten in the future.
This commit is contained in:
Óscar González Fernández 2011-06-15 18:05:16 +02:00
parent bc7c4a8b4e
commit 18c2f12211
3 changed files with 55 additions and 9 deletions

View file

@ -87,6 +87,7 @@ public class GanttPanel extends XulElement implements AfterCompose {
moveCurrentPositionScroll();
}
// FIXME: this is quite awful, it should be simple
@Override
protected void moveCurrentPositionScroll() {
// get the previous data.

View file

@ -49,7 +49,6 @@ import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
import org.zkoss.ganttz.util.Interval;
import org.zkoss.ganttz.util.MenuBuilder;
import org.zkoss.ganttz.util.MenuBuilder.ItemAction;
import org.zkoss.zk.au.out.AuInvoke;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.ext.AfterCompose;
@ -285,7 +284,6 @@ public class TaskList extends XulElement implements AfterCompose {
for (TaskComponent taskComponent : getTaskComponents()) {
taskComponent.zoomChanged();
}
adjustZoomColumnsHeight();
adjustZoomPositionScroll();
}
};
@ -334,10 +332,6 @@ public class TaskList extends XulElement implements AfterCompose {
return (GanttPanel) getParent();
}
public void adjustZoomColumnsHeight() {
response("adjust_height", new AuInvoke(TaskList.this, "adjust_height"));
}
private void adjustZoomPositionScroll() {
getTimeTrackerComponent().movePositionScroll();
}

View file

@ -5,6 +5,7 @@ ganttz.GanttPanel = zk.$extends(zk.Widget,{
xMouse : null,
yMouse : null
},
scrollDay: 0,
$init : function(){
this.$supers('$init', arguments);
this.$class.setInstance(this);
@ -61,9 +62,59 @@ ganttz.GanttPanel = zk.$extends(zk.Widget,{
reScrollX : function(px){
jq('#ganttpanel_inner_scroller_x').width(px);
},
scroll_horizontal : function(value){
jq('#ganttpanel_scroller_x').scrollLeft(value);
/**
* Scrolls horizontally the ganttpanel when the zoom has resized the component
* width.
*/
scroll_horizontal: function(daysDisplacement) {
scrollDay = daysDisplacement;
},
// FIXME: this is quite awful, it should be simple
update_day_scroll: function(previousPixelPerDay) {
this._fromPixelToDay(previousPixelPerDay);
},
move_scroll: function(diffDays, pixelPerDay) {
this._fromDayToPixel(diffDays,pixelPerDay);
},
_fromPixelToDay: function(previousPixelPerDay) {
var div1 = document.getElementById ("ganttpanel").parentNode;
var div2 = div1.parentNode;
var div3 = div2.parentNode;
var maxHPosition = div3.scrollWidth - div3.clientWidth;
if( maxHPosition > 0 ){
var proportion = div3.scrollWidth / maxHPosition;
var positionInScroll = div3.scrollLeft;
var positionInPx = positionInScroll * proportion;
if(positionInPx > 0){
var position = positionInPx / previousPixelPerDay;
var day = position;
this.scrollDay = position;
}
}
},
_fromDayToPixel: function(diffDays,pixelPerDay) {
var div1 = document.getElementById ("ganttpanel").parentNode;
var div2 = div1.parentNode;
var div3 = div2.parentNode;
var day = this.scrollDay;
day += parseInt(diffDays);
var newPosInPx = parseInt(day * pixelPerDay);
var maxHPosition = div3.scrollWidth - div3.clientWidth;
var newProportion = div3.scrollWidth / maxHPosition;
if( newProportion > 0){
var newPosInScroll = newPosInPx / newProportion;
if(newPosInScroll < 0){
newPosInScroll = 0;
}
div1.scrollLeft = newPosInScroll;
div2.scrollLeft = newPosInScroll;
div3.scrollLeft = newPosInScroll;
}
}
},{
getInstance : function(){
return this._instance;
@ -71,4 +122,4 @@ ganttz.GanttPanel = zk.$extends(zk.Widget,{
setInstance : function(instance){
this._instance = instance;
}
});
});