Changeset 31
- Timestamp:
- 10/02/02 18:27:06 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/j/ToolBar.java
r2 r31 3 3 * 4 4 * Copyright (C) 2000-2002 Peter Graves 5 * $Id: ToolBar.java,v 1. 1.1.1 2002-09-24 16:08:17piso Exp $5 * $Id: ToolBar.java,v 1.2 2002-10-02 18:27:06 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 25 25 import java.awt.event.ActionEvent; 26 26 import java.awt.event.ActionListener; 27 import javax.swing.JButton;28 27 import javax.swing.JToolBar; 28 import org.xml.sax.AttributeList; 29 import org.xml.sax.DocumentHandler; 30 import org.xml.sax.HandlerBase; 31 import org.xml.sax.InputSource; 32 import org.xml.sax.Parser; 33 import org.xml.sax.SAXException; 29 34 30 35 public class ToolBar extends JToolBar implements ActionListener, ToolBarConstants … … 62 67 if (iconsEnabled()) 63 68 button.setIconFromFile(iconFile); 64 button.setHorizontalTextPosition( JButton.CENTER);65 button.setVerticalTextPosition( JButton.BOTTOM);69 button.setHorizontalTextPosition(ToolBarButton.CENTER); 70 button.setVerticalTextPosition(ToolBarButton.BOTTOM); 66 71 break; 67 72 case STYLE_ICON_ONLY: … … 119 124 // Defaults to true for j's default look and feel. 120 125 return preferences.getBooleanProperty(Property.TOOL_BAR_IS_ROLLOVER, 121 126 Editor.lookAndFeel == null); 122 127 } 123 128 … … 128 133 editor.getDispatcher().actionPerformed(e); 129 134 } 135 136 public static ToolBar createToolBar(Frame frame, File file) 137 { 138 if (file == null) 139 return null; 140 if (!file.isFile()) 141 return null; 142 try { 143 Parser parser = (Parser) Class.forName( 144 "org.armedbear.j.aelfred.SAXDriver").newInstance(); 145 ToolBar toolBar = new ToolBar(frame); 146 Handler handler = new Handler(toolBar); 147 parser.setDocumentHandler(handler); 148 InputSource inputSource = new InputSource(file.getInputStream()); 149 parser.parse(inputSource); 150 return toolBar; 151 } 152 catch (Exception e) { 153 Log.error(e); 154 return null; 155 } 156 } 157 158 private static class Handler extends HandlerBase implements DocumentHandler 159 { 160 private final ToolBar toolBar; 161 162 public Handler(ToolBar toolBar) 163 { 164 this.toolBar = toolBar; 165 } 166 167 public void startElement(String name, AttributeList attributes) 168 throws SAXException 169 { 170 if (name.equals("button")) { 171 String label = attributes.getValue("label"); 172 String icon = attributes.getValue("icon"); 173 String command = attributes.getValue("command"); 174 toolBar.addButton(label, icon, command); 175 } else if (name.equals("separator")) 176 toolBar.addSeparator(); 177 } 178 } 130 179 }
Note: See TracChangeset
for help on using the changeset viewer.