Example #1
0
  @Override
  public void setColor(Color color) {

    ArrayBlockingQueue<Color> colorHistory = getColorHistory();

    // Check that the color does not already exist
    boolean exists = false;
    Iterator<Color> iter = colorHistory.iterator();
    while (iter.hasNext()) {
      if (color.equals(iter.next())) {
        exists = true;
        break;
      }
    }

    // If the color does not exist then add it
    if (!exists) {
      if (!colorHistory.offer(color)) {
        colorHistory.poll();
        colorHistory.offer(color);
      }
    }

    List<Color> colorList = new ArrayList<Color>(colorHistory);

    // Invert order of colors
    Collections.reverse(colorList);

    // Move the selected color to the front of the list
    Collections.swap(colorList, colorList.indexOf(color), 0);

    // Create 2d color map
    Color[][] colors = new Color[rows][columns];
    iter = colorList.iterator();

    for (int row = 0; row < rows; row++) {
      for (int col = 0; col < columns; col++) {
        if (iter.hasNext()) {
          colors[row][col] = iter.next();
        } else {
          colors[row][col] = Color.WHITE;
        }
      }
    }

    grid.setColorGrid(colors);
    grid.markAsDirty();
  }
Example #2
0
 private void updateSelectedCellsFontColor(Color newColor) {
   if (spreadsheet != null && newColor != null) {
     List<Cell> cellsToRefresh = new ArrayList<Cell>();
     for (CellReference cellRef : spreadsheet.getSelectedCellReferences()) {
       Cell cell = getOrCreateCell(cellRef);
       // Workbook workbook = spreadsheet.getWorkbook();
       XSSFCellStyle style = (XSSFCellStyle) cloneStyle(cell);
       XSSFColor color = new XSSFColor(java.awt.Color.decode(newColor.getCSS()));
       XSSFFont font = (XSSFFont) cloneFont(style);
       font.setColor(color);
       style.setFont(font);
       cell.setCellStyle(style);
       cellsToRefresh.add(cell);
     }
     // Update all edited cells
     spreadsheet.refreshCells(cellsToRefresh);
   }
 }
Example #3
0
  private void updateSelectedCellsBackgroundColor(Color newColor) {
    if (spreadsheet != null && newColor != null) {
      List<Cell> cellsToRefresh = new ArrayList<Cell>();
      for (CellReference cellRef : spreadsheet.getSelectedCellReferences()) {
        // Obtain Cell using CellReference
        Cell cell = getOrCreateCell(cellRef);
        // Clone Cell CellStyle
        // This cast an only be done when using .xlsx files
        XSSFCellStyle style = (XSSFCellStyle) cloneStyle(cell);
        XSSFColor color = new XSSFColor(java.awt.Color.decode(newColor.getCSS()));
        // Set new color value
        style.setFillForegroundColor(color);
        cell.setCellStyle(style);

        cellsToRefresh.add(cell);
      }
      // Update all edited cells
      spreadsheet.refreshCells(cellsToRefresh);
    }
  }
  /**
   * Returns the generated HighCharts script.
   *
   * @return A rendered {@link at.downdrown.vaadinaddons.highchartsapi.HighChart} object.
   */
  public String getHighChartValue() throws HighChartsException {

    if (getChartType() == null)
      throw new NoChartTypeException("No ChartType is set to the configuration.");
    StringBuilder builder = new StringBuilder();
    builder.append("{");
    // Chart properties
    builder.append("chart: { renderTo: 'container' ");
    builder.append(",type: '" + getChartType().getHighchartsvalue() + "'");
    // Set Background
    if (getBackgroundColor() != null) {
      builder.append(",backgroundColor: '" + getBackgroundColor().getCSS() + "'");
    } else {
      builder.append(",backgroundColor: 'transparent'");
    }
    if (getChartMargin() != null) builder.append(getChartMargin().getHighChartValue());

    if (this.zoomType != null)
      builder.append(", zoomZype: '" + this.zoomType.name().toLowerCase() + "'");

    // Chart Properties End
    builder.append("}");

    // Set Title if any was given
    builder.append(", title: { ");
    if (getTitle() != null) {
      builder.append("text: '" + getTitle() + "'");
    } else {
      builder.append("text: null");
    }
    builder.append(", style: { ");
    builder.append("fontFamily: '" + titleFont + "'");
    builder.append(", color: '" + titleFontColor.getCSS() + "'");
    builder.append(", fontSize: '" + titleFontSize + "px'");
    builder.append(", textShadow: false");
    builder.append("}");
    builder.append("}");

    // Set Subtitle if any was given
    builder.append(", subtitle: { ");
    if (getSubTitle() != null) {
      builder.append("text: '" + subTitle + "'");
    } else {
      builder.append("text: null");
    }
    builder.append(", style: { ");
    builder.append("fontFamily: '" + subTitleFont + "'");
    builder.append(", color: '" + subTitleFontColor.getCSS() + "'");
    builder.append(", fontSize: '" + subTitleFontSize + "px'");
    builder.append(", textShadow: false");
    builder.append("}");
    builder.append("}");

    if (getxAxis() != null) builder.append(", " + getxAxis().getHighChartValue());
    if (getyAxis() != null) builder.append(", " + getyAxis().getHighChartValue());

    builder.append(", credits: { enabled: " + isCreditsEnabled() + " }");
    builder.append(", legend: { enabled: " + isLegendEnabled() + " }");
    builder.append(", tooltip: { enabled: " + isTooltipEnabled() + " }");

    if (!getSeriesList().isEmpty()) {
      int seriesNr = 1;
      builder.append(", series: [");
      for (HighChartsSeries series : getSeriesList()) {
        if (getChartType() != series.getChartType())
          throw new WrongSeriesException(
              "The passed series object has a different chart type than the configuration. Series: "
                  + series.getChartType()
                  + " / Configuration: "
                  + getChartType());
        if (seriesNr == 1) {
          builder.append(series.getHighChartValue());
        } else if (seriesNr > 1) {
          builder.append(",");
          builder.append(series.getHighChartValue());
        }
        seriesNr++;
      }
      builder.append("]");
    }

    if (!this.colors.isEmpty()) {
      int colorsNr = 1;
      builder.append(", colors: [");
      for (Color color : getColors()) {
        if (colorsNr == 1) {
          builder.append("'" + color.getCSS() + "'");
        } else if (colorsNr > 1) {
          builder.append(",");
          builder.append("'" + color.getCSS() + "'");
        }
        colorsNr++;
      }
      builder.append("]");
    }

    if (this.plotOptions != null) {
      if (this.plotOptions.getChartType() != this.chartType) {
        throw new WrongPlotOptionsException(
            "Different chart types in configuration and plotOptions.");
      } else {
        builder.append(this.plotOptions.getHighChartValue());
      }
    } else {
      if (this.chartType == ChartType.AREA)
        builder.append(new AreaChartPlotOptions().getHighChartValue());
      if (this.chartType == ChartType.BAR)
        builder.append(new BarChartPlotOptions().getHighChartValue());
      if (this.chartType == ChartType.COLUMN)
        builder.append(new ColumnChartPlotOptions().getHighChartValue());
      if (this.chartType == ChartType.LINE)
        builder.append(new LineChartPlotOptions().getHighChartValue());
      if (this.chartType == ChartType.PIE)
        builder.append(new PieChartPlotOptions().getHighChartValue());
    }

    builder.append(" };");
    return builder.toString();
  }