package org.timepedia.chronoscope.client.browser.event;

import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.user.client.Event;

import org.timepedia.chronoscope.client.Chart;
import org.timepedia.chronoscope.client.Cursor;
import org.timepedia.chronoscope.client.Overlay;
import org.timepedia.chronoscope.client.canvas.Bounds;

/**
 * Handles the event where the user depresses a mouse button.
 *
 * @author Chad Takahashi
 */
public final class ChartMouseDownHandler
    extends AbstractEventHandler<MouseDownHandler> implements MouseDownHandler {

  public void onMouseDown(MouseDownEvent event) {
    ChartState chartInfo = getChartState(event);
    Chart chart = chartInfo.chart;
    int x = getLocalX(event);
    int y = getLocalY(event);

    int overviewX = (int)chart.getPlot().getBounds().x;
    Bounds highlightBounds = chart.getPlot().getOverviewAxisPanel().getHighlightBounds();
    if ( highlightBounds != null) {
       int hiliteX = (int) highlightBounds.x;
       OverviewAxisMouseMoveHandler.setHiliteRelativeGrabX((x - overviewX) - hiliteX);
    }

    boolean handled;

    if (event.getNativeButton() == Event.BUTTON_RIGHT) {
      // Ignore mouse right-click -- let browser handle event.
      handled = false;
    } else {
      // Set the UI component that initiated the drag or select
      CompoundUIAction uiAction = chartInfo.getCompoundUIAction();
      uiAction.setSource(getComponent(x, y, chart.getPlot()));
      if (event.isShiftKeyDown()) {
        chart.setCursor(Cursor.SELECTING);
        uiAction.setSelectAction(true);
      } else {
        chart.setCursor(Cursor.DRAGGING);
        uiAction.setSelectAction(false);
      }
      uiAction.setStartX(x);
      if (uiAction.getSource() instanceof Overlay) {
      
        handled = true;
      } else {
        chart.setPlotFocus(x, y);
        handled = true;
      }
    }

    chartInfo.setHandled(handled);
  }
}


@@ -821,16 +821,123 @@
 vent);%0A%0A
+    if (y %3E (chart.getView().getHeight() - chart.getPlot().getOverviewAxisPanel().getBounds().height)) %7B%0A  
     int 
@@ -980,24 +980,26 @@
 Bounds().x;%0A
+  
     Bounds h
@@ -1076,24 +1076,26 @@
 unds();%0A    
+ 
+ 
 if ( highlig
@@ -1110,24 +1110,25 @@
  != null) %7B%0A
+ 
        int h
@@ -1157,24 +1157,25 @@
 htBounds.x;%0A
+ 
        Overv
@@ -1249,16 +1249,24 @@
 liteX);%0A
+      %7D%0A
     %7D%0A%0A 

check that click is in overview before setting overview relative x