~ubuntu-branches/ubuntu/trusty/libjgraph-java/trusty

« back to all changes in this revision

Viewing changes to src/org/jgraph/plaf/basic/BasicGraphUI.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:
12
12
import java.awt.Dimension;
13
13
import java.awt.Graphics;
14
14
import java.awt.Graphics2D;
 
15
import java.awt.HeadlessException;
15
16
import java.awt.Image;
16
17
import java.awt.Insets;
17
18
import java.awt.Point;
37
38
import java.awt.geom.Dimension2D;
38
39
import java.awt.geom.Point2D;
39
40
import java.awt.geom.Rectangle2D;
40
 
import java.awt.image.BufferedImage;
41
41
import java.awt.image.VolatileImage;
42
42
import java.beans.PropertyChangeEvent;
43
43
import java.beans.PropertyChangeListener;
95
95
import org.jgraph.graph.ParentMap;
96
96
import org.jgraph.graph.PortView;
97
97
import org.jgraph.plaf.GraphUI;
 
98
import org.jgraph.util.RectUtils;
98
99
 
99
100
/**
100
101
 * The basic L&F for a graph data structure.
921
922
                        if (offGraphics == null || offscreen == null) {
922
923
                                drawGraph(g, clipBounds);
923
924
                                paintOverlay(g);
924
 
                                graph.setOffscreenValid(false);
925
925
                                return;
926
926
                        }
927
927
                        if (offscreen instanceof VolatileImage) {
936
936
                                        }
937
937
                                } while (((VolatileImage) offscreen).contentsLost());
938
938
                        }
939
 
                        graph.setOffscreenValid(true);
940
939
                        g.drawImage(graph.getOffscreen(), 0, 0, graph);
 
940
                        if (!graph.isXorEnabled()) {
 
941
                                // Paint Handle
 
942
                                if (handle != null) {
 
943
                                        handle.paint(g);
 
944
                                }
 
945
 
 
946
                                // Paint Marquee
 
947
                                if (marquee != null) {
 
948
                                        marquee.paint(graph, g);
 
949
                                }
 
950
                        }
941
951
                        paintOverlay(g);
942
952
                        offGraphics.setClip(null);
943
953
                } else {
 
954
                        // Not double buffered
944
955
                        drawGraph(g, clipBounds);
945
956
                }
946
 
 
947
 
        }
948
 
 
949
 
        private void renderOffscreen(Graphics offGraphics, Rectangle2D clipBounds) {
950
 
                offGraphics.setColor(graph.getBackground());
951
 
                offGraphics.setPaintMode();
952
 
                Rectangle2D graphBounds = graph.getBounds();
953
 
                offGraphics.fillRect(0, 0, (int) graphBounds.getWidth(), (int) graphBounds
954
 
                                .getHeight());
955
 
                drawGraph(offGraphics, clipBounds);
956
957
        }
957
958
 
958
959
        /**
974
975
         *            the bounds within graph cells must intersect to be redrawn
975
976
         */
976
977
        public void drawGraph(Graphics g, Rectangle2D clipBounds) {
 
978
//              if (g.getClip() != null && clipBounds != null && !(g.getClip().equals(clipBounds))) {
 
979
                        g.setClip(clipBounds);
 
980
//              }
977
981
                Rectangle2D realClipBounds = null;
978
982
                if (clipBounds != null) {
979
 
                        Rectangle2D paintBounds = new Rectangle2D.Double(clipBounds.getX(),
980
 
                                        clipBounds.getY(), clipBounds.getWidth(), clipBounds
981
 
                                                        .getHeight());
982
983
                        realClipBounds = graph.fromScreen(new Rectangle2D.Double(
983
 
                                        paintBounds.getX(), paintBounds.getY(), paintBounds
984
 
                                                        .getWidth(), paintBounds.getHeight()));
 
984
                                        clipBounds.getX(), clipBounds.getY(), clipBounds
 
985
                                                        .getWidth(), clipBounds.getHeight()));
985
986
                }
986
987
                // Paint Background (Typically Grid)
987
988
                paintBackground(g);
1233
1234
         * Paint the foreground of this graph. Calls paintPorts.
1234
1235
         */
1235
1236
        protected void paintForeground(Graphics g) {
1236
 
                if (graph.isPortsVisible())
 
1237
                if (graph.isPortsVisible() && graph.isPortsOnTop())
1237
1238
                        paintPorts(g, graphLayoutCache.getPorts());
1238
1239
        }
1239
1240
 
1294
1295
                if (context != null && !context.isEmpty() && graph.isEnabled()) {
1295
1296
                        try {
1296
1297
                                return new RootHandle(context);
1297
 
                        } catch (NullPointerException e) {
1298
 
                                // ignore for now...
 
1298
                        } catch (HeadlessException e) {
 
1299
                                // Assume because of running on a server
 
1300
                        } catch (RuntimeException e) {
 
1301
                                throw e;
1299
1302
                        }
1300
1303
                }
1301
1304
                return null;
1692
1695
                                // Remove from selection
1693
1696
                                graph.getSelectionModel().removeSelectionCells(removed);
1694
1697
                        }
1695
 
                        if (graphLayoutCache != null)
 
1698
                        Rectangle2D oldDirty = null;
 
1699
                        Rectangle2D dirtyRegion = e.getChange().getDirtyRegion();
 
1700
                        if (dirtyRegion == null) {
 
1701
                                oldDirty = graph.getClipRectangle(e.getChange());
 
1702
                        }
 
1703
                        
 
1704
                        if (graphLayoutCache != null) {
1696
1705
                                graphLayoutCache.graphChanged(e.getChange());
 
1706
                        }
1697
1707
                        // Get arrays
1698
1708
                        Object[] inserted = e.getChange().getInserted();
1699
1709
                        Object[] changed = e.getChange().getChanged();
1710
1720
                                        graph.updateAutoSize(graphLayoutCache.getMapping(
1711
1721
                                                        changed[i], false));
1712
1722
                        }
 
1723
                        if (dirtyRegion == null) {
 
1724
                                Rectangle2D newDirtyRegion = graph.getClipRectangle(e.getChange());
 
1725
                                dirtyRegion = RectUtils.union(oldDirty, newDirtyRegion);
 
1726
                                e.getChange().setDirtyRegion(dirtyRegion);
 
1727
                        }
 
1728
                        
 
1729
                        if (dirtyRegion != null) {
 
1730
                                graph.addOffscreenDirty(dirtyRegion);
 
1731
                        }
1713
1732
                        // Select if not partial
1714
1733
                        if (!graphLayoutCache.isPartial()
1715
1734
                                        && graphLayoutCache.isSelectsAllInsertedCells()
1724
1743
                        }
1725
1744
                        updateSize();
1726
1745
                }
1727
 
 
 
1746
                
1728
1747
        } // End of BasicGraphUI.GraphModelHandler
1729
1748
 
1730
1749
        /**
1746
1765
                                                        changed[i], false));
1747
1766
                                }
1748
1767
                        }
 
1768
                        Rectangle2D oldDirtyRegion = e.getChange().getDirtyRegion();
 
1769
                        graph.addOffscreenDirty(oldDirtyRegion);
 
1770
                        Rectangle2D newDirtyRegion = graph.getClipRectangle(e.getChange());
 
1771
                        graph.addOffscreenDirty(newDirtyRegion);
1749
1772
                        Object[] inserted = e.getChange().getInserted();
1750
1773
                        if (inserted != null
1751
1774
                                        && inserted.length > 0
1798
1821
                                                r = lastFocus.getBounds();
1799
1822
                                }
1800
1823
                                if (r != null) {
 
1824
                                        Rectangle2D unscaledDirty = graph.fromScreen((Rectangle2D)r.clone());
 
1825
                                        graph.addOffscreenDirty(unscaledDirty);
1801
1826
                                        int hsize = (int) (graph.getHandleSize() * graph.getScale()) + 1;
1802
1827
                                        updateHandle();
1803
 
                                        graph.repaint((int) r.getX() - hsize, (int) r.getY()
1804
 
                                                        - hsize, (int) r.getWidth() + 2 * hsize, (int) r
1805
 
                                                        .getHeight()
1806
 
                                                        + 2 * hsize);
 
1828
                                        Rectangle dirtyRegion = new Rectangle((int)(r.getX()
 
1829
                                                        - hsize), (int)(r.getY() - hsize),
 
1830
                                                        (int)(r.getWidth() + 2 * hsize), (int)(r.getHeight() + 2 * hsize));
 
1831
                                        graph.repaint(dirtyRegion);
1807
1832
                                }
1808
 
                        } else
 
1833
                        } else {
 
1834
                                Rectangle dirtyRegion = (Rectangle)graph.getBounds().clone();
 
1835
                                graph.addOffscreenDirty(dirtyRegion);
1809
1836
                                graph.repaint();
 
1837
                        }
1810
1838
                }
1811
1839
        }
1812
1840
 
2765
2793
                                                        double dx = snapCurrent.getX() - start.getX();
2766
2794
                                                        double dy = snapCurrent.getY() - start.getY();
2767
2795
                                                        
 
2796
                                                        if (!graph.isMoveBelowZero() && initialLocation.getX() + dx < 0)
 
2797
                                                            dx = -1 * initialLocation.getX();
 
2798
                                                        if (!graph.isMoveBelowZero() && initialLocation.getY() + dy < 0)
 
2799
                                                            dy = -1 * initialLocation.getY();
 
2800
                                                        
2768
2801
                                                        Point2D tmp = graph.fromScreen(new Point2D.Double(
2769
2802
                                                                        dx, dy));
2770
2803
                                                        GraphLayoutCache.translateViews(views, tmp.getX(),