Ejemplo n.º 1
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Dimension theSize = getSize();

    if (mColorListMode == VisualizationColor.cColorListModeCategories) {
      int categories = mCategoryColorList.length;
      if (categories <= cMaxEditableColors) {
        int fieldWidth = (theSize.width - 2 * cBorder + cSpacing) / categories - cSpacing;
        mRect = new Rectangle[categories];
        for (int i = 0; i < categories; i++) {
          mRect[i] =
              new Rectangle(
                  cBorder + i * (fieldWidth + cSpacing),
                  cBorder,
                  fieldWidth,
                  theSize.height - 2 * cBorder);
          drawColorButton(g, i);
        }
      } else {
        final String message = "<too many colors to edit>";
        g.setColor(Color.GRAY);
        g.setFont(new Font("Arial", Font.BOLD, 13));
        FontMetrics m = g.getFontMetrics();
        g.drawString(
            message,
            (theSize.width - m.stringWidth(message)) / 2,
            (theSize.height + m.getHeight()) / 2 - m.getDescent());
      }
    } else {
      int size = theSize.height - 2 * cBorder;
      int x1 = 2 * cBorder + size;
      int x2 = theSize.width - 2 * cBorder - size;
      mRect = new Rectangle[3];
      mRect[0] = new Rectangle(cBorder, cBorder, size, size);
      mRect[1] =
          new Rectangle(
              theSize.width - size - cBorder, theSize.height - size - cBorder, size, size);
      mRect[cColorWedgeButton] = new Rectangle(x1, cBorder, x2 - x1, size);
      drawColorButton(g, 0);
      drawColorButton(g, 1);
      drawColorButton(g, cColorWedgeButton);
    }
  }