1 2 24 package org.enhydra.tool.common; 25 26 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import java.util.ArrayList ; 30 import java.util.Arrays ; 31 import java.util.ResourceBundle ; 32 import javax.swing.AbstractButton ; 33 import javax.swing.JPanel ; 34 import java.awt.*; 35 import java.beans.*; 36 37 public class ButtonPanel extends JPanel { 39 public static final int BACK = 0; 40 public static final int NEXT = 1; 41 public static final int DEPLOY = 2; 42 public static final int HELP = 3; 43 public static final int ABOUT = 4; 44 public static final int CLOSE = 5; 45 public static final int COMPILE = 6; 46 public static final int CANCEL = 7; 47 public static final int FINISH = 7; 48 public static final int GENERATE = 8; 49 50 public static ResourceBundle res = 52 ResourceBundle.getBundle("org.enhydra.tool.common.Res"); 54 public static final String COMMAND_BACK = res.getString("_Back"); 56 public static final String COMMAND_NEXT = res.getString("Next_"); 57 public static final String COMMAND_DEPLOY = res.getString("Deploy"); 58 public static final String COMMAND_HELP = res.getString("Help"); 59 public static final String COMMAND_ABOUT = res.getString("About_"); 60 public static final String COMMAND_CLOSE = res.getString("Close"); 61 public static final String COMMAND_COMPILE = res.getString("Compile"); 62 public static final String COMMAND_CANCEL = res.getString("Cancel"); 63 public static final String COMMAND_FINISH = res.getString("Finish"); 64 public static final String COMMAND_GENERATE = res.getString("Generate"); 65 66 private ActionListener [] actionListeners = new ActionListener [0]; 68 private GridBagLayout layoutDefault; 69 70 public static Component findButton(Container container, String command) { 71 Component[] children = null; 72 Component button = null; 73 74 if (container == null) { 75 children = new Component[0]; 76 } else { 77 children = container.getComponents(); 78 } 79 for (int i = 0; i < children.length; i++) { 80 if (children[i] instanceof AbstractButton ) { 81 AbstractButton suspect = null; 82 83 suspect = (AbstractButton ) children[i]; 84 if (suspect.getActionCommand().equals(command)) { 85 button = suspect; 86 } 87 } else if (children[i] instanceof Button ) { 88 Button suspect = null; 89 90 suspect = (Button ) children[i]; 91 if (suspect.getActionCommand().equals(command)) { 92 button = suspect; 93 } 94 } else if (children[i] instanceof Container) { 95 button = findButton((Container) children[i], command); 96 } 97 if (button != null) { 98 break; 99 } 100 } 101 return button; 102 } 103 104 public ButtonPanel() { 105 try { 106 jbInit(); 107 } catch (Exception e) { 108 e.printStackTrace(); 109 } 110 } 111 112 public Window getWindow() { 113 return (Window) getTopLevelAncestor(); 114 } 115 116 public void removeHelp() {} 117 118 public void clearAll() { 119 removeAll(); 120 actionListeners = new ActionListener [0]; 121 } 122 123 public synchronized void addActionListener(ActionListener l) { 124 ArrayList list = null; 125 126 list = new ArrayList (Arrays.asList(actionListeners)); 127 if (!list.contains(l)) { 128 list.add(l); 129 } 130 list.trimToSize(); 131 actionListeners = new ActionListener [list.size()]; 132 actionListeners = (ActionListener []) list.toArray(actionListeners); 133 list.clear(); 134 } 135 136 public synchronized void removeActionListener(ActionListener l) { 137 ArrayList list = null; 138 139 list = new ArrayList (Arrays.asList(actionListeners)); 140 if (list.contains(l)) { 141 list.remove(l); 142 } 143 list.trimToSize(); 144 actionListeners = new ActionListener [list.size()]; 145 actionListeners = (ActionListener []) list.toArray(actionListeners); 146 list.clear(); 147 } 148 149 public void notifyActionListeners(ActionEvent event) { 150 for (int i = 0; i < actionListeners.length; i++) { 151 actionListeners[i].actionPerformed(event); 152 } 153 } 154 155 private void jbInit() throws Exception { 156 layoutDefault = 157 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 158 GridBagLayout.class.getName()); 159 this.setLayout(layoutDefault); 160 } 161 162 } 163 | Popular Tags |