org.jfree.chart.entity.ChartEntity Java Examples

The following examples show how to use org.jfree.chart.entity.ChartEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChartRenderingInfoTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    ChartRenderingInfo i1 = new ChartRenderingInfo();
    ChartRenderingInfo i2 = (ChartRenderingInfo) i1.clone();

    assertNotSame(i1, i2);
    assertSame(i1.getClass(), i2.getClass());
    assertEquals(i1, i2);

    // check independence
    i1.getChartArea().setRect(4.0, 3.0, 2.0, 1.0);
    assertFalse(i1.equals(i2));
    i2.getChartArea().setRect(4.0, 3.0, 2.0, 1.0);
    assertEquals(i1, i2);

    i1.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2,
            1)));
    assertFalse(i1.equals(i2));
    i2.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2,
            1)));
    assertEquals(i1, i2);

}
 
Example #2
Source File: ChartRenderingInfoTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    ChartRenderingInfo i1 = new ChartRenderingInfo();
    ChartRenderingInfo i2 = (ChartRenderingInfo) i1.clone();

    assertNotSame(i1, i2);
    assertSame(i1.getClass(), i2.getClass());
    assertEquals(i1, i2);

    // check independence
    i1.getChartArea().setRect(4.0, 3.0, 2.0, 1.0);
    assertFalse(i1.equals(i2));
    i2.getChartArea().setRect(4.0, 3.0, 2.0, 1.0);
    assertEquals(i1, i2);

    i1.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2,
            1)));
    assertFalse(i1.equals(i2));
    i2.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2,
            1)));
    assertEquals(i1, i2);

}
 
Example #3
Source File: TooltipHandlerFX.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the tooltip text.
 * 
 * @param canvas  the canvas that is displaying the chart.
 * @param x  the x-coordinate of the mouse pointer.
 * @param y  the y-coordinate of the mouse pointer.
 * 
 * @return String The tooltip text (possibly <code>null</code>).
  */
private String getTooltipText(ChartCanvas canvas, double x, double y) {
    ChartRenderingInfo info = canvas.getRenderingInfo();
    if (info == null) {
        return null;
    }
    EntityCollection entities = info.getEntityCollection();
    if (entities == null) {
        return null;
    }
    ChartEntity entity = entities.getEntity(x, y);
    if (entity == null) {
        return null;
    }
    return entity.getToolTipText();
}
 
Example #4
Source File: ChartGestureMouseAdapter.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.PRESSED))
    return;

  if (e.getComponent() instanceof ChartPanel) {
    ChartPanel chartPanel = (ChartPanel) e.getComponent();
    ChartEntity entity = findChartEntity(chartPanel, e);
    ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
    Button button = Button.getButton(e.getButton());
    // handle event
    lastDragEvent = new ChartGestureEvent(chartPanel, e, entity,
        new ChartGesture(gestureEntity, Event.PRESSED, button));
    handleEvent(lastDragEvent);
  }
}
 
Example #5
Source File: ChartGestureMouseAdapter.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.MOUSE_WHEEL))
    return;

  if (e.getComponent() instanceof ChartPanel) {
    ChartPanel chartPanel = (ChartPanel) e.getComponent();
    ChartEntity entity = findChartEntity(chartPanel, e);
    ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
    Button button = Button.getButton(e.getButton());

    // handle event
    handleEvent(new ChartGestureEvent(chartPanel, e, entity,
        new ChartGesture(gestureEntity, Event.MOUSE_WHEEL, button)));
  }
}
 
Example #6
Source File: ChartGestureMouseAdapter.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void mouseMoved(MouseEvent e) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.MOVED))
    return;

  if (e.getComponent() instanceof ChartPanel) {
    ChartPanel chartPanel = (ChartPanel) e.getComponent();
    ChartEntity entity = findChartEntity(chartPanel, e);
    ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
    Button button = Button.getButton(e.getButton());

    // handle event
    handleEvent(new ChartGestureEvent(chartPanel, e, entity,
        new ChartGesture(gestureEntity, Event.MOVED, button)));
  }
}
 
Example #7
Source File: ChartGestureMouseAdapter.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.PRESSED))
    return;

  if (e.getComponent() instanceof ChartPanel) {
    ChartPanel chartPanel = (ChartPanel) e.getComponent();
    ChartEntity entity = findChartEntity(chartPanel, e);
    ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
    GestureButton button = GestureButton.getButton(e.getButton());
    // handle event
    lastDragEvent = new ChartGestureEvent(chartPanel, e, entity,
        new ChartGesture(gestureEntity, Event.PRESSED, button));
    handleEvent(lastDragEvent);
  }
}
 
Example #8
Source File: ChartGestureMouseAdapter.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.DRAGGED))
    return;

  if (e.getComponent() instanceof ChartPanel) {
    ChartPanel chartPanel = (ChartPanel) e.getComponent();
    // keep the same chartEntity
    ChartEntity entity = lastDragEvent.getEntity();
    ChartGesture.Entity gestureEntity = lastDragEvent.getGesture().getEntity();
    GestureButton button = lastDragEvent.getGesture().getButton();

    // handle event
    lastDragEvent = new ChartGestureEvent(chartPanel, e, entity,
        new ChartGesture(gestureEntity, Event.DRAGGED, button));
    handleEvent(lastDragEvent);
  }
}
 
Example #9
Source File: AbstractChartPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Returns a string for the tooltip.
 * 
 * @param e
 *            the mouse event.
 * 
 * @return A tool tip or <code>null</code> if no tooltip is available.
 */

@Override
public String getToolTipText(MouseEvent e) {

	String result = null;
	if (this.info != null) {
		EntityCollection entities = this.info.getEntityCollection();
		if (entities != null) {
			Insets insets = getInsets();
			ChartEntity entity = entities.getEntity((int) ((e.getX() - insets.left) / this.scaleX),
					(int) ((e.getY() - insets.top) / this.scaleY));
			if (entity != null) {
				result = entity.getToolTipText();
			}
		}
	}
	return result;

}
 
Example #10
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * 
 * @param chart
 * @return
 */
public static ChartEntity findChartEntity(ChartCanvas chart, double mx, double my) {
  // TODO check if insets were needed
  // coordinates to find chart entities
  int x = (int) (mx / chart.getScaleX());
  int y = (int) (my / chart.getScaleY());

  ChartRenderingInfo info = chart.getRenderingInfo();
  ChartEntity entity = null;
  if (info != null) {
    EntityCollection entities = info.getEntityCollection();
    if (entities != null) {
      entity = entities.getEntity(x, y);
    }
  }
  return entity;
}
 
Example #11
Source File: ChartGestureMouseAdapterFX.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * 
 * @param chartPanel
 * @param x
 * @param y
 * @return
 */
private ChartEntity findChartEntity(MouseEventWrapper e) {
  // TODO check if insets were needed
  // coordinates to find chart entities
  int x = (int) ((e.getX()) / chartViewer.getCanvas().getScaleX());
  int y = (int) ((e.getY()) / chartViewer.getCanvas().getScaleY());

  if (lastEntity != null && x == lastEntityX && y == lastEntityY)
    return lastEntity;
  else {
    ChartRenderingInfo info = chartViewer.getCanvas().getRenderingInfo();
    ChartEntity entity = null;
    if (info != null) {
      EntityCollection entities = info.getEntityCollection();
      if (entities != null) {
        entity = entities.getEntity(x, y);
      }
    }
    return entity;
  }
}
 
Example #12
Source File: ChartGestureMouseAdapterFX.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse moved event. This implementation does nothing, override the method if required.
 * 
 * @param canvas the canvas ({@code null} not permitted).
 * @param e the event ({@code null} not permitted).
 */
@Override
public void handleMouseMoved(ChartCanvas chartPanel, MouseEvent eOrig) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.MOVED))
    return;

  MouseEventWrapper e = new MouseEventWrapper(eOrig);
  ChartViewWrapper cw = new ChartViewWrapper(chartViewer);
  ChartEntity entity = findChartEntity(e);
  ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
  GestureButton button = GestureButton.getButton(e.getButton());

  // handle event
  handleEvent(
      new ChartGestureEvent(cw, e, entity, new ChartGesture(gestureEntity, Event.MOVED, button)));
}
 
Example #13
Source File: ChartGestureMouseAdapterFX.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 
 * @param canvas the canvas ({@code null} not permitted).
 * @param e the event ({@code null} not permitted).
 */
@Override
public void handleMouseReleased(ChartCanvas chartPanel, MouseEvent eOrig) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.RELEASED))
    return;

  MouseEventWrapper e = new MouseEventWrapper(eOrig);
  ChartEntity entity = findChartEntity(e);
  ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
  GestureButton button = GestureButton.getButton(e.getButton());

  // last gesture was dragged? keep the same chartEntity
  if (lastDragEvent != null) {
    entity = lastDragEvent.getEntity();
    gestureEntity = lastDragEvent.getGesture().getEntity();
  }
  // handle event
  handleEvent(new ChartGestureEvent(cw, e, entity,
      new ChartGesture(gestureEntity, Event.RELEASED, button)));

  // reset drag
  lastDragEvent = null;
}
 
Example #14
Source File: ChartPanel.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a string for the tooltip.
 *
 * @param e  the mouse event.
 *
 * @return A tool tip or <code>null</code> if no tooltip is available.
 */
public String getToolTipText(MouseEvent e) {

    String result = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            Insets insets = getInsets();
            ChartEntity entity = entities.getEntity(
                    (int) ((e.getX() - insets.left) / this.scaleX),
                    (int) ((e.getY() - insets.top) / this.scaleY));
            if (entity != null) {
                result = entity.getToolTipText();
            }
        }
    }
    return result;

}
 
Example #15
Source File: TooltipHandlerFX.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the tooltip text.
 * 
 * @param canvas  the canvas that is displaying the chart.
 * @param x  the x-coordinate of the mouse pointer.
 * @param y  the y-coordinate of the mouse pointer.
 * 
 * @return String The tooltip text (possibly <code>null</code>).
  */
private String getTooltipText(ChartCanvas canvas, double x, double y) {
    ChartRenderingInfo info = canvas.getRenderingInfo();
    if (info == null) {
        return null;
    }
    EntityCollection entities = info.getEntityCollection();
    if (entities == null) {
        return null;
    }
    ChartEntity entity = entities.getEntity(x, y);
    if (entity == null) {
        return null;
    }
    return entity.getToolTipText();
}
 
Example #16
Source File: ChartGestureMouseAdapterFX.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse dragged event. This implementation does nothing, override the method if
 * required.
 * 
 * @param canvas the canvas ({@code null} not permitted).
 * @param e the event ({@code null} not permitted).
 */
@Override
public void handleMouseDragged(ChartCanvas chartPanel, MouseEvent eOrig) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.DRAGGED))
    return;

  MouseEventWrapper e = new MouseEventWrapper(eOrig);
  // keep the same chartEntity
  ChartEntity entity = lastDragEvent.getEntity();
  ChartGesture.Entity gestureEntity = lastDragEvent.getGesture().getEntity();
  GestureButton button = lastDragEvent.getGesture().getButton();

  // handle event
  lastDragEvent = new ChartGestureEvent(cw, e, entity,
      new ChartGesture(gestureEntity, Event.DRAGGED, button));
  handleEvent(lastDragEvent);
}
 
Example #17
Source File: ChartRenderingInfoTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    ChartRenderingInfo i1 = new ChartRenderingInfo();
    ChartRenderingInfo i2 = new ChartRenderingInfo();
    assertEquals(i1, i2);

    i1.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertFalse(i1.equals(i2));
    i2.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertEquals(i1, i2);

    i1.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4));
    assertFalse(i1.equals(i2));
    i2.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4));
    assertEquals(i1, i2);

    StandardEntityCollection e1 = new StandardEntityCollection();
    e1.add(new ChartEntity(new Rectangle(1, 2, 3, 4)));
    i1.setEntityCollection(e1);
    assertFalse(i1.equals(i2));
    StandardEntityCollection e2 = new StandardEntityCollection();
    e2.add(new ChartEntity(new Rectangle(1, 2, 3, 4)));
    i2.setEntityCollection(e2);
}
 
Example #18
Source File: ChartRenderingInfoTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    ChartRenderingInfo i1 = new ChartRenderingInfo();
    ChartRenderingInfo i2 = new ChartRenderingInfo();
    assertTrue(i1.equals(i2));
    
    i1.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertFalse(i1.equals(i2));
    i2.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertTrue(i1.equals(i2));
    
    i1.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4));
    assertFalse(i1.equals(i2));
    i2.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4));
    assertTrue(i1.equals(i2));
    
    StandardEntityCollection e1 = new StandardEntityCollection();
    e1.add(new ChartEntity(new Rectangle(1, 2, 3, 4)));
    i1.setEntityCollection(e1);
    assertFalse(i1.equals(i2));
    StandardEntityCollection e2 = new StandardEntityCollection();
    e2.add(new ChartEntity(new Rectangle(1, 2, 3, 4)));
    i2.setEntityCollection(e2); 
}
 
Example #19
Source File: ChartGestureMouseAdapterFX.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse moved event. This implementation does nothing, override the method if required.
 * 
 * @param canvas the canvas ({@code null} not permitted).
 * @param e the event ({@code null} not permitted).
 */
@Override
public void handleMouseMoved(ChartCanvas chartPanel, MouseEvent eOrig) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.MOVED))
    return;

  MouseEventWrapper e = new MouseEventWrapper(eOrig);
  ChartViewWrapper cw = new ChartViewWrapper(chartViewer);
  ChartEntity entity = findChartEntity(e);
  ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
  Button button = Button.getButton(e.getButton());

  // handle event
  handleEvent(
      new ChartGestureEvent(cw, e, entity, new ChartGesture(gestureEntity, Event.MOVED, button)));
}
 
Example #20
Source File: ChartRenderingInfoTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    ChartRenderingInfo i1 = new ChartRenderingInfo();
    ChartRenderingInfo i2 = (ChartRenderingInfo) i1.clone();

    assertNotSame(i1, i2);
    assertSame(i1.getClass(), i2.getClass());
    assertEquals(i1, i2);

    // check independence
    i1.getChartArea().setRect(4.0, 3.0, 2.0, 1.0);
    assertFalse(i1.equals(i2));
    i2.getChartArea().setRect(4.0, 3.0, 2.0, 1.0);
    assertEquals(i1, i2);

    i1.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2,
            1)));
    assertFalse(i1.equals(i2));
    i2.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2,
            1)));
    assertEquals(i1, i2);

}
 
Example #21
Source File: ChartGestureMouseAdapter.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * 
 * @param chartPanel
 * @param x
 * @param y
 * @return
 */
private ChartEntity findChartEntity(ChartPanel chartPanel, MouseEvent e) {
  // coordinates to find chart entities
  Insets insets = chartPanel.getInsets();
  int x = (int) ((e.getX() - insets.left) / chartPanel.getScaleX());
  int y = (int) ((e.getY() - insets.top) / chartPanel.getScaleY());

  if (lastEntity != null && x == lastEntityX && y == lastEntityY)
    return lastEntity;
  else {
    ChartRenderingInfo info = chartPanel.getChartRenderingInfo();
    ChartEntity entity = null;
    if (info != null) {
      EntityCollection entities = info.getEntityCollection();
      if (entities != null) {
        entity = entities.getEntity(x, y);
      }
    }
    return entity;
  }
}
 
Example #22
Source File: TooltipHandlerFX.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the tooltip text.
 * 
 * @param canvas  the canvas that is displaying the chart.
 * @param x  the x-coordinate of the mouse pointer.
 * @param y  the y-coordinate of the mouse pointer.
 * 
 * @return String The tooltip text (possibly <code>null</code>).
  */
private String getTooltipText(ChartCanvas canvas, double x, double y) {
    ChartRenderingInfo info = canvas.getRenderingInfo();
    if (info == null) {
        return null;
    }
    EntityCollection entities = info.getEntityCollection();
    if (entities == null) {
        return null;
    }
    ChartEntity entity = entities.getEntity(x, y);
    if (entity == null) {
        return null;
    }
    return entity.getToolTipText();
}
 
Example #23
Source File: ChartGestureDragDiffHandler.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * use default orientation or orientation of axis
 * 
 * @param event
 * @return
 */
public Orientation getOrientation(ChartGestureEvent event) {
  ChartEntity ce = event.getEntity();
  if (ce instanceof AxisEntity) {
    JFreeChart chart = event.getChart();
    PlotOrientation plotorient = PlotOrientation.HORIZONTAL;
    if (chart.getXYPlot() != null)
      plotorient = chart.getXYPlot().getOrientation();
    else if (chart.getCategoryPlot() != null)
      plotorient = chart.getCategoryPlot().getOrientation();

    Entity entity = event.getGesture().getEntity();
    if ((entity.equals(Entity.DOMAIN_AXIS) && plotorient.equals(PlotOrientation.VERTICAL))
        || (entity.equals(Entity.RANGE_AXIS) && plotorient.equals(PlotOrientation.HORIZONTAL)))
      orient = Orientation.HORIZONTAL;
    else
      orient = Orientation.VERTICAL;
  }
  return orient;
}
 
Example #24
Source File: ChartPanel.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a string for the tooltip.
 *
 * @param e  the mouse event.
 *
 * @return A tool tip or <code>null</code> if no tooltip is available.
 */
@Override
public String getToolTipText(MouseEvent e) {
    String result = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            Insets insets = getInsets();
            ChartEntity entity = entities.getEntity(
                    (int) ((e.getX() - insets.left) / this.scaleX),
                    (int) ((e.getY() - insets.top) / this.scaleY));
            if (entity != null) {
                result = entity.getToolTipText();
            }
        }
    }
    return result;
}
 
Example #25
Source File: ChartRenderingInfoTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    ChartRenderingInfo i1 = new ChartRenderingInfo();
    ChartRenderingInfo i2 = new ChartRenderingInfo();
    assertEquals(i1, i2);

    i1.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertFalse(i1.equals(i2));
    i2.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertEquals(i1, i2);

    i1.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4));
    assertFalse(i1.equals(i2));
    i2.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4));
    assertEquals(i1, i2);

    StandardEntityCollection e1 = new StandardEntityCollection();
    e1.add(new ChartEntity(new Rectangle(1, 2, 3, 4)));
    i1.setEntityCollection(e1);
    assertFalse(i1.equals(i2));
    StandardEntityCollection e2 = new StandardEntityCollection();
    e2.add(new ChartEntity(new Rectangle(1, 2, 3, 4)));
    i2.setEntityCollection(e2);
}
 
Example #26
Source File: ChartComposite.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a string for the tooltip.
 *
 * @param e  the mouse event.
 *
 * @return A tool tip or <code>null</code> if no tooltip is available.
 */
public String getToolTipText(org.eclipse.swt.events.MouseEvent e) {
    String result = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            Rectangle insets = getClientArea();
            ChartEntity entity = entities.getEntity(
                    (int) ((e.x - insets.x) / this.scaleX),
                    (int) ((e.y - insets.y) / this.scaleY));
            if (entity != null) {
                result = entity.getToolTipText();
            }
        }
    }
    return result;

}
 
Example #27
Source File: TooltipHandlerFX.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the tooltip text.
 * 
 * @param canvas  the canvas that is displaying the chart.
 * @param x  the x-coordinate of the mouse pointer.
 * @param y  the y-coordinate of the mouse pointer.
 * 
 * @return String The tooltip text (possibly <code>null</code>).
  */
private String getTooltipText(ChartCanvas canvas, double x, double y) {
    ChartRenderingInfo info = canvas.getRenderingInfo();
    if (info == null) {
        return null;
    }
    EntityCollection entities = info.getEntityCollection();
    if (entities == null) {
        return null;
    }
    ChartEntity entity = entities.getEntity(x, y);
    if (entity == null) {
        return null;
    }
    return entity.getToolTipText();
}
 
Example #28
Source File: CategoryChartHyperlinkProvider.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public JRPrintHyperlink getEntityHyperlink(ChartEntity entity)
{
	JRPrintHyperlink printHyperlink = null;
	if (hasHyperlinks() && entity instanceof CategoryItemEntity)
	{
		CategoryItemEntity itemEntity = (CategoryItemEntity) entity;
		Comparable<?> serie = itemEntity.getRowKey();
		Map<Comparable<?>,JRPrintHyperlink> serieHyperlinks = itemHyperlinks.get(serie);
		if (serieHyperlinks != null)
		{
			Comparable<?> category = itemEntity.getColumnKey();
			printHyperlink = serieHyperlinks.get(category);
		}
	}
	return printHyperlink;
}
 
Example #29
Source File: ChartPanel.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a string for the tooltip.
 *
 * @param e  the mouse event.
 *
 * @return A tool tip or <code>null</code> if no tooltip is available.
 */
@Override
public String getToolTipText(MouseEvent e) {
    String result = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            Insets insets = getInsets();
            ChartEntity entity = entities.getEntity(
                    (int) ((e.getX() - insets.left) / this.scaleX),
                    (int) ((e.getY() - insets.top) / this.scaleY));
            if (entity != null) {
                result = entity.getToolTipText();
            }
        }
    }
    return result;
}
 
Example #30
Source File: ChartGestureMouseAdapter.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.DRAGGED))
    return;

  if (e.getComponent() instanceof ChartPanel) {
    ChartPanel chartPanel = (ChartPanel) e.getComponent();
    // keep the same chartEntity
    ChartEntity entity = lastDragEvent.getEntity();
    ChartGesture.Entity gestureEntity = lastDragEvent.getGesture().getEntity();
    Button button = lastDragEvent.getGesture().getButton();

    // handle event
    lastDragEvent = new ChartGestureEvent(chartPanel, e, entity,
        new ChartGesture(gestureEntity, Event.DRAGGED, button));
    handleEvent(lastDragEvent);
  }
}