Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
    /**
     * Instructs the layout manager to perform the layout for the specified container.
     *
     * @param the Container for which this layout manager is being used
     */
    public void layoutContainer(Container parent) {
      JRootPane root = (JRootPane) parent;
      Rectangle b = root.getBounds();
      Insets i = root.getInsets();
      int nextY = 0;
      int w = b.width - i.right - i.left;
      int h = b.height - i.top - i.bottom;

      if (root.getLayeredPane() != null) {
        root.getLayeredPane().setBounds(i.left, i.top, w, h);
      }
      if (root.getGlassPane() != null) {
        root.getGlassPane().setBounds(i.left, i.top, w, h);
      }
      // Note: This is laying out the children in the layeredPane,
      // technically, these are not our children.
      if (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof RootPaneUI)) {
        JComponent titlePane = ((RootPaneUI) root.getUI()).getTitlePane();
        if (titlePane != null) {
          Dimension tpd = titlePane.getPreferredSize();
          if (tpd != null) {
            int tpHeight = tpd.height;
            titlePane.setBounds(0, 0, w, tpHeight);
            nextY += tpHeight;
          }
        }
      }

      if (root.getContentPane() != null) {

        root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY);
      }
    }
Ejemplo n.º 3
0
    /**
     * Returns the amount of space the layout would like to have.
     *
     * @param the Container for which this layout manager is being used
     * @return a Dimension object containing the layout's preferred size
     */
    public Dimension preferredLayoutSize(Container parent) {
      Dimension cpd, tpd;
      int cpWidth = 0;
      int cpHeight = 0;
      int mbWidth = 0;
      int mbHeight = 0;
      int tpWidth = 0;
      Insets i = parent.getInsets();
      JRootPane root = (JRootPane) parent;

      if (root.getContentPane() != null) {
        cpd = root.getContentPane().getPreferredSize();
      } else {
        cpd = root.getSize();
      }
      if (cpd != null) {
        cpWidth = cpd.width;
        cpHeight = cpd.height;
      }

      if (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof RootPaneUI)) {
        JComponent titlePane = ((RootPaneUI) root.getUI()).getTitlePane();
        if (titlePane != null) {
          tpd = titlePane.getPreferredSize();
          if (tpd != null) {
            tpWidth = tpd.width;
          }
        }
      }

      return new Dimension(
          Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
          cpHeight + mbHeight + tpWidth + i.top + i.bottom);
    }
Ejemplo n.º 4
0
    /**
     * Returns the maximum amount of space the layout can use.
     *
     * @param the Container for which this layout manager is being used
     * @return a Dimension object containing the layout's maximum size
     */
    public Dimension maximumLayoutSize(Container target) {
      Dimension cpd, mbd, tpd;
      int cpWidth = Integer.MAX_VALUE;
      int cpHeight = Integer.MAX_VALUE;
      int mbWidth = Integer.MAX_VALUE;
      int mbHeight = Integer.MAX_VALUE;
      int tpWidth = Integer.MAX_VALUE;
      int tpHeight = Integer.MAX_VALUE;
      Insets i = target.getInsets();
      JRootPane root = (JRootPane) target;

      if (root.getContentPane() != null) {
        cpd = root.getContentPane().getMaximumSize();
        if (cpd != null) {
          cpWidth = cpd.width;
          cpHeight = cpd.height;
        }
      }

      if (root.getMenuBar() != null) {
        mbd = root.getMenuBar().getMaximumSize();
        if (mbd != null) {
          mbWidth = mbd.width;
          mbHeight = mbd.height;
        }
      }

      if (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof HokageRootPaneUI)) {
        JComponent titlePane = ((HokageRootPaneUI) root.getUI()).getTitlePane();
        if (titlePane != null) {
          tpd = titlePane.getMaximumSize();
          if (tpd != null) {
            tpWidth = tpd.width;
            tpHeight = tpd.height;
          }
        }
      }

      int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
      // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE
      // Only will happen if sums to more than 2 billion units.  Not likely.
      if (maxHeight != Integer.MAX_VALUE) {
        maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
      }

      int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
      // Similar overflow comment as above
      if (maxWidth != Integer.MAX_VALUE) {
        maxWidth += i.left + i.right;
      }

      return new Dimension(maxWidth, maxHeight);
    }
Ejemplo n.º 5
0
  /**
   * Sets the window title pane -- the JComponent used to provide a plaf a way to override the
   * native operating system's window title pane with one whose look and feel are controlled by the
   * plaf. The plaf creates and sets this value; the default is null, implying a native operating
   * system window title pane.
   *
   * @param content the <code>JComponent</code> to use for the window title pane.
   */
  private void setTitlePane(JRootPane root, JComponent titlePane) {
    JLayeredPane layeredPane = root.getLayeredPane();
    JComponent oldTitlePane = getTitlePane();

    if (oldTitlePane != null) {
      oldTitlePane.setVisible(false);
      layeredPane.remove(oldTitlePane);
    }
    if (titlePane != null) {
      layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER);
      titlePane.setVisible(true);
    }
    this.titlePane = titlePane;
  }
Ejemplo n.º 6
0
  /**
   * Returns the color for the specified state.
   *
   * @param context SynthContext identifying requestor
   * @param state to get the color for
   * @param type of the color
   * @return Color to render with
   */
  Color getGTKColor(SynthContext context, int state, ColorType type) {
    if (context != null) {
      JComponent c = context.getComponent();
      Region id = context.getRegion();

      state = GTKLookAndFeel.synthStateToGTKState(id, state);
      if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) {
        if (type == ColorType.BACKGROUND || type == ColorType.TEXT_BACKGROUND) {
          Color bg = c.getBackground();
          if (!(bg instanceof UIResource)) {
            return bg;
          }
        } else if (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND) {
          Color fg = c.getForeground();
          if (!(fg instanceof UIResource)) {
            return fg;
          }
        }
      }
    }

    return getStyleSpecificColor(context, state, type);
  }
Ejemplo n.º 7
0
  @Override
  public Color getColor(SynthContext context, ColorType type) {
    JComponent c = context.getComponent();
    Region id = context.getRegion();
    int state = context.getComponentState();

    if (c.getName() == "Table.cellRenderer") {
      if (type == ColorType.BACKGROUND) {
        return c.getBackground();
      }
      if (type == ColorType.FOREGROUND) {
        return c.getForeground();
      }
    }

    if (id == Region.LABEL && type == ColorType.TEXT_FOREGROUND) {
      type = ColorType.FOREGROUND;
    }

    // For the enabled state, prefer the widget's colors
    if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) {
      if (type == ColorType.BACKGROUND) {
        return c.getBackground();
      } else if (type == ColorType.FOREGROUND) {
        return c.getForeground();
      } else if (type == ColorType.TEXT_FOREGROUND) {
        // If getForeground returns a non-UIResource it means the
        // developer has explicitly set the foreground, use it over
        // that of TEXT_FOREGROUND as that is typically the expected
        // behavior.
        Color color = c.getForeground();
        if (color != null && !(color instanceof UIResource)) {
          return color;
        }
      }
    }
    return getColorForState(context, type);
  }
Ejemplo n.º 8
0
  /**
   * Returns the Insets. If <code>insets</code> is non-null the resulting insets will be placed in
   * it, otherwise a new Insets object will be created and returned.
   *
   * @param context SynthContext identifying requestor
   * @param insets Where to place Insets
   * @return Insets.
   */
  @Override
  public Insets getInsets(SynthContext state, Insets insets) {
    Region id = state.getRegion();
    JComponent component = state.getComponent();
    String name = (id.isSubregion()) ? null : component.getName();

    if (insets == null) {
      insets = new Insets(0, 0, 0, 0);
    } else {
      insets.top = insets.bottom = insets.left = insets.right = 0;
    }

    if (id == Region.ARROW_BUTTON || id == Region.BUTTON || id == Region.TOGGLE_BUTTON) {
      if ("Spinner.previousButton" == name || "Spinner.nextButton" == name) {
        return getSimpleInsets(state, insets, 1);
      } else {
        return getButtonInsets(state, insets);
      }
    } else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) {
      return getRadioInsets(state, insets);
    } else if (id == Region.MENU_BAR) {
      return getMenuBarInsets(state, insets);
    } else if (id == Region.MENU
        || id == Region.MENU_ITEM
        || id == Region.CHECK_BOX_MENU_ITEM
        || id == Region.RADIO_BUTTON_MENU_ITEM) {
      return getMenuItemInsets(state, insets);
    } else if (id == Region.FORMATTED_TEXT_FIELD) {
      return getTextFieldInsets(state, insets);
    } else if (id == Region.INTERNAL_FRAME) {
      insets = Metacity.INSTANCE.getBorderInsets(state, insets);
    } else if (id == Region.LABEL) {
      if ("TableHeader.renderer" == name) {
        return getButtonInsets(state, insets);
      } else if (component instanceof ListCellRenderer) {
        return getTextFieldInsets(state, insets);
      } else if ("Tree.cellRenderer" == name) {
        return getSimpleInsets(state, insets, 1);
      }
    } else if (id == Region.OPTION_PANE) {
      return getSimpleInsets(state, insets, 6);
    } else if (id == Region.POPUP_MENU) {
      return getSimpleInsets(state, insets, 2);
    } else if (id == Region.PROGRESS_BAR
        || id == Region.SLIDER
        || id == Region.TABBED_PANE
        || id == Region.TABBED_PANE_CONTENT
        || id == Region.TOOL_BAR
        || id == Region.TOOL_BAR_DRAG_WINDOW
        || id == Region.TOOL_TIP) {
      return getThicknessInsets(state, insets);
    } else if (id == Region.SCROLL_BAR) {
      return getScrollBarInsets(state, insets);
    } else if (id == Region.SLIDER_TRACK) {
      return getSliderTrackInsets(state, insets);
    } else if (id == Region.TABBED_PANE_TAB) {
      return getTabbedPaneTabInsets(state, insets);
    } else if (id == Region.TEXT_FIELD || id == Region.PASSWORD_FIELD) {
      if (name == "Tree.cellEditor") {
        return getSimpleInsets(state, insets, 1);
      }
      return getTextFieldInsets(state, insets);
    } else if (id == Region.SEPARATOR
        || id == Region.POPUP_MENU_SEPARATOR
        || id == Region.TOOL_BAR_SEPARATOR) {
      return getSeparatorInsets(state, insets);
    } else if (id == GTKEngine.CustomRegion.TITLED_BORDER) {
      return getThicknessInsets(state, insets);
    }
    return insets;
  }