Ignore:
Timestamp:
08.03.2010 09:24:03 (2 years ago)
Author:
jttt
Message:

Changes in multipolygon handling (see #4661), cosmetics

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MultiSplitLayout.java

    r3083 r3095  
    4242import java.util.ListIterator; 
    4343import java.util.Map; 
     44 
    4445import javax.swing.UIManager; 
    4546 
     
    141142     */ 
    142143    public void setModel(Node model) { 
    143         if ((model == null) || (model instanceof Divider)) { 
     144        if ((model == null) || (model instanceof Divider)) 
    144145            throw new IllegalArgumentException("invalid model"); 
    145         } 
    146146        Node oldModel = model; 
    147147        this.model = model; 
     
    168168     */ 
    169169    public void setDividerSize(int dividerSize) { 
    170         if (dividerSize < 0) { 
     170        if (dividerSize < 0) 
    171171            throw new IllegalArgumentException("invalid dividerSize"); 
    172         } 
    173172        int oldDividerSize = this.dividerSize; 
    174173        this.dividerSize = dividerSize; 
     
    212211     */ 
    213212    public void addLayoutComponent(String name, Component child) { 
    214         if (name == null) { 
     213        if (name == null) 
    215214            throw new IllegalArgumentException("name not specified"); 
    216         } 
    217215        childMap.put(name, child); 
    218216    } 
     
    253251 
    254252    private Dimension preferredNodeSize(Node root) { 
    255         if (root instanceof Leaf) { 
     253        if (root instanceof Leaf) 
    256254            return preferredComponentSize(root); 
    257         } 
    258255        else if (root instanceof Divider) { 
    259256            int dividerSize = getDividerSize(); 
     
    363360        Rectangle splitBounds = split.getBounds(); 
    364361        ListIterator<Node> splitChildren = split.getChildren().listIterator(); 
    365         Node lastWeightedChild = split.lastWeightedChild(); 
    366362 
    367363        if (split.isRowLayout()) { 
     
    385381                (totalWeightedWidth - minWeightedWidth) > extraWidth; 
    386382 
    387             while(splitChildren.hasNext()) { 
    388                 Node splitChild = splitChildren.next(); 
    389                 Rectangle splitChildBounds = splitChild.getBounds(); 
    390                 double minSplitChildWidth = minimumNodeSize(splitChild).getWidth(); 
    391                 double splitChildWeight = (onlyShrinkWeightedComponents) 
     383                while(splitChildren.hasNext()) { 
     384                    Node splitChild = splitChildren.next(); 
     385                    Rectangle splitChildBounds = splitChild.getBounds(); 
     386                    double minSplitChildWidth = minimumNodeSize(splitChild).getWidth(); 
     387                    double splitChildWeight = (onlyShrinkWeightedComponents) 
    392388                    ? splitChild.getWeight() 
    393                     : (splitChildBounds.getWidth() / (double)totalWidth); 
    394  
    395                 if (!splitChildren.hasNext()) { 
    396                     double newWidth =  Math.max(minSplitChildWidth, bounds.getMaxX() - x); 
    397                     Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, newWidth); 
    398                     layout2(splitChild, newSplitChildBounds); 
    399                 } 
    400                 else if ((availableWidth > 0.0) && (splitChildWeight > 0.0)) { 
    401                     double allocatedWidth = Math.rint(splitChildWeight * extraWidth); 
    402                     double oldWidth = splitChildBounds.getWidth(); 
    403                     double newWidth = Math.max(minSplitChildWidth, oldWidth - allocatedWidth); 
    404                     Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, newWidth); 
    405                     layout2(splitChild, newSplitChildBounds); 
    406                     availableWidth -= (oldWidth - splitChild.getBounds().getWidth()); 
    407                 } 
    408                 else { 
    409                     double existingWidth = splitChildBounds.getWidth(); 
    410                     Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, existingWidth); 
    411                     layout2(splitChild, newSplitChildBounds); 
    412                 } 
    413                 x = splitChild.getBounds().getMaxX(); 
    414             } 
     389                            : (splitChildBounds.getWidth() / totalWidth); 
     390 
     391                    if (!splitChildren.hasNext()) { 
     392                        double newWidth =  Math.max(minSplitChildWidth, bounds.getMaxX() - x); 
     393                        Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, newWidth); 
     394                        layout2(splitChild, newSplitChildBounds); 
     395                    } 
     396                    else if ((availableWidth > 0.0) && (splitChildWeight > 0.0)) { 
     397                        double allocatedWidth = Math.rint(splitChildWeight * extraWidth); 
     398                        double oldWidth = splitChildBounds.getWidth(); 
     399                        double newWidth = Math.max(minSplitChildWidth, oldWidth - allocatedWidth); 
     400                        Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, newWidth); 
     401                        layout2(splitChild, newSplitChildBounds); 
     402                        availableWidth -= (oldWidth - splitChild.getBounds().getWidth()); 
     403                    } 
     404                    else { 
     405                        double existingWidth = splitChildBounds.getWidth(); 
     406                        Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, existingWidth); 
     407                        layout2(splitChild, newSplitChildBounds); 
     408                    } 
     409                    x = splitChild.getBounds().getMaxX(); 
     410                } 
    415411        } 
    416412 
     
    435431                (totalWeightedHeight - minWeightedHeight) > extraHeight; 
    436432 
    437             while(splitChildren.hasNext()) { 
    438                 Node splitChild = splitChildren.next(); 
    439                 Rectangle splitChildBounds = splitChild.getBounds(); 
    440                 double minSplitChildHeight = minimumNodeSize(splitChild).getHeight(); 
    441                 double splitChildWeight = (onlyShrinkWeightedComponents) 
     433                while(splitChildren.hasNext()) { 
     434                    Node splitChild = splitChildren.next(); 
     435                    Rectangle splitChildBounds = splitChild.getBounds(); 
     436                    double minSplitChildHeight = minimumNodeSize(splitChild).getHeight(); 
     437                    double splitChildWeight = (onlyShrinkWeightedComponents) 
    442438                    ? splitChild.getWeight() 
    443                     : (splitChildBounds.getHeight() / (double)totalHeight); 
    444  
    445                 if (!splitChildren.hasNext()) { 
    446                     double oldHeight = splitChildBounds.getHeight(); 
    447                     double newHeight =  Math.max(minSplitChildHeight, bounds.getMaxY() - y); 
    448                     Rectangle newSplitChildBounds = boundsWithYandHeight(bounds, y, newHeight); 
    449                     layout2(splitChild, newSplitChildBounds); 
    450                     availableHeight -= (oldHeight - splitChild.getBounds().getHeight()); 
    451                 } 
    452                 else if ((availableHeight > 0.0) && (splitChildWeight > 0.0)) { 
    453                     double allocatedHeight = Math.rint(splitChildWeight * extraHeight); 
    454                     double oldHeight = splitChildBounds.getHeight(); 
    455                     double newHeight = Math.max(minSplitChildHeight, oldHeight - allocatedHeight); 
    456                     Rectangle newSplitChildBounds = boundsWithYandHeight(bounds, y, newHeight); 
    457                     layout2(splitChild, newSplitChildBounds); 
    458                     availableHeight -= (oldHeight - splitChild.getBounds().getHeight()); 
    459                 } 
    460                 else { 
    461                     double existingHeight = splitChildBounds.getHeight(); 
    462                     Rectangle newSplitChildBounds = boundsWithYandHeight(bounds, y, existingHeight); 
    463                     layout2(splitChild, newSplitChildBounds); 
    464                 } 
    465                 y = splitChild.getBounds().getMaxY(); 
    466             } 
     439                            : (splitChildBounds.getHeight() / totalHeight); 
     440 
     441                    if (!splitChildren.hasNext()) { 
     442                        double oldHeight = splitChildBounds.getHeight(); 
     443                        double newHeight =  Math.max(minSplitChildHeight, bounds.getMaxY() - y); 
     444                        Rectangle newSplitChildBounds = boundsWithYandHeight(bounds, y, newHeight); 
     445                        layout2(splitChild, newSplitChildBounds); 
     446                        availableHeight -= (oldHeight - splitChild.getBounds().getHeight()); 
     447                    } 
     448                    else if ((availableHeight > 0.0) && (splitChildWeight > 0.0)) { 
     449                        double allocatedHeight = Math.rint(splitChildWeight * extraHeight); 
     450                        double oldHeight = splitChildBounds.getHeight(); 
     451                        double newHeight = Math.max(minSplitChildHeight, oldHeight - allocatedHeight); 
     452                        Rectangle newSplitChildBounds = boundsWithYandHeight(bounds, y, newHeight); 
     453                        layout2(splitChild, newSplitChildBounds); 
     454                        availableHeight -= (oldHeight - splitChild.getBounds().getHeight()); 
     455                    } 
     456                    else { 
     457                        double existingHeight = splitChildBounds.getHeight(); 
     458                        Rectangle newSplitChildBounds = boundsWithYandHeight(bounds, y, existingHeight); 
     459                        layout2(splitChild, newSplitChildBounds); 
     460                    } 
     461                    y = splitChild.getBounds().getMaxY(); 
     462                } 
    467463        } 
    468464 
     
    508504                else if ((availableWidth > 0.0) && (splitChildWeight > 0.0)) { 
    509505                    double allocatedWidth = (splitChild.equals(lastWeightedChild)) 
    510                         ? availableWidth 
    511                         : Math.rint(splitChildWeight * extraWidth); 
     506                    ? availableWidth 
     507                            : Math.rint(splitChildWeight * extraWidth); 
    512508                    double newWidth = splitChildBounds.getWidth() + allocatedWidth; 
    513509                    Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, newWidth); 
     
    550546                else if ((availableHeight > 0.0) && (splitChildWeight > 0.0)) { 
    551547                    double allocatedHeight = (splitChild.equals(lastWeightedChild)) 
    552                         ? availableHeight 
    553                         : Math.rint(splitChildWeight * extraHeight); 
     548                    ? availableHeight 
     549                            : Math.rint(splitChildWeight * extraHeight); 
    554550                    double newHeight = splitChildBounds.getHeight() + allocatedHeight; 
    555551                    Rectangle newSplitChildBounds = boundsWithYandHeight(bounds, y, newHeight); 
     
    570566     * as needed. 
    571567     */ 
    572    private void layout2(Node root, Rectangle bounds) { 
     568    private void layout2(Node root, Rectangle bounds) { 
    573569        if (root instanceof Leaf) { 
    574570            Component child = childForNode(root); 
     
    584580            Split split = (Split)root; 
    585581            boolean grow = split.isRowLayout() 
    586                 ? (split.getBounds().width <= bounds.width) 
    587                 : (split.getBounds().height <= bounds.height); 
     582            ? (split.getBounds().width <= bounds.width) 
     583                    : (split.getBounds().height <= bounds.height); 
    588584            if (grow) { 
    589585                layoutGrow(split, bounds); 
     
    635631                        (splitChildren.hasNext()) ? (Divider)(splitChildren.next()) : null; 
    636632 
    637                     double childWidth = 0.0; 
    638                     if (getFloatingDividers()) { 
    639                         childWidth = preferredNodeSize(splitChild).getWidth(); 
    640                     } 
    641                     else { 
    642                         if (dividerChild != null) { 
    643                             childWidth = dividerChild.getBounds().getX() - x; 
     633                        double childWidth = 0.0; 
     634                        if (getFloatingDividers()) { 
     635                            childWidth = preferredNodeSize(splitChild).getWidth(); 
    644636                        } 
    645637                        else { 
    646                             childWidth = split.getBounds().getMaxX() - x; 
     638                            if (dividerChild != null) { 
     639                                childWidth = dividerChild.getBounds().getX() - x; 
     640                            } 
     641                            else { 
     642                                childWidth = split.getBounds().getMaxX() - x; 
     643                            } 
    647644                        } 
    648                     } 
    649                     childBounds = boundsWithXandWidth(bounds, x, childWidth); 
    650                     layout1(splitChild, childBounds); 
    651  
    652                     if (getFloatingDividers() && (dividerChild != null)) { 
    653                         double dividerX = childBounds.getMaxX(); 
    654                         Rectangle dividerBounds = boundsWithXandWidth(bounds, dividerX, dividerSize); 
    655                         dividerChild.setBounds(dividerBounds); 
    656                     } 
    657                     if (dividerChild != null) { 
    658                         x = dividerChild.getBounds().getMaxX(); 
    659                     } 
     645                        childBounds = boundsWithXandWidth(bounds, x, childWidth); 
     646                        layout1(splitChild, childBounds); 
     647 
     648                        if (getFloatingDividers() && (dividerChild != null)) { 
     649                            double dividerX = childBounds.getMaxX(); 
     650                            Rectangle dividerBounds = boundsWithXandWidth(bounds, dividerX, dividerSize); 
     651                            dividerChild.setBounds(dividerBounds); 
     652                        } 
     653                        if (dividerChild != null) { 
     654                            x = dividerChild.getBounds().getMaxX(); 
     655                        } 
    660656                } 
    661657            } 
     
    673669                        (splitChildren.hasNext()) ? (Divider)(splitChildren.next()) : null; 
    674670 
    675                     double childHeight = 0.0; 
    676                     if (getFloatingDividers()) { 
    677                         childHeight = preferredNodeSize(splitChild).getHeight(); 
    678                     } 
    679                     else { 
    680                         if (dividerChild != null) { 
    681                             childHeight = dividerChild.getBounds().getY() - y; 
     671                        double childHeight = 0.0; 
     672                        if (getFloatingDividers()) { 
     673                            childHeight = preferredNodeSize(splitChild).getHeight(); 
    682674                        } 
    683675                        else { 
    684                             childHeight = split.getBounds().getMaxY() - y; 
     676                            if (dividerChild != null) { 
     677                                childHeight = dividerChild.getBounds().getY() - y; 
     678                            } 
     679                            else { 
     680                                childHeight = split.getBounds().getMaxY() - y; 
     681                            } 
    685682                        } 
    686                     } 
    687                     childBounds = boundsWithYandHeight(bounds, y, childHeight); 
    688                     layout1(splitChild, childBounds); 
    689  
    690                     if (getFloatingDividers() && (dividerChild != null)) { 
    691                         double dividerY = childBounds.getMaxY(); 
    692                         Rectangle dividerBounds = boundsWithYandHeight(bounds, dividerY, dividerSize); 
    693                         dividerChild.setBounds(dividerBounds); 
    694                     } 
    695                     if (dividerChild != null) { 
    696                         y = dividerChild.getBounds().getMaxY(); 
    697                     } 
     683                        childBounds = boundsWithYandHeight(bounds, y, childHeight); 
     684                        layout1(splitChild, childBounds); 
     685 
     686                        if (getFloatingDividers() && (dividerChild != null)) { 
     687                            double dividerY = childBounds.getMaxY(); 
     688                            Rectangle dividerBounds = boundsWithYandHeight(bounds, dividerY, dividerSize); 
     689                            dividerChild.setBounds(dividerBounds); 
     690                        } 
     691                        if (dividerChild != null) { 
     692                            y = dividerChild.getBounds().getMaxY(); 
     693                        } 
    698694                } 
    699695            } 
     
    781777            Split split = (Split)root; 
    782778            for(Node child : split.getChildren()) { 
    783                 if (child.getBounds().contains(x, y)) { 
     779                if (child.getBounds().contains(x, y)) 
    784780                    return dividerAt(child, x, y); 
    785                 } 
    786781            } 
    787782        } 
     
    804799        Rectangle r1 = node.getBounds(); 
    805800        return 
    806             (r1.x <= (r2.x + r2.width)) && ((r1.x + r1.width) >= r2.x) && 
    807             (r1.y <= (r2.y + r2.height)) && ((r1.y + r1.height) >= r2.y); 
     801        (r1.x <= (r2.x + r2.width)) && ((r1.x + r1.width) >= r2.x) && 
     802        (r1.y <= (r2.y + r2.height)) && ((r1.y + r1.height) >= r2.y); 
    808803    } 
    809804 
     
    822817            } 
    823818            return dividers; 
    824         } 
    825         else { 
     819        } else 
    826820            return Collections.emptyList(); 
    827         } 
    828821    } 
    829822 
     
    837830     */ 
    838831    public List<Divider> dividersThatOverlap(Rectangle r) { 
    839         if (r == null) { 
     832        if (r == null) 
    840833            throw new IllegalArgumentException("null Rectangle"); 
    841         } 
    842834        return dividersThatOverlap(getModel(), r); 
    843835    } 
     
    890882         */ 
    891883        public void setBounds(Rectangle bounds) { 
    892             if (bounds == null) { 
     884            if (bounds == null) 
    893885                throw new IllegalArgumentException("null bounds"); 
    894             } 
    895886            this.bounds = new Rectangle(bounds); 
    896887        } 
     
    921912         */ 
    922913        public void setWeight(double weight) { 
    923             if ((weight < 0.0)|| (weight > 1.0)) { 
     914            if ((weight < 0.0)|| (weight > 1.0)) 
    924915                throw new IllegalArgumentException("invalid weight"); 
    925             } 
    926916            this.weight = weight; 
    927917        } 
     
    929919        private Node siblingAtOffset(int offset) { 
    930920            Split parent = getParent(); 
    931             if (parent == null) { return null; } 
     921            if (parent == null) 
     922                return null; 
    932923            List<Node> siblings = parent.getChildren(); 
    933924            int index = siblings.indexOf(this); 
    934             if (index == -1) { return null; } 
     925            if (index == -1) 
     926                return null; 
    935927            index += offset; 
    936928            return ((index > -1) && (index < siblings.size())) ? siblings.get(index) : null; 
     
    10201012         */ 
    10211013        public void setChildren(List<Node> children) { 
    1022             if (children == null) { 
     1014            if (children == null) 
    10231015                throw new IllegalArgumentException("children must be a non-null List"); 
    1024             } 
    10251016            for(Node child : this.children) { 
    10261017                child.setParent(null); 
     
    10511042        } 
    10521043 
     1044        @Override 
    10531045        public String toString() { 
    10541046            int nChildren = getChildren().size(); 
     
    10811073         */ 
    10821074        public Leaf(String name) { 
    1083             if (name == null) { 
     1075            if (name == null) 
    10841076                throw new IllegalArgumentException("name is null"); 
    1085             } 
    10861077            this.name = name; 
    10871078        } 
     
    11021093         */ 
    11031094        public void setName(String name) { 
    1104             if (name == null) { 
     1095            if (name == null) 
    11051096                throw new IllegalArgumentException("name is null"); 
    1106             } 
    11071097            this.name = name; 
    11081098        } 
    11091099 
     1100        @Override 
    11101101        public String toString() { 
    11111102            StringBuffer sb = new StringBuffer("MultiSplitLayout.Leaf"); 
     
    11421133         * @throws UnsupportedOperationException 
    11431134         */ 
     1135        @Override 
    11441136        public void setWeight(double weight) { 
    11451137            throw new UnsupportedOperationException(); 
    11461138        } 
    11471139 
     1140        @Override 
    11481141        public String toString() { 
    11491142            return "MultiSplitLayout.Divider " + getBounds().toString(); 
Note: See TracChangeset for help on using the changeset viewer.