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); } }
private void drawColorButton(Graphics g, int no) { g.setColor(cDarkShadowColor); g.drawLine(mRect[no].x, mRect[no].y, mRect[no].x + mRect[no].width - 2, mRect[no].y); g.drawLine(mRect[no].x, mRect[no].y, mRect[no].x, mRect[no].y + mRect[no].height - 2); g.drawLine( mRect[no].x + mRect[no].width - 2, mRect[no].y + 2, mRect[no].x + mRect[no].width - 2, mRect[no].y + mRect[no].height - 2); g.drawLine( mRect[no].x + 2, mRect[no].y + mRect[no].height - 2, mRect[no].x + mRect[no].width - 2, mRect[no].y + mRect[no].height - 2); if (mPressedButton != no || !mMouseOverButton) g.setColor(Color.white); g.drawLine( mRect[no].x + 1, mRect[no].y + 1, mRect[no].x + mRect[no].width - 3, mRect[no].y + 1); g.drawLine( mRect[no].x + 1, mRect[no].y + 1, mRect[no].x + 1, mRect[no].y + mRect[no].height - 3); if (mPressedButton == no && mMouseOverButton) g.setColor(Color.white); g.drawLine( mRect[no].x + mRect[no].width - 1, mRect[no].y + 1, mRect[no].x + mRect[no].width - 1, mRect[no].y + mRect[no].height - 1); g.drawLine( mRect[no].x + 1, mRect[no].y + mRect[no].height - 1, mRect[no].x + mRect[no].width - 1, mRect[no].y + mRect[no].height - 1); if (mColorListMode != VisualizationColor.cColorListModeCategories && no == cColorWedgeButton) { int x1 = mRect[no].x + 2; int x2 = x1 + mRect[no].width - 4; if (x1 < x2) { for (int x = x1; x < x2; x++) { int c = mWedgeColorList.length * (x - x1) / (x2 - x1); g.setColor( (mPressedButton == no && mMouseOverButton) ? mWedgeColorList[c].darker() : mWedgeColorList[c]); g.drawLine(x, mRect[no].y + 2, x, mRect[no].y + mRect[no].height - 3); } } } else { Color color = (mColorListMode == VisualizationColor.cColorListModeCategories) ? mCategoryColorList[no] : mWedgeColorList[no * (mWedgeColorList.length - 1)]; if (mPressedButton == no && mMouseOverButton) color = color.darker(); g.setColor(color); g.fillRect(mRect[no].x + 2, mRect[no].y + 2, mRect[no].width - 4, mRect[no].height - 4); } }