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

📄 userlayoutproperties.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * UserLayoutProperties.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * */package org.executequery;import java.awt.Component;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.io.CharArrayWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.Serializable;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import javax.xml.transform.Transformer;import javax.xml.transform.TransformerFactory;import javax.xml.transform.sax.SAXSource;import javax.xml.transform.stream.StreamResult;import org.executequery.base.DockedDragEvent;import org.executequery.base.DockedTabDragListener;import org.executequery.base.DockedTabEvent;import org.executequery.base.DockedTabListener;import org.executequery.base.DockedTabView;import org.executequery.base.TabComponent;import org.executequery.util.Log;import org.underworldlabs.swing.GUIUtils;import org.underworldlabs.util.FileUtils;import org.underworldlabs.util.SystemProperties;import org.xml.sax.Attributes;import org.xml.sax.ContentHandler;import org.xml.sax.DTDHandler;import org.xml.sax.EntityResolver;import org.xml.sax.ErrorHandler;import org.xml.sax.InputSource;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;import org.xml.sax.XMLReader;import org.xml.sax.helpers.AttributesImpl;import org.xml.sax.helpers.DefaultHandler;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the  *           release of version 3.0.0beta1 has meant a  *           resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * * @author   Takis Diakoumis * @version  $Revision: 1.7 $ * @date     $Date: 2006/06/28 08:35:55 $ */public class UserLayoutProperties implements Serializable,                                             DockedTabDragListener,                                             DockedTabListener,                                             PropertyChangeListener {        /** layout prefs objects */    private static Map<String,UserLayoutObject> layoutObjects;        /** Creates a new instance of UserLayoutProperties */    public UserLayoutProperties() {        load();    }    /**     * Indicates a tab minimised event.     *     * @param the event      */    public void tabMinimised(DockedTabEvent e) {        TabComponent tc = (TabComponent)e.getSource();        if (tc == null) {            return;        }                Component c = tc.getComponent();        if (c instanceof DockedTabView) {            DockedTabView tabView = (DockedTabView)c;            String key = tabView.getPropertyKey();                        UserLayoutObject object = layoutObjects.get(key);            if (object == null) {                object = new UserLayoutObject(key);            }            object.setMinimised(true);            object.setVisible(true);            layoutObjects.put(key, object);            // save the layout options            persist();        }    }    /**     * Indicates a tab restored from minimised event.     *     * @param the event      */    public void tabRestored(DockedTabEvent e) {        TabComponent tc = (TabComponent)e.getSource();        if (tc == null) {            return;        }                Component c = tc.getComponent();        if (c instanceof DockedTabView) {            DockedTabView tabView = (DockedTabView)c;            String key = tabView.getPropertyKey();                        UserLayoutObject object = layoutObjects.get(key);            if (object == null) {                object = new UserLayoutObject(key);            }            object.setMinimised(false);            object.setVisible(true);            layoutObjects.put(key, object);            // save the layout options            persist();        }    }    /**     * Indicates a tab selected event.     *     * @param the event      */    public void tabSelected(DockedTabEvent e) {}    /**     * Indicates a tab deselected event.     *     * @param the event      */    public void tabDeselected(DockedTabEvent e) {}        /**     * Indicates a tab closed event.     *     * @param the event      */    public void tabClosed(DockedTabEvent e) {        TabComponent tc = (TabComponent)e.getSource();        if (tc == null) {            return;        }                Component c = tc.getComponent();        if (c instanceof DockedTabView) {            DockedTabView tabView = (DockedTabView)c;            String key = tabView.getPropertyKey();            setDockedPaneVisible(key, false);        }    }    /**     * Invoked when a mouse button is pressed on a tab and then dragged.     *     * @param the encapsulating event object     */    public void dockedTabDragged(DockedDragEvent e) {}     /**     *  Invoked when a mouse button has been released on a tab.     *     * @param the encapsulating event object     */    public void dockedTabReleased(DockedDragEvent e) {        TabComponent tc = e.getTabComponent();        if (tc == null) {            return;        }                Component c = tc.getComponent();        if (c instanceof DockedTabView) {            DockedTabView tabView = (DockedTabView)c;            String key = tabView.getPropertyKey();            UserLayoutObject object = layoutObjects.get(key);            if (object == null) {                object = new UserLayoutObject(key);            }                        int newIndex = e.getTabComponent().getIndex();            int position = e.getTabComponent().getPosition();            if (newIndex == object.getIndex() && position == object.getPosition()) {                return;            }            // store the old index            int oldIndex = object.getIndex();                        object.setPosition(position);            object.setIndex(newIndex);            object.setVisible(true);            // check existing object indexes for the same position            for (Iterator i = layoutObjects.keySet().iterator(); i.hasNext();) {                Object next = i.next();                if (next != null) {                    String _key = next.toString();                    if (!_key.equals(key)) {                        UserLayoutObject _object = layoutObjects.get(_key);                        if (_object.getPosition() == position) {                            int _index = _object.getIndex();                            if (oldIndex < newIndex) { // move right                                if (newIndex >= _index && _index > 0) {                                    _object.setIndex(_index - 1);                                }                            }                            else if (oldIndex > newIndex) { // move left                                if (newIndex <= _index) {                                    _object.setIndex(_index + 1);                                }                            }                        }                    }                }            }            layoutObjects.put(key, object);            // save the layout options            persist();        }    }    /** the layout sorter */    private static LayoutSorter layoutSorter;        public List<UserLayoutObject> getLayoutObjectsSorted() {        if (layoutObjects == null || layoutObjects.isEmpty()) {            return null;        }        int size = layoutObjects.size();                // place in temp list        List<UserLayoutObject> list = new ArrayList<UserLayoutObject>(size);                for (Iterator i = layoutObjects.keySet().iterator(); i.hasNext();) {            String key = i.next().toString();            list.add(layoutObjects.get(key));        }        if (layoutSorter == null) {            layoutSorter = new LayoutSorter();        }        Collections.sort(list, layoutSorter);        return list;    }        /**     * Property change implementation to record the movements     * of the divider locations on all panes. The new value is stored     * and saved in the user properties/preferences.     *     * @param the event     */    public void propertyChange(PropertyChangeEvent e) {        String name = e.getPropertyName();        int value = ((Integer)e.getNewValue()).intValue();        SystemProperties.setIntProperty("user", name, value);        GUIUtilities.updatePreferencesToFile();    }        /**     * Returns a map of layout definition objects.     *     * @return the user's saved layout definitions     */    public Map<String, UserLayoutObject> getLayoutObjects() {        if (layoutObjects == null) {            load();        }        return layoutObjects;    }    /**     * Persists the properties to file.<br>     * This method will simply call save() in a separate thread.     */    protected void persist() {        GUIUtils.startWorker(new Runnable() {            public void run() {                save();            }        });    }    /**      * Returns the position of the docked tab with the specified name.     *     * @return the tab position     */    public int getPosition(String key) {        UserLayoutObject object = layoutObjects.get(key);        if (object != null) {            return object.getPosition();        }        return -1;    }        /**     * Sets the visibility property of the docked tab with the specified name.     *     * @param true | false     */    public void setDockedPaneVisible(String key, boolean visible) {        setDockedPaneVisible(key, visible, true);    }    /**     * Sets the visibility property of the docked tab with the specified name.     *     * @param true | false     */    public void setDockedPaneVisible(String key, boolean visible, boolean save) {        UserLayoutObject object = layoutObjects.get(key);        if (object != null) {            object.setVisible(visible);            if (save) {                persist();            }

⌨️ 快捷键说明

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