0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: package org.netbeans.modules.form.layoutsupport.delegates;
0043:
0044: import java.beans.*;
0045: import java.awt.*;
0046: import java.awt.event.*;
0047: import javax.swing.*;
0048: import java.util.*;
0049:
0050: import org.openide.nodes.*;
0051: import org.openide.explorer.propertysheet.PropertySheet;
0052: import org.openide.util.*;
0053: import org.netbeans.api.javahelp.Help;
0054:
0055: import org.netbeans.modules.form.*;
0056: import org.netbeans.modules.form.layoutsupport.LayoutSupportManager;
0057:
0058: /** A customizer providing better editing facility for GridBagLayout
0059: *
0060: * @author Petr Hrebejk
0061: */
0062: final public class GridBagCustomizer extends JPanel implements
0063: Customizer {
0064: /** bundle to obtain text information from */
0065: // private static java.util.ResourceBundle bundle = org.openide.util.NbBundle.getBundle(GridBagCustomizer.class);
0066: // -----------------------------------------------------------------------------
0067: // private area
0068: PropertyChangeSupport propertySupport = new PropertyChangeSupport(
0069: this );
0070:
0071: static final int TOP = 1;
0072: static final int BOTTOM = 2;
0073: static final int LEFT = 4;
0074: static final int RIGHT = 8;
0075:
0076: static final int HORIZONTAL = LEFT + RIGHT;
0077: static final int VERTICAL = TOP + BOTTOM;
0078:
0079: static final int PLUS = 1;
0080: static final int MINUS = -1;
0081:
0082: private static final ImageIcon REMAINDER_ICON = new ImageIcon(
0083: GridBagCustomizer.class
0084: .getResource("/org/netbeans/modules/form/layoutsupport/resources/remainder.gif")); // NOI18N
0085:
0086: // private DesignGridBagLayout designLayout;
0087: private GridBagLayoutSupport layoutSupport;
0088:
0089: private FormModel formModel;
0090: private FormModelListener formListener;
0091: private RADVisualContainer radContainer;
0092: private RADVisualComponent[] radComponents;
0093: private GBComponentProxy[] gbcProxies;
0094:
0095: // Customizer components
0096: private JSplitPane splitPane;
0097: private JPanel designPanel;
0098:
0099: private GridBagControlCenter controlCenter;
0100: private GBContainerProxy containerProxy;
0101: private PropertySheet propertySheet;
0102: private javax.swing.JScrollPane designScrollPane;
0103: private JLayeredPane designLayeredPane;
0104:
0105: private GBComponentProxy.DragLabel dragLabel = null;
0106:
0107: /** This is a hack. We need to now whether the GLC is painted first time
0108: * in order to paint empty cols and rows correctlly. Field is setted in
0109: * setObject() and Ppaint() methods.
0110: */
0111: private boolean firstPaint = false;
0112:
0113: static final long serialVersionUID = -632768048562391785L;
0114:
0115: public GridBagCustomizer() {
0116: initComponents();
0117: }
0118:
0119: private void initialize() {
0120:
0121: // initComponents();
0122:
0123: radContainer = ((LayoutSupportManager) layoutSupport
0124: .getLayoutSupportHack()).getMetaContainer(); // ugly hack
0125: formModel = radContainer.getFormModel();
0126: radComponents = radContainer.getSubComponents();
0127:
0128: gbcProxies = new GBComponentProxy[radComponents.length];
0129: for (int i = 0; i < radComponents.length; i++) {
0130: gbcProxies[i] = new GBComponentProxy(radComponents[i],
0131: containerProxy);
0132: }
0133:
0134: containerProxy.removeAll();
0135:
0136: FormDesigner designer = FormEditor.getFormDesigner(formModel);
0137: if (!designer.isInDesigner(radContainer)) {
0138: designer.setTopDesignComponent(radContainer, true);
0139: // terrible hack - wait for designer update
0140: invokeLater(2, new Runnable() {
0141: public void run() {
0142: containerProxy.addAllProxies();
0143: }
0144: });
0145: } else
0146: containerProxy.addAllProxies();
0147:
0148: formListener = new FormListener();
0149: formModel.addFormModelListener(formListener);
0150: }
0151:
0152: void customizerClosed() {
0153: formModel.removeFormModelListener(formListener);
0154: }
0155:
0156: /** inits the components of the customizer */
0157:
0158: private void initComponents() {
0159:
0160: setBorder(new javax.swing.border.EmptyBorder(4, 0, 8, 0));
0161: setLayout(new BorderLayout()); // [PENDING]
0162:
0163: propertySheet = new PropertySheet();
0164: try {
0165: propertySheet.setSortingMode(PropertySheet.UNSORTED);
0166: } catch (java.beans.PropertyVetoException e) {
0167: // ErrorManager.getDefault().notifyException(e);
0168: }
0169: propertySheet.setPreferredSize(new Dimension(300, 380));
0170:
0171: JPanel panel = new JPanel();
0172: panel.setLayout(new BorderLayout());
0173: panel.add(propertySheet, BorderLayout.CENTER);
0174: controlCenter = new GridBagControlCenter(this );
0175: panel.add(controlCenter, BorderLayout.SOUTH);
0176:
0177: designScrollPane = new javax.swing.JScrollPane();
0178: designPanel = new JPanel() {
0179: @Override
0180: public Dimension getPreferredSize() {
0181: //System.out.println(" THE pref size of DesignPanel " + containerProxy.getPreferredSize()); // NOI18N
0182: return containerProxy.getPreferredSize();
0183: }
0184: };
0185:
0186: designPanel.setLayout(new GridBagLayout());
0187: designPanel
0188: .setBackground((java.awt.Color) javax.swing.UIManager
0189: .getDefaults().get("desktop")); // NOI18N
0190: GridBagConstraints con = new GridBagConstraints();
0191: con.anchor = GridBagConstraints.CENTER;
0192: con.fill = GridBagConstraints.NONE;
0193: containerProxy = new GBContainerProxy();
0194:
0195: designPanel.add(containerProxy, con);
0196:
0197: designLayeredPane = new JLayeredPane() {
0198: @Override
0199: public Dimension getPreferredSize() {
0200:
0201: Dimension dpd = designPanel.getPreferredSize();
0202: Dimension spd = designScrollPane.getViewport()
0203: .getExtentSize();
0204:
0205: int width = Math.max(dpd.width + 40, spd.width);
0206: int height = Math.max(dpd.height + 40, spd.height);
0207:
0208: /*
0209: Dimension dpd = designPanel.getPreferredSize();
0210: Dimension spd = designScrollPane.getViewport().getExtentSize();
0211:
0212: return new Dimension(Math.max(dpd.width, spd.width), Math.max(dpd.height, spd.height));
0213: */
0214: //System.out.println(" THE GET " + new Dimension(Math.max(400, width), Math.max(300, height))); // NOI18N
0215: return new Dimension(Math.max(500, width), Math.max(
0216: 300, height));
0217: }
0218: };
0219:
0220: //designLayeredPane.setLayout(new BorderLayout());
0221:
0222: //designLayeredPane.setLayer(designPanel, JLayeredPane.DEFAULT_LAYER.intValue());
0223: designLayeredPane.add(designPanel, JLayeredPane.DEFAULT_LAYER);
0224: designPanel.setBounds(20, 20,
0225: designPanel.getPreferredSize().width, designPanel
0226: .getPreferredSize().height);
0227: designLayeredPane.setOpaque(true);
0228: designLayeredPane
0229: .setBackground((java.awt.Color) javax.swing.UIManager
0230: .getDefaults().get("desktop")); // NOI18N
0231:
0232: designScrollPane.setViewportView(designLayeredPane);
0233:
0234: splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
0235: splitPane.setLeftComponent(panel);
0236: splitPane.setRightComponent(designScrollPane);
0237: splitPane.setUI(new javax.swing.plaf.basic.BasicSplitPaneUI());
0238: splitPane.setBorder(BorderFactory.createEmptyBorder());
0239: splitPane.setContinuousLayout(true);
0240:
0241: add(splitPane, BorderLayout.CENTER);
0242:
0243: getAccessibleContext().setAccessibleDescription(
0244: GridBagLayoutSupport.getBundleHack().getString(
0245: "ACSD_GridBagCustomizer"));
0246: HelpCtx.setHelpIDString(this , "gui.layouts.gbcustomizer"); // NOI18N
0247: }
0248:
0249: void setAnchor(int anchor) {
0250: java.util.List<GBComponentProxy> selected = containerProxy
0251: .getSelectedProxies();
0252: Iterator<GBComponentProxy> it = selected.iterator();
0253: while (it.hasNext())
0254: // setProperty((GBComponentProxy)it.next(), DesignGridBagLayout.PROP_ANCHOR, new Integer(anchor));
0255: setProperty(it.next(), "anchor", new Integer(anchor)); // NOI18N
0256: }
0257:
0258: void setFill(int fill) {
0259: java.util.List<GBComponentProxy> selected = containerProxy
0260: .getSelectedProxies();
0261: Iterator<GBComponentProxy> it = selected.iterator();
0262: while (it.hasNext())
0263: // setProperty((GBComponentProxy)it.next(), DesignGridBagLayout.PROP_FILL, new Integer(fill));
0264: setProperty(it.next(), "fill", new Integer(fill)); // NOI18N
0265: };
0266:
0267: void modifyIPad(int action, int what) {
0268: java.util.List<GBComponentProxy> selected = containerProxy
0269: .getSelectedProxies();
0270: Iterator<GBComponentProxy> it = selected.iterator();
0271: while (it.hasNext()) {
0272: GBComponentProxy p = it.next();
0273: int value = what == HORIZONTAL ? p.getRealConstraints().ipadx
0274: : p.getRealConstraints().ipady;
0275: value += action;
0276: if (value < 0)
0277: continue;
0278: setProperty(p,
0279: // what == HORIZONTAL ? DesignGridBagLayout.PROP_IPADX : DesignGridBagLayout.PROP_IPADY ,
0280: what == HORIZONTAL ? "ipadx" : "ipady", // NOI18N
0281: new Integer(value));
0282: }
0283: }
0284:
0285: void modifyInsets(int action, int what) {
0286: java.util.List<GBComponentProxy> selected = containerProxy
0287: .getSelectedProxies();
0288: Iterator<GBComponentProxy> it = selected.iterator();
0289: while (it.hasNext()) {
0290: GBComponentProxy p = it.next();
0291: Insets old_insets = p.getRealConstraints().insets;
0292: Insets new_insets = (Insets) old_insets.clone();
0293:
0294: if ((what & TOP) != 0) {
0295: new_insets.top += action;
0296: if (new_insets.top < 0)
0297: new_insets.top = 0;
0298: }
0299: if ((what & BOTTOM) != 0) {
0300: new_insets.bottom += action;
0301: if (new_insets.bottom < 0)
0302: new_insets.bottom = 0;
0303: }
0304: if ((what & LEFT) != 0) {
0305: new_insets.left += action;
0306: if (new_insets.left < 0)
0307: new_insets.left = 0;
0308: }
0309: if ((what & RIGHT) != 0) {
0310: new_insets.right += action;
0311: if (new_insets.right < 0)
0312: new_insets.right = 0;
0313: }
0314:
0315: // setProperty(p, DesignGridBagLayout.PROP_INSETS, new_insets);
0316: setProperty(p, "insets", new_insets); // NOI18N
0317: }
0318: }
0319:
0320: void modifyGridSize(int action, int what) {
0321: java.util.List<GBComponentProxy> selected = containerProxy
0322: .getSelectedProxies();
0323: Iterator<GBComponentProxy> it = selected.iterator();
0324:
0325: while (it.hasNext()) {
0326: GBComponentProxy p = it.next();
0327: int value = what == HORIZONTAL ? p.getRealConstraints().gridwidth
0328: : p.getRealConstraints().gridheight;
0329:
0330: if (action == 0)
0331: value = value == 0 ? 1 : 0;
0332: else {
0333: value += action;
0334: if (value < 1) {
0335: value = 1;
0336: }
0337: }
0338:
0339: setProperty(p,
0340: // what == HORIZONTAL ? DesignGridBagLayout.PROP_GRIDWIDTH : DesignGridBagLayout.PROP_GRIDHEIGHT ,
0341: what == HORIZONTAL ? "gridwidth" : "gridheight", // NOI18N
0342: new Integer(value));
0343: }
0344: }
0345:
0346: private void setProperty(GBComponentProxy p, String name,
0347: Object value) {
0348: Node.Property prop = p.getComponent().getPropertyByName(
0349: "GridBagLayoutConstraints " + name); // NOI18N
0350: if (prop != null) {
0351: try {
0352: prop.setValue(value);
0353: } catch (Exception ex) { // ignore
0354: ex.printStackTrace();
0355: }
0356: }
0357: }
0358:
0359: // -----------------------------------------------------------------------------
0360: // Customizer implementation
0361:
0362: /**
0363: * Set the object to be customized. This method should be called only
0364: * once, before the Customizer has been added to any parent AWT container.
0365: * @param bean The object to be customized.
0366: */
0367: public void setObject(Object bean) {
0368: layoutSupport = (GridBagLayoutSupport) bean;
0369: // ((LayoutSupportManager)bean).getLayoutDelegate();
0370: initialize();
0371: firstPaint = true;
0372: }
0373:
0374: /**
0375: * Register a listener for the PropertyChange event. The customizer
0376: * should fire a PropertyChange event whenever it changes the target
0377: * bean in a way that might require the displayed properties to be
0378: * refreshed.
0379: *
0380: * @param listener An object to be invoked when a PropertyChange
0381: * event is fired.
0382: */
0383: // public void addPropertyChangeListener(PropertyChangeListener listener) {
0384: // propertySupport.addPropertyChangeListener(listener);
0385: // }
0386: /**
0387: * Remove a listener for the PropertyChange event.
0388: *
0389: * @param listener The PropertyChange listener to be removed.
0390: */
0391: // public void removePropertyChangeListener(PropertyChangeListener listener) {
0392: // propertySupport.removePropertyChangeListener(listener);
0393: // }
0394: /*
0395: public void propertyChange(final java.beans.PropertyChangeEvent p0) {
0396: System.out.println("PCH :" + p0);
0397: }
0398: */
0399:
0400: // -----------------------------------------------------------------------------
0401: // Form listener implementation
0402: class FormListener implements FormModelListener {
0403: public void formChanged(FormModelEvent[] events) {
0404: if (events != null && GridBagCustomizer.this .isShowing()) {
0405: boolean modifying = false;
0406: for (int i = 0; i < events.length; i++)
0407: if (events[i].isModifying()) {
0408: modifying = true;
0409: break;
0410: }
0411: if (!modifying)
0412: return;
0413:
0414: // we perform update after designer is updated which takes
0415: // three dispatch events - this is only temporary patch
0416: // (very very very ugly :-)
0417: // (it would be much nicer to have some listener on
0418: // FormDesigner directly...)
0419: invokeLater(3, new Runnable() {
0420: public void run() {
0421: containerProxy.updateAllProxies();
0422: }
0423: });
0424: }
0425: // if (propertyName == DesignGridBagLayout.PROP_ANCHOR || propertyName == DesignGridBagLayout.PROP_FILL ||
0426: // propertyName == DesignGridBagLayout.PROP_GRIDWIDTH || propertyName == DesignGridBagLayout.PROP_GRIDHEIGHT)
0427: // controlCenter.newSelection(containerProxy.getSelectedProxies());
0428: }
0429: }
0430:
0431: void waitForDesignerUpdate(int count) {
0432: try {
0433: while (count > 0) {
0434: SwingUtilities.invokeAndWait(new Runnable() {
0435: public void run() {
0436: }
0437: });
0438: count--;
0439: }
0440: } catch (Exception e) {
0441: e.printStackTrace();
0442: }
0443: }
0444:
0445: void invokeLater(final int count, final Runnable task) {
0446: if (count == 0)
0447: task.run();
0448: else
0449: SwingUtilities.invokeLater(new Runnable() {
0450: public void run() {
0451: invokeLater(count - 1, task);
0452: }
0453: });
0454: }
0455:
0456: // public void layoutChanged(RADVisualContainer container,RADVisualComponent component,
0457: // String propertyName,Object oldValue,Object newValue) {
0458: // //System.out.println("Layout changed" + propertyName + newValue); // NOI18N
0459: // containerProxy.updateAllProxies();
0460: // if (propertyName == DesignGridBagLayout.PROP_ANCHOR || propertyName == DesignGridBagLayout.PROP_FILL ||
0461: // propertyName == DesignGridBagLayout.PROP_GRIDWIDTH || propertyName == DesignGridBagLayout.PROP_GRIDHEIGHT)
0462: // controlCenter.newSelection(containerProxy.getSelectedProxies());
0463: // }
0464:
0465: // public void eventAdded(FormEventEvent evt) {}
0466: // public void eventRemoved(FormEventEvent evt) {}
0467: // public void eventRenamed(FormEventEvent evt) {}
0468:
0469: void innerLayoutChanged() {
0470:
0471: /*
0472: System.out.println("1 CP Size : " + containerProxy.getSize());
0473: System.out.println("1 CP Preff Size : " + containerProxy.getSize());
0474:
0475: containerProxy.invalidate();
0476: containerProxy.revalidate();
0477: containerProxy.widenEmpty();
0478: containerProxy.revalidate();
0479:
0480: designPanel.invalidate();
0481: designPanel.validate();
0482: designPanel.revalidate();
0483: */
0484: //designLayeredPane.invalidate();
0485:
0486: containerProxy.widenEmpty();
0487: designPanel.setBounds(20, 20,
0488: designPanel.getPreferredSize().width, designPanel
0489: .getPreferredSize().height);
0490:
0491: //containerProxy.widenEmpty();
0492: //containerProxy.invalidate();
0493: containerProxy.revalidate();
0494:
0495: //designPanel.invalidate();
0496: //designPanel.validate();
0497: //designPanel.revalidate();
0498:
0499: designLayeredPane.revalidate();
0500: //designLayeredPane.repaint();
0501:
0502: /*
0503: System.out.println("2 CP Size : " + containerProxy.getSize());
0504: System.out.println("2 CP Preff Size : " + containerProxy.getPreferredSize());
0505: System.out.println("2 DP Size : " + designPanel.getSize());
0506: System.out.println("2 DP Preff Size : " + designPanel.getPreferredSize());
0507: System.out.println("2 DLP Size : " + designLayeredPane.getSize());
0508: System.out.println("2 DLP Preff Size : " + designLayeredPane.getPreferredSize());
0509: */
0510:
0511: }
0512:
0513: // -----------------------------------------------------------------------------
0514: // Innerclasses
0515:
0516: /** Proxy component for one component in the container */
0517: class GBComponentProxy extends JPanel {
0518: /*
0519: private String name;
0520:
0521: GBComponent(String name) {
0522: this.name = name;
0523: }
0524: */
0525:
0526: private GBContainerProxy parentProxy;
0527: private RADVisualComponent component;
0528: private ComponentProxyNode node;
0529: private javax.swing.border.CompoundBorder compoundBorder;
0530: private javax.swing.border.MatteBorder insetsBorder;
0531: private javax.swing.border.MatteBorder remainderBorder;
0532: // private JPanel innerPanel;
0533: private JLabel componentLabel;
0534: private GridBagLayout layout;
0535: // private GridBagConstraints componentConstraints;
0536: private Color INSETS_COLOR = new Color(255, 255, 204);
0537: private Color CELL_COLOR = new Color(153, 153, 255);
0538:
0539: private boolean isSelected = false;
0540:
0541: static final long serialVersionUID = -6552012922564179923L;
0542:
0543: GBComponentProxy(final RADVisualComponent component,
0544: GBContainerProxy parentProxy) {
0545:
0546: this .component = component;
0547: this .parentProxy = parentProxy;
0548:
0549: //setLayout(new BorderLayout());
0550:
0551: componentLabel = new javax.swing.JLabel() {
0552: @Override
0553: public void paint(Graphics g) {
0554: int borderSize = 5;
0555: Color borderColor = Color.blue;
0556:
0557: super .paint(g);
0558:
0559: if (GBComponentProxy.this .isSelected()) {
0560:
0561: Dimension size = getSize();
0562: g.setColor(borderColor);
0563: g.fillRect(0, 0, borderSize, borderSize); // UpLeft
0564: g.fillRect(size.width - borderSize, 0,
0565: borderSize, borderSize); // UpRight
0566: g.fillRect(0, size.height - borderSize,
0567: borderSize, borderSize); // LoLeft
0568: g.fillRect(size.width - borderSize, size.height
0569: - borderSize, borderSize, borderSize); // LoRight
0570:
0571: /*
0572: //if (resizable) {
0573: //g.fillRect(midHor, 0, borderSize, borderSize); // UpMid
0574: //g.fillRect(0, midVer, borderSize, borderSize); // LeftMid
0575: g.fillRect(size.width-borderSize, midVer, borderSize, borderSize); // RightMid
0576: g.fillRect(midHor, size.height-borderSize, borderSize, borderSize); // LoMid
0577: //}
0578: */
0579: }
0580:
0581: }
0582:
0583: @Override
0584: public Dimension getPreferredSize() {
0585: FormDesigner designer = FormEditor
0586: .getFormDesigner(formModel);
0587: Component comp = (Component) designer
0588: .getComponent(component);
0589: Dimension size;
0590: if (comp == null) {
0591: comp = (Component) component.getBeanInstance();
0592: size = comp.getPreferredSize();
0593: } else {
0594: if (designer.isOpened()) {
0595: size = comp.getSize();
0596: if (size.width > 4096) // [hack for issue 32311]
0597: size.width = comp.getPreferredSize().width;
0598: } else
0599: size = comp.getPreferredSize();
0600: }
0601:
0602: // Use a new instance - avoid modification of
0603: // the preferred size of the component (issue 48033)
0604: size = new Dimension(size);
0605:
0606: if (comp instanceof JComponent
0607: && !(comp instanceof JPanel)) {
0608: Insets this Ins = getInsets();
0609: if (comp instanceof JComponent) {
0610: javax.swing.border.Border b = ((JComponent) comp)
0611: .getBorder();
0612: if (b != null) {
0613: Insets ins = b.getBorderInsets(comp);
0614: this Ins.top -= ins.top;
0615: this Ins.left -= ins.left;
0616: this Ins.bottom -= ins.bottom;
0617: this Ins.right -= ins.right;
0618: }
0619: }
0620: if (this Ins.top > 0)
0621: size.height += this Ins.top;
0622: if (this Ins.bottom > 0)
0623: size.height += this Ins.bottom;
0624: if (this Ins.left > 0)
0625: size.width += this Ins.left;
0626: if (this Ins.right > 0)
0627: size.width += this Ins.right;
0628: }
0629:
0630: if (size.width < 6)
0631: size.width = 6;
0632: if (size.height < 6)
0633: size.height = 6;
0634:
0635: return size;
0636: }
0637:
0638: @Override
0639: public Dimension getMinimumSize() {
0640: Component comp = (Component) FormEditor
0641: .getFormDesigner(formModel).getComponent(
0642: component);
0643: if (comp == null)
0644: comp = (Component) component.getBeanInstance();
0645: return comp.getMinimumSize();
0646: // return component.getComponent().getMinimumSize();
0647: }
0648:
0649: @Override
0650: public Dimension getMaximumSize() {
0651: Component comp = (Component) FormEditor
0652: .getFormDesigner(formModel).getComponent(
0653: component);
0654: if (comp == null)
0655: comp = (Component) component.getBeanInstance();
0656: return comp.getMaximumSize();
0657: // return component.getComponent().getMaximumSize();
0658: }
0659: };
0660: componentLabel.setOpaque(true);
0661: componentLabel
0662: .setBorder(new javax.swing.border.EtchedBorder());
0663: componentLabel.setText(component.getName());
0664: componentLabel.setHorizontalAlignment(0);
0665: componentLabel
0666: .addMouseListener(new java.awt.event.MouseAdapter() {
0667: @Override
0668: public void mouseClicked(
0669: java.awt.event.MouseEvent evt) {
0670: GBComponentProxy.this .mouseClicked(evt);
0671: }
0672:
0673: @Override
0674: public void mousePressed(
0675: java.awt.event.MouseEvent evt) {
0676: GBComponentProxy.this .mousePressed(evt);
0677: }
0678:
0679: @Override
0680: public void mouseReleased(
0681: java.awt.event.MouseEvent evt) {
0682: GBComponentProxy.this .mouseReleased(evt);
0683: }
0684:
0685: });
0686:
0687: componentLabel
0688: .addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
0689: @Override
0690: public void mouseDragged(
0691: java.awt.event.MouseEvent evt) {
0692: GBComponentProxy.this .mouseDragged(evt);
0693: }
0694: });
0695:
0696: /*
0697: innerPanel = new JPanel();
0698: innerPanel.setLayout(layout = new GridBagLayout());
0699: innerPanel.setBackground(CELL_COLOR);
0700: innerPanel.setOpaque(true);
0701:
0702: innerPanel.add(componentLabel, getInnerComponentConstraints());
0703: add(innerPanel);
0704: */
0705:
0706: setLayout(layout = new GridBagLayout());
0707: setBackground(CELL_COLOR);
0708: setOpaque(true);
0709: updateByComponent();
0710: add(componentLabel, getInnerComponentConstraints());
0711: node = new ComponentProxyNode(component.getNodeReference());
0712: }
0713:
0714: RADVisualComponent getComponent() {
0715: return component;
0716: }
0717:
0718: // DesignGridBagLayout.GridBagConstraintsDescription getConstraints() {
0719: // return(DesignGridBagLayout.GridBagConstraintsDescription) component.getConstraints(DesignGridBagLayout.class);
0720: // }
0721:
0722: GridBagConstraints getRealConstraints() {
0723: return (GridBagConstraints) component.getParentContainer()
0724: .getLayoutSupport().getConstraints(component)
0725: .getConstraintsObject();
0726: // return getConstraints().getGridBagConstraints();
0727: }
0728:
0729: ComponentProxyNode getNode() {
0730: return node;
0731: }
0732:
0733: void updateByComponent() {
0734: layout.setConstraints(componentLabel,
0735: getInnerComponentConstraints());
0736: }
0737:
0738: /*
0739: public void paint(Graphics g) {
0740: int borderSize = 5;
0741: Color borderColor = Color.blue;
0742:
0743: super.paint(g);
0744:
0745: if (isSelected()) {
0746: Dimension size = getSize();
0747: int midHor =(size.width - borderSize) / 2;
0748: int midVer =(size.height - borderSize) / 2;
0749: g.setColor(borderColor);
0750: g.fillRect(0, 0, borderSize, borderSize); // UpLeft
0751: g.fillRect(size.width-borderSize, 0, borderSize, borderSize); // UpRight
0752: g.fillRect(0, size.height-borderSize, borderSize, borderSize); // LoLeft
0753: g.fillRect(size.width-borderSize, size.height-borderSize, borderSize, borderSize); // LoRight
0754:
0755:
0756: //if (resizable) {
0757: g.fillRect(midHor, 0, borderSize, borderSize); // UpMid
0758: g.fillRect(0, midVer, borderSize, borderSize); // LeftMid
0759: g.fillRect(size.width-borderSize, midVer, borderSize, borderSize); // RightMid
0760: g.fillRect(midHor, size.height-borderSize, borderSize, borderSize); // LoMid
0761: //}
0762: }
0763: }
0764: */
0765:
0766: GridBagConstraints getInnerComponentConstraints() {
0767:
0768: GridBagConstraints con = new GridBagConstraints();
0769: con.anchor = getRealConstraints().anchor;
0770: con.fill = getRealConstraints().fill;
0771: con.gridheight = 1;
0772: con.gridwidth = 1;
0773: con.gridx = 0;
0774: con.gridy = 0;
0775: // con.insets
0776: con.ipadx = getRealConstraints().ipadx;
0777: con.ipady = getRealConstraints().ipady;
0778: con.weightx = 1.0;
0779: con.weighty = 1.0;
0780:
0781: return con;
0782: }
0783:
0784: GridBagConstraints getProxyConstraints() {
0785: GridBagConstraints con = new GridBagConstraints();
0786:
0787: con.anchor = GridBagConstraints.CENTER;
0788: con.fill = GridBagConstraints.BOTH;
0789: con.gridheight = getRealConstraints().gridheight;
0790: con.gridwidth = getRealConstraints().gridwidth;
0791: con.gridx = getRealConstraints().gridx;
0792: con.gridy = getRealConstraints().gridy;
0793: con.insets = new Insets(3, 3, 3, 3);
0794: con.ipadx = 0;
0795: con.ipady = 0;
0796: //con.weightx = getRealConstraints().weightx;
0797: //con.weighty = getRealConstraints().weighty;
0798: con.weightx = 1.0;
0799: con.weighty = 1.0;
0800: Insets in = getRealConstraints().insets;
0801:
0802: insetsBorder = new javax.swing.border.MatteBorder(in.top,
0803: in.left, in.bottom, in.right, INSETS_COLOR);
0804: remainderBorder = new javax.swing.border.MatteBorder(0, 0,
0805: con.gridheight == 0 ? 4 : 0, con.gridwidth == 0 ? 4
0806: : 0, REMAINDER_ICON);
0807: compoundBorder = new javax.swing.border.CompoundBorder(
0808: remainderBorder, insetsBorder);
0809: setBorder(compoundBorder);
0810:
0811: return con;
0812: }
0813:
0814: boolean isSelected() {
0815: return isSelected;
0816: }
0817:
0818: void setSelected(boolean isSelected) {
0819: if (this .isSelected == isSelected)
0820: return;
0821:
0822: this .isSelected = isSelected;
0823: //innerPanel.invalidate();
0824: componentLabel.repaint();
0825: /*
0826: componentLabel.setBackground(isSelected ?
0827: (java.awt.Color) javax.swing.UIManager.getDefaults().get("controlLtHighlight") :
0828: (java.awt.Color) javax.swing.UIManager.getDefaults().get("Button.background"));
0829: componentLabel.repaint();
0830: */
0831: }
0832:
0833: void mouseClicked(java.awt.event.MouseEvent evt) {
0834: /*
0835: if (evt.isShiftDown())
0836: parentProxy.shiftSelect(this);
0837: else
0838: parentProxy.select(this);
0839: */
0840: }
0841:
0842: void mousePressed(java.awt.event.MouseEvent evt) {
0843: if (evt.isControlDown())
0844: parentProxy.shiftSelect(this );
0845: else
0846: parentProxy.select(this );
0847: }
0848:
0849: void mouseReleased(java.awt.event.MouseEvent evt) {
0850: if (dragLabel != null) {
0851:
0852: if (!dragLabel.getLastIndex().equals(
0853: dragLabel.getOriginalIndex())) {
0854: // setProperty(this, DesignGridBagLayout.PROP_GRIDX, new Integer(dragLabel.getLastIndex().x));
0855: // setProperty(this, DesignGridBagLayout.PROP_GRIDY, new Integer(dragLabel.getLastIndex().y));
0856: setProperty(this , "gridx", new Integer(dragLabel
0857: .getLastIndex().x)); // NOI18N
0858: setProperty(this , "gridy", new Integer(dragLabel
0859: .getLastIndex().y)); // NOI18N
0860: }
0861:
0862: designLayeredPane.remove(dragLabel);
0863: dragLabel = null;
0864: componentLabel.setCursor(Cursor.getDefaultCursor());
0865: designLayeredPane.repaint();
0866: }
0867: }
0868:
0869: void mouseDragged(java.awt.event.MouseEvent evt) {
0870:
0871: //System.out.print("Dragged "); // NOI18N
0872:
0873: if (dragLabel == null) {
0874: if (isSelected()) {
0875:
0876: //System.out.println(" - first time"); // NOI18N
0877:
0878: dragLabel = new DragLabel();
0879: dragLabel.setHotSpot(evt.getPoint());
0880: dragLabel.resolveOrigin();
0881: dragLabel.setLastIndex(dragLabel.getIndex(evt
0882: .getPoint()));
0883: dragLabel.setOriginalIndex(dragLabel.getIndex(evt
0884: .getPoint()));
0885:
0886: designLayeredPane.setLayer(dragLabel,
0887: JLayeredPane.DRAG_LAYER.intValue());
0888: designLayeredPane.add(dragLabel,
0889: BorderLayout.CENTER);
0890: dragLabel.setBounds(evt.getPoint().x, evt
0891: .getPoint().y);
0892: componentLabel.setCursor(Cursor
0893: .getPredefinedCursor(Cursor.MOVE_CURSOR));
0894: } else {
0895: //System.out.println(" - Undefined"); // NOI18N
0896:
0897: }
0898: } else {
0899:
0900: Point newLoc;
0901: if (!dragLabel.getLastIndex().equals(
0902: newLoc = dragLabel.getIndex(evt.getPoint()))) {
0903:
0904: Point converted = SwingUtilities.convertPoint(
0905: dragLabel, evt.getPoint(),
0906: designLayeredPane);
0907:
0908: //System.out.println(" - with layout change"); // NOI18N
0909:
0910: GridBagConstraints con = getProxyConstraints();
0911:
0912: con.gridx = newLoc.x;
0913: con.gridy = newLoc.y;
0914:
0915: parentProxy.layout.setConstraints(this , con);
0916:
0917: /*
0918: invalidate();
0919: doLayout();
0920: */
0921: //System.out.println("Constraints set"); // NOI18N
0922:
0923: // parentProxy.widenEmpty();
0924: //System.out.println(" Widden "); // NOI18N
0925:
0926: //invalidate();
0927: //innerPanel.invalidate();
0928: //parentProxy.invalidateAllProxies();
0929: //parentProxy.invalidate();
0930: //parentProxy.revalidate();
0931: //parentProxy.widenEmpty();
0932: //innerLayoutChanged();
0933:
0934: dragLabel.resolveOrigin();
0935:
0936: SwingUtilities.convertPoint(designLayeredPane,
0937: converted, dragLabel);
0938: //dragLabel.setBounds(converted.x, converted.y);
0939: Rectangle r = dragLabel.getBounds();
0940: Point loc = r.getLocation();
0941: loc.x += r.width + 20;
0942: loc.y += r.height + 20;
0943: //designScrollPane.getViewport().setViewPosition(r.getLocation());
0944:
0945: innerLayoutChanged();
0946: dragLabel.repaint();
0947:
0948: //System.out.println(" layout changed"); // NOI18N
0949:
0950: dragLabel.setLastIndex(newLoc);
0951:
0952: } else
0953: //System.out.println(" - simple"); // NOI18N
0954:
0955: dragLabel.setBounds(evt.getPoint().x, evt
0956: .getPoint().y);
0957: }
0958: }
0959:
0960: /** Innerclass for the component which is dragged */
0961: class DragLabel extends JLabel {
0962:
0963: Point origin;
0964: Point hotSpot;
0965: Point lastIndex;
0966: Point originalIndex;
0967:
0968: private Dimension preferredSize;
0969:
0970: static final long serialVersionUID = 992490305277357953L;
0971:
0972: DragLabel() {
0973: setOpaque(false);
0974: setEnabled(false);
0975: setBorder(new javax.swing.border.EtchedBorder());
0976: setText(component.getName());
0977: setHorizontalAlignment(0);
0978:
0979: preferredSize = (Dimension) componentLabel
0980: .getPreferredSize().clone();
0981: }
0982:
0983: @Override
0984: public Dimension getPreferredSize() {
0985: preferredSize.height = componentLabel
0986: .getPreferredSize().height
0987: + getRealConstraints().ipady;
0988: preferredSize.width = componentLabel.getPreferredSize().width
0989: + getRealConstraints().ipadx;
0990:
0991: return preferredSize;
0992: }
0993:
0994: @Override
0995: public Dimension getMinimumSize() {
0996: return componentLabel.getMinimumSize();
0997: }
0998:
0999: @Override
1000: public Dimension getMaximumSize() {
1001: return componentLabel.getMaximumSize();
1002: }
1003:
1004: void setHotSpot(Point hotSpot) {
1005: this .hotSpot = hotSpot;
1006: }
1007:
1008: void resolveOrigin() {
1009: origin = SwingUtilities.convertPoint(componentLabel, 0,
1010: 0, designLayeredPane);
1011: }
1012:
1013: Point getLastIndex() {
1014: return lastIndex;
1015: }
1016:
1017: void setLastIndex(Point lastIndex) {
1018: this .lastIndex = lastIndex;
1019: }
1020:
1021: Point getOriginalIndex() {
1022: return originalIndex;
1023: }
1024:
1025: void setOriginalIndex(Point originalIndex) {
1026: this .originalIndex = originalIndex;
1027: }
1028:
1029: Point getIndex(Point p) {
1030: return parentProxy.getLayoutLocation(SwingUtilities
1031: .convertPoint(componentLabel, p, parentProxy));
1032: }
1033:
1034: public void setBounds(int x, int y) {
1035: resolveOrigin();
1036: super .setBounds(origin.x + x - hotSpot.x, origin.y + y
1037: - hotSpot.y, getPreferredSize().width,
1038: getPreferredSize().height);
1039: }
1040:
1041: }
1042:
1043: }
1044:
1045: /** Properties of this node are displayed in the layout property sheet */
1046: static class ComponentProxyNode extends FilterNode {
1047:
1048: ComponentProxyNode(Node original) {
1049: super (original);
1050: }
1051:
1052: @Override
1053: public Node.PropertySet[] getPropertySets() {
1054: Node.PropertySet[] sets = super .getPropertySets();
1055: for (int i = 0; i < sets.length; i++)
1056: if ("layout".equals(sets[i].getName())) // NOI18N
1057: return new Node.PropertySet[] { sets[i] };
1058: return new Node.PropertySet[0]; // cannot return null...
1059: }
1060: }
1061:
1062: /** Proxy for the container it's layout is edited */
1063: class GBContainerProxy extends JPanel {
1064:
1065: private GridBagLayout layout;
1066: private boolean[][] empties;
1067:
1068: static final long serialVersionUID = 5113122235848232590L;
1069:
1070: GBContainerProxy() {
1071: setLayout(layout = new GridBagLayout());
1072: setBorder(new javax.swing.border.BevelBorder(
1073: javax.swing.border.BevelBorder.RAISED));
1074: setOpaque(true);
1075: }
1076:
1077: void addAllProxies() {
1078: for (int i = 0; i < gbcProxies.length; i++) {
1079: add(gbcProxies[i], gbcProxies[i].getProxyConstraints());
1080: }
1081: invalidate();
1082: validate();
1083: innerLayoutChanged();
1084: widenEmpty();
1085:
1086: if (gbcProxies.length > 0)
1087: select(gbcProxies[0]);
1088: }
1089:
1090: void widenEmpty() {
1091:
1092: layout.rowHeights = layout.columnWidths = null;
1093:
1094: layout.layoutContainer(this );
1095: validate();
1096:
1097: int[][] dims = layout.getLayoutDimensions();
1098:
1099: empties = new boolean[2][];
1100:
1101: int[] widths = new int[dims[0].length];
1102: empties[0] = new boolean[dims[0].length];
1103:
1104: for (int i = 0; i < widths.length; i++) {
1105: // System.out.println("Col [" + i + "] = " + dims[0][i]); // NOI18N
1106: widths[i] = 25;
1107: empties[0][i] = dims[0][i] == 0 ? true : false;
1108: }
1109: layout.columnWidths = widths;
1110:
1111: int[] heights = new int[dims[1].length];
1112: empties[1] = new boolean[dims[1].length];
1113: for (int i = 0; i < heights.length; i++) {
1114: // System.out.println("Rpw [" + i + "] = " + dims[1][i]); // NOI18N
1115: heights[i] = 25;
1116: empties[1][i] = dims[1][i] == 0 ? true : false;
1117: }
1118: layout.rowHeights = heights;
1119:
1120: //layout.layoutContainer(this);
1121: }
1122:
1123: @Override
1124: public void paint(Graphics g) {
1125:
1126: if (firstPaint) {
1127: innerLayoutChanged();
1128: firstPaint = false;
1129: }
1130:
1131: super .paint(g);
1132:
1133: if (gbcProxies.length > 0) {
1134:
1135: Color emptyColor = new Color(255, 173, 173);
1136:
1137: Point origin = layout.getLayoutOrigin();
1138:
1139: int[][] dims = layout.getLayoutDimensions();
1140:
1141: int width = 0;
1142: for (int i = 0; i < dims[0].length; i++) {
1143: width += dims[0][i];
1144: //System.out.println("W " + i + " : " + dims[0][i]);
1145: }
1146:
1147: int height = 0;
1148: for (int i = 0; i < dims[1].length; i++) {
1149: height += dims[1][i];
1150: // System.out.println("H " + i + " : " + dims[1][i]);
1151: }
1152:
1153: //Paint empty rows
1154: int yCoord = origin.y;
1155: g.setColor(emptyColor);
1156: for (int i = 0; i < dims[1].length; i++) {
1157: if (empties[1][i]) {
1158: g.setColor(emptyColor);
1159: g.fillRect(origin.x, yCoord, width, dims[1][i]);
1160: }
1161: yCoord += dims[1][i];
1162: }
1163:
1164: //Paint empty columns
1165: int xCoord = origin.x;
1166: for (int i = 0; i < dims[0].length; i++) {
1167: if (empties[0][i]) {
1168: g.setColor(emptyColor);
1169: g
1170: .fillRect(xCoord, origin.y, dims[0][i],
1171: height);
1172: }
1173: xCoord += dims[0][i];
1174: }
1175:
1176: // Paint horizontal lines
1177: g.setColor(Color.black);
1178: yCoord = dims[1][0] + origin.y - 1;
1179: for (int i = 1; i < dims[1].length; i++) {
1180: g.drawLine(origin.x, yCoord, origin.x + width - 1,
1181: yCoord);
1182: g.drawLine(origin.x, yCoord + 1, origin.x + width
1183: - 1, yCoord + 1);
1184: yCoord += dims[1][i];
1185: }
1186:
1187: // Paint vertical lines
1188: xCoord = dims[0][0] + origin.x - 1;
1189: for (int i = 1; i < dims[0].length; i++) {
1190: g.drawLine(xCoord, origin.y, xCoord, origin.y
1191: + height - 1);
1192: g.drawLine(xCoord + 1, origin.y, xCoord + 1,
1193: origin.y + height - 1);
1194: xCoord += dims[0][i];
1195: }
1196: }
1197:
1198: paintChildren(g);
1199: }
1200:
1201: Point getLayoutLocation(Point p) {
1202: return layout.location(p.x, p.y);
1203: }
1204:
1205: /* Updates all proxies */
1206: void updateAllProxies() {
1207:
1208: for (int i = 0; i < gbcProxies.length; i++) {
1209: updateProxy(gbcProxies[i]);
1210: }
1211:
1212: //invalidate();
1213:
1214: innerLayoutChanged();
1215: controlCenter.newSelection(getSelectedProxies());
1216:
1217: //designPanel.revalidate();
1218: //designPanel.repaint();
1219: //designLayeredPane.revalidate();
1220: //designPanel.repaint();
1221: }
1222:
1223: /* Updates the selected proxy */
1224:
1225: void updateProxy(GBComponentProxy p) {
1226: p.updateByComponent();
1227:
1228: p.getProxyConstraints();
1229: layout.setConstraints(p, p.getProxyConstraints());
1230:
1231: p.invalidate();
1232: //p.innerPanel.invalidate();
1233: p.validate();
1234:
1235: }
1236:
1237: void invalidateAllProxies() {
1238: for (int i = 0; i < gbcProxies.length; i++) {
1239: gbcProxies[i].invalidate();
1240: }
1241: doLayout();
1242: }
1243:
1244: java.util.List<GBComponentProxy> getSelectedProxies() {
1245: java.util.List<GBComponentProxy> selected = new ArrayList<GBComponentProxy>(
1246: gbcProxies.length);
1247:
1248: for (int i = 0; i < gbcProxies.length; i++) {
1249: if (gbcProxies[i].isSelected)
1250: selected.add(gbcProxies[i]);
1251: }
1252:
1253: return selected;
1254: }
1255:
1256: Node[] getSelectedNodes() {
1257: java.util.List<GBComponentProxy> selected = getSelectedProxies();
1258:
1259: Node[] result = new Node[selected.size()];
1260:
1261: Iterator<GBComponentProxy> it = selected.iterator();
1262:
1263: for (int i = 0; it.hasNext(); i++) {
1264: result[i] = it.next().getNode();
1265: }
1266:
1267: return result;
1268: }
1269:
1270: void select(GBComponentProxy p) {
1271: select(p, false);
1272: }
1273:
1274: void shiftSelect(GBComponentProxy p) {
1275: select(p, true);
1276: }
1277:
1278: void select(GBComponentProxy p, boolean shift) {
1279:
1280: java.util.List<GBComponentProxy> selected = getSelectedProxies();
1281:
1282: if (p.isSelected()) {
1283: if (selected.size() == 1) {
1284: return;
1285: } else if (shift) {
1286: p.setSelected(false);
1287: } else {
1288: Iterator<GBComponentProxy> it = selected.iterator();
1289: while (it.hasNext()) {
1290: it.next().setSelected(false);
1291: }
1292: p.setSelected(true);
1293: }
1294:
1295: } else {
1296: if (!shift) {
1297: Iterator<GBComponentProxy> it = selected.iterator();
1298: while (it.hasNext())
1299: it.next().setSelected(false);
1300: }
1301: p.setSelected(true);
1302: }
1303:
1304: propertySheet.setNodes(getSelectedNodes());
1305: controlCenter.newSelection(getSelectedProxies());
1306: }
1307:
1308: }
1309:
1310: public static class Window extends JDialog implements Customizer,
1311: ActionListener {
1312: final private GridBagCustomizer customizerPanel;
1313: private boolean packCalled;
1314:
1315: public Window() {
1316: super (org.openide.windows.WindowManager.getDefault()
1317: .getMainWindow());
1318: java.util.ResourceBundle bundle = GridBagLayoutSupport
1319: .getBundleHack();
1320:
1321: setTitle(bundle.getString("CTL_CustomizerTitle")); // NOI18N
1322:
1323: getContentPane().setLayout(new BorderLayout(0, 0));
1324: customizerPanel = new GridBagCustomizer();
1325: getContentPane().add(customizerPanel, BorderLayout.CENTER);
1326:
1327: JPanel buttonPanel = new JPanel();
1328: buttonPanel
1329: .setLayout(new FlowLayout(FlowLayout.RIGHT, 6, 6));
1330:
1331: JButton closeButton = new JButton();
1332: closeButton.setText(bundle.getString("CTL_CloseButton")); // NOI18N
1333: closeButton.setActionCommand("close"); // NOI18N
1334: closeButton.addActionListener(this );
1335: buttonPanel.add(closeButton);
1336:
1337: JButton helpButton = new JButton();
1338: helpButton.setText(bundle.getString("CTL_HelpButton")); // NOi18N
1339: helpButton.setActionCommand("help"); // NOI18N
1340: helpButton.addActionListener(this );
1341: buttonPanel.add(helpButton);
1342:
1343: getContentPane().add(buttonPanel, BorderLayout.SOUTH);
1344:
1345: addWindowListener(new WindowAdapter() {
1346: @Override
1347: public void windowClosed(WindowEvent e) {
1348: customizerPanel.customizerClosed();
1349: }
1350: });
1351:
1352: setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
1353: }
1354:
1355: @Override
1356: public void pack() {
1357: if (packCalled)
1358: return;
1359: packCalled = true;
1360:
1361: super .pack();
1362: Dimension size = getSize();
1363: Rectangle screenBounds = Utilities.getUsableScreenBounds();
1364: if (size.width > screenBounds.width - 80)
1365: size.width = screenBounds.width * 4 / 5;
1366: if (size.height > screenBounds.height - 80)
1367: size.height = screenBounds.height * 4 / 5;
1368: setBounds(Utilities.findCenterBounds(size));
1369: }
1370:
1371: public void setObject(Object bean) {
1372: customizerPanel.setObject(bean);
1373: }
1374:
1375: public void actionPerformed(ActionEvent ev) {
1376: if (ev.getActionCommand().equals("close")) // NOI18N
1377: dispose();
1378: else if (ev.getActionCommand().equals("help")) { // NOI18N
1379: Help help = Lookup.getDefault().lookup(Help.class);
1380: if (help != null)
1381: help.showHelp(HelpCtx.findHelp(customizerPanel));
1382: }
1383: }
1384: }
1385:
1386: }
|