View Javadoc
1 package com.bonevich.erj.diagram; 2 3 import com.bonevich.erj.ErjConstants; 4 5 import org.tigris.gef.presentation.*; 6 7 import java.awt.*; 8 import java.util.Enumeration; 9 10 /*** 11 * A subclass of Fig that displays an AWT/Swing container 12 * and its contents. 13 */ 14 public class FigContainer extends FigGroup 15 { 16 //////////////////////////////////////////////////////////////// 17 // Attributes 18 private Fig _verticalStrut; 19 20 ////////////////////////////////////////////////////////// 21 // Constructors 22 public FigContainer() 23 { 24 this(0,0,0,0); 25 } 26 27 public FigContainer(int x, int y, int w, int h) 28 { 29 _x = x; _y = y; _w = w; _h = h; 30 _verticalStrut = new FigStrut(x, y, w, h); 31 addFig(_verticalStrut); 32 } 33 34 public void addFig(Fig f) 35 { 36 // we always want the strut at the bottom, so pop it off the stack first 37 _figs.remove(_verticalStrut); 38 if (f != _verticalStrut) 39 { 40 super.addFig(f); 41 } 42 super.addFig(_verticalStrut); 43 updateBounds(); 44 } 45 46 public Dimension getMinimumSize() 47 { 48 int maxW = 0, curH = 0; 49 50 Enumeration figs = _figs.elements(); 51 while (figs.hasMoreElements()) 52 { 53 Fig f = (Fig) figs.nextElement(); 54 Dimension dim = f.getMinimumSize(); 55 maxW = Math.max(dim.width, maxW); 56 curH += dim.height; 57 } 58 59 return new Dimension(maxW, curH); 60 } 61 62 public void setBounds(int x, int y, int w, int h) 63 { 64 Rectangle oldBounds = getBounds(); 65 66 // calculate the max width and the cumulative height 67 // of all the figs grouped in this node 68 int maxWidth = w; 69 int maxHeight = h; 70 maxWidth = Math.max(getMinimumSize().width, maxWidth); 71 maxHeight = Math.max(getMinimumSize().height, maxHeight); 72 73 int curY = y; 74 Enumeration figs = _figs.elements(); 75 while (figs.hasMoreElements()) 76 { 77 Fig f = (Fig) figs.nextElement(); 78 Dimension dim = f.getMinimumSize(); 79 int height = dim.height; 80 if (f == _verticalStrut) height = maxHeight - (curY - y); 81 f.setBounds(x, curY, maxWidth, height); 82 curY += dim.height; 83 } 84 85 _x = x; 86 _y = y; 87 _w = maxWidth; 88 _h = maxHeight; 89 90 calcBounds(); //this is super.calcBounds really - figures out a bounding box for all figs 91 firePropChange("bounds", oldBounds, getBounds()); 92 } 93 94 private void updateBounds() 95 { 96 setBounds(getBounds()); 97 startTrans(); 98 } 99 100 public void paint(Graphics g) 101 { 102 super.paint(g); 103 104 // paint the line 105 if (_lineWidth > 0 && _lineColor != null) 106 { 107 g.setColor(_lineColor); 108 g.drawRect(_x, _y, _w - _lineWidth, _h - _lineWidth); 109 } 110 } 111 112 ////////////////////////////////////////////////////////// 113 // Inner classes 114 static class FigStrut extends Fig 115 { 116 public FigStrut(int x, int y, int w, int h) 117 { 118 super(x, y, w, h); 119 setLineWidth(0); 120 setFilled(true); 121 setFillColor(ErjConstants.SUBLABEL_FILL); 122 } 123 124 public void paint(Graphics g) 125 { 126 g.setColor(_fillColor); 127 g.fillRect(_x, _y, _w, _h); 128 if (_lineWidth > 0 && _lineColor != null) 129 { 130 g.setColor(_lineColor); 131 g.drawRect(_x, _y, _w - _lineWidth, _h - _lineWidth); 132 } 133 } 134 } /* end inner class FigStrut */ 135 136 } /* end class FigContainer */

This page was automatically generated by Maven