示例#1
0
    @Override
    public int getColor(VisualItem item) {

      // highlight border of glyphs for which search is true
      // TODO: thicker borders? more outstanding highlighting?
      // do (inefficient) manual comparison (for now)
      Iterator itemsInGroup = m_vis.getGroup(Visualization.SEARCH_ITEMS).tuples();
      while (itemsInGroup.hasNext()) {
        Tuple itemInGroup = (Tuple) itemsInGroup.next();
        if (item.getString(DocumentGridTable.NODE_NAME)
            .equals(itemInGroup.getString(DocumentGridTable.NODE_NAME))) {
          // debug
          //                    System.out.println("debug: "+this.getClass().getName()+": item in
          // group! "+item.toString());
          return ColorLib.rgb(191, 99, 130);
        }
      }

      if (item.isHover()) {
        return Color.LIGHT_GRAY.getRGB();
      }

      // default border color
      //            return ColorLib.gray(50);
      return Color.DARK_GRAY.getRGB();
    }
/**
 * Class to store mouse start location when dragging, and to deselect any selected components when
 * the mouse is pressed
 *
 * @author Alex Billingsley
 */
public class MseSelectListener extends MouseAdapter {

  private Point xy1;
  public static final Color DESELECT = new Color(Color.WHITE.getRGB());
  public static final Color SELECT = new Color(Color.LIGHT_GRAY.getRGB());

  /** Creates a new instance of MouseSelectionListener */
  public MseSelectListener() {}

  public void mousePressed(MouseEvent e) {
    xy1 = new Point(e.getX(), e.getY());
    JPanel layer = (JPanel) e.getComponent();
    deSelect(layer);
  }

  public static void deSelect(JPanel layer) {

    Component[] components = layer.getComponents();
    int i = 0;
    while (i < components.length) {

      if (components[i].getClass().getName().equals("javax.swing.JLabel")) {
        if (components[i].getBackground().equals(SELECT)) {
          JLabel temp = (JLabel) components[i];
          temp.setOpaque(false);
          components[i].setBackground(DESELECT);
        }
      }

      if (components[i].getClass().getName().equals("Display.TextBox")) {
        if (components[i].getBackground().equals(SELECT)) {
          components[i].setBackground(DESELECT);
        }
      }

      // If panel is selected, de-select all components nested on panel
      if (components[i].getClass().getName().equals("javax.swing.JPanel")) {
        if (components[i].getBackground().equals(SELECT)) {
          components[i].setBackground(DESELECT);
        }
        deSelect((JPanel) components[i]);
      }

      i++;
    }
  }

  /**
   * Getter for property xy1.
   *
   * @return Value of property xy1.
   */
  public Point getXy1() {
    return this.xy1;
  }
}
 private static BufferedImage createAlphaBackground(int width, int height) {
   BufferedImage background = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
   DataBufferInt dataBuffer = (DataBufferInt) background.getRaster().getDataBuffer();
   int[] data = dataBuffer.getData();
   int gray = Color.LIGHT_GRAY.getRGB();
   int white = Color.WHITE.getRGB();
   for (int i = 0; i < data.length; i++) {
     int x = i % width;
     int y = i / width;
     data[i] = ((x / 4) % 2 == (y / 4) % 2) ? gray : white;
   }
   return background;
 }