Java Code Examples for javax.swing.JComponent.getUIClassID()

The following are Jave code examples for showing how to use getUIClassID() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sumo   File: MultiThumbSlider.java   View Source Code Vote up 6 votes
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());
    }
}
 
Example 2
Project: Moenagade   File: MetalLayoutStyle.java   View Source Code Vote up 5 votes
private int getButtonAdjustment(JComponent source, int edge) {
    String uid = source.getUIClassID();
    if (uid == "ButtonUI" || uid == "ToggleButtonUI") {
        if (!isOcean && (edge == SwingConstants.EAST ||
                         edge == SwingConstants.SOUTH)) {
            return 1;
        }
    }
    else if (edge == SwingConstants.SOUTH) {
        if (uid == "RadioButtonUI" || (!isOcean && uid == "CheckBoxUI")) {
            return 1;
        }
    }
    return 0;
}
 
Example 3
Project: Moenagade   File: LayoutStyle.java   View Source Code Vote up 5 votes
private int getCBRBPadding(JComponent c, int position) {
    if (c.getUIClassID() == "CheckBoxUI" ||
          c.getUIClassID() == "RadioButtonUI") {
        Border border = c.getBorder();
        if (border instanceof UIResource) {
            return getInset(c, position);
        }
    }
    return 0;
}
 
Example 4
Project: Moenagade   File: MetalLayoutStyle.java   View Source Code Vote up 4 votes
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 12;
        }
        // Treat vertical INDENT as RELATED
        type = RELATED;
    }
    
    String sourceCID = source.getUIClassID();
    String targetCID = target.getUIClassID();
    int offset;

    if (type == RELATED) {
        if (sourceCID == "ToggleButtonUI" &&
                  targetCID == "ToggleButtonUI") {
            ButtonModel sourceModel = ((JToggleButton)source).getModel();
            ButtonModel targetModel = ((JToggleButton)target).getModel();
            if ((sourceModel instanceof DefaultButtonModel) &&
                (targetModel instanceof DefaultButtonModel) &&
                (((DefaultButtonModel)sourceModel).getGroup() ==
                 ((DefaultButtonModel)targetModel).getGroup()) &&
                    ((DefaultButtonModel)sourceModel).getGroup() != null) {
                // When toggle buttons are exclusive (that is, they form a
                // radio button set), separate them with 2 pixels. This
                // rule applies whether the toggle buttons appear in a
                // toolbar or elsewhere in the interface.
                // Note: this number does not appear to include any borders
                // and so is not adjusted by the border of the toggle
                // button
                return 2;
            }
            // When toggle buttons are independent (like checkboxes)
            // and used outside a toolbar, separate them with 5
            // pixels.
            if (isOcean) {
                return 6;
            }
            return 5;
        }
        offset = 6;
    }
    else {
        offset = 12;
    }
    if ((position == SwingConstants.EAST ||
         position == SwingConstants.WEST) &&
        ((sourceCID == "LabelUI" && targetCID != "LabelUI") ||
         (sourceCID != "LabelUI" && targetCID == "LabelUI"))) {
        // Insert 12 pixels between the trailing edge of a
        // label and any associated components. Insert 12
        // pixels between the trailing edge of a label and the
        // component it describes when labels are
        // right-aligned. When labels are left-aligned, insert
        // 12 pixels between the trailing edge of the longest
        // label and its associated component
        return getCBRBPadding(source, target, position, offset + 6);
    }
    return getCBRBPadding(source, target, position, offset);
}
 
Example 5
Project: Moenagade   File: GnomeLayoutStyle.java   View Source Code Vote up 4 votes
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;
            }
            // Indent group members 12 pixels to denote hierarchy and
            // association.
            return 12;
        }
        // Treat vertical INDENT as RELATED
        type = RELATED;
    }
    // Between labels and associated components, leave 12 horizontal
    // pixels.
    if (position == SwingConstants.EAST ||
                    position == SwingConstants.WEST) {
        boolean sourceLabel = (source.getUIClassID() == "LabelUI");
        boolean targetLabel = (target.getUIClassID() == "LabelUI");
        if ((sourceLabel && !targetLabel) || 
                (!sourceLabel && targetLabel)) {
            return 12;
        }
    }
    // As a basic rule of thumb, leave space between user
    // interface components in increments of 6 pixels, going up as
    // the relationship between related elements becomes more
    // distant. For example, between icon labels and associated
    // graphics within an icon, 6 pixels are adequate. Between
    // labels and associated components, leave 12 horizontal
    // pixels. For vertical spacing between groups of components,
    // 18 pixels is adequate.
    //
    // The first part of this is handled automatically by Icon (which
    // won't give you 6 pixels).
    if (type == RELATED) {
        return 6;
    }
    return 12;
}
 
Example 6
Project: Moenagade   File: WindowsLayoutStyle.java   View Source Code Vote up 4 votes
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));
    }
}