aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.7/libjava/gnu/gcj/xlib/Colormap.java
blob: 538782e7e76cc99a1744a49adeb901276b3f0dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Copyright (C) 2000  Free Software Foundation

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

package gnu.gcj.xlib;

import gnu.gcj.RawData;

/**
 * An X11 color map resource.
 *
 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
 */
public final class Colormap extends XID
{
  Screen screen;
  
  public static final byte FLAG_SHARED = 1;
  public static final byte FLAG_NOT_SHARED = 2;
  
  public Colormap(Screen screen, int xid)
  {
    super(screen.getDisplay(), xid);
    this.screen = screen;
  }
  
  /**
   * Allocate color pixel.
   *
   * @param color The color to be allocated.  If allocation is
   * successful, this object will be modified to reflect the actual
   * color that was allocated.
   *
   * @return the pixel value of the allocated color.
   */
  public native long allocateColorPixel(XColor color);

  /**
   * Allocate a color consisting of the given RGB-triplet.
   *
   * @return a color object describing the allocated color.
   */
  public XColor allocateColor(int r, int g, int b)
  {
    XColor color = new XColor(r, g, b);
    allocateColorPixel(color);
    
    return color;
  }

  /**
   * Get an array of all colors that currently resides in shared (read
   * only) color-cells in this color map.
   */
  public native XColor[] getSharedColors();


  /**
   * Get all colors currently residing in this color map.  Colors that
   * are shared (read only) are marked as such by the color flags.
   * The indexes of the returned array will correspond to the
   * colorcells of the color map.  Given a color <code>XColor
   * color</code> from a given color-cell, the expression
   * <code>color.getFlags() == Colormap.FLAG_SHARED</code> will check
   * whether the color-cell is shared.
   */
  public native XColor[] getXColors();

  /**
   * Convenience method used by native code to create fully
   * initialized arrays of XColor objects.
   */
  private XColor[] newXColorArray(int n)
  {
    XColor[] array = new XColor[n];
    for (int i=0; i<n; i++)
      array[i] = new XColor();
    return array;
  }
}