コード例 #1
0
ファイル: VisualBellViewport.java プロジェクト: zieglerm/enh
 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();
   }
 }
コード例 #2
0
ファイル: ColorPickerPanel.java プロジェクト: ryokbys/Akira
  /**
   * 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();
    }
  }
コード例 #3
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;
 }
コード例 #4
0
ファイル: Subtree.java プロジェクト: siwells/monkeypuzzle
 /**
  * Sets the fillColor and defines the outline color to be a non-transparent version of the fill
  * color
  */
 public void setColor(Color fillColor) {
   m_fillColor = fillColor;
   m_outlineColor =
       new Color(
           fillColor.getRed() < 255 ? 0.0f : 1.0f,
           fillColor.getGreen() < 255 ? 0.0f : 1.0f,
           fillColor.getBlue() < 255 ? 0.0f : 1.0f);
 }
コード例 #5
0
 public Star(Point loc, Color c, int alpha) {
   location = loc;
   r = c.getRed();
   b = c.getBlue();
   g = c.getGreen();
   a = alpha;
   pulseRate = rand.nextInt(155);
 }
コード例 #6
0
ファイル: JREImage.java プロジェクト: kazuyakuza/wh40kh
 /**
  * Turn a (possibly) translucent or indexed image into a display-compatible bitmask image using
  * the given alpha threshold and render-to-background colour, or display-compatible translucent
  * image. The alpha values in the image are set to either 0 (below threshold) or 255 (above
  * threshold). The render-to-background colour bg_col is used to determine how the pixels
  * overlapping transparent pixels should be rendered. The fast algorithm just sets the colour
  * behind the transparent pixels in the image (for bitmask source images); the slow algorithm
  * actually renders the image to a background of bg_col (for translucent sources).
  *
  * @param thresh alpha threshold between 0 and 255
  * @param fast use fast algorithm (only set bg_col behind transp. pixels)
  * @param bitmask true=use bitmask, false=use translucent
  */
 public JGImage toDisplayCompatible(int thresh, JGColor bg_col, boolean fast, boolean bitmask) {
   Color bgcol = new Color(bg_col.r, bg_col.g, bg_col.b);
   int bgcol_rgb = (bgcol.getRed() << 16) | (bgcol.getGreen() << 8) | bgcol.getBlue();
   JGPoint size = getSize();
   int[] buffer = getPixels();
   // render image to bg depending on bgcol
   BufferedImage img_bg;
   if (bitmask) {
     img_bg = createCompatibleImage(size.x, size.y, Transparency.BITMASK);
   } else {
     img_bg = createCompatibleImage(size.x, size.y, Transparency.TRANSLUCENT);
   }
   int[] bg_buf;
   if (!fast) {
     Graphics g = img_bg.getGraphics();
     g.setColor(bgcol);
     // the docs say I could use bgcol in the drawImage as an
     // equivalent to the following two lines, but this
     // doesn't handle translucency properly and is _slower_
     g.fillRect(0, 0, size.x, size.y);
     g.drawImage(img, 0, 0, null);
     bg_buf = new JREImage(img_bg).getPixels();
   } else {
     bg_buf = buffer;
   }
   // g.dispose();
   // ColorModel rgb_bitmask = ColorModel.getRGBdefault();
   // rgb_bitmask = new PackedColorModel(
   //		rgb_bitmask.getColorSpace(),25,0xff0000,0x00ff00,0x0000ff,
   //		0x1000000, false, Transparency.BITMASK, DataBuffer.TYPE_INT);
   //		ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean
   // isAlphaPremultiplied, int trans, int transferType)
   int[] thrsbuf = new int[size.x * size.y];
   for (int y = 0; y < size.y; y++) {
     for (int x = 0; x < size.x; x++) {
       if (((buffer[y * size.x + x] >> 24) & 0xff) >= thresh) {
         thrsbuf[y * size.x + x] = bg_buf[y * size.x + x] | (0xff << 24);
       } else {
         // explicitly set the colour of the transparent pixel.
         // This makes a difference when scaling!
         // thrsbuf[y*size.x+x]=bg_buf[y*size.x+x]&~(0xff<<24);
         thrsbuf[y * size.x + x] = bgcol_rgb;
       }
     }
   }
   return new JREImage(
       output_comp.createImage(
           new MemoryImageSource(
               size.x,
               size.y,
               // rgb_bitmask,
               img_bg.getColorModel(), // display compatible bitmask
               bitmask ? thrsbuf : bg_buf,
               0,
               size.x)));
 }
コード例 #7
0
  // TODO how to calculate minimum-difference pixels?
  @Override
  protected void changeQueue(Pixel p) {
    // recalculate neighbors
    for (Pixel np : p.neighbors) {
      if (np.isEmpty) {
        int r = 0, g = 0, b = 0, n = 0;
        for (Pixel nnp : np.neighbors) {
          if (!nnp.isEmpty) {
            r += nnp.color.getRed();
            g += nnp.color.getGreen();
            b += nnp.color.getBlue();
            n++;
          }
        }

        np.nonEmptyNeigh++;

        r /= n;
        g /= n;
        b /= n;

        Color avg = new Color(r, g, b);

        Color newBlock =
            new Color(
                r >> blockOffset & blockMask,
                g >> blockOffset & blockMask,
                b >> blockOffset & blockMask);
        int blockIndex =
            newBlock.getRed() * rOffset
                + newBlock.getGreen() * gOffset
                + newBlock.getBlue() * bOffset;

        if (!np.inQueue) {
          np.block = blockIndex;
          np.inQueue = true;
          pixelBlocks[blockIndex].add(np);
        } else if (blockIndex != np.block) {
          if (!pixelBlocks[np.block].remove(np)) {
            System.out.println(
                "Couldn't remove pixel "
                    + np
                    + ", even though it should be in block "
                    + blockIndex
                    + " !");
          }

          np.inQueue = true;
          np.block = blockIndex;
          pixelBlocks[blockIndex].add(np);
        }

        np.avg = avg;
      }
    }
  }
コード例 #8
0
ファイル: Text.java プロジェクト: lachlaan/Custom-Salem
 public Text renderwrap(String text, Color c, int width) {
   if (wfnd == null) wfnd = new RichText.Foundry(font, defcol);
   wfnd.aa = aa;
   text = RichText.Parser.quote(text);
   if (c != null)
     text =
         String.format(
             "$col[%d,%d,%d,%d]{%s}", c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha(), text);
   return (wfnd.render(text, width));
 }
コード例 #9
0
 void initGraphics(Graphics g, Color textColor, Color defaultColor) {
   if (smallFont == null) {
     smallFont = new Font("SansSerif", Font.PLAIN, 9);
     largeFont = new Font("SansSerif", Font.PLAIN, 12);
   }
   if (textColor != null) {
     labelColor = textColor;
     if (overlay != null && overlay.getDrawBackgrounds())
       bgColor =
           new Color(
               255 - labelColor.getRed(), 255 - labelColor.getGreen(), 255 - labelColor.getBlue());
     else bgColor = null;
   } else {
     int red = defaultColor.getRed();
     int green = defaultColor.getGreen();
     int blue = defaultColor.getBlue();
     if ((red + green + blue) / 3 < 128) labelColor = Color.white;
     else labelColor = Color.black;
     bgColor = defaultColor;
   }
   this.defaultColor = defaultColor;
   g.setColor(defaultColor);
 }
コード例 #10
0
  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();
  }
コード例 #11
0
 public final void setModulationColor(final Color modulationColor) {
   if (modulationColor == this.m_modulationColor) {
     return;
   }
   if (modulationColor != null) {
     this.m_entity3D.setColor(
         modulationColor.getRed(),
         modulationColor.getGreen(),
         modulationColor.getBlue(),
         modulationColor.getAlpha());
   } else {
     this.m_entity3D.setColor(1.0f, 1.0f, 1.0f, 1.0f);
   }
   this.m_modulationColor = modulationColor;
 }
コード例 #12
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);
        }
      }
    }
  }
コード例 #13
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);
 }
コード例 #14
0
ファイル: Picture.java プロジェクト: roshinc/shiny-archer
  /*
  ****************** CHECKLIST ******************************
  [x] manipulate every Pixel in the Picture
  [x] The value of amount MUST control the amount of the effect

  */
  public void changeWhole(double amount) {
    int yMax = this.getHeight();
    int xMax = this.getWidth();

    Color p;

    for (int i = 0; i < xMax - 1; i++) {
      for (int j = 0; j < yMax - 1; j++) {
        p = this.getPixel(i, j).getColor();
        int R = (int) (p.getRed() * amount);
        int G = (int) (p.getBlue() * (amount));
        int B = (int) (p.getGreen() * (amount));
        Color C = new Color(G, B, R);
        this.getPixel(i, j).setColor((C));
      }
    }
  }
コード例 #15
0
ファイル: Obj3d.java プロジェクト: Wingman4l7/flightclub
    /**
     * Calculates the apparent color of this polygon. We ask the camera how much light falls on a
     * surface wiith this normal and then darken the color accordingly.
     */
    private Color calcLight() {
      if (noShade) {
        return c;
      }

      int r = c.getRed();
      int g = c.getGreen();
      int b = c.getBlue();

      float light = modelViewer.cameraMan.surfaceLight(normal);

      r *= light;
      g *= light;
      b *= light;

      return new Color(r, g, b);
    }
コード例 #16
0
  /** {@inheritDoc} */
  public void setBackgroundColor(Color color) {
    if (color == null) {
      String message = Logging.getMessage("nullValue.ColorIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    // Only set the color if it actually changed
    if (!color.equals(this.getBackgroundColor())) {
      this.backgroundColor = color;

      // Convert the color to an RGB hex triplet string that the WebBrowser will understand
      int rgb =
          (color.getRed() & 0xFF) << 16 | (color.getGreen() & 0xFF) << 8 | (color.getBlue() & 0xFF);
      String colorString = String.format("#%06X", rgb);

      WindowsWebViewJNI.setBackgroundColor(this.webViewWindowPtr, colorString);
    }
  }
コード例 #17
0
 protected void setDrawingColor(int ox, int oy, boolean setBackground) {
   // IJ.log("setDrawingColor: "+setBackground+this);
   int type = imp.getType();
   int[] v = imp.getPixel(ox, oy);
   switch (type) {
     case ImagePlus.GRAY8:
       {
         if (setBackground) setBackgroundColor(getColor(v[0]));
         else setForegroundColor(getColor(v[0]));
         break;
       }
     case ImagePlus.GRAY16:
     case ImagePlus.GRAY32:
       {
         double min = imp.getProcessor().getMin();
         double max = imp.getProcessor().getMax();
         double value = (type == ImagePlus.GRAY32) ? Float.intBitsToFloat(v[0]) : v[0];
         int index = (int) (255.0 * ((value - min) / (max - min)));
         if (index < 0) index = 0;
         if (index > 255) index = 255;
         if (setBackground) setBackgroundColor(getColor(index));
         else setForegroundColor(getColor(index));
         break;
       }
     case ImagePlus.COLOR_RGB:
     case ImagePlus.COLOR_256:
       {
         Color c = new Color(v[0], v[1], v[2]);
         if (setBackground) setBackgroundColor(c);
         else setForegroundColor(c);
         break;
       }
   }
   Color c;
   if (setBackground) c = Toolbar.getBackgroundColor();
   else {
     c = Toolbar.getForegroundColor();
     imp.setColor(c);
   }
   IJ.showStatus("(" + c.getRed() + ", " + c.getGreen() + ", " + c.getBlue() + ")");
 }
コード例 #18
0
    private Color getColor(Element shape) {
      Color color;
      if (shape.hasAttribute(ATR_COLOUR)) {
        String s = shape.getAttribute(ATR_COLOUR);
        if (s.indexOf(',') > -1) {
          String[] rgb = s.split(",");
          color =
              new Color(
                  Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]));
        } else {
          color = new Color(Integer.parseInt(s));
        }
      } else color = IMPLIED_COLOR;

      if (shape.hasAttribute(ATR_TRANSPARENCY)) {
        int alpha = Integer.parseInt(shape.getAttribute(ATR_TRANSPARENCY));
        if (alpha < 255) return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
      }

      return color;
    }
コード例 #19
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;
   }
 }
コード例 #20
0
ファイル: ColorRenderer.java プロジェクト: adoGT/prismFDCTMC
  public Component getTableCellRendererComponent(
      JTable table,
      Setting owner,
      Object value,
      boolean isSelected,
      boolean hasFocus,
      boolean isEnabled,
      int row,
      int column) {
    // renderer.setMargin(new Insets(0, 2, 4, 2));

    if (isSelected) {
      renderer.setForeground(table.getSelectionForeground());
      panel.setBackground(table.getSelectionBackground());
      blank1.setBackground(table.getSelectionBackground());
      blank2.setBackground(table.getSelectionBackground());
    } else {
      renderer.setForeground(table.getForeground());
      panel.setBackground(table.getBackground());
      blank1.setBackground(table.getBackground());
      blank2.setBackground(table.getBackground());
    }

    if (hasFocus) {
      panel.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
    } else {
      panel.setBorder(new EmptyBorder(1, 2, 2, 1));
    }

    if (value instanceof Color) {
      Color col = (Color) value;

      // System.out.println("setting background to "+col.toString());

      renderer.setText("[" + col.getRed() + "," + col.getGreen() + "," + col.getBlue() + "]");

      renderer.setEnabled(isEnabled);

      renderer.setFont(font);

      colourPanel.setBackground(col);
    } else if (value instanceof ArrayList) {
      ArrayList values = (ArrayList) value;
      if (values.size() > 0) {
        // if we have multiple properties selected.
        Color last = null;
        boolean allSame = true;
        for (int i = 0; i < values.size(); i++) {
          if (values.get(i) instanceof Color) {
            Color str = (Color) values.get(i);
            if (last != null) {
              if (!str.equals(last)) {
                allSame = false;
                break;
              }
              last = str;
            } else {
              last = str;
            }
          }
        }
        if (allSame) {
          renderer.setText(
              "[" + last.getRed() + "," + last.getGreen() + "," + last.getBlue() + "]");

          renderer.setEnabled(isEnabled);

          renderer.setFont(font);

          colourPanel.setBackground(last);
        } else {
          renderer.setText("(Different values)");

          renderer.setEnabled(isEnabled);

          renderer.setFont(font);

          colourPanel.setBackground(Color.lightGray);
          panel.setBackground(Color.lightGray);
          blank1.setBackground(Color.lightGray);
          blank2.setBackground(Color.lightGray);
        }
      }
    }

    return panel;
  }
コード例 #21
0
 private void setBackgroundColor(Color c) {
   Toolbar.setBackgroundColor(c);
   if (Recorder.record)
     Recorder.record("setBackgroundColor", c.getRed(), c.getGreen(), c.getBlue());
 }
コード例 #22
0
  public GroundTexture(int size, Ground grnd) {

    System.out.println("Calculating Ground Texture...");

    img = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);

    double r, g, b;
    Random rnd = new Random();

    System.out.print("Initializing...");

    for (int x = 0; x < size; x++) {
      for (int y = 0; y < size; y++) {
        double slope = 0;
        for (int nx = x - 1; nx < x + 1; nx++)
          for (int ny = y - 1; ny < y + 1; ny++)
            if ((nx >= 0) && (nx < size))
              if ((ny >= 0) && (ny < size)) slope += Math.abs(grnd.topo[nx][ny] - grnd.topo[x][y]);
        if (slope < 1) slope = 1;
        g = 5d + 80d / (grnd.topo[x][y] / 2000d + 1d) + rnd.nextDouble() * 30d / (slope);
        r =
            g
                * (1.17
                    + (-.3 + (rnd.nextDouble() * .3))
                        / (grnd.topo[x][y] / 200d + 1d)
                        / (slope / 5 + 1));
        b =
            r
                * (.7
                    + (-.3 + (rnd.nextDouble() * .2))
                        / (grnd.topo[x][y] / 200d + 1d)
                        / (slope / 5 + 1));

        img.setRGB(x, y, colorRGB((int) r, (int) g, (int) b));
      }
    }

    /**/

    //		save("bodentextur2","png");

    System.out.print("                \rRandom Growth");

    for (int i = 0; i < size * size * 8; i++) {
      if (i % (size * size / 2) == 0) System.out.print(".");
      int x = 3 + rnd.nextInt(size - 6);
      int y = 3 + rnd.nextInt(size - 6);
      int nx = x - 1 + rnd.nextInt(3);
      int ny = y - 1 + rnd.nextInt(3);
      while ((nx < 0) || (nx >= size) || (ny < 0) || (ny >= size)) {
        nx = x - 1 + rnd.nextInt(3);
        ny = y - 1 + rnd.nextInt(3);
      }
      Color dis = getColorAt(x, y);
      Color col = getColorAt(nx, ny);
      if (grnd.topo[nx][ny] >= 4.5)
        if (col.getGreen() / col.getRed() > dis.getGreen() / dis.getRed())
          if (Math.abs(grnd.topo[x][y] - grnd.topo[nx][ny]) < .65) {
            int c = colorRGB(col.getRed(), col.getGreen(), col.getBlue());
            // img.setRGB(x,y, colorRGB(col.getRed(), col.getGreen(), col.getBlue()));
            // img.setRGB(x-1+rnd.nextInt(3),y-1+rnd.nextInt(3), colorRGB(col.getRed(),
            // col.getGreen(), col.getBlue()));
            for (nx = x - 1 - rnd.nextInt(3); nx < 1 + x + rnd.nextInt(3); nx++)
              for (ny = y - 1 - rnd.nextInt(3); ny < y + 1 + rnd.nextInt(3); ny++) {
                img.setRGB(nx, ny, c);
                grnd.topo[nx][ny] += 1.8;
              }
          }
    }

    System.out.print("                 \rAntialiasing...");
    /*		for (int x = 0; x < size; x++){
    	for (int y = 0; y < size; y++){
    		double sumr = 0;
    		double sumg = 0;
    		double sumb = 0;
    		double div = 0;
    		for (int nx=x-1;nx<x+1;nx++)
    			for (int ny=y-1;ny<y+1;ny++)
    				if ((nx>=0) && (nx < size)) if ((ny>=0) && (ny < size)) {
    					Color col = getColorAt(nx,ny);
    					sumr+=col.getRed();
    					sumg+=col.getGreen();
    					sumb+=col.getBlue();
    					div++;
    				}
    		r=sumr/div;
    		g=sumg/div;
    		b=sumb/div;
    		img.setRGB(x,y, colorRGB((int)r, (int)g, (int)b) );

    	}
    }*/

    System.out.print("        \r");
    //		save("bodentextur3","png");
    save("bodentextur", "png");
  }
コード例 #23
0
ファイル: AquaUtils.java プロジェクト: susotajuraj/jdk8u-jdk
 private static Color resetAlpha(final Color color) {
   return new Color(color.getRed(), color.getGreen(), color.getBlue(), 0);
 }
コード例 #24
0
    ImageProcessor setup(ImagePlus imp) {

      ImageProcessor ip;
      int type = imp.getType();
      if (type != ImagePlus.COLOR_RGB) return null;
      ip = imp.getProcessor();
      int id = imp.getID();
      int slice = imp.getCurrentSlice();

      if ((id != previousImageID) | (slice != previousSlice) | (flag)) {
        flag = false; // if true, flags a change from HSB to RGB or viceversa
        numSlices = imp.getStackSize();
        stack = imp.getStack();
        width = stack.getWidth();
        height = stack.getHeight();
        numPixels = width * height;

        hSource = new byte[numPixels];
        sSource = new byte[numPixels];
        bSource = new byte[numPixels];

        // restore = (int[])ip.getPixelsCopy(); //This runs into trouble sometimes, so do it the
        // long way:
        int[] temp = (int[]) ip.getPixels();
        restore = new int[numPixels];
        for (int i = 0; i < numPixels; i++) restore[i] = temp[i];

        fillMask = new int[numPixels];

        // Get hsb or rgb from image.
        ColorProcessor cp = (ColorProcessor) ip;
        IJ.showStatus("Gathering data");

        if (isRGB) cp.getRGB(hSource, sSource, bSource);
        else cp.getHSB(hSource, sSource, bSource);

        IJ.showStatus("done");

        // Create a spectrum ColorModel for the Hue histogram plot.
        Color c;
        byte[] reds = new byte[256];
        byte[] greens = new byte[256];
        byte[] blues = new byte[256];
        for (int i = 0; i < 256; i++) {
          c = Color.getHSBColor(i / 255f, 1f, 1f);

          reds[i] = (byte) c.getRed();
          greens[i] = (byte) c.getGreen();
          blues[i] = (byte) c.getBlue();
        }
        ColorModel cm = new IndexColorModel(8, 256, reds, greens, blues);

        // Make an image with just the hue from the RGB image and the spectrum LUT.
        // This is just for a hue histogram for the plot.  Do not show it.
        // ByteProcessor bpHue = new ByteProcessor(width,height,h,cm);
        ByteProcessor bpHue = new ByteProcessor(width, height, hSource, cm);
        ImagePlus impHue = new ImagePlus("Hue", bpHue);
        // impHue.show();

        ByteProcessor bpSat = new ByteProcessor(width, height, sSource, cm);
        ImagePlus impSat = new ImagePlus("Sat", bpSat);
        // impSat.show();

        ByteProcessor bpBri = new ByteProcessor(width, height, bSource, cm);
        ImagePlus impBri = new ImagePlus("Bri", bpBri);
        // impBri.show();

        plot.setHistogram(impHue, 0);
        splot.setHistogram(impSat, 1);
        bplot.setHistogram(impBri, 2);

        updateLabels();
        updatePlot();
        updateScrollBars();
        imp.updateAndDraw();
      }
      previousImageID = id;
      previousSlice = slice;
      return ip;
    }
コード例 #25
0
 /**
  * Set the cursor color.
  *
  * @param color cursor color
  * @exception RemoteException If there was a problem making this change in a remote collaborative
  *     <CODE>DisplayRenderer</CODE>.
  * @exception VisADException If this renderer as not yet been assigned to a <CODE>Display</CODE>.
  */
 public void setCursorColor(Color color) throws RemoteException, VisADException {
   final float r = (float) color.getRed() / 255.0f;
   final float g = (float) color.getGreen() / 255.0f;
   final float b = (float) color.getBlue() / 255.0f;
   setCursorColor(r, g, b);
 }
コード例 #26
0
  public void paintRegion(Graphics2D g, int x1, int y1, int w, int h) {
    int h2 = h / 2;
    int rad = 3;
    int diam = rad * 2;

    Color lg = Color.cyan;
    Color dg = Color.orange;

    lg = new Color(lg.getRed(), lg.getGreen(), lg.getBlue(), 75);
    dg = new Color(dg.getRed(), dg.getGreen(), dg.getBlue(), 75);

    /*
     * Draw the Baseline
     */
    g.setColor(Color.black);
    g.drawLine(x1, y1 + h, x1 + w, y1 + h);

    Stroke oldStroke = g.getStroke();
    g.setStroke(new BasicStroke((float) 2.0));

    /*
     * Draw the datapoints
     */
    for (ExprPoint ep : points) {
      if (ep.strand == '+') {
        g.setColor(lg);
      } else {
        g.setColor(dg);
      }

      g.drawOval(x1 + ep.x - rad, y1 + ep.y - rad, diam, diam);
    }

    g.setStroke(oldStroke);

    /*
     * Paint the hash marks...
     */
    if (!displayOppositeChannel) {
      g.setColor(Color.black);
      boolean flipper = true;
      for (int value = 100;
          value <= scale.getMax();
          value *= (flipper ? 5 : 2), flipper = !flipper) {
        int yoff = getYOffset((double) value);
        String line = String.format("%d", value);
        int uy = y1 + h2 - yoff, ly = y1 + h2 + yoff;

        g.drawLine(x1, uy, x1 + 10, uy);
        g.drawString(line, x1 + 12, uy + 5);

        g.drawLine(x1, ly, x1 + 10, ly);
        g.drawString(line, x1 + 12, ly + 5);
      }
    }

    /*
     * Draw any selections.
     */

    g.setColor(Color.black);
    for (Point p : selections.keySet()) {
      ExprPoint ep = selections.get(p);
      g.drawLine(p.x, p.y, ep.x, ep.y);
      g.drawString(ep.getLabel(), p.x, p.y);
    }

    /*
     * Draw the label in the upper-right hand corner.
     */
    g.setColor(Color.black);
    Font oldFont = g.getFont();
    Font newFont = new Font("Arial", Font.BOLD, 24);
    g.setFont(newFont);
    FontMetrics fm = g.getFontMetrics();
    int lblHeight = fm.getAscent() + fm.getDescent();
    int lblWidth = fm.charsWidth(label.toCharArray(), 0, label.length());

    int padding = 5;
    int lblx = x1 + w - lblWidth - padding;
    int lbly = y1 + lblHeight + padding;

    g.drawString(label, lblx, lbly);

    g.setFont(oldFont);
  }
コード例 #27
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int width = getWidth() - rightMargin - leftMargin - 10;
    int height = getHeight() - topMargin - bottomMargin;
    if (width <= 0 || height <= 0) {
      // not enough room to paint anything
      return;
    }

    Color oldColor = g.getColor();
    Font oldFont = g.getFont();
    Color fg = getForeground();
    Color bg = getBackground();
    boolean bgIsLight = (bg.getRed() > 200 && bg.getGreen() > 200 && bg.getBlue() > 200);

    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    if (smallFont == null) {
      smallFont = oldFont.deriveFont(9.0F);
    }

    r.x = leftMargin - 5;
    r.y = topMargin - 8;
    r.width = getWidth() - leftMargin - rightMargin;
    r.height = getHeight() - topMargin - bottomMargin + 16;

    if (border == null) {
      // By setting colors here, we avoid recalculating them
      // over and over.
      border =
          new BevelBorder(
              BevelBorder.LOWERED,
              getBackground().brighter().brighter(),
              getBackground().brighter(),
              getBackground().darker().darker(),
              getBackground().darker());
    }

    border.paintBorder(this, g, r.x, r.y, r.width, r.height);

    // Fill background color
    g.setColor(bgColor);
    g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4);
    g.setColor(oldColor);

    long tMin = Long.MAX_VALUE;
    long tMax = Long.MIN_VALUE;
    long vMin = Long.MAX_VALUE;
    long vMax = 1;

    int w = getWidth() - rightMargin - leftMargin - 10;
    int h = getHeight() - topMargin - bottomMargin;

    if (times.size > 1) {
      tMin = Math.min(tMin, times.time(0));
      tMax = Math.max(tMax, times.time(times.size - 1));
    }
    long viewRangeMS;
    if (viewRange > 0) {
      viewRangeMS = viewRange * MINUTE;
    } else {
      // Display full time range, but no less than a minute
      viewRangeMS = Math.max(tMax - tMin, 1 * MINUTE);
    }

    // Calculate min/max values
    for (Sequence seq : seqs) {
      if (seq.size > 0) {
        for (int i = 0; i < seq.size; i++) {
          if (seq.size == 1 || times.time(i) >= tMax - viewRangeMS) {
            long val = seq.value(i);
            if (val > Long.MIN_VALUE) {
              vMax = Math.max(vMax, val);
              vMin = Math.min(vMin, val);
            }
          }
        }
      } else {
        vMin = 0L;
      }
      if (unit == Unit.BYTES || !seq.isPlotted) {
        // We'll scale only to the first (main) value set.
        // TODO: Use a separate property for this.
        break;
      }
    }

    // Normalize scale
    vMax = normalizeMax(vMax);
    if (vMin > 0) {
      if (vMax / vMin > 4) {
        vMin = 0;
      } else {
        vMin = normalizeMin(vMin);
      }
    }

    g.setColor(fg);

    // Axes
    // Draw vertical axis
    int x = leftMargin - 18;
    int y = topMargin;
    FontMetrics fm = g.getFontMetrics();

    g.drawLine(x, y, x, y + h);

    int n = 5;
    if (("" + vMax).startsWith("2")) {
      n = 4;
    } else if (("" + vMax).startsWith("3")) {
      n = 6;
    } else if (("" + vMax).startsWith("4")) {
      n = 4;
    } else if (("" + vMax).startsWith("6")) {
      n = 6;
    } else if (("" + vMax).startsWith("7")) {
      n = 7;
    } else if (("" + vMax).startsWith("8")) {
      n = 8;
    } else if (("" + vMax).startsWith("9")) {
      n = 3;
    }

    // Ticks
    ArrayList<Long> tickValues = new ArrayList<Long>();
    tickValues.add(vMin);
    for (int i = 0; i < n; i++) {
      long v = i * vMax / n;
      if (v > vMin) {
        tickValues.add(v);
      }
    }
    tickValues.add(vMax);
    n = tickValues.size();

    String[] tickStrings = new String[n];
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      tickStrings[i] = getSizeString(v, vMax);
    }

    // Trim trailing decimal zeroes.
    if (decimals > 0) {
      boolean trimLast = true;
      boolean removedDecimalPoint = false;
      do {
        for (String str : tickStrings) {
          if (!(str.endsWith("0") || str.endsWith("."))) {
            trimLast = false;
            break;
          }
        }
        if (trimLast) {
          if (tickStrings[0].endsWith(".")) {
            removedDecimalPoint = true;
          }
          for (int i = 0; i < n; i++) {
            String str = tickStrings[i];
            tickStrings[i] = str.substring(0, str.length() - 1);
          }
        }
      } while (trimLast && !removedDecimalPoint);
    }

    // Draw ticks
    int lastY = Integer.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
      g.drawLine(x - 2, y, x + 2, y);
      String s = tickStrings[i];
      if (unit == Unit.PERCENT) {
        s += "%";
      }
      int sx = x - 6 - fm.stringWidth(s);
      if (y < lastY - 13) {
        if (checkLeftMargin(sx)) {
          // Wait for next repaint
          return;
        }
        g.drawString(s, sx, y + 4);
      }
      // Draw horizontal grid line
      g.setColor(Color.lightGray);
      g.drawLine(r.x + 4, y, r.x + r.width - 4, y);
      g.setColor(fg);
      lastY = y;
    }

    // Draw horizontal axis
    x = leftMargin;
    y = topMargin + h + 15;
    g.drawLine(x, y, x + w, y);

    long t1 = tMax;
    if (t1 <= 0L) {
      // No data yet, so draw current time
      t1 = System.currentTimeMillis();
    }
    long tz = timeDF.getTimeZone().getOffset(t1);
    long tickInterval = calculateTickInterval(w, 40, viewRangeMS);
    if (tickInterval > 3 * HOUR) {
      tickInterval = calculateTickInterval(w, 80, viewRangeMS);
    }
    long t0 = tickInterval - (t1 - viewRangeMS + tz) % tickInterval;
    while (t0 < viewRangeMS) {
      x = leftMargin + (int) (w * t0 / viewRangeMS);
      g.drawLine(x, y - 2, x, y + 2);

      long t = t1 - viewRangeMS + t0;
      String str = formatClockTime(t);
      g.drawString(str, x, y + 16);
      // if (tickInterval > (1 * HOUR) && t % (1 * DAY) == 0) {
      if ((t + tz) % (1 * DAY) == 0) {
        str = formatDate(t);
        g.drawString(str, x, y + 27);
      }
      // Draw vertical grid line
      g.setColor(Color.lightGray);
      g.drawLine(x, topMargin, x, topMargin + h);
      g.setColor(fg);
      t0 += tickInterval;
    }

    // Plot values
    int start = 0;
    int nValues = 0;
    int nLists = seqs.size();
    if (nLists > 0) {
      nValues = seqs.get(0).size;
    }
    if (nValues == 0) {
      g.setColor(oldColor);
      return;
    } else {
      Sequence seq = seqs.get(0);
      // Find starting point
      for (int p = 0; p < seq.size; p++) {
        if (times.time(p) >= tMax - viewRangeMS) {
          start = p;
          break;
        }
      }
    }

    // Optimization: collapse plot of more than four values per pixel
    int pointsPerPixel = (nValues - start) / w;
    if (pointsPerPixel < 4) {
      pointsPerPixel = 1;
    }

    // Draw graphs
    // Loop backwards over sequences because the first needs to be painted on top
    for (int i = nLists - 1; i >= 0; i--) {
      int x0 = leftMargin;
      int y0 = topMargin + h + 1;

      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Paint twice, with white and with color
        for (int pass = 0; pass < 2; pass++) {
          g.setColor((pass == 0) ? Color.white : seq.color);
          int x1 = -1;
          long v1 = -1;
          for (int p = start; p < nValues; p += pointsPerPixel) {
            // Make sure we get the last value
            if (pointsPerPixel > 1 && p >= nValues - pointsPerPixel) {
              p = nValues - 1;
            }
            int x2 = (int) (w * (times.time(p) - (t1 - viewRangeMS)) / viewRangeMS);
            long v2 = seq.value(p);
            if (v2 >= vMin && v2 <= vMax) {
              int y2 = (int) (h * (v2 - vMin) / (vMax - vMin));
              if (x1 >= 0 && v1 >= vMin && v1 <= vMax) {
                int y1 = (int) (h * (v1 - vMin) / (vMax - vMin));

                if (y1 == y2) {
                  // fillrect is much faster
                  g.fillRect(x0 + x1, y0 - y1 - pass, x2 - x1, 1);
                } else {
                  Graphics2D g2d = (Graphics2D) g;
                  Stroke oldStroke = null;
                  if (seq.transitionStroke != null) {
                    oldStroke = g2d.getStroke();
                    g2d.setStroke(seq.transitionStroke);
                  }
                  g.drawLine(x0 + x1, y0 - y1 - pass, x0 + x2, y0 - y2 - pass);
                  if (oldStroke != null) {
                    g2d.setStroke(oldStroke);
                  }
                }
              }
            }
            x1 = x2;
            v1 = v2;
          }
        }

        // Current value
        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          // a small triangle/arrow
          g.fillPolygon(new int[] {x + 2, x + 6, x + 6}, new int[] {y, y + 3, y - 3}, 3);
        }
        g.setColor(fg);
      }
    }

    int[] valueStringSlots = new int[nLists];
    for (int i = 0; i < nLists; i++) valueStringSlots[i] = -1;
    for (int i = 0; i < nLists; i++) {
      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Draw current value

        // TODO: collapse values if pointsPerPixel >= 4

        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          int y2 = getValueStringSlot(valueStringSlots, y, 2 * 10, i);
          g.setFont(smallFont);
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          String curValue = getFormattedValue(v, true);
          if (unit == Unit.PERCENT) {
            curValue += "%";
          }
          int valWidth = fm.stringWidth(curValue);
          String legend = (displayLegend ? seq.name : "");
          int legendWidth = fm.stringWidth(legend);
          if (checkRightMargin(valWidth) || checkRightMargin(legendWidth)) {
            // Wait for next repaint
            return;
          }
          g.drawString(legend, x + 17, Math.min(topMargin + h, y2 + 3 - 10));
          g.drawString(curValue, x + 17, Math.min(topMargin + h + 10, y2 + 3));

          // Maybe draw a short line to value
          if (y2 > y + 3) {
            g.drawLine(x + 9, y + 2, x + 14, y2);
          } else if (y2 < y - 3) {
            g.drawLine(x + 9, y - 2, x + 14, y2);
          }
        }
        g.setFont(oldFont);
        g.setColor(fg);
      }
    }
    g.setColor(oldColor);
  }