1 19 package org.openide.explorer.view; 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 import javax.swing.UIManager ; 32 33 34 42 final class DropGlassPane extends JPanel { 43 private static HashMap <Integer , DropGlassPane> map = new HashMap <Integer , DropGlassPane>(); 44 final static private int MIN_X = 5; 45 final static private int MIN_Y = 3; 46 final static private int MIN_WIDTH = 10; 47 final static private int MIN_HEIGTH = 3; 48 transient static private Component oldPane; 49 transient static private JTree originalSource; 50 transient static private boolean wasVisible; 51 Line2D line = null; 52 53 private DropGlassPane() { 54 } 55 56 60 synchronized static public DropGlassPane getDefault(JComponent comp) { 61 Integer id = new Integer (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(JTree 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 this.line = line; 118 119 } 121 122 126 private Line2D checkLineBounds(Line2D line) { 127 Rectangle bounds = getBounds(); 128 double startPointX; 129 double startPointY; 130 double endPointX; 131 double endPointY; 132 133 startPointX = Math.max(line.getX1(), bounds.x + MIN_X); 135 startPointY = Math.max(line.getY1(), bounds.y + MIN_Y); 136 137 endPointX = Math.min(line.getX2(), (bounds.x + bounds.width) - MIN_WIDTH); 139 endPointY = Math.min(line.getY2(), (bounds.y + bounds.height) - MIN_HEIGTH); 140 141 line.setLine(startPointX, startPointY, endPointX, endPointY); 143 144 return line; 145 } 146 147 149 public void paint(Graphics g) { 150 if (line != null) { 151 line = checkLineBounds(line); 153 154 int x1 = (int) line.getX1(); 155 int x2 = (int) line.getX2(); 156 int y1 = (int) line.getY1(); 157 158 g.setColor( UIManager.getColor( "Tree.selectionBackground" ) ); 159 160 g.drawLine(x1 + 2, y1, x2 - 2, y1); 163 g.drawLine(x1 + 2, y1 + 1, x2 - 2, y1 + 1); 164 165 g.drawLine(x1, y1 - 2, x1, y1 + 3); 167 g.drawLine(x1 + 1, y1 - 1, x1 + 1, y1 + 2); 168 169 g.drawLine(x2, y1 - 2, x2, y1 + 3); 171 g.drawLine(x2 - 1, y1 - 1, x2 - 1, y1 + 2); 172 } 173 174 176 181 } 182 } 183 | Popular Tags |