fixed label size updating and bounds re-adjustments after_dev_vw_insync_asyncmodeling
authorjsandusky@netbeans.org
Wed, 25 Apr 2007 08:52:14 +0000
changeset 42886ee3466d510
parent 427 0f57250fbc62
child 429 a48dea4a8fe3
fixed label size updating and bounds re-adjustments
compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaEngineTitleWidget.java
compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaMinimizable.java
compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaNodeWidget.java
compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaNodeWidgetBinding.java
compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaNodeWidgetEngine.java
compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaPinWidget.java
compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaPinWidgetEngine.java
compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/SerialLayoutWithJustifications.java
     1.1 --- a/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaEngineTitleWidget.java	Wed Apr 25 08:16:30 2007 +0000
     1.2 +++ b/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaEngineTitleWidget.java	Wed Apr 25 08:52:14 2007 +0000
     1.3 @@ -42,7 +42,7 @@
     1.4   *
     1.5   * @author Josh Sandusky
     1.6   */
     1.7 -public class CasaEngineTitleWidget extends Widget {
     1.8 +public class CasaEngineTitleWidget extends Widget implements CasaMinimizable {
     1.9      
    1.10      private static final int   TITLE_GAP          = 3;
    1.11      
    1.12 @@ -150,11 +150,7 @@
    1.13          mEditWidget.setImage(bValue ? RegionUtilities.IMAGE_EDIT_16_ICON : null);
    1.14      }
    1.15      
    1.16 -    protected void updateBounds(boolean isMinimized) {
    1.17 -        mTitleWidget.setPreferredBounds(null);
    1.18 -        mNameWidget.setPreferredBounds(null);
    1.19 -        setPreferredBounds(null);
    1.20 -        
    1.21 +    public void setMinimized(boolean isMinimized) {
    1.22          minimizeWidget.setImage(isMinimized ? IMAGE_EXPAND : IMAGE_COLLAPSE);
    1.23      }
    1.24  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaMinimizable.java	Wed Apr 25 08:52:14 2007 +0000
     2.3 @@ -0,0 +1,28 @@
     2.4 +/*
     2.5 + * The contents of this file are subject to the terms of the Common Development
     2.6 + * and Distribution License (the License). You may not use this file except in
     2.7 + * compliance with the License.
     2.8 + * 
     2.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
    2.10 + * or http://www.netbeans.org/cddl.txt.
    2.11 + * 
    2.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
    2.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
    2.14 + * If applicable, add the following below the CDDL Header, with the fields
    2.15 + * enclosed by brackets [] replaced by your own identifying information:
    2.16 + * "Portions Copyrighted [year] [name of copyright owner]"
    2.17 + * 
    2.18 + * To change this template, choose Tools | Template Manager
    2.19 + * and open the template in the editor.
    2.20 + */
    2.21 +package org.netbeans.modules.compapp.casaeditor.graph;
    2.22 +
    2.23 +/**
    2.24 + *
    2.25 + * @author Josh Sandusky
    2.26 + */
    2.27 +public interface CasaMinimizable {
    2.28 +    
    2.29 +    void setMinimized(boolean isMinimized);
    2.30 +    
    2.31 +}
     3.1 --- a/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaNodeWidget.java	Wed Apr 25 08:16:30 2007 +0000
     3.2 +++ b/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaNodeWidget.java	Wed Apr 25 08:52:14 2007 +0000
     3.3 @@ -112,4 +112,11 @@
     3.4      protected DependenciesRegistry getRegistry() {
     3.5          return mDependenciesRegistry;
     3.6      }
     3.7 -} 
     3.8 +    
     3.9 +    public void readjustBounds() {
    3.10 +        if (getBounds() != null) {
    3.11 +            revalidate();
    3.12 +            getScene().validate();
    3.13 +        }
    3.14 +    }
    3.15 +}
     4.1 --- a/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaNodeWidgetBinding.java	Wed Apr 25 08:16:30 2007 +0000
     4.2 +++ b/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaNodeWidgetBinding.java	Wed Apr 25 08:52:14 2007 +0000
     4.3 @@ -206,8 +206,10 @@
     4.4      public void setEndpointLabel(String nodeName) {
     4.5          mNameWidget.setToolTipText(nodeName);
     4.6          mNameWidget.setLabel(nodeName);
     4.7 -        // validate to trigger a bounds update
     4.8 -        getScene().validate();
     4.9 +        if (getBounds() != null) {
    4.10 +            mNameWidget.resolveBounds(null, null);
    4.11 +            readjustBounds();
    4.12 +        }
    4.13      }
    4.14      
    4.15      /**
    4.16 @@ -218,11 +220,8 @@
    4.17       * @param glyphs the node glyphs
    4.18       */
    4.19      public void setNodeProperties(String nodeName, String nodeType) {
    4.20 -        mNameWidget.setToolTipText(nodeName);
    4.21 -        mNameWidget.setLabel(nodeName);
    4.22          mVertTextBarText = nodeType;
    4.23 -        revalidate();
    4.24 -        getScene().revalidate();
    4.25 +        setEndpointLabel(nodeName);
    4.26      }
    4.27      
    4.28      public void regenerateHeaderBorder() {
     5.1 --- a/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaNodeWidgetEngine.java	Wed Apr 25 08:16:30 2007 +0000
     5.2 +++ b/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaNodeWidgetEngine.java	Wed Apr 25 08:52:14 2007 +0000
     5.3 @@ -37,7 +37,8 @@
     5.4   *
     5.5   * @author rdara
     5.6   */
     5.7 -public class CasaNodeWidgetEngine extends CasaNodeWidget implements StateModel.Listener {
     5.8 +public class CasaNodeWidgetEngine extends CasaNodeWidget 
     5.9 +        implements StateModel.Listener, CasaMinimizable {
    5.10      
    5.11      public static final int ARROW_PIN_WIDTH           = 25;
    5.12      public static final int MARGIN_SE_ROUNDED_RECTANGLE = ARROW_PIN_WIDTH * 77 / 100;
    5.13 @@ -80,8 +81,11 @@
    5.14                  return CasaFactory.getCasaCustomizer().getCOLOR_SU_INTERNAL_BACKGROUND();
    5.15              }
    5.16              public Rectangle getHeaderRect() {
    5.17 -                if (mTitleWidget.getBounds() != null) {
    5.18 -                    return getClipRect().intersection(mTitleWidget.getBounds());
    5.19 +                Rectangle titleBounds = mTitleWidget.getBounds();
    5.20 +                if (titleBounds != null) {
    5.21 +                    Rectangle clipRect = getClipRect();
    5.22 +                    clipRect.height = titleBounds.height;
    5.23 +                    return clipRect;
    5.24                  }
    5.25                  return null;
    5.26              }
    5.27 @@ -108,14 +112,14 @@
    5.28              public void paint(Graphics2D g) {
    5.29                  // Draw a line below the title widget to separate
    5.30                  // the title from the pin area.
    5.31 -                Rectangle rect = mTitleWidget.getBounds();
    5.32 +                Rectangle rect = provider.getHeaderRect();
    5.33                  if (rect != null) {
    5.34                      if (getState().isSelected()) {
    5.35                          g.setColor(CasaFactory.getCasaCustomizer().getCOLOR_SELECTION());
    5.36                      } else {
    5.37                          g.setColor(CasaFactory.getCasaCustomizer().getCOLOR_SU_INTERNAL_BORDER());
    5.38                      }
    5.39 -                    g.drawLine(0, rect.height, rect.width, rect.height);
    5.40 +                    g.drawLine(rect.x, rect.y + rect.height, rect.x + rect.width, rect.y + rect.height);
    5.41                  }
    5.42                  if (isHighlighted()) {
    5.43                      InnerGlowBorderDrawer.paintInnerGlowBorder(
    5.44 @@ -141,54 +145,10 @@
    5.45      }
    5.46      
    5.47      
    5.48 -    private Dimension mPreviousHolderSize = new Dimension();
    5.49 -    private static final int MINIMUM_SE_NODE_HEIGHT   = 20;
    5.50 -    private static final int MINIMUM_SE_NODE_WIDTH    = 120;
    5.51 -    
    5.52      protected void notifyAdded() {
    5.53          super.notifyAdded();
    5.54          
    5.55          notifyStateChanged(ObjectState.createNormal(), ObjectState.createNormal());
    5.56 -        
    5.57 -        Widget.Dependency pinSizer = new Widget.Dependency() {
    5.58 -            // Maintains the height of the vertical text bar.
    5.59 -            public void revalidateDependency() {
    5.60 -                if (
    5.61 -                        getScene().getGraphics() == null || 
    5.62 -                        getBounds() == null || 
    5.63 -                        getParentWidget() == null) {
    5.64 -                    return;
    5.65 -                }
    5.66 -                Rectangle bounds = mContainerWidget.getClientArea().getBounds();
    5.67 -                if (!bounds.getSize().equals(mPreviousHolderSize))
    5.68 -                {
    5.69 -                    mPreviousHolderSize = bounds.getSize();
    5.70 -                    
    5.71 -                    if (bounds.width < MINIMUM_SE_NODE_WIDTH) {
    5.72 -                        mPreviousHolderSize.width = MINIMUM_SE_NODE_WIDTH;
    5.73 -                        bounds.width = MINIMUM_SE_NODE_WIDTH;
    5.74 -                    }
    5.75 -                    if (bounds.height < MINIMUM_SE_NODE_HEIGHT) {
    5.76 -                        mPreviousHolderSize.height = MINIMUM_SE_NODE_HEIGHT;
    5.77 -                        bounds.height = MINIMUM_SE_NODE_HEIGHT;
    5.78 -                    }
    5.79 -                    
    5.80 -                    mContainerWidget.setPreferredBounds(bounds);
    5.81 -
    5.82 -                    /* All pins bounds need to be set so that the Anchor will be calculated correctly */
    5.83 -                    Rectangle childBounds;
    5.84 -                    for (Widget child : mContainerWidget.getChildren ()) {
    5.85 -                        if (child.getBounds() != null) {
    5.86 -                            childBounds = child.getPreferredBounds();
    5.87 -                            childBounds.width = bounds.width;
    5.88 -                            child.setPreferredBounds(childBounds);
    5.89 -                        }
    5.90 -                    }
    5.91 -                }
    5.92 -            }
    5.93 -        };
    5.94 -        
    5.95 -        getRegistry().registerDependency(pinSizer);
    5.96      }
    5.97      
    5.98      public Rectangle getEntireBounds() {
    5.99 @@ -211,29 +171,23 @@
   5.100          } else if (hasNodeName) {
   5.101              mTitleWidget.setLabel(nodeName);                            // NOI18N
   5.102          }
   5.103 -        if (getBounds() != null) {
   5.104 -            readjustBounds();
   5.105 -        }
   5.106 +        readjustBounds();
   5.107      }
   5.108      
   5.109      public void stateChanged() {
   5.110 -        readjustBounds();
   5.111 +        setMinimized(mStateModel.getBooleanState());
   5.112      }
   5.113      
   5.114 -    public void readjustBounds() {
   5.115 -        boolean isMinimized = mStateModel.getBooleanState();
   5.116 +    public void setMinimized(boolean isMinimized) {
   5.117          for (Widget child : mContainerWidget.getChildren()) {
   5.118 -            if (child instanceof CasaPinWidget) {
   5.119 -                ((CasaPinWidget) child).updateBounds(isMinimized);
   5.120 -            } else if (child instanceof CasaEngineTitleWidget) {
   5.121 -                ((CasaEngineTitleWidget) child).updateBounds(isMinimized);
   5.122 +            if (child instanceof CasaMinimizable) {
   5.123 +                ((CasaMinimizable) child).setMinimized(isMinimized);
   5.124              }
   5.125          }
   5.126          mContainerWidget.setPreferredBounds(isMinimized ? mTitleWidget.getPreferredBounds() : null);
   5.127 -        setPreferredBounds(null);
   5.128          getScene().validate();
   5.129      }
   5.130 -    
   5.131 +
   5.132      protected Color getBackgroundColor() {
   5.133          return CasaFactory.getCasaCustomizer().getCOLOR_REGION_ENGINE();
   5.134      }
   5.135 @@ -249,9 +203,7 @@
   5.136      
   5.137      public void setTitleFont(Font font) {
   5.138          mTitleWidget.setTitleFont(font);
   5.139 -        if (getBounds() != null) {
   5.140 -            readjustBounds();
   5.141 -        }
   5.142 +        readjustBounds();
   5.143      }
   5.144      
   5.145      public void setTitleColor(Color color) {
     6.1 --- a/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaPinWidget.java	Wed Apr 25 08:16:30 2007 +0000
     6.2 +++ b/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaPinWidget.java	Wed Apr 25 08:52:14 2007 +0000
     6.3 @@ -100,10 +100,6 @@
     6.4      protected abstract void setSelected(boolean isSelected);
     6.5      
     6.6      
     6.7 -    protected void updateBounds(boolean isMinimized) {
     6.8 -        // does nothing by deafult
     6.9 -    }
    6.10 -    
    6.11      /**
    6.12       * Called to notify about the change of the widget state.
    6.13       * @param previousState the previous state
     7.1 --- a/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaPinWidgetEngine.java	Wed Apr 25 08:16:30 2007 +0000
     7.2 +++ b/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/CasaPinWidgetEngine.java	Wed Apr 25 08:52:14 2007 +0000
     7.3 @@ -24,6 +24,7 @@
     7.4  import java.awt.Image;
     7.5  import java.awt.Rectangle;
     7.6  import org.netbeans.api.visual.anchor.Anchor;
     7.7 +import org.netbeans.api.visual.border.BorderFactory;
     7.8  import org.netbeans.api.visual.layout.LayoutFactory;
     7.9  import org.netbeans.api.visual.widget.ImageWidget;
    7.10  import org.netbeans.api.visual.widget.LabelWidget;
    7.11 @@ -36,7 +37,7 @@
    7.12   *
    7.13   * @author rdara
    7.14   */
    7.15 -public class CasaPinWidgetEngine extends CasaPinWidget {
    7.16 +public class CasaPinWidgetEngine extends CasaPinWidget implements CasaMinimizable {
    7.17      
    7.18      private static final int LABEL_MAX_CHAR = 48;
    7.19      private static final int VERTICAL_GAP = 3;
    7.20 @@ -63,7 +64,7 @@
    7.21          
    7.22          switch(getDirection()) {
    7.23              case LEFT :
    7.24 -                setLayout(LayoutFactory.createHorizontalLayout(LayoutFactory.SerialAlignment.LEFT_TOP, 5));
    7.25 +                setLayout(RegionUtilities.createHorizontalLayoutWithJustifications(LayoutFactory.SerialAlignment.LEFT_TOP, 5));
    7.26                  addChild(mImageWidget);
    7.27                  addChild(mNameWidget);
    7.28                  addChild(mEmptyWidget);
    7.29 @@ -101,9 +102,7 @@
    7.30          while(!(widget instanceof CasaNodeWidgetEngine)) {
    7.31              widget = widget.getParentWidget();
    7.32          }
    7.33 -        if (getBounds() != null) {
    7.34 -            ((CasaNodeWidgetEngine) widget).readjustBounds();
    7.35 -        }
    7.36 +        ((CasaNodeWidgetEngine) widget).readjustBounds();
    7.37      }
    7.38      
    7.39      protected Directions getDirection() {
    7.40 @@ -114,19 +113,6 @@
    7.41          return RegionUtilities.createFixedDirectionalAnchor(this, getDirection(), 0);
    7.42      }
    7.43      
    7.44 -    protected void updateBounds(boolean isMinimized) {
    7.45 -        Rectangle rect = isMinimized ? new Rectangle() : null;
    7.46 -        mNameWidget.setPreferredBounds(rect);
    7.47 -        mImageWidget.setPreferredBounds(rect);
    7.48 -        setPreferredBounds(rect);
    7.49 -        
    7.50 -        if (isMinimized) {
    7.51 -            mImageWidget.setImage(null);
    7.52 -        } else {
    7.53 -            mImageWidget.setImage(mCurrentDisplayedImage);
    7.54 -        }
    7.55 -    }
    7.56 -    
    7.57      public void setLabelFont(Font font) {
    7.58          mNameWidget.setFont(font);
    7.59      }
    7.60 @@ -139,4 +125,16 @@
    7.61          mImageWidget.setToolTipText(strValue);
    7.62      }
    7.63  
    7.64 +    public void setMinimized(boolean isMinimized) {
    7.65 +        Rectangle rect = isMinimized ? new Rectangle() : null;
    7.66 +        mNameWidget.setPreferredBounds(rect);
    7.67 +        mImageWidget.setPreferredBounds(rect);
    7.68 +        setPreferredBounds(rect);
    7.69 +        
    7.70 +        if (isMinimized) {
    7.71 +            mImageWidget.setImage(null);
    7.72 +        } else {
    7.73 +            mImageWidget.setImage(mCurrentDisplayedImage);
    7.74 +        }
    7.75 +    }
    7.76  }
     8.1 --- a/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/SerialLayoutWithJustifications.java	Wed Apr 25 08:16:30 2007 +0000
     8.2 +++ b/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/SerialLayoutWithJustifications.java	Wed Apr 25 08:52:14 2007 +0000
     8.3 @@ -128,13 +128,26 @@
     8.4      }
     8.5  
     8.6      public boolean requiresJustification (Widget widget) {
     8.7 -       return (alignment == LayoutFactory.SerialAlignment.JUSTIFY) || (alignment == LayoutFactory.SerialAlignment.RIGHT_BOTTOM) ;
     8.8 +       return true;
     8.9      }
    8.10      
    8.11 -    //Right align the children
    8.12 -
    8.13      public void justify (Widget widget) {
    8.14          Rectangle bounds = widget.getParentWidget().getClientArea ();
    8.15 +        
    8.16 +        if (
    8.17 +                alignment == LayoutFactory.SerialAlignment.JUSTIFY || 
    8.18 +                alignment == LayoutFactory.SerialAlignment.RIGHT_BOTTOM) {
    8.19 +            justifyChildren(widget, bounds);
    8.20 +        }
    8.21 +        
    8.22 +        // Ensure the widget stretches to the width of the parent.
    8.23 +        Rectangle widgetBounds = widget.getPreferredBounds();
    8.24 +        widgetBounds.width = bounds.width;
    8.25 +        widget.resolveBounds(widget.getLocation(), widgetBounds);
    8.26 +    }
    8.27 +
    8.28 +    // right-align the children
    8.29 +    private void justifyChildren(Widget widget, Rectangle bounds) {
    8.30          int childrenWidth = 0 - gap;
    8.31          for (Widget child : widget.getChildren ()) {
    8.32              childrenWidth += child.getPreferredBounds().width;
    8.33 @@ -180,5 +193,4 @@
    8.34              }
    8.35          }
    8.36      }
    8.37 -
    8.38  }