List of usage examples for org.jfree.util TableOrder BY_ROW
TableOrder BY_ROW
To view the source code for org.jfree.util TableOrder BY_ROW.
Click Source Link
From source file:spinworld.gui.RadarPlot.java
/** * Draws a radar plot polygon./* w ww. j a v a 2 s . com*/ * * @param g2 the graphics device. * @param plotArea the area we are plotting in (already adjusted). * @param centre the centre point of the radar axes * @param info chart rendering info. * @param series the series within the dataset we are plotting * @param catCount the number of categories per radar plot * @param headH the data point height * @param headW the data point width */ protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info, int series, int catCount, double headH, double headW) { Polygon polygon = new Polygon(); EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // plot the data... for (int cat = 0; cat < catCount; cat++) { Number dataValue = getPlotValue(series, cat); if (dataValue != null) { double value = dataValue.doubleValue(); // Finds our starting angle from the centre for this axis double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount); // The following angle calc will ensure there isn't a top // vertical axis - this may be useful if you don't want any // given criteria to 'appear' move important than the // others.. // + (getDirection().getFactor() // * (cat + 0.5) * 360 / catCount); // find the point at the appropriate distance end point // along the axis/angle identified above and add it to the // polygon double _maxValue = getMaxValue(cat).doubleValue(); double _origin = getOrigin(cat).doubleValue(); double lowerBound = Math.min(_origin, _maxValue); double upperBound = Math.max(_origin, _maxValue); boolean lesser = value < lowerBound; boolean greater = value > upperBound; if ((lesser || greater) && !drawOutOfRangePoints) { continue; } if (lesser) { value = lowerBound; } if (greater) { value = upperBound; } double length = _maxValue == _origin ? 0 : (value - lowerBound) / (upperBound - lowerBound); if (_maxValue < _origin) { // inversed length = 1 - length; } Point2D point = getWebPoint(plotArea, angle, length); polygon.addPoint((int) point.getX(), (int) point.getY()); Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); double px = point.getX(); double py = point.getY(); g2.setPaint(paint); if (lesser || greater) { // user crosshair for out-of-range data points distinguish g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)); double delta = 3; g2.draw(new Line2D.Double(px - delta, py, px + delta, py)); g2.draw(new Line2D.Double(px, py - delta, px, py + delta)); } else { // put an elipse at the point being plotted.. Ellipse2D head = new Ellipse2D.Double(px - headW / 2, py - headH / 2, headW, headH); g2.fill(head); g2.setStroke(getHeadOutlineStroke(series)); g2.setPaint(outlinePaint); g2.draw(head); } if (entities != null) { int row = 0; int col = 0; if (this.dataExtractOrder == TableOrder.BY_ROW) { row = series; col = cat; } else { row = cat; col = series; } String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, row, col); } Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH), (int) (headW * 2), (int) (headH * 2)); CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset, this.dataset.getRowKey(row), this.dataset.getColumnKey(col)); entities.add(entity); } } } // Plot the polygon Paint paint = getSeriesPaint(series); g2.setPaint(paint); g2.setStroke(getSeriesOutlineStroke(series)); g2.draw(polygon); // Lastly, fill the web polygon if this is required if (this.webFilled) { g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); g2.fill(polygon); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); } }
From source file:spinworld.gui.RadarPlot.java
/** * Draws the label for one axis./* www.j av a 2s . co m*/ * * @param g2 the graphics device. * @param plotArea whole plot drawing area (e.g. including space for labels) * @param plotDrawingArea the plot drawing area (just spanning of axis) * @param value the value of the label (ignored). * @param cat the category (zero-based index). * @param startAngle the starting angle. * @param extent the extent of the arc. */ protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, Rectangle2D plotDrawingArea, double value, int cat, double startAngle, double extent) { FontRenderContext frc = g2.getFontRenderContext(); String label = null; if (this.dataExtractOrder == TableOrder.BY_ROW) { // if series are in rows, then the categories are the column keys label = this.labelGenerator.generateColumnLabel(this.dataset, cat); } else { // if series are in columns, then the categories are the row keys label = this.labelGenerator.generateRowLabel(this.dataset, cat); } double angle = normalize(startAngle); Font font = getLabelFont(); Point2D labelLocation; do { Rectangle2D labelBounds = font.getStringBounds(label, frc); LineMetrics lm = font.getLineMetrics(label, frc); double ascent = lm.getAscent(); labelLocation = calculateLabelLocation(labelBounds, ascent, plotDrawingArea, startAngle); boolean leftOut = angle > 90 && angle < 270 && labelLocation.getX() < plotArea.getX(); boolean rightOut = (angle < 90 || angle > 270) && labelLocation.getX() + labelBounds.getWidth() > plotArea.getX() + plotArea.getWidth(); if (leftOut || rightOut) { font = font.deriveFont(font.getSize2D() - 1); } else { break; } } while (font.getSize() > 8); Composite saveComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.setPaint(getLabelPaint()); g2.setFont(font); g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY()); g2.setComposite(saveComposite); }
From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java
private void cbo_barChartTableOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbo_barChartTableOrderActionPerformed // TODO add your handling code here: if (this.cbo_barChartTableOrder.getSelectedItem().toString().equals("Column")) { this.datasetTable.setTableOrder(TableOrder.BY_COLUMN); this.refreshData(); } else {/* ww w.j a va 2s. c o m*/ this.datasetTable.setTableOrder(TableOrder.BY_ROW); this.refreshData(); } }
From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java
/** * activate series editor frame (used in change series * tool bar button event//from ww w .j ava 2s . c om */ private void seriesColorEdit() { if (this.pieChartOption.isEnabled()) { String tableOrder = cbo_pieDataSelect.getSelectedItem().toString(); TableOrder tbOrder = null; if (tableOrder.equals("Row")) { tbOrder = TableOrder.BY_ROW; } else { tbOrder = TableOrder.BY_COLUMN; } new SeriesColorEditor(datasetTable, c, table, tbOrder).setVisible(true); } else new SeriesColorEditor(datasetTable, c, table, TableOrder.BY_ROW).setVisible(true); }
From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java
private void groupCategoryByCol() { if (datasetTable.getTableOrder() == TableOrder.BY_ROW) { JOptionPane.showMessageDialog(this, "Can not group column when row orientation is selected!"); return;//from w w w .ja va 2 s . c o m } int[] rows = this.dataviewTable.getSelectedRows(); int[] cols = this.dataviewTable.getSelectedColumns(); String name = null; for (int i = 0; i < cols.length; i++) { if (cols[i] == 0) { JOptionPane.showMessageDialog(this, "Column 1 is not used! please select from column 2 and on"); return; } } if (rows.length > 1 && rows[0] != 0) { JOptionPane.showMessageDialog(this, "Please select only the first row!"); return; } else if (cols.length < 2) { JOptionPane.showMessageDialog(this, "Please select at least 2 categories to group"); return; } else { name = JOptionPane.showInputDialog("Please enter group name!"); if (name == null) return; String colNames[] = new String[cols.length]; for (int i = 0; i < cols.length; i++) { try { colNames[i] = dataviewTable.getValueAt(0, cols[i]).toString(); } catch (Exception ex) { System.out.println(ex.toString()); } } datasetTable.addColGroupKey(name, colNames); //datasetTable.addGroupKey(name); } }
From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java
private void generateBaseDataset() { try {/*from w ww. j a va2 s . c o m*/ if (this.cbo_barChartTableOrder.isEnabled()) { String tableOrder = cbo_barChartTableOrder.getSelectedItem().toString(); TableOrder tbOrder = null; if (tableOrder.equals("Row")) { tbOrder = TableOrder.BY_ROW; this.baseDataset = DatasetUtilities.createCategoryDataset(datasetTable.getRowLabels(), datasetTable.getColumnLabels(table), datasetTable.getTableContentAsValue(table)); } else { tbOrder = TableOrder.BY_COLUMN; this.baseDataset = DatasetUtilities.createCategoryDataset(datasetTable.getColumnLabels(table), datasetTable.getRowLabels(), datasetTable.getTableContentAsValueTranspose(table)); } if (this.opt_subCategory.isSelected() && datasetTable.getGroupKey().length > 0) { groupMap = CustomJFreeChartData.generateGroupedMap(baseDataset, datasetTable.getGroupKey()); } } else { this.baseDataset = DatasetUtilities.createCategoryDataset(datasetTable.getRowLabels(), datasetTable.getColumnLabels(table), datasetTable.getTableContentAsValue(table)); } } catch (Exception ex) { System.out.print("Dataset generation error: " + ex.toString()); JOptionPane.showMessageDialog(this, ex.getMessage()); this.baseDataset = DatasetUtilities.createCategoryDataset("series", "", datasetTable.getTableContentAsValue(table)); } }
From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java
private void generateChart() { //generate Base Dataset (Category Dataset) if (datasetTable != null) this.generateBaseDataset(); if (c != null) { if (this.splitPane.getTopComponent() == panel) { int option = JOptionPane.showConfirmDialog(this, "Create new chart?\r\n", "Warning", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { if (this.cmd_saveChart.isEnabled()) { int innerOption = JOptionPane.showConfirmDialog(this, "Current chart is modified. Do you want to save?\r\n", "Warning", JOptionPane.YES_NO_OPTION); if (innerOption == JOptionPane.YES_OPTION) this.saveFigure(); }// w ww . j av a 2 s . c o m this.figure = null; this.splitPane.remove(panel); } else return; } } if (this.pieChartOption.isSelected()) { //get series PieDataset dataset = null; String series = this.cbo_pieDataSeries.getSelectedItem().toString(); CustomPieChart ch = new CustomPieChart(txt_chartName.getText(), this.opt_legend.isSelected());//legend String tableOrder = cbo_pieDataSelect.getSelectedItem().toString(); TableOrder tbOrder = null; if (tableOrder.equals("Row")) { tbOrder = TableOrder.BY_ROW; } else { tbOrder = TableOrder.BY_COLUMN; } if (this.opt_multiPieCharts.isSelected())//multiple piechart { if (this.opt_effect3D.isSelected()) ch.generateMultiple3DPieChart(baseDataset, tbOrder); else ch.generateMultiplePieChart(baseDataset, tbOrder); if (this.opt_exploded.isSelected()) { try { ch.setExplodePercent(this.cbo_explodedSections.getSelectedItem().toString(), Double.parseDouble(this.txt_explodedPercent.getText())); } catch (Exception ex) { System.out.println("Error setting exploded section! " + ex.getMessage()); } } } else { try { if (tbOrder == TableOrder.BY_ROW) dataset = DatasetUtilities.createPieDatasetForRow(baseDataset, series); else dataset = DatasetUtilities.createPieDatasetForColumn(baseDataset, series); } catch (Exception ex) { System.out.println("Error with pie dataset, default series is used"); dataset = DatasetUtilities.createPieDatasetForRow(baseDataset, 0); } //ch.setIgnoreNullOrZeroValues(true);//ignore null values if (opt_effect3D.isSelected()) { ch.generate3DPieChart(dataset, series, tbOrder); } else { ch.generatePieChart(dataset, series, tbOrder); //edit exploded parts if (this.opt_exploded.isSelected()) { try { ch.setExplodePercent(this.cbo_explodedSections.getSelectedItem().toString(), Double.parseDouble(this.txt_explodedPercent.getText())); } catch (Exception ex) { System.out.println("Error setting exploded section! " + ex.getMessage()); } } } } ch.setIgnoreNullOrZeroValues(true);//ignore null values int labelFormat = cbo_pieSectionLabel.getSelectedIndex(); ch.setLabelFormat(labelFormat); c = ch; this.updateStatus("Pie chart has been generated."); } else if (this.lineChartOption.isSelected()) { // create a chart... PlotOrientation orientation;//options for orientation if (this.opt_layoutV.isSelected()) orientation = PlotOrientation.VERTICAL; else if (this.opt_layoutH.isSelected()) orientation = PlotOrientation.HORIZONTAL; else orientation = PlotOrientation.VERTICAL; CustomLineChart ch = new CustomLineChart(this.txt_chartName.getText(), this.txt_DomainLabel.getText(), this.txt_RangeLabel.getText(), orientation, this.opt_legend.isSelected()); if (opt_effect3D.isSelected()) { ch.generate3DLineChart(baseDataset); } else { ch.generateLineChart(baseDataset); } //apply options if (this.opt_showGridline.isSelected()) { ch.setGridLineVisible(true); } else { ch.setGridLineVisible(false); } c = ch; this.updateStatus("Line chart has been generated."); } else if (this.BarChartOption.isSelected()) { // create a chart... PlotOrientation orientation;//options for orientation if (this.opt_layoutV.isSelected()) orientation = PlotOrientation.VERTICAL; else if (this.opt_layoutH.isSelected()) orientation = PlotOrientation.HORIZONTAL; else orientation = PlotOrientation.VERTICAL; CustomBarChart ch = new CustomBarChart(this.txt_chartName.getText(), this.txt_DomainLabel.getText(), this.txt_RangeLabel.getText(), orientation, opt_legend.isSelected()); if (this.opt_subCategory.isSelected()) { ch.generateGroupBarChart(baseDataset, groupMap); ch.setSubCategoryAxis(txt_DomainLabel.getText(), datasetTable.getGroupKey()); } else { if (opt_effect3D.isSelected()) { if (this.opt_effectStacked.isSelected()) ch.generate3DStackedBarChart(baseDataset); else ch.generate3DBarChart(baseDataset); } else { if (this.opt_effectStacked.isSelected()) ch.generateStackedBarChart(baseDataset); else ch.generateBarChart(baseDataset); } } //apply options if (this.opt_showGridline.isSelected()) { ch.setGridLineVisible(true); } else { ch.setGridLineVisible(false); } if (this.opt_showItemLabel.isSelected()) { ch.setItemLabelGenerator(txt_itemLabelFormat.getText(), Integer.parseInt(cbo_itemLabelSize.getSelectedItem().toString())); ch.setItemLabelVisible(true); } c = ch; this.updateStatus("Bar chart has been generated."); } else if (this.combinedChartOption.isSelected()) { //not available yet } else { JOptionPane.showMessageDialog(this, "Please select chart type first!"); return; } //c.generate3DStackedBarChart(baseDataset); ChartFrame f = c.drawChart(""); panel = f.getChartPanel(); splitPane.setDividerLocation(panel.getHeight()); this.splitPane.setTopComponent(panel); //ChartPanel.add(panel); //panel.setSize(500, splitPane.getWidth()); if (panel != null) panel.addHierarchyBoundsListener(new java.awt.event.HierarchyBoundsListener() { @Override public void ancestorResized(java.awt.event.HierarchyEvent evt) { panelAncestorResized(evt); }; @Override public void ancestorMoved(HierarchyEvent e) { } }); this.cmd_saveChart.setEnabled(true); this.cmd_changeSeriesColor.setEnabled(true); this.cmd_generateChart.setEnabled(false); }