/**
  * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles
  * Enumeration of StyleRanges, need to be in order. (output) LineStyleEvent.background line
  * background color (output)
  */
 public void lineGetStyle(LineStyleEvent event) {
   Vector styles = new Vector();
   int token;
   StyleRange lastStyle;
   // If the line is part of a block comment, create one style for the entire line.
   if (inBlockComment(event.lineOffset, event.lineOffset + event.lineText.length())) {
     styles.addElement(
         new StyleRange(event.lineOffset, event.lineText.length(), getColor(COMMENT), null));
     event.styles = new StyleRange[styles.size()];
     styles.copyInto(event.styles);
     return;
   }
   Color defaultFgColor = ((Control) event.widget).getForeground();
   scanner.setRange(event.lineText);
   token = scanner.nextToken();
   while (token != EOF) {
     if (token == OTHER) {
       // do nothing for non-colored tokens
     } else if (token != WHITE) {
       Color color = getColor(token);
       // Only create a style if the token color is different than the
       // widget's default foreground color and the token's style is not
       // bold.  Keywords are bolded.
       if ((!color.equals(defaultFgColor)) || (token == KEY)) {
         StyleRange style =
             new StyleRange(
                 scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null);
         if (token == KEY) {
           style.fontStyle = SWT.BOLD;
         }
         if (styles.isEmpty()) {
           styles.addElement(style);
         } else {
           // Merge similar styles.  Doing so will improve performance.
           lastStyle = (StyleRange) styles.lastElement();
           if (lastStyle.similarTo(style) && (lastStyle.start + lastStyle.length == style.start)) {
             lastStyle.length += style.length;
           } else {
             styles.addElement(style);
           }
         }
       }
     } else if ((!styles.isEmpty())
         && ((lastStyle = (StyleRange) styles.lastElement()).fontStyle == SWT.BOLD)) {
       int start = scanner.getStartOffset() + event.lineOffset;
       lastStyle = (StyleRange) styles.lastElement();
       // A font style of SWT.BOLD implies that the last style
       // represents a java keyword.
       if (lastStyle.start + lastStyle.length == start) {
         // Have the white space take on the style before it to
         // minimize the number of style ranges created and the
         // number of font style changes during rendering.
         lastStyle.length += scanner.getLength();
       }
     }
     token = scanner.nextToken();
   }
   event.styles = new StyleRange[styles.size()];
   styles.copyInto(event.styles);
 }
  public void write(OutStream out, boolean hasAlpha) throws IOException {
    out.writeUI8(fillType);

    if (fillType == SWFConstants.FILL_SOLID) {
      if (hasAlpha) color.writeWithAlpha(out);
      else color.writeRGB(out);
    } else if (fillType == SWFConstants.FILL_LINEAR_GRADIENT
        || fillType == SWFConstants.FILL_RADIAL_GRADIENT) {
      matrix.write(out);

      int numRatios = ratios.length;

      out.writeUI8(numRatios);

      for (int i = 0; i < numRatios; i++) {
        if (colors[i] == null) continue;

        out.writeUI8(ratios[i]);

        if (hasAlpha) colors[i].writeWithAlpha(out);
        else colors[i].writeRGB(out);
      }
    } else if (fillType == SWFConstants.FILL_TILED_BITMAP
        || fillType == SWFConstants.FILL_CLIPPED_BITMAP) {
      out.writeUI16(bitmapId);
      matrix.write(out);
    }
  }
Exemple #3
0
  /**
   * Find the color band that this value falls in and assign that color.
   *
   * @param v
   * @param color
   */
  private final void absoluteValue(final double v, final int[] color) {
    final double search;
    switch (scaling) {
      case Absolute:
        search = v;
        break;
      case MinMax:
        search = (v - min) / (max - min);
        break;
      case Modulo:
        search = v % (max - min);
        break;
      default:
        search = 0;
        break;
    }

    final Map.Entry<Double, Color> lower = floorEntry(search);

    Color c;
    if (lower == null) {
      c = entrySet().iterator().next().getValue();
    } else {
      c = lower.getValue();
    }

    color[R] = c.getRed();
    color[G] = c.getGreen();
    color[B] = c.getBlue();
    color[A] = c.getAlpha();
  }
  /**
   * Function: getJavaColor Pre: Takes an ANIMAL color string 'c' Post: Returns the java color for
   * this node (Note: returns "white" as a default)
   */
  private Color getJavaColor(String c) {
    if (!isValidNodeColor(c)) return Color.white;

    // Temporary color to use with numbered colors
    Color temp = Color.white;

    if (c.compareTo("black") == 0) return Color.black;
    if (c.compareTo("white") == 0) return Color.white;
    if (c.compareTo("gray") == 0) return Color.gray;
    if (c.compareTo("yellow") == 0) return Color.yellow;
    if (c.startsWith("blue")) temp = Color.blue;
    if (c.startsWith("cyan")) temp = Color.cyan;
    if (c.startsWith("pink")) temp = Color.pink;
    if (c.startsWith("red")) temp = Color.red;
    if (c.startsWith("magenta")) temp = Color.magenta;
    if (c.startsWith("green")) temp = Color.green;

    // Finally, do some final handling for
    temp = temp.darker().darker();
    if (c.endsWith("2")) return temp.brighter();
    if (c.endsWith("3")) return temp.brighter().brighter();
    if (c.endsWith("4")) return temp.brighter().brighter().brighter();

    return temp;
  }
Exemple #5
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);
    }
 @Override
 public void write(final OutputStream out) throws IOException {
   out.write(TYPE_COLOR);
   super.write(out);
   out.write(color.getRed());
   out.write(color.getGreen());
   out.write(color.getBlue());
   out.write(color.getAlpha());
 }
Exemple #7
0
  /**
   * Esta funcion se usa para inicializar los colores del tema segun los argumentos que se le pasen.
   */
  static NimRODTheme iniCustomColors(
      NimRODTheme nt,
      String selection,
      String background,
      String p1,
      String p2,
      String p3,
      String s1,
      String s2,
      String s3,
      String w,
      String b,
      String opMenu,
      String opFrame) {
    if (selection != null) {
      nt.setPrimary(Color.decode(selection));
    }
    if (background != null) {
      nt.setSecondary(Color.decode(background));
    }

    if (p1 != null) {
      nt.setPrimary1(Color.decode(p1));
    }
    if (p2 != null) {
      nt.setPrimary2(Color.decode(p2));
    }
    if (p3 != null) {
      nt.setPrimary3(Color.decode(p3));
    }

    if (s1 != null) {
      nt.setSecondary1(Color.decode(s1));
    }
    if (s2 != null) {
      nt.setSecondary2(Color.decode(s2));
    }
    if (s3 != null) {
      nt.setSecondary3(Color.decode(s3));
    }

    if (w != null) {
      nt.setWhite(Color.decode(w));
    }
    if (b != null) {
      nt.setBlack(Color.decode(b));
    }

    if (opMenu != null) {
      nt.setMenuOpacity(Integer.parseInt(opMenu));
    }
    if (opFrame != null) {
      nt.setFrameOpacity(Integer.parseInt(opFrame));
    }

    return nt;
  }
Exemple #8
0
 /**
  * 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)));
 }
Exemple #9
0
  public boolean equals(final ColorScale cs) {
    if (min == null && cs.min != null || min != null && cs.min == null) {
      return false;
    }
    if ((min != null && cs.min != null) && Double.compare(min, cs.min) != 0) {
      return false;
    }
    if (max == null && cs.max != null || max != null && cs.max == null) {
      return false;
    }
    if ((max != null && cs.max != null) && Double.compare(max, cs.max) != 0) {
      return false;
    }
    if (!scaling.equals(cs.scaling)) {
      return false;
    }
    if (interpolate != cs.interpolate) {
      return false;
    }
    if (forceValuesIntoRange != cs.forceValuesIntoRange) {
      return false;
    }
    if (reliefShading != cs.reliefShading) {
      return false;
    }
    if (nullColor.length != cs.nullColor.length) {
      return false;
    }
    for (int i = 0; i < nullColor.length; i++) {
      if (nullColor[i] != cs.nullColor[i]) {
        return false;
      }
    }
    if (size() != cs.size()) {
      return false;
    }
    final Iterator<Double> iterator1 = cs.keySet().iterator();
    for (final Double d1 : this.keySet()) {
      final Double d2 = iterator1.next();
      if (d1.compareTo(d2) != 0) {
        return false;
      }

      final Color value1 = get(d1);
      final Color value2 = get(d2);
      if (!value1.equals(value2)) {
        return false;
      }
    }
    return true;
  }
  // Get Color as String
  public static String getColor(Color color) {
    ArrayList<String> colors = new ArrayList<String>();
    colors.add(Long.toHexString(color.getRed()));
    colors.add(Long.toHexString(color.getGreen()));
    colors.add(Long.toHexString(color.getBlue()));

    StringBuilder buffer = new StringBuilder();
    for (String c : colors) {
      if (c.length() == 1) {
        buffer.append("0");
      }
      buffer.append(c);
    }
    return ("#" + buffer.toString());
  }
Exemple #11
0
  /**
   * Class constructor alloowing specification of the heading text.
   *
   * @param properties the Properties object containing the initial values of the extensions list
   *     and the path to be displayed. This object is updated tin response to root changes,
   *     extension changes, and file selections. If any property is missing, a suitable one is
   *     supplied by default.
   * @param heading the text to appear in the heading of the JPanel.
   * @param background the background color or null if the default is to be used.
   */
  public SourcePanel(ApplicationProperties properties, String heading, Color background) {
    super();
    this.properties = properties;
    if (background == null) this.background = Color.getHSBColor(0.58f, 0.17f, 0.95f);
    else this.background = background;

    // Make the file filter
    filter = new GeneralFileFilter();
    String extensions = properties.getProperty("extensions");
    if (extensions != null) filter.setExtensions(extensions);
    else {
      filter.addExtension(".dcm");
      properties.setProperty("extensions", filter.getExtensionString());
    }

    // Get the starting directory path from the properties.
    // If it is missing, start in the directory containing the program.
    String currentDirectoryPath = properties.getProperty("directory");
    if (currentDirectoryPath == null) currentDirectoryPath = System.getProperty("user.dir");

    // Create the UI components
    this.setLayout(new BorderLayout());
    directoryPane = new DirectoryPane(filter, currentDirectoryPath);
    directoryPane.addFileListener(this);
    headerPanel = new HeaderPanel(heading);
    footerPanel = new FooterPanel();
    this.add(headerPanel, BorderLayout.NORTH);
    this.add(directoryPane, BorderLayout.CENTER);
    this.add(footerPanel, BorderLayout.SOUTH);
  }
  /**
   * WhiteboardObjectTextJabberImpl constructor.
   *
   * @param xml the XML string object to parse.
   */
  public WhiteboardObjectTextJabberImpl(String xml) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
      builder = factory.newDocumentBuilder();
      InputStream in = new ByteArrayInputStream(xml.getBytes());
      Document doc = builder.parse(in);

      Element e = doc.getDocumentElement();
      String elementName = e.getNodeName();
      if (elementName.equals("text")) {
        // we have a text
        String id = e.getAttribute("id");
        double x = Double.parseDouble(e.getAttribute("x"));
        double y = Double.parseDouble(e.getAttribute("y"));
        String fill = e.getAttribute("fill");
        String fontFamily = e.getAttribute("font-family");
        int fontSize = Integer.parseInt(e.getAttribute("font-size"));
        String text = e.getTextContent();

        this.setID(id);
        this.setWhiteboardPoint(new WhiteboardPoint(x, y));
        this.setFontName(fontFamily);
        this.setFontSize(fontSize);
        this.setText(text);
        this.setColor(Color.decode(fill).getRGB());
      }
    } catch (ParserConfigurationException ex) {
      if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml);
    } catch (IOException ex) {
      if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml);
    } catch (Exception ex) {
      if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml);
    }
  }
Exemple #13
0
    /**
     * 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);
    }
 /**
  * \ Draw saved State (color dots on panel) on WhiteBoard
  *
  * @param outstream
  * @throws IOException
  */
 public void writeState(OutputStream outstream) throws IOException {
   if (state == null) return;
   synchronized (state) {
     DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(outstream));
     // DataOutputStream dos=new DataOutputStream(outstream);
     dos.writeInt(state.size());
     for (Map.Entry<Point, Color> entry : state.entrySet()) {
       Point point = entry.getKey();
       Color col = entry.getValue();
       dos.writeInt(point.x);
       dos.writeInt(point.x);
       dos.writeInt(col.getRGB());
     }
     dos.flush();
     System.out.println("wrote " + state.size() + " elements");
   }
 }
Exemple #15
0
  void initComponents() {
    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    Color bgColor = Color.getHSBColor(0.58f, 0.17f, 0.95f);
    buttonPanel.setBackground(bgColor);
    Border empty = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    buttonPanel.setBorder(empty);

    textField = new JTextField(75);
    buttonPanel.add(textField);

    buttonPanel.add(Box.createHorizontalStrut(10));
    searchPHI = new JButton("Search PHI");
    searchPHI.addActionListener(this);
    buttonPanel.add(searchPHI);

    buttonPanel.add(Box.createHorizontalStrut(10));
    searchTrial = new JButton("Search Trial IDs");
    searchTrial.addActionListener(this);
    buttonPanel.add(searchTrial);

    buttonPanel.add(Box.createHorizontalStrut(20));
    buttonPanel.add(Box.createHorizontalGlue());
    saveAs = new JCheckBox("Save As...");
    saveAs.setBackground(bgColor);
    buttonPanel.add(saveAs);

    mainPanel.add(buttonPanel, BorderLayout.NORTH);

    JScrollPane scrollPane = new JScrollPane();
    textPane = new ColorPane();
    // textPane.setEditable(false);
    scrollPane.setViewportView(textPane);
    mainPanel.add(scrollPane, BorderLayout.CENTER);

    JPanel footerPanel = new JPanel();
    footerPanel.setLayout(new BoxLayout(footerPanel, BoxLayout.X_AXIS));
    footerPanel.setBackground(bgColor);
    message = new JLabel("Ready...");
    footerPanel.add(message);
    mainPanel.add(footerPanel, BorderLayout.SOUTH);

    setTitle(windowTitle);
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent evt) {
            System.exit(0);
          }
        });
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    pack();
    centerFrame();
  }
    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;
    }
Exemple #17
0
  public static Bitmap blurBmp(Bitmap bmp, int Blur) {

    int pixels[] = new int[bmp.getWidth() * bmp.getHeight()];
    int pixelsRawSource[] = new int[bmp.getWidth() * bmp.getHeight() * 3];
    int pixelsRawNew[] = new int[bmp.getWidth() * bmp.getHeight() * 3];
    bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());

    for (int k = 1; k <= Blur; k++) {

      for (int i = 0; i < pixels.length; i++) {
        pixelsRawSource[i * 3 + 0] = Color.red(pixels[i]);
        pixelsRawSource[i * 3 + 1] = Color.green(pixels[i]);
        pixelsRawSource[i * 3 + 2] = Color.blue(pixels[i]);
      }

      int CurrentPixel = bmp.getWidth() * 3 + 3;
      for (int i = 0; i < bmp.getHeight() - 3; i++) {
        for (int j = 0; j < bmp.getWidth() * 3; j++) {
          CurrentPixel += 1;

          int sumColor = 0;
          sumColor = pixelsRawSource[CurrentPixel - bmp.getWidth() * 3];
          sumColor = sumColor + pixelsRawSource[CurrentPixel - 3];
          sumColor = sumColor + pixelsRawSource[CurrentPixel + 3];
          sumColor = sumColor + pixelsRawSource[CurrentPixel + bmp.getWidth() * 3];
          pixelsRawNew[CurrentPixel] = Math.round(sumColor / 4);
        }
      }

      for (int i = 0; i < pixels.length; i++) {
        pixels[i] =
            Color.rgb(pixelsRawNew[i * 3 + 0], pixelsRawNew[i * 3 + 1], pixelsRawNew[i * 3 + 2]);
      }
    }

    Bitmap bmpReturn = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888);
    bmpReturn.setPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());

    return bmpReturn;
  }
Exemple #18
0
 public FooterPanel() {
   super();
   this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
   this.setBackground(Color.getHSBColor(0.58f, 0.17f, 0.95f));
   subdirectories = new JCheckBox("Include subdirectories");
   subdirectories.setBackground(background);
   this.add(subdirectories);
   this.add(Box.createHorizontalGlue());
   extensionButton = new JButton(filter.getDescription());
   this.add(extensionButton);
   this.add(Box.createHorizontalStrut(17));
   extensionButton.addActionListener(this);
 }
 /** Returns index of palette color closest to c */
 protected int findClosest(Color c) {
   if (colorTab == null) return -1;
   int r = c.getRed();
   int g = c.getGreen();
   int b = c.getBlue();
   int minpos = 0;
   int dmin = 256 * 256 * 256;
   int len = colorTab.length;
   for (int i = 0; i < len; ) {
     int dr = r - (colorTab[i++] & 0xff);
     int dg = g - (colorTab[i++] & 0xff);
     int db = b - (colorTab[i] & 0xff);
     int d = dr * dr + dg * dg + db * db;
     int index = i / 3;
     if (usedEntry[index] && (d < dmin)) {
       dmin = d;
       minpos = index;
     }
     i++;
   }
   return minpos;
 }
Exemple #20
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);
 }
 /**
  * Send State (content on WhiteBoard) to all members of Group
  *
  * @param copy
  */
 protected void sendOwnState(final Map<Point, Color> copy) {
   if (copy == null) return;
   for (Point point : copy.keySet()) {
     // we don't need the color: it is our draw_color anyway
     DrawCommand comm = new DrawCommand(DrawCommand.DRAW, point.x, point.y, drawColor.getRGB());
     try {
       byte[] buf = Util.streamableToByteBuffer(comm);
       if (use_unicasts) sendToAll(buf);
       else channel.send(new Message(null, buf));
     } catch (Exception ex) {
       System.err.println(ex);
     }
   }
 }
Exemple #22
0
  /**
   * Esta funcion se usa para pintar la barra de seleccion de los menus. Esta aqui para no repetirla
   * en todas partes...
   */
  static void pintaBarraMenu(Graphics g, JMenuItem menuItem, Color bgColor) {
    ButtonModel model = menuItem.getModel();
    Color oldColor = g.getColor();

    int menuWidth = menuItem.getWidth();
    int menuHeight = menuItem.getHeight();

    if (menuItem.isOpaque()) {
      g.setColor(menuItem.getBackground());
      g.fillRect(0, 0, menuWidth, menuHeight);
    }

    if ((menuItem instanceof JMenu && !(((JMenu) menuItem).isTopLevelMenu()) && model.isSelected())
        || model.isArmed()) {
      RoundRectangle2D.Float boton = new RoundRectangle2D.Float();
      boton.x = 1;
      boton.y = 0;
      boton.width = menuWidth - 3;
      boton.height = menuHeight - 1;
      boton.arcwidth = 8;
      boton.archeight = 8;

      GradientPaint grad = new GradientPaint(1, 1, getBrilloMenu(), 0, menuHeight, getSombraMenu());

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

      g.setColor(bgColor);
      g2D.fill(boton);

      g.setColor(bgColor.darker());
      g2D.draw(boton);

      g2D.setPaint(grad);
      g2D.fill(boton);

      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
    }

    g.setColor(oldColor);
  }
Exemple #23
0
 // convert color name in Java Color object
 public Color getColour(String name) {
   if (name.equals("red")) {
     return Color.red;
   } else if (name.equals("blue")) {
     return Color.blue;
   } else if (name.equals("black")) {
     return Color.black;
   } else if (name.equals("cyan")) {
     return Color.cyan;
   } else if (name.equals("dark gray")) {
     return Color.darkGray;
   } else if (name.equals("gray")) {
     return Color.gray;
   } else if (name.equals("light gray")) {
     return Color.lightGray;
   } else if (name.equals("green")) {
     return Color.gray;
   } else if (name.equals("magenta")) {
     return Color.magenta;
   } else if (name.equals("orange")) {
     return Color.orange;
   } else if (name.equals("pink")) {
     return Color.pink;
   } else if (name.equals("white")) {
     return Color.white;
   } else if (name.equals("yellow")) {
     return Color.yellow;
   }
   try {
     // see if the colour is expressed in
     // 0xAABBCC format for RGB...
     return Color.decode(name);
   } catch (NumberFormatException e) {
   }
   // no, ok bail then ... but this will certainly
   // through an exception
   return null;
 }
Exemple #24
0
 /**
  * Computes color from index in color table
  *
  * @param i index in color table
  * @return Color
  */
 public static Color index2color(int i) {
   if (i > 63 || i < 0) return Color.black;
   if (i >= 56)
     switch (i) {
       case 56:
         return Color.black;
       case 57:
         return Color.red;
       case 58:
         return Color.green;
       case 59:
         return Color.blue;
       case 60:
         return Color.yellow;
       case 61:
         return Color.magenta;
       case 62:
         return Color.cyan;
       case 63:
         return Color.white;
     }
   if (i >= 48) {
     int j = (int) ((i - 47) * 85 / 3.);
     return new Color(j, j, j);
   } else {
     float h, s, b;
     h = (i & 7) / 8.F;
     if (i >= 32) {
       b = 1;
       s = (2 - ((i & 8) >> 3)) / 4.F;
     } else {
       s = 1;
       b = (((i & 24) >> 3) + 1) / 4.F;
     }
     return Color.getHSBColor(h, s, b);
   }
 }
  @Override
  public MenuScreen getChangeScreenResolutionMenu() {
    return new MenuScreen(Color.V(0.75f)) {
      public DisplayMode[] modes;
      private int selectedMode;

      @Override
      protected void drawBackground(final Matrix tform) {
        drawTextBackground("Change Screen Resolution", tform);
      }

      public void setSelectedMode(final int selectedMode) {
        this.selectedMode = selectedMode;
        try {
          Display.setDisplayMode(this.modes[this.selectedMode]);
          Display.setVSyncEnabled(Main.isVSyncEnabled);
        } catch (LWJGLException e) {
          StringWriter w = new StringWriter();
          PrintWriter pw = new PrintWriter(w, true);
          e.printStackTrace(pw);
          Main.alert("Can't change display mode", w.toString());
        }
      }

      public int getSelectedMode() {
        return this.selectedMode;
      }

      {
        try {
          this.modes = Display.getAvailableDisplayModes();
        } catch (LWJGLException e) {
          e.printStackTrace();
          System.exit(1);
        }
        this.selectedMode = -1;
        DisplayMode[] newModes = new DisplayMode[0];
        for (int i = 0; i < this.modes.length; i++) {
          boolean found = false;
          for (int j = 0; j < newModes.length; j++) {
            if (newModes[j].getWidth() == this.modes[i].getWidth()
                && newModes[j].getHeight() == this.modes[i].getHeight()) {
              found = true;
              int oldDist =
                  Math.abs(newModes[j].getBitsPerPixel() - 32)
                      + Math.abs(newModes[j].getFrequency() - 60);
              int newDist =
                  Math.abs(this.modes[i].getBitsPerPixel() - 32)
                      + Math.abs(this.modes[i].getFrequency() - 60);
              if (newDist <= oldDist) newModes[j] = this.modes[i];
            }
          }
          if (!found) {
            DisplayMode[] temp = new DisplayMode[newModes.length + 1];
            for (int j = 0; j < newModes.length; j++) temp[j] = newModes[j];
            temp[newModes.length] = this.modes[i];
            newModes = temp;
          }
        }
        this.modes = newModes;
        for (int i = 0; i < this.modes.length; i++) {
          if (this.modes[i].getWidth() == Display.getDisplayMode().getWidth()
              && this.modes[i].getHeight() == Display.getDisplayMode().getHeight())
            this.selectedMode = i;
          final int index = i;
          add(
              new OptionMenuItem(
                  Integer.toString(this.modes[i].getWidth())
                      + "x"
                      + Integer.toString(this.modes[i].getHeight()),
                  Color.RGB(0f, 0f, 0f),
                  getBackgroundColor(),
                  Color.RGB(0f, 0f, 0f),
                  Color.RGB(0.0f, 0.0f, 1.0f),
                  this) {
                @Override
                public void pick() {
                  setSelectedMode(index);
                }

                @Override
                public boolean isPicked() {
                  return index == getSelectedMode();
                }
              });
        }
        add(new SpacerMenuItem(Color.V(0), this));
        add(
            new TextMenuItem(
                "OK",
                Color.RGB(0f, 0f, 0f),
                getBackgroundColor(),
                Color.RGB(0f, 0f, 0f),
                Color.RGB(0.0f, 0.0f, 1.0f),
                this) {
              @Override
              public void onMouseOver(final float mouseX, final float mouseY) {
                select();
              }

              @Override
              public void onClick(final float mouseX, final float mouseY) {
                this.container.close();
              }
            });
      }
    };
  }
Exemple #26
0
 /**
  * Returns the red value of the image at the given coordinates.
  *
  * <p>The coordinates should be non-negative and less than the width (x) or height (y) of the
  * image. The red value is returned as an integer in the range [0,255].
  *
  * @param x the horizontal coordinate of the pixel
  * @param y the vertical coordinate of the pixel
  * @return the red value at the given coordinates
  */
 public int getRed(int x, int y) {
   // works!
   Color c = new Color(img.getRGB(x, y));
   return c.getRed(); // (img.getRGB(x, y) & 0x00ff0000) >> 16;
 }
  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");
  }
Exemple #28
0
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (value == null) return null;

    RenderableObject mol_image = (RenderableObject) value;

    Indigo indigo = mol_image.getIndigo();
    IndigoRenderer indigo_renderer = mol_image.getIndigoRenderer();

    // To avoid parallel rendering (maybe will be fixed)
    synchronized (indigo) {
      indigo.setOption("render-output-format", "png");

      if (mol_image == null) return null;

      IndigoObject indigo_obj = mol_image.getRenderableObject();

      int cell_h = table.getRowHeight(row);
      int cell_w = table.getColumnModel().getColumn(column).getWidth();

      if (isSelected) bg_color = table.getSelectionBackground();
      else bg_color = table.getBackground();

      float[] c = bg_color.getComponents(null);
      indigo.setOption("render-background-color", c[0], c[1], c[2]);

      if (indigo_obj == null) {
        image = new BufferedImage(cell_w, cell_h, BufferedImage.TYPE_INT_RGB);
        Graphics2D gc = image.createGraphics();
        gc.setColor(bg_color);
        gc.fillRect(0, 0, cell_w, cell_h);
        gc.setColor(Color.black);
        gc.drawString("Cannot render", 40, (int) (cell_h / 2));
        gc.drawImage(_exclamation_img.getImage(), 5, 10, null);
      } else {
        indigo.setOption("render-image-size", cell_w, cell_h);
        byte[] bytes = null;

        try {
          bytes = indigo_renderer.renderToBuffer(indigo_obj);

          // System.out.print("Render: " + call_count + "\n");
          call_count++;

          ByteArrayInputStream bytes_is = new ByteArrayInputStream(bytes, 0, bytes.length);
          image = ImageIO.read(new MemoryCacheImageInputStream(bytes_is));
        } catch (IOException ex) {
          System.err.println(">>>>" + ex.getMessage());
          ex.printStackTrace();
        }
        if (mol_image.getErrorMessageToRender() != null) {
          // Mark molecule somehow
          Graphics2D gc = image.createGraphics();
          gc.setColor(Color.red);
          gc.drawImage(_exclamation_img.getImage(), 5, 10, null);
          gc.drawString(
              mol_image.getErrorMessageToRender(),
              5 + _exclamation_img.getIconWidth() + 5,
              10 + _exclamation_img.getIconHeight() / 2);
        }
      }

      if (hasFocus) setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
      else setBorder(new EmptyBorder(1, 2, 1, 2));
      return this;
    }
  }
Exemple #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));
 }
Exemple #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));
 }