예제 #1
0
파일: ColorUtility.java 프로젝트: di/school
 /* Color.toString() is not great so we need a way to convert a
  * Color to some easily readable format, since we only
  * support black, white, blue, green, red, & yellow we can
  * easily check these by looking at the RGB values of the
  * color found by calling Color.getRGB().
  */
 public String colorToString(Color color) {
   if (color.getRGB() == Color.BLACK.getRGB()) {
     return "Black";
   } else if (color.getRGB() == Color.BLUE.getRGB()) {
     return "Blue";
   } else if (color.getRGB() == Color.GREEN.getRGB()) {
     return "Green";
   } else if (color.getRGB() == Color.RED.getRGB()) {
     return "Red";
   } else if (color.getRGB() == Color.YELLOW.getRGB()) {
     return "Yellow";
   } else {
     return "No Color Information";
   }
 }
예제 #2
0
  /**
   * This method is called whenever the observed object is changed. An application calls an
   * <tt>Observable</tt> object's <code>notifyObservers</code> method to have all the object's
   * observers notified of the change.
   *
   * @param obj the observable object.
   * @param arg an argument passed to the <code>notifyObservers</code> method.
   */
  public void update(final Observable obj, final Object arg) {
    final String line = (String) arg;
    final String thisLine =
        line.substring(
            line.indexOf("Text [") + "Text [".length(), line.indexOf("]", line.indexOf("Text [")));

    if (thisLine.indexOf(MSG) < 0 && thisLine.indexOf(MSG_LEADER) < 0) {
      return;
    }

    final StringTokenizer stok = new StringTokenizer(thisLine, ";");
    stok.nextToken();
    final String fromNodeId = stok.nextToken();

    final VizNode fromNode = displayNode(fromNodeId);

    // Check if node should be ignored
    if (fromNode == null) {
      return;
    }

    fromNode.setColorInt(Color.GREEN.getRGB());
  }
예제 #3
0
  @Override
  public void glyph(
      final Graphics2D g,
      final Rectangle2D rect,
      final CachedDimRangeSymbolizer symbol,
      final MapLayer layer) {

    int[] ARGB = new int[] {Color.RED.getRGB(), Color.GREEN.getRGB(), Color.BLUE.getRGB()};

    if (layer instanceof CoverageMapLayer) {
      final CoverageMapLayer cml = (CoverageMapLayer) layer;
      final CoverageReference ref = cml.getCoverageReference();
      try {
        final GridCoverageReader reader = ref.acquireReader();
        final GridCoverageReadParam param = new GridCoverageReadParam();
        param.setResolution(1, 1);
        GridCoverage2D cov = (GridCoverage2D) reader.read(0, param);
        ref.recycle(reader);
        cov = cov.view(ViewType.NATIVE);
        RenderedImage img = cov.getRenderedImage();
        ColorModel cm = img.getColorModel();

        if (cm instanceof IndexColorModel) {
          final IndexColorModel icm = (IndexColorModel) cm;

          final GridSampleDimension sampleDim = cov.getSampleDimension(0);

          int size = icm.getMapSize();
          ARGB = new int[size];
          icm.getRGBs(ARGB);
          final double minVal = sampleDim.getMinimumValue();
          final double maxVal = sampleDim.getMaximumValue();

          final ColorMap colorMap = new ColorMap();
          colorMap.setGeophysicsRange(
              ColorMap.ANY_QUANTITATIVE_CATEGORY,
              new MeasurementRange(
                  NumberRange.create(minVal, true, maxVal, true), sampleDim.getUnits()));

          GridSampleDimension ret = colorMap.recolor(sampleDim, ARGB);
        }

      } catch (CoverageStoreException | CancellationException ex) {
        Logging.getLogger("org.geotoolkit.display2d.ext.dimrange").log(Level.WARNING, null, ex);
      }
    }

    final float[] space = new float[ARGB.length];
    final Color[] colors = new Color[ARGB.length];
    for (int i = 0; i < space.length; i++) {
      space[i] = (float) i / (space.length - 1);
      colors[i] = new Color(ARGB[i]);
    }

    final LinearGradientPaint paint =
        new LinearGradientPaint(
            (float) rect.getMinX(),
            (float) rect.getMinY(),
            (float) rect.getMaxX(),
            (float) rect.getMinY(),
            space,
            colors);

    g.setPaint(paint);
    g.fill(rect);
  }
예제 #4
0
 @Override
 public void apply(GameMap map, int pixel, int row, int column) {
   if (pixel == Color.GREEN.getRGB()) {
     map.addPill(new BigPill(row, column));
   }
 }