1 19 20 package org.netbeans.modules.openide.awt; 21 22 import java.awt.Component ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.Collection ; 26 import javax.swing.Action ; 27 import javax.swing.JMenuItem ; 28 import javax.swing.JPopupMenu ; 29 import javax.swing.JSeparator ; 30 import org.openide.awt.Actions; 31 import org.openide.awt.DynamicMenuContent; 32 import org.openide.util.actions.BooleanStateAction; 33 import org.openide.util.actions.SystemAction; 34 35 37 public final class DefaultAWTBridge extends org.netbeans.modules.openide.util.AWTBridge { 38 public JMenuItem createMenuPresenter (Action action) { 39 if (action instanceof BooleanStateAction) { 40 BooleanStateAction b = (BooleanStateAction)action; 41 return new Actions.CheckboxMenuItem (b, true); 42 } 43 if (action instanceof SystemAction) { 44 SystemAction s = (SystemAction)action; 45 return new Actions.MenuItem (s, true); 46 } 47 48 return new Actions.MenuItem (action, true); 49 } 50 51 public JMenuItem createPopupPresenter(Action action) { 52 if (action instanceof BooleanStateAction) { 53 BooleanStateAction b = (BooleanStateAction)action; 54 return new Actions.CheckboxMenuItem (b, false); 55 } 56 if (action instanceof SystemAction) { 57 SystemAction s = (SystemAction)action; 58 return new Actions.MenuItem (s, false); 59 } 60 61 return new Actions.MenuItem (action, false); 62 } 63 64 public Component createToolbarPresenter(Action action) { 65 if (action instanceof BooleanStateAction) { 66 BooleanStateAction b = (BooleanStateAction)action; 67 return new Actions.ToolbarToggleButton (b); 68 } 69 if (action instanceof SystemAction) { 70 SystemAction s = (SystemAction)action; 71 return new Actions.ToolbarButton (s); 72 } 73 74 return new Actions.ToolbarButton (action); 75 } 76 77 public JPopupMenu createEmptyPopup() { 78 return new JPopupMenu (); 79 } 80 81 public Component [] convertComponents(Component comp) { 82 if (comp instanceof DynamicMenuContent) { 83 Component [] toRet = ((DynamicMenuContent)comp).getMenuPresenters(); 84 boolean atLeastOne = false; 85 Collection <Component > col = new ArrayList <Component >(); 86 for (int i = 0; i < toRet.length; i++) { 87 if (toRet[i] instanceof DynamicMenuContent && toRet[i] != comp) { 88 col.addAll(Arrays.asList(convertComponents(toRet[i]))); 89 atLeastOne = true; 90 } else { 91 if (toRet[i] == null) { 92 toRet[i] = new JSeparator (); 93 } 94 col.add(toRet[i]); 95 } 96 } 97 if (atLeastOne) { 98 return col.toArray(new Component [col.size()]); 99 } else { 100 return toRet; 101 } 102 } 103 return new Component [] {comp}; 104 } 105 106 } 107 | Popular Tags |