~ubuntu-branches/ubuntu/quantal/libjgraph-java/quantal

« back to all changes in this revision

Viewing changes to src/org/jgraph/graph/GraphLayoutCache.java

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2008-03-17 20:28:08 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080317202808-jol9tcnnn9lu0gc3
Tags: 5.12.0.4.dfsg-1
* New upstream release.
* Remove debian/dirs and create /usr/share/java directly from
  debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * @(#)GraphLayoutCache.java 1.0 03-JUL-04
 
2
 * $Id: GraphLayoutCache.java,v 1.34 2008/03/17 09:54:22 david Exp $
3
3
 * 
4
 
 * Copyright (c) 2001-2004 Gaudenz Alder
 
4
 * Copyright (c) 2001-2008 Gaudenz Alder
5
5
 *  
6
6
 */
7
7
package org.jgraph.graph;
32
32
import org.jgraph.event.GraphLayoutCacheEvent;
33
33
import org.jgraph.event.GraphLayoutCacheListener;
34
34
import org.jgraph.event.GraphModelEvent;
 
35
import org.jgraph.util.RectUtils;
35
36
 
36
37
/**
37
38
 * An object that defines the view of a graphmodel. This object maps between
158
159
        protected boolean reconnectsEdgesToVisibleParent = false;
159
160
 
160
161
        /**
161
 
         * The list of listeners that listen to the model.
 
162
         * The list of listeners that listen to the GraphLayoutCache.
162
163
         */
163
164
        protected EventListenerList listenerList = new EventListenerList();
164
165
 
347
348
                                                        return null;
348
349
                                                }
349
350
 
 
351
                                                public Rectangle2D getDirtyRegion() {
 
352
                                                        return null;
 
353
                                                }
 
354
 
 
355
                                                public void setDirtyRegion(Rectangle2D dirty) {}
 
356
 
350
357
                                        });
351
358
                }
352
359
        }
385
392
                                .getListeners(GraphLayoutCacheListener.class);
386
393
        }
387
394
 
 
395
 
388
396
        //
389
397
        // Accessors
390
398
        //
437
445
         */
438
446
        public static Rectangle2D getBounds(CellView[] views) {
439
447
                if (views != null && views.length > 0) {
440
 
                        Rectangle2D r = views[0].getBounds();
 
448
                        Rectangle2D r = (views[0] != null) ? views[0].getBounds() : null;
441
449
                        Rectangle2D ret = (r != null) ? (Rectangle2D) r.clone() : null;
442
450
                        for (int i = 1; i < views.length; i++) {
443
 
                                r = views[i].getBounds();
 
451
                                r = (views[i] != null) ? views[i].getBounds() : null;
444
452
                                if (r != null) {
445
453
                                        if (ret == null)
446
454
                                                ret = (r != null) ? (Rectangle2D) r.clone() : null;
2007
2015
        }
2008
2016
 
2009
2017
        /**
2010
 
         * An implementation of GraphViewChange.
 
2018
         * An implementation of GraphLayoutCacheChange.
2011
2019
         */
2012
2020
        public class GraphLayoutCacheEdit extends CompoundEdit implements
2013
2021
                        GraphLayoutCacheEvent.GraphLayoutCacheChange {
2019
2027
                protected Map attributes, previousAttributes;
2020
2028
 
2021
2029
                protected Object[] visible, invisible;
 
2030
                
 
2031
                /**
 
2032
                 * The dirty region associated with this event prior to the change
 
2033
                 */
 
2034
                protected Rectangle2D dirtyRegion = null;
2022
2035
 
2023
2036
                // Remember which cells have changed for finding their context
2024
2037
                protected Set changedCells = new HashSet();
2116
2129
                        return previousAttributes;
2117
2130
                }
2118
2131
 
 
2132
                public Rectangle2D getDirtyRegion() {
 
2133
                        return dirtyRegion;
 
2134
                }
 
2135
 
 
2136
                public void setDirtyRegion(Rectangle2D dirty) {
 
2137
                        this.dirtyRegion = dirty;
 
2138
                        
 
2139
                }
 
2140
                
2119
2141
                /**
2120
2142
                 * Redoes a change.
2121
2143
                 * 
2150
2172
                                for (int i = 0; i < hidden.length; i++)
2151
2173
                                        if (hidden[i] != null)
2152
2174
                                                mapping.put(hidden[i].getCell(), hidden[i]);
 
2175
                        
 
2176
                        if (invisible != null && invisible.length >0) {
 
2177
                                CellView[] invisibleViews = new CellView[invisible.length];
 
2178
                                invisibleViews = getMapping(invisible, true);
 
2179
                                Rectangle2D changedBounds = getBounds(invisibleViews);
 
2180
                                dirtyRegion = RectUtils.union(dirtyRegion, changedBounds);
 
2181
                        }
 
2182
 
 
2183
                                                
2153
2184
                        if (!remembersCellViews) // already remembered
2154
2185
                                hidden = getMapping(invisible);
2155
2186
                        // Handle visibility
2175
2206
                        if (attributes != null) {
2176
2207
                                previousAttributes = attributes;
2177
2208
                                changedCells.addAll(attributes.keySet());
2178
 
                                attributes = handleAttributes(attributes);
2179
2209
                        }
2180
2210
                        if (updatePorts)
2181
2211
                                updatePorts();
2190
2220
                                }
2191
2221
                        }
2192
2222
                        changedCells.addAll(parentSet);
 
2223
                        Set ctx = DefaultGraphModel.getEdges(getModel(), changedCells
 
2224
                                        .toArray());
 
2225
                        context = getMapping(ctx.toArray());
 
2226
                        Set allChangedCells = new HashSet(changedCells);
 
2227
                        allChangedCells.addAll(ctx);
 
2228
                        CellView[] allChangedCellViews = getMapping(allChangedCells.toArray());
 
2229
                        Rectangle2D changedBounds = getBounds(allChangedCellViews);
 
2230
                        dirtyRegion = RectUtils.union(dirtyRegion, changedBounds);
 
2231
                        if (attributes != null) {
 
2232
                                attributes = handleAttributes(attributes);
 
2233
                        }
2193
2234
                        // Refresh all changed cells
2194
2235
                        refresh(getMapping(changedCells.toArray(), false), false);
2195
2236
                        // Updates the connected edges. Make sure that changedCells
2196
2237
                        // contains no edges, as these will be removed from the result.
2197
 
                        Set ctx = DefaultGraphModel.getEdges(getModel(), changedCells
2198
 
                                        .toArray());
2199
 
                        context = getMapping(ctx.toArray());
2200
2238
                        refresh(context, false);
2201
2239
                        tmp = cells;
2202
2240
                        cells = previousCells;