use of org.jfree.chart.entity.XYItemEntity in project Course_Generator by patrovite.
the class frmEditCurve method initComponents.
/**
* This method is called to initialize the form.
*/
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(bundle.getString("frmEditCurve.title"));
setPreferredSize(new Dimension(1200, 600));
setAlwaysOnTop(true);
setResizable(false);
setType(java.awt.Window.Type.UTILITY);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
// -- Layout
// ------------------------------------------------------------
Container paneGlobal = getContentPane();
paneGlobal.setLayout(new GridBagLayout());
// -- Curves list
ListCurves = new javax.swing.JList<>();
model = new ParamListModel();
ListCurves.setModel(model);
ListCurves.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
ListCurves.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
SelectCurve();
}
});
jScrollPaneCurves = new javax.swing.JScrollPane();
jScrollPaneCurves.setViewportView(ListCurves);
Utils.addComponent(paneGlobal, jScrollPaneCurves, 0, 0, 1, 4, 0.5, 1, 10, 10, 0, 0, GridBagConstraints.PAGE_START, GridBagConstraints.BOTH);
// -- Curve management toolbar
CreateCurvesToolbar();
Utils.addComponent(paneGlobal, ToolBarAction, 1, 0, 1, 4, 0, 0, 10, 0, 0, 0, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);
lbSelectedCurve = new javax.swing.JLabel();
lbSelectedCurve.setBorder(javax.swing.BorderFactory.createEtchedBorder());
lbSelectedCurve.setText("Selected");
lbSelectedCurve.setHorizontalAlignment(JLabel.LEFT);
Utils.addComponent(paneGlobal, lbSelectedCurve, 2, 0, GridBagConstraints.REMAINDER, 1, 1, 0, 10, 0, 5, 10, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL);
// -- Curve name
lbName = new javax.swing.JLabel();
lbName.setBorder(javax.swing.BorderFactory.createEtchedBorder());
lbName.setText(" " + bundle.getString("frmEditCurve.lbName.text") + " ");
Utils.addComponent(paneGlobal, lbName, 2, 1, 1, 1, 0, 0, 0, 0, 5, 0, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL);
lbNameVal = new javax.swing.JLabel();
lbNameVal.setBorder(javax.swing.BorderFactory.createEtchedBorder());
Utils.addComponent(paneGlobal, lbNameVal, 3, 1, GridBagConstraints.REMAINDER, 1, 1, 0, 0, 5, 5, 10, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);
// -- Curve comment
lbComment = new javax.swing.JLabel();
lbComment.setBorder(javax.swing.BorderFactory.createEtchedBorder());
lbComment.setText(" " + bundle.getString("frmEditCurve.lbComment.text") + " ");
Utils.addComponent(paneGlobal, lbComment, 2, 2, 1, 1, 0, 0, 0, 0, 5, 0, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL);
tfComment = new JTextField();
tfComment.setBorder(javax.swing.BorderFactory.createEtchedBorder());
Utils.addComponent(paneGlobal, tfComment, 3, 2, GridBagConstraints.REMAINDER, 1, 1, 0, 0, 5, 5, 10, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL);
// -- Point list
TablePoints = new javax.swing.JTable();
// new ParamPointsModel(param));
TablePoints.setModel(tablemodel);
TablePoints.getTableHeader().setReorderingAllowed(false);
TablePoints.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
// TableMainMouseClicked(evt);
// TODO
}
});
TablePoints.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
// TableMainKeyReleased(evt);
// TODO
}
});
TablePoints.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent event) {
btEditLine.setEnabled(TablePoints.getSelectedRow() > 0);
}
});
jScrollPanePoint = new javax.swing.JScrollPane();
jScrollPanePoint.setViewportView(TablePoints);
Utils.addComponent(paneGlobal, jScrollPanePoint, 2, 3, 2, 1, 0.5, 0, 0, 0, 0, 0, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);
// -- Edit toolbar
CreateEditToolbar();
Utils.addComponent(paneGlobal, ToolBarEdit, 4, 3, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);
jPanelProfilChart = new ChartPanel(chart);
Utils.addComponent(paneGlobal, jPanelProfilChart, 5, 3, 1, 1, 1, 0, 0, 0, 0, 10, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);
CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
xCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
xCrosshair.setLabelVisible(true);
xCrosshair.setLabelBackgroundPaint(Color.WHITE);
yCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
yCrosshair.setLabelVisible(true);
yCrosshair.setLabelBackgroundPaint(Color.WHITE);
crosshairOverlay.addDomainCrosshair(xCrosshair);
crosshairOverlay.addRangeCrosshair(yCrosshair);
jPanelProfilChart.addOverlay(crosshairOverlay);
jPanelProfilChart.setBackground(new java.awt.Color(255, 0, 51));
jPanelProfilChart.addChartMouseListener(new ChartMouseListener() {
@Override
public void chartMouseClicked(ChartMouseEvent event) {
ChartEntity chartentity = event.getEntity();
if (chartentity instanceof XYItemEntity) {
XYItemEntity e = (XYItemEntity) chartentity;
XYDataset d = e.getDataset();
int s = e.getSeriesIndex();
int i = e.getItem();
double x = d.getXValue(s, i);
double y = d.getYValue(s, i);
xCrosshair.setValue(x);
yCrosshair.setValue(y);
}
}
@Override
public void chartMouseMoved(ChartMouseEvent event) {
}
});
// == Bottom button
// ===========================================================
btOk = new javax.swing.JButton();
btOk.setText(bundle.getString("Global.btOk.text"));
btOk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/valid.png")));
btOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RequestToClose();
}
});
Utils.addComponent(paneGlobal, btOk, 0, 5, GridBagConstraints.REMAINDER, 1, 0, 0, 10, 0, 10, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE);
// --
pack();
// -- Refresh the curve list
RefreshCurveList();
// -- Center the windows
setLocationRelativeTo(null);
}
use of org.jfree.chart.entity.XYItemEntity in project SIMVA-SoS by SESoS.
the class DefaultPolarItemRenderer method addEntity.
/**
* Adds an entity to the collection.
*
* @param entities the entity collection being populated.
* @param area the entity area (if <code>null</code> a default will be
* used).
* @param dataset the dataset.
* @param series the series.
* @param item the item.
* @param entityX the entity's center x-coordinate in user space (only
* used if <code>area</code> is <code>null</code>).
* @param entityY the entity's center y-coordinate in user space (only
* used if <code>area</code> is <code>null</code>).
*/
protected void addEntity(EntityCollection entities, Shape area, XYDataset dataset, int series, int item, double entityX, double entityY) {
if (!getItemCreateEntity(series, item)) {
return;
}
Shape hotspot = area;
if (hotspot == null) {
double r = getDefaultEntityRadius();
double w = r * 2;
if (getPlot().getOrientation() == PlotOrientation.VERTICAL) {
hotspot = new Ellipse2D.Double(entityX - r, entityY - r, w, w);
} else {
hotspot = new Ellipse2D.Double(entityY - r, entityX - r, w, w);
}
}
String tip = null;
XYToolTipGenerator generator = getToolTipGenerator(series, item);
if (generator != null) {
tip = generator.generateToolTip(dataset, series, item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(dataset, series, item);
}
XYItemEntity entity = new XYItemEntity(hotspot, dataset, series, item, tip, url);
entities.add(entity);
}
use of org.jfree.chart.entity.XYItemEntity in project SIMVA-SoS by SESoS.
the class AbstractXYItemRenderer method addEntity.
/**
* Adds an entity to the collection.
*
* @param entities the entity collection being populated.
* @param area the entity area (if <code>null</code> a default will be
* used).
* @param dataset the dataset.
* @param series the series.
* @param item the item.
* @param entityX the entity's center x-coordinate in user space (only
* used if <code>area</code> is <code>null</code>).
* @param entityY the entity's center y-coordinate in user space (only
* used if <code>area</code> is <code>null</code>).
*/
protected void addEntity(EntityCollection entities, Shape area, XYDataset dataset, int series, int item, double entityX, double entityY) {
if (!getItemCreateEntity(series, item)) {
return;
}
Shape hotspot = area;
if (hotspot == null) {
double r = getDefaultEntityRadius();
double w = r * 2;
if (getPlot().getOrientation() == PlotOrientation.VERTICAL) {
hotspot = new Ellipse2D.Double(entityX - r, entityY - r, w, w);
} else {
hotspot = new Ellipse2D.Double(entityY - r, entityX - r, w, w);
}
}
String tip = null;
XYToolTipGenerator generator = getToolTipGenerator(series, item);
if (generator != null) {
tip = generator.generateToolTip(dataset, series, item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(dataset, series, item);
}
XYItemEntity entity = new XYItemEntity(hotspot, dataset, series, item, tip, url);
entities.add(entity);
}
use of org.jfree.chart.entity.XYItemEntity in project SIMVA-SoS by SESoS.
the class StackedXYAreaRenderer method drawItem.
/**
* Draws the visual representation of a single data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area within which the data is being drawn.
* @param info collects information about the drawing.
* @param plot the plot (can be used to obtain standard color information
* etc).
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param crosshairState information about crosshairs on a plot.
* @param pass the pass index.
*
* @throws ClassCastException if <code>state</code> is not an instance of
* <code>StackedXYAreaRendererState</code> or <code>dataset</code>
* is not an instance of {@link TableXYDataset}.
*/
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
PlotOrientation orientation = plot.getOrientation();
StackedXYAreaRendererState areaState = (StackedXYAreaRendererState) state;
// Get the item count for the series, so that we can know which is the
// end of the series.
TableXYDataset tdataset = (TableXYDataset) dataset;
int itemCount = tdataset.getItemCount();
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
boolean nullPoint = false;
if (Double.isNaN(y1)) {
y1 = 0.0;
nullPoint = true;
}
// Get height adjustment based on stack and translate to Java2D values
double ph1 = getPreviousHeight(tdataset, series, item);
double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge());
double transY1 = rangeAxis.valueToJava2D(y1 + ph1, dataArea, plot.getRangeAxisEdge());
// Get series Paint and Stroke
Paint seriesPaint = getItemPaint(series, item);
Paint seriesFillPaint = seriesPaint;
if (getUseFillPaint()) {
seriesFillPaint = getItemFillPaint(series, item);
}
Stroke seriesStroke = getItemStroke(series, item);
if (pass == 0) {
if (item == 0) {
// Create a new Area for the series
areaState.setSeriesArea(new Polygon());
areaState.setLastSeriesPoints(areaState.getCurrentSeriesPoints());
areaState.setCurrentSeriesPoints(new Stack());
// start from previous height (ph1)
double transY2 = rangeAxis.valueToJava2D(ph1, dataArea, plot.getRangeAxisEdge());
// The first point is (x, 0)
if (orientation == PlotOrientation.VERTICAL) {
areaState.getSeriesArea().addPoint((int) transX1, (int) transY2);
} else if (orientation == PlotOrientation.HORIZONTAL) {
areaState.getSeriesArea().addPoint((int) transY2, (int) transX1);
}
}
// Add each point to Area (x, y)
if (orientation == PlotOrientation.VERTICAL) {
Point point = new Point((int) transX1, (int) transY1);
areaState.getSeriesArea().addPoint((int) point.getX(), (int) point.getY());
areaState.getCurrentSeriesPoints().push(point);
} else if (orientation == PlotOrientation.HORIZONTAL) {
areaState.getSeriesArea().addPoint((int) transY1, (int) transX1);
}
if (getPlotLines()) {
if (item > 0) {
// get the previous data point...
double x0 = dataset.getXValue(series, item - 1);
double y0 = dataset.getYValue(series, item - 1);
double ph0 = getPreviousHeight(tdataset, series, item - 1);
double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge());
double transY0 = rangeAxis.valueToJava2D(y0 + ph0, dataArea, plot.getRangeAxisEdge());
if (orientation == PlotOrientation.VERTICAL) {
areaState.getLine().setLine(transX0, transY0, transX1, transY1);
} else if (orientation == PlotOrientation.HORIZONTAL) {
areaState.getLine().setLine(transY0, transX0, transY1, transX1);
}
g2.setPaint(seriesPaint);
g2.setStroke(seriesStroke);
g2.draw(areaState.getLine());
}
}
// items > 0. We can't draw an area for a single point.
if (getPlotArea() && item > 0 && item == (itemCount - 1)) {
double transY2 = rangeAxis.valueToJava2D(ph1, dataArea, plot.getRangeAxisEdge());
if (orientation == PlotOrientation.VERTICAL) {
// Add the last point (x,0)
areaState.getSeriesArea().addPoint((int) transX1, (int) transY2);
} else if (orientation == PlotOrientation.HORIZONTAL) {
// Add the last point (x,0)
areaState.getSeriesArea().addPoint((int) transY2, (int) transX1);
}
// polygon
if (series != 0) {
Stack points = areaState.getLastSeriesPoints();
while (!points.empty()) {
Point point = (Point) points.pop();
areaState.getSeriesArea().addPoint((int) point.getX(), (int) point.getY());
}
}
// Fill the polygon
g2.setPaint(seriesFillPaint);
g2.setStroke(seriesStroke);
g2.fill(areaState.getSeriesArea());
// Draw an outline around the Area.
if (isOutline()) {
g2.setStroke(lookupSeriesOutlineStroke(series));
g2.setPaint(lookupSeriesOutlinePaint(series));
g2.draw(areaState.getSeriesArea());
}
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
updateCrosshairValues(crosshairState, x1, ph1 + y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
} else if (pass == 1) {
// On second pass render shapes and collect entity and tooltip
// information
Shape shape = null;
if (getPlotShapes()) {
shape = getItemShape(series, item);
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
} else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
}
if (!nullPoint) {
if (getShapePaint() != null) {
g2.setPaint(getShapePaint());
} else {
g2.setPaint(seriesPaint);
}
if (getShapeStroke() != null) {
g2.setStroke(getShapeStroke());
} else {
g2.setStroke(seriesStroke);
}
g2.draw(shape);
}
} else {
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
shape = new Rectangle2D.Double(transX1 - 3, transY1 - 3, 6.0, 6.0);
} else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
shape = new Rectangle2D.Double(transY1 - 3, transX1 - 3, 6.0, 6.0);
}
}
// collect entity and tool tip information...
if (state.getInfo() != null) {
EntityCollection entities = state.getEntityCollection();
if (entities != null && shape != null && !nullPoint) {
String tip = null;
XYToolTipGenerator generator = getToolTipGenerator(series, item);
if (generator != null) {
tip = generator.generateToolTip(dataset, series, item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(dataset, series, item);
}
XYItemEntity entity = new XYItemEntity(shape, dataset, series, item, tip, url);
entities.add(entity);
}
}
}
}
use of org.jfree.chart.entity.XYItemEntity in project pentaho-platform by pentaho.
the class TimeSeriesCollectionChartComponent method populateInfo.
private void populateInfo(final ChartRenderingInfo info) {
if (urlTemplate == null) {
return;
}
Iterator iter = info.getEntityCollection().iterator();
while (iter.hasNext()) {
ChartEntity entity = (ChartEntity) iter.next();
if (entity instanceof XYItemEntity) {
if (urlTemplate != null) {
XYItemEntity xyItemEntity = (XYItemEntity) entity;
if (paramName == null) {
xyItemEntity.setURLText(urlTemplate);
} else {
try {
int seriesIndex = xyItemEntity.getSeriesIndex();
int itemIndex = xyItemEntity.getItem();
String xySeriesKey = (String) ((TimeSeriesCollection) xyItemEntity.getDataset()).getSeriesKey(seriesIndex);
String encodedVal = URLEncoder.encode(xySeriesKey, LocaleHelper.getSystemEncoding());
String drillURL = TemplateUtil.applyTemplate(urlTemplate, paramName, encodedVal);
String itemValueStr = ((TimeSeriesCollection) xyItemEntity.getDataset()).getX(seriesIndex, itemIndex).toString();
encodedVal = URLEncoder.encode(itemValueStr, LocaleHelper.getSystemEncoding());
if (seriesName == null) {
// $NON-NLS-1$
drillURL = TemplateUtil.applyTemplate(drillURL, "SERIES", encodedVal);
} else {
drillURL = TemplateUtil.applyTemplate(drillURL, seriesName, encodedVal);
}
xyItemEntity.setURLText(drillURL);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}
Aggregations