1 package rero.gui; 2 3 import javax.swing.*; 4 import javax.swing.event.*; 5 6 import java.awt.*; 7 import java.awt.event.*; 8 9 import java.awt.image.*; 10 11 import rero.config.*; 12 13 import rero.gui.toolbar.*; 14 import java.util.*; 15 16 public class GraphicalToolbar extends JToolBar 17 { 18 public static ImageIcon[] images = new ImageIcon[37]; 19 protected LinkedList tools = new LinkedList(); 20 21 private static GraphicalToolbar toolbar = null; 22 private static StateListener state; 24 public static void startup() 25 { 26 28 state = new StateListener(); 29 state.propertyChanged("ui.usetoolbar", ""); 30 31 ClientState.getClientState().addClientStateListener("ui.usetoolbar", state); 32 } 33 34 35 public static void stateChanged() 36 { 37 if (toolbar != null) 38 toolbar.refresh(); 39 } 40 41 public void refresh() 42 { 43 Iterator i = tools.iterator(); 44 while (i.hasNext()) 45 { 46 ((ToolButton)i.next()).displayIcon(); 47 } 48 } 49 50 private static class StateListener implements ClientStateListener 51 { 52 public void propertyChanged(String property, String parameter) 53 { 54 if (toolbar != null) 55 SessionManager.getGlobalCapabilities().getFrame().getContentPane().remove(toolbar); 56 57 if (ClientState.getClientState().isOption("ui.usetoolbar", ClientDefaults.ui_usetoolbar)) 58 { 59 if (toolbar == null) 60 toolbar = new GraphicalToolbar(); 61 62 SessionManager.getGlobalCapabilities().getFrame().getContentPane().add(toolbar, BorderLayout.NORTH); 63 } 64 65 if (toolbar != null) 66 SessionManager.getGlobalCapabilities().getFrame().getContentPane().validate(); 67 } 68 } 69 70 public GraphicalToolbar() 71 { 72 int[] tiles; 73 ToolAction[] actions; 74 75 if (ClientState.getClientState().isOption("ui.sdi", ClientDefaults.ui_sdi)) 76 { 77 tiles = new int[] { 0, -1, 4, 7, -1, 10, -1, 22, 23, 24, -1, 26, 28, -1, 35, 36 }; 78 actions = new ToolAction[] { 79 new ConnectAction(), 80 null, 81 new OptionsAction(), 82 new ScriptAction(), null, 84 new ListAction(), null, 86 new SendAction(), new ChatAction(), new DCCAction(), null, 90 new NotifyAction(), new NotifyAction2(), null, 93 new HelpAction(), 94 new AboutAction(), 95 new EvilAction() 96 }; 97 } 98 else 99 { 100 tiles = new int[] { 0, -1, 4, 7, -1, 10, -1, 22, 23, 24, -1, 26, 28, -1, 31, 32, -1, 35, 36 }; 101 actions = new ToolAction[] { 102 new ConnectAction(), 103 null, 104 new OptionsAction(), 105 new ScriptAction(), null, 107 new ListAction(), null, 109 new SendAction(), new ChatAction(), new DCCAction(), null, 113 new NotifyAction(), new NotifyAction2(), null, 116 new CascadeAction(), 117 new TileAction(), 118 null, 119 new HelpAction(), 120 new AboutAction(), 121 new EvilAction() 122 }; 123 } 124 125 BufferedImage all = LoadToolbarImage(); 126 127 for (int x = 0; x < 37; x++) 128 { 129 images[x] = new ImageIcon(all.getSubimage(x * 16, 0, 16, 16)); 130 } 131 132 for (int x = 0; x < actions.length; x++) 133 { 134 if (actions[x] == null) 135 { 136 addSeparator(new Dimension(12, 12)); 137 } 138 else 139 { 140 ToolButton temp = new ToolButton(actions[x]); 141 add(temp); 142 tools.add(temp); 143 } 144 } 145 146 setFloatable(false); 147 setBorderPainted(true); 148 } 149 150 private static class ToolButton extends JLabel 151 { 152 private ImageIcon normal; 153 private ImageIcon pressed; 154 private ToolAction action; 155 156 public ToolButton(ToolAction taction) 157 { 158 setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); 159 160 addMouseListener(new Listeners()); 161 162 action = taction; 163 displayIcon(); 164 } 165 166 public void displayIcon() 167 { 168 normal = images[action.getIndex()]; 169 pressed = new ImageIcon(GrayFilter.createDisabledImage(normal.getImage())); 170 setToolTipText(action.getDescription()); 171 172 setIcon(normal); 173 } 174 175 private class Listeners extends MouseAdapter 176 { 177 public void mouseClicked(MouseEvent ev) 178 { 179 action.actionPerformed(ev); 180 } 181 182 public void mousePressed(MouseEvent ev) 183 { 184 setIcon(pressed); 185 } 186 187 public void mouseReleased(MouseEvent ev) 188 { 189 setIcon(normal); 190 } 191 } 192 } 193 194 private static BufferedImage LoadToolbarImage() 195 { 196 ImageIcon original = ClientState.getClientState().getIcon("jirc.toolbar", "toolbar.gif"); 197 198 Image image = original.getImage(); 199 BufferedImage value = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); 200 201 Graphics g = value.getGraphics(); 202 g.drawImage(image, 0, 0, null); 203 204 original.getImage().flush(); 205 206 return value; 207 } 208 } 209 | Popular Tags |