List of usage examples for javax.swing JComponent getClientProperty
public final Object getClientProperty(Object key)
From source file:au.org.ala.delta.editor.DeltaEditor.java
/** * Loads a previously loaded delta file from the Most Recently Used list. It is assumed that the source ActionEvent as set the filename in a client property called "Filename". * /*w w w. j a v a 2s .c om*/ * @param e * The action event that triggered this action * @return A DeltaFileLoader task */ @Action(block = BlockingScope.APPLICATION) public DeltaFileLoader loadPreviousFile(ActionEvent e) { DeltaFileLoader fileOpenTask = null; JComponent item = (JComponent) e.getSource(); if (item != null) { String filename = (String) item.getClientProperty("Filename"); File toOpen = new File(filename); if (toOpen != null && toOpen.exists()) { fileOpenTask = new DeltaFileLoader(this, toOpen); fileOpenTask.addPropertyChangeListener(_statusBar); } else { JOptionPane.showMessageDialog(getMainFrame(), "File not found or not readable!", "File open failed", JOptionPane.ERROR_MESSAGE); item.getParent().remove(item); EditorPreferences.removeFileFromMRU(filename); } } return fileOpenTask; }
From source file:brainflow.app.toplevel.BrainFlow.java
private void showActionMenu(MouseEvent e) { Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); java.util.List<Action> actionList = new ArrayList<Action>(); while (true) { if (c instanceof IActionProvider) { IActionProvider provider = (IActionProvider) c; provider.addActions(e, actionList); } else if (c instanceof JComponent) { JComponent jc = (JComponent) c; Object provider = jc.getClientProperty(IActionProvider.KEY); if (provider != null) { ((IActionProvider) provider).addActions(e, actionList); }// w w w . j a v a 2 s . co m } Component p = c.getParent(); if (p != null) { c = p; } else { break; } } if (actionList.size() > 0) { createPopup(actionList).setVisible(true); } }
From source file:fxts.stations.ui.SideLayout.java
/** * Lays out the grid.// w ww . j a v a2 s.c om * * @param aParent the layout container */ protected void arrangeGrid(Container aParent) { ///////////////////////////////////////////////////////// //It`s only for debugging JComponent jc = (JComponent) aParent; String sType = (String) jc.getClientProperty("TYPE"); if (sType != null) { boolean bInternal = "internal".equals(sType); mLogger.debug("\n" + sType); } ////////////////////////////////////////////////////////// Component comp; int compindex; SideConstraints constraints; Insets insets = aParent.getInsets(); Component[] components = aParent.getComponents(); Dimension d; Rectangle r = new Rectangle(); int i, diffw, diffh; double weight; SideLayoutInfo info; mRightToLeft = !aParent.getComponentOrientation().isLeftToRight(); /* * If the parent has no slaves anymore, then don't do anything * at all: just leave the parent's size as-is. */ if (components.length == 0 && (mColumnWidths == null || mColumnWidths.length == 0) && (mRowHeights == null || mRowHeights.length == 0)) { return; } /* * Pass #1: scan all the slaves to figure out the total amount * of space needed. */ info = getLayoutInfo(aParent, PREFERREDSIZE); d = getMinSize(aParent, info); // // System.out.println("parent=w:" + parent.getWidth() + ",h:" + parent.getHeight() + // "min=w:" + d.getWidth() + ",h:" + d.getHeight()); if (aParent.getWidth() < d.width || aParent.getHeight() < d.height) { info = getLayoutInfo(aParent, MINSIZE); d = getMinSize(aParent, info); // // System.out.println("MINSIZE"); } else { // // System.out.println("Non MINSIZE"); } mLayoutInfo = info; r.width = d.width; r.height = d.height; /* * If the current dimensions of the window don't match the desired * dimensions, then adjust the minWidth and minHeight arrays * according to the weights. */ diffw = aParent.getWidth() - r.width; // // System.out.println("diffw=" + diffw); if (diffw != 0) { weight = 0.0; for (i = 0; i < info.width; i++) { weight += info.weightX[i]; } if (weight > 0.0) { for (i = 0; i < info.width; i++) { int dx = (int) (((double) diffw * info.weightX[i]) / weight); info.minWidth[i] += dx; r.width += dx; if (info.minWidth[i] < 0) { r.width -= info.minWidth[i]; info.minWidth[i] = 0; } } } diffw = aParent.getWidth() - r.width; } else { diffw = 0; } diffh = aParent.getHeight() - r.height; // // System.out.println("diffh=" + diffh); if (diffh != 0) { weight = 0.0; for (i = 0; i < info.height; i++) { weight += info.weightY[i]; } if (weight > 0.0) { for (i = 0; i < info.height; i++) { int dy = (int) (((double) diffh * info.weightY[i]) / weight); info.minHeight[i] += dy; r.height += dy; if (info.minHeight[i] < 0) { r.height -= info.minHeight[i]; info.minHeight[i] = 0; } } } diffh = aParent.getHeight() - r.height; } else { diffh = 0; } /* * Now do the actual layout of the slaves using the layout information * that has been collected. */ info.startx = /*diffw/2 +*/ insets.left; info.starty = /*diffh/2 +*/ insets.top; // // System.out.println("info.startx = " + info.startx); // System.out.println("info.starty = " + info.startx); for (compindex = 0; compindex < components.length; compindex++) { comp = components[compindex]; if (!comp.isVisible()) { continue; } constraints = lookupConstraints(comp); if (!mRightToLeft) { r.x = info.startx; for (i = 0; i < constraints.tempX; i++) { r.x += info.minWidth[i]; } } else { r.x = aParent.getWidth() - insets.right; for (i = 0; i < constraints.tempX; i++) { r.x -= info.minWidth[i]; } } r.y = info.starty; for (i = 0; i < constraints.tempY; i++) { r.y += info.minHeight[i]; } r.width = 0; for (i = constraints.tempX; i < constraints.tempX + constraints.tempWidth; i++) { r.width += info.minWidth[i]; } r.height = 0; for (i = constraints.tempY; i < constraints.tempY + constraints.tempHeight; i++) { r.height += info.minHeight[i]; } adjustForGravity(constraints, r); if (r.x < 0) { r.width -= r.x; r.x = 0; } if (r.y < 0) { r.height -= r.y; r.y = 0; } /* * If the window is too small to be interesting then * unmap it. Otherwise configure it and then make sure * it's mapped. */ if (r.width <= 0 || r.height <= 0) { comp.setBounds(0, 0, 0, 0); } else { if (comp.getX() != r.x || comp.getY() != r.y || comp.getWidth() != r.width || comp.getHeight() != r.height) { comp.setBounds(r.x, r.y, r.width, r.height); } } // System.out.println("Initial component size (x = " + (int)comp.getX() + // ", y = " + (int)(comp.getY()) + // ", widht = " + (int)(comp.getWidth()) + // ", height = " + (int)(comp.getHeight())); if (diffw > 0) { // System.out.println("It`s increasing by x!"); //if (comp instanceof IResizableComponent) { // System.out.println("It`s resizable component: " + comp); //IResizableComponent resizeComp = (IResizableComponent)comp; ResizeParameter param = constraints.resize; // System.out.println("Params: Left=" + param.getLeft() + ",top=" + param.getTop() + // ",Right=" + param.getRight() + ",bottom=" + param.getBottom()); comp.setBounds((int) (comp.getX() + diffw * param.getLeft()), comp.getY(), (int) (comp.getWidth() + diffw * (param.getRight() - param.getLeft())), comp.getHeight()); // System.out.println("Set Bounds (x = " + (int)(comp.getX() + diffw * param.getLeft()) + // ", y = " + (int)(comp.getY()) + // ", widht = " + (int)(comp.getWidth() + /// diffw * (param.getRight() - param.getLeft())) + // ", height = " + (int)(comp.getHeight())); // } } if (diffh > 0) { // System.out.println("It`s increasing by y!"); // if (comp instanceof IResizableComponent) { // System.out.println("It`s resizable component: " + comp); // IResizableComponent resizeComp = (IResizableComponent)comp; ResizeParameter param = constraints.resize; // System.out.println("Params: Left=" + param.getLeft() + ",top=" + param.getTop() + // ",Right=" + param.getRight() + ",bottom=" + param.getBottom()); comp.setBounds(comp.getX(), (int) (comp.getY() + diffh * param.getTop()), comp.getWidth(), (int) (comp.getHeight() + diffh * (param.getBottom() - param.getTop()))); // System.out.println("Set Bounds (x = " + (int)(comp.getX()) + // ", y = " + (int)(comp.getY() + diffh * param.getTop()) + // ", widht = " + (int)(comp.getWidth()) + // ", height = " + (int)(comp.getHeight() + // diffh * (param.getBottom() - param.getTop()))); // } } } }
From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java
private void markFieldInHistoricalView(CollectableGenericObjectWithDependants clctlowdCurrent, String sFieldName, CollectableField clctfShown) { if (clctlowdCurrent != null) { final CollectableField clctf = clctlowdCurrent.getField(sFieldName); if (!clctfShown.equals(clctf)) { final Collection<CollectableComponent> collclctcomp = layoutrootDetails .getCollectableComponentsFor(sFieldName); if (!collclctcomp.isEmpty()) { final CollectableComponent clctcomp = collclctcomp.iterator().next(); final JComponent compFocussable = clctcomp.getFocusableComponent(); String initialToolTip = (String) compFocussable.getClientProperty("initialToolTip"); if (initialToolTip == null) { initialToolTip = StringUtils.emptyIfNull(compFocussable.getToolTipText()); compFocussable.putClientProperty("initialToolTip", initialToolTip); }/*w w w . ja va2 s.co m*/ if (clctcomp instanceof CollectableComboBox) { CollectableComboBox clctcmbx = (CollectableComboBox) clctcomp; clctcmbx.getJComboBox().setRenderer(clctcmbx.new CollectableFieldRenderer() { @Override protected void paintComponent(Graphics g) { setBackground(colorHistoricalChanged); super.paintComponent(g); } }); } else compFocussable.setBackground(colorHistoricalChanged); final String sToolTip = getSpringLocaleDelegate().getMessage("GenericObjectCollectController.4", "{0} [Ge\u00e4ndert; aktueller Wert: \"{1}\"]", initialToolTip, clctf.toString()); compFocussable.setToolTipText(sToolTip); clctcomp.getJComponent().setToolTipText(sToolTip); // todo: mark fields which are not tracked in logbook? } } } }
From source file:org.nuclos.client.ui.resplan.header.JHeaderGrid.java
private void calculateGroupingExtents() { final Orientation groupOrient = orientation.opposite(); int preferredGroupingsExtent = 0; for (CategoryView categoryView : groupings) { int preferredCategorySize = 0; for (HeaderCell cell : categoryView.cells) { JComponent renderer = setupCellRenderer(cell.levelValue, false); Dimension preferredSize = renderer.getPreferredSize(); int preferredExtent = groupOrient.extentFrom(preferredSize); if (renderer instanceof JLabel) { // This is a some kind of hack for determing the preferred size of an HTML JLabel // using a given width or height. See also: // http://blog.nobel-joergensen.com/2009/01/18/changing-preferred-size-of-a-html-jlabel/ // NOTE: This seems to work for horizontal orientations (i.e. calculating the height for a // given width) while for vertical orientations often the dummy value 0 is returned. View view = (View) renderer.getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey); if (view != null) { float w = (orientation == Orientation.HORIZONTAL) ? cellExtent : 0; float h = (orientation == Orientation.VERTICAL) ? cellExtent : 0; view.setSize(w, h);// www .j ava 2 s. c om float span = (int) Math.ceil(view.getPreferredSpan(groupOrient.swingConstant())); preferredExtent = Math.max(preferredExtent, (int) Math.ceil(span)); } } preferredCategorySize = Math.max(preferredCategorySize, preferredExtent + 2); } categoryView.preferredSize = preferredCategorySize; categoryView.size = preferredCategorySize; preferredGroupingsExtent += preferredCategorySize + GRID_SIZE; } // Real size and preferred size may vary int realGroupingsExtent = groupOrient.extentFrom(getSize()); int delta = realGroupingsExtent - preferredGroupingsExtent; if (delta > 0) { int gap = delta / groupings.length; for (CategoryView v : groupings) { v.size += gap; } int rem = delta % groupings.length; if (rem > 0 && groupings.length > 0) { groupings[groupings.length - 1].size += rem; } } }
From source file:org.springframework.richclient.form.binding.support.AbstractBinder.java
public Binding bind(JComponent control, FormModel formModel, String formPropertyPath, Map context) { // Ensure that this component has not already been bound Binding binding = (Binding) control.getClientProperty(BINDING_CLIENT_PROPERTY_KEY); if (binding != null) { throw new IllegalStateException("Component is already bound to property: " + binding.getProperty()); }//from ww w . ja va2 s .c om validateContextKeys(context); binding = doBind(control, formModel, formPropertyPath, context); control.putClientProperty(BINDING_CLIENT_PROPERTY_KEY, binding); return binding; }