/** if a button is pressed ... */
  public void actionPerformed(ActionEvent evt) {
    try {
      String acmd = evt.getActionCommand();

      if (acmd.equals(ACTION_CMD_PRINT)) {

        this.chartPanel.createChartPrintJob();

      } else if (acmd.equals(ACTION_CMD_SAVE_AS)) {

        this.chartPanel.doSaveAs();

      } else if (acmd.equals(ACTION_CMD_ZOOM_IN)) {

        ChartRenderingInfo info = chartPanel.getChartRenderingInfo();
        Rectangle2D rect = info.getChartArea();
        chartPanel.setZoomInFactor(ZOOM_FACTOR);
        chartPanel.zoomInDomain(rect.getCenterX(), rect.getCenterY());
      } else if (acmd.equals(ACTION_CMD_ZOOM_OUT)) {

        ChartRenderingInfo info = chartPanel.getChartRenderingInfo();
        Rectangle2D rect = info.getChartArea();
        chartPanel.setZoomOutFactor(1 / ZOOM_FACTOR);
        chartPanel.zoomOutDomain(rect.getCenterX(), rect.getCenterY());

      } else if (acmd.equals(ACTION_CMD_ZOOM_TO_FIT)) {
        // X-axis (has no fixed borders)
        chartPanel.restoreAutoBounds();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#2
0
    /* (non-Javadoc)
     * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
     */
    @Override
    public void paint(Graphics g) {
      super.paint(g);

      if (rect != null) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(Color.RED);

        adjustRect(rect);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setStroke(lineStroke);

        if (boundings == null) {
          boundings = new Rectangle[4];

          if (entities == null) {
            entities = new ArrayList<CategoryItemEntity>();
            EntityCollection entCol = chartPanel.getChartRenderingInfo().getEntityCollection();

            for (int i = 0; i < entCol.getEntityCount(); i++) {
              ChartEntity ce = (ChartEntity) entCol.getEntity(i);
              if (ce instanceof CategoryItemEntity) {
                CategoryItemEntity cie = (CategoryItemEntity) ce;
                Rectangle r = adjustRect(cie.getArea().getBounds());
                if (r.height > maxHeight) {
                  maxHeight = (int) cie.getArea().getBounds().getHeight();
                  maxY = r.y;
                }
                entities.add(cie);
              }
            }
          }

          int half = (entities.size() - 1) / 2;
          boundings[0] = getEntityPoint(entities, 0);
          boundings[1] = getEntityPoint(entities, half);
          boundings[2] = getEntityPoint(entities, half + 1);
          boundings[3] = getEntityPoint(entities, entities.size() - 1);

          int[] inxs = new int[] {0, half, half + 1, entities.size() - 1};
          currEntities = new CategoryItemEntity[4];
          for (int i = 0; i < inxs.length; i++) {
            currEntities[i] = entities.get(inxs[i]);
          }
        }

        for (Rectangle r : boundings) {
          g.drawImage(
              thumb.getImage(),
              r.x - (thumb.getIconWidth() / 2) + 2,
              r.y + r.height - thumb.getIconHeight(),
              null);
        }

        int x = (int) ((double) boundings[0].x * 1); // chartPanel.getScaleX());
        int w = (int) ((double) (boundings[1].x - boundings[0].x) * 1); // chartPanel.getScaleX());

        // int y = (int)((double)maxY * chartPanel.getScaleY());
        int h = (int) ((double) maxHeight * chartPanel.getScaleY());

        g2d.setColor(new Color(255, 255, 255, 64));
        g2d.fillRect(x + 2, maxY, w, h);

        x = (int) ((double) boundings[2].x * 1); // chartPanel.getScaleX());
        w = (int) ((double) (boundings[3].x - boundings[2].x) * 1); // chartPanel.getScaleX());

        g2d.setColor(new Color(255, 255, 255, 64));
        g2d.fillRect(x + 2, maxY, w, h);
      }
    }