Exemplo n.º 1
0
 public void run(Component comp, Graphics cg) {
   if (!comp.isLightweight()) {
     comp.printAll(cg);
   } else if (comp instanceof Container) {
     runComponents(((Container) comp).getComponents(), cg, LIGHTWEIGHTS | HEAVYWEIGHTS);
   }
 }
Exemplo n.º 2
0
  @SuppressWarnings("deprecation")
  public final void runOneComponent(
      Component comp, Rectangle bounds, Graphics g, Shape clip, int weightFlags) {
    if (comp == null || comp.getPeer() == null || !comp.isVisible()) {
      return;
    }
    boolean lightweight = comp.isLightweight();
    if ((lightweight && (weightFlags & LIGHTWEIGHTS) == 0)
        || (!lightweight && (weightFlags & HEAVYWEIGHTS) == 0)) {
      return;
    }

    if (bounds == null) {
      bounds = comp.getBounds();
    }

    if (clip == null || clip.intersects(bounds)) {
      Graphics cg = g.create();
      try {
        constrainGraphics(cg, bounds);
        cg.setFont(comp.getFont());
        cg.setColor(comp.getForeground());
        if (cg instanceof Graphics2D) {
          ((Graphics2D) cg).setBackground(comp.getBackground());
        } else if (cg instanceof Graphics2Delegate) {
          ((Graphics2Delegate) cg).setBackground(comp.getBackground());
        }
        run(comp, cg);
      } finally {
        cg.dispose();
      }
    }
  }
Exemplo n.º 3
0
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   if (c.hasFocus()) {
     g.setColor(focus);
     g.drawRect(x, y, w - 1, h - 1);
   } else {
     g.setColor(control);
     g.drawRect(x, y, w - 1, h - 1);
   }
 }
Exemplo n.º 4
0
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
      Color color = c.getBackground();

      if (origColor != color) {
        origColor = color;
        paintColor = new Color(~origColor.getRGB());
      }

      g.setColor(paintColor);
      BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
    }
Exemplo n.º 5
0
 public Insets getBorderInsets(Component c, Insets insets) {
   insets.set(1, 1, 1, 1);
   if (!(c instanceof JToolBar)) {
     return insets;
   }
   if (((JToolBar) c).isFloatable()) {
     int gripInset = (XPStyle.getXP() != null) ? 12 : 9;
     if (((JToolBar) c).getOrientation() == HORIZONTAL) {
       if (c.getComponentOrientation().isLeftToRight()) {
         insets.left = gripInset;
       } else {
         insets.right = gripInset;
       }
     } else {
       insets.top = gripInset;
     }
   }
   return insets;
 }
Exemplo n.º 6
0
 private static boolean isEnabled(Component c, State state) {
   if (state == null && c instanceof JMenuItem) {
     WindowsMenuItemUIAccessor accessor = getAccessor((JMenuItem) c);
     if (accessor != null) {
       state = accessor.getState((JMenuItem) c);
     }
   }
   if (state == null) {
     if (c != null) {
       return c.isEnabled();
     } else {
       return true;
     }
   } else {
     return (state != State.DISABLED)
         && (state != State.DISABLEDHOT)
         && (state != State.DISABLEDPUSHED);
   }
 }
Exemplo n.º 7
0
    /**
     * Reinitialize the insets parameter with this Border's current Insets.
     *
     * @param c the component for which this border insets value applies
     * @param insets the object to be reinitialized
     */
    public Insets getBorderInsets(Component c, Insets insets) {
      if (!(c instanceof JPopupMenu)) {
        return insets;
      }
      FontMetrics fm;
      int descent = 0;
      int ascent = 16;

      String title = ((JPopupMenu) c).getLabel();
      if (title == null) {
        insets.left = insets.top = insets.right = insets.bottom = 0;
        return insets;
      }

      fm = c.getFontMetrics(font);

      if (fm != null) {
        descent = fm.getDescent();
        ascent = fm.getAscent();
      }

      insets.top += ascent + descent + TEXT_SPACING + GROOVE_HEIGHT;
      return insets;
    }
Exemplo n.º 8
0
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
      if (!(c instanceof JToolBar)) {
        return;
      }
      g.translate(x, y);

      XPStyle xp = XPStyle.getXP();
      if (xp != null) {
        Border xpBorder = xp.getBorder(c, Part.TP_TOOLBAR);
        if (xpBorder != null) {
          xpBorder.paintBorder(c, g, 0, 0, width, height);
        }
      }
      if (((JToolBar) c).isFloatable()) {
        boolean vertical = ((JToolBar) c).getOrientation() == VERTICAL;

        if (xp != null) {
          Part part = vertical ? Part.RP_GRIPPERVERT : Part.RP_GRIPPER;
          Skin skin = xp.getSkin(c, part);
          int dx, dy, dw, dh;
          if (vertical) {
            dx = 0;
            dy = 2;
            dw = width - 1;
            dh = skin.getHeight();
          } else {
            dw = skin.getWidth();
            dh = height - 1;
            dx = c.getComponentOrientation().isLeftToRight() ? 2 : (width - dw - 2);
            dy = 0;
          }
          skin.paintSkin(g, dx, dy, dw, dh, State.NORMAL);

        } else {

          if (!vertical) {
            if (c.getComponentOrientation().isLeftToRight()) {
              g.setColor(shadow);
              g.drawLine(4, 3, 4, height - 4);
              g.drawLine(4, height - 4, 2, height - 4);

              g.setColor(highlight);
              g.drawLine(2, 3, 3, 3);
              g.drawLine(2, 3, 2, height - 5);
            } else {
              g.setColor(shadow);
              g.drawLine(width - 3, 3, width - 3, height - 4);
              g.drawLine(width - 4, height - 4, width - 4, height - 4);

              g.setColor(highlight);
              g.drawLine(width - 5, 3, width - 4, 3);
              g.drawLine(width - 5, 3, width - 5, height - 5);
            }
          } else { // Vertical
            g.setColor(shadow);
            g.drawLine(3, 4, width - 4, 4);
            g.drawLine(width - 4, 2, width - 4, 4);

            g.setColor(highlight);
            g.drawLine(3, 2, width - 4, 2);
            g.drawLine(3, 2, 3, 3);
          }
        }
      }

      g.translate(-x, -y);
    }
Exemplo n.º 9
0
 /**
  * Fetches the font metrics associated with the component hosting this view.
  *
  * @return the metrics
  */
 protected FontMetrics getFontMetrics() {
   Component c = getContainer();
   return c.getFontMetrics(c.getFont());
 }
Exemplo n.º 10
0
 /*
  * Convenience function for determining ComponentOrientation.  Helps us
  * avoid having Munge directives throughout the code.
  */
 static boolean isLeftToRight(Component c) {
   return c.getComponentOrientation().isLeftToRight();
 }
Exemplo n.º 11
0
  public int compare(Component a, Component b) {
    if (a == b) {
      return 0;
    }

    // Row/Column algorithm only applies to siblings. If 'a' and 'b'
    // aren't siblings, then we need to find their most inferior
    // ancestors which share a parent. Compute the ancestory lists for
    // each Component and then search from the Window down until the
    // hierarchy branches.
    if (a.getParent() != b.getParent()) {
      LinkedList<Component> aAncestory = new LinkedList<Component>();

      for (; a != null; a = a.getParent()) {
        aAncestory.add(a);
        if (a instanceof Window) {
          break;
        }
      }
      if (a == null) {
        // 'a' is not part of a Window hierarchy. Can't cope.
        throw new ClassCastException();
      }

      LinkedList<Component> bAncestory = new LinkedList<Component>();

      for (; b != null; b = b.getParent()) {
        bAncestory.add(b);
        if (b instanceof Window) {
          break;
        }
      }
      if (b == null) {
        // 'b' is not part of a Window hierarchy. Can't cope.
        throw new ClassCastException();
      }

      for (ListIterator<Component> aIter = aAncestory.listIterator(aAncestory.size()),
              bIter = bAncestory.listIterator(bAncestory.size());
          ; ) {
        if (aIter.hasPrevious()) {
          a = aIter.previous();
        } else {
          // a is an ancestor of b
          return -1;
        }

        if (bIter.hasPrevious()) {
          b = bIter.previous();
        } else {
          // b is an ancestor of a
          return 1;
        }

        if (a != b) {
          break;
        }
      }
    }

    int ax = a.getX(), ay = a.getY(), bx = b.getX(), by = b.getY();

    int zOrder = a.getParent().getComponentZOrder(a) - b.getParent().getComponentZOrder(b);
    if (horizontal) {
      if (leftToRight) {

        // LT - Western Europe (optional for Japanese, Chinese, Korean)

        if (Math.abs(ay - by) < ROW_TOLERANCE) {
          return (ax < bx) ? -1 : ((ax > bx) ? 1 : zOrder);
        } else {
          return (ay < by) ? -1 : 1;
        }
      } else { // !leftToRight

        // RT - Middle East (Arabic, Hebrew)

        if (Math.abs(ay - by) < ROW_TOLERANCE) {
          return (ax > bx) ? -1 : ((ax < bx) ? 1 : zOrder);
        } else {
          return (ay < by) ? -1 : 1;
        }
      }
    } else { // !horizontal
      if (leftToRight) {

        // TL - Mongolian

        if (Math.abs(ax - bx) < ROW_TOLERANCE) {
          return (ay < by) ? -1 : ((ay > by) ? 1 : zOrder);
        } else {
          return (ax < bx) ? -1 : 1;
        }
      } else { // !leftToRight

        // TR - Japanese, Chinese, Korean

        if (Math.abs(ax - bx) < ROW_TOLERANCE) {
          return (ay < by) ? -1 : ((ay > by) ? 1 : zOrder);
        } else {
          return (ax > bx) ? -1 : 1;
        }
      }
    }
  }