Java Code Examples for javax.swing.plaf.synth.Region

The following examples show how to use javax.swing.plaf.synth.Region. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
void testNames() {
    Color defaultColor = label.getBackground();

    UIManager.put("\"BlueLabel\"[Enabled].background",
            new ColorUIResource(Color.BLUE));
    UIManager.put("\"RedLabel\"[Enabled].background",
            new ColorUIResource(Color.RED));
    nimbus.register(Region.LABEL, "\"BlueLabel\"");
    nimbus.register(Region.LABEL, "\"RedLabel\"");

    label.setName("BlueLabel");
    check(Color.BLUE);
    label.setName("RedLabel");
    check(Color.RED);

    // remove name, color goes back to default
    label.setName(null);
    check(defaultColor);
}
 
Example 2
void testNames() {
    Color defaultColor = label.getBackground();

    UIManager.put("\"BlueLabel\"[Enabled].background",
            new ColorUIResource(Color.BLUE));
    UIManager.put("\"RedLabel\"[Enabled].background",
            new ColorUIResource(Color.RED));
    nimbus.register(Region.LABEL, "\"BlueLabel\"");
    nimbus.register(Region.LABEL, "\"RedLabel\"");

    label.setName("BlueLabel");
    check(Color.BLUE);
    label.setName("RedLabel");
    check(Color.RED);

    // remove name, color goes back to default
    label.setName(null);
    check(defaultColor);
}
 
Example 3
void testNames() {
    Color defaultColor = label.getBackground();

    UIManager.put("\"BlueLabel\"[Enabled].background",
            new ColorUIResource(Color.BLUE));
    UIManager.put("\"RedLabel\"[Enabled].background",
            new ColorUIResource(Color.RED));
    nimbus.register(Region.LABEL, "\"BlueLabel\"");
    nimbus.register(Region.LABEL, "\"RedLabel\"");

    label.setName("BlueLabel");
    check(Color.BLUE);
    label.setName("RedLabel");
    check(Color.RED);

    // remove name, color goes back to default
    label.setName(null);
    check(defaultColor);
}
 
Example 4
void testNames() {
    Color defaultColor = label.getBackground();

    UIManager.put("\"BlueLabel\"[Enabled].background",
            new ColorUIResource(Color.BLUE));
    UIManager.put("\"RedLabel\"[Enabled].background",
            new ColorUIResource(Color.RED));
    nimbus.register(Region.LABEL, "\"BlueLabel\"");
    nimbus.register(Region.LABEL, "\"RedLabel\"");

    label.setName("BlueLabel");
    check(Color.BLUE);
    label.setName("RedLabel");
    check(Color.RED);

    // remove name, color goes back to default
    label.setName(null);
    check(defaultColor);
}
 
Example 5
Source Project: seaglass   Source File: SeaGlassTreeUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
protected void uninstallDefaults() {
    SeaGlassContext context = getContext(tree, ENABLED);

    style.uninstallDefaults(context);
    context.dispose();
    style = null;

    context = getContext(tree, Region.TREE_CELL, ENABLED);
    cellStyle.uninstallDefaults(context);
    context.dispose();
    cellStyle = null;

    if (tree.getTransferHandler() instanceof UIResource) {
        tree.setTransferHandler(null);
    }
}
 
Example 6
void testNames() {
    Color defaultColor = label.getBackground();

    UIManager.put("\"BlueLabel\"[Enabled].background",
            new ColorUIResource(Color.BLUE));
    UIManager.put("\"RedLabel\"[Enabled].background",
            new ColorUIResource(Color.RED));
    nimbus.register(Region.LABEL, "\"BlueLabel\"");
    nimbus.register(Region.LABEL, "\"RedLabel\"");

    label.setName("BlueLabel");
    check(Color.BLUE);
    label.setName("RedLabel");
    check(Color.RED);

    // remove name, color goes back to default
    label.setName(null);
    check(defaultColor);
}
 
Example 7
Source Project: seaglass   Source File: SeaGlassTextFieldUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * DOCUMENT ME!
 *
 * @param g      DOCUMENT ME!
 * @param c      DOCUMENT ME!
 * @param region DOCUMENT ME!
 */
protected void paintSearchButton(Graphics g, JTextComponent c, Region region) {
    Rectangle bounds;

    if (region == SeaGlassRegion.SEARCH_FIELD_FIND_BUTTON) {
        bounds = getFindButtonBounds();
    } else {
        bounds = getCancelButtonBounds();
    }

    SeaGlassContext subcontext = getContext(c, region);

    SeaGlassLookAndFeel.updateSubregion(subcontext, g, bounds);

    SeaGlassSynthPainterImpl painter = (SeaGlassSynthPainterImpl) subcontext.getPainter();

    painter.paintSearchButtonForeground(subcontext, g, bounds.x, bounds.y, bounds.width, bounds.height);

    subcontext.dispose();
}
 
Example 8
Source Project: seaglass   Source File: SeaGlassLookAndFeel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Called by UIManager when this look and feel is installed.
 */
@Override
public void initialize() {
    super.initialize();

    // create synth style factory
    setStyleFactory(new SynthStyleFactory() {
            @Override
            public SynthStyle getStyle(JComponent c, Region r) {
                SynthStyle style = getSeaGlassStyle(c, r);

                if (!(style instanceof SeaGlassStyle)) {
                    style = new SeaGlassStyleWrapper(style);
                }

                return style;
            }
        });
}
 
Example 9
void testNames() {
    Color defaultColor = label.getBackground();

    UIManager.put("\"BlueLabel\"[Enabled].background",
            new ColorUIResource(Color.BLUE));
    UIManager.put("\"RedLabel\"[Enabled].background",
            new ColorUIResource(Color.RED));
    nimbus.register(Region.LABEL, "\"BlueLabel\"");
    nimbus.register(Region.LABEL, "\"RedLabel\"");

    label.setName("BlueLabel");
    check(Color.BLUE);
    label.setName("RedLabel");
    check(Color.RED);

    // remove name, color goes back to default
    label.setName(null);
    check(defaultColor);
}
 
Example 10
Source Project: seaglass   Source File: SeaGlassScrollBarUI.java    License: Apache License 2.0 6 votes vote down vote up
protected void uninstallDefaults() {
    SeaGlassContext context = getContext(scrollbar, ENABLED);
    style.uninstallDefaults(context);
    context.dispose();
    style = null;

    context = getContext(scrollbar, Region.SCROLL_BAR_TRACK, ENABLED);
    trackStyle.uninstallDefaults(context);
    context.dispose();
    trackStyle = null;

    context = getContext(scrollbar, Region.SCROLL_BAR_THUMB, ENABLED);
    thumbStyle.uninstallDefaults(context);
    context.dispose();
    thumbStyle = null;

    context = getContext(scrollbar, SeaGlassRegion.SCROLL_BAR_CAP, ENABLED);
    capStyle.uninstallDefaults(context);
    context.dispose();
    capStyle = null;

    super.uninstallDefaults();
}
 
Example 11
Source Project: jdk1.8-source-analysis   Source File: NimbusLookAndFeel.java    License: Apache License 2.0 5 votes vote down vote up
/** Called by UIManager when this look and feel is installed. */
@Override public void initialize() {
    super.initialize();
    defaults.initialize();
    // create synth style factory
    setStyleFactory(new SynthStyleFactory() {
        @Override
        public SynthStyle getStyle(JComponent c, Region r) {
            return defaults.getStyle(c, r);
        }
    });
}
 
Example 12
Source Project: jdk1.8-source-analysis   Source File: NimbusDefaults.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>Registers the given region and prefix. The prefix, if it contains
 * quoted sections, refers to certain named components. If there are not
 * quoted sections, then the prefix refers to a generic component type.</p>
 *
 * <p>If the given region/prefix combo has already been registered, then
 * it will not be registered twice. The second registration attempt will
 * fail silently.</p>
 *
 * @param region The Synth Region that is being registered. Such as Button,
 *        or ScrollBarThumb.
 * @param prefix The UIDefault prefix. For example, could be ComboBox, or if
 *        a named components, "MyComboBox", or even something like
 *        ToolBar:"MyComboBox":"ComboBox.arrowButton"
 */
void register(Region region, String prefix) {
    //validate the method arguments
    if (region == null || prefix == null) {
        throw new IllegalArgumentException(
                "Neither Region nor Prefix may be null");
    }

    //Add a LazyStyle for this region/prefix to m.
    List<LazyStyle> styles = m.get(region);
    if (styles == null) {
        styles = new LinkedList<LazyStyle>();
        styles.add(new LazyStyle(prefix));
        m.put(region, styles);
    } else {
        //iterate over all the current styles and see if this prefix has
        //already been registered. If not, then register it.
        for (LazyStyle s : styles) {
            if (prefix.equals(s.prefix)) {
                return;
            }
        }
        styles.add(new LazyStyle(prefix));
    }

    //add this region to the map of registered regions
    registeredRegions.put(region.getName(), region);
}
 
Example 13
Source Project: jdk1.8-source-analysis   Source File: NimbusDefaults.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>Locate the style associated with the given region, and component.
 * This is called from NimbusLookAndFeel in the SynthStyleFactory
 * implementation.</p>
 *
 * <p>Lookup occurs as follows:<br/>
 * Check the map of styles <code>m</code>. If the map contains no styles at
 * all, then simply return the defaultStyle. If the map contains styles,
 * then iterate over all of the styles for the Region <code>r</code> looking
 * for the best match, based on prefix. If a match was made, then return
 * that SynthStyle. Otherwise, return the defaultStyle.</p>
 *
 * @param comp The component associated with this region. For example, if
 *        the Region is Region.Button then the component will be a JButton.
 *        If the Region is a subregion, such as ScrollBarThumb, then the
 *        associated component will be the component that subregion belongs
 *        to, such as JScrollBar. The JComponent may be named. It may not be
 *        null.
 * @param r The region we are looking for a style for. May not be null.
 */
SynthStyle getStyle(JComponent comp, Region r) {
    //validate method arguments
    if (comp == null || r == null) {
        throw new IllegalArgumentException(
                "Neither comp nor r may be null");
    }

    //if there are no lazy styles registered for the region r, then return
    //the default style
    List<LazyStyle> styles = m.get(r);
    if (styles == null || styles.size() == 0) {
        return defaultStyle;
    }

    //Look for the best SynthStyle for this component/region pair.
    LazyStyle foundStyle = null;
    for (LazyStyle s : styles) {
        if (s.matches(comp)) {
            //replace the foundStyle if foundStyle is null, or
            //if the new style "s" is more specific (ie, its path was
            //longer), or if the foundStyle was "simple" and the new style
            //was not (ie: the foundStyle was for something like Button and
            //the new style was for something like "MyButton", hence, being
            //more specific.) In all cases, favor the most specific style
            //found.
            if (foundStyle == null ||
               (foundStyle.parts.length < s.parts.length) ||
               (foundStyle.parts.length == s.parts.length 
                && foundStyle.simple && !s.simple)) {
                foundStyle = s;
            }
        }
    }

    //return the style, if found, or the default style if not found
    return foundStyle == null ? defaultStyle : foundStyle.getStyle(comp, r);
}
 
Example 14
Source Project: jdk1.8-source-analysis   Source File: NimbusDefaults.java    License: Apache License 2.0 5 votes vote down vote up
private boolean matches(Component c, int partIndex) {
    if (partIndex < 0) return true;
    if (c == null) return false;
    //only get here if partIndex > 0 and c == null

    String name = c.getName();
    if (parts[partIndex].named && parts[partIndex].s.equals(name)) {
        //so far so good, recurse
        return matches(c.getParent(), partIndex - 1);
    } else if (!parts[partIndex].named) {
        //if c is not named, and parts[partIndex] has an expected class
        //type registered, then check to make sure c is of the
        //right type;
        Class clazz = parts[partIndex].c;
        if (clazz != null && clazz.isAssignableFrom(c.getClass())) {
            //so far so good, recurse
            return matches(c.getParent(), partIndex - 1);
        } else if (clazz == null &&
                   registeredRegions.containsKey(parts[partIndex].s)) {
            Region r = registeredRegions.get(parts[partIndex].s);
            Component parent = r.isSubregion() ? c : c.getParent();
            //special case the JInternalFrameTitlePane, because it
            //doesn't fit the mold. very, very funky.
            if (r == Region.INTERNAL_FRAME_TITLE_PANE && parent != null
                && parent instanceof JInternalFrame.JDesktopIcon) {
                JInternalFrame.JDesktopIcon icon =
                        (JInternalFrame.JDesktopIcon) parent;
                parent = icon.getInternalFrame();
            }
            //it was the name of a region. So far, so good. Recurse.
            return matches(parent, partIndex - 1);
        }
    }

    return false;
}
 
Example 15
/** Called by UIManager when this look and feel is installed. */
@Override public void initialize() {
    super.initialize();
    defaults.initialize();
    // create synth style factory
    setStyleFactory(new SynthStyleFactory() {
        @Override
        public SynthStyle getStyle(JComponent c, Region r) {
            return defaults.getStyle(c, r);
        }
    });
}
 
Example 16
/** Called by UIManager when this look and feel is installed. */
@Override public void initialize() {
    super.initialize();
    defaults.initialize();
    // create synth style factory
    setStyleFactory(new SynthStyleFactory() {
        @Override
        public SynthStyle getStyle(JComponent c, Region r) {
            return defaults.getStyle(c, r);
        }
    });
}
 
Example 17
Source Project: TencentKona-8   Source File: Test6660049.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Test6660049(Class<? extends JComponent>... types) {
    this.types = types;
    run();

    this.region = new Region("Button", "ButtonUI", true) {
        @Override
        public String getName() {
            throw new Error("6660049: exploit is available");
        }
    };
}
 
Example 18
Source Project: jdk8u60   Source File: NimbusLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Called by UIManager when this look and feel is installed. */
@Override public void initialize() {
    super.initialize();
    defaults.initialize();
    // create synth style factory
    setStyleFactory(new SynthStyleFactory() {
        @Override
        public SynthStyle getStyle(JComponent c, Region r) {
            return defaults.getStyle(c, r);
        }
    });
}
 
Example 19
Source Project: JDKSourceCode1.8   Source File: NimbusLookAndFeel.java    License: MIT License 5 votes vote down vote up
/** Called by UIManager when this look and feel is installed. */
@Override public void initialize() {
    super.initialize();
    defaults.initialize();
    // create synth style factory
    setStyleFactory(new SynthStyleFactory() {
        @Override
        public SynthStyle getStyle(JComponent c, Region r) {
            return defaults.getStyle(c, r);
        }
    });
}
 
Example 20
Source Project: seaglass   Source File: SeaGlassScrollBarUI.java    License: Apache License 2.0 5 votes vote down vote up
private SeaGlassContext getContext(JComponent c, Region region, int state) {
    SynthStyle style = trackStyle;

    if (region == Region.SCROLL_BAR_THUMB) {
        style = thumbStyle;
    } else if (region == SeaGlassRegion.SCROLL_BAR_CAP) {
        style = capStyle;
    }
    return SeaGlassContext.getContext(SeaGlassContext.class, c, region, style, state);
}
 
Example 21
Source Project: JDKSourceCode1.8   Source File: NimbusDefaults.java    License: MIT License 5 votes vote down vote up
/**
 * Gets the style. Creates it if necessary.
 * @return the style
 */
SynthStyle getStyle(JComponent c, Region r) {
    // if the component has overrides, it gets its own unique style
    // instead of the shared style.
    if (c.getClientProperty("Nimbus.Overrides") != null) {
        Map<Region, SynthStyle> map = overridesCache.get(c);
        SynthStyle s = null;
        if (map == null) {
            map = new HashMap<Region, SynthStyle>();
            overridesCache.put(c, map);
        } else {
            s = map.get(r);
        }
        if (s == null) {
            s = new NimbusStyle(prefix, c);
            map.put(r, s);
        }
        return s;
    }
    
    // lazily create the style if necessary
    if (style == null)
        style = new NimbusStyle(prefix, null);
    
    // return the style
    return style;
}
 
Example 22
/** Called by UIManager when this look and feel is installed. */
@Override public void initialize() {
    super.initialize();
    defaults.initialize();
    // create synth style factory
    setStyleFactory(new SynthStyleFactory() {
        @Override
        public SynthStyle getStyle(JComponent c, Region r) {
            return defaults.getStyle(c, r);
        }
    });
}
 
Example 23
Source Project: seaglass   Source File: SeaGlassSplitPaneUI.java    License: Apache License 2.0 5 votes vote down vote up
private int getComponentState(JComponent c, Region subregion) {
    int state = SeaGlassLookAndFeel.getComponentState(c);

    if (divider.isMouseOver()) {
        state |= MOUSE_OVER;
    }
    return state;
}
 
Example 24
Source Project: jdk8u-jdk   Source File: Test6660049.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Test6660049(Class<? extends JComponent>... types) {
    this.types = types;
    run();

    this.region = new Region("Button", "ButtonUI", true) {
        @Override
        public String getName() {
            throw new Error("6660049: exploit is available");
        }
    };
}
 
Example 25
Source Project: netbeans   Source File: ThemeValue.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of GTKColor */
public ThemeValue(Region region, ColorType colorType, Object fallback) {
    this.fallback = fallback;
    this.aRegion = region;
    this.aColorType = colorType;
    register(this);
}
 
Example 26
Source Project: netbeans   Source File: ThemeValue.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of GTKColor */
public ThemeValue(Region region, ColorType colorType, Object fallback, boolean darken) {
    this.fallback = fallback;
    this.aRegion = region;
    this.aColorType = colorType;
    this.darken = darken;
    register(this);
}
 
Example 27
Source Project: jdk8u-dev-jdk   Source File: Test6660049.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Test6660049(Class<? extends JComponent>... types) {
    this.types = types;
    run();

    this.region = new Region("Button", "ButtonUI", true) {
        @Override
        public String getName() {
            throw new Error("6660049: exploit is available");
        }
    };
}
 
Example 28
Source Project: seaglass   Source File: SeaGlassToolBarUI.java    License: Apache License 2.0 5 votes vote down vote up
protected void paint(SeaGlassContext context, Graphics g) {
    if (handleIcon != null && toolBar.isFloatable()) {
        int startX = toolBar.getComponentOrientation().isLeftToRight() ? 0 : toolBar.getWidth()
                - SeaGlassIcon.getIconWidth(handleIcon, context);
        SeaGlassIcon.paintIcon(handleIcon, context, g, startX, 0, SeaGlassIcon.getIconWidth(handleIcon, context), SeaGlassIcon.getIconHeight(
            handleIcon, context));
    }

    SeaGlassContext subcontext = getContext(toolBar, Region.TOOL_BAR_CONTENT, contentStyle);
    // paintContent(subcontext, g, contentRect);
    subcontext.dispose();
}
 
Example 29
private Test6660049(Class<? extends JComponent>... types) {
    this.types = types;
    run();

    this.region = new Region("Button", "ButtonUI", true) {
        @Override
        public String getName() {
            throw new Error("6660049: exploit is available");
        }
    };
}
 
Example 30
Source Project: seaglass   Source File: SeaGlassToolBarUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void paintDragWindow(Graphics g) {
    int w = dragWindow.getWidth();
    int h = dragWindow.getHeight();
    SeaGlassContext context = getContext(toolBar, Region.TOOL_BAR_DRAG_WINDOW, dragWindowStyle);
    SeaGlassLookAndFeel.updateSubregion(context, g, new Rectangle(0, 0, w, h));
    context.getPainter().paintToolBarDragWindowBackground(context, g, 0, 0, w, h, dragWindow.getOrientation());
    context.getPainter().paintToolBarDragWindowBorder(context, g, 0, 0, w, h, dragWindow.getOrientation());
    context.dispose();
}