示例#1
0
 @Override
 public int getIconHeight(SynthContext context) {
   if (context == null) {
     return height;
   }
   JComponent c = context.getComponent();
   if (c instanceof JToolBar) {
     JToolBar toolbar = (JToolBar) c;
     if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
       // 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) {
         return c.getHeight() - 1;
       } else {
         return c.getHeight();
       }
     } else {
       return scale(context, width);
     }
   } else {
     return scale(context, height);
   }
 }
示例#2
0
 /**
  * Package private method which returns either BorderLayout.NORTH, BorderLayout.SOUTH,
  * BorderLayout.EAST, or BorderLayout.WEST depending on the location of the toolbar in its parent.
  * The toolbar might be in PAGE_START, PAGE_END, CENTER, or some other position, but will be
  * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar actually IS, with
  * CENTER being NORTH.
  *
  * <p>This code is used to determine where the border line should be drawn by the custom toolbar
  * states, and also used by NimbusIcon to determine whether the handle icon needs to be shifted to
  * look correct.
  *
  * <p>Toollbars are unfortunately odd in the way these things are handled, and so this code exists
  * to unify the logic related to toolbars so it can be shared among the static files such as
  * NimbusIcon and generated files such as the ToolBar state classes.
  */
 static Object resolveToolbarConstraint(JToolBar toolbar) {
   // NOTE: we don't worry about component orientation or PAGE_END etc
   // because the BasicToolBarUI always uses an absolute position of
   // NORTH/SOUTH/EAST/WEST.
   if (toolbar != null) {
     Container parent = toolbar.getParent();
     if (parent != null) {
       LayoutManager m = parent.getLayout();
       if (m instanceof BorderLayout) {
         BorderLayout b = (BorderLayout) m;
         Object con = b.getConstraints(toolbar);
         if (con == SOUTH || con == EAST || con == WEST) {
           return con;
         }
         return NORTH;
       }
     }
   }
   return NORTH;
 }
示例#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;
      }
    }
  }