Java Code Examples for org.jfree.chart.entity.ChartEntity

The following examples show how to use org.jfree.chart.entity.ChartEntity. These examples are extracted from open source projects. 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
@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 2
Source Project: openstock   Source File: TooltipHandlerFX.java    License: 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 3
/**
 * 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 4
@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
/**
 * 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 6
@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
@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
@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
/**
 * 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 Project: mzmine2   Source File: ChartLogicsFX.java    License: 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
/**
 * 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
/**
 * 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
/**
 * 
 * @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 Project: astor   Source File: ChartPanel.java    License: 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
/**
 * 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 16
Source Project: ECG-Viewer   Source File: TooltipHandlerFX.java    License: 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 17
Source Project: SIMVA-SoS   Source File: ChartRenderingInfoTest.java    License: 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 18
/**
 * 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 19
/**
 * 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 20
/**
 * 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 21
/**
 * 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 22
/**
 * 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 23
/**
 * 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 24
/**
 * 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 25
Source Project: ccu-historian   Source File: ChartPanel.java    License: 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 26
/**
 * 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 27
Source Project: ECG-Viewer   Source File: ChartComposite.java    License: 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 28
Source Project: SIMVA-SoS   Source File: TooltipHandlerFX.java    License: 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 29
@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 30
Source Project: buffer_bci   Source File: ChartPanel.java    License: 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;
}