Source Code Cross Referenced for DAVFileChooser.java in  » Net » SkunkDAV » org » skunk » dav » client » gui » 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 » Net » SkunkDAV » org.skunk.dav.client.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright (c) 2000, Jacob Smullyan.
003:         *
004:         *  This is part of SkunkDAV, a WebDAV client.  See http://skunkdav.sourceforge.net/ 
005:         *  for the latest version.
006:         * 
007:         *  SkunkDAV is free software; you can redistribute it and/or
008:         *  modify it under the terms of the GNU General Public License as published
009:         *  by the Free Software Foundation; either version 2, or (at your option)
010:         *  any later version.
011:         * 
012:         *  SkunkDAV  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:         *  General Public License for more details.
016:         * 
017:         *  You should have received a copy of the GNU General Public License
018:         *  along with SkunkDAV; see the file COPYING.  If not, write to the Free
019:         *  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020:         *  02111-1307, USA.
021:         */
022:
023:        package org.skunk.dav.client.gui;
024:
025:        import java.awt.Component;
026:        import java.awt.Font;
027:        import java.awt.FontMetrics;
028:        import java.util.StringTokenizer;
029:        import javax.swing.DefaultListCellRenderer;
030:        import javax.swing.JList;
031:        import org.skunk.dav.client.DAVConstants;
032:        import org.skunk.swing.TreeNodeChooser;
033:        import org.skunk.trace.Debug;
034:
035:        //for test
036:        import javax.swing.tree.DefaultMutableTreeNode;
037:        import javax.swing.tree.TreeNode;
038:        import javax.swing.tree.TreePath;
039:        import javax.swing.JOptionPane;
040:        import org.skunk.config.Configurator;
041:        import org.skunk.config.InMemoryConfigStore;
042:
043:        public class DAVFileChooser extends TreeNodeChooser {
044:            //this shouldn't be hard-coded -- TO BE DONE
045:            private int maximumLabelLength = 320;
046:
047:            public DAVFileChooser(DAVTreeModel model) {
048:                super (model);
049:                setRootVisible(false);
050:                setNodeSeparator(DAVConstants.DAV_FILE_SEPARATOR);
051:                setComboBoxCellRenderer(new DAVFileComboRenderer());
052:            }
053:
054:            protected int getMaximumLabelLength() {
055:                return maximumLabelLength;
056:            }
057:
058:            protected void setMaximumLabelLength(int maximumLabelLength) {
059:                this .maximumLabelLength = maximumLabelLength;
060:            }
061:
062:            private class DAVFileComboRenderer extends DefaultListCellRenderer {
063:                public Component getListCellRendererComponent(JList list,
064:                        Object value, int index, boolean isSelected,
065:                        boolean cellHasFocus) {
066:                    String formattedValue = format(value).toString();
067:                    Component c = super .getListCellRendererComponent(list,
068:                            formattedValue, index, isSelected, cellHasFocus);
069:                    //Debug.trace(this, Debug.DP5, "renderer preferred size: "+c.getPreferredSize());
070:                    Font daFont = c.getFont();
071:                    FontMetrics daMetrics = c.getFontMetrics(daFont);
072:                    int diff = daMetrics.stringWidth(formattedValue)
073:                            - maximumLabelLength;
074:                    if (diff >= 0) {
075:                        int garbage = 1; //trash this many tokens
076:                        while (diff >= 0) {
077:                            StringBuffer formatBuffer = new StringBuffer(".../");
078:                            StringTokenizer st = new StringTokenizer(
079:                                    formattedValue,
080:                                    DAVConstants.DAV_FILE_SEPARATOR);
081:                            for (int i = 0; st.hasMoreTokens(); i++) {
082:                                String thing = st.nextToken();
083:                                if (i <= garbage)
084:                                    continue;
085:                                formatBuffer.append(thing).append(
086:                                        DAVConstants.DAV_FILE_SEPARATOR);
087:                            }
088:                            garbage++;
089:                            formattedValue = formatBuffer.toString();
090:                            diff = daMetrics.stringWidth(formattedValue)
091:                                    - maximumLabelLength;
092:                        }
093:                        return super 
094:                                .getListCellRendererComponent(list,
095:                                        formattedValue, index, isSelected,
096:                                        cellHasFocus);
097:                    }
098:                    return c;
099:                }
100:
101:                private Object format(Object value) {
102:                    if (value instanceof  DAVTreeNode)
103:                        return ((DAVTreeNode) value).getDAVFile().getFullName();
104:                    if (value == null)
105:                        return "";
106:                    return value;
107:                }
108:            }
109:
110:            public ChoiceStruct getChoiceStruct() {
111:                Object lastPathComponent = getSelectedPath()
112:                        .getLastPathComponent();
113:                if (lastPathComponent == null
114:                        || !(lastPathComponent instanceof  DAVTreeNode)) {
115:                    return null;
116:                }
117:                DAVTreeNode parentNode = (DAVTreeNode) lastPathComponent;
118:                Object leafNode = getSelectedLeaf();
119:
120:                return new ChoiceStruct(
121:                        parentNode,
122:                        getEntryFieldText(),
123:                        ((leafNode != null && leafNode instanceof  DAVTreeNode) ? (DAVTreeNode) leafNode
124:                                : null));
125:            }
126:
127:            public static class ChoiceStruct {
128:                private DAVTreeNode parentNode;
129:                private String entryText;
130:                private DAVTreeNode selectedLeaf;
131:                private String newPath;
132:
133:                private ChoiceStruct(DAVTreeNode parentNode, String entryText,
134:                        DAVTreeNode selectedLeaf) {
135:                    this .parentNode = parentNode;
136:                    this .entryText = entryText;
137:                    this .selectedLeaf = selectedLeaf;
138:                    setNewPath();
139:                }
140:
141:                public DAVTreeNode getParentNode() {
142:                    return this .parentNode;
143:                }
144:
145:                public void setParentNode(DAVTreeNode parentNode) {
146:                    this .parentNode = parentNode;
147:                }
148:
149:                public String getFilename() {
150:                    return this .entryText;
151:                }
152:
153:                public String getFilePath() {
154:                    return this .newPath;
155:                }
156:
157:                public DAVTreeNode getSelectedLeaf() {
158:                    return this .selectedLeaf;
159:                }
160:
161:                private void setNewPath() {
162:                    if (parentNode != null) {
163:                        StringBuffer sb = new StringBuffer(parentNode
164:                                .getDAVFile().getFullName());
165:                        if (entryText != null)
166:                            sb.append(entryText);
167:                        newPath = sb.toString();
168:                    } else
169:                        newPath = null;
170:                }
171:
172:            }
173:
174:            public static class Test {
175:                public static void main(String[] args) {
176:                    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(
177:                            "oink");
178:                    DAVTreeModel model = new DAVTreeModel(rootNode, true);
179:                    //throwaway configurator, just to get the ServerData class not to barf
180:                    Configurator.setConfigurator(new Configurator(
181:                            new InMemoryConfigStore()));
182:                    ServerData sd = new ServerData("support.skunk.org", 8888,
183:                            "/", "jsmullyan", "");
184:                    model.addConnectionNode(sd, null);
185:                    //let it load
186:                    while (model.getChildCount(rootNode) < 1) {
187:                        try {
188:                            Thread.sleep(333);
189:                        } catch (InterruptedException ie) {
190:                        }
191:                    }
192:                    DAVFileChooser chooser = new DAVFileChooser(model);
193:                    if (args.length > 0 && args[0].equals("visible"))
194:                        chooser.setRootVisible(true);
195:                    chooser.setCurrentPath(new TreePath(model
196:                            .getPathToRoot((TreeNode) model.getChild(rootNode,
197:                                    0))));
198:                    JOptionPane.showMessageDialog(null, chooser);
199:                    System.exit(0);
200:                }
201:            }
202:        }
203:
204:        /* $Log: DAVFileChooser.java,v $
205:         /* Revision 1.3  2001/06/05 01:09:53  smulloni
206:         /* fixed bug wtih failed connection attempts, which used to set the
207:         /* connection flag as if the connection had succeeded.
208:         /*
209:         /* Revision 1.2  2001/01/03 20:11:31  smulloni
210:         /* the DAVFileChooser now replaces JFileChooser for remote file access.
211:         /* DAVMethod now has a protocol property.
212:         /*
213:         /* Revision 1.1  2001/01/03 00:30:35  smulloni
214:         /* a number of modifications along the way to replacing JFileChooser with
215:         /* something more suitable for remote (virtual) files.
216:         /* */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.