Example usage for java.lang Comparable toString

List of usage examples for java.lang Comparable toString

Introduction

In this page you can find the example usage for java.lang Comparable toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.adempiere.apps.graph.Graph.java

/**
 * Get BarGraphColumn for ChartEntity/* w  w  w . ja v a  2  s.  c  o  m*/
 * @param event
 * @return BarGraphColumn or null if not found
 */
private GraphColumn getGraphColumn(ChartMouseEvent event) {
    ChartEntity entity = event.getEntity();
    String key = null;
    if (entity instanceof CategoryItemEntity) {
        Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey();
        if (colKey != null) {
            key = colKey.toString();
        }
    } else if (entity instanceof PieSectionEntity) {
        Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
        if (sectionKey != null) {
            key = sectionKey.toString();
        }
    }
    if (key == null) {
        return null;
    }
    for (int i = 0; i < list.size(); i++) {
        final String label = list.get(i).getLabel();
        if (key.equals(label)) {
            return list.get(i);
        }
    }
    //
    return null;
}

From source file:org.pentaho.platform.uifoundation.chart.PentahoChartURLTagFragmentGenerator.java

@Override
public String generateURLFragment(final String urlText) {
    if (urlFragment != null) {

        String urlTemplate = " href=\""; //$NON-NLS-1$

        // do not add ase URL if script
        boolean isScript = urlFragment.startsWith("javascript:"); //$NON-NLS-1$ 

        // If isScript is true, ignore useBaseURL parameter...
        if (!isScript) {
            if (useBaseUrl) {
                urlTemplate += PentahoSystem.getApplicationContext().getFullyQualifiedServerURL();
            }/*  w w w  .j  av  a 2s. c  om*/
        }

        // Handle " in the urlFragment
        urlTemplate += urlFragment.replaceAll("\"", "%22") + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 

        String value = null;
        String itemValue = null;

        // Do we have a 'category=' as part of the urlText in? If so, grab the value from the urlText
        // this is the replacement value for the paramName parameter (when categorical).
        value = retrieveValue(PentahoChartURLTagFragmentGenerator.CATEGORY_TAG, urlText);

        if (value != null) {
            urlTemplate = TemplateUtil.applyTemplate(urlTemplate, parameterName, value); // <paramName> replacement
                                                                                         // value
        }

        // Do we have a 'series=' as part of the urlText in? If so, grab the value from the urlText
        // this is the replacement value for the series-name parameter.
        value = retrieveValue(PentahoChartURLTagFragmentGenerator.SERIES_TAG, urlText);
        if (value != null) {

            if ((dataset instanceof CategoryDatasetChartDefinition)
                    || (dataset instanceof XYZSeriesCollectionChartDefinition)) {

                urlTemplate = TemplateUtil.applyTemplate(urlTemplate, seriesName, value); // <series-name> replacement
                                                                                          // value

            } else if (dataset instanceof XYDataset) {

                XYDataset set = (XYDataset) dataset;
                Comparable<?> seriesKey = set.getSeriesKey(Integer.parseInt(value));
                urlTemplate = TemplateUtil.applyTemplate(urlTemplate, seriesName, seriesKey.toString()); // <series-name>
                                                                                                         // replacement
                                                                                                         // value

                // Do we have an 'item=' as part of the urlText in? If so, grab the value from the urlText
                // this is the replacement value for the paramName parameter, when the chart is an x/y plot.
                itemValue = retrieveValue(PentahoChartURLTagFragmentGenerator.ITEM_TAG, urlText);

                if (itemValue != null) {

                    int itemVal = Integer.parseInt(itemValue);
                    int val = Integer.parseInt(value);

                    Object x = null;
                    Number xNum = set.getX(val, itemVal);
                    x = (xNum instanceof Long) ? new Date((Long) xNum) : xNum;

                    urlTemplate = TemplateUtil.applyTemplate(urlTemplate, parameterName, x.toString()); // <paramName>
                                                                                                        // replacement
                                                                                                        // value

                    // This value is NEW. We have never returned more than 2 parameters in the url-template.
                    // A logical extension for x/y plots is to return the series, the x value and the y value.
                    // However, the item value is not plumbed through to the chart definition yet.
                    Object y = null;
                    Number yNum = set.getY(val, itemVal);
                    y = (yNum instanceof Long) ? new Date((Long) yNum) : yNum;

                    urlTemplate = TemplateUtil.applyTemplate(urlTemplate, "ITEM", y.toString()); // {ITEM} replacement
                                                                                                 // value,
                                                                                                 // in the
                                                                                                 // url-template. There
                                                                                                 // is no
                                                                                                 // parameter
                                                                                                 // plumbed for this.
                }
            }
        }

        if (!isScript) {
            urlTemplate = urlTemplate + " target=\"" + urlTarget + "\""; //$NON-NLS-1$//$NON-NLS-2$ 
        }

        return urlTemplate;
    } else {
        return super.generateURLFragment(urlText);
    }
}

From source file:com.itemanalysis.jmetrik.graph.piechart.PieChartPanel.java

public void updateDefaultPieDataset(TwoWayTable table) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Iterator<Comparable<?>> rowIter = table.rowValuesIterator();
    Iterator<Comparable<?>> colIter = null;
    Comparable<?> r = null;
    Comparable<?> c = null;

    while (rowIter.hasNext()) {
        r = rowIter.next();//from w ww .ja  v a2  s  .c  om
        colIter = table.colValuesIterator();
        while (colIter.hasNext()) {
            c = colIter.next();
            dataset.setValue(c.toString(), table.getCount(r, c));
        }
    }
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDataset(dataset);
}

From source file:com.itemanalysis.jmetrik.stats.frequency.FrequencyAnalysis.java

public void publishTable(VariableAttributes v) {
    TextTableColumnFormat[] cformats = new TextTableColumnFormat[6];
    cformats[0] = new TextTableColumnFormat();
    cformats[0].setStringFormat(11, TextTableColumnFormat.OutputAlignment.LEFT);
    cformats[1] = new TextTableColumnFormat();
    cformats[1].setIntFormat(10, TextTableColumnFormat.OutputAlignment.RIGHT);
    cformats[2] = new TextTableColumnFormat();
    cformats[2].setDoubleFormat(10, 4, TextTableColumnFormat.OutputAlignment.RIGHT);
    cformats[3] = new TextTableColumnFormat();
    cformats[3].setDoubleFormat(10, 4, TextTableColumnFormat.OutputAlignment.RIGHT);
    cformats[4] = new TextTableColumnFormat();
    cformats[4].setIntFormat(10, TextTableColumnFormat.OutputAlignment.RIGHT);
    cformats[5] = new TextTableColumnFormat();
    cformats[5].setDoubleFormat(10, 4, TextTableColumnFormat.OutputAlignment.RIGHT);

    Frequency temp = frequencyTables.get(v);

    TextTable table = new TextTable();
    table.addAllColumnFormats(cformats, 4);
    table.getRowAt(0).addHeader(0, 6, v.getName().toString(), TextTablePosition.CENTER);
    table.getRowAt(1).addHorizontalRule(0, 6, "=");
    table.getRowAt(2).addHeader(0, 1, "Value", TextTablePosition.CENTER);
    table.getRowAt(2).addHeader(1, 1, "Frequency", TextTablePosition.CENTER);
    table.getRowAt(2).addHeader(2, 1, "Percent", TextTablePosition.CENTER);
    table.getRowAt(2).addHeader(3, 1, "Valid Pct.", TextTablePosition.CENTER);
    table.getRowAt(2).addHeader(4, 1, "Cum. Freq.", TextTablePosition.CENTER);
    table.getRowAt(2).addHeader(5, 1, "Cum. Pct.", TextTablePosition.CENTER);
    table.getRowAt(3).addHorizontalRule(0, 6, "-");

    Iterator<Comparable<?>> iter = temp.valuesIterator();

    int index = 4;
    double pctSum = 0.0;
    long validSum = temp.getSumFreq();
    long miss = (long) (maxProgress - validSum);

    while (iter.hasNext()) {
        table.addRow(new TextTableRow(cformats.length), cformats);

        Comparable<?> value = iter.next();
        table.addStringAt(index, 0, value.toString());
        table.addLongAt(index, 1, temp.getCount(value));
        table.addDoubleAt(index, 2, ((double) temp.getCount(value) / maxProgress) * 100);
        table.addDoubleAt(index, 3, temp.getPct(value) * 100);
        table.addLongAt(index, 4, temp.getCumFreq(value));
        table.addDoubleAt(index, 5, temp.getCumPct(value) * 100);
        index++;//www  .  ja  v a2  s. co m
        pctSum += (double) temp.getCount(value) / (double) maxProgress;
    }

    table.addRow(new TextTableRow(cformats.length), cformats);
    table.addStringAt(index, 0, "Valid Total");
    table.addLongAt(index, 1, validSum);
    table.addDoubleAt(index, 2, pctSum * 100);
    table.addDoubleAt(index, 3, (double) validSum / (double) (maxProgress - miss) * 100);
    index++;

    table.addRow(new TextTableRow(cformats.length), cformats);
    table.addStringAt(index, 0, "Missing");
    table.addLongAt(index, 1, miss);
    table.addDoubleAt(index, 2, ((double) miss / maxProgress) * 100);
    index++;

    table.addRow(new TextTableRow(cformats.length), cformats);
    table.addStringAt(index, 0, "Grand Total");
    table.addLongAt(index, 1, (long) maxProgress);
    table.addDoubleAt(index, 2, ((double) (miss + temp.getSumFreq()) / maxProgress) * 100);
    index++;

    table.addRow(new TextTableRow(cformats.length), cformats);
    table.getRowAt(index).addHorizontalRule(0, 6, "=");
    publish(table.toString() + "\n");
}

From source file:org.cyberoam.iview.charts.CustomCategoryAxis.java

/**
 * Label creation //from   www  .  ja va2  s.c  o m
 * @return will return textblock of label
 */
protected TextBlock createLabel(Comparable category, float width, RectangleEdge edge, Graphics2D g2) {
    String labelValue = category.toString().substring(2);
    if (labelValue == null || "".equalsIgnoreCase(labelValue) || "null".equalsIgnoreCase(labelValue)) {
        labelValue = "N/A";
    } else if (getLabelFormat() == TabularReportConstants.PROTOCOL_FORMATTING
            && labelValue.indexOf(':') != -1) {
        String data = ProtocolBean
                .getProtocolNameById(Integer.parseInt(labelValue.substring(0, labelValue.indexOf(':'))));
        labelValue = data + labelValue.substring(labelValue.indexOf(':'), labelValue.length());
    } else if (getLabelFormat() == TabularReportConstants.SEVERITY_FORMATTING) {
        labelValue = TabularReportConstants.getSeverity(labelValue);
    }
    return super.createLabel(labelValue, width, edge, g2);
}

From source file:org.datacleaner.widgets.result.ValueDistributionResultSwingRendererGroupDelegate.java

protected String getDataSetKey(int i) {
    Comparable<?> key = _dataset.getRowKey(i);
    assert key instanceof String;
    return key.toString();
}

From source file:org.adempiere.webui.editor.WChartEditor.java

private void render(JFreeChart chart) {
    ChartRenderingInfo info = new ChartRenderingInfo();
    int width = 400;
    int height = chartModel.getWinHeight();
    BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info);
    try {/*from ww w .j  av a  2s . co  m*/
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage image = new AImage("", bytes);
        Imagemap myImage = new Imagemap();

        Panel panel = getComponent();
        myImage.setContent(image);
        if (panel.getPanelchildren() != null) {
            panel.getPanelchildren().getChildren().clear();
            panel.getPanelchildren().appendChild(myImage);
        } else {
            Panelchildren pc = new Panelchildren();
            panel.appendChild(pc);
            pc.appendChild(myImage);
        }

        int count = 0;
        for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) {
            ChartEntity entity = (ChartEntity) it.next();

            String key = null;
            String seriesName = null;
            if (entity instanceof CategoryItemEntity) {
                CategoryItemEntity item = ((CategoryItemEntity) entity);
                Comparable<?> colKey = item.getColumnKey();
                Comparable<?> rowKey = item.getRowKey();
                if (colKey != null && rowKey != null) {
                    key = colKey.toString();
                    seriesName = rowKey.toString();
                }
            } else if (entity instanceof PieSectionEntity) {
                Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
                if (sectionKey != null) {
                    key = sectionKey.toString();
                }
            }
            if (entity instanceof XYItemEntity) {
                XYItemEntity item = ((XYItemEntity) entity);
                if (item.getDataset() instanceof TimeSeriesCollection) {
                    TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset();
                    TimeSeries series = data.getSeries(item.getSeriesIndex());
                    TimeSeriesDataItem dataitem = series.getDataItem(item.getItem());
                    seriesName = series.getKey().toString();
                    key = dataitem.getPeriod().toString();
                }
            }

            if (key == null)
                continue;

            Area area = new Area();
            myImage.appendChild(area);
            area.setCoords(entity.getShapeCoords());
            area.setShape(entity.getShapeType());
            area.setTooltiptext(entity.getToolTipText());
            area.setId(count + "_WG__" + seriesName + "__" + key);
            count++;
        }

        myImage.addEventListener(Events.ON_CLICK, new EventListener() {
            public void onEvent(Event event) throws Exception {
                MouseEvent me = (MouseEvent) event;
                String areaId = me.getArea();
                if (areaId != null) {
                    String[] strs = areaId.split("__");
                    if (strs.length == 3) {
                        chartMouseClicked(strs[2], strs[1]);
                    }
                }
            }
        });
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }

}

From source file:com.itemanalysis.jmetrik.graph.piechart.PieChartPanel.java

public void updateDefaultCategoryDataset(TwoWayTable table) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Iterator<Comparable<?>> rowIter = table.rowValuesIterator();
    Iterator<Comparable<?>> colIter = null;
    Comparable<?> r = null;
    Comparable<?> c = null;

    while (rowIter.hasNext()) {
        r = rowIter.next();/*w  w w.ja  v a2  s . c  om*/
        colIter = table.colValuesIterator();
        while (colIter.hasNext()) {
            c = colIter.next();
            dataset.addValue(table.getCount(r, c), r.toString(), c.toString());
        }
    }
    MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    plot.setDataset(dataset);
}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.interactivepiechartfilters.JfreeDivaPieChartFilter.java

private String initPieChart(int width, int height) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int x = 0; x < labels.length; x++) {
        dataset.setValue(labels[x], new Double(values[x]));

    }/* w  w w  . java  2s .c  o  m*/
    plot = new PiePlot(dataset);
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);

    plot.setLabelGap(0);

    plot.setLabelFont(new Font("Verdana", Font.BOLD, 15));
    plot.setLabelGenerator(new PieSectionLabelGenerator() {

        @Override
        public String generateSectionLabel(PieDataset pd, Comparable cmprbl) {
            return valuesMap.get(cmprbl.toString());
        }

        @Override
        public AttributedString generateAttributedSectionLabel(PieDataset pd, Comparable cmprbl) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    plot.setSimpleLabels(true);

    plot.setLabelBackgroundPaint(null);
    plot.setLabelShadowPaint(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelOutlinePaint(null);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInteriorGap(0);
    plot.setShadowPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f));
    plot.setInteriorGap(0.05);
    for (String label : labels) {
        plot.setSectionPaint(label, defaultKeyColorMap.get(label));
    }

    chart = new JFreeChart(plot);
    chart.setTitle(
            new TextTitle(Local_Filter_Manager.getFilterTitle(filter_Id), new Font("Verdana", Font.BOLD, 13)));
    chart.setBorderPaint(null);
    chart.setBackgroundPaint(null);
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setItemFont(new Font("Verdana", Font.PLAIN, 12));
    String imgUrl = saveToFile(chart, width, height);

    return imgUrl;

}

From source file:ch.unibe.iam.scg.archie.controller.ProviderChartFactory.java

/**
 * @param dataset//from   w  w  w . ja  va  2s .c  o  m
 * @return
 */
private DefaultCategoryDataset createJFreeBarDataset(DataSet dataset) {
    DefaultCategoryDataset categoryDataSet = new DefaultCategoryDataset();

    int[] rows = this.model.getRows();
    int[] columns = this.model.getColumns();

    int rowTitleColumnIndex = this.model.getCategoryColumnIndex();

    for (int i = 0; i < rows.length; i++) {
        int rowIndex = rows[i];

        Comparable<?>[] row = dataset.getRow(rowIndex);

        String rowTitle = row[rowTitleColumnIndex].toString();

        for (int j = 0; j < columns.length; j++) {
            double value = 0.0;
            int columnIndex = columns[j];

            String columnTitle = (String) dataset.getHeadings().get(columnIndex);

            Comparable<?> cell = dataset.getCell(rowIndex, columnIndex);

            if (cell instanceof Money) {
                value = ((Money) cell).doubleValue();
            } else {
                value = new Double(cell.toString());
            }

            categoryDataSet.addValue(value, columnTitle, rowTitle);
        }
    }

    return categoryDataSet;
}