code
stringlengths 67
466k
| docstring
stringlengths 1
13.2k
|
---|---|
protected String constructSecurityControllerId(String commandFaceId) {
String id = null;
String formModelId = getFormModel().getId();
if (commandFaceId != null) {
id = (formModelId != null) ? formModelId + "." + commandFaceId : commandFaceId;
}
return id;
} | Construct a default security controller Id for a given command face id.
The id will be a combination of the form model id, if any, and the face
id.
<p>
<code>[formModel.id] + "." + [commandFaceId]</code> if the form model
id is not null.
<p>
<code>[commandFaceId]</code> if the form model is null.
<p>
<code>null</code> if the commandFaceId is null.
@param commandFaceId
@return default security controller id |
public ValidationResultsReporter newSingleLineResultsReporter(Messagable messageReceiver) {
SimpleValidationResultsReporter reporter = new SimpleValidationResultsReporter(
formModel.getValidationResults(), messageReceiver);
return reporter;
} | Construct the validation results reporter for this form and attach it to
the provided Guarded object. An instance of
{@link SimpleValidationResultsReporter} will be constructed and returned.
All registered child forms will be attached to the same
<code>guarded</code> and <code>messageReceiver</code> as this form. |
private void putPropertyConstraint(PropertyConstraint constraint) {
And and = new And();
and.add(constraint);
if (logger.isDebugEnabled()) {
logger.debug("Putting constraint for property '" + constraint.getPropertyName() + "', constraint -> ["
+ constraint + "]");
}
PropertyConstraint compoundConstraint = new CompoundPropertyConstraint(and);
propertiesConstraints.put(constraint.getPropertyName(), compoundConstraint);
orderedConstraints.add( compoundConstraint );
} | Put a constraint into the collection. Store it in the map under the property
name and add it to the ordered list.
@param constraint to add |
public Rules add(PropertyConstraint constraint) {
CompoundPropertyConstraint and = (CompoundPropertyConstraint)propertiesConstraints.get(constraint
.getPropertyName());
if (and == null) {
putPropertyConstraint(constraint);
}
else {
and.add(constraint);
}
return this;
} | Adds the provided bean property expression (constraint) to the list of
constraints for the constrained property.
@param constraint
the bean property expression
@return this, to support chaining. |
public void add(String propertyName, Constraint[] valueConstraints) {
add(new PropertyValueConstraint(propertyName, all(valueConstraints)));
} | Adds a value constraint for the specified property.
@param propertyName
The property name.
@param valueConstraints
The value constraint. |
protected JComponent createDialogContentPane() {
pageControl = new JPanel(new BorderLayout());
JPanel titlePaneContainer = new JPanel(new BorderLayout());
setMessage(getDescription());
titlePaneContainer.add(titlePane.getControl());
titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
pageControl.add(titlePaneContainer, BorderLayout.NORTH);
contentPane = createTitledDialogContentPane();
if (getPreferredSize() != null) {
contentPane.setPreferredSize(getPreferredSize());
}
GuiStandardUtils.attachDialogBorder(contentPane);
pageControl.add(contentPane);
return pageControl;
} | {@inheritDoc}
Creates an additional panel at the top containing a title/message area.
This can be used in conjunction with validation reporters to show the
most recent error or to simply show a title and a description of the
current Dialog.
Use {@link #createTitledDialogContentPane()} to add your custom components. |
public JComponent[] add(String fieldName, String attributes) {
return addBinding(createDefaultBinding(fieldName), attributes, getLabelAttributes());
} | Adds the field to the form. {@link #createDefaultBinding(String)} is used to create the binding for the field
@param fieldName
the name of the field to add
@param attributes
optional layout attributes for the component. See {@link TableLayoutBuilder} for syntax details
@return an array containing the label and the component which where added to the form |
public JComponent[] add(Binding binding, String attributes) {
return addBinding(binding, attributes, getLabelAttributes());
} | Adds the field binding to the form.
@param binding
the field binding to add
@param attributes
optional layout attributes for the component. See {@link TableLayoutBuilder} for syntax details
@return an array containing the label and the component which where added to the form |
public JComponent[] add(String fieldName, JComponent component, String attributes) {
return addBinding(createBinding(fieldName, component), attributes, getLabelAttributes());
} | Adds the field to the form by using the provided component. {@link #createBinding(String, JComponent)} is used to
create the binding of the field
@param fieldName
the name of the field to add
@param component
the component for the field
@param attributes
optional layout attributes for the component. See {@link TableLayoutBuilder} for syntax details
@return an array containing the label and the component which where added to the form |
public JComponent[] addSelector(String fieldName, Constraint filter, String attributes) {
Map context = new HashMap();
context.put(ComboBoxBinder.FILTER_KEY, filter);
return addBinding(getBindingFactory().createBinding(JComboBox.class, fieldName), attributes,
getLabelAttributes());
} | Adds the field to the form by using a selector component.
@param fieldName
the name of the field to add
@param filter
optional filter constraint for the items of the selector
@param attributes
optional layout attributes for the selector component. See {@link TableLayoutBuilder} for syntax
details
@return an array containing the label and the selector component which where added to the form |
public JComponent[] addPasswordField(String fieldName, String attributes) {
return addBinding(createBinding(fieldName, createPasswordField(fieldName)), attributes, getLabelAttributes());
} | Adds the field to the form by using a password component. {@link #createPasswordField(String)} is used to create
the component for the password field
@param fieldName
the name of the field to add
@param attributes
optional layout attributes for the password component. See {@link TableLayoutBuilder} for syntax
details
@return an array containing the label and the password component which where added to the form
@see #createPasswordField(String) |
public JComponent[] addTextArea(String fieldName, String attributes) {
JComponent textArea = createTextArea(fieldName);
String labelAttributes = getLabelAttributes();
if (labelAttributes == null) {
labelAttributes = VALIGN_TOP;
} else if (!labelAttributes.contains(TableLayoutBuilder.VALIGN)) {
labelAttributes += " " + VALIGN_TOP;
}
return addBinding(createBinding(fieldName, textArea), new JScrollPane(textArea), attributes, labelAttributes);
} | Adds the field to the form by using a text area component which is wrapped inside a scrollpane.
{@link #createTextArea(String)} is used to create the component for the text area field
<p>
Note: this method ensures that the the label of the textarea has a top vertical alignment if <code>valign</code>
is not defined in the default label attributes
@param fieldName
the name of the field to add
@param attributes
optional layout attributes for the scrollpane. See {@link TableLayoutBuilder} for syntax details
@return an array containing the label, the textarea and the scrollpane and which where added to the form
@see #createTextArea(String) |
public JComponent[] addInScrollPane(String fieldName, String attributes) {
return addInScrollPane(createDefaultBinding(fieldName), attributes);
} | Adds the field to the form by using the default binding. The component will be placed inside a scrollpane.
@param fieldName
the name of the field to add
@param attributes
optional layout attributes for the scrollpane. See {@link TableLayoutBuilder} for syntax details
@return an array containing the label, the component of the field binding and the scrollpane binding which where
added to the form
@see #createScrollPane(String, JComponent) |
public JComponent[] addInScrollPane(Binding binding, String attributes) {
Assert.isTrue(getFormModel() == binding.getFormModel(),
"Binding's form model must match FormBuilder's form model");
return add(binding.getProperty(), createScrollPane(binding.getProperty(), binding.getControl()), attributes);
} | Adds the field binding to the form. The component will be placed inside a scrollpane.
{@link #createScrollPane(String, JComponent)} is used to create the component for the scrollpane
@param binding
the binding to use
@param attributes
optional layout attributes for the scrollpane. See {@link TableLayoutBuilder} for syntax details
@return an array containing the label, the component of the field binding and the scrollpane and the component of
the binding which where added to the form
@see #createScrollPane(String, JComponent) |
public JComponent addSeparator(String text, String attributes) {
JComponent separator = getComponentFactory().createLabeledSeparator(text);
getLayoutBuilder().cell(separator, attributes);
return separator;
} | Adds a labeled separator to the form
@param text
the key for the label. Must not be null
@param attributes
optional attributes. See {@link TableLayoutBuilder} for syntax details |
public JComponent[] addBinding(Binding binding, String attributes, String labelAttributes) {
return addBinding(binding, binding.getControl(), attributes, labelAttributes);
} | adds a field binding to the form. This method does not use the default label attributes which may have been set
through {@link #setLabelAttributes(String)}
@param binding
the binding of the field
@param attributes
optional layout attributes for the label. If null no layout attributes will be applied to the label.
See {@link TableLayoutBuilder} for syntax details
@return an array containing the label and the component of the binding |
public JComponent[] addBinding(Binding binding, JComponent wrappedControl, String attributes) {
return addBinding(binding, wrappedControl, attributes, getLabelAttributes());
} | adds a field binding to the form
@param binding
the binding of the field
@param wrappedControl
the optional wrapped component. If null the component of the binding is used. This Parameter should be
used if the component of the binding is being wrapped inside this component
@param attributes
optional layout attributes for the label. If null no layout attributes will be applied to the label.
See {@link TableLayoutBuilder} for syntax details
@return an array containing the label, the component of the field binding and the wrapped component |
public JComponent[] addBinding(Binding binding, JComponent wrappedComponent, String attributes,
String labelAttributes) {
Assert.notNull(binding, "binding is null");
Assert.isTrue(getFormModel() == binding.getFormModel(),
"Binding's form model must match FormBuilder's form model");
JComponent component = binding.getControl();
final JLabel label = createLabelFor(binding.getProperty(), component);
if (wrappedComponent == null) {
wrappedComponent = component;
}
TableLayoutBuilder layoutBuilder = getLayoutBuilder();
if (!layoutBuilder.hasGapToLeft()) {
layoutBuilder.gapCol();
}
layoutBuilder.cell(label, labelAttributes);
layoutBuilder.labelGapCol();
layoutBuilder.cell(wrappedComponent, attributes);
return new JComponent[] { label, component, wrappedComponent };
} | adds a field binding to the form
@param binding
the binding of the field
@param wrappedComponent
the optional wrapped component. If null the component of the binding is used. This Parameter should be
used if the component of the binding is being wrapped inside this component
@param attributes
optional layout attributes for the wrapped component. If null no layout attributes will be applied to
the component. See {@link TableLayoutBuilder} for syntax details
@param attributes
optional layout attributes for the label. If null no layout attributes will be applied to the label.
See {@link TableLayoutBuilder} for syntax details
@return an array containing the label, the component of the field binding and the wrapped component |
protected Object[] getSourceValues() {
Object[] values = new Object[sourceValueModels.length];
for (int i = 0; i < values.length; i++) {
values[i] = sourceValueModels[i].getValue();
}
return values;
} | Convenience method to extract values from all sourceValueModels that
influence the derived value.
@return an <code>Array</code> containing the source values in the same
order as the source valueModels were defined. |
public void setFrameIcon(Icon newIcon) {
Icon oldIcon = getFrameIcon();
titleLabel.setIcon(newIcon);
firePropertyChange("frameIcon", oldIcon, newIcon);
} | Sets a new frame icon.
@param newIcon
the icon to be set |
public void setTitle(String newText) {
String oldText = getTitle();
titleLabel.setText(newText);
firePropertyChange("title", oldText, newText);
} | Sets a new title text.
@param newText
the title text tp be set |
public void setToolBar(JToolBar newToolBar) {
JToolBar oldToolBar = getToolBar();
if (oldToolBar == newToolBar) {
return;
}
if (oldToolBar != null) {
headerPanel.remove(oldToolBar);
}
if (newToolBar != null) {
newToolBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
headerPanel.add(newToolBar, BorderLayout.EAST);
}
updateHeader();
firePropertyChange("toolBar", oldToolBar, newToolBar);
} | Sets a new tool bar in the header.
@param newToolBar
the tool bar to be set in the header |
public void setContent(Component newContent) {
Component oldContent = getContent();
if (hasContent()) {
remove(oldContent);
}
add(newContent, BorderLayout.CENTER);
firePropertyChange("content", oldContent, newContent);
} | Sets a new panel content; replaces any existing content, if existing.
@param newContent
the panel's new content |
public void setSelected(boolean newValue) {
boolean oldValue = isSelected();
isSelected = newValue;
updateHeader();
firePropertyChange("selected", oldValue, newValue);
} | This panel draws its title bar differently if it is selected, which may
be used to indicate to the user that this panel has the focus, or should
get more attention than other simple internal frames.
@param newValue
a boolean, where true means the frame is selected (currently
active) and false means it is not |
private JPanel buildHeader(JLabel label, JToolBar bar) {
gradientPanel = new GradientPanel(new BorderLayout(), getHeaderBackground());
label.setOpaque(false);
gradientPanel.add(label, BorderLayout.WEST);
gradientPanel.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 1));
headerPanel = new JPanel(new BorderLayout());
headerPanel.add(gradientPanel, BorderLayout.CENTER);
setToolBar(bar);
headerPanel.setBorder(new RaisedHeaderBorder());
headerPanel.setOpaque(false);
return headerPanel;
} | Creates and answers the header panel, that consists of: an icon, a title
label, a tool bar, and a gradient background.
@param label
the label to paint the icon and text
@param bar
the panel's tool bar
@return the panel's built header area |
private void updateHeader() {
gradientPanel.setBackground(getHeaderBackground());
gradientPanel.setOpaque(isSelected());
titleLabel.setForeground(getTextForeground(isSelected()));
headerPanel.repaint();
} | Updates the header. |
protected Color getTextForeground(boolean selected) {
Color c = UIManager.getColor(selected ? "SimpleInternalFrame.activeTitleForeground"
: "SimpleInternalFrame.inactiveTitleForeground");
if (c != null) {
return c;
}
return UIManager.getColor(selected ? "InternalFrame.activeTitleForeground" : "Label.foreground");
} | Determines and answers the header's text foreground color. Tries to
lookup a special color from the L&F. In case it is absent, it uses
the standard internal frame forground.
@param selected
true to lookup the active color, false for the inactive
@return the color of the foreground text |
protected Color getHeaderBackground() {
Color c = UIManager.getColor("SimpleInternalFrame.activeTitleBackground");
return c != null ? c : UIManager.getColor("InternalFrame.activeTitleBackground");
} | Determines and answers the header's background color. Tries to lookup a
special color from the L&F. In case it is absent, it uses the
standard internal frame background.
@return the color of the header's background |
protected Object getUserMetadataFor(String propertyPath, String key) {
final Map allMetadata = getAllUserMetadataFor(propertyPath);
return allMetadata != null ? allMetadata.get(key) : null;
} | Subclasses may override this method to supply user metadata for the
specified <code>propertyPath</code> and <code>key</code>. The
default implementation invokes {@link #getAllUserMetadataFor(String)} and
uses the returned Map with the <code>key</code> parameter to find the
correlated value.
@param propertyPath path of property relative to this bean
@param key
@return metadata associated with the specified key for the property or
<code>null</code> if there is no custom metadata associated with the
property and key. |
protected String getFullPropertyPath(String propertyPath) {
if (basePropertyPath.equals("")) {
return propertyPath;
}
else if (propertyPath.equals("")) {
return basePropertyPath;
}
else {
return basePropertyPath + '.' + propertyPath;
}
} | Returns a property path that includes the base property path of the
class. |
protected String getPropertyName(String propertyPath) {
int lastSeparator = getLastPropertySeparatorIndex(propertyPath);
if (lastSeparator == -1) {
return propertyPath;
}
if (propertyPath.charAt(lastSeparator) == PropertyAccessor.NESTED_PROPERTY_SEPARATOR_CHAR)
return propertyPath.substring(lastSeparator + 1);
return propertyPath.substring(lastSeparator);
} | Extracts the property name from a propertyPath. |
protected String getParentPropertyPath(String propertyPath) {
int lastSeparator = getLastPropertySeparatorIndex(propertyPath);
return lastSeparator == -1 ? "" : propertyPath.substring(0, lastSeparator);
} | Returns the property name component of the provided property path. |
protected int getLastPropertySeparatorIndex(String propertyPath) {
boolean inKey = false;
for (int i = propertyPath.length() - 1; i >= 0; i--) {
switch (propertyPath.charAt(i)) {
case PropertyAccessor.PROPERTY_KEY_SUFFIX_CHAR:
inKey = true;
break;
case PropertyAccessor.PROPERTY_KEY_PREFIX_CHAR:
return i;
case PropertyAccessor.NESTED_PROPERTY_SEPARATOR_CHAR:
if (!inKey) {
return i;
}
break;
}
}
return -1;
} | Returns the index of the last nested property separator in the given
property path, ignoring dots in keys (like "map[my.key]"). |
protected void setId(String id) {
if (!StringUtils.hasText(id)) {
id = null;
}
this.id = id;
} | Set the id. In most cases, this is provided by the constructor or through
the beanId provided in the applicationContext.
@param id |
public void setFaceDescriptors(Map faceDescriptors) {
Assert.notNull(faceDescriptors);
Iterator it = faceDescriptors.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String faceDescriptorId = (String) entry.getKey();
CommandFaceDescriptor faceDescriptor = (CommandFaceDescriptor) entry.getValue();
setFaceDescriptor(faceDescriptorId, faceDescriptor);
}
} | Add a number of {@link CommandFaceDescriptor}s to this Command.
@param faceDescriptors a {@link Map} which contains <faceDescriptorId,
CommandFaceDescriptor> pairs. |
public void afterPropertiesSet() {
if (getId() == null) {
logger.info("Command " + this + " has no set id; note: anonymous commands cannot be used in registries.");
}
if (this instanceof ActionCommand && !isFaceConfigured()) {
logger.info("The face descriptor property is not yet set for action command '" + getId()
+ "'; configuring");
}
} | Performs initialisation and validation of this instance after its
dependencies have been set. If subclasses override this method, they
should begin by calling {@code super.afterPropertiesSet()}. |
private CommandFaceDescriptor getOrCreateFaceDescriptor() {
if (!isFaceConfigured()) {
if (logger.isInfoEnabled()) {
logger.info("Lazily instantiating default face descriptor on behalf of caller to prevent npe; "
+ "command is being configured manually, right?");
}
if(ValkyrieRepository.isCurrentlyRunningInContext()) {
ValkyrieRepository.getInstance().getApplicationConfig().commandConfigurer().configure(this);
} else {
setFaceDescriptor(new CommandFaceDescriptor());
}
}
return getFaceDescriptor();
} | Returns the defaultFaceDescriptor. Creates one if needed. |
protected CommandServices getCommandServices() {
if (commandServices == null) {
commandServices = ValkyrieRepository.getInstance().getApplicationConfig().commandServices();
}
return this.commandServices;
} | Returns the {@link CommandServices} for this {@link AbstractCommand}. |
public void setAuthorized(boolean authorized) {
boolean wasAuthorized = isAuthorized();
if (hasChanged(wasAuthorized, authorized)) {
this.authorized = authorized;
firePropertyChange(AUTHORIZED_PROPERTY, wasAuthorized, authorized);
updatedEnabledState();
}
} | Set the authorized state. Setting authorized to false will override any
call to {@link #setEnabled(boolean)}. As long as this object is
unauthorized, it can not be enabled.
@param authorized Pass <code>true</code> if the object is to be
authorized |
protected void updatedEnabledState() {
boolean isEnabled = isEnabled();
if (oldEnabledState == null || hasChanged(oldEnabledState.booleanValue(), isEnabled)) {
firePropertyChange(ENABLED_PROPERTY_NAME, oldEnabledState == null ? !isEnabled : oldEnabledState
.booleanValue(), isEnabled);
}
oldEnabledState = Boolean.valueOf(isEnabled);
} | This method is called when any predicate for enabled state has changed.
This implementation fires the enabled changed event if the return value
of {@link #isEnabled()} has changed.
<p>
Subclasses which have an additional predicate to enabled state must call
this method if the state of the predicate changes. |
protected final Iterator buttonIterator() {
if (this.faceButtonManagers == null)
return Collections.EMPTY_SET.iterator();
return new NestedButtonIterator(this.faceButtonManagers.values().iterator());
} | Returns an iterator over <em>all</em> buttons by traversing
<em>each</em> {@link CommandFaceButtonManager}. |
protected void updatedVisibleState() {
boolean isVisible = isVisible();
if (oldVisibleState == null || hasChanged(oldVisibleState.booleanValue(), isVisible)) {
firePropertyChange(VISIBLE_PROPERTY_NAME, oldVisibleState == null ? !isVisible : oldVisibleState
.booleanValue(), isVisible);
}
oldVisibleState = Boolean.valueOf(isVisible);
} | <p>
This method is called when any predicate for visible state has changed.
This implementation fires the visible changed event if the return value
of {@link #isVisible()} has changed.
</p>
<p>
Subclasses which have an additional predicate to visible state must call
this method if the state of the predicate changes.
</p> |
public final AbstractButton createButton(String faceDescriptorId, ButtonFactory buttonFactory) {
return createButton(faceDescriptorId, buttonFactory, getDefaultButtonConfigurer());
} | Create a button using the default buttonConfigurer.
@see #createButton(String, ButtonFactory, CommandButtonConfigurer) |
public final AbstractButton createButton(ButtonFactory buttonFactory, CommandButtonConfigurer buttonConfigurer) {
return createButton(getDefaultFaceDescriptorId(), buttonFactory, buttonConfigurer);
} | Create a button using the default buttonFactory.
@see #createButton(String, ButtonFactory, CommandButtonConfigurer) |
public AbstractButton createButton(String faceDescriptorId, ButtonFactory buttonFactory,
CommandButtonConfigurer buttonConfigurer) {
AbstractButton button = buttonFactory.createButton();
attach(button, faceDescriptorId, buttonConfigurer);
return button;
} | Creates a button using the provided id, factory and configurer.
@param faceDescriptorId id of the faceDescriptor used to configure the
button.
@param buttonFactory factory that delivers the button.
@param buttonConfigurer configurer mapping the faceDescriptor on the
button.
@return a button attached to this command. |
public final JMenuItem createMenuItem(String faceDescriptorId, MenuFactory menuFactory) {
return createMenuItem(faceDescriptorId, menuFactory, getMenuItemButtonConfigurer());
} | Create a menuItem using the default and menuItemButtonConfigurer.
@see #createMenuItem(String, MenuFactory, CommandButtonConfigurer) |
public final JMenuItem createMenuItem(MenuFactory menuFactory, CommandButtonConfigurer buttonConfigurer) {
return createMenuItem(getDefaultFaceDescriptorId(), menuFactory, buttonConfigurer);
} | Create a menuItem using the default faceDescriptorId.
@see #createMenuItem(String, MenuFactory, CommandButtonConfigurer) |
public JMenuItem createMenuItem(String faceDescriptorId, MenuFactory menuFactory,
CommandButtonConfigurer buttonConfigurer) {
JMenuItem menuItem = menuFactory.createMenuItem();
attach(menuItem, faceDescriptorId, buttonConfigurer);
return menuItem;
} | Create a menuItem using the provided id, factory and configurer.
@param faceDescriptorId id of the faceDescriptor used to configure the
button.
@param menuFactory factory that delivers the menuItem.
@param buttonConfigurer configurer mapping the faceDescriptor on the
button.
@return a menuItem attached to this command. |
public void attach(AbstractButton button, String faceDescriptorId, CommandButtonConfigurer configurer) {
getButtonManager(faceDescriptorId).attachAndConfigure(button, configurer);
onButtonAttached(button);
} | Attach and configure the button to the faceDescriptorId using the configurer.
@param button the button to attach and configure.
@param faceDescriptorId the id of the faceDescriptor.
@param configurer that maps the faceDescriptor on the button. |
protected void onButtonAttached(AbstractButton button) {
if (logger.isDebugEnabled()) {
logger.debug("Configuring newly attached button for command '" + getId() + "' enabled=" + isEnabled()
+ ", visible=" + isVisible());
}
button.setEnabled(isEnabled());
button.setVisible(isVisible());
} | Additional code to execute when attaching a button.
@param button the button that has been attached. |
public void detach(AbstractButton button) {
if (getDefaultButtonManager().isAttachedTo(button)) {
getDefaultButtonManager().detach(button);
onButtonDetached();
}
} | Detach the button from the {@link CommandFaceButtonManager}.
@param button the button to detach. |
private CommandFaceButtonManager getButtonManager(String faceDescriptorId) {
if (this.faceButtonManagers == null) {
this.faceButtonManagers = new AbstractCachingMapDecorator() {
protected Object create(Object key) {
return new CommandFaceButtonManager(AbstractCommand.this, (String) key);
}
};
}
CommandFaceButtonManager m = (CommandFaceButtonManager) this.faceButtonManagers.get(faceDescriptorId);
return m;
} | Returns the {@link CommandFaceButtonManager} for the given
faceDescriptorId.
@param faceDescriptorId id of the {@link CommandFaceDescriptor}.
@return the {@link CommandFaceButtonManager} managing buttons configured
with the {@link CommandFaceDescriptor}. |
public boolean requestFocusIn(Container container) {
AbstractButton button = getButtonIn(container);
if (button != null) {
return button.requestFocusInWindow();
}
return false;
} | Search for a button representing this command in the provided container
and let it request the focus.
@param container the container which holds the command button.
@return <code>true</code> if the focus request is likely to succeed.
@see #getButtonIn(Container)
@see JComponent#requestFocusInWindow() |
public AbstractButton getButtonIn(Container container) {
Iterator it = buttonIterator();
while (it.hasNext()) {
AbstractButton button = (AbstractButton) it.next();
if (SwingUtilities.isDescendingFrom(button, container)) {
return button;
}
}
return null;
} | Search for the first button of this command that is a child component of
the given container.
@param container the container to be searched.
@return the {@link AbstractButton} representing this command that is
embedded in the container or <code>null</code> if none was found. |
public boolean hasValueChanged(Object oldValue, Object newValue) {
if( oldValue != null && classesWithSafeEquals.contains( oldValue.getClass() ) )
return !oldValue.equals( newValue );
return oldValue != newValue;
} | Determines if there has been a change in value between the provided arguments. As
many objects do not implement #equals in a manner that is strict enough for the
requirements of this class, difference is determined using <code>!=</code>,
however, to improve accuracy #equals will be used when this is definitely safe e.g.
for Strings, Booleans, Numbers, Dates.
@param oldValue Original object value
@param newValue New object value
@return true if the objects are different enough to indicate a change in the value
model |
public PropertyColumn addPropertyColumn(String propertyName, Class<?> propertyType)
{
String[] headerKeys = getMessageResolver().getMessageKeys(this.id, propertyName, MessageConstants.HEADER);
Accessor accessor = ClassUtils.getAccessorForProperty(entityClass, propertyName);
if (propertyType == null)
propertyType = accessor.getPropertyType();
PropertyColumn propertyColumn = new PropertyColumn(propertyName, accessor, propertyType);
if (String.class.isAssignableFrom(propertyColumn.getType()))
propertyColumn.setFilterColumn(true);
propertyColumn.setHeaderKeys(headerKeys);
columns.add(propertyColumn);
return propertyColumn;
} | Create and add a column for the given property. Property type is passed or determined (when
<code>null</code>) by examining the {@link Accessor} and headerKeys are added based upon the id of
the {@link PropertyColumnTableDescription}, the propertyName and the postfix "HEADER".
@param propertyName
name of the property.
@param propertyType
type of the property. If <code>null</code> a type will be determined by examining the
accessor method. |
public void addPropertyColumn(String propertyName, Class propertyType, TableCellEditor editor)
{
addPropertyColumn(propertyName).withEditor(editor);
} | WARNING: propertyType is discarded, it should be fetched from the entityType through introspection.
@deprecated
@see #addPropertyColumn(String)
@see PropertyColumn#withEditor(javax.swing.table.TableCellEditor) |
public void addPropertyColumn(String propertyName, Class propertyType, TableCellRenderer renderer)
{
addPropertyColumn(propertyName).withRenderer(renderer);
} | WARNING: propertyType is discarded, it should be fetched from the entityType through introspection.
@deprecated
@see #addPropertyColumn(String)
@see PropertyColumn#withRenderer(TableCellRenderer) |
public void addPropertyColumn(String propertyName, Class propertyType, int minWidth, int maxWidth)
{
addPropertyColumn(propertyName).withMinWidth(minWidth).withMaxWidth(maxWidth);
} | WARNING: propertyType is discarded, it should be fetched from the entityType through introspection.
@deprecated
@see #addPropertyColumn(String)
@see PropertyColumn#withMinWidth(int)
@see PropertyColumn#withMaxWidth(int) |
public void addPropertyColumn(String propertyName, Class propertyType, String[] headerKeys, int minWidth,
int maxWidth, boolean resizable, TableCellRenderer renderer, Boolean isInTextFilter,
Comparator comparator)
{
addPropertyColumn(propertyName).withHeaderKeys(headerKeys).withMinWidth(minWidth).withMaxWidth(maxWidth)
.withResizable(resizable).withRenderer(renderer).withComparator(comparator).withFilterColumn(
isInTextFilter);
} | WARNING: propertyType is discarded, it should be fetched from the entityType through introspection.
@deprecated
@see #addPropertyColumn(String)
@see PropertyColumn#withComparator(Comparator)
@see PropertyColumn#withMinWidth(int)
@see PropertyColumn#withMaxWidth(int)
@see PropertyColumn#withResizable(boolean)
@see PropertyColumn#withRenderer(TableCellRenderer) |
public String[] getPropertiesInTextFilter()
{
List<String> filterProperties = new ArrayList<String>(getColumnCount());
for (PropertyColumn column : columns)
{
if (column.isFilterColumn())
filterProperties.add(column.getPropertyName());
}
return filterProperties.toArray(new String[filterProperties.size()]);
} | {@inheritDoc} |
public Object getValue(Object rowObject, int propertyIndex)
{
try
{
return getPropertyColumn(propertyIndex).getAccessor().getValue(rowObject);
}
catch (Exception e)
{
log.warn("Error reading property " + propertyIndex + " from object " + rowObject, e);
throw new RuntimeException("Error reading property " + propertyIndex + " from object "
+ rowObject, e);
}
} | {@inheritDoc} |
public void setValue(Object rowObject, int propertyIndex, Object newValue)
{
try
{
Accessor accessor = getPropertyColumn(propertyIndex).getAccessor();
if (accessor instanceof Writer)
((Writer) accessor).setValue(rowObject, newValue);
}
catch (Exception e)
{
log.warn("Error writing property " + propertyIndex + " to object " + rowObject
+ " new value: " + newValue, e);
throw new RuntimeException("Error writing property " + propertyIndex + " to object " + rowObject
+ " new value: " + newValue, e);
}
} | {@inheritDoc} |
public void addSeparator() {
if (container instanceof JMenu) {
((JMenu)container).addSeparator();
}
else if (container instanceof JPopupMenu) {
((JPopupMenu)container).addSeparator();
}
else if (container instanceof JToolBar) {
((JToolBar)container).addSeparator();
}
else {
container.add(new JSeparator(SwingConstants.VERTICAL));
}
} | {@inheritDoc} |
public String getMessage(Constraint constraint) {
String objectName = null;
if (constraint instanceof PropertyConstraint) {
objectName = ((PropertyConstraint) constraint).getPropertyName();
}
String message = buildMessage(objectName, null, constraint);
return message;
} | /*
(non-Javadoc)
@see org.springframework.rules.reporting.MessageTranslator#getMessage(org.springframework.rules.constraint.Constraint) |
protected void visit(CompoundConstraint compoundConstraint) {
Iterator it = compoundConstraint.iterator();
String compoundMessage = getMessageCode(compoundConstraint);
while (it.hasNext()) {
Constraint p = (Constraint) it.next();
visitorSupport.invokeVisit(this, p);
if (it.hasNext()) {
add(compoundMessage, null, compoundMessage);
}
}
} | Visit function for compound constraints like And/Or/XOr.
<p>syntax: <code>CONSTRAINT MESSAGE{code} CONSTRAINT</code></p>
@param compoundConstraint |
protected String getMessageCode(Object o) {
if (o instanceof TypeResolvable) {
String type = ((TypeResolvable) o).getType();
if (type != null) {
return type;
}
}
return ClassUtils.getShortNameAsProperty(o.getClass());
} | Determines the messageCode (key in messageSource) to look up.
If <code>TypeResolvable</code> is implemented, user can give a custom code,
otherwise the short className is used.
@param o
@return |
public static void initializeClass(Class clazz) {
try {
Class.forName(clazz.getName(), true, Thread.currentThread().getContextClassLoader());
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} | Intializes the specified class if not initialized already.
This is required for EnumUtils if the enum class has not yet been loaded. |
public static String getClassFieldNameWithValue(Class clazz, Object value) {
Field[] fields = clazz.getFields();
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
try {
Object constant = field.get(null);
if (value.equals(constant)) {
return clazz.getName() + "." + field.getName();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
return null;
} | Returns the qualified class field name with the specified value. For
example, with a class defined with a static field "NORMAL" with value =
"0", passing in "0" would return: className.NORMAL.
@return The qualified field. |
public static Object getFieldValue(String qualifiedFieldName) {
Class clazz;
try {
clazz = classForName(ClassUtils.qualifier(qualifiedFieldName));
}
catch (ClassNotFoundException cnfe) {
return null;
}
try {
return clazz.getField(ClassUtils.unqualify(qualifiedFieldName)).get(null);
}
catch (Exception e) {
return null;
}
} | Gets the field value for the specified qualified field name. |
public static Class classForName(String name) throws ClassNotFoundException {
try {
return Thread.currentThread().getContextClassLoader().loadClass(name);
}
catch (Exception e) {
return Class.forName(name);
}
} | Load the class with the specified name.
@param name
@return The loaded class.
@throws ClassNotFoundException |
public static String qualifier(String qualifiedName) {
int loc = qualifiedName.lastIndexOf('.');
if (loc < 0)
return "";
return qualifiedName.substring(0, loc);
} | Returns the qualifier for a name separated by dots. The qualified part is
everything up to the last dot separator.
@param qualifiedName The qualified name.
@return The qualifier portion. |
public static Class convertPrimitiveToWrapper(Class clazz) {
if (clazz == null || !clazz.isPrimitive())
return clazz;
return (Class) primativeToWrapperMap.get(clazz);
} | Gets the equivalent class to convert to if the given clazz is a
primitive.
@param clazz Class to examin.
@return the class to convert to or the inputted clazz. |
public static Object getValueFromMapForClass(final Class typeClass, final Map classMap) {
Object val = classMap.get(typeClass);
if (val == null) {
// search through the interfaces first
val = getValueFromMapForInterfaces(typeClass, classMap);
if (val == null) {
// now go up through the inheritance hierarchy
val = getValueFromMapForSuperClass(typeClass, classMap);
}
if (val == null) {
// not found anywhere
if (logger.isDebugEnabled()) {
logger.debug("Could not find a definition for " + typeClass + " in " + classMap.keySet());
}
return null;
}
// remember this so it doesn't have to be looked-up again
classMap.put(typeClass, val);
return val;
}
return val;
} | Given a {@link Map}where the keys are {@link Class}es, search the map
for the closest match of the key to the <tt>typeClass</tt>. This is
extremely useful to support polymorphism (and an absolute requirement to
find proxied classes where classes are acting as keys in a map).
<p />
For example: If the Map has keys of Number.class and String.class, using
a <tt>typeClass</tt> of Long.class will find the Number.class entry and
return its value.
<p />
When doing the search, it looks for the most exact match it can, giving
preference to interfaces over class inheritance. As a performance
optimiziation, if it finds a match it stores the derived match in the map
so it does not have to be derived again.
@param typeClass the kind of class to search for
@param classMap the map where the keys are of type Class
@return null only if it can't find any match |
public static boolean isAProperty(Class theClass, String propertyName) {
if (theClass == null)
throw new IllegalArgumentException("theClass == null");
if (propertyName == null)
throw new IllegalArgumentException("propertyName == null");
if (getReadMethod(theClass, propertyName) != null)
return true;
if (getWriteMethod(theClass, propertyName) != null)
return true;
return false;
} | Is the given name a property in the class? In other words, does it have a
setter and/or a getter method?
@param theClass the class to look for the property in
@param propertyName the name of the property
@return true if there is either a setter or a getter for the property
@throws IllegalArgumentException if either argument is null |
public static Class getPropertyClass(Class parentClass, String propertyName) throws IllegalArgumentException {
if (parentClass == null)
throw new IllegalArgumentException("theClass == null");
if (propertyName == null)
throw new IllegalArgumentException("propertyName == null");
final Method getterMethod = getReadMethod(parentClass, propertyName);
if (getterMethod != null) {
return getterMethod.getReturnType();
}
final Method setterMethod = getWriteMethod(parentClass, propertyName);
if (setterMethod != null) {
return setterMethod.getParameterTypes()[0];
}
throw new IllegalArgumentException(propertyName + " is not a property of " + parentClass);
} | Returns the class of the property.
<p />
For example, getPropertyClass(JFrame.class, "size") would return the
java.awt.Dimension class.
@param parentClass the class to look for the property in
@param propertyName the name of the property
@return the class of the property; never null
@throws IllegalArgumentException if either argument is null
@throws IllegalArgumentException <tt>propertyName</tt> is not a
property of <tt>parentClass</tt> |
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof ApplicationWindowAware) {
((ApplicationWindowAware)bean).setApplicationWindow(window);
}
return bean;
} | If the given bean is an implementation of {@link ApplicationWindowAware}, it will have its
application window set to the window provided to this instance at construction time. |
public void setTitle(String title)
{
super.setTitle(title);
if ((this.widget instanceof TitleConfigurable) && (this.titledWidgetId == null))
((TitleConfigurable) this.widget).setTitle(title);
} | {@inheritDoc} |
public void addPropertyChangeListener(String property, PropertyChangeListener propertyChangeListener)
{
if (this.widget instanceof Messagable)
((Messagable) this.widget).addPropertyChangeListener(property, propertyChangeListener);
} | {@inheritDoc} |
public void removePropertyChangeListener(String property, PropertyChangeListener propertyChangeListener)
{
if (this.widget instanceof Messagable)
((Messagable) this.widget).removePropertyChangeListener(property, propertyChangeListener);
} | {@inheritDoc} |
protected void setTargetClass(Class targetClass) {
this.targetClass = targetClass;
this.readAccessors.clear();
this.writeAccessors.clear();
introspectMethods(targetClass, new HashSet());
if (isFieldAccessEnabled()) {
introspectFields(targetClass, new HashSet());
}
} | Clears all cached members and introspect methods again. If fieldAccess is
enabled introspect fields as well.
@param targetClass the target class. |
private void introspectFields(Class type, Set introspectedClasses) {
if (type == null || Object.class.equals(type) || type.isInterface() || introspectedClasses.contains(type)) {
return;
}
introspectedClasses.add(type);
introspectFields(type.getSuperclass(), introspectedClasses);
Field[] fields = type.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
if (!Modifier.isStatic(fields[i].getModifiers())) {
readAccessors.put(fields[i].getName(), fields[i]);
if (!Modifier.isFinal(fields[i].getModifiers())) {
writeAccessors.put(fields[i].getName(), fields[i]);
}
}
}
} | Introspect fields of a class. This excludes static fields and handles
final fields as readOnly.
@param type the class to inspect.
@param introspectedClasses a set of already inspected classes. |
private void introspectMethods(Class type, Set introspectedClasses) {
if (type == null || Object.class.equals(type) || introspectedClasses.contains(type)) {
return;
}
introspectedClasses.add(type);
Class[] interfaces = type.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
introspectMethods(interfaces[i], introspectedClasses);
}
introspectMethods(type.getSuperclass(), introspectedClasses);
Method[] methods = type.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
String methodName = methods[i].getName();
if (methodName.startsWith("get") && methods[i].getParameterTypes().length == 0) {
readAccessors.put(getPropertyName(methodName, 3), methods[i]);
}
else if (methodName.startsWith("is") && methods[i].getParameterTypes().length == 0) {
readAccessors.put(getPropertyName(methodName, 2), methods[i]);
}
else if (methodName.startsWith("set") && methods[i].getParameterTypes().length == 1) {
writeAccessors.put(getPropertyName(methodName, 3), methods[i]);
}
}
} | Introspect class for accessor methods. This includes methods starting
with 'get', 'set' and 'is'.
@param type class to introspect.
@param introspectedClasses set of already inspected classes. |
protected Member getPropertyAccessor(String propertyName) {
if (readAccessors.containsKey(propertyName)) {
return (Member) readAccessors.get(propertyName);
}
else {
return (Member) writeAccessors.get(propertyName);
}
} | Return any accessor, be it read or write, for the given property.
@param propertyName name of the property.
@return an accessor for the property or <code>null</code> |
public boolean isReadableProperty(String propertyName) {
if (PropertyAccessorUtils.isIndexedProperty(propertyName)) {
String rootProperty = getRootPropertyName(propertyName);
String parentProperty = getParentPropertyName(propertyName);
return isReadableProperty(rootProperty)
&& checkKeyTypes(propertyName)
&& (!getPropertyType(parentProperty).isArray() || checkSize(propertyName) || isWritableProperty(parentProperty))
&& ((isReadableProperty(parentProperty) && getPropertyValue(parentProperty) != null) || isWritableProperty(parentProperty));
}
else {
return readAccessors.containsKey(propertyName);
}
} | {@inheritDoc} |
public boolean isWritableProperty(String propertyName) {
if (PropertyAccessorUtils.isIndexedProperty(propertyName)) {
// if an indexed property is readable it is writable, too
return isReadableProperty(propertyName);
}
else {
return writeAccessors.containsKey(propertyName);
}
} | {@inheritDoc} |
public Class getPropertyType(String propertyName) {
if (PropertyAccessorUtils.isIndexedProperty(propertyName)) {
int nestingLevel = PropertyAccessorUtils.getNestingLevel(propertyName);
if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) {
Member accessor = getPropertyAccessor(getRootPropertyName(propertyName));
if (accessor instanceof Field) {
return GenericCollectionTypeResolver.getIndexedValueFieldType((Field) accessor, nestingLevel);
}
else {
Method accessorMethod = (Method) accessor;
MethodParameter parameter = new MethodParameter(accessorMethod,
accessorMethod.getParameterTypes().length - 1);
return GenericCollectionTypeResolver.getIndexedValueMethodType(parameter, nestingLevel);
}
}
else {
// we can only resolve array types in Java 1.4
Class type = getPropertyType(getRootPropertyName(propertyName));
for (int i = 0; i < nestingLevel; i++) {
if (type.isArray()) {
type = type.getComponentType();
}
else {
return Object.class; // cannot resolve type
}
}
return type;
}
}
else {
Member readAccessor = (Member) readAccessors.get(propertyName);
if (readAccessor instanceof Field) {
return ((Field) readAccessor).getType();
}
else if (readAccessor instanceof Method) {
return ((Method) readAccessor).getReturnType();
}
Member writeAccessor = (Member) writeAccessors.get(propertyName);
if (writeAccessor instanceof Field) {
return ((Field) writeAccessor).getType();
}
else if (writeAccessor instanceof Method) {
return ((Method) writeAccessor).getParameterTypes()[0];
}
}
return null;
} | {@inheritDoc} |
public Class getIndexedPropertyKeyType(String propertyName) {
if (!PropertyAccessorUtils.isIndexedProperty(propertyName)) {
throw new IllegalArgumentException("'" + propertyName + "' is no indexed property");
}
Class type = getPropertyType(getParentPropertyName(propertyName));
if (!Map.class.isAssignableFrom(type)) {
return Integer.class;
}
if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) {
int nestingLevel = PropertyAccessorUtils.getNestingLevel(propertyName) - 1;
Member accessor = getPropertyAccessor(getRootPropertyName(propertyName));
if (accessor instanceof Field) {
return GenericCollectionTypeResolver.getMapKeyFieldType((Field) accessor, nestingLevel);
}
else if (accessor instanceof Method) {
MethodParameter parameter = new MethodParameter((Method) accessor, ((Method) accessor)
.getParameterTypes().length - 1, nestingLevel);
return GenericCollectionTypeResolver.getMapKeyParameterType(parameter);
}
else {
throw new InvalidPropertyException(getTargetClass(), propertyName, "property not accessable");
}
}
else {
return String.class; // the default for Java 1.4
}
} | Determine the type of the key used to index the collection/map. When jdk
is at least 1.5, maps can be specified with generics and their key type
can be resolved.
@param propertyName name of the property.
@return the type of the key. An integer if it's not a map, {@link String}
if the jdk is less than 1.5, a specific type if the map was generified. |
public Object getPropertyValue(String propertyName) throws BeansException {
if (PropertyAccessorUtils.isIndexedProperty(propertyName)) {
return getIndexedPropertyValue(propertyName);
}
else {
return getSimplePropertyValue(propertyName);
}
} | {@inheritDoc} |
public void setPropertyValue(String propertyName, Object value) throws BeansException {
if (PropertyAccessorUtils.isIndexedProperty(propertyName)) {
setIndexedPropertyValue(propertyName, value);
}
else {
setSimplePropertyValue(propertyName, value);
}
} | {@inheritDoc} |
protected String getPropertyName(String methodName, int prefixLength) {
return Character.toLowerCase(methodName.charAt(prefixLength)) + methodName.substring(prefixLength + 1);
} | Returns the propertyName based on the methodName. Cuts of the prefix and
removes first capital.
@param methodName name of method to convert.
@param prefixLength length of prefix to cut of.
@return property name. |
protected String getRootPropertyName(String propertyName) {
int location = propertyName.indexOf(PROPERTY_KEY_PREFIX);
return location == -1 ? propertyName : propertyName.substring(0, location);
} | Returns the root property of an indexed property. The root property is
the property that contains no indices.
@param propertyName the name of the property.
@return the root property. |
protected String getParentPropertyName(String propertyName) {
if (!PropertyAccessorUtils.isIndexedProperty(propertyName)) {
return "";
}
else {
return propertyName.substring(0, propertyName.lastIndexOf(PROPERTY_KEY_PREFIX_CHAR));
}
} | Return the parent property name of an indexed property or the empty string.
@param propertyName the name of the property.
@return the empty string or the parent property name if it was indexed. |
protected Object setAssemblageValue(Class assemblageType, Object assemblage, Object index, Object value) {
if (assemblageType.isArray()) {
int i = ((Integer) index).intValue();
if (Array.getLength(assemblage) <= i) {
Object newAssemblage = Array.newInstance(assemblageType.getComponentType(), i + 1);
System.arraycopy(assemblage, 0, newAssemblage, 0, Array.getLength(assemblage));
assemblage = newAssemblage;
}
Array.set(assemblage, i, value);
}
else if (List.class.isAssignableFrom(assemblageType)) {
int i = ((Integer) index).intValue();
List list = (List) assemblage;
if (list.size() > i) {
list.set(i, value);
}
else {
while (list.size() < i) {
list.add(null);
}
list.add(value);
}
}
else if (Map.class.isAssignableFrom(assemblageType)) {
((Map) assemblage).put(index, value);
}
else if (assemblage instanceof Collection) {
((Collection) assemblage).add(value);
}
else {
throw new IllegalArgumentException("assemblage must be of type array, collection or map.");
}
return assemblage;
} | Helper method for subclasses to set values of indexed properties, like
map-values, collection-values or array-values.
@param assemblageType either map or collection or array
@param assemblage the assemblage to set the value on
@param index the index to set the value at
@param value the value to set
@return the assemblage |
protected Binding createBinding(String fieldName, JComponent component) {
return getBindingFactory().bindControl(component, fieldName);
} | Create a binding that uses the given component instead of its default
component.
@param fieldName the name of the property to bind.
@param component the component to bind to the property.
@return the {@link Binding} that binds the component to the valuemodel of
the property. |
protected JComponent createSelector(String fieldName, Constraint filter) {
Map context = new HashMap();
context.put(ComboBoxBinder.FILTER_KEY, filter);
return getBindingFactory().createBinding(JComboBox.class, fieldName).getControl();
} | Creates a component which is used as a selector in the form. This
implementation creates a {@link JComboBox}
@param fieldName the name of the field for the selector
@param filter an optional filter constraint
@return the component to use for a selector, not null |
protected JLabel createLabelFor(String fieldName, JComponent component) {
JLabel label = getComponentFactory().createLabel("");
getFormModel().getFieldFace(fieldName).configure(label);
label.setLabelFor(component);
FormComponentInterceptor interceptor = getFormComponentInterceptor();
if (interceptor != null) {
interceptor.processLabel(fieldName, label);
}
return label;
} | Create a label for the property.
@param fieldName the name of the property.
@param component the component of the property which is related to the
label.
@return a {@link JLabel} for the property. |
public static Point getCenteringPointOnScreen(Dimension dimension) {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
if (dimension.width > screen.width) {
dimension.width = screen.width;
}
if (dimension.height > screen.height) {
dimension.height = screen.height;
}
return new Point((screen.width - dimension.width) / 2, (screen.height - dimension.height) / 2);
} | Return the centering point on the screen for the object with the
specified dimension.
@param dimension the dimension of an object
@return The centering point on the screen for that object. |
public static void centerOnScreenAndSetVisible(Window window) {
window.pack();
centerOnScreen(window);
window.setVisible(true);
} | Pack the window, center it on the screen, and set the window visible.
@param window the window to center and show. |
public static void centerOnScreen(Window window) {
Assert.notNull(window, "window cannot be null");
// This works around a bug in setLocationRelativeTo(...): it currently
// does not take multiple monitors into accounts on all operating
// systems.
try {
// Note that if this is running on a JVM prior to 1.4, then an
// exception will be thrown and we will fall back to
// setLocationRelativeTo(...).
final Rectangle screenBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
final Dimension windowSize = window.getSize();
final int x = screenBounds.x + ((screenBounds.width - windowSize.width) / 2);
final int y = screenBounds.y + ((screenBounds.height - windowSize.height) / 2);
window.setLocation(x, y);
}
catch (Throwable t) {
window.setLocationRelativeTo(window);
}
} | Take the window and center it on the screen.
<p>
This works around a bug in setLocationRelativeTo(...): it currently does
not take multiple monitors into accounts on all operating systems.
@param window the window to center |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.