Ejemplo n.º 1
0
    public Component getPlacerRendererComponent(
        Placer placer, Object value, boolean selected, boolean focused, int index) {
      this.placer = placer;
      this.index = index;
      this.selected = selected;
      if (selected) {
        setForeground(placer.getSelectionForeground());
        setBackground(placer.getSelectionBackground());
      } else {
        setForeground(placer.getSelectionBackground());
        setBackground(placer.getSelectionForeground());
      }

      return this;
    }
Ejemplo n.º 2
0
    public void paintComponent(Graphics g) {
      super.paintComponent(g);
      if (placer != null && index >= 0) {
        Dimension dim = placer.getModel().getSizeOf(index);

        ImageIcon icon, scaled_icon;

        // XXX: Come up with a cleaner way to do this.
        if (((ConfigElement) placer.getModel().getElement(index))
            .getDefinition()
            .getToken()
            .equals(SURFACE_VIEWPORT_TYPE)) {
          icon = surfaceIcon;
          scaled_icon = scaledSurfaceIcon;
        } else {
          icon = simIcon;
          scaled_icon = scaledSimIcon;
        }

        // Check if we need to update the scaled image
        Image img = scaled_icon.getImage();
        if ((scaled_icon.getIconWidth() != dim.width)
            || (scaled_icon.getIconHeight() != dim.height)) {
          img = icon.getImage().getScaledInstance(dim.width, dim.height, Image.SCALE_DEFAULT);
          scaled_icon.setImage(img);
        }

        // Sanity check in case our scale failed
        if (img != null) {
          g.drawImage(img, 0, 0, null);
        }

        // Highlight the window nicely
        if (selected) {
          g.setColor(getBackground());
        } else {
          g.setColor(Color.white);
        }

        g.drawRect(0, 0, dim.width - 1, dim.height - 1);
        g.fillRect(0, 0, dim.width, 3);
      }
    }