javax.swing.JComponent#getClientProperty ( )源码实例Demo

下面列出了javax.swing.JComponent#getClientProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: DefaultTabbedContainerUI.java
public Dimension minimumLayoutSize(Container parent) {
    JComponent c = tabDisplayer;
    
    Object orientation = c.getClientProperty (
        TabDisplayer.PROP_ORIENTATION);
    
    Dimension tabSize = tabDisplayer.getPreferredSize();
    Insets ins = container.getInsets();
    
    Dimension result = new Dimension();
    
    Dimension contentSize = contentDisplayer.getPreferredSize();
    if (tabDisplayer.getSelectionModel().getSelectedIndex() == -1) {
        contentSize.width = 0;
        contentSize.height = 0;
    }
    
    if (orientation == TabDisplayer.ORIENTATION_NORTH || orientation == TabDisplayer.ORIENTATION_SOUTH) {
        result.height = ins.top + ins.bottom + contentSize.height + tabSize.height;
        result.width = ins.left + ins.right + Math.max (contentSize.width, tabSize.width);
    } else {
        result.width = ins.left + ins.right + contentSize.width + tabSize.width;
        result.height = ins.top + ins.bottom + Math.max (contentSize.height, tabSize.height);
    }
    return result;
}
 
源代码2 项目: visualvm   文件: FilterUtils.java
public static void filterSubclasses(String className, JComponent filterPanel) {
    Object filterString = filterPanel.getClientProperty("FILTER_STRING"); // NOI18N
    if (filterString instanceof JTextComponent) {
        ((JTextComponent)filterString).setText(className);
    } else {
        return;
    }

    Object filterType = filterPanel.getClientProperty("FILTER_TYPE"); // NOI18N
    if (filterType instanceof FilterType) {
        ((FilterType)filterType).filterImpl(FILTER_INSTANCEOF, Icons.getIcon(LanguageIcons.CLASS), Bundle.OQLFilterUtils_FilterSubclass());
    } else {
        return;
    }

    Object filterAction = filterPanel.getClientProperty("FILTER_ACTION"); // NOI18N
    if (filterAction instanceof AbstractAction) {
        ((AbstractAction)filterAction).actionPerformed(null);
    } else {
        return;
    }
}
 
源代码3 项目: jbox2d   文件: TestbedSidePanel.java
public void stateChanged(ChangeEvent e) {
  JComponent component = (JComponent) e.getSource();
  TestbedSetting setting = (TestbedSetting) component.getClientProperty(SETTING_TAG);

  switch (setting.constraintType) {
    case BOOLEAN:
      JCheckBox box = (JCheckBox) e.getSource();
      setting.enabled = box.isSelected();
      break;
    case RANGE:
      JSlider slider = (JSlider) e.getSource();
      setting.value = slider.getValue();
      JLabel label = (JLabel) slider.getClientProperty(LABEL_TAG);
      label.setText(setting.name + ": " + setting.value);
      break;
  }
  model.getPanel().grabFocus();
}
 
源代码4 项目: FlatLaf   文件: FlatTextFieldUI.java
static void paintPlaceholder( Graphics g, JTextComponent c, Color placeholderForeground ) {
	// check whether text component is empty
	if( c.getDocument().getLength() > 0 )
		return;

	// check for JComboBox
	Container parent = c.getParent();
	JComponent jc = (parent instanceof JComboBox) ? (JComboBox<?>) parent : c;

	// get placeholder text
	Object placeholder = jc.getClientProperty( FlatClientProperties.PLACEHOLDER_TEXT );
	if( !(placeholder instanceof String) )
		return;

	// compute placeholder location
	Insets insets = c.getInsets();
	FontMetrics fm = c.getFontMetrics( c.getFont() );
	int x = insets.left;
	int y = insets.top + fm.getAscent() + ((c.getHeight() - insets.top - insets.bottom - fm.getHeight()) / 2);

	// paint placeholder
	g.setColor( placeholderForeground );
	FlatUIUtils.drawString( c, g, (String) placeholder, x, y );
}
 
源代码5 项目: seaglass   文件: TextComponentPainter.java
/**
 * Test if we should also paint the line seperators.
 * @param c
 * @return
 */
private boolean isPaintLineSeperators(JComponent c) {
    boolean paintLines = c instanceof JTextArea;

    // Global settings
    String globalOverride = System.getProperty("SeaGlass.JTextArea.drawLineSeparator");
    if (globalOverride != null && globalOverride.length() > 0) {
        paintLines = Boolean.valueOf(globalOverride);
    }
    
    // Settings per component
    Boolean overrideProperty = (Boolean) c.getClientProperty("SeaGlass.JTextArea.drawLineSeparator");
    if (overrideProperty != null) {
        paintLines = overrideProperty;   
    }
    return paintLines;
}
 
源代码6 项目: netbeans   文件: ComponentPanel.java
private Dimension getSize(JComponent component) {
    Object object = component.getClientProperty(PrintManager.PRINT_SIZE);

    if (object instanceof Dimension) {
        return (Dimension) object;
    }
    return null;
}
 
源代码7 项目: pumpernickel   文件: DialogFooter.java
/**
 * This indicates that an action button risks losing user's data. On Macs an
 * unsafe button is spaced farther away from safe buttons.
 */
public static boolean isUnsafe(JComponent c) {
	Boolean b = (Boolean) c.getClientProperty(PROPERTY_UNSAFE);
	if (b == null)
		b = Boolean.FALSE;
	return b.booleanValue();
}
 
源代码8 项目: netbeans   文件: JComponentByLabelFinder.java
public boolean checkComponent(Component c) {
    if (c instanceof JComponent) {
        JComponent jc = (JComponent) c;
        Object o = jc.getClientProperty("labeledBy"); //NOI18N
        if (o != null && o instanceof JLabel) {
            JLabel lbl = (JLabel) o;
            return label.equals(lbl.getText().trim());
        }
    }
    return false;
}
 
源代码9 项目: Java8CN   文件: NimbusDefaults.java
/**
 * 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;
}
 
源代码10 项目: pumpernickel   文件: VectorImageInspector.java
BooleanProperty getPopupRequested(JComponent jc) {
	BooleanProperty b = (BooleanProperty) jc
			.getClientProperty(PROPERTY_POPUP_REQUESTED);
	if (b == null) {
		b = new BooleanProperty(PROPERTY_POPUP_REQUESTED, false);
		jc.putClientProperty(PROPERTY_POPUP_REQUESTED, b);
	}
	return b;
}
 
源代码11 项目: netbeans   文件: GridUtils.java
/**
 * Determines whether the specified component is a padding component.
 *
 * @param comp component to check.
 * @return {@code true} if the specified component is a padding component,
 * returns {@code false} otherwise.
 */
public static boolean isPaddingComponent(Component comp) {
    boolean padding = false;
    if (comp instanceof JComponent) {
        JComponent jcomp = (JComponent)comp;
        padding = jcomp.getClientProperty(PADDING_COMPONENT) != null;
    }
    return padding;
}
 
源代码12 项目: pumpernickel   文件: ContextualMenuHelper.java
/**
 * Return the ContextualMenuHelper the static helper methods refer to.
 * 
 * @param jc
 *            the component to retrieve a common ContextualMenuHelper for.
 * @return the common ContextualMenuHelper for the argument. This will
 *         create one if it doesn't already exist.
 */
public static ContextualMenuHelper getContextualMenuHelper(JComponent jc) {
	ContextualMenuHelper cmh = (ContextualMenuHelper) jc
			.getClientProperty(MENU_KEY);
	if (cmh == null) {
		cmh = new ContextualMenuHelper(jc);
		jc.putClientProperty(MENU_KEY, cmh);
	}
	return cmh;
}
 
源代码13 项目: netbeans   文件: TerminalContainerCommon.java
/**
    * 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;
}
   }
 
源代码14 项目: FlatLaf   文件: FlatClientProperties.java
/**
 * Checks whether a client property of a component is a color and returns its value.
 * If the client property is not set, or not a color, defaultValue is returned.
 */
static Color clientPropertyColor( JComponent c, String key, Color defaultValue ) {
	Object value = c.getClientProperty( key );
	return (value instanceof Color) ? (Color) value : defaultValue;
}
 
源代码15 项目: rapidminer-studio   文件: PopupBorder.java
@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);
}
 
源代码16 项目: PyramidShader   文件: ContextualMenuHelper.java
/** Clear any registered contextual menu information for this component.
 * 
 * @param component the component to purge all contextual menu info for.
 */
public static void clear(JComponent component) {
	ContextualMenuHelper cmh = (ContextualMenuHelper)component.getClientProperty(MENU_KEY);
	if(cmh==null) return;
	cmh.popup.removeAll();
}
 
源代码17 项目: netbeans   文件: EditorActionUtilities.java
public static boolean isUseLargeIcon(JComponent c) {
    Object prefIconSize = c.getClientProperty("PreferredIconSize"); //NOI18N
    return (prefIconSize instanceof Integer) && (((Integer) prefIconSize).intValue() >= LARGE_ICON_SIZE);
}
 
源代码18 项目: seaglass   文件: TableHeaderRendererSortedState.java
/**
 * {@inheritDoc}
 */
public boolean isInState(JComponent c) {
    String sortOrder = (String) c.getClientProperty("Table.sortOrder");

    return sortOrder != null && ("ASCENDING".equals(sortOrder) || "DESCENDING".equals(sortOrder));
}
 
源代码19 项目: pumpernickel   文件: MultiThumbSliderUI.java
/**
 * This retrieves a property. If the component has this property manually
 * set (by calling <code>component.putClientProperty()</code>), then that
 * value will be returned. Otherwise this method refers to
 * <code>UIManager.get()</code>. If that value is missing, this returns
 * <code>defaultValue</code>
 * 
 * @param jc
 * @param propertyName
 *            the property name
 * @param defaultValue
 *            if no other value is found, this is returned
 * @return the property value
 */
public static <K> K getProperty(JComponent jc, String propertyName,
		K defaultValue) {
	Object jcValue = jc.getClientProperty(propertyName);
	if (jcValue != null)
		return (K) jcValue;
	Object uiValue = UIManager.get(propertyName);
	if (uiValue != null)
		return (K) uiValue;
	return defaultValue;
}
 
源代码20 项目: netbeans   文件: EditorRegistry.java
static Item item(JComponent c) {
    return (Item)c.getClientProperty(Item.class);

}