1 package com.ca.directory.jxplorer; 2 3 import com.ca.commons.cbutil.CBIntText; 4 import com.ca.commons.cbutil.CBUtility; 5 6 import javax.swing.*; 7 import java.awt.*; 8 import java.awt.event.ActionEvent ; 9 import java.awt.event.ActionListener ; 10 import java.util.logging.Logger ; 11 12 13 14 19 20 public class ButtonBar extends JToolBar 21 implements ActionListener 22 { 23 JXplorer jxplorer; 24 MainMenu menu; 25 JButton connect,disconnect,print,cut,copy,paste,del,newEntry,rename,refresh,stop,pasteAlias,copyDN; 26 27 ButtonRegister br = null; 28 29 private static Logger log = Logger.getLogger(ButtonBar.class.getName()); 30 31 32 36 37 public ButtonBar(JXplorer jxplorer) 38 { 39 super(); 40 this.jxplorer = jxplorer; 41 setFloatable(false); 42 43 menu = jxplorer.mainMenu; 45 setSize(750, 20); 46 47 String dir = JXplorer.getProperty("dir.images"); 48 String dirIcons = JXplorer.getProperty("dir.icons"); 49 add(connect = new JButton(new ImageIcon(dir + "connect.gif"))); 50 add(disconnect = new JButton(new ImageIcon(dir + "disconnect.gif"))); 51 add(print = new JButton(new ImageIcon(dir + "print.gif"))); 52 addSeparator(); 53 add(cut = new JButton(new ImageIcon(dir + "cut.gif"))); 54 add(copyDN = new JButton(new ImageIcon(dir + "copy_dn.gif"))); 55 add(copy = new JButton(new ImageIcon(dir + "copy.gif"))); 56 add(paste = new JButton(new ImageIcon(dir + "paste.gif"))); 57 add(pasteAlias = new JButton(new ImageIcon(dirIcons + "alias.gif"))); 58 addSeparator(); 59 add(del = new JButton(new ImageIcon(dir + "delete.gif"))); 60 addSeparator(); 61 add(newEntry = new JButton(new ImageIcon(dir + "new.gif"))); 62 add(rename = new JButton(new ImageIcon(dir + "rename.gif"))); 63 addSeparator(); 64 add(refresh = new JButton(new ImageIcon(dir + "refresh.gif"))); 65 addSeparator(); 66 add(stop = new JButton(new ImageIcon(dir + "stop.gif"))); 67 68 connect.setRolloverIcon(new ImageIcon(dir + "connect_rollover.gif")); 69 disconnect.setRolloverIcon(new ImageIcon(dir + "disconnect_rollover.gif")); 70 print.setRolloverIcon(new ImageIcon(dir + "print_rollover.gif")); 71 cut.setRolloverIcon(new ImageIcon(dir + "cut_rollover.gif")); 72 copy.setRolloverIcon(new ImageIcon(dir + "copy_rollover.gif")); 73 copyDN.setRolloverIcon(new ImageIcon(dir + "copy_dn_rollover.gif")); 74 paste.setRolloverIcon(new ImageIcon(dir + "paste_rollover.gif")); 75 pasteAlias.setRolloverIcon(new ImageIcon(dir + "alias_rollover.gif")); 76 del.setRolloverIcon(new ImageIcon(dir + "delete_rollover.gif")); 77 newEntry.setRolloverIcon(new ImageIcon(dir + "new_rollover.gif")); 78 rename.setRolloverIcon(new ImageIcon(dir + "rename_rollover.gif")); 79 refresh.setRolloverIcon(new ImageIcon(dir + "refresh_rollover.gif")); 80 stop.setRolloverIcon(new ImageIcon(dir + "stop_rollover.gif")); 81 82 Component buttons[] = this.getComponents(); 83 for (int i = 0; i < buttons.length; i++) 84 if (buttons[i] instanceof JButton) { 86 JButton temp = ((JButton) buttons[i]); 87 temp.addActionListener(this); 88 temp.setRolloverEnabled(true); 89 temp.setSize(16, 16); 90 } 91 92 connect.setToolTipText(CBIntText.get("Connect to a DSA.")); 93 disconnect.setToolTipText(CBIntText.get("Disconnect from a DSA.")); 94 print.setToolTipText(CBIntText.get("Print out the current entry.")); 95 cut.setToolTipText(CBIntText.get("Select a subtree to move.")); 96 copy.setToolTipText(CBIntText.get("Select a subtree to copy.")); 97 copyDN.setToolTipText(CBIntText.get("Copy the Distinguished Name of an entry to the clipboard.")); 98 paste.setToolTipText(CBIntText.get("Paste a previously selected subtree.")); 99 pasteAlias.setToolTipText(CBIntText.get("Paste an Alias.")); 100 del.setToolTipText(CBIntText.get("Delete an entry.")); 101 newEntry.setToolTipText(CBIntText.get("Create a new entry.")); 102 rename.setToolTipText(CBIntText.get("Rename an entry.")); 103 refresh.setToolTipText(CBIntText.get("Refresh an entry.")); 104 stop.setToolTipText(CBIntText.get("Cancel queries.")); 105 106 br = JXplorer.getButtonRegister(); 107 108 br.registerItem(br.PASTE, paste); 109 br.registerItem(br.PASTE_ALIAS, pasteAlias); 110 br.registerItem(br.COPY, copy); 111 br.registerItem(br.COPY_DN, copyDN); 112 br.registerItem(br.CUT, cut); 113 br.registerItem(br.CONNECT, connect); 114 br.registerItem(br.DISCONNECT, disconnect); 115 br.registerItem(br.PRINT, print); 116 br.registerItem(br.DELETE, del); 117 br.registerItem(br.NEW, newEntry); 118 br.registerItem(br.RENAME, rename); 119 br.registerItem(br.REFRESH, refresh); 120 br.registerItem(br.STOP, stop); 121 122 br.setItemEnabled(br.STOP, false); 123 124 jxplorer.getStopMonitor().addWatcher(stop); 126 setDisconnected(); 127 128 setMargin(new Insets(2, 0, 2, 0)); 129 130 doLayout(); 131 } 132 133 134 135 140 public void actionPerformed(ActionEvent e) 141 { 142 if (e.getSource() == connect) 143 menu.connect(); 144 else if (e.getSource() == disconnect) 145 menu.disconnect(); 146 else if (e.getSource() == print) 147 menu.print(); 148 else if (e.getSource() == cut) 149 jxplorer.getActiveTree().getPopupTool().cut(); 150 else if (e.getSource() == copy) 151 jxplorer.getActiveTree().getPopupTool().copy(); 152 else if (e.getSource() == copyDN) 153 jxplorer.getActiveTree().getPopupTool().copyDN(); 154 else if (e.getSource() == paste) 155 jxplorer.getActiveTree().getPopupTool().paste(); 156 else if (e.getSource() == pasteAlias) 157 jxplorer.getActiveTree().getPopupTool().pasteAlias(); 158 else if (e.getSource() == del) 159 jxplorer.getActiveTree().getPopupTool().delete(); 160 else if (e.getSource() == newEntry) 161 jxplorer.getActiveTree().getPopupTool().newEntry(); 162 else if (e.getSource() == rename) 163 jxplorer.getActiveTree().getPopupTool().rename(); 164 else if (e.getSource() == refresh) 165 jxplorer.getActiveTree().getPopupTool().refresh(); 166 else if (e.getSource() == stop) 167 jxplorer.getStopMonitor().show(); 168 else 169 log.warning("error - unknown option in ButtonBar: " + e.getSource().toString()); 170 171 } 172 173 174 175 179 public void setConnected() 180 { 181 br.setConnectedState(); 182 } 183 184 185 186 190 public void setDisconnected() 191 { 192 br.setDisconnectState(); 193 } 194 } | Popular Tags |