Lines 41-76
Link Here
|
41 |
|
41 |
|
42 |
package org.openide.awt; |
42 |
package org.openide.awt; |
43 |
|
43 |
|
44 |
import java.awt.*; |
44 |
import java.awt.Component; |
45 |
import java.awt.datatransfer.*; |
45 |
import java.awt.Insets; |
46 |
import java.awt.dnd.*; |
|
|
47 |
import java.awt.event.*; |
48 |
import java.io.IOException; |
46 |
import java.io.IOException; |
49 |
import java.lang.reflect.InvocationTargetException; |
47 |
import java.util.EventListener; |
50 |
import java.lang.reflect.Method; |
|
|
51 |
import java.util.ArrayList; |
52 |
import java.util.Arrays; |
53 |
import java.util.EventObject; |
48 |
import java.util.EventObject; |
54 |
import java.util.HashMap; |
49 |
import java.util.HashMap; |
55 |
import java.util.Map; |
50 |
import java.util.Map; |
56 |
import java.util.logging.Level; |
51 |
import java.util.logging.Level; |
57 |
import java.util.logging.Logger; |
52 |
import java.util.logging.Logger; |
58 |
import javax.swing.*; |
53 |
import javax.swing.AbstractButton; |
59 |
import javax.swing.border.*; |
54 |
import javax.swing.Action; |
60 |
import javax.swing.event.*; |
55 |
import javax.swing.Icon; |
|
|
56 |
import javax.swing.ImageIcon; |
57 |
import javax.swing.JButton; |
58 |
import javax.swing.JComponent; |
59 |
import javax.swing.JSeparator; |
60 |
import javax.swing.JToolBar; |
61 |
import javax.swing.UIManager; |
61 |
import javax.swing.plaf.metal.MetalLookAndFeel; |
62 |
import javax.swing.plaf.metal.MetalLookAndFeel; |
62 |
import javax.swing.plaf.synth.Region; |
|
|
63 |
import javax.swing.plaf.synth.SynthConstants; |
64 |
import javax.swing.plaf.synth.SynthContext; |
65 |
import javax.swing.plaf.synth.SynthLookAndFeel; |
66 |
import javax.swing.plaf.synth.SynthStyle; |
67 |
import javax.swing.plaf.synth.SynthStyleFactory; |
68 |
import org.openide.cookies.InstanceCookie; |
63 |
import org.openide.cookies.InstanceCookie; |
69 |
import org.openide.loaders.*; |
64 |
import org.openide.loaders.DataFolder; |
70 |
import org.openide.nodes.Node; |
65 |
import org.openide.loaders.DataObject; |
71 |
import org.openide.util.*; |
66 |
import org.openide.loaders.FolderInstance; |
|
|
67 |
import org.openide.util.ImageUtilities; |
68 |
import org.openide.util.Task; |
72 |
import org.openide.util.actions.Presenter; |
69 |
import org.openide.util.actions.Presenter; |
73 |
import org.openide.util.datatransfer.ExTransferable; |
|
|
74 |
|
70 |
|
75 |
/** |
71 |
/** |
76 |
* Toolbar provides a component which is useful for displaying commonly used |
72 |
* Toolbar provides a component which is useful for displaying commonly used |
Lines 87-113
Link Here
|
87 |
|
83 |
|
88 |
static final Logger LOG = Logger.getLogger(Toolbar.class.getName()); |
84 |
static final Logger LOG = Logger.getLogger(Toolbar.class.getName()); |
89 |
|
85 |
|
90 |
/** 5 pixels is tolerance of toolbar height so toolbar can be high (BASIC_HEIGHT + HEIGHT_TOLERANCE) |
|
|
91 |
but it will be set to BASIC_HEIGHT high. */ |
92 |
static int HEIGHT_TOLERANCE = 5; |
93 |
/** TOP of toolbar empty border. */ |
94 |
static int TOP = 2; |
95 |
/** LEFT of toolbar empty border. */ |
96 |
static int LEFT = 3; |
97 |
/** BOTTOM of toolbar empty border. */ |
98 |
static int BOTTOM = 2; |
99 |
/** RIGHT of toolbar empty border. */ |
100 |
static int RIGHT = 3; |
101 |
/** Residual size of the toolbar when dragged far right */ |
102 |
static int RESIDUAL_WIDTH = 16; |
103 |
|
104 |
|
105 |
/** is toolbar floatable */ |
106 |
private boolean floatable; |
107 |
/** Toolbar DnDListener */ |
86 |
/** Toolbar DnDListener */ |
108 |
private DnDListener listener; |
87 |
private DnDListener listener; |
109 |
/** Toolbar mouse listener */ |
|
|
110 |
private ToolbarMouseListener mouseListener; |
111 |
/** display name of the toolbar */ |
88 |
/** display name of the toolbar */ |
112 |
private String displayName; |
89 |
private String displayName; |
113 |
|
90 |
|
Lines 130-153
Link Here
|
130 |
isJdk16 = javaVersion.startsWith( "1.6" ); |
107 |
isJdk16 = javaVersion.startsWith( "1.6" ); |
131 |
} |
108 |
} |
132 |
|
109 |
|
133 |
private static final int customFontHeightCorrection; |
|
|
134 |
|
135 |
static { |
136 |
int customFontSize = UIManager.getInt( "customFontSize" ); |
137 |
if( customFontSize < 1 ) |
138 |
customFontSize = 1; |
139 |
|
140 |
int defaultFontSize = UIManager.getInt( "nbDefaultFontSize" ); |
141 |
if( defaultFontSize <= 0 ) |
142 |
defaultFontSize = 11; |
143 |
|
144 |
customFontHeightCorrection = Math.max( customFontSize - defaultFontSize, 0 ); |
145 |
} |
146 |
|
147 |
private static Class synthIconClass = null; |
148 |
|
149 |
private static boolean testExecuted = false; |
150 |
|
151 |
/** Create a new Toolbar with empty name. */ |
110 |
/** Create a new Toolbar with empty name. */ |
152 |
public Toolbar () { |
111 |
public Toolbar () { |
153 |
this (""); // NOI18N |
112 |
this (""); // NOI18N |
Lines 174-616
Link Here
|
174 |
this (name, name, f); |
133 |
this (name, name, f); |
175 |
} |
134 |
} |
176 |
|
135 |
|
177 |
Toolbar(DataFolder folder, boolean f) { |
136 |
Toolbar(DataFolder folder) { |
178 |
super(); |
137 |
super(); |
179 |
backingFolder = folder; |
138 |
backingFolder = folder; |
180 |
initAll(folder.getName(), f); |
139 |
initAll(folder.getName(), false); |
181 |
initDnD(); |
140 |
putClientProperty("folder", folder); //NOI18N |
182 |
} |
141 |
} |
183 |
|
142 |
|
184 |
/** |
|
|
185 |
* Test if SynthIcon is available and can be used for painting native Toolbar |
186 |
* D&D handle. If not use our own handle. Reflection is used here as it is Sun |
187 |
* proprietary API. |
188 |
*/ |
189 |
private static boolean useSynthIcon () { |
190 |
if (!testExecuted) { |
191 |
testExecuted = true; |
192 |
try { |
193 |
synthIconClass = Class.forName("sun.swing.plaf.synth.SynthIcon"); |
194 |
} catch (ClassNotFoundException exc) { |
195 |
LOG.log(Level.INFO, null, exc); |
196 |
} |
197 |
} |
198 |
return (synthIconClass != null); |
199 |
} |
200 |
|
201 |
private void initDnD() { |
202 |
DropTarget dt = new DropTarget(this, getDnd()); |
203 |
} |
204 |
|
205 |
DataFolder getFolder() { |
143 |
DataFolder getFolder() { |
206 |
return backingFolder; |
144 |
return backingFolder; |
207 |
} |
145 |
} |
208 |
|
146 |
|
209 |
|
|
|
210 |
@Override |
211 |
public void paint( Graphics g ) { |
212 |
super.paint( g ); |
213 |
if( -1 != dropTargetButtonIndex ) { |
214 |
paintDropGesture( g ); |
215 |
} |
216 |
} |
217 |
|
218 |
private void updateDropGesture( DropTargetDragEvent e ) { |
219 |
Point p = e.getLocation(); |
220 |
Component c = getComponentAt(p); |
221 |
int index = Toolbar.this.getComponentIndex(c); |
222 |
if( index == 0 ) { |
223 |
//dragging over toolbar's grip |
224 |
resetDropGesture(); |
225 |
} else { |
226 |
//find out whether we want to drop before or after this component |
227 |
boolean b = p.x <= c.getLocation().x + c.getWidth() / 2; |
228 |
if( index != dropTargetButtonIndex || b != insertBefore ) { |
229 |
dropTargetButtonIndex = index; |
230 |
insertBefore = b; |
231 |
repaint(); |
232 |
} |
233 |
} |
234 |
} |
235 |
|
236 |
private void resetDropGesture() { |
237 |
dropTargetButtonIndex = -1; |
238 |
repaint(); |
239 |
} |
240 |
|
241 |
private void paintDropGesture( Graphics g ) { |
242 |
Component c = getComponentAtIndex( dropTargetButtonIndex ); |
243 |
if( null == c ) |
244 |
return; |
245 |
|
246 |
Point location = c.getLocation(); |
247 |
int cursorLocation = location.x; |
248 |
if( !insertBefore ) { |
249 |
cursorLocation += c.getWidth(); |
250 |
if( dropTargetButtonIndex == getComponentCount()-1 ) |
251 |
cursorLocation -= 3; |
252 |
} |
253 |
drawDropLine( g, cursorLocation ); |
254 |
} |
255 |
|
256 |
private void drawDropLine( Graphics g, int x ) { |
257 |
Color oldColor = g.getColor(); |
258 |
g.setColor( Color.black ); |
259 |
int height = getHeight(); |
260 |
g.drawLine( x, 3, x, height-4 ); |
261 |
g.drawLine( x-1, 3, x-1, height-4 ); |
262 |
|
263 |
g.drawLine( x+1, 2, x+1+2, 2 ); |
264 |
g.drawLine( x+1, height-3, x+1+2, height-3 ); |
265 |
|
266 |
g.drawLine( x-2, 2, x-2-2, 2 ); |
267 |
g.drawLine( x-2, height-3, x-2-2, height-3 ); |
268 |
g.setColor( oldColor ); |
269 |
} |
270 |
|
271 |
/** |
272 |
* Remove a toolbar button represented by the given Transferable. |
273 |
*/ |
274 |
private void removeButton( Transferable t ) { |
275 |
try { |
276 |
Object o = null; |
277 |
if( t.isDataFlavorSupported( buttonDataFlavor ) ) { |
278 |
o = t.getTransferData( buttonDataFlavor ); //XXX |
279 |
} |
280 |
if( null != o && o instanceof DataObject ) { |
281 |
((DataObject) o).delete(); |
282 |
repaint(); |
283 |
if( backingFolder.getChildren().length == 0 ) { |
284 |
javax.swing.SwingUtilities.invokeLater(new java.lang.Runnable() { |
285 |
|
286 |
public void run() { |
287 |
try { |
288 |
backingFolder.delete(); |
289 |
} |
290 |
catch (java.io.IOException e) { |
291 |
LOG.log(Level.WARNING, |
292 |
null, |
293 |
e); |
294 |
} |
295 |
} |
296 |
}); |
297 |
} |
298 |
} |
299 |
} catch( UnsupportedFlavorException ex ) { |
300 |
Exceptions.printStackTrace(ex); |
301 |
} catch (IOException ioe) { |
302 |
Exceptions.printStackTrace(ioe); |
303 |
} |
304 |
} |
305 |
|
306 |
/** |
307 |
* Perform the drop operation. |
308 |
* |
309 |
* @return True if the drop has been successful. |
310 |
*/ |
311 |
private boolean handleDrop( Transferable t ) { |
312 |
try { |
313 |
Object o; |
314 |
if( t.isDataFlavorSupported( actionDataFlavor ) ) { |
315 |
o = t.getTransferData( actionDataFlavor ); |
316 |
if( o instanceof Node ) { |
317 |
DataObject dobj = ((Node)o).getLookup().lookup( DataObject.class ); |
318 |
return addButton( dobj, dropTargetButtonIndex-1, insertBefore ); |
319 |
} |
320 |
} else { |
321 |
o = t.getTransferData( buttonDataFlavor ); |
322 |
if( o instanceof DataObject ) { |
323 |
return moveButton( (DataObject)o, dropTargetButtonIndex-1, insertBefore ); |
324 |
} |
325 |
} |
326 |
} catch (UnsupportedFlavorException e) { |
327 |
Exceptions.printStackTrace(e); |
328 |
} catch (IOException ioe) { |
329 |
Exceptions.printStackTrace(ioe); |
330 |
} |
331 |
return false; |
332 |
} |
333 |
|
334 |
/** |
335 |
* Component index of the button under the drag cursor, or -1 when the cursor |
336 |
* is above the toolbar drag handle |
337 |
*/ |
338 |
int dropTargetButtonIndex = -1; |
339 |
/** |
340 |
* Component index of the button being dragged, only used when dragging a button |
341 |
* within the same toolbar. |
342 |
*/ |
343 |
int dragSourceButtonIndex = -1; |
344 |
/** |
345 |
* True if the button being dragged should be dropped BEFORE the button |
346 |
* under the drag cursor. |
347 |
*/ |
348 |
boolean insertBefore = true; |
349 |
/** |
350 |
* True indicates the toolbar instance whose button is being dragged. |
351 |
*/ |
352 |
boolean isDragSourceToolbar = false; |
353 |
|
354 |
private static DataFlavor buttonDataFlavor = new DataFlavor( DataObject.class, "Toolbar Item" ); |
355 |
private static DataFlavor actionDataFlavor = new DataFlavor( Node.class, "Action Node" ); |
356 |
|
357 |
private DnDSupport dnd; |
358 |
private class DnDSupport implements DragSourceListener, DragGestureListener, DropTargetListener, DragSourceMotionListener { |
359 |
private DragSource dragSource = new DragSource(); |
360 |
|
361 |
private Cursor dragMoveCursor = DragSource.DefaultMoveDrop; |
362 |
private Cursor dragNoDropCursor = DragSource.DefaultMoveNoDrop; |
363 |
private Cursor dragRemoveCursor = Utilities.createCustomCursor( Toolbar.this, ImageUtilities.loadImage( "org/openide/loaders/delete.gif"), "NO_ACTION_MOVE" ); |
364 |
private Map<Component, DragGestureRecognizer> recognizers = new HashMap<Component, DragGestureRecognizer>(); |
365 |
|
366 |
public DnDSupport() { |
367 |
dragSource.addDragSourceMotionListener(this); |
368 |
} |
369 |
|
370 |
public void register(Component c) { |
371 |
DragGestureRecognizer dgr = recognizers.get( c ); |
372 |
if( null == dgr ) { |
373 |
dgr = dragSource.createDefaultDragGestureRecognizer(c, DnDConstants.ACTION_MOVE, this); |
374 |
recognizers.put( c, dgr ); |
375 |
} |
376 |
} |
377 |
|
378 |
public void unregister(Component c) { |
379 |
DragGestureRecognizer dgr = recognizers.get( c ); |
380 |
if( null != dgr ) { |
381 |
dgr.removeDragGestureListener( this ); |
382 |
recognizers.remove( c ); |
383 |
} |
384 |
} |
385 |
|
386 |
public void dragEnter(DragSourceDragEvent e) { |
387 |
//handled in dragMouseMoved |
388 |
} |
389 |
|
390 |
public void dragOver(DragSourceDragEvent e) { |
391 |
//handled in dragMouseMoved |
392 |
} |
393 |
|
394 |
public void dragExit(DragSourceEvent e) { |
395 |
//handled in dragMouseMoved |
396 |
resetDropGesture(); |
397 |
} |
398 |
|
399 |
public void dragDropEnd(DragSourceDropEvent e) { |
400 |
isDragSourceToolbar = false; |
401 |
Component sourceComponent = e.getDragSourceContext().getComponent(); |
402 |
if( sourceComponent instanceof JButton ) { |
403 |
((JButton)sourceComponent).getModel().setRollover( false ); |
404 |
} |
405 |
sourceComponent.repaint(); |
406 |
resetDropGesture(); |
407 |
if ( e.getDropSuccess() == false && !isInToolbarPanel( e.getLocation() ) ) { |
408 |
removeButton( e.getDragSourceContext().getTransferable() ); |
409 |
} |
410 |
} |
411 |
|
412 |
public void dragGestureRecognized(DragGestureEvent e) { |
413 |
if( !ToolbarPool.getDefault().isInEditMode() |
414 |
|| "QuickSearch".equals(getName()) ) //HACK (137286)- there's not better way... |
415 |
return; |
416 |
try { |
417 |
Component c = e.getComponent(); |
418 |
//do not allow to drag toolbar separators |
419 |
if( c instanceof JToolBar.Separator || "grip".equals( c.getName() ) ) |
420 |
return; |
421 |
Transferable t = null; |
422 |
if (c instanceof JComponent) { |
423 |
final DataObject dob = (DataObject) ((JComponent) c).getClientProperty("file"); |
424 |
if (dob != null) { |
425 |
t = new ExTransferable.Single( buttonDataFlavor ) { |
426 |
public Object getData() { |
427 |
return dob; |
428 |
} |
429 |
}; |
430 |
} |
431 |
} |
432 |
if( c instanceof JButton ) { |
433 |
((JButton)c).getModel().setArmed( false ); |
434 |
((JButton)c).getModel().setPressed( false ); |
435 |
((JButton)c).getModel().setRollover( true ); |
436 |
} |
437 |
if (t != null) { |
438 |
dragSourceButtonIndex = Toolbar.this.getComponentIndex( c ); |
439 |
isDragSourceToolbar = true; |
440 |
dragSource.startDrag(e, dragMoveCursor, t, this); |
441 |
} |
442 |
|
443 |
} catch ( InvalidDnDOperationException idoe ) { |
444 |
Exceptions.printStackTrace(idoe); |
445 |
} |
446 |
} |
447 |
|
448 |
public void dropActionChanged (DragSourceDragEvent e) { |
449 |
//ignore |
450 |
} |
451 |
|
452 |
public void drop(DropTargetDropEvent dtde) { |
453 |
boolean res = false; |
454 |
try { |
455 |
if( validateDropPosition() ) { |
456 |
res = handleDrop( dtde.getTransferable() ); |
457 |
} |
458 |
} finally { |
459 |
dtde.dropComplete(res); |
460 |
} |
461 |
resetDropGesture(); |
462 |
} |
463 |
|
464 |
public void dragExit(DropTargetEvent dte) { |
465 |
resetDropGesture(); |
466 |
} |
467 |
|
468 |
public void dropActionChanged(DropTargetDragEvent dtde) { |
469 |
//ignore |
470 |
} |
471 |
|
472 |
public void dragEnter(DropTargetDragEvent e) { |
473 |
if( e.isDataFlavorSupported( buttonDataFlavor ) |
474 |
|| e.isDataFlavorSupported( actionDataFlavor ) ) { |
475 |
e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); |
476 |
} else { |
477 |
e.rejectDrag(); |
478 |
} |
479 |
} |
480 |
|
481 |
public void dragOver(DropTargetDragEvent e) { |
482 |
if( e.isDataFlavorSupported( buttonDataFlavor ) |
483 |
|| e.isDataFlavorSupported( actionDataFlavor ) ) { |
484 |
updateDropGesture( e ); |
485 |
if( !validateDropPosition() ) { |
486 |
e.rejectDrag(); |
487 |
} else { |
488 |
e.acceptDrag( DnDConstants.ACTION_COPY_OR_MOVE ); |
489 |
} |
490 |
} else { |
491 |
e.rejectDrag(); |
492 |
} |
493 |
} |
494 |
|
495 |
public void dragMouseMoved(DragSourceDragEvent e) { |
496 |
DragSourceContext context = e.getDragSourceContext(); |
497 |
int action = e.getDropAction(); |
498 |
if ((action & DnDConstants.ACTION_MOVE) != 0) { |
499 |
context.setCursor( dragMoveCursor ); |
500 |
} else { |
501 |
if( isInToolbarPanel( e.getLocation() ) ) |
502 |
context.setCursor( dragNoDropCursor ); |
503 |
else |
504 |
context.setCursor( dragRemoveCursor ); |
505 |
} |
506 |
} |
507 |
} |
508 |
|
509 |
private boolean isInToolbarPanel( Point p ) { |
510 |
Component c = ToolbarPool.getDefault(); |
511 |
SwingUtilities.convertPointFromScreen( p, c ); |
512 |
return c.contains( p ); |
513 |
} |
514 |
|
515 |
/** |
516 |
* Add a new toolbar button represented by the given DataObject. |
517 |
*/ |
518 |
private boolean addButton( DataObject dobj, int dropIndex, boolean dropBefore ) throws IOException { |
519 |
if( null == dobj ) |
520 |
return false; |
521 |
//check if the dropped button (action) already exists in this toolbar |
522 |
String objName = dobj.getName(); |
523 |
DataObject[] children = backingFolder.getChildren(); |
524 |
for( int i=0; i<children.length; i++ ) { |
525 |
//TODO is comparing DataObject names ok? |
526 |
if( objName.equals( children[i].getName() ) ) { |
527 |
//user dropped to toolbat a new button that already exists in this toolbar |
528 |
//just move the existing button to a new position |
529 |
isDragSourceToolbar = true; |
530 |
return moveButton( children[i], dropIndex, dropBefore ); |
531 |
} |
532 |
} |
533 |
|
534 |
DataObject objUnderCursor = getDataObjectUnderDropCursor( dropIndex, dropBefore ); |
535 |
|
536 |
DataShadow shadow = DataShadow.create( backingFolder, dobj ); |
537 |
|
538 |
//find the added object |
539 |
DataObject newObj = null; |
540 |
children = backingFolder.getChildren(); |
541 |
for( int i=0; i<children.length; i++ ) { |
542 |
if( objName.equals( children[i].getName() ) ) { |
543 |
newObj = children[i]; |
544 |
break; |
545 |
} |
546 |
} |
547 |
|
548 |
if( null != newObj ) |
549 |
reorderButtons( newObj, objUnderCursor ); //put the button to its proper position |
550 |
|
551 |
return true; |
552 |
} |
553 |
|
554 |
/** |
555 |
* Move toolbar button to a new position. |
556 |
*/ |
557 |
private boolean moveButton( DataObject ob, int dropIndex, boolean dropBefore ) throws IOException { |
558 |
//find out which button is currently under the drag cursor |
559 |
DataObject objUnderCursor = getDataObjectUnderDropCursor( dropIndex, dropBefore ); |
560 |
|
561 |
if( !isDragSourceToolbar ) { |
562 |
//move button to the new toolbar |
563 |
ob.move(backingFolder); |
564 |
} |
565 |
|
566 |
reorderButtons( ob, objUnderCursor ); |
567 |
//else we're dragging a button to an empty toolbar |
568 |
return true; |
569 |
} |
570 |
|
571 |
private void reorderButtons( DataObject objToMove, DataObject objUnderCursor ) throws IOException { |
572 |
java.util.List<DataObject> children = |
573 |
new ArrayList<DataObject>( Arrays.asList( backingFolder.getChildren() ) ); |
574 |
if( null == objUnderCursor ) { |
575 |
children.remove( objToMove ); |
576 |
children.add( objToMove ); |
577 |
} else { |
578 |
int targetIndex = children.indexOf( objUnderCursor ); |
579 |
int currentIndex = children.indexOf( objToMove ); |
580 |
if( currentIndex < targetIndex ) |
581 |
targetIndex--; |
582 |
children.remove( objToMove ); |
583 |
children.add( targetIndex, objToMove ); |
584 |
} |
585 |
|
586 |
backingFolder.setOrder( children.toArray( new DataObject[children.size()]) ); |
587 |
} |
588 |
|
589 |
private DataObject getDataObjectUnderDropCursor( int dropIndex, boolean dropBefore ) { |
590 |
DataObject[] buttons = backingFolder.getChildren(); |
591 |
DataObject objUnderCursor = null; |
592 |
if( buttons.length > 0 ) { |
593 |
if( !dropBefore ) |
594 |
dropIndex++; |
595 |
if( dropIndex < buttons.length && dropIndex >= 0 ) { |
596 |
objUnderCursor = buttons[dropIndex]; |
597 |
} |
598 |
} |
599 |
return objUnderCursor; |
600 |
} |
601 |
|
602 |
private boolean validateDropPosition() { |
603 |
//the drag cursor cannot be positioned above toolbar's drag handle |
604 |
return dropTargetButtonIndex >= 0 |
605 |
//when toolbar has buttons '1 2 3 4 5' and we're dragging button 3, |
606 |
//do not allow drop between buttons 2 and 3 and also between buttons 3 and 3 |
607 |
&& !(isDragSourceToolbar && (dragSourceButtonIndex == dropTargetButtonIndex //drop index 3 |
608 |
|| (dropTargetButtonIndex == dragSourceButtonIndex-1 && !insertBefore) //drop index 2 |
609 |
|| (dropTargetButtonIndex == dragSourceButtonIndex+1 && insertBefore))) //drop index 4 |
610 |
//dragging a button to an empty toolbar |
611 |
|| (dropTargetButtonIndex < 0 && getComponentCount() == 1); |
612 |
} |
613 |
|
614 |
/** Start tracking content of the underlaying folder if not doing so yet */ |
147 |
/** Start tracking content of the underlaying folder if not doing so yet */ |
615 |
final Folder waitFinished() { |
148 |
final Folder waitFinished() { |
616 |
// check for too early call (from constructor and UI.setUp...) |
149 |
// check for too early call (from constructor and UI.setUp...) |
Lines 671-680
Link Here
|
671 |
} |
204 |
} |
672 |
|
205 |
|
673 |
super.addImpl (c, constraints, idx); |
206 |
super.addImpl (c, constraints, idx); |
674 |
if( !("grip".equals(c.getName()) || (c instanceof JToolBar.Separator)) ) { |
|
|
675 |
getDnd().register(c); |
676 |
} |
207 |
} |
677 |
} |
|
|
678 |
|
208 |
|
679 |
/** |
209 |
/** |
680 |
* Create a new <code>Toolbar</code>. |
210 |
* Create a new <code>Toolbar</code>. |
Lines 691-737
Link Here
|
691 |
* toolbar layout manager. |
221 |
* toolbar layout manager. |
692 |
* @return basic toolbar height |
222 |
* @return basic toolbar height |
693 |
* @since 4.15 |
223 |
* @since 4.15 |
|
|
224 |
* @deprecated Returns preferred icon size. |
694 |
*/ |
225 |
*/ |
695 |
public static int getBasicHeight () { |
226 |
public static int getBasicHeight () { |
696 |
if (ToolbarPool.getDefault().getPreferredIconSize() == 24) { |
227 |
return ToolbarPool.getDefault().getPreferredIconSize(); |
697 |
return 44; |
|
|
698 |
} else { |
699 |
return 34; |
700 |
} |
228 |
} |
701 |
} |
|
|
702 |
|
229 |
|
703 |
private void initAll(String name, boolean f) { |
230 |
private void initAll(String name, boolean f) { |
704 |
floatable = f; |
|
|
705 |
mouseListener = null; |
706 |
|
707 |
setName (name); |
231 |
setName (name); |
708 |
|
232 |
|
709 |
setFloatable (false); |
233 |
setFloatable (f); |
710 |
String lAndF = UIManager.getLookAndFeel().getName(); |
|
|
711 |
|
234 |
|
712 |
if (lAndF.equals("Windows")) { |
|
|
713 |
//Get rid of extra height, also allow for minimalist main |
714 |
//window |
715 |
setBorder(Boolean.getBoolean("netbeans.small.main.window") ? |
716 |
BorderFactory.createEmptyBorder(1,1,1,1) : |
717 |
BorderFactory.createEmptyBorder()); //NOI18N |
718 |
} else if (!"Aqua".equals(UIManager.getLookAndFeel().getID()) && !"GTK".equals(UIManager.getLookAndFeel().getID())){ |
719 |
Border b = UIManager.getBorder ("ToolBar.border"); //NOI18N |
720 |
|
721 |
if ((b==null) || (b instanceof javax.swing.plaf.metal.MetalBorders.ToolBarBorder)) |
722 |
b=BorderFactory.createEtchedBorder (EtchedBorder.LOWERED); |
723 |
setBorder (new CompoundBorder ( |
724 |
b, |
725 |
new EmptyBorder (TOP, LEFT, BOTTOM, RIGHT)) |
726 |
); |
727 |
|
728 |
} |
729 |
|
730 |
if (!"Aqua".equals(UIManager.getLookAndFeel().getID())) { |
731 |
putClientProperty("JToolBar.isRollover", Boolean.TRUE); // NOI18N |
732 |
} |
733 |
addGrip(); |
734 |
|
735 |
getAccessibleContext().setAccessibleName(displayName == null ? getName() : displayName); |
235 |
getAccessibleContext().setAccessibleName(displayName == null ? getName() : displayName); |
736 |
getAccessibleContext().setAccessibleDescription(getName()); |
236 |
getAccessibleContext().setAccessibleDescription(getName()); |
737 |
} |
237 |
} |
Lines 745-844
Link Here
|
745 |
} |
245 |
} |
746 |
} |
246 |
} |
747 |
|
247 |
|
748 |
@Override |
|
|
749 |
public Dimension getPreferredSize() { |
750 |
String lfid = UIManager.getLookAndFeel().getID(); |
751 |
int minheight; |
752 |
|
753 |
if (ToolbarPool.getDefault().getPreferredIconSize() == 24) { |
754 |
if ("Aqua".equals(lfid)) { |
755 |
minheight = 29 + 8; |
756 |
} else if ("Metal".equals(lfid)) { |
757 |
minheight = 36 + 8; |
758 |
} else if ("Windows".equals(lfid)) { |
759 |
minheight = isXPTheme() ? (23 + 8) : (27 + 8); |
760 |
} else if ("GTK".equals(lfid)) { |
761 |
minheight = 32 + 8; |
762 |
} else { |
763 |
minheight = 28 + 8; |
764 |
} |
765 |
} else { |
766 |
if ("Aqua".equals(lfid)) { |
767 |
minheight = 29; |
768 |
} else if ("Metal".equals(lfid)) { |
769 |
minheight = 36; |
770 |
} else if ("Windows".equals(lfid)) { |
771 |
minheight = isXPTheme() ? 23 : 27; |
772 |
} else if ("GTK".equals(lfid)) { |
773 |
minheight = 32; |
774 |
} else { |
775 |
minheight = 28; |
776 |
} |
777 |
} |
778 |
Dimension result = super.getPreferredSize(); |
779 |
result.height = Math.max (result.height, minheight); |
780 |
return result; |
781 |
} |
782 |
|
783 |
/** Removes all ACTION components. */ |
784 |
@Override |
785 |
public void removeAll () { |
786 |
for( int i=0; i<getComponentCount(); i++ ) { |
787 |
getDnd().unregister( getComponent(i) ); |
788 |
} |
789 |
super.removeAll(); |
790 |
addGrip(); |
791 |
} |
792 |
|
793 |
/** |
794 |
* When Toolbar is floatable, ToolbarBump is added as Grip as first toolbar component |
795 |
* modified by Michael Wever, to use l&f's grip/bump. */ |
796 |
void addGrip () { |
797 |
//HACK (137286)- there's not better way... |
798 |
if (floatable && !"QuickSearch".equals(getName()) ) { //NOI18N |
799 |
/** Uses L&F's grip **/ |
800 |
String lfID = UIManager.getLookAndFeel().getID(); |
801 |
JPanel dragarea = null; |
802 |
// #98888: recognize JGoodies L&F properly |
803 |
if (lfID.endsWith("Windows")) { |
804 |
if (isXPTheme()) { |
805 |
dragarea = (JPanel) new ToolbarXP(); |
806 |
} else { |
807 |
dragarea = (JPanel) new ToolbarGrip(); |
808 |
} |
809 |
} else if (lfID.equals("Aqua")) { |
810 |
dragarea = (JPanel) new ToolbarAqua(); |
811 |
} else if (lfID.equals("GTK")) { |
812 |
dragarea = (JPanel) new ToolbarGtk(); |
813 |
//setFloatable(true); |
814 |
} else { |
815 |
//Default for Metal and uknown L&F |
816 |
dragarea = (JPanel)new ToolbarBump(); |
817 |
} |
818 |
if (mouseListener == null) { |
819 |
mouseListener = new ToolbarMouseListener (); |
820 |
} |
821 |
|
822 |
if (dragarea != null) { |
823 |
dragarea.addMouseListener (mouseListener); |
824 |
dragarea.addMouseMotionListener (mouseListener); |
825 |
|
826 |
dragarea.setName ("grip"); |
827 |
add (dragarea); |
828 |
} |
829 |
} |
830 |
} |
831 |
|
832 |
/** Compute with HEIGHT_TOLERANCE number of rows for specific toolbar height. |
248 |
/** Compute with HEIGHT_TOLERANCE number of rows for specific toolbar height. |
833 |
* @param height of some toolbar |
249 |
* @param height of some toolbar |
834 |
* @return number of rows |
250 |
* @return number of rows |
|
|
251 |
* @deprecated Always returns 1 |
835 |
*/ |
252 |
*/ |
836 |
static public int rowCount (int height) { |
253 |
static public int rowCount (int height) { |
837 |
return 1 + height / (getBasicHeight() + HEIGHT_TOLERANCE+customFontHeightCorrection); |
254 |
return 1; |
838 |
} |
255 |
} |
839 |
|
256 |
|
840 |
/** Set DnDListener to Toolbar. |
257 |
/** Set DnDListener to Toolbar. |
841 |
* @param l DndListener for toolbar |
258 |
* @param l DndListener for toolbar |
|
|
259 |
* @deprecated |
842 |
*/ |
260 |
*/ |
843 |
public void setDnDListener (DnDListener l) { |
261 |
public void setDnDListener (DnDListener l) { |
844 |
listener = l; |
262 |
listener = l; |
Lines 867-965
Link Here
|
867 |
this.displayName = displayName; |
285 |
this.displayName = displayName; |
868 |
} |
286 |
} |
869 |
|
287 |
|
870 |
private static final void setToolTipText (JComponent comp, String text) { |
|
|
871 |
comp.setToolTipText(Actions.cutAmpersand(text)); |
872 |
} |
873 |
|
874 |
/** Fire drag of Toolbar |
875 |
* @param dx distance of horizontal dragging |
876 |
* @param dy distance of vertical dragging |
877 |
* @param type type of toolbar dragging |
878 |
*/ |
879 |
protected void fireDragToolbar (int dx, int dy, int type) { |
880 |
if (listener != null) |
881 |
listener.dragToolbar (new DnDEvent (this, getName(), dx, dy, type)); |
882 |
} |
883 |
|
884 |
/** Fire drop of Toolbar |
885 |
* @param dx distance of horizontal dropping |
886 |
* @param dy distance of vertical dropping |
887 |
* @param type type of toolbar dropping |
888 |
*/ |
889 |
protected void fireDropToolbar (int dx, int dy, int type) { |
890 |
if (listener != null) |
891 |
listener.dropToolbar (new DnDEvent (this, getName(), dx, dy, type)); |
892 |
} |
893 |
|
894 |
synchronized final MouseInputListener mouseDelegate () { |
895 |
if (mouseListener == null) mouseListener = new ToolbarMouseListener (); |
896 |
return mouseListener; |
897 |
} |
898 |
|
899 |
/** Toolbar mouse listener. */ |
900 |
class ToolbarMouseListener extends MouseInputAdapter { |
901 |
/** Is toolbar dragging now. */ |
902 |
private boolean dragging = false; |
903 |
/** Start point of dragging. */ |
904 |
private Point startPoint = null; |
905 |
|
906 |
/** Invoked when a mouse button has been pressed on a component. */ |
907 |
@Override |
908 |
public void mousePressed (MouseEvent e) { |
909 |
startPoint = e.getPoint(); |
910 |
} |
911 |
|
912 |
/** Invoked when a mouse button has been released on a component. */ |
913 |
@Override |
914 |
public void mouseReleased (MouseEvent e) { |
915 |
if (dragging) { |
916 |
|
917 |
int dx = getX() + e.getX() - startPoint.x > getParent().getWidth() - RESIDUAL_WIDTH ? |
918 |
0 : e.getX() - startPoint.x; |
919 |
|
920 |
fireDropToolbar (dx, |
921 |
e.getY() - startPoint.y, |
922 |
DnDEvent.DND_ONE); |
923 |
dragging = false; |
924 |
} |
925 |
} |
926 |
|
927 |
/** Invoked when a mouse button is pressed on a component and then dragged. */ |
928 |
@Override |
929 |
public void mouseDragged (MouseEvent e) { |
930 |
int m = e.getModifiers(); |
931 |
int type = DnDEvent.DND_ONE; |
932 |
int dx; |
933 |
|
934 |
if (e.isControlDown()) |
935 |
type = DnDEvent.DND_LINE; |
936 |
else if (((m & InputEvent.BUTTON2_MASK) != 0) || |
937 |
((m & InputEvent.BUTTON3_MASK) != 0)) |
938 |
type = DnDEvent.DND_END; |
939 |
if (startPoint == null) { |
940 |
startPoint = new Point (e.getX(), e.getY()); |
941 |
} |
942 |
|
943 |
if ( getX() + e.getX() + startPoint.x > getParent().getWidth() - RESIDUAL_WIDTH ) { |
944 |
if ( getX() >= getParent().getWidth() - RESIDUAL_WIDTH ) { |
945 |
dx = 0; |
946 |
} |
947 |
else { |
948 |
dx = getParent().getWidth() - RESIDUAL_WIDTH - getX(); |
949 |
} |
950 |
} |
951 |
else { |
952 |
dx = e.getX() - startPoint.x; |
953 |
} |
954 |
|
955 |
fireDragToolbar ( dx, |
956 |
e.getY() - startPoint.y, |
957 |
type); |
958 |
dragging = true; |
959 |
} |
960 |
|
961 |
} // end of inner class ToolbarMouseListener |
962 |
|
963 |
/** |
288 |
/** |
964 |
* This class can be used to produce a <code>Toolbar</code> instance from |
289 |
* This class can be used to produce a <code>Toolbar</code> instance from |
965 |
* the given <code>DataFolder</code>. |
290 |
* the given <code>DataFolder</code>. |
Lines 1012-1018
Link Here
|
1012 |
*/ |
337 |
*/ |
1013 |
@Override |
338 |
@Override |
1014 |
protected InstanceCookie acceptCookie (InstanceCookie cookie) |
339 |
protected InstanceCookie acceptCookie (InstanceCookie cookie) |
1015 |
throws java.io.IOException, ClassNotFoundException { |
340 |
throws IOException, ClassNotFoundException { |
1016 |
boolean is; |
341 |
boolean is; |
1017 |
|
342 |
|
1018 |
if (cookie instanceof InstanceCookie.Of) { |
343 |
if (cookie instanceof InstanceCookie.Of) { |
Lines 1047-1099
Link Here
|
1047 |
* @return the updated <code>ToolbarPool</code> representee |
372 |
* @return the updated <code>ToolbarPool</code> representee |
1048 |
*/ |
373 |
*/ |
1049 |
protected Object createInstance(final InstanceCookie[] cookies) |
374 |
protected Object createInstance(final InstanceCookie[] cookies) |
1050 |
throws java.io.IOException, ClassNotFoundException { |
375 |
throws IOException, ClassNotFoundException { |
1051 |
// refresh the toolbar's content |
376 |
// refresh the toolbar's content |
1052 |
Toolbar.this.removeAll(); |
377 |
Toolbar.this.removeAll(); |
1053 |
for (int i = 0; i < cookies.length; i++) { |
378 |
for (int i = 0; i < cookies.length; i++) { |
1054 |
try { |
379 |
try { |
1055 |
java.lang.Object obj = cookies[i].instanceCreate(); |
380 |
Object obj = cookies[i].instanceCreate(); |
1056 |
java.lang.Object file = cookiesToObjects.get(obj); |
381 |
Object file = cookiesToObjects.get(obj); |
1057 |
|
382 |
|
1058 |
if (obj instanceof org.openide.util.actions.Presenter.Toolbar) { |
383 |
if (obj instanceof Presenter.Toolbar) { |
1059 |
obj = ((org.openide.util.actions.Presenter.Toolbar) obj).getToolbarPresenter(); |
384 |
obj = ((Presenter.Toolbar) obj).getToolbarPresenter(); |
1060 |
} |
385 |
} |
1061 |
if (obj instanceof java.awt.Component) { |
386 |
if (obj instanceof Component) { |
1062 |
// remove border and grip if requested. "Fixed" toolbar |
387 |
// remove border and grip if requested. "Fixed" toolbar |
1063 |
// item has to live alone in toolbar now |
388 |
// item has to live alone in toolbar now |
1064 |
if ((obj instanceof javax.swing.JComponent) && |
389 |
if ((obj instanceof JComponent) && |
1065 |
"Fixed".equals(((javax.swing.JComponent) obj).getClientProperty("Toolbar"))) { |
390 |
"Fixed".equals(((JComponent) obj).getClientProperty("Toolbar"))) { |
1066 |
floatable = false; |
|
|
1067 |
org.openide.awt.Toolbar.this.removeAll(); |
391 |
org.openide.awt.Toolbar.this.removeAll(); |
1068 |
setBorder(null); |
392 |
setBorder(null); |
1069 |
} |
393 |
} |
1070 |
if (obj instanceof javax.swing.JComponent) { |
394 |
if (obj instanceof javax.swing.JComponent) { |
1071 |
if (org.openide.awt.ToolbarPool.getDefault().getPreferredIconSize() == |
395 |
if (ToolbarPool.getDefault().getPreferredIconSize() == 24) { |
1072 |
24) { |
396 |
((JComponent) obj).putClientProperty("PreferredIconSize", new Integer(24)); |
1073 |
((javax.swing.JComponent) obj).putClientProperty("PreferredIconSize", |
|
|
1074 |
new java.lang.Integer(24)); |
1075 |
} |
397 |
} |
1076 |
((javax.swing.JComponent) obj).putClientProperty("file", |
398 |
((JComponent) obj).putClientProperty("file", file); |
1077 |
file); |
|
|
1078 |
} |
399 |
} |
1079 |
org.openide.awt.Toolbar.this.add((java.awt.Component) obj); |
400 |
Toolbar.this.add((Component) obj); |
1080 |
continue; |
401 |
continue; |
1081 |
} |
402 |
} |
1082 |
if (obj instanceof javax.swing.Action) { |
403 |
if (obj instanceof Action) { |
1083 |
javax.swing.Action a = (javax.swing.Action) obj; |
404 |
Action a = (Action) obj; |
1084 |
javax.swing.JButton b = new org.openide.awt.Toolbar.DefaultIconButton(); |
405 |
JButton b = new DefaultIconButton(); |
1085 |
|
406 |
|
1086 |
if (org.openide.awt.ToolbarPool.getDefault().getPreferredIconSize() == |
407 |
if (ToolbarPool.getDefault().getPreferredIconSize() == 24) { |
1087 |
24) { |
408 |
b.putClientProperty("PreferredIconSize", new Integer(24)); |
1088 |
b.putClientProperty("PreferredIconSize", |
|
|
1089 |
new java.lang.Integer(24)); |
1090 |
} |
409 |
} |
1091 |
if (null == a.getValue(javax.swing.Action.SMALL_ICON) && |
410 |
if (null == a.getValue(Action.SMALL_ICON) |
1092 |
(null == a.getValue(javax.swing.Action.NAME) || |
411 |
&& (null == a.getValue(Action.NAME) || a.getValue(Action.NAME).toString().length() == 0)) { |
1093 |
a.getValue(javax.swing.Action.NAME).toString().length() == |
412 |
a.putValue(Action.SMALL_ICON, new ImageIcon( ImageUtilities.loadImage( "org/openide/loaders/unknown.gif") )); |
1094 |
0)) { |
|
|
1095 |
a.putValue(javax.swing.Action.SMALL_ICON, |
1096 |
new ImageIcon( ImageUtilities.loadImage( "org/openide/loaders/unknown.gif") )); |
1097 |
} |
413 |
} |
1098 |
org.openide.awt.Actions.connect(b, a); |
414 |
org.openide.awt.Actions.connect(b, a); |
1099 |
b.putClientProperty("file", file); |
415 |
b.putClientProperty("file", file); |
Lines 1126-1398
Link Here
|
1126 |
|
442 |
|
1127 |
} // end of inner class Folder |
443 |
} // end of inner class Folder |
1128 |
|
444 |
|
1129 |
/** Bumps for floatable toolbar */ |
|
|
1130 |
private final class ToolbarBump extends JPanel { |
1131 |
/** Top gap. */ |
1132 |
static final int TOPGAP = 2; |
1133 |
/** Bottom gap. */ |
1134 |
static final int BOTGAP = 2; |
1135 |
/** Width of bump element. */ |
1136 |
static final int WIDTH = 6; |
1137 |
|
1138 |
/** Minimum size. */ |
1139 |
Dimension dim; |
1140 |
/** Maximum size. */ |
1141 |
Dimension max; |
1142 |
|
1143 |
static final long serialVersionUID =-8819972936203315277L; |
1144 |
|
1145 |
/** Create new ToolbarBump. */ |
1146 |
public ToolbarBump () { |
1147 |
super(); |
1148 |
int width = WIDTH; |
1149 |
dim = new Dimension (width, width); |
1150 |
max = new Dimension (width, Integer.MAX_VALUE); |
1151 |
Toolbar.setToolTipText (this, Toolbar.this.getDisplayName()); |
1152 |
} |
1153 |
|
1154 |
/** Paint bumps to specific Graphics. */ |
1155 |
@Override |
445 |
@Override |
1156 |
public void paint (Graphics g) { |
|
|
1157 |
Dimension size = this.getSize (); |
1158 |
int height = size.height - BOTGAP; |
1159 |
g.setColor (this.getBackground ()); |
1160 |
|
1161 |
for (int x = 0; x+1 < size.width; x+=4) { |
1162 |
for (int y = TOPGAP; y+1 < height; y+=4) { |
1163 |
g.setColor (this.getBackground ().brighter ()); |
1164 |
g.drawLine (x, y, x, y); |
1165 |
if (x+5 < size.width && y+5 < height) { |
1166 |
g.drawLine (x+2, y+2, x+2, y+2); |
1167 |
} |
1168 |
g.setColor (this.getBackground ().darker ().darker ()); |
1169 |
g.drawLine (x+1, y+1, x+1, y+1); |
1170 |
if (x+5 < size.width && y+5 < height) { |
1171 |
g.drawLine (x+3, y+3, x+3, y+3); |
1172 |
} |
1173 |
} |
1174 |
} |
1175 |
} |
1176 |
|
1177 |
/** @return minimum size */ |
1178 |
@Override |
1179 |
public Dimension getMinimumSize () { |
1180 |
return dim; |
1181 |
} |
1182 |
|
1183 |
/** @return preferred size */ |
1184 |
@Override |
1185 |
public Dimension getPreferredSize () { |
1186 |
return this.getMinimumSize (); |
1187 |
} |
1188 |
|
1189 |
@Override |
1190 |
public Dimension getMaximumSize () { |
1191 |
return max; |
1192 |
} |
1193 |
} // end of inner class ToolbarBump |
1194 |
|
1195 |
/** Bumps for floatable toolbar GTK L&F */ |
1196 |
private final class ToolbarGtk extends JPanel { |
1197 |
/** Top gap. */ |
1198 |
int TOPGAP; |
1199 |
/** Bottom gap. */ |
1200 |
int BOTGAP; |
1201 |
/** Width of bump element. */ |
1202 |
static final int WIDTH = 6; |
1203 |
|
1204 |
/** Minimum size. */ |
1205 |
Dimension dim; |
1206 |
/** Maximum size. */ |
1207 |
Dimension max; |
1208 |
|
1209 |
static final long serialVersionUID = -8819972936203315277L; |
1210 |
|
1211 |
/** Create new ToolbarBump. */ |
1212 |
public ToolbarGtk () { |
1213 |
super(); |
1214 |
int width = WIDTH; |
1215 |
if (useSynthIcon()) { |
1216 |
TOPGAP = 0; |
1217 |
BOTGAP = 0; |
1218 |
} else { |
1219 |
TOPGAP = 2; |
1220 |
BOTGAP = 2; |
1221 |
} |
1222 |
dim = new Dimension (width, width); |
1223 |
max = new Dimension (width, Integer.MAX_VALUE); |
1224 |
Toolbar.setToolTipText (this, Toolbar.this.getDisplayName()); |
1225 |
} |
1226 |
|
1227 |
/** Paint bumps to specific Graphics. */ |
1228 |
@Override |
1229 |
public void paint (Graphics g) { |
1230 |
if (useSynthIcon()) { |
1231 |
int height = Toolbar.this.getHeight() - BOTGAP; |
1232 |
Icon icon = UIManager.getIcon("ToolBar.handleIcon"); |
1233 |
Region region = Region.TOOL_BAR; |
1234 |
SynthStyleFactory sf = SynthLookAndFeel.getStyleFactory(); |
1235 |
SynthStyle style = sf.getStyle(Toolbar.this, region); |
1236 |
SynthContext context = new SynthContext(Toolbar.this, region, style, SynthConstants.DEFAULT); |
1237 |
|
1238 |
// for vertical toolbar, you'll need to ask for getIconHeight() instead |
1239 |
Method m = null; |
1240 |
try { |
1241 |
m = synthIconClass.getMethod("getIconWidth",Icon.class, SynthContext.class); |
1242 |
} catch (NoSuchMethodException exc) { |
1243 |
LOG.log(Level.WARNING, null, exc); |
1244 |
} |
1245 |
int width = 0; |
1246 |
//width = SynthIcon.getIconWidth(icon, context); |
1247 |
try { |
1248 |
width = (Integer) m.invoke(null, new Object [] {icon, context}); |
1249 |
} catch (IllegalAccessException exc) { |
1250 |
LOG.log(Level.WARNING, null, exc); |
1251 |
} catch (InvocationTargetException exc) { |
1252 |
LOG.log(Level.WARNING, null, exc); |
1253 |
} |
1254 |
try { |
1255 |
m = synthIconClass.getMethod("paintIcon",Icon.class,SynthContext.class, |
1256 |
Graphics.class,Integer.TYPE,Integer.TYPE,Integer.TYPE,Integer.TYPE); |
1257 |
} catch (NoSuchMethodException exc) { |
1258 |
LOG.log(Level.WARNING, null, exc); |
1259 |
} |
1260 |
//SynthIcon.paintIcon(icon, context, g, 0, 0, width, height); |
1261 |
try { |
1262 |
m.invoke(null, new Object [] {icon,context,g,new Integer(0),new Integer(-1), |
1263 |
new Integer(width),new Integer(height)}); |
1264 |
} catch (IllegalAccessException exc) { |
1265 |
LOG.log(Level.WARNING, null, exc); |
1266 |
} catch (InvocationTargetException exc) { |
1267 |
LOG.log(Level.WARNING, null, exc); |
1268 |
} |
1269 |
} else { |
1270 |
Dimension size = this.getSize(); |
1271 |
int height = size.height - BOTGAP; |
1272 |
g.setColor (this.getBackground ()); |
1273 |
|
1274 |
for (int x = 0; x+1 < size.width; x+=4) { |
1275 |
for (int y = TOPGAP; y+1 < height; y+=4) { |
1276 |
g.setColor (this.getBackground ().brighter ()); |
1277 |
g.drawLine (x, y, x, y); |
1278 |
if (x+5 < size.width && y+5 < height) { |
1279 |
g.drawLine (x+2, y+2, x+2, y+2); |
1280 |
} |
1281 |
g.setColor (this.getBackground ().darker ().darker ()); |
1282 |
g.drawLine (x+1, y+1, x+1, y+1); |
1283 |
if (x+5 < size.width && y+5 < height) { |
1284 |
g.drawLine (x+3, y+3, x+3, y+3); |
1285 |
} |
1286 |
} |
1287 |
} |
1288 |
} |
1289 |
} |
1290 |
|
1291 |
/** @return minimum size */ |
1292 |
@Override |
1293 |
public Dimension getMinimumSize () { |
1294 |
return dim; |
1295 |
} |
1296 |
|
1297 |
/** @return preferred size */ |
1298 |
@Override |
1299 |
public Dimension getPreferredSize () { |
1300 |
return new Dimension(WIDTH,Toolbar.this.getHeight() - BOTGAP - TOPGAP); |
1301 |
} |
1302 |
|
1303 |
@Override |
1304 |
public Dimension getMaximumSize () { |
1305 |
return max; |
1306 |
} |
1307 |
} // end of inner class ToolbarGtk |
1308 |
|
1309 |
/** Recognizes if XP theme is set. |
1310 |
* @return true if XP theme is set, false otherwise |
1311 |
*/ |
1312 |
private static Boolean isXP = null; |
1313 |
private static boolean isXPTheme () { |
1314 |
if (isXP == null) { |
1315 |
Boolean xp = (Boolean)Toolkit.getDefaultToolkit(). |
1316 |
getDesktopProperty("win.xpstyle.themeActive"); //NOI18N |
1317 |
isXP = Boolean.TRUE.equals(xp)? Boolean.TRUE : Boolean.FALSE; |
1318 |
} |
1319 |
return isXP.booleanValue(); |
1320 |
} |
1321 |
|
1322 |
private final class ToolbarAqua extends JPanel { |
1323 |
/** Width of grip */ |
1324 |
static final int WIDTH = 8; |
1325 |
/** Minimum size. */ |
1326 |
Dimension dim; |
1327 |
/** Maximum size. */ |
1328 |
Dimension max; |
1329 |
static final long serialVersionUID =-8819972972003315277L; |
1330 |
|
1331 |
public ToolbarAqua() { |
1332 |
dim = new Dimension (WIDTH, WIDTH); |
1333 |
max = new Dimension (WIDTH, Integer.MAX_VALUE); |
1334 |
Toolbar.setToolTipText (this, Toolbar.this.getDisplayName()); |
1335 |
} |
1336 |
|
1337 |
@Override |
1338 |
public void paintComponent (Graphics g) { |
1339 |
super.paintComponent(g); |
1340 |
java.awt.Graphics2D g2d = (Graphics2D) g; |
1341 |
g2d.addRenderingHints(getHints()); |
1342 |
|
1343 |
int sz = 5; |
1344 |
|
1345 |
int y = ((getHeight() / 2) - (sz / 2)) - 2; |
1346 |
int x = ((getWidth() / 2) - (sz / 2)) - 2; |
1347 |
|
1348 |
GradientPaint gradient = new GradientPaint(x+1, y+1, Color.BLACK, |
1349 |
x+sz-1, y+sz-1, Color.WHITE); |
1350 |
|
1351 |
Paint paint = g2d.getPaint(); |
1352 |
|
1353 |
g2d.setPaint(gradient); |
1354 |
g2d.drawArc(x,y,sz,sz,0,359); |
1355 |
|
1356 |
g.setColor(new Color(240,240,240)); |
1357 |
g.drawLine(x+(sz/2), y + (sz/2),x+(sz/2), y + (sz/2)); |
1358 |
|
1359 |
g2d.setPaint(paint); |
1360 |
} |
1361 |
|
1362 |
/** @return minimum size */ |
1363 |
@Override |
1364 |
public Dimension getMinimumSize () { |
1365 |
return dim; |
1366 |
} |
1367 |
|
1368 |
/** @return preferred size */ |
1369 |
@Override |
1370 |
public Dimension getPreferredSize () { |
1371 |
return this.getMinimumSize (); |
1372 |
} |
1373 |
|
1374 |
@Override |
1375 |
public Dimension getMaximumSize () { |
1376 |
return max; |
1377 |
} |
1378 |
} |
1379 |
|
1380 |
private static java.util.Map<RenderingHints.Key, Object> hintsMap = null; |
1381 |
@SuppressWarnings("unchecked") |
1382 |
static final Map getHints() { |
1383 |
//XXX We REALLY need to put this in a graphics utils lib |
1384 |
if (hintsMap == null) { |
1385 |
//Thanks to Phil Race for making this possible |
1386 |
hintsMap = (Map<RenderingHints.Key, Object>)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N |
1387 |
if (hintsMap == null) { |
1388 |
hintsMap = new HashMap<RenderingHints.Key, Object>(); |
1389 |
hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
1390 |
} |
1391 |
} |
1392 |
return hintsMap; |
1393 |
} |
1394 |
|
1395 |
@Override |
1396 |
public void setUI(javax.swing.plaf.ToolBarUI ui) { |
446 |
public void setUI(javax.swing.plaf.ToolBarUI ui) { |
1397 |
super.setUI(ui); |
447 |
super.setUI(ui); |
1398 |
if( null != backingFolder && null != processor ) { |
448 |
if( null != backingFolder && null != processor ) { |
Lines 1401-1584
Link Here
|
1401 |
} |
451 |
} |
1402 |
} |
452 |
} |
1403 |
|
453 |
|
1404 |
private final class ToolbarXP extends JPanel { |
|
|
1405 |
/** Width of grip */ |
1406 |
static final int WIDTH = 7; |
1407 |
/** Minimum size. */ |
1408 |
Dimension dim; |
1409 |
/** Maximum size. */ |
1410 |
Dimension max; |
1411 |
|
454 |
|
1412 |
static final long serialVersionUID =-8819972936203315277L; |
455 |
/** DnDListener is Drag and Drop listener for Toolbar motion events. |
1413 |
public ToolbarXP() { |
456 |
* @deprecated There is no public support for toolbar drag and drop. |
1414 |
dim = new Dimension (WIDTH, WIDTH); |
|
|
1415 |
max = new Dimension (WIDTH, Integer.MAX_VALUE); |
1416 |
Toolbar.setToolTipText (this, Toolbar.this.getDisplayName()); |
1417 |
} |
1418 |
|
1419 |
@Override |
1420 |
public void paintComponent (Graphics g) { |
1421 |
super.paintComponent(g); |
1422 |
int x = 3; |
1423 |
for (int i=4; i < getHeight()-4; i+=4) { |
1424 |
//first draw the rectangular highlight below each dot |
1425 |
g.setColor(UIManager.getColor("controlLtHighlight")); //NOI18N |
1426 |
g.fillRect(x + 1, i + 1, 2, 2); |
1427 |
//Get the shadow color. We'll paint the darkest dot first, |
1428 |
//and work our way to the lightest |
1429 |
Color col = UIManager.getColor("controlShadow"); //NOI18N |
1430 |
g.setColor(col); |
1431 |
//draw the darkest dot |
1432 |
g.drawLine(x+1, i+1, x+1, i+1); |
1433 |
|
1434 |
//Get the color components and calculate the amount each component |
1435 |
//should increase per dot |
1436 |
int red = col.getRed(); |
1437 |
int green = col.getGreen(); |
1438 |
int blue = col.getBlue(); |
1439 |
|
1440 |
//Get the default component background - we start with the dark |
1441 |
//color, and for each dot, add a percentage of the difference |
1442 |
//between this and the background color |
1443 |
Color back = getBackground(); |
1444 |
int rb = back.getRed(); |
1445 |
int gb = back.getGreen(); |
1446 |
int bb = back.getBlue(); |
1447 |
|
1448 |
//Get the amount to increment each component for each dot |
1449 |
int incr = (rb - red) / 5; |
1450 |
int incg = (gb - green) / 5; |
1451 |
int incb = (bb - blue) / 5; |
1452 |
|
1453 |
//Increment the colors |
1454 |
red += incr; |
1455 |
green += incg; |
1456 |
blue += incb; |
1457 |
//Create a slightly lighter color and draw the dot |
1458 |
col = new Color(red, green, blue); |
1459 |
g.setColor(col); |
1460 |
g.drawLine(x+1, i, x+1, i); |
1461 |
|
1462 |
//And do it for the next dot, and so on, for all four dots |
1463 |
red += incr; |
1464 |
green += incg; |
1465 |
blue += incb; |
1466 |
col = new Color(red, green, blue); |
1467 |
g.setColor(col); |
1468 |
g.drawLine(x, i+1, x, i+1); |
1469 |
|
1470 |
red += incr; |
1471 |
green += incg; |
1472 |
blue += incb; |
1473 |
col = new Color(red, green, blue); |
1474 |
g.setColor(col); |
1475 |
g.drawLine(x, i, x, i); |
1476 |
} |
1477 |
} |
1478 |
|
1479 |
/** @return minimum size */ |
1480 |
@Override |
1481 |
public Dimension getMinimumSize() { |
1482 |
return dim; |
1483 |
} |
1484 |
|
1485 |
/** @return preferred size */ |
1486 |
@Override |
1487 |
public Dimension getPreferredSize () { |
1488 |
return this.getMinimumSize (); |
1489 |
} |
1490 |
|
1491 |
@Override |
1492 |
public Dimension getMaximumSize () { |
1493 |
return max; |
1494 |
} |
1495 |
} |
1496 |
|
1497 |
/* |
1498 |
public static void main(String[] args) { |
1499 |
JFrame jf = new JFrame(); |
1500 |
jf.getContentPane().add (new ToolbarXP()); |
1501 |
jf.setSize(new java.awt.Dimension(200,200)); |
1502 |
jf.setLocation(20,20); |
1503 |
jf.show(); |
1504 |
} |
1505 |
*/ |
457 |
*/ |
1506 |
|
458 |
public interface DnDListener extends EventListener { |
1507 |
|
|
|
1508 |
/** Grip for floatable toolbar, used for Windows Classic L&F */ |
1509 |
private final class ToolbarGrip extends JPanel { |
1510 |
/** Horizontal gaps. */ |
1511 |
static final int HGAP = 1; |
1512 |
/** Vertical gaps. */ |
1513 |
static final int VGAP = 2; |
1514 |
/** Step between two grip elements. */ |
1515 |
static final int STEP = 1; |
1516 |
/** Width of grip element. */ |
1517 |
static final int WIDTH = 2; |
1518 |
|
1519 |
/** Number of grip elements. */ |
1520 |
int columns; |
1521 |
/** Minimum size. */ |
1522 |
Dimension dim; |
1523 |
/** Maximum size. */ |
1524 |
Dimension max; |
1525 |
|
1526 |
static final long serialVersionUID =-8819972936203315276L; |
1527 |
|
1528 |
/** Create new ToolbarGrip for default number of grip elements. */ |
1529 |
public ToolbarGrip () { |
1530 |
this(1); |
1531 |
} |
1532 |
|
1533 |
/** Create new ToolbarGrip for specific number of grip elements. |
1534 |
* @param col number of grip elements |
1535 |
*/ |
1536 |
public ToolbarGrip (int col) { |
1537 |
super (); |
1538 |
columns = col; |
1539 |
int width = (col - 1) * STEP + col * WIDTH + 2 * HGAP; |
1540 |
dim = new Dimension (width, width); |
1541 |
max = new Dimension (width, Integer.MAX_VALUE); |
1542 |
this.setBorder (new EmptyBorder (VGAP, HGAP, VGAP, HGAP)); |
1543 |
Toolbar.setToolTipText (this, Toolbar.this.getDisplayName()); |
1544 |
} |
1545 |
|
1546 |
/** Paint grip to specific Graphics. */ |
1547 |
@Override |
1548 |
public void paint (Graphics g) { |
1549 |
Dimension size = this.getSize(); |
1550 |
int top = VGAP; |
1551 |
int bottom = size.height - 1 - VGAP; |
1552 |
int height = bottom - top; |
1553 |
g.setColor ( this.getBackground() ); |
1554 |
|
1555 |
for (int i = 0, x = HGAP; i < columns; i++, x += WIDTH + STEP) { |
1556 |
g.draw3DRect (x, top, WIDTH, height, true); // grip element is 3D rectangle now |
1557 |
} |
1558 |
|
1559 |
} |
1560 |
|
1561 |
/** @return minimum size */ |
1562 |
@Override |
1563 |
public Dimension getMinimumSize () { |
1564 |
return dim; |
1565 |
} |
1566 |
|
1567 |
/** @return preferred size */ |
1568 |
@Override |
1569 |
public Dimension getPreferredSize () { |
1570 |
return this.getMinimumSize(); |
1571 |
} |
1572 |
|
1573 |
@Override |
1574 |
public Dimension getMaximumSize () { |
1575 |
return max; |
1576 |
} |
1577 |
|
1578 |
} // end of inner class ToolbarGrip |
1579 |
|
1580 |
/** DnDListener is Drag and Drop listener for Toolbar motion events. */ |
1581 |
public interface DnDListener extends java.util.EventListener { |
1582 |
/** Invoced when toolbar is dragged. */ |
459 |
/** Invoced when toolbar is dragged. */ |
1583 |
public void dragToolbar (DnDEvent e); |
460 |
public void dragToolbar (DnDEvent e); |
1584 |
|
461 |
|
Lines 1587-1593
Link Here
|
1587 |
} // end of interface DnDListener |
464 |
} // end of interface DnDListener |
1588 |
|
465 |
|
1589 |
|
466 |
|
1590 |
/** DnDEvent is Toolbar's drag and drop event. */ |
467 |
/** DnDEvent is Toolbar's drag and drop event. |
|
|
468 |
* @deprecated |
469 |
*/ |
1591 |
public static class DnDEvent extends EventObject { |
470 |
public static class DnDEvent extends EventObject { |
1592 |
/** Type of DnDEvent. Dragging with only one Toolbar. */ |
471 |
/** Type of DnDEvent. Dragging with only one Toolbar. */ |
1593 |
public static final int DND_ONE = 1; |
472 |
public static final int DND_ONE = 1; |
Lines 1647-1653
Link Here
|
1647 |
Icon retValue = super.getIcon(); |
526 |
Icon retValue = super.getIcon(); |
1648 |
if( null == retValue && (null == getText() || getText().length() == 0 ) ) { |
527 |
if( null == retValue && (null == getText() || getText().length() == 0 ) ) { |
1649 |
if (unknownIcon == null) { |
528 |
if (unknownIcon == null) { |
1650 |
unknownIcon = new ImageIcon( ImageUtilities.loadImage( "org/openide/loaders/unknown.gif") ); |
529 |
unknownIcon = new ImageIcon( ImageUtilities.loadImage( "org/openide/loaders/unknown.gif") ); //NOI18N |
1651 |
} |
530 |
} |
1652 |
retValue = unknownIcon; |
531 |
retValue = unknownIcon; |
1653 |
} |
532 |
} |
Lines 1655-1664
Link Here
|
1655 |
} |
534 |
} |
1656 |
} |
535 |
} |
1657 |
|
536 |
|
1658 |
private DnDSupport getDnd() { |
|
|
1659 |
if (dnd == null) { |
1660 |
dnd = new DnDSupport(); |
1661 |
} |
1662 |
return dnd; |
1663 |
} |
1664 |
} // end of class Toolbar |
537 |
} // end of class Toolbar |