⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ui.java

📁 POS is a Java&#174 platform-based, mission-critical, ISO-8583 based financial transaction library/fr
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * jPOS Project [http://jpos.org] * Copyright (C) 2000-2008 Alejandro P. Revilla * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program.  If not, see <http://www.gnu.org/licenses/>. */package org.jpos.ui;import java.awt.BorderLayout;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.Frame;import java.awt.GraphicsDevice;import java.awt.GraphicsEnvironment;import java.awt.Toolkit;import java.awt.event.ActionListener;import java.net.MalformedURLException;import java.net.URL;import java.util.Arrays;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.MissingResourceException;import java.util.ResourceBundle;import javax.swing.AbstractButton;import javax.swing.ButtonGroup;import javax.swing.ImageIcon;import javax.swing.JCheckBoxMenuItem;import javax.swing.JComponent;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JRadioButtonMenuItem;import javax.swing.JScrollPane;import javax.swing.UIManager;import org.jdom.Element;import org.jdom.JDOMException;import org.jpos.util.Log;/** * @author Alejandro Revilla * * <p>jPOS UI main class</p> * * @see UIFactory * * See src/examples/ui/* for usage details */public class UI implements UIFactory, UIObjectFactory {    JFrame mainFrame;    Map registrar, mapping;    Element config;    UIObjectFactory objFactory;    Log log;    boolean destroyed = false;    static final ResourceBundle classMapping;    static {        classMapping = ResourceBundle.getBundle(UI.class.getName());    }    /**     * Create a new UI object     */    public UI () {        super ();        registrar = new HashMap ();        mapping = new HashMap ();        setObjectFactory (this);    }    /**     * Creates a new UI object     * @param config configuration element     */    public UI (Element config) {        this ();        setConfig (config);    }    /**     * Assigns an object factory use to create new object instances.     * If no object factory is asigned, UI uses the default classloader     *     * @param objFactory reference to an Object Factory     */    public void setObjectFactory (UIObjectFactory objFactory) {        this.objFactory = objFactory;    }    /**     * @param config the Configuration element     */    public void setConfig (Element config) {        this.config = config;    }    /**     * @param Log an optional Log instance     * @see org.jpos.util.Log     */    public void setLog (Log log) {        this.log = log;    }    public Log getLog () {        return log;    }    /**     * UI uses a map to hold references to its components     * ("id" attribute)     *     * @return UI component registrar     */    public Map getRegistrar () {        return registrar;    }    /**     * @param id Component id ("id" configuration attribute)     * @return the Object or null     */    public Object get (String id) {        return registrar.get (id);    }   /**    * UI is itself a UIFactory.     * This strategy is used to recursively instantiate components    * inside a container    *     * @param ui reference to this UI instance    * @param config free form configuration Element    * @return JComponent    */    public JComponent create (UI ui, Element e) {        return create (e);    }    /**     * UIObjectFactory implementation.     * uses default classloader     * @param clazz the Clazzzz     * @return the Object     * @throws throw exception if unable to instantiate      * @see setLog     */    public Object newInstance (String clazz) throws Exception {        ClassLoader cl = Thread.currentThread().getContextClassLoader ();        Class type = cl.loadClass (clazz);        return type.newInstance ();    }    /**     * configure this UI object     */    public void configure () throws JDOMException {        configure (config);    }     /**     * reconfigure can be used in order to re-configure components     * inside a container (i.e. changing a panel in response to     * an event).     * @see org.jpos.ui.action.Redirect     *     * @param elementName the element name used as new configuration     * @param panelName panel ID (see "id" attribute)     */    public void reconfigure (String elementName, String panelName) {        Container c =             panelName == null ? mainFrame.getContentPane() : ((JComponent) get (panelName));        if (c != null) {            c.removeAll ();            c.add (                createComponent (config.getChild (elementName))            );            if (c instanceof JComponent) {                ((JComponent)c).revalidate ();            }            c.repaint ();        }    }    /**     * dispose this UI object     */    public void dispose () {     /* This is the right code for the dispose, but it freezes in        JVM running under WinXP (in linux went fine.. I didn't         test it under other OS's)        (last version tested: JRE 1.5.0-beta2)          if (mainFrame != null) {            // dumpComponent (mainFrame);            mainFrame.dispose ();     */        destroyed = true;        Iterator it = (Arrays.asList(Frame.getFrames())).iterator();        while (it.hasNext()) {            JFrame jf = (JFrame) it.next();            removeComponent(jf);        }    }    /**     * @return true if this UI object has been disposed and is no longer valid     */    public boolean isDestroyed () {        return destroyed;    }    protected void configure (Element ui) throws JDOMException {        setLookAndFeel (ui);        createMappings (ui);        createObjects (ui, "object");        createObjects (ui, "action");        if (!"ui".equals (ui.getName())) {            ui = ui.getChild ("ui");        }        if (ui != null) {            JFrame frame = initFrame (ui);            Element mb = ui.getChild ("menubar");            if (mb != null)                 frame.setJMenuBar (buildMenuBar (mb));            frame.setContentPane (                createComponent (ui.getChild ("components"))            );            if ("true".equals (ui.getAttributeValue ("full-screen"))) {                GraphicsDevice device = GraphicsEnvironment                                            .getLocalGraphicsEnvironment()                                            .getDefaultScreenDevice();                frame.setUndecorated (                    "true".equals (ui.getAttributeValue ("undecorated"))                );                device.setFullScreenWindow(frame);            } else {                frame.show ();            }        }    }    private void removeComponent (Component c) {        if (c instanceof Container) {            Container cont = (Container) c;            Component[] cc = cont.getComponents();                        for (int i=0; i<cc.length; i++) {                removeComponent (cc[i]);            }            cont.removeAll();        }    }    // ##DEBUG##    private void dumpComponent (Component c) {        System.out.println (c.getClass().getName() + ":" + c.getBounds().getSize().toString());        if (c instanceof Container) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -