Exemplo n.º 1
0
 private void paintBell(Graphics g) {
   P9TermPreferences preferences = P9Term.getPreferences();
   if (preferences.getBoolean(P9TermPreferences.VISUAL_BELL) == false) {
     return;
   }
   Color foreground = preferences.getColor(P9TermPreferences.FOREGROUND_COLOR);
   if (preferences.getBoolean(P9TermPreferences.FANCY_BELL)) {
     // On decent hardware, we can produce a really tasteful effect by compositing a
     // semi-transparent rectangle over the terminal.
     // We need to choose a color that will show up against the background.
     // A reasonable assumption is that the user has already chosen such a color for the
     // foreground.
     Color color =
         new Color(foreground.getRed(), foreground.getGreen(), foreground.getBlue(), 100);
     g.setColor(color);
     g.fillRect(0, 0, getWidth(), getHeight());
   } else {
     // On a remote X11 display (or really rubbish hardware) the compositing effect is
     // prohibitively expensive, so we offer XOR instead.
     Color background = preferences.getColor(P9TermPreferences.BACKGROUND_COLOR);
     ;
     final int R = blend(background.getRed(), foreground.getRed());
     final int G = blend(background.getGreen(), foreground.getGreen());
     final int B = blend(background.getBlue(), foreground.getBlue());
     g.setColor(background);
     g.setXORMode(new Color(R, G, B));
     g.fillRect(0, 0, getWidth(), getHeight());
     g.setPaintMode();
   }
 }
Exemplo n.º 2
0
  /**
   * Sets the selected color of this panel.
   *
   * <p>If this panel is in RED, GREEN, or BLUE mode, then this method converts these values to RGB
   * coordinates and calls <code>setRGB</code>.
   *
   * <p>This method may regenerate the graphic if necessary.
   *
   * @param h the hue value of the selected color.
   * @param s the saturation value of the selected color.
   * @param b the brightness value of the selected color.
   */
  public void setHSB(float h, float s, float b) {
    if (Float.isInfinite(h) || Float.isNaN(h))
      throw new IllegalArgumentException("The hue value (" + h + ") is not a valid number.");
    // hue is cyclic, so it can be any value:
    while (h < 0) h++;
    while (h > 1) h--;

    if (s < 0 || s > 1)
      throw new IllegalArgumentException("The saturation value (" + s + ") must be between [0,1]");
    if (b < 0 || b > 1)
      throw new IllegalArgumentException("The brightness value (" + b + ") must be between [0,1]");

    if (hue != h || sat != s || bri != b) {
      if (mode == ColorPicker.HUE || mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
        float lastHue = hue;
        float lastBri = bri;
        float lastSat = sat;
        hue = h;
        sat = s;
        bri = b;
        if (mode == ColorPicker.HUE) {
          if (lastHue != hue) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.SAT) {
          if (lastSat != sat) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.BRI) {
          if (lastBri != bri) {
            regenerateImage();
          }
        }
      } else {

        Color c = new Color(Color.HSBtoRGB(h, s, b));
        setRGB(c.getRed(), c.getGreen(), c.getBlue());
        return;
      }

      Color c = new Color(Color.HSBtoRGB(hue, sat, bri));
      red = c.getRed();
      green = c.getGreen();
      blue = c.getBlue();

      regeneratePoint();
      repaint();
      fireChangeListeners();
    }
  }
Exemplo n.º 3
0
 public void addPlot(String name, int[] data) {
   plot_names.add(name);
   plot_data.add(data);
   int new_max = getMax(plot_data.size() - 1);
   if (new_max > MAX_Y) {
     MAX_Y = new_max;
   }
   if (data.length > MAX_X) {
     MAX_X = data.length;
   }
   int i = plot_data.size();
   Color c =
       new Color(
           (i * COLOR_RATIO) % 255,
           ((i + 2) * COLOR_RATIO) % 255,
           ((i + 3) * COLOR_RATIO) % 255,
           255);
   plot_colors.add(c);
   for (int j = 0; j < plot_colors.size(); j++) {
     Color color = plot_colors.get(j);
     Color new_color =
         new Color(
             color.getRed(), color.getBlue(), color.getGreen(), 127 / plot_colors.size() + 128);
     plot_colors.set(j, new_color);
   }
 }
Exemplo n.º 4
0
  @NotNull
  public static Icon colorize(@NotNull final Icon source, @NotNull Color color, boolean keepGray) {
    float[] base = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);

    final BufferedImage image =
        UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT);
    final Graphics2D g = image.createGraphics();
    source.paintIcon(null, g, 0, 0);
    g.dispose();

    final BufferedImage img =
        UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT);
    int[] rgba = new int[4];
    float[] hsb = new float[3];
    for (int y = 0; y < image.getRaster().getHeight(); y++) {
      for (int x = 0; x < image.getRaster().getWidth(); x++) {
        image.getRaster().getPixel(x, y, rgba);
        if (rgba[3] != 0) {
          Color.RGBtoHSB(rgba[0], rgba[1], rgba[2], hsb);
          int rgb = Color.HSBtoRGB(base[0], base[1] * (keepGray ? hsb[1] : 1f), base[2] * hsb[2]);
          img.getRaster()
              .setPixel(x, y, new int[] {rgb >> 16 & 0xff, rgb >> 8 & 0xff, rgb & 0xff, rgba[3]});
        }
      }
    }

    return createImageIcon(img);
  }
Exemplo n.º 5
0
 /** Patches attributes to be visible under debugger active line */
 @SuppressWarnings("UseJBColor")
 private static TextAttributes patchAttributesColor(
     TextAttributes attributes, TextRange range, Editor editor) {
   int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
   for (RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) {
     if (!highlighter.isValid()) continue;
     if (highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE
         && editor.offsetToLogicalPosition(highlighter.getStartOffset()).line == line) {
       TextAttributes textAttributes = highlighter.getTextAttributes();
       if (textAttributes != null) {
         Color color = textAttributes.getBackgroundColor();
         if (color != null
             && color.getBlue() > 128
             && color.getRed() < 128
             && color.getGreen() < 128) {
           TextAttributes clone = attributes.clone();
           clone.setForegroundColor(Color.orange);
           clone.setEffectColor(Color.orange);
           return clone;
         }
       }
     }
   }
   return attributes;
 }
Exemplo n.º 6
0
 /** Patches attributes to be visible under debugger active line */
 @SuppressWarnings("UseJBColor")
 public static TextAttributes patchAttributesColor(
     TextAttributes attributes, @NotNull TextRange range, @NotNull Editor editor) {
   if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null)
     return attributes;
   MarkupModel model =
       DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);
   if (model != null) {
     if (!((MarkupModelEx) model)
         .processRangeHighlightersOverlappingWith(
             range.getStartOffset(),
             range.getEndOffset(),
             highlighter -> {
               if (highlighter.isValid()
                   && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
                 TextAttributes textAttributes = highlighter.getTextAttributes();
                 if (textAttributes != null) {
                   Color color = textAttributes.getBackgroundColor();
                   return !(color != null
                       && color.getBlue() > 128
                       && color.getRed() < 128
                       && color.getGreen() < 128);
                 }
               }
               return true;
             })) {
       TextAttributes clone = attributes.clone();
       clone.setForegroundColor(Color.orange);
       clone.setEffectColor(Color.orange);
       return clone;
     }
   }
   return attributes;
 }
Exemplo n.º 7
0
 @Override
 public void step(Graphics g) {
   Color c;
   double factor = new Random().nextDouble() * 2;
   double factor2 = new Random().nextDouble() * 2;
   double factor3 = new Random().nextDouble() * 2;
   // blur using averaging algorithm
   for (int y = 0; y < height; y++) {
     for (int x = 0; x < width; x++) {
       c = new Color(original.getRGB(x, y));
       switch (box.getSelectedIndex()) {
         case 0:
           g.setColor(
               new Color(
                   c.getRed(),
                   c.getGreen(),
                   (int) Math.min(Math.round(c.getBlue() * factor), 255)));
           break;
         case 1:
           g.setColor(
               new Color(
                   (int) Math.min(Math.round(c.getRed() * factor), 255),
                   c.getGreen(),
                   c.getBlue()));
           break;
         case 2:
           g.setColor(
               new Color(
                   c.getRed(),
                   (int) Math.min(Math.round(c.getGreen() * factor), 255),
                   c.getBlue()));
           break;
         case 3:
           g.setColor(
               new Color(
                   (int) Math.min(Math.round(c.getRed() * factor), 255),
                   (int) Math.min(Math.round(c.getGreen() * factor2), 255),
                   (int) Math.min(Math.round(c.getBlue() * factor3), 255)));
           break;
         default:
           System.out.println("shouldn't happen");
           break;
       }
       g.drawLine(x, y, x, y);
     }
   }
 }
Exemplo n.º 8
0
 public ColorPane(Color c) {
   col = c;
   setBackground(c);
   setBorder(unselectedBorder);
   String msg = "R " + c.getRed() + ", G " + c.getGreen() + ", B " + c.getBlue();
   setToolTipText(msg);
   addMouseListener(this);
 }
Exemplo n.º 9
0
  private Color classeColor() {
    Color color = new Color(255, 255, 255);
    int dist = 50;
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();
    switch (anno) {
      case 1:
        break;
      case 2:
        r = Math.max((int) (color.getRed() - dist), 0);
        g = Math.max((int) (color.getGreen() - dist), 0);
        b = Math.max((int) (color.getBlue() - dist), 0);
        break;
      case 3:
        break;
      case 4:
        r = Math.max((int) (color.getRed() - dist), 0);
        g = Math.max((int) (color.getGreen() - dist), 0);
        b = Math.max((int) (color.getBlue() - dist), 0);
        break;
      case 5:
        r = Math.max((int) (color.getRed() - 2 * dist), 0);
        g = Math.max((int) (color.getGreen() - 2 * dist), 0);
        b = Math.max((int) (color.getBlue() - 2 * dist), 0);
        break;
      default:
        r = 255;
        g = 0;
        b = 0;
    }

    /**
     * *************** switch (indirizzo) { case 1: color = Color.ORANGE; r = color.getRed(); g =
     * Math.max((int)(color.getGreen() -(anno-1)*70), 0); b = color.getBlue(); break; case 2: color
     * = Color.BLUE; r = color.getRed(); g = Math.min((int)(color.getGreen() +(anno-1)*70), 255); b
     * = color.getBlue(); break; case 3: color = Color.GREEN; r = color.getRed(); g =
     * Math.max((int)(color.getGreen() -(anno-1)*70), 0); b = color.getBlue(); break; case 4: color
     * = Color.GRAY; r = Math.max((int)(color.getRed() -(anno-1)*40), 0); g =
     * Math.max((int)(color.getGreen() -(anno-1)*40), 0); b = Math.max((int)(color.getBlue()
     * -(anno-1)*40), 0); break; default: color = Color.BLACK; } ***************
     */
    //        System.out.println("Classe:"+nome+"Anno="+anno+"R="+r+"G="+g+"B="+b);
    return new Color(r, g, b);
  }
Exemplo n.º 10
0
 public void drawTileNumC(int tileNum, int x, int y, Color c, Graphics g) {
   BufferedImage coloredTile = tiles[tileNum];
   for (int i = 0; i < this.tW; i++) {
     for (int j = 0; j < this.tH; j++) {
       Color originalColor = new Color(coloredTile.getRGB(i, j), true);
       Color nc = new Color(c.getRed(), c.getGreen(), c.getBlue(), originalColor.getAlpha());
       coloredTile.setRGB(i, j, nc.getRGB());
     }
   }
   g.drawImage(tiles[tileNum], x, y, null);
 }
Exemplo n.º 11
0
 /**
  * Determine the color used for blurring. If the no blurColor is set (see {@link
  * JModalConfiguration#setBlurColor(Color) setBlurColor}) then the {@link
  * JBusyPanel#DEFAULT_ALPHA_TRANSPARENCY_FACTOR DEFAULT_ALPHA_TRANSPARENCY_FACTOR} is applied to
  * the supplied backgroundColor.
  *
  * @param backgroundColor Color Optional base color for blurring.
  * @return int Current blurring color.
  */
 public static Color getBlurColor(Color backgroundColor) {
   if (getBlurColor() == null) {
     return new Color(
         backgroundColor.getRed(),
         backgroundColor.getGreen(),
         backgroundColor.getBlue(),
         JBusyPanel.DEFAULT_ALPHA_TRANSPARENCY_FACTOR);
   } else {
     return getBlurColor();
   }
 }
Exemplo n.º 12
0
 public Color getColor() {
   if (myColorWheelPanel.myColorWheel.myOpacity == 255) {
     return myColor;
   } else {
     //noinspection UseJBColor
     return new Color(
         myColor.getRed(),
         myColor.getGreen(),
         myColor.getBlue(),
         myColorWheelPanel.myColorWheel.myOpacity);
   }
 }
Exemplo n.º 13
0
    /**
     * @param points
     * @param color
     * @param g
     */
    private void paintSequence(
        Slot type, List<List<ValuePointColored>> points, Color color, Graphics2D g) {
      int i = 0;
      int size = points.size();

      if (size > 0) {
        double increment = 200 / size;

        for (List<ValuePointColored> valuePoints : points) {
          int alpha = (int) (i * increment) + 55;
          Color c = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
          for (ValuePointColored valuePoint : valuePoints) {
            double[] coordinates = valuePoint.getPoint().toArray();
            int x = xToPix(coordinates[0]);
            int y = yToPix(coordinates[1]);
            // if minimum then red, else black
            if (valuePoint.getBest() == true) {
              g.setColor(Color.red);
            } else {
              g.setColor(c);
            }
            g.setStroke(LINE);

            switch (type) {
              case CIRCLE:
                g.drawOval(x - RADIUS / 2 - 3, y - RADIUS / 2 - 3, RADIUS * 2, RADIUS * 2);
                break;
              case SQUARE:
                g.drawRect(x - RADIUS / 2 - 2, y - RADIUS / 2 - 2, RADIUS * 2 - 2, RADIUS * 2 - 2);
                break;
              case TRIANGLE:
                GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3);
                polyline.moveTo(x, y - RADIUS / 2 - 4);
                polyline.lineTo(x + RADIUS / 2 + 3, y + RADIUS / 2 + 1);
                polyline.lineTo(x - RADIUS / 2 - 3, y + RADIUS / 2 + 1);
                polyline.closePath();
                g.draw(polyline);
                break;
              case CROSS:
                int xLow = x - RADIUS / 2 - 1;
                int xHigh = x + RADIUS / 2 + 1;
                int yLow = y - RADIUS / 2 - 1;
                int yHigh = y + RADIUS / 2 + 1;
                g.drawLine(xLow, yLow, xHigh, yHigh);
                g.drawLine(xHigh, yLow, xLow, yHigh);
                break;
            }
          }
          i++;
        }
      }
    }
Exemplo n.º 14
0
 /**
  * Set a fixed blurring color. If the blurColor has no alpha transparency factor (see {@link
  * JBusyPanel#DEFAULT_ALPHA_NO_TRANSPARENCY_FACTOR DEFAULT_ALPHA_NO_TRANSPARENCY_FACTOR} ) the
  * {@link JBusyPanel#DEFAULT_ALPHA_TRANSPARENCY_FACTOR DEFAULT_ALPHA_TRANSPARENCY_FACTOR} is
  * applied.
  *
  * <p>If the blurColor is NULL the {@link JBusyPanel#DEFAULT_ALPHA_TRANSPARENCY_FACTOR
  * DEFAULT_ALPHA_TRANSPARENCY_FACTOR} is applied to the window's background color in {@link
  * JBusyPanel#BLUR_STYLE_ALPHA_CHANNEL BLUR_STYLE_ALPHA_CHANNEL} mode.
  *
  * @param blurColor Color New blurring color.
  */
 public static synchronized void setBlurColor(Color blurColor) {
   if ((blurColor == null)
       || (blurColor.getAlpha() != JBusyPanel.DEFAULT_ALPHA_NO_TRANSPARENCY_FACTOR)) {
     getInstance().blurColor = blurColor;
   } else {
     getInstance().blurColor =
         new Color(
             blurColor.getRed(),
             blurColor.getGreen(),
             blurColor.getBlue(),
             JBusyPanel.DEFAULT_ALPHA_TRANSPARENCY_FACTOR);
   }
 }
Exemplo n.º 15
0
    private void setColor(Color color, Object source) {
      float[] hsb = new float[3];
      Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);
      myColor = color;
      myHue = hsb[0];
      mySaturation = hsb[1];
      myBrightness = hsb[2];
      myOpacity = color.getAlpha();

      fireColorChanged(source);

      repaint();
    }
Exemplo n.º 16
0
    @Override
    public String getToolTipText(MouseEvent event) {
      Color color = getColor(event);
      if (color != null) {
        return String.format(
            "R: %d G: %d B: %d A: %s",
            color.getRed(),
            color.getGreen(),
            color.getBlue(),
            String.format("%.2f", (float) (color.getAlpha() / 255.0)));
      }

      return super.getToolTipText(event);
    }
Exemplo n.º 17
0
    public void setColor(Color color, Object source) {
      float[] hsb = new float[3];
      Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);

      myBrightnessComponent.setValue(255 - (int) (hsb[2] * 255));
      myBrightnessComponent.repaint();

      myColorWheel.dropImage();
      if (myOpacityComponent != null && source instanceof ColorPicker) {
        myOpacityComponent.setValue(color.getAlpha());
        myOpacityComponent.repaint();
      }

      myColorWheel.setColor(color, source);
    }
Exemplo n.º 18
0
  public void paintView() {
    if (isInvalid() || visibleDrawables == null) {
      visibleDrawables = getVisibleDrawables();
    }
    // visibleDrawables set to null on clear() for a load
    int visFeatSize = (visibleDrawables == null ? 0 : visibleDrawables.size());
    if (visFeatSize == 0) return;
    int i = 0;
    for (i = 0; i < visFeatSize; i++) {
      Vector curVis = (Vector) visibleDrawables.elementAt(i);
      for (int j = 0; j < curVis.size(); j++) {
        Drawable dsf = (Drawable) curVis.elementAt(j);
        if (inHotspot) {
          FeatureProperty fp = dsf.getFeatureProperty();
          Color old = fp.getColour();

          int red, green, blue;

          if (hotspotType == EVIDENCE_HOTSPOT) {
            red = 255 - old.getRed();
            green = 255 - old.getGreen();
            blue = 255 - old.getBlue();
          } else {
            red = old.getRed() & 0x8f;
            green = old.getGreen() & 0x8f;
            blue = old.getBlue() & 0x8f;
          }
          fp.setColour(new Color(red, green, blue), true);
          dsf.draw(graphics, transformer, manager);
          fp.setColour(old, true);
        } else {
          dsf.draw(graphics, transformer, manager);
        }
      }
    }
  }
  private static String toHex(@NotNull final Color color) {
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 3; i++) {
      String s =
          Integer.toHexString(
              i == 0 ? color.getRed() : i == 1 ? color.getGreen() : color.getBlue());
      if (s.length() < 2) {
        sb.append('0');
      }

      sb.append(s);
    }

    return sb.toString();
  }
Exemplo n.º 20
0
 @SuppressWarnings("UseJBColor")
 private static Color parseColor(String value) {
   if (value != null && value.length() == 8) {
     final Color color = ColorUtil.fromHex(value.substring(0, 6));
     if (color != null) {
       try {
         int alpha = Integer.parseInt(value.substring(6, 8), 16);
         return new ColorUIResource(
             new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha));
       } catch (Exception ignore) {
       }
     }
     return null;
   }
   return ColorUtil.fromHex(value, null);
 }
Exemplo n.º 21
0
  /**
   * Method description
   *
   * @param color
   * @return
   */
  public static String getcommaSeparatedRGBString(Color color) {

    if (color != null) {

      scratchBuffer.delete(0, scratchBuffer.length()); // Clear
      int red = color.getRed();
      int green = color.getGreen();
      int blue = color.getBlue();
      scratchBuffer.append(red);
      scratchBuffer.append(",");
      scratchBuffer.append(green);
      scratchBuffer.append(",");
      scratchBuffer.append(blue);
    }
    return scratchBuffer.toString();
  }
Exemplo n.º 22
0
  /**
   * Initializes colors.
   *
   * @param prop gui properties
   */
  public static void init(final GUIProp prop) {
    final int r = prop.num(GUIProp.COLORRED);
    final int g = prop.num(GUIProp.COLORGREEN);
    final int b = prop.num(GUIProp.COLORBLUE);

    // calculate color c:
    // c = (255 - expectedColor) * 10 / factor (= GUIRED/BLUE/GREEN)
    color1 = new Color(col(r, 24), col(g, 25), col(b, 40));
    color2 = new Color(col(r, 32), col(g, 32), col(b, 44));
    color3 = new Color(col(r, 48), col(g, 50), col(b, 40));
    color4 = new Color(col(r, 140), col(g, 100), col(b, 70));
    color1A = new Color(col(r, 110), col(g, 150), col(b, 160), 100);

    colormark1A = new Color(col(r, 32), col(g, 160), col(b, 320), 100);
    colormark2A = new Color(col(r, 16), col(g, 80), col(b, 160), 100);
    colormark1 = new Color(col(r, 16), col(g, 120), col(b, 240));
    colormark2 = new Color(col(r, 16), col(g, 80), col(b, 160));
    colormark3 = new Color(col(r, 32), col(g, 160), col(b, 320));
    colormark4 = new Color(col(r, 1), col(g, 40), col(b, 80));

    // create color array
    for (int l = 1; l < COLORS.length + 1; ++l) {
      COLORS[l - 1] =
          new Color(Math.max(255 - l * r, 0), Math.max(255 - l * g, 0), Math.max(255 - l * b, 0));
    }
    final Color c = COLORS[16];
    color2A = new Color(c.getRed(), c.getGreen(), c.getBlue(), 40);
    color3A = new Color(c.getRed(), c.getGreen(), c.getBlue(), 100);

    final String f = prop.get(GUIProp.FONT);
    final int type = prop.num(GUIProp.FONTTYPE);
    fontSize = prop.num(GUIProp.FONTSIZE);
    font = new Font(f, type, fontSize);
    mfont = new Font(prop.get(GUIProp.MONOFONT), type, fontSize);
    bfont = new Font(f, Font.BOLD, fontSize);
    lfont = new Font(f, type, 18 + (fontSize >> 1));
    dmfont = new Font(prop.get(GUIProp.MONOFONT), 0, TFONT.getSize() - 1);

    final Container comp = new Container();
    dwidth = comp.getFontMetrics(dmfont).getWidths();
    fwidth = comp.getFontMetrics(font).getWidths();
    lwidth = comp.getFontMetrics(lfont).getWidths();
    mfwidth = comp.getFontMetrics(mfont).getWidths();
    bwidth = comp.getFontMetrics(bfont).getWidths();
  }
Exemplo n.º 23
0
    public void saveColors() {
      final List<String> values = new ArrayList<>();
      for (Color recentColor : myRecentColors) {
        if (recentColor == null) break;
        values.add(
            String.format(
                "%d-%d-%d-%d",
                recentColor.getRed(),
                recentColor.getGreen(),
                recentColor.getBlue(),
                recentColor.getAlpha()));
      }

      PropertiesComponent.getInstance()
          .setValue(
              COLOR_CHOOSER_COLORS_KEY,
              values.isEmpty() ? null : StringUtil.join(values, ",,,"),
              null);
    }
  /** {@collect.stats} Sets the values of the controls to reflect the color */
  private void setColor(Color newColor) {
    int red = newColor.getRed();
    int blue = newColor.getBlue();
    int green = newColor.getGreen();

    if (redSlider.getValue() != red) {
      redSlider.setValue(red);
    }
    if (greenSlider.getValue() != green) {
      greenSlider.setValue(green);
    }
    if (blueSlider.getValue() != blue) {
      blueSlider.setValue(blue);
    }

    if (((Integer) redField.getValue()).intValue() != red) redField.setValue(new Integer(red));
    if (((Integer) greenField.getValue()).intValue() != green)
      greenField.setValue(new Integer(green));
    if (((Integer) blueField.getValue()).intValue() != blue) blueField.setValue(new Integer(blue));
  }
Exemplo n.º 25
0
 /**
  * Method used to highlight or low-light a space on the board. This is used to indicate which
  * space was clicked on, or which spaces a piece can move to
  *
  * @param space Space on the board to be modified
  * @param highlight If true, brighten space, else, darken space
  */
 public void light(JButton space, boolean highlight) {
   // set the space to be clickable
   space.setEnabled(true);
   Color color = space.getBackground();
   int red = color.getRed();
   int green = color.getGreen();
   int blue = color.getBlue();
   int[] components = {red, green, blue};
   for (int i = 0; i < 3; i++) {
     // modify the rgb values
     if (highlight) {
       components[i] += HIGHLIGHT_FACTOR;
     } else {
       components[i] -= LOWLIGHT_FACTOR;
     }
     if (components[i] > 255) {
       components[i] = 255;
     } else if (components[i] < 0) {
       components[i] = 0;
     }
   }
   space.setBackground(new Color(components[0], components[1], components[2]));
 }
Exemplo n.º 26
0
 @Nullable
 public Component getTableCellEditorComponent(
     JTable table, Object value, boolean isSelected, int row, int column) {
   myValue = ((MyTableModel) table.getModel()).getRegistryValue(row);
   if (myValue.asColor(null) != null) {
     final Color color =
         ColorChooser.chooseColor(
             table, "Choose color", ((RegistryValue) value).asColor(Color.WHITE));
     if (color != null) {
       myValue.setValue(color.getRed() + "," + color.getGreen() + "," + color.getBlue());
     }
     return null;
   } else if (myValue.isBoolean()) {
     myCheckBox.setSelected(myValue.asBoolean());
     myCheckBox.setBackground(table.getBackground());
     return myCheckBox;
   } else {
     myField.setText(myValue.asString());
     myField.setBorder(null);
     myField.selectAll();
     return myField;
   }
 }
 /** Methode appelee quand l'utilisateur appuie sur le bouton. */
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == button) {
     Color choosedColor =
         JColorChooser.showDialog(parent.dialog(), "Choose color", new Color(R, G, B));
     if (choosedColor != null) {
       this.R = choosedColor.getRed();
       this.G = choosedColor.getGreen();
       this.B = choosedColor.getBlue();
       parent.elementModified();
     }
     String tmp =
         new String(
             label
                 + Integer.toString(getRed())
                 + ", "
                 + Integer.toString(getGreen())
                 + ", "
                 + Integer.toString(getBlue()));
     while (tmp.length() < 38) {
       tmp = tmp + " ";
     }
     jlabel.setText(tmp);
   }
 }
Exemplo n.º 28
0
 static Color getColorAlfa(Color col, int alfa) {
   return new Color(col.getRed(), col.getGreen(), col.getBlue(), alfa);
 }
Exemplo n.º 29
0
 static Color getColorMedio(Color a, Color b) {
   return new Color(
       propInt(a.getRed(), b.getRed(), 2),
       propInt(a.getGreen(), b.getGreen(), 2),
       propInt(a.getBlue(), b.getBlue(), 2));
 }
Exemplo n.º 30
0
 static ColorUIResource getColorTercio(Color a, Color b) {
   return new ColorUIResource(
       propInt(a.getRed(), b.getRed(), 3),
       propInt(a.getGreen(), b.getGreen(), 3),
       propInt(a.getBlue(), b.getBlue(), 3));
 }