1 9 10 package org.netbeans.modules.web.jsf.navigation.graph; 11 12 import java.awt.Image ; 13 import java.awt.Point ; 14 import java.awt.Rectangle ; 15 import java.util.Collection ; 16 import org.netbeans.api.visual.layout.Layout; 17 import org.netbeans.api.visual.layout.LayoutFactory; 18 import org.netbeans.api.visual.vmd.VMDNodeWidget; 19 import org.netbeans.api.visual.widget.ImageWidget; 20 import org.netbeans.api.visual.widget.Scene; 21 import org.netbeans.api.visual.widget.Widget; 22 import org.openide.util.Utilities; 23 24 28 public class NavigationNodeWidget extends VMDNodeWidget{ 29 30 private static final Image POINT_SHAPE_IMAGE = Utilities.loadImage("org/netbeans/modules/visual/resources/vmd-pin.png"); 32 33 36 public NavigationNodeWidget(Scene scene) { 37 super(scene); 38 39 setLayout( new NavigationNodeLayout(true, LayoutFactory.SerialAlignment.JUSTIFY, 0) ); 40 43 53 55 57 58 } 66 67 private class DefaultPinWidget extends ImageWidget { 68 private DefaultPinWidget(Scene scene, Image image) { 69 super(scene, image); 70 } 71 } 72 73 private static class NavigationNodeLayout implements Layout { 74 75 private boolean verticalOrientation; 76 private LayoutFactory.SerialAlignment alignment; 77 private int gap; 78 79 public NavigationNodeLayout(boolean verticalOrientation, LayoutFactory.SerialAlignment alignment, int gap) { 80 this.verticalOrientation = verticalOrientation; 81 this.alignment = alignment; 82 this.gap = gap; 83 } 84 85 private DefaultPinWidget defaultPinWidget = null; 86 87 public void layout(Widget widget) { 88 int max = 0; 89 Collection <Widget> children = widget.getChildren(); 90 for (Widget child : children) { 91 if (! child.isVisible()) 92 continue; 93 Rectangle preferredBounds = child.getPreferredBounds(); 94 int i = preferredBounds.width; 95 if (i > max) 96 max = i; 97 } 98 int pos = 0; 99 100 for (Widget child : children) { 101 if (child instanceof DefaultPinWidget ){ 102 defaultPinWidget = (DefaultPinWidget)child; 103 defaultPinWidget.resolveBounds(new Point (max,5), null); 104 continue; 105 } 106 Rectangle preferredBounds = child.getPreferredBounds(); 107 int x = preferredBounds.x; 108 int y = preferredBounds.y; 109 int width = preferredBounds.width; 110 int height = preferredBounds.height; 111 int lx = - x; 112 int ly = pos - y; 113 width = max; if (child.isVisible()) { 115 child.resolveBounds(new Point (lx, ly), new Rectangle (x, y, width, height)); 116 pos += height + gap; 117 } else 118 child.resolveBounds(new Point (lx, ly), new Rectangle (x, y, 0, 0)); 119 } 120 121 124 } 125 126 public boolean requiresJustification(Widget widget) { 127 return true; 128 } 129 130 public void justify(Widget widget) { 131 for (Widget child : widget.getChildren()) { 132 Rectangle bounds = widget.getClientArea(); 133 Point location = child.getLocation(); 134 Rectangle childBounds = child.getBounds(); 135 136 if (verticalOrientation) { 137 int parentX1 = bounds.x; 138 int parentX2 = parentX1 + bounds.width; 139 int childX1 = location.x + childBounds.x; 140 int childX2 = childX1 + childBounds.width; 141 142 childBounds.x = Math.min(parentX1, childX1); 143 childBounds.width = Math.max(parentX2, childX2) - childBounds.x; 144 childBounds.x -= location.x; 145 } 146 child.resolveBounds(location, childBounds); 147 } 148 } 149 } 150 } 151 | Popular Tags |