Пример #1
0
 private Insets getVisualMargin(JComponent component) {
   String uid = component.getUIClassID();
   String style = null;
   if (uid == "ButtonUI" || uid == "ToggleButtonUI") {
     style = (String) component.getClientProperty("JButton.buttonType");
   } else if (uid == "ProgressBarUI") {
     style =
         (((JProgressBar) component).getOrientation() == JProgressBar.HORIZONTAL)
             ? "horizontal"
             : "vertical";
   } else if (uid == "SliderUI") {
     style =
         (((JSlider) component).getOrientation() == JProgressBar.HORIZONTAL)
             ? "horizontal"
             : "vertical";
   } else if (uid == "TabbedPaneUI") {
     switch (((JTabbedPane) component).getTabPlacement()) {
       case JTabbedPane.TOP:
         style = "top";
         break;
       case JTabbedPane.LEFT:
         style = "left";
         break;
       case JTabbedPane.BOTTOM:
         style = "bottom";
         break;
       case JTabbedPane.RIGHT:
         style = "right";
         break;
     }
   }
   Insets gap = getInsets(VISUAL_MARGINS, uid, style, 0);
   // Take into account different positions of the button icon
   if (uid == "RadioButtonUI" || uid == "CheckBoxUI") {
     switch (((AbstractButton) component).getHorizontalTextPosition()) {
       case SwingConstants.RIGHT:
         gap = new Insets(gap.top, gap.right, gap.bottom, gap.left);
         break;
       case SwingConstants.CENTER:
         gap = new Insets(gap.top, gap.right, gap.bottom, gap.right);
         break;
         /*
         case SwingConstants.LEFT :
             break;
              */
       default:
         gap = new Insets(gap.top, gap.left, gap.bottom, gap.right);
     }
     if (component.getBorder() instanceof EmptyBorder) {
       gap.left -= 2;
       gap.right -= 2;
       gap.top -= 2;
       gap.bottom -= 2;
     }
   }
   return gap;
 }
Пример #2
0
  public int getPreferredGap(
      JComponent source, JComponent target, int type, int position, Container parent) {
    // Invoke super to check arguments.
    super.getPreferredGap(source, target, type, position, parent);

    if (type == INDENT) {
      if (position == SwingConstants.EAST || position == SwingConstants.WEST) {
        int gap = getButtonChildIndent(source, position);
        if (gap != 0) {
          return gap;
        }
        return 10;
      }
      // Treat vertical INDENT as RELATED
      type = RELATED;
    }
    if (type == UNRELATED) {
      // Between unrelated controls: 7
      return getCBRBPadding(source, target, position, dluToPixels(7, position));
    } else { // type == RELATED
      boolean sourceLabel = (source.getUIClassID() == "LabelUI");
      boolean targetLabel = (target.getUIClassID() == "LabelUI");

      if (((sourceLabel && !targetLabel) || (targetLabel && !sourceLabel))
          && (position == SwingConstants.EAST || position == SwingConstants.WEST)) {
        // Between text labels and their associated controls (for
        // example, text boxes and list boxes): 3
        // NOTE: We're not honoring:
        // 'Text label beside a button 3 down from the top of
        // the button,' but I suspect that is an attempt to
        // enforce a baseline layout which will be handled
        // separately.  In order to enforce this we would need
        // this API to return a more complicated type (Insets,
        // or something else).
        return getCBRBPadding(source, target, position, dluToPixels(3, position));
      }
      // Between related controls: 4
      return getCBRBPadding(source, target, position, dluToPixels(4, position));
    }
  }
Пример #3
0
  private Insets getPreferredGap(JComponent component, int type, int sizeStyle) {
    Map gapMap;

    switch (type) {
      case INDENT:
        gapMap = INDENT_GAPS;
        break;
      case RELATED:
        gapMap = RELATED_GAPS;
        break;
      case UNRELATED:
      default:
        gapMap = UNRELATED_GAPS;
        break;
    }

    String uid = component.getUIClassID();
    String style = null;
    // == is ok here as Strings from Swing get interned, if for some reason
    // need .equals then must deal with null.
    if (uid == "ButtonUI" || uid == "ToggleButtonUI") {
      style = (String) component.getClientProperty("JButton.buttonType");
    } else if (uid == "ProgressBarUI") {
      style =
          (((JProgressBar) component).getOrientation() == JProgressBar.HORIZONTAL)
              ? "horizontal"
              : "vertical";
    } else if (uid == "SliderUI") {
      style =
          (((JSlider) component).getOrientation() == JProgressBar.HORIZONTAL)
              ? "horizontal"
              : "vertical";
    } else if (uid == "TabbedPaneUI") {
      switch (((JTabbedPane) component).getTabPlacement()) {
        case JTabbedPane.TOP:
          style = "top";
          break;
        case JTabbedPane.LEFT:
          style = "left";
          break;
        case JTabbedPane.BOTTOM:
          style = "bottom";
          break;
        case JTabbedPane.RIGHT:
          style = "right";
          break;
      }
    } else if (uid == "ComboBoxUI") {
      style = ((JComboBox) component).isEditable() ? "editable" : "uneditable";
    }
    return getInsets(gapMap, uid, style, sizeStyle);
  }
Пример #4
0
 /**
  * Returns the baseline for the specified component, or a value less than 0 if the baseline can
  * not be determined. The baseline is measured from the top of the component.
  *
  * @param component JComponent to calculate baseline for
  * @param width Width of the component to determine baseline for.
  * @param height Height of the component to determine baseline for.
  * @return baseline for the specified component
  */
 public static int getBaseline(JComponent component, int width, int height) {
   Method baselineMethod = getBaselineMethod(component);
   if (baselineMethod != null) {
     return invokeBaseline(baselineMethod, component, width, height);
   }
   Object baselineImpl = UIManager.get("Baseline.instance");
   if (baselineImpl != null && (baselineImpl instanceof Baseline)) {
     return ((Baseline) baselineImpl).getComponentBaseline(component, width, height);
   }
   if (!isKnownLookAndFeel()) {
     return -1;
   }
   String uid = component.getUIClassID();
   int baseline = -1;
   if (uid == "ButtonUI"
       || uid == "CheckBoxUI"
       || uid == "RadioButtonUI"
       || uid == "ToggleButtonUI") {
     baseline = getButtonBaseline((AbstractButton) component, height);
   } else if (uid == "ComboBoxUI") {
     return getComboBoxBaseline((JComboBox) component, height);
   } else if (uid == "TextAreaUI") {
     return getTextAreaBaseline((JTextArea) component, height);
   } else if (uid == "FormattedTextFieldUI" || uid == "PasswordFieldUI" || uid == "TextFieldUI") {
     baseline = getSingleLineTextBaseline((JTextComponent) component, height);
   } else if (uid == "LabelUI") {
     baseline = getLabelBaseline((JLabel) component, height);
   } else if (uid == "ListUI") {
     baseline = getListBaseline((JList) component, height);
   } else if (uid == "PanelUI") {
     baseline = getPanelBaseline((JPanel) component, height);
   } else if (uid == "ProgressBarUI") {
     baseline = getProgressBarBaseline((JProgressBar) component, height);
   } else if (uid == "SliderUI") {
     baseline = getSliderBaseline((JSlider) component, height);
   } else if (uid == "SpinnerUI") {
     baseline = getSpinnerBaseline((JSpinner) component, height);
   } else if (uid == "ScrollPaneUI") {
     baseline = getScrollPaneBaseline((JScrollPane) component, height);
   } else if (uid == "TabbedPaneUI") {
     baseline = getTabbedPaneBaseline((JTabbedPane) component, height);
   } else if (uid == "TableUI") {
     baseline = getTableBaseline((JTable) component, height);
   } else if (uid == "TreeUI") {
     baseline = getTreeBaseline((JTree) component, height);
   }
   return Math.max(baseline, -1);
 }
Пример #5
0
  /**
   * Sets the name of UI for the Component passed
   *
   * @param c
   */
  public static void setUIName(JComponent c) {
    String key = c.getUIClassID();
    String uiClassName = (String) UIManager.get(key);

    if (uiClassName == null) {
      String componentName = c.getClass().getName();
      int index = componentName.lastIndexOf('.') + 1;
      StringBuffer sb = new StringBuffer();
      sb.append(componentName.substring(0, index));
      String lookAndFeelName = UIManager.getLookAndFeel().getName();
      if (lookAndFeelName.startsWith("CDE/")) {
        lookAndFeelName = lookAndFeelName.substring(4, lookAndFeelName.length());
      }
      sb.append(lookAndFeelName);
      sb.append(key);
      UIManager.put(key, sb.toString());
    }
  }
Пример #6
0
 /**
  * Returns a constant indicating how the baseline varies with the size of the component.
  *
  * @param c the JComponent to get the baseline resize behavior for
  * @return one of BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET or BRB_OTHER
  */
 public static int getBaselineResizeBehavior(JComponent c) {
   Method brbIMethod = getBRBIMethod(c);
   if (brbIMethod != null) {
     return invokeBRBIMethod(brbIMethod, c);
   }
   if (COMPONENT_BRB_METHOD != null) {
     return getBaselineResizeBehaviorUsingMustang(c);
   }
   String uid = c.getUIClassID();
   if (uid == "ButtonUI"
       || uid == "CheckBoxUI"
       || uid == "RadioButtonUI"
       || uid == "ToggleButtonUI") {
     return getButtonBaselineResizeBehavior((AbstractButton) c);
   } else if (uid == "ComboBoxUI") {
     return getComboBoxBaselineResizeBehavior((JComboBox) c);
   } else if (uid == "TextAreaUI") {
     return getTextAreaBaselineResizeBehavior((JTextArea) c);
   } else if (uid == "TextFieldUI" || uid == "FormattedTextFieldUI" || uid == "PasswordFieldUI") {
     return getSingleLineTextBaselineResizeBehavior((JTextField) c);
   } else if (uid == "LabelUI") {
     return getLabelBaselineResizeBehavior((JLabel) c);
   } else if (uid == "ListUI") {
     return getListBaselineResizeBehavior((JList) c);
   } else if (uid == "PanelUI") {
     return getPanelBaselineResizeBehavior((JPanel) c);
   } else if (uid == "ProgressBarUI") {
     return getProgressBarBaselineResizeBehavior((JProgressBar) c);
   } else if (uid == "SliderUI") {
     return getSliderBaselineResizeBehavior((JSlider) c);
   } else if (uid == "SpinnerUI") {
     return getSpinnerBaselineResizeBehavior((JSpinner) c);
   } else if (uid == "ScrollPaneUI") {
     return getScrollPaneBaselineBaselineResizeBehavior((JScrollPane) c);
   } else if (uid == "TabbedPaneUI") {
     return getTabbedPaneBaselineResizeBehavior((JTabbedPane) c);
   } else if (uid == "TableUI") {
     return getTableBaselineResizeBehavior((JTable) c);
   } else if (uid == "TreeUI") {
     return getTreeBaselineResizeBehavior((JTree) c);
   }
   return BRB_OTHER;
 }