1 7 8 package javax.swing.plaf.synth; 9 10 11 import java.awt.*; 12 import java.awt.event.*; 13 import java.beans.*; 14 import java.util.*; 15 import javax.swing.*; 16 import javax.swing.event.*; 17 import javax.swing.plaf.*; 18 import javax.swing.plaf.basic.*; 19 import sun.swing.plaf.synth.SynthUI; 20 21 22 28 class SynthSplitPaneUI extends BasicSplitPaneUI implements 29 PropertyChangeListener, SynthUI { 30 34 private static Set managingFocusForwardTraversalKeys; 35 36 40 private static Set managingFocusBackwardTraversalKeys; 41 42 45 private SynthStyle style; 46 49 private SynthStyle dividerStyle; 50 51 52 55 public static ComponentUI createUI(JComponent x) { 56 return new SynthSplitPaneUI (); 57 } 58 59 62 protected void installDefaults() { 63 updateStyle(splitPane); 64 65 setOrientation(splitPane.getOrientation()); 66 setContinuousLayout(splitPane.isContinuousLayout()); 67 68 resetLayoutManager(); 69 70 72 if(nonContinuousLayoutDivider == null) { 73 setNonContinuousLayoutDivider( 74 createDefaultNonContinuousLayoutDivider(), 75 true); 76 } else { 77 setNonContinuousLayoutDivider(nonContinuousLayoutDivider, true); 78 } 79 80 if (managingFocusForwardTraversalKeys==null) { 82 managingFocusForwardTraversalKeys = new TreeSet(); 83 managingFocusForwardTraversalKeys.add( 84 KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); 85 } 86 splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, 87 managingFocusForwardTraversalKeys); 88 if (managingFocusBackwardTraversalKeys==null) { 90 managingFocusBackwardTraversalKeys = new TreeSet(); 91 managingFocusBackwardTraversalKeys.add( 92 KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); 93 } 94 splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, 95 managingFocusBackwardTraversalKeys); 96 } 97 98 private void updateStyle(JSplitPane splitPane) { 99 SynthContext context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, 100 ENABLED); 101 SynthStyle oldDividerStyle = dividerStyle; 102 dividerStyle = SynthLookAndFeel.updateStyle(context, this); 103 context.dispose(); 104 105 context = getContext(splitPane, ENABLED); 106 SynthStyle oldStyle = style; 107 108 style = SynthLookAndFeel.updateStyle(context, this); 109 110 if (style != oldStyle) { 111 Object value = style.get(context, "SplitPane.size"); 112 if (value == null) { 113 value = new Integer (6); 114 } 115 LookAndFeel.installProperty(splitPane, "dividerSize", value); 116 117 value = style.get(context, "SplitPane.oneTouchExpandable"); 118 if (value != null) { 119 LookAndFeel.installProperty(splitPane, "oneTouchExpandable", value); 120 } 121 122 if (divider != null) { 123 splitPane.remove(divider); 124 divider.setDividerSize(splitPane.getDividerSize()); 125 } 126 if (oldStyle != null) { 127 uninstallKeyboardActions(); 128 installKeyboardActions(); 129 } 130 } 131 if (style != oldStyle || dividerStyle != oldDividerStyle) { 132 if (divider != null) { 135 splitPane.remove(divider); 136 } 137 divider = createDefaultDivider(); 138 divider.setBasicSplitPaneUI(this); 139 splitPane.add(divider, JSplitPane.DIVIDER); 140 } 141 context.dispose(); 142 } 143 144 147 protected void installListeners() { 148 super.installListeners(); 149 splitPane.addPropertyChangeListener(this); 150 } 151 152 155 protected void uninstallDefaults() { 156 SynthContext context = getContext(splitPane, ENABLED); 157 158 style.uninstallDefaults(context); 159 context.dispose(); 160 style = null; 161 162 context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, ENABLED); 163 dividerStyle.uninstallDefaults(context); 164 context.dispose(); 165 dividerStyle = null; 166 167 super.uninstallDefaults(); 168 } 169 170 171 174 protected void uninstallListeners() { 175 super.uninstallListeners(); 176 splitPane.removePropertyChangeListener(this); 177 } 178 179 180 public SynthContext getContext(JComponent c) { 181 return getContext(c, getComponentState(c)); 182 } 183 184 private SynthContext getContext(JComponent c, int state) { 185 return SynthContext.getContext(SynthContext .class, c, 186 SynthLookAndFeel.getRegion(c), style, state); 187 } 188 189 private Region getRegion(JComponent c) { 190 return SynthLookAndFeel.getRegion(c); 191 } 192 193 private int getComponentState(JComponent c) { 194 return SynthLookAndFeel.getComponentState(c); 195 } 196 197 SynthContext getContext(JComponent c, Region region) { 198 return getContext(c, region, getComponentState(c, region)); 199 } 200 201 private SynthContext getContext(JComponent c, Region region, int state) { 202 if (region == Region.SPLIT_PANE_DIVIDER) { 203 return SynthContext.getContext(SynthContext .class, c, region, 204 dividerStyle, state); 205 } 206 return SynthContext.getContext(SynthContext .class, c, region, 207 style, state); 208 } 209 210 private int getComponentState(JComponent c, Region subregion) { 211 int state = SynthLookAndFeel.getComponentState(c); 212 213 if (divider.isMouseOver()) { 214 state |= MOUSE_OVER; 215 } 216 return state; 217 } 218 219 220 public void propertyChange(PropertyChangeEvent e) { 221 if (SynthLookAndFeel.shouldUpdateStyle(e)) { 222 updateStyle((JSplitPane)e.getSource()); 223 } 224 } 225 226 229 public BasicSplitPaneDivider createDefaultDivider() { 230 SynthSplitPaneDivider divider = new SynthSplitPaneDivider (this); 231 232 divider.setDividerSize(splitPane.getDividerSize()); 233 return divider; 234 } 235 236 protected Component createDefaultNonContinuousLayoutDivider() { 237 return new Canvas() { 238 public void paint(Graphics g) { 239 paintDragDivider(g, 0, 0, getWidth(), getHeight()); 240 } 241 }; 242 } 243 244 public void update(Graphics g, JComponent c) { 245 SynthContext context = getContext(c); 246 247 SynthLookAndFeel.update(context, g); 248 context.getPainter().paintSplitPaneBackground(context, 249 g, 0, 0, c.getWidth(), c.getHeight()); 250 paint(context, g); 251 context.dispose(); 252 } 253 254 public void paint(Graphics g, JComponent c) { 255 SynthContext context = getContext(c); 256 257 paint(context, g); 258 context.dispose(); 259 } 260 261 protected void paint(SynthContext context, Graphics g) { 262 super.paint(g, splitPane); 265 } 266 267 268 public void paintBorder(SynthContext context, Graphics g, int x, 269 int y, int w, int h) { 270 context.getPainter().paintSplitPaneBorder(context, g, x, y, w, h); 271 } 272 273 private void paintDragDivider(Graphics g, int x, int y, int w, int h) { 274 SynthContext context = getContext(splitPane,Region.SPLIT_PANE_DIVIDER); 275 context.setComponentState(((context.getComponentState() | MOUSE_OVER) ^ 276 MOUSE_OVER) | PRESSED); 277 Shape oldClip = g.getClip(); 278 g.clipRect(x, y, w, h); 279 context.getPainter().paintSplitPaneDragDivider(context, g, x, y, w, h, 280 splitPane.getOrientation()); 281 g.setClip(oldClip); 282 context.dispose(); 283 } 284 285 public void finishedPaintingChildren(JSplitPane jc, Graphics g) { 286 if(jc == splitPane && getLastDragLocation() != -1 && 287 !isContinuousLayout() && !draggingHW) { 288 if(jc.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { 289 paintDragDivider(g, getLastDragLocation(), 0, dividerSize - 1, 290 splitPane.getHeight() - 1); 291 } else { 292 paintDragDivider(g, 0, getLastDragLocation(), 293 splitPane.getWidth() - 1, dividerSize - 1); 294 } 295 } 296 } 297 } 298 | Popular Tags |