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

The following examples show how to use javax.swing.JComponent#getClientProperty() . 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
Source File: DefaultTabbedContainerUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: TextComponentPainter.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: FlatTextFieldUI.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
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 );
}
 
Example 4
Source File: TestbedSidePanel.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
}
 
Example 5
Source File: FilterUtils.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example 6
Source File: DialogFooter.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example 7
Source File: ComponentPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Dimension getSize(JComponent component) {
    Object object = component.getClientProperty(PrintManager.PRINT_SIZE);

    if (object instanceof Dimension) {
        return (Dimension) object;
    }
    return null;
}
 
Example 8
Source File: JComponentByLabelFinder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: NimbusDefaults.java    From Java8CN with Apache License 2.0 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 10
Source File: VectorImageInspector.java    From pumpernickel with MIT License 5 votes vote down vote up
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;
}
 
Example 11
Source File: GridUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: ContextualMenuHelper.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 13
Source File: TerminalContainerCommon.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
    * 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 14
Source File: FlatClientProperties.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: PopupBorder.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@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 16
Source File: ContextualMenuHelper.java    From PyramidShader with GNU General Public License v3.0 4 votes vote down vote up
/** 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();
}
 
Example 17
Source File: EditorActionUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static boolean isUseLargeIcon(JComponent c) {
    Object prefIconSize = c.getClientProperty("PreferredIconSize"); //NOI18N
    return (prefIconSize instanceof Integer) && (((Integer) prefIconSize).intValue() >= LARGE_ICON_SIZE);
}
 
Example 18
Source File: TableHeaderRendererSortedState.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean isInState(JComponent c) {
    String sortOrder = (String) c.getClientProperty("Table.sortOrder");

    return sortOrder != null && ("ASCENDING".equals(sortOrder) || "DESCENDING".equals(sortOrder));
}
 
Example 19
Source File: MultiThumbSliderUI.java    From pumpernickel with MIT License 3 votes vote down vote up
/**
 * 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;
}
 
Example 20
Source File: EditorRegistry.java    From netbeans with Apache License 2.0 2 votes vote down vote up
static Item item(JComponent c) {
    return (Item)c.getClientProperty(Item.class);

}