Example #1
0
  public void paintComponent(Graphics g) {
    final Color bg = getBackground();
    final Insets insets = getInsets();

    if (shouldPaintBg) {
      super.paintComponent(g);

      if ((bg != null) && (bg.getAlpha() > 0)) {
        g.setColor(bg);
        g.fillRect(
            insets.left,
            insets.top,
            getWidth() - (insets.left + insets.right),
            getHeight() - (insets.top + insets.bottom));
      }
      if (!clear) {
        shouldPaintBg = false;
        setOpaque(true);
      }
    }
    if (pen != null) {
      if (pen.getAbsCoords()) {
        pen.paintIcon(this, g, 0, 0);
      } else {
        pen.paintIcon(this, g, insets.left, insets.top);
      }
    }
  }
  private BufferedImage aplicaFiltroMatrizConvolucion(
      double[][] filter, double factor, double bias, BufferedImage img) {

    imgTmp = new BufferedImage(img.getWidth(), img.getHeight(), img.getType());
    for (int x = 0; x < img.getWidth(); x++) {
      for (int y = 0; y < img.getHeight(); y++) {
        int r = 0, g = 0, b = 0;

        for (int filterX = 0; filterX < filter.length; filterX++)
          for (int filterY = 0; filterY < filter.length; filterY++) {
            int imageX = (x - filter.length / 2 + filterX + img.getWidth()) % img.getWidth();
            int imageY = (y - filter.length / 2 + filterY + img.getHeight()) % img.getHeight();
            Color c = new Color(img.getRGB(imageX, imageY));
            r += c.getRed() * filter[filterX][filterY];
            g += c.getGreen() * filter[filterX][filterY];
            b += c.getBlue() * filter[filterX][filterY];
          }
        imgTmp.setRGB(
            x,
            y,
            new Color(
                    Math.min(Math.max((int) (factor * r + bias), 0), 255),
                    Math.min(Math.max((int) (factor * g + bias), 0), 255),
                    Math.min(Math.max((int) (factor * b + bias), 0), 255))
                .getRGB());
      }
    }
    return imgTmp;
  }
Example #3
0
  /** @param args */
  public static void main(String[] args) {
    JFileChooser chooser = new JFileChooser();
    chooser.showOpenDialog(null);
    File file = chooser.getSelectedFile();
    String indir = file.getAbsolutePath();
    BufferedImage out = null;
    try (BufferedReader br = new BufferedReader(new FileReader(file))) {
      out = new BufferedImage(256, 1, BufferedImage.TYPE_INT_RGB);
      String sCurrentLine;
      int pos = 0;
      while ((sCurrentLine = br.readLine()) != null) {
        String[] values = sCurrentLine.split(" ");
        Color ocol =
            new Color(
                Integer.valueOf(values[0]), Integer.valueOf(values[1]), Integer.valueOf(values[2]));
        out.setRGB(pos, 0, ocol.getRGB());
        pos++;
      }
      File outputimage = new File("C:\\ydkj\\palette", "GENPALETTE.bmp");
      ImageIO.write(out, "bmp", outputimage);

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #4
0
  /**
   * Creates a new color mixer filter. The specified color will be used to tint the source image,
   * with a mixing strength defined by <code>mixValue</code>.
   *
   * @param mixColor the solid color to mix with the source image
   * @param mixValue the strength of the mix, between 0.0 and 1.0; if the specified value lies
   *     outside this range, it is clamped
   * @throws IllegalArgumentException if <code>mixColor</code> is null
   */
  public ColorTintFilter(Color mixColor, float mixValue) {
    if (mixColor == null) {
      throw new IllegalArgumentException("mixColor cannot be null");
    }

    this.mixColor = mixColor;
    if (mixValue < 0.0f) {
      mixValue = 0.0f;
    } else if (mixValue > 1.0f) {
      mixValue = 1.0f;
    }
    this.mixValue = mixValue;

    int mix_r = (int) (mixColor.getRed() * mixValue);
    int mix_g = (int) (mixColor.getGreen() * mixValue);
    int mix_b = (int) (mixColor.getBlue() * mixValue);

    // Since we use only lookup tables to apply the filter, this filter
    // could be implemented as a LookupOp.
    float factor = 1.0f - mixValue;
    preMultipliedRed = new int[256];
    preMultipliedGreen = new int[256];
    preMultipliedBlue = new int[256];

    for (int i = 0; i < 256; i++) {
      int value = (int) (i * factor);
      preMultipliedRed[i] = value + mix_r;
      preMultipliedGreen[i] = value + mix_g;
      preMultipliedBlue[i] = value + mix_b;
    }
  }
 @Override
 public void marshal(
     Object o, HierarchicalStreamWriter writer, MarshallingContext marshallingContext) {
   Color color = (Color) o;
   writer.setValue(String.valueOf(color.getRGB()));
   writer.endNode();
 }
  @Override
  public Component getVisualizationComponent(Object renderable, IOContainer ioContainer) {
    TTestSignificanceTestResult result = (TTestSignificanceTestResult) renderable;

    PerformanceVector[] allVectors = result.getAllVectors();
    StringBuffer buffer = new StringBuffer();
    Color bgColor = SwingTools.LIGHTEST_YELLOW;
    String bgColorString =
        Integer.toHexString(bgColor.getRed())
            + Integer.toHexString(bgColor.getGreen())
            + Integer.toHexString(bgColor.getBlue());

    buffer.append("<table bgcolor=\"" + bgColorString + "\" border=\"1\">");
    buffer.append("<tr><td></td>");
    for (int i = 0; i < result.getAllVectors().length; i++) {
      buffer.append(
          "<td>"
              + Tools.formatNumber(allVectors[i].getMainCriterion().getAverage())
              + " +/- "
              + Tools.formatNumber(Math.sqrt(allVectors[i].getMainCriterion().getVariance()))
              + "</td>");
    }
    buffer.append("</tr>");
    for (int i = 0; i < allVectors.length; i++) {
      buffer.append(
          "<tr><td>"
              + Tools.formatNumber(allVectors[i].getMainCriterion().getAverage())
              + " +/- "
              + Tools.formatNumber(Math.sqrt(allVectors[i].getMainCriterion().getVariance()))
              + "</td>");
      for (int j = 0; j < allVectors.length; j++) {
        buffer.append("<td>");
        if (!Double.isNaN(result.getProbMatrix()[i][j])) {
          double prob = result.getProbMatrix()[i][j];
          if (prob < result.getAlpha()) {
            buffer.append("<b>");
          }
          buffer.append(Tools.formatNumber(prob));
          if (prob < result.getAlpha()) {
            buffer.append("</b>");
          }
        }
        buffer.append("</td>");
      }
      buffer.append("</tr>");
    }
    buffer.append("</table>");
    buffer.append(
        "<br>Probabilities for random values with the same result.<br>Bold values are smaller than alpha="
            + Tools.formatNumber(result.getAlpha())
            + " which indicates a probably significant difference between the actual mean values!");

    JEditorPane textPane =
        new ExtendedHTMLJEditorPane(
            "text/html", "<html><h1>" + getName() + "</h1>" + buffer.toString() + "</html>");
    textPane.setBackground((new JLabel()).getBackground());
    textPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(11, 11, 11, 11));
    textPane.setEditable(false);
    return new ExtendedJScrollPane(textPane);
  }
Example #7
0
  public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    // choose which colors we want to use
    Color bg = c.getBackground();

    if (c.getParent() != null) {
      bg = c.getParent().getBackground();
    }

    if (bg != null) {
      Color mid = bg.darker();
      Color edge = average(mid, bg);

      g.setColor(bg);
      g.drawLine(0, h - 2, w, h - 2);
      g.drawLine(0, h - 1, w, h - 1);
      g.drawLine(w - 2, 0, w - 2, h);
      g.drawLine(w - 1, 0, w - 1, h);

      // draw the drop-shadow
      g.setColor(mid);
      g.drawLine(1, h - 2, w - 2, h - 2);
      g.drawLine(w - 2, 1, w - 2, h - 2);

      g.setColor(edge);
      g.drawLine(2, h - 1, w - 2, h - 1);
      g.drawLine(w - 1, 2, w - 1, h - 2);
    }
  }
  /** Redraws the image. */
  private void redrawImage() {
    ScreenToWorldPointConverter converter = null;
    try {
      converter =
          new ScreenToWorldPointConverter(
              currWXMin, currWYMin, currWXMax, currWYMax, 0, 0, width - 1, height - 1);
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }

    Point2D P = null;
    Point2D.Double screenPoint = new Point2D.Double();
    ComplexNumber C = null;
    Color theColor = null;
    int colorIndex = 0;
    for (int i = 0; i < width; ++i) {
      for (int j = 0; j < height; ++j) {
        screenPoint.setLocation(i, j);
        P = converter.getWorldCoordinates(screenPoint);
        C = new ComplexNumber(new RealNumber(P.getX()), new RealNumber(P.getY()));
        colorIndex = Mandelbrot.divergenceIndex(C);
        if (colorIndex < 0) {
          theColor = Color.black;
        } else {
          theColor = Mandelbrot.getColor(colorIndex);
        }
        img.paintPixel(i, j, theColor.getRGB());
      }
    }
  }
  public int getAlpha(double level) {
    if (colors != null) {
      if (level >= 0 && level < colors.length) return colors[(int) level].getAlpha();
    }

    // else...

    final double minLevel = this.minLevel;
    final double maxLevel = this.maxLevel;
    // these next two also handle the possibility that maxLevel = minLevel
    if (level >= maxLevel) return maxColor.getAlpha();
    else if (level <= minLevel) return minColor.getAlpha();
    else {
      // now convert to between 0 and 1
      double interval = maxLevel - minLevel;
      // finally call the convert() function, then set back to between
      // minLevel and maxLevel
      level = filterLevel((level - minLevel) / interval) * interval + minLevel;
    }

    final double interpolation = (level - minLevel) / (maxLevel - minLevel);

    // TODO all messed up
    final int maxAlpha = alphas[alphas.length - 1]; // this.maxAlpha;
    final int minAlpha = alphas[0]; // this.minAlpha;
    return (maxAlpha == minAlpha
        ? minAlpha
        : (int) (interpolation * (maxAlpha - minAlpha) + minAlpha));
  }
Example #10
0
  @Override
  public void writeExternal(Element element) throws WriteExternalException {
    List<HighlightSeverity> list = getOrderAsList(getOrderMap());
    for (HighlightSeverity severity : list) {
      Element info = new Element(INFO_TAG);
      String severityName = severity.getName();
      final SeverityBasedTextAttributes infoType = getAttributesBySeverity(severity);
      if (infoType != null) {
        infoType.writeExternal(info);
        final Color color = myRendererColors.get(severityName);
        if (color != null) {
          info.setAttribute(COLOR_ATTRIBUTE, Integer.toString(color.getRGB() & 0xFFFFFF, 16));
        }
        element.addContent(info);
      }
    }

    if (myReadOrder != null && !myReadOrder.isEmpty()) {
      myReadOrder.writeExternal(element);
    } else if (!getDefaultOrder().equals(list)) {
      final JDOMExternalizableStringList ext =
          new JDOMExternalizableStringList(Collections.nCopies(getOrderMap().size(), ""));
      getOrderMap()
          .forEachEntry(
              new TObjectIntProcedure<HighlightSeverity>() {
                @Override
                public boolean execute(HighlightSeverity orderSeverity, int oIdx) {
                  ext.set(oIdx, orderSeverity.getName());
                  return true;
                }
              });
      ext.writeExternal(element);
    }
  }
Example #11
0
  @Override
  public void mouseClicked(java.awt.event.MouseEvent e) {
    Point cellLocation = this.mGrid.getCells()[0][0].getLocation();
    int mouseX = e.getX() - (int) cellLocation.getX();
    int mouseY = e.getY() - (int) cellLocation.getY();

    this.mGrid.getCells()[mouseX / 12][mouseY / 12].setState(this.mCellTemp.getState());
    if (this.mGrid.getCells()[mouseX / 12][mouseY / 12].getState() == 0) {
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].setBackground(Color.white);
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].repaint();
    } else if (this.mGrid.getCells()[mouseX / 12][mouseY / 12].getState() == 1) {
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].setBackground(Color.decode("#92d050"));
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].repaint();
    } else if (this.mGrid.getCells()[mouseX / 12][mouseY / 12].getState() == 2) {
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].setBackground(Color.decode("#339933"));
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].repaint();
    } else if (this.mGrid.getCells()[mouseX / 12][mouseY / 12].getState() == 4) {
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].setBackground(Color.decode("#004800"));
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].repaint();
    } else if (this.mGrid.getCells()[mouseX / 12][mouseY / 12].getState() == 5) {
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].setBackground(Color.decode("#ff0000"));
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].repaint();
    } else if (this.mGrid.getCells()[mouseX / 12][mouseY / 12].getState() == 7) {
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].setBackground(Color.decode("#7030a0"));
      this.mGrid.getCells()[mouseX / 12][mouseY / 12].repaint();
    }
  }
 private static String toRGBFunctionCall(Color color) {
   StringBuffer sbuf = new StringBuffer();
   sbuf.append('#');
   String s = Integer.toHexString(color.getRed());
   if (s.length() == 1) {
     sbuf.append('0');
   }
   sbuf.append(s);
   s = Integer.toHexString(color.getGreen());
   if (s.length() == 1) {
     sbuf.append('0');
   }
   sbuf.append(s);
   s = Integer.toHexString(color.getBlue());
   if (s.length() == 1) {
     sbuf.append('0');
   }
   sbuf.append(s);
   if (color.getAlpha() != 255) {
     s = Integer.toHexString(color.getAlpha());
     if (s.length() == 1) {
       sbuf.append('0');
     }
     sbuf.append(s);
   }
   return sbuf.toString();
 }
 /**
  * Parse a color given with the cmyk() function.
  *
  * @param value the complete line
  * @return a color if possible
  * @throws PropertyException if the format is wrong.
  */
 private static Color parseAsCMYK(String value) throws PropertyException {
   Color parsedColor;
   int poss = value.indexOf("(");
   int pose = value.indexOf(")");
   if (poss != -1 && pose != -1) {
     value = value.substring(poss + 1, pose);
     String[] args = value.split(",");
     try {
       if (args.length != 4) {
         throw new PropertyException("Invalid number of arguments: cmyk(" + value + ")");
       }
       float cyan = parseComponent1(args[0], value);
       float magenta = parseComponent1(args[1], value);
       float yellow = parseComponent1(args[2], value);
       float black = parseComponent1(args[3], value);
       float[] comps = new float[] {cyan, magenta, yellow, black};
       Color cmykColor = DeviceCMYKColorSpace.createCMYKColor(comps);
       float[] rgbComps = cmykColor.getRGBColorComponents(null);
       parsedColor =
           new ColorWithAlternatives(
               rgbComps[0], rgbComps[1], rgbComps[2], new Color[] {cmykColor});
     } catch (RuntimeException re) {
       throw new PropertyException(re);
     }
   } else {
     throw new PropertyException("Unknown color format: " + value + ". Must be cmyk(c,m,y,k)");
   }
   return parsedColor;
 }
Example #14
0
 protected ColorRGBA makeColorRGBA(Color color) {
   return new ColorRGBA(
       color.getRed() / 255f,
       color.getGreen() / 255f,
       color.getBlue() / 255f,
       color.getAlpha() / 255f);
 }
Example #15
0
    private void drawSquare(Graphics g, int x, int y, Tetrominoes shape) {

      int squareWidth = (int) getSize().getWidth() / model.getWidth();
      int squareHeight = (int) getSize().getHeight() / model.getHeight();

      Color colors[] = {
        new Color(0, 0, 0),
        new Color(204, 102, 102),
        new Color(102, 204, 102),
        new Color(102, 102, 204),
        new Color(204, 204, 102),
        new Color(204, 102, 204),
        new Color(102, 204, 204),
        new Color(218, 170, 0)
      };

      Color color = colors[shape.ordinal()];
      g.setColor(color);
      g.fillRect(x + 1, y + 1, squareWidth - 2, squareHeight - 2);
      g.setColor(color.brighter());
      g.drawLine(x, y + squareHeight - 1, x, y);
      g.drawLine(x, y, x + squareWidth - 1, y);

      g.setColor(color.darker());
      g.drawLine(x + 1, y + squareHeight - 1, x + squareWidth - 1, y + squareHeight - 1);
      g.drawLine(x + squareWidth - 1, y + squareHeight - 1, x + squareWidth - 1, y + 1);
    }
  public int getRGB(double level) {

    double minLevel = this.minLevel;
    double maxLevel = this.maxLevel;
    // these next two also handle the possibility that maxLevel = minLevel
    if (level >= maxLevel) return maxColor.getRGB();
    else if (level <= minLevel) return minColor.getRGB();

    int interval = 0;
    for (int i = 1; i < levels.length; i++) { // start at 1, for level <
      // first interval it should
      // be < minLevel
      if (level <= levels[i]) {
        interval = i;
        i = levels.length; // force the for loop to halt
      }
    }
    // reevaluate min,maxLevel for this particular interval
    minLevel = levels[interval - 1];
    maxLevel = levels[interval];
    final double interpolation = (level - minLevel) / (maxLevel - minLevel);

    final int alpha =
        (int) (interpolation * (alphas[interval] - alphas[interval - 1]) + alphas[interval - 1]);

    // TODO: not right!
    final int red =
        (int) (interpolation * (reds[interval] - reds[interval - 1]) + reds[interval - 1]);
    final int green =
        (int) (interpolation * (greens[interval] - greens[interval - 1]) + greens[interval - 1]);
    final int blue =
        (int) (interpolation * (blues[interval] - blues[interval - 1]) + blues[interval - 1]);

    return (alpha << 24) | (red << 16) | (green << 8) | blue;
  }
 @Override
 public boolean equals(Object obj) {
   boolean rtrn = false;
   if (obj != null && super.equals(obj)) {
     if (obj instanceof EmbedTypeWeatherInfo) {
       EmbedTypeWeatherInfo etwi = (EmbedTypeWeatherInfo) obj;
       rtrn = location != null && location.equals(etwi.location);
       rtrn = rtrn && latitude == etwi.latitude;
       rtrn = rtrn && longitude == etwi.longitude;
       rtrn = rtrn && locationIncluded == etwi.locationIncluded;
       rtrn = rtrn && iconIncluded == etwi.iconIncluded;
       rtrn = rtrn && descriptionIncluded == etwi.descriptionIncluded;
       rtrn = rtrn && temperatureIncluded == etwi.temperatureIncluded;
       rtrn = rtrn && isFahrennheit == etwi.isFahrennheit;
       rtrn = rtrn && humidityIncluded == etwi.humidityIncluded;
       rtrn = rtrn && windSpeedIncluded == etwi.windSpeedIncluded;
       rtrn = rtrn && forecastIncluded == etwi.forecastIncluded;
       rtrn = rtrn && isRectangular == etwi.isRectangular;
       rtrn =
           rtrn && (textColor == null && etwi.textColor == null)
               || textColor.equals(etwi.textColor);
       rtrn =
           rtrn && (textColor == null && etwi.textColor == null)
               || backgroundColor.equals(etwi.backgroundColor);
       rtrn = rtrn && address != null && address.equals(etwi.address);
       rtrn =
           rtrn && (geocodeResult == null && etwi.geocodeResult == null)
               || (geocodeResult.equals(etwi.geocodeResult));
     }
   }
   return rtrn;
 }
Example #18
0
    public void composeRGB(int[] src, int[] dst, float alpha) {
      int w = src.length;

      for (int i = 0; i < w; i += 4) {
        int sr = src[i];
        int dir = dst[i];
        int sg = src[i + 1];
        int dig = dst[i + 1];
        int sb = src[i + 2];
        int dib = dst[i + 2];
        int sa = src[i + 3];
        int dia = dst[i + 3];
        int dor, dog, dob;

        Color.RGBtoHSB(sr, sg, sb, sHSB);
        Color.RGBtoHSB(dir, dig, dib, dHSB);

        dHSB[0] = sHSB[0];

        int doRGB = Color.HSBtoRGB(dHSB[0], dHSB[1], dHSB[2]);
        dor = (doRGB & 0xff0000) >> 16;
        dog = (doRGB & 0xff00) >> 8;
        dob = (doRGB & 0xff);

        float a = alpha * sa / 255f;
        float ac = 1 - a;

        dst[i] = (int) (a * dor + ac * dir);
        dst[i + 1] = (int) (a * dog + ac * dig);
        dst[i + 2] = (int) (a * dob + ac * dib);
        dst[i + 3] = (int) (sa * alpha + dia * ac);
      }
    }
Example #19
0
  @Override
  public boolean apply(NodeRenderingProperty p) {
    if (!isColorEnabled) {
      p.targetFillColor = NodeColors.getDefaultColor();
      return true;
    }
    @SuppressWarnings("unchecked")
    NodeColorData vals = (NodeColorData) p.pluginStore.get(this);

    Color color = guessColor(p);

    if (p.isSelected()) {
      p.targetStrokeColor = Color.red;
      p.targetFillColor = color.darker().darker();
      return true;
    }
    if (seedColoring && vals.degree == 0) {
      p.targetStrokeColor = Color.green;
      p.targetFillColor = Color.green; // c.brighter().brighter();
      return true;
    }
    p.targetFillColor = color;
    p.targetStrokeColor = Color.blue;
    return true;
  }
Example #20
0
  private static Component createDescription(Example example, ExampleGroup group) {
    Color foreground = group.getPreferredForeground();

    WebLabel titleLabel = new WebLabel(example.getTitle(), JLabel.TRAILING);
    titleLabel.setDrawShade(true);
    titleLabel.setForeground(foreground);
    if (foreground.equals(Color.WHITE)) {
      titleLabel.setShadeColor(Color.BLACK);
    }

    if (example.getDescription() == null) {
      return titleLabel;
    } else {
      WebLabel descriptionLabel = new WebLabel(example.getDescription(), WebLabel.TRAILING);
      descriptionLabel.setForeground(Color.GRAY);
      SwingUtils.changeFontSize(descriptionLabel, -1);

      WebPanel vertical =
          new WebPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, 0, true, false));
      vertical.setOpaque(false);
      vertical.add(titleLabel);
      vertical.add(descriptionLabel);

      return vertical;
    }
  }
Example #21
0
  private static JFreeChart createChart(XYDataset dataset, String exp) {
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "", "", "", dataset, PlotOrientation.VERTICAL, false, false, false);
    chart.setBorderVisible(false);
    chart.setAntiAlias(true);
    chart.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0, (float) 0.96));
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);

    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.WHITE); // 网格线颜色
    plot.setNoDataMessage("No data!");
    plot.setOutlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);

    plot.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0.01, (float) 0.91));

    // xylineandshaperenderer.setShapesFilled(true);
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRange(true);
    axis.setPositiveArrowVisible(true);
    axis.setAutoRangeIncludesZero(true);
    axis.setAutoRangeStickyZero(true);

    // List axisIndices = Arrays.asList(new Integer[] {new Integer(0),
    //        new Integer(1)});
    // plot.mapDatasetToDomainAxes(0, axisIndices);
    // plot.mapDatasetToRangeAxes(0, axisIndices);
    // ChartUtilities.applyCurrentTheme(chart);
    return chart;
  }
Example #22
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;
 }
 @Override
 public void onOvalButtonPressed(Color c) {
   System.out.println("button pressed" + c);
   System.out.println(jTextField1.getForeground());
   if (jTextField1.getForeground().getRed() == c.getRed()
       && jTextField1.getForeground().getGreen() == c.getGreen()
       && jTextField1.getForeground().getBlue() == c.getBlue()) {
     newScore += 100;
     System.out.println("score:" + newScore);
     generateButtons();
     revalidate();
     repaint();
   } else {
     newScore -= 100;
     System.out.println("score:" + newScore);
     generateButtons();
     revalidate();
     repaint();
   }
   numOfGames++;
   System.out.println(numOfGames);
   if (numOfGames == 5) {
     colorListener.onColorGameFinished(newScore);
     numOfGames = 0;
     return;
   }
 }
Example #24
0
 @Override
 public String toString() {
   return "#"
       + String.format("%02X", color.getRed())
       + String.format("%02X", color.getGreen())
       + String.format("%02X", color.getBlue());
 }
 /**
  * We store the alpha value separately because of the color pallet. We may want to apply different
  * alpha values to different shapes but use the same color. But, when it comes time to render our
  * shapes, we need the alpha value, so this method creates a color that combines the
  * colorWithoutAlpha argument with this shape's alpha value. That constructed Color object is then
  * returned.
  *
  * @param colorWithoutAlpha The color to process. It does not have an alpha value.
  * @return A Color object with the same rgb values as the colorWithAlpha argument and an added
  *     alpha value from this class's instance variable.
  */
 private Color getColorWithAlpha(Color colorWithoutAlpha) {
   return new Color(
       colorWithoutAlpha.getRed(),
       colorWithoutAlpha.getGreen(),
       colorWithoutAlpha.getBlue(),
       alpha);
 }
Example #26
0
 public static final Color contrastBW(Color c) {
   if ((c.getRed() + c.getGreen() + c.getBlue()) > 200.0) {
     return (Color.black);
   } else {
     return (Color.white);
   }
 }
 protected String paramString() {
   String str;
   if (linkBehavior == ALWAYS_UNDERLINE) str = "ALWAYS_UNDERLINE";
   else if (linkBehavior == HOVER_UNDERLINE) str = "HOVER_UNDERLINE";
   else if (linkBehavior == NEVER_UNDERLINE) str = "NEVER_UNDERLINE";
   else str = "SYSTEM_DEFAULT";
   String colorStr = linkColor == null ? "" : linkColor.toString();
   String colorPressStr = colorPressed == null ? "" : colorPressed.toString();
   String disabledLinkColorStr = disabledLinkColor == null ? "" : disabledLinkColor.toString();
   String visitedLinkColorStr = visitedLinkColor == null ? "" : visitedLinkColor.toString();
   String buttonURLStr = buttonURL == null ? "" : buttonURL.toString();
   String isLinkVisitedStr = isLinkVisited ? "true" : "false";
   return super.paramString()
       + ",linkBehavior="
       + str
       + ",linkURL="
       + buttonURLStr
       + ",linkColor="
       + colorStr
       + ",activeLinkColor="
       + colorPressStr
       + ",disabledLinkColor="
       + disabledLinkColorStr
       + ",visitedLinkColor="
       + visitedLinkColorStr
       + ",linkvisitedString="
       + isLinkVisitedStr;
 }
Example #28
0
  /**
   * Returns a hex string for the specified color, suitable for HTML.
   *
   * @param c The color.
   * @return The string representation, in the form "<code>#rrggbb</code>", or <code>null</code> if
   *     <code>c</code> is <code>null</code>.
   */
  private static String getHexString(Color c) {

    if (c == null) {
      return null;
    }

    StringBuilder sb = new StringBuilder("#");
    int r = c.getRed();
    if (r < 16) {
      sb.append('0');
    }
    sb.append(Integer.toHexString(r));
    int g = c.getGreen();
    if (g < 16) {
      sb.append('0');
    }
    sb.append(Integer.toHexString(g));
    int b = c.getBlue();
    if (b < 16) {
      sb.append('0');
    }
    sb.append(Integer.toHexString(b));

    return sb.toString();
  }
Example #29
0
 private void glcolor() {
   gl.glColor4f(
       (float) color.getRed() / 255.0f,
       (float) color.getGreen() / 255.0f,
       (float) color.getBlue() / 255.0f,
       (float) color.getAlpha() / 255.0f);
 }
  @SubscribeEvent(priority = EventPriority.LOWEST)
  public static void onSoundEvent(PlaySoundEvent evt) {
    ISound sound = evt.getResultSound();

    if (sound != null && shouldSilence(sound)) {
      if (sound instanceof ITickableSound) {
        evt.setResultSound(new WrappedTickableSound((ITickableSound) sound, MULTIPLIER));
      } else {
        SubTileBergamute berg =
            SubTileBergamute.getBergamuteNearby(
                sound.getXPosF(), sound.getYPosF(), sound.getZPosF());

        if (berg != null) {
          evt.setResultSound(new WrappedSound(sound, MULTIPLIER));

          if (RAND.nextBoolean()) {
            Color color = TilePool.PARTICLE_COLOR;
            BotaniaAPI.internalHandler.sparkleFX(
                berg.getWorld(),
                berg.getPos().getX() + 0.3 + Math.random() * 0.5,
                berg.getPos().getY() + 0.5 + Math.random() * 0.5,
                berg.getPos().getZ() + 0.3 + Math.random() * 0.5,
                color.getRed() / 255F,
                color.getGreen() / 255F,
                color.getBlue() / 255F,
                (float) Math.random(),
                5);
          }
        }
      }
    }
  }