Changeset 31


Ignore:
Timestamp:
10/02/02 18:27:06 (20 years ago)
Author:
piso
Message:

public static ToolBar? createToolBar(Frame frame, File file)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/ToolBar.java

    r2 r31  
    33 *
    44 * Copyright (C) 2000-2002 Peter Graves
    5  * $Id: ToolBar.java,v 1.1.1.1 2002-09-24 16:08:17 piso Exp $
     5 * $Id: ToolBar.java,v 1.2 2002-10-02 18:27:06 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2525import java.awt.event.ActionEvent;
    2626import java.awt.event.ActionListener;
    27 import javax.swing.JButton;
    2827import javax.swing.JToolBar;
     28import org.xml.sax.AttributeList;
     29import org.xml.sax.DocumentHandler;
     30import org.xml.sax.HandlerBase;
     31import org.xml.sax.InputSource;
     32import org.xml.sax.Parser;
     33import org.xml.sax.SAXException;
    2934
    3035public class ToolBar extends JToolBar implements ActionListener, ToolBarConstants
     
    6267                if (iconsEnabled())
    6368                    button.setIconFromFile(iconFile);
    64                 button.setHorizontalTextPosition(JButton.CENTER);
    65                 button.setVerticalTextPosition(JButton.BOTTOM);
     69                button.setHorizontalTextPosition(ToolBarButton.CENTER);
     70                button.setVerticalTextPosition(ToolBarButton.BOTTOM);
    6671                break;
    6772            case STYLE_ICON_ONLY:
     
    119124        // Defaults to true for j's default look and feel.
    120125        return preferences.getBooleanProperty(Property.TOOL_BAR_IS_ROLLOVER,
    121                                               Editor.lookAndFeel == null);
     126            Editor.lookAndFeel == null);
    122127    }
    123128
     
    128133        editor.getDispatcher().actionPerformed(e);
    129134    }
     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    }
    130179}
Note: See TracChangeset for help on using the changeset viewer.