Exemple #1
0
  private Insets getScrollBarInsets(SynthContext context, Insets insets) {
    int troughBorder = getClassSpecificIntValue(context, "trough-border", 1);
    insets.left = insets.right = insets.top = insets.bottom = troughBorder;

    JComponent c = context.getComponent();
    if (c.getParent() instanceof JScrollPane) {
      // This scrollbar is part of a scrollpane; use only the
      // "scrollbar-spacing" style property to determine the padding
      // between the scrollbar and its parent scrollpane.
      int spacing = getClassSpecificIntValue(WidgetType.SCROLL_PANE, "scrollbar-spacing", 3);
      if (((JScrollBar) c).getOrientation() == JScrollBar.HORIZONTAL) {
        insets.top += spacing;
      } else {
        if (c.getComponentOrientation().isLeftToRight()) {
          insets.left += spacing;
        } else {
          insets.right += spacing;
        }
      }
    } else {
      // This is a standalone scrollbar; leave enough room for the
      // focus line in addition to the trough border.
      if (c.isFocusable()) {
        int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1);
        int focusPad = getClassSpecificIntValue(context, "focus-padding", 1);
        int totalFocus = focusSize + focusPad;
        insets.left += totalFocus;
        insets.right += totalFocus;
        insets.top += totalFocus;
        insets.bottom += totalFocus;
      }
    }
    return insets;
  }
  /**
   * Returns the <code>GTKStyle</code> to use based on the <code>Region</code> id
   *
   * @param c this parameter isn't used, may be null.
   * @param id of the region to get the style.
   */
  public synchronized SynthStyle getStyle(JComponent c, Region id) {
    WidgetType wt = GTKNativeEngine.getWidgetType(c, id);

    Object key = null;
    if (id == Region.SCROLL_BAR) {
      // The style/insets of a scrollbar can depend on a number of
      // factors (see GTKStyle.getScrollBarInsets()) so use a
      // complex key here.
      if (c != null) {
        JScrollBar sb = (JScrollBar) c;
        boolean sp = (sb.getParent() instanceof JScrollPane);
        boolean horiz = (sb.getOrientation() == JScrollBar.HORIZONTAL);
        boolean ltr = sb.getComponentOrientation().isLeftToRight();
        boolean focusable = sb.isFocusable();
        key = new ComplexKey(wt, sp, horiz, ltr, focusable);
      }
    } else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) {
      // The style/insets of a checkbox or radiobutton can depend
      // on the component orientation, so use a complex key here.
      if (c != null) {
        boolean ltr = c.getComponentOrientation().isLeftToRight();
        key = new ComplexKey(wt, ltr);
      }
    } else if (id == Region.BUTTON) {
      // The style/insets of a button can depend on whether it is
      // default capable or in a toolbar, so use a complex key here.
      if (c != null) {
        JButton btn = (JButton) c;
        boolean toolButton = (btn.getParent() instanceof JToolBar);
        boolean defaultCapable = btn.isDefaultCapable();
        key = new ComplexKey(wt, toolButton, defaultCapable);
      }
    }
    if (key == null) {
      // Otherwise, just use the WidgetType as the key.
      key = wt;
    }

    GTKStyle result = stylesCache.get(key);
    if (result == null) {
      result = isNativeGtk ? new GTKNativeStyle(defaultFont, wt) : new GTKDefaultStyle(defaultFont);
      stylesCache.put(key, result);
    }

    return result;
  }
Exemple #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;
      }
    }
  }
  public static void main(String args[]) {
    JComponent ch = new JComponent() {};
    ch.getAccessibleContext();
    ch.isFocusTraversable();
    ch.setEnabled(false);
    ch.setEnabled(true);
    ch.requestFocus();
    ch.requestFocusInWindow();
    ch.getPreferredSize();
    ch.getMaximumSize();
    ch.getMinimumSize();
    ch.contains(1, 2);
    Component c1 = ch.add(new Component() {});
    Component c2 = ch.add(new Component() {});
    Component c3 = ch.add(new Component() {});
    Insets ins = ch.getInsets();
    ch.getAlignmentY();
    ch.getAlignmentX();
    ch.getGraphics();
    ch.setVisible(false);
    ch.setVisible(true);
    ch.setForeground(Color.red);
    ch.setBackground(Color.red);
    for (String font : Toolkit.getDefaultToolkit().getFontList()) {
      for (int j = 8; j < 17; j++) {
        Font f1 = new Font(font, Font.PLAIN, j);
        Font f2 = new Font(font, Font.BOLD, j);
        Font f3 = new Font(font, Font.ITALIC, j);
        Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);

        ch.setFont(f1);
        ch.setFont(f2);
        ch.setFont(f3);
        ch.setFont(f4);

        ch.getFontMetrics(f1);
        ch.getFontMetrics(f2);
        ch.getFontMetrics(f3);
        ch.getFontMetrics(f4);
      }
    }
    ch.enable();
    ch.disable();
    ch.reshape(10, 10, 10, 10);
    ch.getBounds(new Rectangle(1, 1, 1, 1));
    ch.getSize(new Dimension(1, 2));
    ch.getLocation(new Point(1, 2));
    ch.getX();
    ch.getY();
    ch.getWidth();
    ch.getHeight();
    ch.isOpaque();
    ch.isValidateRoot();
    ch.isOptimizedDrawingEnabled();
    ch.isDoubleBuffered();
    ch.getComponentCount();
    ch.countComponents();
    ch.getComponent(1);
    ch.getComponent(2);
    Component[] cs = ch.getComponents();
    ch.getLayout();
    ch.setLayout(new FlowLayout());
    ch.doLayout();
    ch.layout();
    ch.invalidate();
    ch.validate();
    ch.remove(0);
    ch.remove(c2);
    ch.removeAll();
    ch.preferredSize();
    ch.minimumSize();
    ch.getComponentAt(1, 2);
    ch.locate(1, 2);
    ch.getComponentAt(new Point(1, 2));
    ch.isFocusCycleRoot(new Container());
    ch.transferFocusBackward();
    ch.setName("goober");
    ch.getName();
    ch.getParent();
    ch.getGraphicsConfiguration();
    ch.getTreeLock();
    ch.getToolkit();
    ch.isValid();
    ch.isDisplayable();
    ch.isVisible();
    ch.isShowing();
    ch.isEnabled();
    ch.enable(false);
    ch.enable(true);
    ch.enableInputMethods(false);
    ch.enableInputMethods(true);
    ch.show();
    ch.show(false);
    ch.show(true);
    ch.hide();
    ch.getForeground();
    ch.isForegroundSet();
    ch.getBackground();
    ch.isBackgroundSet();
    ch.getFont();
    ch.isFontSet();
    Container c = new Container();
    c.add(ch);
    ch.getLocale();
    for (Locale locale : Locale.getAvailableLocales()) ch.setLocale(locale);

    ch.getColorModel();
    ch.getLocation();

    boolean exceptions = false;
    try {
      ch.getLocationOnScreen();
    } catch (IllegalComponentStateException e) {
      exceptions = true;
    }
    if (!exceptions)
      throw new RuntimeException("IllegalComponentStateException did not occur when expected");

    ch.location();
    ch.setLocation(1, 2);
    ch.move(1, 2);
    ch.setLocation(new Point(1, 2));
    ch.getSize();
    ch.size();
    ch.setSize(1, 32);
    ch.resize(1, 32);
    ch.setSize(new Dimension(1, 32));
    ch.resize(new Dimension(1, 32));
    ch.getBounds();
    ch.bounds();
    ch.setBounds(10, 10, 10, 10);
    ch.setBounds(new Rectangle(10, 10, 10, 10));
    ch.isLightweight();
    ch.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
    ch.getCursor();
    ch.isCursorSet();
    ch.inside(1, 2);
    ch.contains(new Point(1, 2));
    ch.isFocusable();
    ch.setFocusable(true);
    ch.setFocusable(false);
    ch.transferFocus();
    ch.getFocusCycleRootAncestor();
    ch.nextFocus();
    ch.transferFocusUpCycle();
    ch.hasFocus();
    ch.isFocusOwner();
    ch.toString();
    ch.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    ch.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    ch.setComponentOrientation(ComponentOrientation.UNKNOWN);
    ch.getComponentOrientation();
  }