Ejemplo n.º 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();
    }
Ejemplo n.º 2
0
/** Created by Mostafa Shabani. Date: 4/30/11 Time: 5:51 PM */
public class MrlBurningBuildingLayer extends MrlAreaLayer<Building> {

  //    private static final Color HEATING = new Color(176, 176, 56, 128);
  //    private static final Color BURNING = new Color(204, 122, 50, 128);
  //    private static final Color INFERNO = new Color(160, 52, 52, 128);
  //    private static final Color WATER_DAMAGE = new Color(50, 120, 130, 128);
  //    private static final Color MINOR_DAMAGE = new Color(100, 140, 210, 128);
  //    private static final Color MODERATE_DAMAGE = new Color(100, 70, 190, 128);
  //    private static final Color SEVERE_DAMAGE = new Color(80, 60, 140, 128);
  //    private static final Color BURNT_OUT = new Color(0, 0, 0, 255);

  private static final Color OUTLINE_COLOUR = Color.GRAY.darker().darker();

  private static final Color HEATING_COLOUR = Color.YELLOW; // 1
  private static final Color BURNING_COLOUR = Color.ORANGE; // 2
  private static final Color INFERNO_COLOUR = Color.RED; // 3
  private static final Color WATER_DAMAGE_COLOUR = Color.BLUE; // 4
  private static final Color MINOR_DAMAGE_COLOUR = new Color(10, 140, 210, 255); // Color.PINK; //5
  private static final Color MODERATE_DAMAGE_COLOUR =
      new Color(10, 70, 190, 255); // Color.MAGENTA; //6
  private static final Color SEVERE_DAMAGE_COLOUR = new Color(1, 50, 140, 255); // Color.CYAN;  //7
  private static final Color BURNT_OUT_COLOUR = Color.DARK_GRAY.darker(); // 8
  private static final Color PROB = Color.PINK;

  //    private static final Color REFUGE_BUILDING_COLOR = Color.GREEN.darker();
  //    private static final Color CENTER_BUILDING_COLOR = Color.WHITE.brighter().brighter();
  //
  //    private static final Color BURNING_REFUGE_COLOR = Color.RED.darker().darker();
  private static final Stroke WALL_STROKE =
      new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
  private static final Stroke ENTRANCE_STROKE =
      new BasicStroke(0.2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
  //    public static Map<EntityID, Collection<StandardEntity>> BURNING_BUILDINGS_MAP = new
  // FastMap<EntityID, Collection<StandardEntity>>();
  public static Map<EntityID, List<MrlBuilding>> BURNING_BUILDINGS_MAP =
      Collections.synchronizedMap(new FastMap<EntityID, List<MrlBuilding>>());
  public static Set<EntityID> BURNING_BUILDINGS = new FastSet<EntityID>();

  /** Construct a building view layer. */
  public MrlBurningBuildingLayer() {
    super(Building.class);
  }

  @Override
  public String getName() {
    return "Burning Buildings";
  }

  @Override
  protected void paintEdge(Edge e, Graphics2D g, ScreenTransform t) {
    g.setColor(OUTLINE_COLOUR);
    g.setStroke(e.isPassable() ? ENTRANCE_STROKE : WALL_STROKE);
    g.drawLine(
        t.xToScreen(e.getStartX()),
        t.yToScreen(e.getStartY()),
        t.xToScreen(e.getEndX()),
        t.yToScreen(e.getEndY()));
  }

  @Override
  protected void paintShape(Building b, Polygon shape, Graphics2D g) {
    if (StaticViewProperties.selectedObject != null) {

      BURNING_BUILDINGS.clear();
      List<MrlBuilding> buildings = null;
      try {
        buildings =
            Collections.synchronizedList(
                BURNING_BUILDINGS_MAP.get(StaticViewProperties.selectedObject.getID()));
      } catch (NullPointerException ignored) {
      }

      if (buildings != null) {
        showRealFieriness = true;
        for (MrlBuilding bb : buildings) {
          //                    if (bb.getEstimatedFieryness() > 0 &&
          // b.equals(bb.getSelfBuilding())) {
          if (bb.getSelfBuilding().isFierynessDefined()
              && bb.getSelfBuilding().getFieryness() > 0
              && b.equals(bb.getSelfBuilding())) {
            drawBurningBuildings(bb, shape, g);
            BURNING_BUILDINGS.add(bb.getSelfBuilding().getID());

            return;
          }
          //                    else if (bb.isProbablyOnFire() && b.equals(bb.getSelfBuilding())) {
          //                        g.setColor(PROB);
          //                        g.fill(shape);
          //                        return;
          //                    }
        }
      } else {
        showRealFieriness = false;
      }
    }
  }

  private void drawBurningBuildings(MrlBuilding b, Shape shape, Graphics2D g) {
    //        switch (b.getEstimatedFieryness()) {
    switch (b.getSelfBuilding().getFieryness()) {
      case 1:
        g.setColor(HEATING_COLOUR);
        break;
      case 2:
        g.setColor(BURNING_COLOUR);
        break;
      case 3:
        g.setColor(INFERNO_COLOUR);
        break;
      case 4:
        g.setColor(WATER_DAMAGE_COLOUR);
        break;
      case 5:
        g.setColor(MINOR_DAMAGE_COLOUR);
        break;
      case 6:
        g.setColor(MODERATE_DAMAGE_COLOUR);
        break;
      case 7:
        g.setColor(SEVERE_DAMAGE_COLOUR);
        break;
      case 8:
        g.setColor(BURNT_OUT_COLOUR);
        break;
    }
    g.fill(shape);
  }

  //    private void drawFieriness(Building b, Polygon shape, Graphics2D g) {
  //        StandardEntityToPaint entityToPaint = StaticViewProperties.getPaintObject(b);
  //        if (entityToPaint != null) {
  //            g.setColor(entityToPaint.getColor());
  //            g.fill(shape);
  //            return;
  //        }
  //        if (b instanceof Refuge) {
  //            g.setColor(REFUGE_BUILDING_COLOR);
  //            if (b.isFierynessDefined() && b.getFieryness() > 0) {
  //                g.setColor(BURNING_REFUGE_COLOR);
  //            }
  //            g.fill(shape);
  //        } else if ((b instanceof AmbulanceCentre) || (b instanceof FireStation) || (b instanceof
  // PoliceOffice)) {
  //            g.setColor(CENTER_BUILDING_COLOR);
  //            if (b.isFierynessDefined() && b.getFieryness() > 0) {
  //                g.setColor(BURNING_REFUGE_COLOR);
  //            }
  //            g.fill(shape);
  //        }
  //        if (!b.isFierynessDefined()) {
  //            return;
  //        }
  //        switch (b.getFierynessEnum()) {
  //            case UNBURNT:
  //                return;
  //            case HEATING:
  //                g.setColor(HEATING);
  //                break;
  //            case BURNING:
  //                g.setColor(BURNING);
  //                break;
  //            case INFERNO:
  //                g.setColor(INFERNO);
  //                break;
  //            case WATER_DAMAGE:
  //                g.setColor(WATER_DAMAGE);
  //                break;
  //            case MINOR_DAMAGE:
  //                g.setColor(MINOR_DAMAGE);
  //                break;
  //            case MODERATE_DAMAGE:
  //                g.setColor(MODERATE_DAMAGE);
  //                break;
  //            case SEVERE_DAMAGE:
  //                g.setColor(SEVERE_DAMAGE);
  //                break;
  //            case BURNT_OUT:
  //                g.setColor(BURNT_OUT);
  //                break;
  //            default:
  //                throw new IllegalArgumentException("Don't know how to render fieriness " +
  // b.getFierynessEnum());
  //        }
  //        g.fill(shape);
  //    }
  //
  //    private void drawBrokenness(Building b, Shape shape, Graphics2D g) {
  //        int brokenness = b.getBrokenness();
  //        // CHECK STYLE:OFF:MagicNumber
  //        int colour = Math.max(0, 135 - brokenness / 2);
  //        // CHECK STYLE:ON:MagicNumber
  //        g.setColor(new Color(colour, colour, colour));
  //        g.fill(shape);
  //    }

  @Override
  public void initialise(Config config) {}
}
Ejemplo n.º 3
0
  /*
   * This method renders the screen, returning an array of the pixels to be displayed to the user
   *
   */
  public int[] update(Camera camera, int[] pixels) {
    for (int i = 0; i < pixels.length / 2; i++) { // Background colouring
      if (pixels[i] != Color.DARK_GRAY.getRGB()) {
        pixels[i] = Color.DARK_GRAY.getRGB();
      }
    }
    for (int j = pixels.length / 2; j < pixels.length; j++) { // background colouring
      if (pixels[j] != Color.gray.getRGB()) {
        pixels[j] = Color.gray.getRGB();
      }
    }

    for (int x = 0; x < width; x = x + 1) { // for every column in the screen
      double cameraX = 2 * x / (double) (width) - 1; // rendering position
      double rayDirX = camera.xDir + camera.xPlane * cameraX; // direction of ray vector
      double rayDirY = camera.yDir + camera.yPlane * cameraX; // direction of ray vector

      int mapX = (int) camera.xPos; // X-coordinate location on the map
      int mapY = (int) camera.yPos; // Y-coordinate location on the map
      // length of ray from current position of camera  to next side
      double distToSideX;
      double distToSideY;
      // Length of ray from edge to edge
      double deltaDistX = Math.sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX));
      double deltaDistY = Math.sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY));
      double perpWallDist;
      // Direction
      int stepX, stepY;
      int lineHeight;
      boolean collision = false; // collision flag
      int side = 0; // Wall orientation
      // Calculate step direction and distance to side of wall
      if (rayDirX < 0) {
        stepX = -1;
        distToSideX = (camera.xPos - mapX) * deltaDistX;
      } else {
        stepX = 1;
        distToSideX = (mapX + 1.0 - camera.xPos) * deltaDistX;
      }
      if (rayDirY < 0) {
        stepY = -1;
        distToSideY = (camera.yPos - mapY) * deltaDistY;
      } else {
        stepY = 1;
        distToSideY = (mapY + 1.0 - camera.yPos) * deltaDistY;
      }
      // Loop to find where the ray collisions a wall
      while (!collision) {
        // Jump to next square
        if (distToSideX < distToSideY) {
          distToSideX += deltaDistX;
          mapX += stepX;
          side = 0;
        } else {
          distToSideY += deltaDistY;
          mapY += stepY;
          side = 1;
        }
        // Check if ray has collision a wall
        if (map[mapX][mapY] > 0) collision = true;
      }
      // Calculate distance to the point of impact
      if (side == 0) perpWallDist = Math.abs((mapX - camera.xPos + (1 - stepX) / 2) / rayDirX);
      else perpWallDist = Math.abs((mapY - camera.yPos + (1 - stepY) / 2) / rayDirY);
      // Now calculate the height of the wall based on the distance from the camera
      if (perpWallDist > 0) lineHeight = Math.abs((int) (height / perpWallDist));
      else lineHeight = height;
      // calculate lowest and highest pixel to fill in current stripe
      int drawStart = -lineHeight / 2 + height / 2;
      if (drawStart < 0) drawStart = 0;
      int drawEnd = lineHeight / 2 + height / 2;
      if (drawEnd >= height) drawEnd = height - 1;
      // add a texture
      int texNum = map[mapX][mapY] - 1;
      double wallLocX; // position of collision with wall
      if (side == 1) { // Is the wall on the Y axis?
        wallLocX = (camera.xPos + ((mapY - camera.yPos + (1 - stepY) / 2) / rayDirY) * rayDirX);
      } else { // Is the wall on the X axis?
        wallLocX = (camera.yPos + ((mapX - camera.xPos + (1 - stepX) / 2) / rayDirX) * rayDirY);
      }
      wallLocX -= Math.floor(wallLocX);
      // X-coordinate on the texture
      int texX = (int) (wallLocX * (textures.get(texNum).SIZE));
      if (side == 0 && rayDirX > 0) texX = textures.get(texNum).SIZE - texX - 1;
      if (side == 1 && rayDirY < 0) texX = textures.get(texNum).SIZE - texX - 1;
      // calculate Y-coordinate on texture
      for (int y = drawStart; y < drawEnd; y++) {
        int texY = (((y * 2 - height + lineHeight) << 6) / lineHeight) / 2;
        int color;
        if (side == 0)
          color = textures.get(texNum).pixels[texX + (texY * textures.get(texNum).SIZE)];
        else
          color =
              (textures.get(texNum).pixels[texX + (texY * textures.get(texNum).SIZE)] >> 1)
                  & 8355711; // Make y sides darker
        pixels[x + y * (width)] = color;
      }
    }
    return pixels; // return the pixels to be rendered
  }
Ejemplo n.º 4
0
/**
 * A custom JButton that contains only text. A custom background could be set, which will result in
 * a round cornered background behind the text. Note that you can also set a semi-transparent
 * background. The button also supports a rollover effect.
 *
 * @author Yana Stamcheva
 */
public class SIPCommTextButton extends JButton {
  /** Serial version UID. */
  private static final long serialVersionUID = 0L;

  /** Class id key used in UIDefaults. */
  private static final String UIClassID = "BasicButtonUI";

  /** Adds the ui class to UIDefaults. */
  static {
    UIManager.getDefaults().put(UIClassID, BasicButtonUI.class.getName());
  }

  private final float[] borderColor = Color.DARK_GRAY.getRGBComponents(null);

  private Image bgImage;

  /** Creates a <tt>SIPCommTextButton</tt>. */
  public SIPCommTextButton() {
    this("", null);
  }

  /**
   * Creates a <tt>SIPCommTextButton</tt>
   *
   * @param text the text of the button
   */
  public SIPCommTextButton(String text) {
    this(text, null);
  }

  public SIPCommTextButton(String text, Image bgImage) {
    super(text);

    this.bgImage = bgImage;

    MouseRolloverHandler mouseHandler = new MouseRolloverHandler();

    this.addMouseListener(mouseHandler);
    this.addMouseMotionListener(mouseHandler);

    this.setIcon(null);
    this.setIconTextGap(0);

    /*
     * Explicitly remove all borders that may be set from the current look
     * and feel.
     */
    this.setContentAreaFilled(false);
  }

  public void setBgImage(Image image) {
    this.bgImage = image;
  }

  /**
   * Return the background image.
   *
   * @return the background image of this button
   */
  public Image getBgImage() {
    return bgImage;
  }

  /**
   * Overrides the <code>paintComponent</code> method of <tt>JButton</tt> to paint the button
   * background and icon, and all additional effects of this configurable button.
   *
   * @param g The Graphics object.
   */
  @Override
  protected void paintComponent(Graphics g) {
    Graphics2D g1 = (Graphics2D) g.create();
    try {
      internalPaintComponent(g1);
    } finally {
      g1.dispose();
    }

    super.paintComponent(g);
  }

  /**
   * Paints this button.
   *
   * @param g the <tt>Graphics</tt> object used for painting
   */
  private void internalPaintComponent(Graphics2D g) {
    AntialiasingManager.activateAntialiasing(g);

    // Paint a roll over fade out.
    FadeTracker fadeTracker = FadeTracker.getInstance();

    float visibility = this.getModel().isRollover() ? 1.0f : 0.0f;
    if (fadeTracker.isTracked(this, FadeKind.ROLLOVER)) {
      visibility = fadeTracker.getFade(this, FadeKind.ROLLOVER);
    }

    visibility /= 2;

    if (visibility != 0.0f) {
      g.setColor(new Color(borderColor[0], borderColor[1], borderColor[2], visibility));

      if (bgImage != null)
        g.fillRoundRect(
            (this.getWidth() - bgImage.getWidth(null)) / 2,
            (this.getHeight() - bgImage.getHeight(null)) / 2,
            bgImage.getWidth(null) - 1,
            bgImage.getHeight(null) - 1,
            20,
            20);
      else g.fillRoundRect(0, 0, this.getWidth() - 1, this.getHeight() - 1, 20, 20);
    }

    if (bgImage != null) {
      g.drawImage(
          bgImage,
          (this.getWidth() - bgImage.getWidth(null)) / 2,
          (this.getHeight() - bgImage.getHeight(null)) / 2,
          null);
    } else {
      g.setColor(getBackground());
      g.fillRoundRect(1, 1, this.getWidth() - 2, this.getHeight() - 2, 20, 20);
    }
  }

  /**
   * Returns the name of the L&F class that renders this component.
   *
   * @return the string "TreeUI"
   * @see JComponent#getUIClassID
   * @see UIDefaults#getUI
   */
  @Override
  public String getUIClassID() {
    return UIClassID;
  }

  /**
   * The <tt>ButtonRepaintCallback</tt> is charged to repaint this button when the fade animation is
   * performed.
   */
  private class ButtonRepaintCallback implements FadeTrackerCallback {
    public void fadeEnded(FadeKind arg0) {
      repaintLater();
    }

    public void fadePerformed(FadeKind arg0, float arg1) {
      repaintLater();
    }

    private void repaintLater() {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              SIPCommTextButton.this.repaint();
            }
          });
    }

    public void fadeReversed(FadeKind arg0, boolean arg1, float arg2) {}
  }

  /** Perform a fade animation on mouse over. */
  private class MouseRolloverHandler implements MouseListener, MouseMotionListener {
    public void mouseMoved(MouseEvent e) {}

    public void mouseExited(MouseEvent e) {
      if (isEnabled()) {
        getModel().setRollover(false);

        FadeTracker fadeTracker = FadeTracker.getInstance();

        fadeTracker.trackFadeOut(
            FadeKind.ROLLOVER, SIPCommTextButton.this, true, new ButtonRepaintCallback());
      }
    }

    public void mouseClicked(MouseEvent e) {}

    public void mouseEntered(MouseEvent e) {
      if (isEnabled()) {
        getModel().setRollover(true);

        FadeTracker fadeTracker = FadeTracker.getInstance();

        fadeTracker.trackFadeIn(
            FadeKind.ROLLOVER, SIPCommTextButton.this, true, new ButtonRepaintCallback());
      }
    }

    public void mousePressed(MouseEvent e) {}

    public void mouseReleased(MouseEvent e) {}

    public void mouseDragged(MouseEvent e) {}
  }
}