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

The following are Jave code examples for showing how to use getClientProperty() 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: incubator-netbeans   File: TemplateWizardIterator.java   View Source Code Vote up 6 votes
@Override
public void initialize(WizardDescriptor wizard) {
    wiz = wizard;
    delegateIterator.initialize(wizard);
    superclassPanelCurrent = false;
    if (superclassPanel == null && specifySuperclass) {
        superclassPanel = new SuperclassWizardPanel();
        
        ResourceBundle bundle = NbBundle.getBundle(TemplateWizardIterator.class);
        JComponent comp = (JComponent)delegateIterator.current().getComponent();
        String[] contentData = (String[])comp.getClientProperty(WizardDescriptor.PROP_CONTENT_DATA); // NOI18N
        String[] newContentData = new String[contentData.length+1];
        System.arraycopy(contentData, 0, newContentData, 0, contentData.length);
        newContentData[contentData.length] = bundle.getString("CTL_SuperclassTitle"); // NOI18N
        comp.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, newContentData); // NOI18N
    }    
}
 
Example 2
Project: incubator-netbeans   File: MasterDetailWizard.java   View Source Code Vote up 6 votes
/**
 * Returns current panel of the wizard.
 *
 * @return current panel of the wizard.
 */
@Override
public WizardDescriptor.Panel current() {
    String title = NbBundle.getMessage(MasterDetailWizard.class, "TITLE_MasterDetail");  // NOI18N
    wizard.putProperty("NewFileWizard_Title", title); // NOI18N
    if (steps == null) {
        initSteps();
    }
    WizardDescriptor.Panel panel;
    if (panelIndex < beforeStepsNo) {
        panel = delegateIterator.current();
    } else {
        panel = panels[panelIndex-beforeStepsNo];
    }
    JComponent comp = (JComponent)panel.getComponent();
    if ((panelIndex < beforeStepsNo) || (comp.getClientProperty(WIZARD_PANEL_CONTENT_DATA) == null)) {
        comp.putClientProperty(WIZARD_PANEL_CONTENT_DATA, steps);
    }
    if (comp.getClientProperty(WIZARD_PANEL_CONTENT_SELECTED_INDEX) == null) {
        comp.putClientProperty(WIZARD_PANEL_CONTENT_SELECTED_INDEX, panelIndex);
    }
    return panel;
}
 
Example 3
Project: incubator-netbeans   File: ComponentDetailsProvider.java   View Source Code Vote up 6 votes
private void hoverChanged() {
    String toolTipText;
    if (hover != null) {                
        JComponent jc = hover instanceof JComponent ? (JComponent)hover : null;
        Object cn = jc == null ? null : jc.getClientProperty("className");
        String name = cn == null ? "" : cn.toString();
        
        toolTipText = name.isEmpty() ? null : name;
    } else {
        toolTipText = null;
    }
    // ToolTipManager doesn't like changing the tooltip from mouseMoved().
    // This is a workaround to hide the tip when needed and prevent NPEs.
    if (toolTipText == null) ToolTipManager.sharedInstance().mousePressed(null);
    glassPane.setToolTipText(toolTipText);
    repaint();
}
 
Example 4
Project: incubator-netbeans   File: DefaultFoldingOptions.java   View Source Code Vote up 5 votes
private void updateEnabledState() {
    boolean foldEnable = preferences.getBoolean(SimpleValueNames.CODE_FOLDING_ENABLE, true);
    boolean useDefaults = preferences.getBoolean(FoldUtilitiesImpl.PREF_OVERRIDE_DEFAULTS, true);
    
    for (JComponent c : controls) {
        FoldType ft = (FoldType)c.getClientProperty("type"); // NOI18N
        boolean enable = true;
        if (defaultPrefs != null && useDefaults) {
            enable = !isDefinedDefault(ft);
        }
        enable &= foldEnable;
        c.setEnabled(enable);
    }
}
 
Example 5
Project: incubator-netbeans   File: RectangularSelectionUtils.java   View Source Code Vote up 5 votes
public static List<Position> regionsCopy(JComponent c) {
    @SuppressWarnings("unchecked") List<Position> regions =
            (List<Position>) c.getClientProperty(RECTANGULAR_SELECTION_REGIONS_PROPERTY);
    List<Position> lRegions;
    if (regions != null) {
        synchronized (regions) {
            lRegions = new ArrayList<Position>(regions);
        }
    } else {
        lRegions = null;
    }
    return lRegions;
}
 
Example 6
Project: marathonv5   File: AbstractJavaElement.java   View Source Code Vote up 5 votes
@Override public void submit() {
    if (component instanceof JComponent) {
        JComponent tc = (JComponent) component;
        Object clientProperty = tc.getClientProperty("marathon.celleditor.parent");
        if (clientProperty != null) {
            EventQueueWait.call_noexc(clientProperty, "stopEditing");
        }
    }
}
 
Example 7
Project: incubator-netbeans   File: PrintAction.java   View Source Code Vote up 5 votes
private String getName(List<JComponent> printable, JComponent top) {
    for (JComponent component : printable) {
        Object object = component.getClientProperty(PrintManager.PRINT_NAME);

        if (object instanceof String) {
            return (String) object;
        }
    }
    return getName(getData(top));
}
 
Example 8
Project: OpenJSharp   File: NimbusDefaults.java   View Source Code Vote up 5 votes
/**
 * 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 9
Project: incubator-netbeans   File: MasterDetailWizard.java   View Source Code Vote up 5 votes
/**
 * Initializes array of steps of this wizard.
 */
private void initSteps() {
    String[] thisSteps = new String[] {
        NbBundle.getMessage(MasterDetailWizard.class, "TITLE_MasterPanel"), // NOI18N
        NbBundle.getMessage(MasterDetailWizard.class, "TITLE_DetailPanel") // NOI18N
    };

    Object prop;
    if (delegateIterator != null) {
        JComponent comp = (JComponent)delegateIterator.current().getComponent();
        prop = comp.getClientProperty(WizardDescriptor.PROP_CONTENT_DATA); // NOI18N
    }
    else prop = null;

    String[] beforeSteps;
    int stepsStartPos;
    
    if (prop instanceof String[]) {
        beforeSteps = (String[]) prop;
        beforeStepsNo = beforeSteps.length;
        stepsStartPos = beforeSteps.length;
        if (stepsStartPos > 0 && ("...".equals(beforeSteps[stepsStartPos - 1]))) { // NOI18N
            stepsStartPos--;
        }
    } else {
        beforeStepsNo = 0;
        beforeSteps = null;
        stepsStartPos = 0;
    }
    
    steps = new String[stepsStartPos + thisSteps.length];
    if (beforeSteps != null)
        System.arraycopy(beforeSteps, 0, steps, 0, stepsStartPos);
    System.arraycopy(thisSteps, 0, steps, stepsStartPos, thisSteps.length);
}
 
Example 10
Project: incubator-netbeans   File: TerminalContainerCommon.java   View Source Code Vote up 5 votes
/**
    * Return Attributes associated with 'comp'.
    * Create and attach of none exist.
    * @param comp
    * @return
    */
   protected final Attributes attributesFor(JComponent comp) {
Object o = comp.getClientProperty(PROP_ATTRIBUTES);
if (o == null) {
    Attributes a = new Attributes();
    comp.putClientProperty(PROP_ATTRIBUTES, a);
    return a;
} else {
    return (Attributes) o;
}
   }
 
Example 11
Project: incubator-netbeans   File: ToolbarContainer.java   View Source Code Vote up 5 votes
/**
 * Register toolbar content for drag and drop.
 */
private void registerDnd() {
    for( Component c : toolbar.getComponents() ) {
        if( !(c instanceof JComponent) )
            continue;
        JComponent jc = (JComponent) c;
        Object o = jc.getClientProperty("file");
        //is the component to register a draggable toolbar button?
        if( !(o instanceof DataObject) )
            continue;
        dnd.register(c);
    }
    if( isDraggable() && null != dragger )
        dnd.register(dragger);
}
 
Example 12
Project: incubator-netbeans   File: FilterCondition.java   View Source Code Vote up 5 votes
final boolean isValueValid(JComponent cmp) {
    Boolean valid = (Boolean) cmp.getClientProperty(PROP_VALUE_VALID);
    if (valid == null) {
        return true;
    } else {
        return valid.booleanValue();
    }
}
 
Example 13
Project: rapidminer   File: OnboardingDialog.java   View Source Code Vote up 5 votes
private void decorateJComponent(JComponent component) {
    String prop = (String)component.getClientProperty("com.rapidminer.ui.label.type");
    if("header".equals(prop)) {
        component.setFont(OPEN_SANS_LIGHT_28);
        component.setForeground(SwingTools.RAPIDMINER_ORANGE);
    } else if("bold".equals(prop)) {
        component.setFont(OPEN_SANS_SEMIBOLD_14);
        component.setForeground(Color.DARK_GRAY);
    } else if("normal".equals(prop)) {
        component.setFont(OPEN_SANS_LIGHT_14);
        component.setForeground(Color.DARK_GRAY);
    } else if("large".equals(prop)) {
        component.setFont(OPEN_SANS_SEMIBOLD_16);
        component.setForeground(Color.DARK_GRAY);
    }

    prop = (String)component.getClientProperty("com.rapidminer.ui.button.type");
    if("cfa".equals(prop)) {
        component.setFont(OPEN_SANS_SEMIBOLD_14);
        component.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
    } else if("normal".equals(prop)) {
        component.setFont(OPEN_SANS_LIGHT_14);
        component.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        component.setMinimumSize(new Dimension(175, component.getPreferredSize().height));
        component.setPreferredSize(new Dimension(175, component.getPreferredSize().height));
    }

    prop = (String)component.getClientProperty("com.rapidmniner.ui.link_button.id");
    if(prop != null && component instanceof LinkButton) {
        ((LinkButton)component).setText(this.generateHTML(prop));
    }

    Color foregroundColor = (Color)component.getClientProperty("com.rapidminer.ui.label.foreground");
    if(foregroundColor != null) {
        component.setForeground(foregroundColor);
    }

}
 
Example 14
Project: incubator-netbeans   File: IOWindow.java   View Source Code Vote up 5 votes
JButton[] getTabButtons(JComponent comp) {
    JButton[] buttons = (JButton[]) comp.getClientProperty(TOOLBAR_BUTTONS_PROP);
    if (buttons != null) {
        return buttons;
    }
    Action[] actions = (Action[]) comp.getClientProperty(TOOLBAR_ACTIONS_PROP);
    if (actions == null) {
        return new JButton[0];
    }

    buttons = new JButton[actions.length];
    for (int i=0; i < buttons.length; i++) {
        buttons[i] = new JButton(actions[i]);
        buttons[i].setBorderPainted(false);
        buttons[i].setOpaque(false);
        buttons[i].setText(null);
        buttons[i].putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
        Object icon = actions[i].getValue(Action.SMALL_ICON);
        if (!(icon instanceof Icon)) {
            throw new IllegalStateException ("No icon provided for " + actions[i]); //NOI18N
        }
        buttons[i].setDisabledIcon(ImageUtilities.createDisabledIcon((Icon) icon));
        String name = (String) actions[i].getValue(Action.NAME);
        String shortDescription = (String) actions[i].getValue(Action.SHORT_DESCRIPTION);
        String longDescription = (String) actions[i].getValue(Action.LONG_DESCRIPTION);
        if (name == null) name = shortDescription;
        if (longDescription == null) longDescription = shortDescription;
        buttons[i].getAccessibleContext().setAccessibleName(name);
        buttons[i].getAccessibleContext().setAccessibleDescription(longDescription);
    }
    return buttons;
}
 
Example 15
Project: incubator-netbeans   File: AddServerInstanceWizard.java   View Source Code Vote up 5 votes
private int getContentSelectedIndex() {
    if (iterator.current().equals(getChooser())) {
        return 0;
    } else {
        JComponent component = (JComponent) iterator.current().getComponent();
        Integer componentIndex = (Integer) component.getClientProperty(PROP_CONTENT_SELECTED_INDEX);
        if (componentIndex != null) {
            return componentIndex.intValue() + 1;
        } else {
            return 1;
        }
    }
}
 
Example 16
Project: rapidminer   File: PopupBorder.java   View Source Code Vote up 4 votes
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
	JComponent popup = (JComponent) c;
	g.translate(x, y);
	try {
		this.bottomLeft = (Image) popup.getClientProperty(RoundedPopupFactory.BOTTOM_LEFT_PIC);
		if (this.bottomLeft != null) {
			g.drawImage(this.bottomLeft, 0, h - 5, c);
		}

		this.bottomRight = (Image) popup.getClientProperty(RoundedPopupFactory.BOTTOM_RIGHT_PIC);
		if (this.bottomRight != null) {
			g.drawImage(this.bottomRight, w - 5, h - 5, c);
		}

		this.right = (Image) popup.getClientProperty(RoundedPopupFactory.RIGHT_PIC);
		if (this.right != null) {
			g.drawImage(this.right, w - 1, 0, c);
		}

		this.bottom = (Image) popup.getClientProperty(RoundedPopupFactory.BOTTOM_PIC);
		if (this.bottom != null) {
			g.drawImage(this.bottom, 5, h - 1, c);
		}
	} catch (Exception exp) {
		// do nothing
	}

	if (ShadowedPopupMenuBorder.POPUP_BOTTOM_LEFT != null) {
		g.drawImage(ShadowedPopupMenuBorder.POPUP_BOTTOM_LEFT, 0, h - 5, popup);
	}
	if (ShadowedPopupMenuBorder.POPUP_BOTTOM_RIGHT != null) {
		g.drawImage(ShadowedPopupMenuBorder.POPUP_BOTTOM_RIGHT, w - 5, h - 5, popup);
	}

	ColorUIResource c1 = new ColorUIResource(150, 150, 150);
	Color c4 = new Color(160, 160, 160, 100);
	ColorUIResource c2 = new ColorUIResource(135, 135, 135);

	g.setColor(UIManager.getColor("MenuItem.background"));
	g.drawLine(1, 0, w - 4, 0);
	g.drawLine(1, 1, w - 4, 1);
	g.drawLine(1, 0, 1, h - 7);
	g.drawLine(5, h - 3, w - 6, h - 3);
	g.setColor(UIManager.getColor("MenuItem.fadingColor"));
	g.drawLine(w - 3, 2, w - 3, h - 5);

	g.setColor(c1);
	g.drawLine(0, 0, 0, h - 6);
	g.setColor(c4);
	g.drawLine(5, h - 1, w - 6, h - 1);
	g.drawLine(w - 1, 2, w - 1, h - 6);

	g.setColor(c2);
	g.drawLine(w - 2, 0, w - 2, h - 6);
	g.drawLine(5, h - 2, w - 6, h - 2);

	g.translate(-x, -y);
}
 
Example 17
Project: rapidminer   File: ToggleButtonUI.java   View Source Code Vote up 4 votes
@Override
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;

	Dimension size = b.getSize();
	FontMetrics fm = g.getFontMetrics();

	Insets i = c.getInsets();

	Rectangle viewRect = new Rectangle(size);

	viewRect.x += i.left;
	viewRect.y += i.top;
	viewRect.width -= i.right + viewRect.x;
	viewRect.height -= i.bottom + viewRect.y;

	Rectangle iconRect = new Rectangle();
	Rectangle textRect = new Rectangle();

	Font f = c.getFont();
	g.setFont(f);

	String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), b.getVerticalAlignment(),
			b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect,
			textRect, b.getText() == null ? 0 : b.getIconTextGap());

	g.setColor(b.getBackground());

	if (b.isContentAreaFilled()) {
		if (RapidLookTools.isToolbarButton(b)) {
			RapidLookTools.drawToolbarButton(g, b);
		} else {
			RapidLookTools.drawButton(b, g, RapidLookTools.createShapeForButton(b));
		}
	}

	if (b.getIcon() != null) {
		paintIcon(g, b, iconRect);
	}

	if (text != null && !text.equals("")) {
		View v = (View) c.getClientProperty(BasicHTML.propertyKey);
		if (v != null) {
			v.paint(g, textRect);
		} else {
			paintText(g, b, textRect, text);
		}
	}

	if (b.isFocusPainted() && b.hasFocus()) {
		paintFocus(g, b, viewRect, textRect, iconRect);
	}

	if (!RapidLookTools.isToolbarButton(b)) {
		if (b.isBorderPainted()) {
			RapidLookTools.drawButtonBorder(b, g, RapidLookTools.createBorderShapeForButton(b));
		}
	}
}
 
Example 18
Project: incubator-netbeans   File: DefaultTabbedContainerUI.java   View Source Code Vote up 4 votes
public void layoutContainer(Container parent) {
    JComponent c = tabDisplayer;
    
    Object orientation = c.getClientProperty (
        TabDisplayer.PROP_ORIENTATION);
    
    Dimension d = tabDisplayer.getPreferredSize();
    Insets ins = container.getInsets();
    int width = parent.getWidth() - (ins.left + ins.right);
    int height = parent.getHeight() - (ins.top + ins.bottom);
    
    if (orientation == TabDisplayer.ORIENTATION_NORTH) {
        c.setBounds (ins.left, ins.top, 
            width, d.height);
        
        contentDisplayer.setBounds (ins.left, ins.top + d.height, 
            width, 
            parent.getHeight() - (d.height + ins.top + ins.bottom));
        
    } else if (orientation == TabDisplayer.ORIENTATION_SOUTH) {
        contentDisplayer.setBounds (ins.top, ins.left, width, 
            parent.getHeight() - (d.height + ins.top + ins.bottom));
        
        c.setBounds (ins.left, parent.getHeight() - (d.height + ins.top + ins.bottom),
            width, d.height);
    } else if (orientation == TabDisplayer.ORIENTATION_EAST) {
        contentDisplayer.setBounds (ins.left, ins.top, width - d.width,
            height);
        
        c.setBounds (parent.getWidth() - (ins.right + d.width), ins.top, 
            d.width, height);
        
    } else if (orientation == TabDisplayer.ORIENTATION_WEST) {
        c.setBounds (ins.left, ins.top, d.width, height);
        
        contentDisplayer.setBounds (ins.left + d.width, ins.top, 
            width - d.width, height);
        
    } else {
        throw new IllegalArgumentException ("Unknown orientation: " + orientation);
    }
}
 
Example 19
Project: ramus   File: CloseableTabbedPane.java   View Source Code Vote up 4 votes
/**
 * Draw the icon at the specified location. Icon implementations may use
 * the Component argument to get properties useful for painting, e.g.
 * the foreground or background color.
 *
 * @param c the component which the icon belongs to
 * @param g the graphic object to draw on
 * @param x the upper left point of the icon in the x direction
 * @param y the upper left point of the icon in the y direction
 */
public void paintIcon(Component c, Graphics g, int x, int y) {
    boolean doPaintCloseIcon = true;
    try {
        // JComponent.putClientProperty("isClosable", new
        // Boolean(false));
        JTabbedPane tabbedpane = (JTabbedPane) c;
        int tabNumber = tabbedpane.getUI().tabForCoordinate(tabbedpane,
                x, y);
        JComponent curPanel = (JComponent) tabbedpane
                .getComponentAt(tabNumber);
        Object prop = null;
        if ((prop = curPanel.getClientProperty("isClosable")) != null) {
            doPaintCloseIcon = (Boolean) prop;
        }
    } catch (Exception ignored) {/*
                                 * Could probably be a
		 * ClassCastException
		 */
    }
    if (doPaintCloseIcon) {
        x_pos = x;
        y_pos = y;
        int y_p = y + 1;

        if (normalCloseIcon != null && !mouseover) {
            normalCloseIcon.paintIcon(c, g, x, y_p);
        } else if (hooverCloseIcon != null && mouseover
                && !mousepressed) {
            hooverCloseIcon.paintIcon(c, g, x, y_p);
        } else if (pressedCloseIcon != null && mousepressed) {
            pressedCloseIcon.paintIcon(c, g, x, y_p);
        } else {
            y_p++;

            Color col = g.getColor();

            if (mousepressed && mouseover) {
                g.setColor(Color.WHITE);
                g.fillRect(x + 1, y_p, 12, 13);
            }

            g.setColor(Color.black);
            g.drawLine(x + 1, y_p, x + 12, y_p);
            g.drawLine(x + 1, y_p + 13, x + 12, y_p + 13);
            g.drawLine(x, y_p + 1, x, y_p + 12);
            g.drawLine(x + 13, y_p + 1, x + 13, y_p + 12);
            g.drawLine(x + 3, y_p + 3, x + 10, y_p + 10);
            if (mouseover)
                g.setColor(Color.GRAY);
            g.drawLine(x + 3, y_p + 4, x + 9, y_p + 10);
            g.drawLine(x + 4, y_p + 3, x + 10, y_p + 9);
            g.drawLine(x + 10, y_p + 3, x + 3, y_p + 10);
            g.drawLine(x + 10, y_p + 4, x + 4, y_p + 10);
            g.drawLine(x + 9, y_p + 3, x + 3, y_p + 9);
            g.setColor(col);
            if (fileIcon != null) {
                fileIcon.paintIcon(c, g, x + width, y_p);
            }
        }
    }
}
 
Example 20
Project: incubator-netbeans   File: EditorRegistry.java   View Source Code Vote up 2 votes
static Item item(JComponent c) {
    return (Item)c.getClientProperty(Item.class);

}