Source Code Cross Referenced for BrowserSelectorFrame.java in  » Search-Engine » regain » net » sf » regain » ui » desktop » 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 » Search Engine » regain » net.sf.regain.ui.desktop 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * regain - A file search engine providing plenty of formats
003:         * Copyright (C) 2004  Til Schneider
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         *
019:         * Contact: Til Schneider, info@murfman.de
020:         *
021:         * CVS information:
022:         *  $RCSfile$
023:         *   $Source$
024:         *     $Date: 2005-08-04 15:52:50 +0200 (Do, 04 Aug 2005) $
025:         *   $Author: til132 $
026:         * $Revision: 143 $
027:         */
028:        package net.sf.regain.ui.desktop;
029:
030:        import java.awt.BorderLayout;
031:        import java.awt.Dimension;
032:        import java.awt.Point;
033:        import java.awt.Toolkit;
034:        import java.beans.PropertyChangeEvent;
035:        import java.beans.PropertyChangeListener;
036:        import java.io.File;
037:
038:        import javax.swing.JFileChooser;
039:        import javax.swing.JFrame;
040:        import javax.swing.JOptionPane;
041:        import javax.swing.JPanel;
042:
043:        import org.apache.log4j.Logger;
044:        import org.w3c.dom.Document;
045:        import org.w3c.dom.Element;
046:        import org.w3c.dom.Node;
047:
048:        import net.sf.regain.RegainException;
049:        import net.sf.regain.XmlToolkit;
050:        import net.sf.regain.util.io.Localizer;
051:
052:        /**
053:         * Shows a frame that asks the user to select a browser.
054:         * 
055:         * @author Til Schneider, www.murfman.de
056:         */
057:        public class BrowserSelectorFrame implements  DesktopConstants {
058:
059:            /** The logger for this class */
060:            private static Logger mLog = Logger
061:                    .getLogger(BrowserSelectorFrame.class);
062:
063:            /** The localizer for this class. */
064:            private static Localizer mLocalizer = new Localizer(
065:                    BrowserSelectorFrame.class);
066:
067:            /** The frame. */
068:            private JFrame mFrame;
069:
070:            /** Option pane that contains the message. */
071:            private JOptionPane mOptionPane;
072:
073:            /** The page to open when a browser was chosen. */
074:            private String mPageUrl;
075:
076:            /**
077:             * Creates a new instance of BrowserSelectorFrame.
078:             * 
079:             * @param pageUrl The page to open when a browser was chosen.
080:             */
081:            public BrowserSelectorFrame(String pageUrl) {
082:                mPageUrl = pageUrl;
083:
084:                String msg = mLocalizer.msg("error.title", "Error");
085:                mFrame = new JFrame(msg);
086:
087:                JPanel main = new JPanel(new BorderLayout());
088:                mFrame.setContentPane(main);
089:
090:                msg = mLocalizer
091:                        .msg("error.message",
092:                                "No browser found.\n\nDo you want to choose a browser now?");
093:                mOptionPane = new JOptionPane(msg, JOptionPane.ERROR_MESSAGE,
094:                        JOptionPane.YES_NO_OPTION);
095:                mOptionPane
096:                        .addPropertyChangeListener(new PropertyChangeListener() {
097:                            public void propertyChange(PropertyChangeEvent evt) {
098:                                if (evt.getPropertyName().equals(
099:                                        JOptionPane.VALUE_PROPERTY)
100:                                        && evt.getNewValue() != null
101:                                        && evt.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
102:                                    handleOptionPaneChanged();
103:                                }
104:                            }
105:                        });
106:                mFrame.setContentPane(mOptionPane);
107:
108:                mFrame.pack();
109:            }
110:
111:            /**
112:             * Handles a changed value. Called when yes or no was pressed.
113:             */
114:            void handleOptionPaneChanged() {
115:                int option = ((Integer) mOptionPane.getValue()).intValue();
116:
117:                if (option == 0) {
118:                    // Yes
119:                    try {
120:                        chooseBrowser();
121:                    } catch (RegainException exc) {
122:                        mLog.error("Choosing browser failed", exc);
123:                    }
124:
125:                    mFrame.dispose();
126:                } else if (option == 1) {
127:                    // No
128:                    mFrame.dispose();
129:                }
130:            }
131:
132:            /**
133:             * Centers and shows the frame.
134:             */
135:            public void show() {
136:                // Center the frame
137:                Dimension screenSize = Toolkit.getDefaultToolkit()
138:                        .getScreenSize();
139:                Dimension wD = mFrame.getSize();
140:                Point wPos = new Point((screenSize.width - wD.width) / 2,
141:                        (screenSize.height - wD.height) / 2);
142:                wPos.x = Math.max(0, wPos.x); // Make x > 0
143:                wPos.y = Math.max(0, wPos.y); // Make y > 0
144:                mFrame.setLocation(wPos);
145:
146:                // Show the frame
147:                mFrame.show();
148:            }
149:
150:            /**
151:             * Chooses the browser.
152:             * 
153:             * @throws RegainException If saving the config failed.
154:             */
155:            private void chooseBrowser() throws RegainException {
156:                JFileChooser fileChooser = new JFileChooser();
157:
158:                String msg = mLocalizer.msg("chooseBrowser", "Choose browser");
159:                fileChooser.setDialogTitle(msg);
160:                fileChooser.showOpenDialog(mFrame);
161:
162:                File file = fileChooser.getSelectedFile();
163:                if (file != null) {
164:                    Document desktopDoc = XmlToolkit
165:                            .loadXmlDocument(DESKTOP_CONFIG_FILE);
166:                    Element desktopConfig = desktopDoc.getDocumentElement();
167:
168:                    // Set the browser
169:                    Node browserNode = XmlToolkit.getOrAddChild(desktopDoc,
170:                            desktopConfig, "browser");
171:                    XmlToolkit.setText(desktopDoc, browserNode, file
172:                            .getAbsolutePath());
173:
174:                    // Save the config
175:                    XmlToolkit.saveXmlDocument(DESKTOP_CONFIG_FILE, desktopDoc);
176:
177:                    DesktopToolkit.openPageInBrowser(mPageUrl);
178:                }
179:            }
180:
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.