예제 #1
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   if (WindowsMenuItemUI.isVistaPainting()) {
     XPStyle xp = XPStyle.getXP();
     State state = State.NORMAL;
     if (c instanceof JMenuItem) {
       state = ((JMenuItem) c).getModel().isEnabled() ? State.NORMAL : State.DISABLED;
     }
     Skin skin = xp.getSkin(c, Part.MP_POPUPSUBMENU);
     if (WindowsGraphicsUtils.isLeftToRight(c)) {
       skin.paintSkin(g, x, y, state);
     } else {
       Graphics2D g2d = (Graphics2D) g.create();
       g2d.translate(x + skin.getWidth(), y);
       g2d.scale(-1, 1);
       skin.paintSkin(g2d, 0, 0, state);
       g2d.dispose();
     }
   } else {
     g.translate(x, y);
     if (WindowsGraphicsUtils.isLeftToRight(c)) {
       g.drawLine(0, 0, 0, 7);
       g.drawLine(1, 1, 1, 6);
       g.drawLine(2, 2, 2, 5);
       g.drawLine(3, 3, 3, 4);
     } else {
       g.drawLine(4, 0, 4, 7);
       g.drawLine(3, 1, 3, 6);
       g.drawLine(2, 2, 2, 5);
       g.drawLine(1, 3, 1, 4);
     }
     g.translate(-x, -y);
   }
 }
예제 #2
0
 /**
  * Implements the standard Icon interface's paintIcon method as the standard synth stub passes
  * null for the context and this will cause us to not paint any thing, so we override here so that
  * we can paint the enabled state if no synth context is available
  */
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Painter painter = (Painter) UIManager.get(prefix + "[Enabled]." + key);
   if (painter != null) {
     JComponent jc = (c instanceof JComponent) ? (JComponent) c : null;
     Graphics2D gfx = (Graphics2D) g;
     gfx.translate(x, y);
     painter.paint(gfx, jc, width, height);
     gfx.translate(-x, -y);
   }
 }
예제 #3
0
  @Override
  public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) {
    Painter painter = null;
    if (context != null) {
      painter = (Painter) context.getStyle().get(context, key);
    }
    if (painter == null) {
      painter = (Painter) UIManager.get(prefix + "[Enabled]." + key);
    }

    if (painter != null && context != null) {
      JComponent c = context.getComponent();
      boolean rotate = false;
      boolean flip = false;
      // translatex and translatey are additional translations that
      // must occur on the graphics context when rendering a toolbar
      // icon
      int translatex = 0;
      int translatey = 0;
      if (c instanceof JToolBar) {
        JToolBar toolbar = (JToolBar) c;
        rotate = toolbar.getOrientation() == JToolBar.VERTICAL;
        flip = !toolbar.getComponentOrientation().isLeftToRight();
        Object o = NimbusLookAndFeel.resolveToolbarConstraint(toolbar);
        // we only do the +1 hack for UIResource borders, assuming
        // that the border is probably going to be our border
        if (toolbar.getBorder() instanceof UIResource) {
          if (o == BorderLayout.SOUTH) {
            translatey = 1;
          } else if (o == BorderLayout.EAST) {
            translatex = 1;
          }
        }
      } else if (c instanceof JMenu) {
        flip = !c.getComponentOrientation().isLeftToRight();
      }
      if (g instanceof Graphics2D) {
        Graphics2D gfx = (Graphics2D) g;
        gfx.translate(x, y);
        gfx.translate(translatex, translatey);
        if (rotate) {
          gfx.rotate(Math.toRadians(90));
          gfx.translate(0, -w);
          painter.paint(gfx, context.getComponent(), h, w);
          gfx.translate(0, w);
          gfx.rotate(Math.toRadians(-90));
        } else if (flip) {
          gfx.scale(-1, 1);
          gfx.translate(-w, 0);
          painter.paint(gfx, context.getComponent(), w, h);
          gfx.translate(w, 0);
          gfx.scale(-1, 1);
        } else {
          painter.paint(gfx, context.getComponent(), w, h);
        }
        gfx.translate(-translatex, -translatey);
        gfx.translate(-x, -y);
      } else {
        // use image if we are printing to a Java 1.1 PrintGraphics as
        // it is not a instance of Graphics2D
        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics2D gfx = img.createGraphics();
        if (rotate) {
          gfx.rotate(Math.toRadians(90));
          gfx.translate(0, -w);
          painter.paint(gfx, context.getComponent(), h, w);
        } else if (flip) {
          gfx.scale(-1, 1);
          gfx.translate(-w, 0);
          painter.paint(gfx, context.getComponent(), w, h);
        } else {
          painter.paint(gfx, context.getComponent(), w, h);
        }
        gfx.dispose();
        g.drawImage(img, x, y, null);
        img = null;
      }
    }
  }