Source Code Cross Referenced for BaseListInternalFrame.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » client » gui » db » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.client.gui.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.client.gui.db;
002:
003:        /*
004:         * Copyright (C) 2001-2004 Colin Bell
005:         * colbell@users.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:        import java.awt.BorderLayout;
022:        import java.awt.Container;
023:        import java.awt.Dimension;
024:        import java.awt.event.MouseAdapter;
025:        import java.awt.event.MouseEvent;
026:
027:        import javax.swing.JList;
028:        import javax.swing.JScrollPane;
029:        import javax.swing.event.InternalFrameAdapter;
030:        import javax.swing.event.InternalFrameEvent;
031:        import javax.swing.event.ListDataEvent;
032:        import javax.swing.event.ListDataListener;
033:
034:        import net.sourceforge.squirrel_sql.fw.gui.BasePopupMenu;
035:        import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
036:        import net.sourceforge.squirrel_sql.fw.gui.ToolBar;
037:        import net.sourceforge.squirrel_sql.fw.util.BaseException;
038:        import net.sourceforge.squirrel_sql.fw.util.ICommand;
039:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
040:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
041:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
042:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
043:
044:        import net.sourceforge.squirrel_sql.client.gui.BaseInternalFrame;
045:
046:        abstract class BaseListInternalFrame extends BaseInternalFrame {
047:            protected interface IUserInterfaceFactory {
048:                ToolBar getToolBar();
049:
050:                BasePopupMenu getPopupMenu();
051:
052:                JList getList();
053:
054:                String getWindowTitle();
055:
056:                ICommand getDoubleClickCommand();
057:
058:                void enableDisableActions();
059:            }
060:
061:            /** Logger for this class. */
062:            private static ILogger s_log = LoggerController
063:                    .createLogger(BaseListInternalFrame.class);
064:
065:            private IUserInterfaceFactory _uiFactory;
066:
067:            /** Popup menu for the list. */
068:            private BasePopupMenu _popupMenu;
069:
070:            /** Toolbar for window. */
071:            private ToolBar _toolBar;
072:
073:            private boolean _hasBeenBuilt;
074:
075:            private boolean _hasBeenSized = false;
076:
077:            /** Internationalized strings for this class. */
078:            private static final StringManager s_stringMgr = StringManagerFactory
079:                    .getStringManager(BaseListInternalFrame.class);
080:
081:            public BaseListInternalFrame(IUserInterfaceFactory uiFactory) {
082:                super ("", true, true);
083:                if (uiFactory == null) {
084:                    throw new IllegalArgumentException(
085:                            "Null IUserInterfaceFactory passed");
086:                }
087:                _uiFactory = uiFactory;
088:
089:                createUserInterface();
090:            }
091:
092:            public void updateUI() {
093:                super .updateUI();
094:                if (_hasBeenBuilt) {
095:                    _hasBeenSized = false;
096:                    privateResize();
097:                }
098:            }
099:
100:            protected IUserInterfaceFactory getUserInterfaceFactory() {
101:                return _uiFactory;
102:            }
103:
104:            protected void setToolBar(ToolBar tb) {
105:                final Container content = getContentPane();
106:                if (_toolBar != null) {
107:                    content.remove(_toolBar);
108:                }
109:                if (tb != null) {
110:                    content.add(tb, BorderLayout.NORTH);
111:                }
112:                _toolBar = tb;
113:            }
114:
115:            /**
116:             * Process a mouse press event in this list. If this event is a trigger
117:             * for a popup menu then display the popup menu.
118:             *
119:             * @param	evt	 The mouse event being processed.
120:             */
121:            private void mousePress(MouseEvent evt) {
122:                if (evt.isPopupTrigger()) {
123:                    if (_popupMenu == null) {
124:                        _popupMenu = _uiFactory.getPopupMenu();
125:                    }
126:                    _popupMenu.show(evt);
127:                }
128:            }
129:
130:            private void privateResize() {
131:                if (!_hasBeenSized) {
132:                    if (_toolBar != null) {
133:                        _hasBeenSized = true;
134:                        Dimension windowSize = getSize();
135:                        int rqdWidth = _toolBar.getPreferredSize().width + 15;
136:                        if (rqdWidth > windowSize.width) {
137:                            windowSize.width = rqdWidth;
138:                            setSize(windowSize);
139:                        }
140:                    }
141:                }
142:            }
143:
144:            private void createUserInterface() {
145:                // This is a tool window.
146:                GUIUtils.makeToolWindow(this , true);
147:
148:                setDefaultCloseOperation(HIDE_ON_CLOSE);
149:
150:                // Pane to add window content to.
151:                final Container content = getContentPane();
152:                content.setLayout(new BorderLayout());
153:
154:                String winTitle = _uiFactory.getWindowTitle();
155:                if (winTitle != null) {
156:                    setTitle(winTitle);
157:                }
158:
159:                // Put toolbar at top of window.
160:                setToolBar(_uiFactory.getToolBar());
161:
162:                // The main list for window.
163:                final JList list = _uiFactory.getList();
164:
165:                // Allow list to scroll.
166:                final JScrollPane sp = new JScrollPane();
167:                sp.setViewportView(list);
168:                sp.setPreferredSize(new Dimension(100, 100));
169:
170:                // List in the centre of the window.
171:                content.add(sp, BorderLayout.CENTER);
172:
173:                // Add mouse listener for displaying popup menu.
174:                list.addMouseListener(new MouseAdapter() {
175:                    public void mousePressed(MouseEvent evt) {
176:                        mousePress(evt);
177:                    }
178:
179:                    public void mouseReleased(MouseEvent evt) {
180:                        mousePress(evt);
181:                    }
182:                });
183:
184:                // Add a listener to handle doubleclick events in the list.
185:                list.addMouseListener(new MouseAdapter() {
186:                    public void mouseClicked(MouseEvent evt) {
187:                        if (evt.getClickCount() == 2) {
188:                            ICommand cmd = _uiFactory.getDoubleClickCommand();
189:                            if (cmd != null) {
190:                                try {
191:                                    cmd.execute();
192:                                } catch (BaseException ex) {
193:                                    // i18n[BaseListInternalFrame.error.execdoubleclick=Error occured executing doubleclick event]
194:                                    s_log
195:                                            .error(
196:                                                    s_stringMgr
197:                                                            .getString("BaseListInternalFrame.error.execdoubleclick"),
198:                                                    ex);
199:                                }
200:                            }
201:                        }
202:                    }
203:                });
204:
205:                // Add listener to listen for items added/removed from list.
206:                list.getModel().addListDataListener(new ListDataListener() {
207:                    public void intervalAdded(ListDataEvent evt) {
208:                        list.setSelectedIndex(evt.getIndex0()); // select the one just added.
209:                        _uiFactory.enableDisableActions();
210:                    }
211:
212:                    public void intervalRemoved(ListDataEvent evt) {
213:                        int nextIdx = evt.getIndex0();
214:                        int lastIdx = list.getModel().getSize() - 1;
215:                        if (nextIdx > lastIdx) {
216:                            nextIdx = lastIdx;
217:                        }
218:                        list.setSelectedIndex(nextIdx);
219:                        _uiFactory.enableDisableActions();
220:                    }
221:
222:                    public void contentsChanged(ListDataEvent evt) {
223:                        // Unused.
224:                    }
225:                });
226:
227:                // When window opened ensure it is wide enough to display the toolbar.
228:                // There is a bug in JDK1.2 where internalFrameOpened() doesn't get
229:                // called so we've used a workaround. The workaround doesn't work in
230:                // JDK1.3.
231:                addInternalFrameListener(new InternalFrameAdapter() {
232:                    //private boolean _hasBeenActivated = false;
233:                    //public void internalFrameActivated(InternalFrameEvent evt)
234:                    //{
235:                    //if (!_hasBeenActivated)
236:                    //{
237:                    ////	_hasBeenActivated = true;
238:                    //	privateResize();
239:                    //}
240:                    //list.requestFocus();
241:                    //}
242:
243:                    public void internalFrameOpened(InternalFrameEvent evt) {
244:                        privateResize();
245:                    }
246:
247:                });
248:
249:                validate();
250:
251:            }
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.