예제 #1
0
 public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(Color.white);
   g.fillRect(0, 0, c.getWidth(), c.getHeight());
   if (getImageObserver() == null) {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         c);
   } else {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         getImageObserver());
   }
 }
예제 #2
0
 public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) {
   if (isVisible()) {
     g.drawImage(
         icon.getImage(),
         x,
         y,
         (int) (icon.getIconWidth() * scale),
         (int) (icon.getIconHeight() * scale),
         this);
   }
 }
예제 #3
0
  public void paint(Graphics g) {
    Dimension osize = getSize();

    if ((buffer == null)
        || (osize.height != buffer.getHeight(null))
        || (osize.width != buffer.getWidth(null))) {
      if (buffer != null) {
        buffer.flush();
      }
      buffer = createImage(osize.width, osize.height);
    }

    Graphics gc = buffer.getGraphics();

    drawAll(gc);
    g.drawImage(buffer, 0, 0, this);
    gc.dispose();
  }
예제 #4
0
  // ----------------------------------------------------------------
  // PAINT
  // recall that paint() is called the first time the window
  // needs to be drawn, or if something damages the window,
  // and in this case by RefreshScreenNow()
  public void paint(Graphics g) {
    super.paint(g); // first paint the panel normally

    // the following block of code is used
    // if this is the first time being drawn or if the window was resized
    // Otherwise we don't creat a new buffer
    Dimension d = getSize();

    if ((doubleBufferImage == null)
        || (d.width != doubleBufferImageSize.width)
        || (d.height
            != doubleBufferImageSize
                .height)) // if this is the first time being drawn or if the window was resized
    {
      doubleBufferImage = createImage(d.width, d.height);
      doubleBufferImageSize = d;
      if (doubleBufferGraphic != null) {
        doubleBufferGraphic.dispose();
      }
      doubleBufferGraphic = doubleBufferImage.getGraphics();
      doubleBufferGraphic.setFont(getFont());
    }

    doubleBufferGraphic.setColor(Color.white);
    doubleBufferGraphic.fillRect(0, 0, d.width, d.height);

    if ((fitToScreenAutomatically)
        || (screenIsEmpty)) { // if the user wants all the nodes on the screen, or if these are the
      // first nodes on the screen, fit all nodes to the visible area
      // FitToScreen();
      ;
    }

    // draw things on the screen before any nodes or edges appear
    MainClass.displayManager.PaintUnderScreen(doubleBufferGraphic);

    // draw all the nodes
    DisplayManager.NodeInfo nodeDisplayInfo;
    int xCoord, yCoord, imageWidth, imageHeight;
    for (Enumeration nodes = MainClass.displayManager.GetNodeInfo(); nodes.hasMoreElements(); ) {
      nodeDisplayInfo = (DisplayManager.NodeInfo) nodes.nextElement();
      // figure out where to put the node on the screen
      xCoord =
          ScaleNodeXCoordToScreenCoord(
              MainClass.locationAnalyzer.GetX(nodeDisplayInfo.GetNodeNumber()));
      yCoord =
          ScaleNodeYCoordToScreenCoord(
              MainClass.locationAnalyzer.GetY(nodeDisplayInfo.GetNodeNumber()));
      // if that spot is not on the visible area, don't draw it at all
      if ((xCoord > this.getSize().getWidth()) || (yCoord > this.getSize().getHeight())) {
        continue;
      }

      // MDW: Don't scale size of dots
      // imageWidth = (int)Math.max(20,xScale*nodeDisplayInfo.GetImageWidth()/100);
      // imageHeight = (int)Math.max(20,yScale*nodeDisplayInfo.GetImageHeight()/100);
      imageWidth = imageHeight = 20;
      MainClass.displayManager.PaintAllNodes(
          nodeDisplayInfo.GetNodeNumber(),
          xCoord - imageWidth / 2,
          yCoord - imageHeight / 2,
          xCoord + imageWidth / 2,
          yCoord + imageHeight / 2,
          doubleBufferGraphic);
    }

    // draw all the edges
    DisplayManager.EdgeInfo edgeDisplayInfo;
    for (Enumeration edges = MainClass.displayManager.GetEdgeInfo(); edges.hasMoreElements(); ) {
      edgeDisplayInfo = (DisplayManager.EdgeInfo) edges.nextElement();
      // figure out the coordinates of the endpoints of the edge
      int x1 =
          ScaleNodeXCoordToScreenCoord(
              MainClass.locationAnalyzer.GetX(edgeDisplayInfo.GetSourceNodeNumber()));
      int y1 =
          ScaleNodeYCoordToScreenCoord(
              MainClass.locationAnalyzer.GetY(edgeDisplayInfo.GetSourceNodeNumber()));
      int x2 =
          ScaleNodeXCoordToScreenCoord(
              MainClass.locationAnalyzer.GetX(edgeDisplayInfo.GetDestinationNodeNumber()));
      int y2 =
          ScaleNodeYCoordToScreenCoord(
              MainClass.locationAnalyzer.GetY(edgeDisplayInfo.GetDestinationNodeNumber()));

      //		edgeDisplayInfo.paint(doubleBufferGraphic);
      MainClass.displayManager.PaintAllEdges(
          edgeDisplayInfo.GetSourceNodeNumber(),
          edgeDisplayInfo.GetDestinationNodeNumber(),
          x1,
          y1,
          x2,
          y2,
          doubleBufferGraphic);
    }

    // draw things over the entire display
    MainClass.displayManager.PaintOverScreen(doubleBufferGraphic);

    // Make everything that was drawn visible
    g.drawImage(doubleBufferImage, 0, 0, null);
  }