Lines 42-60
Link Here
|
42 |
package org.openide.awt; |
42 |
package org.openide.awt; |
43 |
|
43 |
|
44 |
|
44 |
|
45 |
import java.awt.*; |
45 |
import java.awt.BorderLayout; |
46 |
import java.awt.event.*; |
46 |
import java.awt.Component; |
|
|
47 |
import java.awt.FlowLayout; |
48 |
import java.awt.event.ActionEvent; |
49 |
import java.awt.event.ActionListener; |
50 |
import java.awt.event.MouseEvent; |
47 |
import java.io.IOException; |
51 |
import java.io.IOException; |
48 |
import java.util.*; |
|
|
49 |
import java.util.ArrayList; |
52 |
import java.util.ArrayList; |
50 |
import javax.accessibility.*; |
53 |
import java.util.Collections; |
51 |
import javax.swing.*; |
54 |
import java.util.Map; |
|
|
55 |
import java.util.TreeMap; |
56 |
import java.util.WeakHashMap; |
57 |
import java.util.logging.Level; |
58 |
import java.util.logging.Logger; |
59 |
import javax.accessibility.Accessible; |
60 |
import javax.accessibility.AccessibleContext; |
61 |
import javax.accessibility.AccessibleRole; |
62 |
import javax.swing.ButtonGroup; |
63 |
import javax.swing.JComponent; |
52 |
import javax.swing.JComponent.AccessibleJComponent; |
64 |
import javax.swing.JComponent.AccessibleJComponent; |
53 |
import javax.swing.border.Border; |
65 |
import javax.swing.JPanel; |
|
|
66 |
import javax.swing.JPopupMenu; |
67 |
import javax.swing.JRadioButtonMenuItem; |
54 |
import org.openide.cookies.InstanceCookie; |
68 |
import org.openide.cookies.InstanceCookie; |
55 |
import org.openide.filesystems.*; |
69 |
import org.openide.filesystems.FileObject; |
56 |
import org.openide.loaders.*; |
70 |
import org.openide.filesystems.FileUtil; |
57 |
import org.openide.util.*; |
71 |
import org.openide.filesystems.Repository; |
|
|
72 |
import org.openide.loaders.DataFolder; |
73 |
import org.openide.loaders.FolderInstance; |
74 |
import org.openide.util.Task; |
75 |
import org.openide.util.TaskListener; |
58 |
|
76 |
|
59 |
/** |
77 |
/** |
60 |
* This class keeps track of the current toolbars and their names. |
78 |
* This class keeps track of the current toolbars and their names. |
Lines 107-115
Link Here
|
107 |
try { |
125 |
try { |
108 |
fo = FileUtil.createFolder(root, "Toolbars"); // NOI18N |
126 |
fo = FileUtil.createFolder(root, "Toolbars"); // NOI18N |
109 |
} catch (IOException ex) { |
127 |
} catch (IOException ex) { |
110 |
Exceptions.printStackTrace(ex); |
128 |
Logger.getLogger(ToolbarPool.class.getName()).log(Level.CONFIG, "Cannot create Toolbars folder.", ex); |
111 |
} |
129 |
} |
112 |
if (fo == null) throw new IllegalStateException("No Toolbars/"); // NOI18N |
130 |
if (fo == null) |
|
|
131 |
throw new IllegalStateException("No Toolbars/"); // NOI18N |
113 |
DataFolder folder = DataFolder.findFolder(fo); |
132 |
DataFolder folder = DataFolder.findFolder(fo); |
114 |
defaultPool = new ToolbarPool(folder); |
133 |
defaultPool = new ToolbarPool(folder); |
115 |
// we mustn't do this in constructor to prevent from |
134 |
// we mustn't do this in constructor to prevent from |
Lines 142-166
Link Here
|
142 |
|
161 |
|
143 |
getAccessibleContext().setAccessibleName(instance.instanceName()); |
162 |
getAccessibleContext().setAccessibleName(instance.instanceName()); |
144 |
getAccessibleContext().setAccessibleDescription(instance.instanceName()); |
163 |
getAccessibleContext().setAccessibleDescription(instance.instanceName()); |
145 |
|
|
|
146 |
if ("Windows".equals(UIManager.getLookAndFeel().getID())) { |
147 |
if( isXPTheme() ) { |
148 |
//Set up custom borders for XP |
149 |
setBorder(BorderFactory.createCompoundBorder( |
150 |
upperBorder, |
151 |
BorderFactory.createCompoundBorder( |
152 |
BorderFactory.createMatteBorder(0, 0, 1, 0, |
153 |
fetchColor("controlShadow", Color.DARK_GRAY)), |
154 |
BorderFactory.createMatteBorder(0, 0, 1, 0, mid)) |
155 |
)); //NOI18N |
156 |
} else { |
157 |
setBorder( BorderFactory.createEtchedBorder() ); |
158 |
} |
164 |
} |
159 |
} else if ("GTK".equals(UIManager.getLookAndFeel().getID())) { |
|
|
160 |
//No border |
161 |
setBorder (BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
162 |
} |
163 |
} |
164 |
|
165 |
|
165 |
/** |
166 |
/** |
166 |
* Gets preferred size of icons used by toolbar buttons. Default icon size |
167 |
* Gets preferred size of icons used by toolbar buttons. Default icon size |
Lines 185-245
Link Here
|
185 |
this.preferredIconSize = preferredIconSize; |
186 |
this.preferredIconSize = preferredIconSize; |
186 |
} |
187 |
} |
187 |
|
188 |
|
188 |
public Border getBorder() { |
|
|
189 |
//Issue 36867, hide border if there are no toolbars. Not the most |
190 |
//performant way to do it; if it has a measurable impact, can be |
191 |
//improved |
192 |
if (center != null && center instanceof Container && |
193 |
((Container)center).getComponentCount() > 0) { |
194 |
|
195 |
boolean show = false; |
196 |
for (int i=0; i < ((Container)center).getComponentCount(); i++) { |
197 |
Component c = ((Container)center).getComponent(i); |
198 |
if (c.isVisible()) { |
199 |
show = true; |
200 |
break; |
201 |
} |
202 |
} |
203 |
if (show) { |
204 |
return super.getBorder(); |
205 |
} |
206 |
} |
207 |
return lowerBorder; |
208 |
} |
209 |
|
210 |
private static Color fetchColor (String key, Color fallback) { |
211 |
//Fix ExceptionInInitializerError from MainWindow on GTK L&F - use |
212 |
//fallback colors |
213 |
Color result = (Color) UIManager.get(key); |
214 |
if (result == null) { |
215 |
result = fallback; |
216 |
} |
217 |
return result; |
218 |
} |
219 |
|
220 |
private static Color mid; |
221 |
static { |
222 |
Color lo = fetchColor("controlShadow", Color.DARK_GRAY); //NOI18N |
223 |
Color hi = fetchColor("control", Color.GRAY); //NOI18N |
224 |
|
225 |
int r = (lo.getRed() + hi.getRed()) / 2; |
226 |
int g = (lo.getGreen() + hi.getGreen()) / 2; |
227 |
int b = (lo.getBlue() + hi.getBlue()) / 2; |
228 |
mid = new Color(r, g, b); |
229 |
} |
230 |
|
231 |
private static final Border lowerBorder = BorderFactory.createCompoundBorder( |
232 |
BorderFactory.createMatteBorder(0, 0, 1, 0, |
233 |
fetchColor("controlShadow", Color.DARK_GRAY)), |
234 |
BorderFactory.createMatteBorder(0, 0, 1, 0, mid)); //NOI18N |
235 |
|
236 |
private static final Border upperBorder = BorderFactory.createCompoundBorder( |
237 |
BorderFactory.createMatteBorder(1, 0, 0, 0, |
238 |
fetchColor("controlShadow", Color.DARK_GRAY)), |
239 |
BorderFactory.createMatteBorder(1, 0, 0, 0, |
240 |
fetchColor("controlLtHighlight", Color.WHITE))); //NOI18N |
241 |
|
242 |
|
243 |
/** Allows to wait till the content of the pool is initialized. */ |
189 |
/** Allows to wait till the content of the pool is initialized. */ |
244 |
public final void waitFinished () { |
190 |
public final void waitFinished () { |
245 |
instance.instanceFinished (); |
191 |
instance.instanceFinished (); |
Lines 262-276
Link Here
|
262 |
|
208 |
|
263 |
/** Updates the default configuration. */ |
209 |
/** Updates the default configuration. */ |
264 |
private synchronized void updateDefault () { |
210 |
private synchronized void updateDefault () { |
265 |
Toolbar[] toolbars = getToolbars (); |
211 |
Toolbar[] bars = getToolbars (); |
266 |
name = ""; // NOI18N |
212 |
name = ""; // NOI18N |
267 |
|
213 |
|
268 |
if (toolbars.length == 1) { |
214 |
if (bars.length == 1) { |
269 |
revalidate(toolbars[0]); |
215 |
revalidate(bars[0]); |
270 |
} else { |
216 |
} else { |
271 |
JPanel tp = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
217 |
JPanel tp = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
272 |
for (int i = 0; i < toolbars.length; i++) { |
218 |
for (int i = 0; i < bars.length; i++) { |
273 |
tp.add(toolbars[i]); |
219 |
tp.add(bars[i]); |
274 |
} |
220 |
} |
275 |
revalidate(tp); |
221 |
revalidate(tp); |
276 |
} |
222 |
} |
Lines 285-291
Link Here
|
285 |
revalidate (comp); |
231 |
revalidate (comp); |
286 |
} |
232 |
} |
287 |
|
233 |
|
288 |
/** Sets DnDListener to all Toolbars. */ |
234 |
/** Sets DnDListener to all Toolbars. |
|
|
235 |
* @deprecated |
236 |
*/ |
289 |
public void setToolbarsListener (Toolbar.DnDListener l) { |
237 |
public void setToolbarsListener (Toolbar.DnDListener l) { |
290 |
for (Toolbar t: toolbars.values()) { |
238 |
for (Toolbar t: toolbars.values()) { |
291 |
t.setDnDListener (l); |
239 |
t.setDnDListener (l); |
Lines 302-312
Link Here
|
302 |
} |
250 |
} |
303 |
add (center = c, BorderLayout.CENTER); |
251 |
add (center = c, BorderLayout.CENTER); |
304 |
center.addMouseListener (listener); |
252 |
center.addMouseListener (listener); |
305 |
|
|
|
306 |
// java.awt.Window w = javax.swing.SwingUtilities.windowForComponent (this); |
307 |
// if (w != null) { |
308 |
// w.validate(); |
309 |
// } |
310 |
} |
253 |
} |
311 |
} |
254 |
} |
312 |
|
255 |
|
Lines 366-372
Link Here
|
366 |
activate (config); |
309 |
activate (config); |
367 |
} |
310 |
} |
368 |
|
311 |
|
369 |
firePropertyChange("configuration", old, name); |
312 |
firePropertyChange("configuration", old, name); //NOI18N |
370 |
} |
313 |
} |
371 |
|
314 |
|
372 |
/** |
315 |
/** |
Lines 402-410
Link Here
|
402 |
/** Read accessible context |
345 |
/** Read accessible context |
403 |
* @return - accessible context |
346 |
* @return - accessible context |
404 |
*/ |
347 |
*/ |
|
|
348 |
@Override |
405 |
public AccessibleContext getAccessibleContext () { |
349 |
public AccessibleContext getAccessibleContext () { |
406 |
if(toolbarAccessibleContext == null) { |
350 |
if(toolbarAccessibleContext == null) { |
407 |
toolbarAccessibleContext = new AccessibleJComponent() { |
351 |
toolbarAccessibleContext = new AccessibleJComponent() { |
|
|
352 |
@Override |
408 |
public AccessibleRole getAccessibleRole() { |
353 |
public AccessibleRole getAccessibleRole() { |
409 |
return AccessibleRole.TOOL_BAR; |
354 |
return AccessibleRole.TOOL_BAR; |
410 |
} |
355 |
} |
Lines 413-440
Link Here
|
413 |
return toolbarAccessibleContext; |
358 |
return toolbarAccessibleContext; |
414 |
} |
359 |
} |
415 |
|
360 |
|
416 |
/** Recognizes if XP theme is set. |
|
|
417 |
* (copy & paste from org.openide.awt.Toolbar to avoid API changes) |
418 |
* @return true if XP theme is set, false otherwise |
419 |
*/ |
420 |
private static Boolean isXP = null; |
421 |
private static boolean isXPTheme () { |
422 |
if (isXP == null) { |
423 |
Boolean xp = (Boolean)Toolkit.getDefaultToolkit(). |
424 |
getDesktopProperty("win.xpstyle.themeActive"); //NOI18N |
425 |
isXP = Boolean.TRUE.equals(xp)? Boolean.TRUE : Boolean.FALSE; |
426 |
} |
427 |
return isXP.booleanValue(); |
428 |
} |
429 |
|
430 |
/** |
361 |
/** |
431 |
* @return True if the Toolbar Customizer is visible and toolbar buttons can be dragged. |
|
|
432 |
*/ |
433 |
boolean isInEditMode() { |
434 |
return null != getClientProperty( "editMode" ); |
435 |
} |
436 |
|
437 |
/** |
438 |
* This class is used for delayed setting of configuration after instance |
362 |
* This class is used for delayed setting of configuration after instance |
439 |
* creation is finished. It may happen during IDE start that |
363 |
* creation is finished. It may happen during IDE start that |
440 |
* ToolbarPool.setConfiguration is called before instance is created. |
364 |
* ToolbarPool.setConfiguration is called before instance is created. |
Lines 473-478
Link Here
|
473 |
* Full name of the data folder's primary file separated by dots. |
397 |
* Full name of the data folder's primary file separated by dots. |
474 |
* @return the name |
398 |
* @return the name |
475 |
*/ |
399 |
*/ |
|
|
400 |
@Override |
476 |
public String instanceName () { |
401 |
public String instanceName () { |
477 |
return instanceClass().getName(); |
402 |
return instanceClass().getName(); |
478 |
} |
403 |
} |
Lines 481-486
Link Here
|
481 |
* Returns the root class of all objects. |
406 |
* Returns the root class of all objects. |
482 |
* @return Object.class |
407 |
* @return Object.class |
483 |
*/ |
408 |
*/ |
|
|
409 |
@Override |
484 |
public Class instanceClass () { |
410 |
public Class instanceClass () { |
485 |
return ToolbarPool.class; |
411 |
return ToolbarPool.class; |
486 |
} |
412 |
} |
Lines 490-497
Link Here
|
490 |
* @param cookie the instance cookie to test |
416 |
* @param cookie the instance cookie to test |
491 |
* @return true if the cookie can provide <code>Configuration</code> |
417 |
* @return true if the cookie can provide <code>Configuration</code> |
492 |
*/ |
418 |
*/ |
|
|
419 |
@Override |
493 |
protected InstanceCookie acceptCookie (InstanceCookie cookie) |
420 |
protected InstanceCookie acceptCookie (InstanceCookie cookie) |
494 |
throws java.io.IOException, ClassNotFoundException { |
421 |
throws java.io.IOException, ClassNotFoundException { |
|
|
422 |
|
495 |
Class cls = cookie.instanceClass(); |
423 |
Class cls = cookie.instanceClass(); |
496 |
if (ToolbarPool.Configuration.class.isAssignableFrom (cls)) { |
424 |
if (ToolbarPool.Configuration.class.isAssignableFrom (cls)) { |
497 |
return cookie; |
425 |
return cookie; |
Lines 508-517
Link Here
|
508 |
* @param df a <code>DataFolder</code> to create the cookie for |
436 |
* @param df a <code>DataFolder</code> to create the cookie for |
509 |
* @return a <code>Toolbar.Folder</code> for the specified folder |
437 |
* @return a <code>Toolbar.Folder</code> for the specified folder |
510 |
*/ |
438 |
*/ |
|
|
439 |
@Override |
511 |
protected InstanceCookie acceptFolder (DataFolder df) { |
440 |
protected InstanceCookie acceptFolder (DataFolder df) { |
512 |
InstanceCookie ic = foldersCache.get (df); |
441 |
InstanceCookie ic = foldersCache.get (df); |
513 |
if (ic == null) { |
442 |
if (ic == null) { |
514 |
ic = (FolderInstance)new Toolbar (df, true).waitFinished (); |
443 |
ic = (FolderInstance) new Toolbar(df).waitFinished (); |
515 |
foldersCache.put (df, ic); |
444 |
foldersCache.put (df, ic); |
516 |
} |
445 |
} |
517 |
return ic; |
446 |
return ic; |
Lines 533-542
Link Here
|
533 |
|
462 |
|
534 |
for (int i = 0; i < length; i++) { |
463 |
for (int i = 0; i < length; i++) { |
535 |
try { |
464 |
try { |
536 |
java.lang.Object obj = cookies[i].instanceCreate(); |
465 |
Object obj = cookies[i].instanceCreate(); |
537 |
|
466 |
|
538 |
if (obj instanceof org.openide.awt.Toolbar) { |
467 |
if (obj instanceof Toolbar) { |
539 |
org.openide.awt.Toolbar toolbar = (org.openide.awt.Toolbar) obj; |
468 |
Toolbar toolbar = (Toolbar) obj; |
540 |
|
469 |
|
541 |
// should be done by ToolbarPanel in add method |
470 |
// should be done by ToolbarPanel in add method |
542 |
toolbar.removeMouseListener(listener); |
471 |
toolbar.removeMouseListener(listener); |
Lines 545-552
Link Here
|
545 |
toolbarNames.add(toolbar.getName()); |
474 |
toolbarNames.add(toolbar.getName()); |
546 |
continue; |
475 |
continue; |
547 |
} |
476 |
} |
548 |
if (obj instanceof org.openide.awt.ToolbarPool.Configuration) { |
477 |
if (obj instanceof ToolbarPool.Configuration) { |
549 |
org.openide.awt.ToolbarPool.Configuration config = (org.openide.awt.ToolbarPool.Configuration) obj; |
478 |
ToolbarPool.Configuration config = (ToolbarPool.Configuration) obj; |
550 |
java.lang.String name = config.getName(); |
479 |
java.lang.String name = config.getName(); |
551 |
|
480 |
|
552 |
if (name == null) { |
481 |
if (name == null) { |
Lines 555-579
Link Here
|
555 |
conf.put(name, config); |
484 |
conf.put(name, config); |
556 |
continue; |
485 |
continue; |
557 |
} |
486 |
} |
558 |
if (obj instanceof java.awt.Component) { |
487 |
if (obj instanceof Component) { |
559 |
java.awt.Component comp = (java.awt.Component) obj; |
488 |
Component comp = (Component) obj; |
560 |
java.lang.String name = comp.getName(); |
489 |
String name = comp.getName(); |
561 |
|
490 |
|
562 |
if (name == null) { |
491 |
if (name == null) { |
563 |
name = cookies[i].instanceName(); |
492 |
name = cookies[i].instanceName(); |
564 |
} |
493 |
} |
565 |
conf.put(name, |
494 |
conf.put(name, new ToolbarPool.ComponentConfiguration(comp)); |
566 |
new org.openide.awt.ToolbarPool.ComponentConfiguration(comp)); |
|
|
567 |
continue; |
495 |
continue; |
568 |
} |
496 |
} |
|
|
497 |
} catch (IOException ex) { |
498 |
Logger.getLogger(ToolbarPool.class.getName()).log(Level.INFO, "Error while creating toolbars.", ex); |
499 |
} catch (ClassNotFoundException ex) { |
500 |
Logger.getLogger(ToolbarPool.class.getName()).log(Level.INFO, "Error while creating toolbars.", ex); |
569 |
} |
501 |
} |
570 |
catch (java.io.IOException ex) { |
|
|
571 |
Exceptions.printStackTrace(ex); |
572 |
} |
502 |
} |
573 |
catch (java.lang.ClassNotFoundException ex) { |
|
|
574 |
Exceptions.printStackTrace(ex); |
575 |
} |
576 |
} |
577 |
update (toolbars, conf, toolbarNames); |
503 |
update (toolbars, conf, toolbarNames); |
578 |
|
504 |
|
579 |
return ToolbarPool.this; |
505 |
return ToolbarPool.this; |
Lines 581-586
Link Here
|
581 |
|
507 |
|
582 |
/** Recreate the instance in AWT thread. |
508 |
/** Recreate the instance in AWT thread. |
583 |
*/ |
509 |
*/ |
|
|
510 |
@Override |
584 |
protected Task postCreationTask (Runnable run) { |
511 |
protected Task postCreationTask (Runnable run) { |
585 |
return new AWTTask (run); |
512 |
return new AWTTask (run); |
586 |
} |
513 |
} |
Lines 635-643
Link Here
|
635 |
* component */ |
562 |
* component */ |
636 |
private static final class ComponentConfiguration extends JPopupMenu |
563 |
private static final class ComponentConfiguration extends JPopupMenu |
637 |
implements Configuration, ActionListener { |
564 |
implements Configuration, ActionListener { |
|
|
565 |
|
638 |
private Component comp; |
566 |
private Component comp; |
639 |
|
567 |
|
640 |
ComponentConfiguration() {} |
568 |
ComponentConfiguration() { |
|
|
569 |
} |
641 |
|
570 |
|
642 |
static final long serialVersionUID =-409474484612485719L; |
571 |
static final long serialVersionUID =-409474484612485719L; |
643 |
/** @param comp component that represents this configuration */ |
572 |
/** @param comp component that represents this configuration */ |
Lines 652-657
Link Here
|
652 |
|
581 |
|
653 |
/** @return name of the component |
582 |
/** @return name of the component |
654 |
*/ |
583 |
*/ |
|
|
584 |
@Override |
655 |
public String getName () { |
585 |
public String getName () { |
656 |
return comp.getName (); |
586 |
return comp.getName (); |
657 |
} |
587 |
} |
Lines 662-672
Link Here
|
662 |
removeAll (); |
592 |
removeAll (); |
663 |
|
593 |
|
664 |
// generate list of available toolbar panels |
594 |
// generate list of available toolbar panels |
665 |
Iterator it = Arrays.asList (ToolbarPool.getDefault ().getConfigurations ()).iterator (); |
|
|
666 |
ButtonGroup bg = new ButtonGroup (); |
595 |
ButtonGroup bg = new ButtonGroup (); |
667 |
String current = ToolbarPool.getDefault ().getConfiguration (); |
596 |
String current = ToolbarPool.getDefault ().getConfiguration (); |
668 |
while (it.hasNext()) { |
597 |
for( String name : ToolbarPool.getDefault().getConfigurations() ) { |
669 |
final String name = (String)it.next (); |
|
|
670 |
JRadioButtonMenuItem mi = new JRadioButtonMenuItem (name, (name.compareTo (current) == 0)); |
598 |
JRadioButtonMenuItem mi = new JRadioButtonMenuItem (name, (name.compareTo (current) == 0)); |
671 |
mi.addActionListener (this); |
599 |
mi.addActionListener (this); |
672 |
bg.add (mi); |
600 |
bg.add (mi); |
Lines 681-688
Link Here
|
681 |
public void actionPerformed (ActionEvent evt) { |
609 |
public void actionPerformed (ActionEvent evt) { |
682 |
ToolbarPool.getDefault().setConfiguration (evt.getActionCommand ()); |
610 |
ToolbarPool.getDefault().setConfiguration (evt.getActionCommand ()); |
683 |
} |
611 |
} |
684 |
|
|
|
685 |
} |
612 |
} |
686 |
|
|
|
687 |
} // end of ToolbarPool |
613 |
} // end of ToolbarPool |
688 |
|
614 |
|