Source Code Cross Referenced for FolderToolBar.java in  » Swing-Library » jide-common » com » jidesoft » plaf » basic » 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 » Swing Library » jide common » com.jidesoft.plaf.basic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)FolderToolBar.java 10/6/2005
003:         *
004:         * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005:         */
006:        package com.jidesoft.plaf.basic;
007:
008:        import com.jidesoft.utils.SystemInfo;
009:
010:        import javax.swing.*;
011:        import javax.swing.event.PopupMenuEvent;
012:        import javax.swing.event.PopupMenuListener;
013:        import javax.swing.filechooser.FileSystemView;
014:        import java.awt.*;
015:        import java.awt.event.ActionEvent;
016:        import java.io.File;
017:        import java.util.ArrayList;
018:        import java.util.List;
019:        import java.util.Locale;
020:        import java.util.ResourceBundle;
021:
022:        /**
023:         * Manages the optional folder toolbar that sits above the folderview's tree view panel
024:         */
025:        class FolderToolBar extends JToolBar {
026:            private final static FileSystemView _fsv = FileSystemView
027:                    .getFileSystemView();
028:
029:            private JButton _deleteFolderBtn;
030:            private JButton _newFolderBtn;
031:            private JComboBox _recentFoldersList;
032:
033:            private List<FolderToolBarListener> _listeners = new ArrayList(1);
034:
035:            public FolderToolBar(boolean showRecentFolders,
036:                    List<String> recentFoldersList) {
037:                setFloatable(false);
038:                setupToolBar(showRecentFolders, recentFoldersList);
039:
040:            }
041:
042:            public void enableDelete() {
043:                _deleteFolderBtn.setEnabled(true);
044:            }
045:
046:            public void disableDelete() {
047:                _deleteFolderBtn.setEnabled(false);
048:            }
049:
050:            public void enableNewFolder() {
051:                _newFolderBtn.setEnabled(true);
052:            }
053:
054:            public void disableNewFolder() {
055:                _newFolderBtn.setEnabled(false);
056:            }
057:
058:            /**
059:             * Creates the toolbar buttons and dropdown
060:             */
061:            private void setupToolBar(boolean showRecentFolders,
062:                    List<String> recentFoldersList) {
063:
064:                // add to toolbar
065:                if (showRecentFolders) {
066:                    _recentFoldersList = new JComboBox(
067:                            new DefaultComboBoxModel());
068:                    if (recentFoldersList != null
069:                            && recentFoldersList.size() > 0) {
070:                        _recentFoldersList.setModel(new DefaultComboBoxModel(
071:                                (recentFoldersList.toArray())));
072:                    }
073:                    _recentFoldersList.setEditable(false);
074:                    _recentFoldersList.setRenderer(new FileListCellRenderer());
075:                    _recentFoldersList
076:                            .addPopupMenuListener(new PopupMenuListener() {
077:                                private boolean m_wasCancelled = false;
078:
079:                                public void popupMenuWillBecomeVisible(
080:                                        PopupMenuEvent e) {
081:                                    m_wasCancelled = false;
082:                                }
083:
084:                                public void popupMenuWillBecomeInvisible(
085:                                        PopupMenuEvent e) {
086:                                    if (e.getSource() instanceof  JComboBox) {
087:                                        JComboBox box = (JComboBox) e
088:                                                .getSource();
089:
090:                                        Object selectedFile = box.getModel()
091:                                                .getSelectedItem();
092:                                        // if popup was not cancelled then select the folder
093:                                        if (!m_wasCancelled
094:                                                && selectedFile != null) {
095:                                            //                            System.out.println("User selected file: " + selectedFile.getAbsolutePath());
096:                                            if (selectedFile instanceof  File) {
097:                                                recentFolderSelected((File) selectedFile);
098:                                            } else {
099:                                                recentFolderSelected(new File(
100:                                                        "" + selectedFile));
101:                                            }
102:                                        }
103:                                    }
104:                                }
105:
106:                                public void popupMenuCanceled(PopupMenuEvent e) {
107:                                    m_wasCancelled = true;
108:                                }
109:                            });
110:                    _recentFoldersList
111:                            .setPrototypeDisplayValue("AAAAAAAAAAAAAAAAAA");
112:                    add(new JLabel("Recent: "));
113:                    add(_recentFoldersList);
114:                    addSeparator();
115:                } else {
116:                    add(Box.createHorizontalGlue());
117:                }
118:
119:                JButton desktopBtn = new NoFocusButton(
120:                        new ToolBarAction(
121:                                null,
122:                                SystemInfo.isWindows() ? _fsv
123:                                        .getSystemIcon(_fsv.getHomeDirectory())
124:                                        : BasicFolderChooserIconsFactory
125:                                                .getImageIcon(BasicFolderChooserIconsFactory.ToolBar.HOME)) {
126:                            public void actionPerformed(ActionEvent e) {
127:                                desktopButtonClicked();
128:                            }
129:                        });
130:
131:                final ResourceBundle resourceBundle = FolderChooserResource
132:                        .getResourceBundle(Locale.getDefault());
133:                desktopBtn
134:                        .setToolTipText(SystemInfo.isWindows() ? resourceBundle
135:                                .getString("FolderChooser.toolbar.desktop")
136:                                : resourceBundle
137:                                        .getString("FolderChooser.toolbar.home"));
138:                add(desktopBtn);
139:
140:                if (SystemInfo.isWindows()) {
141:                    JButton myDocumentsBtn = new NoFocusButton(
142:                            new ToolBarAction(null, _fsv.getSystemIcon(_fsv
143:                                    .getDefaultDirectory())) {
144:                                public void actionPerformed(ActionEvent e) {
145:                                    myDocumentsButtonClicked();
146:                                }
147:                            });
148:                    myDocumentsBtn.setToolTipText(resourceBundle
149:                            .getString("FolderChooser.toolbar.mydocuments"));
150:                    add(myDocumentsBtn);
151:                }
152:                // dredge up appropriate icons
153:                Icon deleteIcon = BasicFolderChooserIconsFactory
154:                        .getImageIcon(BasicFolderChooserIconsFactory.ToolBar.DELETE);
155:
156:                _deleteFolderBtn = new NoFocusButton(new ToolBarAction(null,
157:                        deleteIcon) {
158:                    public void actionPerformed(ActionEvent e) {
159:                        deleteFolderButtonClicked();
160:                    }
161:                });
162:
163:                _deleteFolderBtn.setToolTipText(resourceBundle
164:                        .getString("FolderChooser.toolbar.delete"));
165:
166:                Icon newFolderIcon = BasicFolderChooserIconsFactory
167:                        .getImageIcon(BasicFolderChooserIconsFactory.ToolBar.NEW);
168:                _newFolderBtn = new NoFocusButton(new ToolBarAction(null,
169:                        newFolderIcon) {
170:                    public void actionPerformed(ActionEvent e) {
171:                        newFolderButtonClicked();
172:                    }
173:                });
174:
175:                _newFolderBtn.setToolTipText(resourceBundle
176:                        .getString("FolderChooser.toolbar.new"));
177:
178:                addSeparator();
179:                add(_deleteFolderBtn);
180:                add(_newFolderBtn);
181:            }
182:
183:            private class FileListCellRenderer implements  ListCellRenderer {
184:                protected DefaultListCellRenderer m_defaultRenderer = new DefaultListCellRenderer();
185:
186:                public Component getListCellRendererComponent(JList list,
187:                        Object value, int index, boolean isSelected,
188:                        boolean cellHasFocus) {
189:                    JLabel renderer = (JLabel) m_defaultRenderer
190:                            .getListCellRendererComponent(list, value, index,
191:                                    isSelected, cellHasFocus);
192:                    File f = null;
193:                    if (value instanceof  File) {
194:                        f = (File) value;
195:                    } else if (value != null) {
196:                        f = new File(value.toString());
197:                    }
198:
199:                    if (f != null && f.exists()) {
200:                        String text = _fsv.getSystemDisplayName(f);
201:                        Icon icon = _fsv.getSystemIcon(f);
202:                        renderer.setIcon(icon);
203:                        renderer.setText(text);
204:                        renderer.setToolTipText(f.getAbsolutePath());
205:                    } else {
206:                        String filePath = value == null ? "" : value.toString();
207:                        renderer.setText(filePath);
208:                        renderer.setToolTipText(filePath);
209:                    }
210:                    return renderer;
211:                }
212:            }
213:
214:            // ----------------------------------------------------------------
215:            // Listener methods
216:            // ----------------------------------------------------------------
217:            public void addListener(FolderToolBarListener listener) {
218:                _listeners.add(listener);
219:            }
220:
221:            public void removeListener(FolderToolBarListener listener) {
222:                _listeners.remove(listener);
223:            }
224:
225:            public void clearListeners() {
226:                _listeners.clear();
227:            }
228:
229:            private void deleteFolderButtonClicked() {
230:                for (FolderToolBarListener listener : _listeners) {
231:                    listener.deleteFolderButtonClicked();
232:                }
233:            }
234:
235:            private void newFolderButtonClicked() {
236:                for (FolderToolBarListener listener : _listeners) {
237:                    listener.newFolderButtonClicked();
238:                }
239:            }
240:
241:            private void myDocumentsButtonClicked() {
242:                for (FolderToolBarListener listener : _listeners) {
243:                    listener.myDocumentsButtonClicked();
244:                }
245:            }
246:
247:            private void desktopButtonClicked() {
248:                for (FolderToolBarListener listener : _listeners) {
249:                    listener.desktopButtonClicked();
250:                }
251:            }
252:
253:            private void recentFolderSelected(File recentFolder) {
254:                for (FolderToolBarListener listener : _listeners) {
255:                    listener.recentFolderSelected(recentFolder);
256:                }
257:            }
258:
259:            public void setRecentList(List<String> recentFoldersList) {
260:                _recentFoldersList.setModel(new DefaultComboBoxModel(
261:                        (recentFoldersList.toArray())));
262:            }
263:
264:            private abstract class ToolBarAction extends AbstractAction {
265:                public ToolBarAction(String name, Icon icon) {
266:                    super (name, icon);
267:                }
268:            }
269:
270:            static class NoFocusButton extends JButton {
271:                public NoFocusButton(Action a) {
272:                    super (a);
273:                    setRequestFocusEnabled(false);
274:                    setFocusable(false);
275:
276:                    // on jdk1.6, the button size is wrong
277:                    Insets margin = getMargin();
278:                    margin.left = margin.top;
279:                    margin.right = margin.bottom;
280:                    setMargin(margin);
281:                }
282:            }
283:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.