1 19 package org.netbeans.modules.palette.ui; 20 21 import java.awt.Component ; 22 import java.awt.Graphics ; 23 import java.awt.Rectangle ; 24 import java.awt.geom.Line2D ; 25 26 import java.util.HashMap ; 27 28 import javax.swing.JComponent ; 29 import javax.swing.JPanel ; 30 import javax.swing.JTree ; 31 32 33 41 final class DropGlassPane extends JPanel { 42 static private HashMap <Integer ,DropGlassPane> map = new HashMap <Integer ,DropGlassPane>(); 43 final static private int MIN_X = 0; final static private int MIN_Y = 0; final static private int MIN_WIDTH = 0; final static private int MIN_HEIGTH = 0; static private Component oldPane; 48 static private JComponent originalSource; 49 static private boolean wasVisible; 50 Line2D line = null; 51 Rectangle prevLineRect = null; 52 53 private DropGlassPane() { 54 } 55 56 60 synchronized static public DropGlassPane getDefault(JComponent comp) { 61 Integer id = Integer.valueOf(System.identityHashCode(comp)); 62 63 if ((map.get(id)) == null) { 64 DropGlassPane dgp = new DropGlassPane(); 65 dgp.setOpaque(false); 66 map.put(id, dgp); 67 } 68 69 return map.get(id); 70 } 71 72 77 static void setOriginalPane( JComponent source, Component pane, boolean visible ) { 78 oldPane = pane; 80 originalSource = source; 81 wasVisible = visible; 82 } 83 84 87 static boolean isOriginalPaneStored() { 88 return oldPane != null; 89 } 90 91 93 static void putBackOriginal() { 94 if (oldPane == null) { 95 return; 97 } 98 99 originalSource.getRootPane().setGlassPane(oldPane); 100 oldPane.setVisible(wasVisible); 101 oldPane = null; 102 } 103 104 106 public void setVisible(boolean aFlag) { 107 super.setVisible(aFlag); 108 109 if (!aFlag) { 110 setDropLine(null); 111 } 112 } 113 114 116 public void setDropLine(Line2D line) { 117 if( !isValid() ) 118 return; 119 120 if( null != prevLineRect 121 && ((null != line 122 && (!prevLineRect.contains( line.getP1() ) 123 || !prevLineRect.contains( line.getP2() ))) 124 || null == line) ) { 125 126 repaint( prevLineRect ); 127 } 128 129 this.line = line; 130 Rectangle newLineRect = null; 131 if( null != this.line ) { 132 checkLineBounds( this.line ); 133 newLineRect = line.getBounds(); 134 newLineRect.grow( 5, 5 ); 135 } 136 137 if( null != newLineRect && !newLineRect.equals( prevLineRect ) ) { 138 repaint( newLineRect ); 139 } 140 prevLineRect = newLineRect; 141 } 142 143 147 private Line2D checkLineBounds(Line2D line) { 148 Rectangle bounds = getBounds(); 149 double startPointX; 150 double startPointY; 151 double endPointX; 152 double endPointY; 153 154 startPointX = Math.max(line.getX1(), bounds.x + MIN_X); 156 startPointY = Math.max(line.getY1(), bounds.y + MIN_Y); 157 158 endPointX = Math.min(line.getX2(), (bounds.x + bounds.width)); endPointY = Math.min(line.getY2(), (bounds.y + bounds.height) - MIN_HEIGTH); 161 162 line.setLine(startPointX, startPointY, endPointX, endPointY); 164 165 return line; 166 } 167 168 170 public void paint(Graphics g) { 171 if (line != null) { 172 173 int x1 = (int) line.getX1(); 174 int x2 = (int) line.getX2(); 175 int y1 = (int) line.getY1(); 176 int y2 = (int)line.getY2 (); 177 178 if( y1 == y2 ) { 179 g.drawLine(x1 + 2, y1, x2 - 2, y1); 181 g.drawLine(x1 + 2, y1 + 1, x2 - 2, y1 + 1); 182 183 g.drawLine(x1, y1 - 2, x1, y1 + 3); 185 g.drawLine(x1 + 1, y2 - 1, x1 + 1, y1 + 2); 186 187 g.drawLine(x2, y1 - 2, x2, y1 + 3); 189 g.drawLine(x2 - 1, y1 - 1, x2 - 1, y1 + 2); 190 } else { 191 g.drawLine(x1, y1 + 2, x2, y2 - 2); 193 g.drawLine(x1 + 1, y1 + 2, x2 + 1, y2 - 2); 194 195 g.drawLine(x1 - 2, y1, x1 + 3, y1); 197 g.drawLine(x1 - 1, y1 + 1, x1 + 2, y1 + 1); 198 199 g.drawLine(x2 - 2, y2, x2 + 3, y2); 201 g.drawLine(x2 - 1, y2 - 1, x2 + 2, y2 - 1); 202 } 203 } 204 } 205 } 206 | Popular Tags |