Here you can find the source of drawEditableBackground(Graphics2D g2d, Color leftColor, Color rightColor, int width, int height, int iconWidth, boolean isReversed)
public static void drawEditableBackground(Graphics2D g2d, Color leftColor, Color rightColor, int width, int height, int iconWidth, boolean isReversed)
//package com.java2s; /*//w ww.j ava2 s . co m * * This file is part of Genome Artist. * * Genome Artist is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Genome Artist is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Genome Artist. If not, see <http://www.gnu.org/licenses/>. * */ import java.awt.Color; import java.awt.Graphics2D; public class Main { /** * Desenez fundalul unei celule editabile */ public static void drawEditableBackground(Graphics2D g2d, Color leftColor, Color rightColor, int width, int height, int iconWidth, boolean isReversed) { //FUnctia nu trebuie sa altereze culoarea de fundal la final Color oldColor = g2d.getColor(); //Umplu panoul cu culoarea din dreapta g2d.setColor(rightColor); g2d.fillRect(0, 0, width, height); //Desenez un shield de culoare intermediara Color intermediateColor = colorAverage(leftColor, rightColor); g2d.setColor(intermediateColor); if (isReversed) { g2d.fillRect(width - iconWidth, 0, iconWidth, height); } else { g2d.fillRect(0, 0, iconWidth, height); } //Refac setarile de culoare initiale g2d.setColor(oldColor); } /** * Returns the average of two colors * @param color1 * @param color2 * @return */ public static Color colorAverage(Color color1, Color color2) { int redValue = (color1.getRed() + color2.getRed()) / 2; int greenValue = (color1.getGreen() + color2.getGreen()) / 2; int blueValue = (color1.getBlue() + color2.getBlue()) / 2; return new Color(redValue, greenValue, blueValue); } }