Source Code Cross Referenced for JDK13GruntspudHost.java in  » Source-Control » gruntspud » gruntspud » standalone » 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 » Source Control » gruntspud » gruntspud.standalone 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Gruntspud
0003:         * 
0004:         * Copyright (C) 2002 Brett Smith.
0005:         * 
0006:         * Written by: Brett Smith <t_magicthize@users.sourceforge.net>
0007:         * 
0008:         * This program is free software; you can redistribute it and/or modify it under
0009:         * the terms of the GNU Library General Public License as published by the Free
0010:         * Software Foundation; either version 2 of the License, or (at your option) any
0011:         * later version. This program is distributed in the hope that it will be
0012:         * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
0014:         * General Public License for more details.
0015:         * 
0016:         * You should have received a copy of the GNU Library General Public License
0017:         * along with this program; if not, write to the Free Software Foundation, Inc.,
0018:         * 675 Mass Ave, Cambridge, MA 02139, USA.
0019:         */
0020:        package gruntspud.standalone;
0021:
0022:        import gruntspud.CVSFileNode;
0023:        import gruntspud.CVSSubstType;
0024:        import gruntspud.CVSUtil;
0025:        import gruntspud.Constants;
0026:        import gruntspud.Gruntspud;
0027:        import gruntspud.GruntspudContext;
0028:        import gruntspud.GruntspudHost;
0029:        import gruntspud.GruntspudUtil;
0030:        import gruntspud.VersionInfo;
0031:        import gruntspud.actions.GruntspudAction;
0032:        import gruntspud.connection.ConnectionProfile;
0033:        import gruntspud.connection.ConnectionProfileModel;
0034:        import gruntspud.style.TextStyle;
0035:        import gruntspud.ui.BrowserLauncher;
0036:        import gruntspud.ui.FolderBar;
0037:        import gruntspud.ui.OptionDialog;
0038:        import gruntspud.ui.OptionsTab;
0039:        import gruntspud.ui.ScrollingPanel;
0040:        import gruntspud.ui.Tab;
0041:        import gruntspud.ui.UIUtil;
0042:        import gruntspud.ui.icons.IconResource;
0043:        import gruntspud.ui.view.View;
0044:        import gruntspud.ui.view.ViewEvent;
0045:        import gruntspud.ui.view.ViewListener;
0046:        import gruntspud.ui.view.ViewManager;
0047:        import java.awt.BorderLayout;
0048:        import java.awt.CardLayout;
0049:        import java.awt.Color;
0050:        import java.awt.Dimension;
0051:        import java.awt.Frame;
0052:        import java.awt.GridLayout;
0053:        import java.awt.Insets;
0054:        import java.awt.Toolkit;
0055:        import java.awt.Window;
0056:        import java.awt.event.ActionEvent;
0057:        import java.awt.event.WindowAdapter;
0058:        import java.awt.event.WindowEvent;
0059:        import java.io.File;
0060:        import java.io.FileInputStream;
0061:        import java.io.FileOutputStream;
0062:        import java.io.IOException;
0063:        import java.io.InputStream;
0064:        import java.lang.reflect.Method;
0065:        import java.net.URL;
0066:        import java.security.CodeSource;
0067:        import java.security.Permission;
0068:        import java.security.PermissionCollection;
0069:        import java.security.Policy;
0070:        import java.security.ProtectionDomain;
0071:        import java.util.Enumeration;
0072:        import java.util.Iterator;
0073:        import java.util.Properties;
0074:        import java.util.StringTokenizer;
0075:        import java.util.Vector;
0076:        import javax.help.HelpSet;
0077:        import javax.help.HelpSetException;
0078:        import javax.help.JHelp;
0079:        import javax.swing.AbstractAction;
0080:        import javax.swing.Action;
0081:        import javax.swing.BorderFactory;
0082:        import javax.swing.Icon;
0083:        import javax.swing.ImageIcon;
0084:        import javax.swing.JComponent;
0085:        import javax.swing.JDialog;
0086:        import javax.swing.JFrame;
0087:        import javax.swing.JOptionPane;
0088:        import javax.swing.JPanel;
0089:        import javax.swing.LookAndFeel;
0090:        import javax.swing.SwingConstants;
0091:        import javax.swing.SwingUtilities;
0092:        import javax.swing.UIManager;
0093:        import org.apache.log4j.BasicConfigurator;
0094:        import org.apache.log4j.Level;
0095:        import org.apache.log4j.Logger;
0096:        import org.apache.log4j.PropertyConfigurator;
0097:        import org.netbeans.lib.cvsclient.file.FileStatus;
0098:
0099:        /**
0100:         * Description of the Class
0101:         * 
0102:         * @author magicthize
0103:         */
0104:        public class JDK13GruntspudHost extends JFrame implements 
0105:                GruntspudHost, ViewListener {
0106:            ///
0107:            private static UIManager.LookAndFeelInfo[] allLookAndFeelInfo;
0108:
0109:            public final static Insets FILE_RENDERER_INSETS = new Insets(1, 0,
0110:                    0, 0);
0111:
0112:            //  Icons specfic to standalone
0113:            public final static String ICON_TOOL_LARGE_TIPS = "icon.tool.largeTips";
0114:
0115:            public final static String ICON_TOOL_LARGE_INDEX = "icon.tool.largeIndex";
0116:
0117:            public final static String ICON_TOOL_LARGE_CONTENTS = "icon.tool.largeContents";
0118:
0119:            public final static String ICON_TOOL_INDEX = "icon.tool.index";
0120:
0121:            public final static String ICON_TOOL_CONTENTS = "icon.tool.contents";
0122:
0123:            public final static String ICON_TOOL_SMALL_INDEX = "icon.tool.smallIndex";
0124:
0125:            public final static String ICON_TOOL_SMALL_CONTENTS = "icon.tool.smallContents";
0126:
0127:            //  Properties specific to standalone
0128:            public final static String PROP_LAF = "gruntspudSA.laf";
0129:
0130:            public final static String PROP_GEOMETRY = "gruntspudSA.geometry";
0131:
0132:            public final static String PROP_EDITOR_FONT = "gruntspudSA.editor.font";
0133:
0134:            public final static String PROP_EDITOR_WORD_WRAP = "gruntspudSA.editor.wordWrap";
0135:
0136:            public final static String PROP_HELP_DIVIDER_LOCATION = "gruntspudSA.helpDividerLocation";
0137:
0138:            public final static String PROP_HELP_GEOMETRY = "gruntspudSA.helpGeometry";
0139:
0140:            public final static String PROP_USE_INTERNAL_HTML_VIEWER = "gruntspudSA.useInternalHTMLViewer";
0141:
0142:            public final static String PROP_HTML_VIEWER_GEOMETRY = "gruntspudSA.htmlViewerGeometry";
0143:
0144:            public final static String PROP_HTML_VIEWER_SINGLE_INSTANCE = "gruntspudSA.htmlViewerSingleInstance";
0145:
0146:            public final static String PROP_DOCK_EDITOR_AS_TAB = "gruntspudSA.dockEditorAsTab";
0147:
0148:            public final static String PROP_DOCK_HTML_VIEWER_AS_TAB = "gruntspudSA.dockHTMLViewerAsTab";
0149:
0150:            public final static String PROP_CONSOLE_BACKGROUND = "gruntspudSA.console.background";
0151:
0152:            public final static String PROP_CONSOLE_MAX_SIZE = "gruntspudSA.console.maxSize";
0153:
0154:            public final static String PROP_CONSOLE_FONT = "gruntspudSA.console.font";
0155:
0156:            public final static String PROP_CONSOLE_DIVIDER_LOCATION = "gruntspudSA.console.dividerLocation";
0157:
0158:            public final static String PROP_CONSOLE_LAST_SAVE_LOCATION = "gruntspudSA.console.lastSaveLocation";
0159:
0160:            public final static String PROP_SHOW_TIPS_ON_STARTUP = "gruntspudSA.showTipsOnStartup";
0161:
0162:            public final static String PROP_NEXT_TIP_INDEX = "gruntspudSA.nextTipIndex";
0163:
0164:            public final static String PROP_SHOW_MENU_BAR = "gruntspudSA.showMenuBar";
0165:
0166:            public final static String PROP_SHOW_TOOL_BAR = "gruntspudSA.showToolBar";
0167:
0168:            public final static String PROP_SHOW_MEMORY_MONITOR = "gruntspudSA.showMemoryMonitor";
0169:
0170:            //  Diff viewer
0171:            public final static String PROP_DIFF_VIEWER_HORIZONTAL_SPLIT = "gruntspudSA.diffViewer.horizontalSplit";
0172:
0173:            public final static String PROP_DIFF_VIEWER_VERTICAL_SPLIT = "gruntspudSA.diffViewer.verticalSplit";
0174:
0175:            public final static String PROP_DIFF_VIEWER_TABLE_GEOMETRY = "gruntspudSA.diffViewer.tableGeometry";
0176:
0177:            //  Resource names specific to standalone
0178:            public final static String TIPS_RESOURCE_NAME = "resources/tips.txt";
0179:
0180:            //  Other specific to standalone
0181:            public final static String CROSS_PLATFORM_LAF = "CROSS_PLATFORM";
0182:
0183:            //	Styles specific to standalone
0184:            public final static String OPTIONS_STYLE_DIFF_NON_EXISTANT = "diff.nonExistant";
0185:
0186:            public final static String OPTIONS_STYLE_DIFF_IDENTICAL = "diff.identical";
0187:
0188:            public final static String OPTIONS_STYLE_DIFF_INSERTION = "diff.insertion";
0189:
0190:            public final static String OPTIONS_STYLE_DIFF_DELETION = "diff.deletion";
0191:
0192:            public final static String OPTIONS_STYLE_DIFF_CHANGE = "diff.change";
0193:            static {
0194:                //  This is necessary for the plugins to work in the web start version
0195:                Policy.setPolicy(new JDK13GruntspudHostPolicy());
0196:                //
0197:                UIUtil.cacheIcon(ICON_TOOL_LARGE_TIPS,
0198:                        "images/tool_large_tips.png");
0199:                UIUtil.cacheIcon(ICON_TOOL_LARGE_INDEX,
0200:                        "images/tool_large_index.png");
0201:                UIUtil.cacheIcon(ICON_TOOL_LARGE_CONTENTS,
0202:                        "images/tool_large_contents.png");
0203:                UIUtil.cacheIcon(ICON_TOOL_INDEX, "images/tool_index.png");
0204:                UIUtil
0205:                        .cacheIcon(ICON_TOOL_CONTENTS,
0206:                                "images/tool_contents.png");
0207:                UIUtil.cacheIcon(ICON_TOOL_SMALL_INDEX,
0208:                        "images/tool_small_index.png");
0209:                UIUtil.cacheIcon(ICON_TOOL_SMALL_CONTENTS,
0210:                        "images/tool_small_contents.png");
0211:                UIManager.LookAndFeelInfo[] i;
0212:                try {
0213:                    i = UIManager.getInstalledLookAndFeels();
0214:                } catch (Throwable t) {
0215:                    i = new UIManager.LookAndFeelInfo[0];
0216:                }
0217:                allLookAndFeelInfo = new UIManager.LookAndFeelInfo[i.length + 3];
0218:                System.arraycopy(i, 0, allLookAndFeelInfo, 0, i.length);
0219:                allLookAndFeelInfo[i.length] = new UIManager.LookAndFeelInfo(
0220:                        "Default", UIManager.getLookAndFeel().getClass()
0221:                                .getName());
0222:                allLookAndFeelInfo[i.length + 1] = new UIManager.LookAndFeelInfo(
0223:                        "Cross Platform", UIManager
0224:                                .getCrossPlatformLookAndFeelClassName());
0225:                allLookAndFeelInfo[i.length + 2] = new UIManager.LookAndFeelInfo(
0226:                        "System", UIManager.getSystemLookAndFeelClassName());
0227:            }
0228:
0229:            private Gruntspud gruntspud;
0230:
0231:            private GruntspudContext context;
0232:
0233:            private SimpleConsole console;
0234:
0235:            private Properties properties;
0236:
0237:            private File tmpDir;
0238:
0239:            private File prefFile;
0240:
0241:            private boolean commandRunning;
0242:
0243:            private JHelp help;
0244:
0245:            private JDialog helpDialog;
0246:
0247:            private GruntspudHelpUI helpUI;
0248:
0249:            private HTMLViewerFrame htmlViewerFrame;
0250:
0251:            private Vector openFiles;
0252:
0253:            private Icon defaultFolderOpenIcon, defaultFolderClosedIcon,
0254:                    defaultLeafIcon, defaultLeafOpenIcon;
0255:
0256:            /**
0257:             * Constructor for the JDK13GruntspudHost object
0258:             * 
0259:             * @param properties DOCUMENT ME!
0260:             * @param prefFile DOCUMENT ME!
0261:             * 
0262:             * @exception IOException Description of the Exception
0263:             */
0264:            private JDK13GruntspudHost(Properties properties, File prefFile)
0265:                    throws Exception {
0266:                super ("Gruntspud " + VersionInfo.getVersion());
0267:                getDefaultIcons();
0268:                this .properties = properties;
0269:                this .prefFile = prefFile;
0270:                openFiles = new Vector();
0271:                setIconImage(((ImageIcon) UIUtil
0272:                        .loadIconForResource("images/fish.png")).getImage());
0273:                //
0274:                gruntspud = new Gruntspud(this );
0275:                context = gruntspud.getContext();
0276:                gruntspud.start();
0277:                setJMenuBar(context.getViewManager().getMenuBar());
0278:                getContentPane().setLayout(new GridLayout(1, 1));
0279:                getContentPane().add(gruntspud);
0280:                console = new SimpleConsole(context);
0281:                if (getProperty(PROP_GEOMETRY) != null) {
0282:                    loadGeometry(this , PROP_GEOMETRY);
0283:                } else {
0284:                    setSize(new Dimension(780, 580));
0285:                    UIUtil.positionComponent(SwingConstants.CENTER, this );
0286:                }
0287:                int n = Math.abs(hashCode());
0288:                while (true) {
0289:                    tmpDir = new File(new File(System
0290:                            .getProperty("java.io.tmpdir")), "gruntspud_" + n
0291:                            + "_tmp");
0292:                    if (!tmpDir.exists()) {
0293:                        if (!tmpDir.mkdir()) {
0294:                            throw new IOException(
0295:                                    "Could not create temporary directory");
0296:                        } else {
0297:                            break;
0298:                        }
0299:                    } else {
0300:                        n++;
0301:                    }
0302:                }
0303:                tmpDir.deleteOnExit();
0304:                context.getViewManager().addViewListener(this );
0305:                context
0306:                        .registerOptionsTab(gruntspud.standalone.OtherOptionsTab.class);
0307:                context.getTextStyleModel().addStyle(
0308:                        new TextStyle(OPTIONS_STYLE_DIFF_IDENTICAL,
0309:                                "Diff identical", Color.black, Color.white,
0310:                                false, false));
0311:                context.getTextStyleModel().addStyle(
0312:                        new TextStyle(OPTIONS_STYLE_DIFF_NON_EXISTANT,
0313:                                "Diff missing", Color.black, Color.lightGray,
0314:                                false, false));
0315:                context.getTextStyleModel().addStyle(
0316:                        new TextStyle(OPTIONS_STYLE_DIFF_INSERTION,
0317:                                "Diff insertion", Color.black, new Color(120,
0318:                                        220, 130), false, false));
0319:                context.getTextStyleModel().addStyle(
0320:                        new TextStyle(OPTIONS_STYLE_DIFF_DELETION,
0321:                                "Diff deletion", Color.black, Color.pink,
0322:                                false, false));
0323:                context.getTextStyleModel().addStyle(
0324:                        new TextStyle(OPTIONS_STYLE_DIFF_CHANGE, "Diff change",
0325:                                Color.black, new Color(70, 170, 230), false,
0326:                                false));
0327:                try {
0328:                    Class macOS = Class
0329:                            .forName("gruntspud.standalone.os.MacOSX");
0330:                    Class argC[] = { ViewManager.class };
0331:                    Object arg[] = { context.getViewManager() };
0332:                    Method init = macOS.getMethod("init", argC);
0333:                    Object obj = macOS.newInstance();
0334:                    init.invoke(obj, arg);
0335:                } catch (Throwable t) {
0336:                    // not on macos
0337:                }
0338:            }
0339:
0340:            /**
0341:             *  
0342:             */
0343:            public TextStyle getNodeStyle(CVSFileNode node) {
0344:                FileStatus s = node.getOverallStatus();
0345:                TextStyle style = null;
0346:                if (s != null) {
0347:                    style = context.getTextStyleModel().getStyle(
0348:                            "status." + s.toString());
0349:                }
0350:                if (style == null) {
0351:                    if (!node.isLeaf()) {
0352:                        style = new TextStyle();
0353:                        style.setBold(true);
0354:                    } else
0355:                        style = context.getTextStyleModel().getStyle(
0356:                                "status.Erased");
0357:                }
0358:                return style;
0359:            }
0360:
0361:            private void getDefaultIcons() {
0362:                defaultFolderClosedIcon = UIManager.getIcon("Tree.closedIcon");
0363:                defaultFolderOpenIcon = UIManager.getIcon("Tree.openIcon");
0364:                defaultLeafIcon = UIManager.getIcon("Tree.leafIcon");
0365:                defaultLeafOpenIcon = defaultLeafIcon;
0366:            }
0367:
0368:            public Icon getIcon(String name) {
0369:                if (name.equals(Constants.ICON_TOOL_SMALL_DEFAULT_FOLDER_OPEN)) {
0370:                    return defaultFolderOpenIcon;
0371:                } else if (name
0372:                        .equals(Constants.ICON_TOOL_SMALL_DEFAULT_FOLDER_CLOSED)) {
0373:                    return defaultFolderClosedIcon;
0374:                } else if (name.equals(Constants.ICON_TOOL_SMALL_DEFAULT_LEAF)) {
0375:                    return defaultLeafIcon;
0376:                } else if (name
0377:                        .equals(Constants.ICON_TOOL_SMALL_DEFAULT_LEAF_OPEN)) {
0378:                    return defaultLeafOpenIcon;
0379:                } else {
0380:                    return UIUtil.getCachedIcon(name);
0381:                }
0382:            }
0383:
0384:            public Insets getFileRendererInsets() {
0385:                return FILE_RENDERER_INSETS;
0386:            }
0387:
0388:            public boolean isNodeOpenedInEditor(CVSFileNode node) {
0389:                for (Iterator i = openFiles.iterator(); i.hasNext();) {
0390:                    if (((File) i.next()).equals(node.getFile())) {
0391:                        return true;
0392:                    }
0393:                }
0394:                return false;
0395:            }
0396:
0397:            private GruntspudContext getContext() {
0398:                return context;
0399:            }
0400:
0401:            /**
0402:             * DOCUMENT ME!
0403:             * 
0404:             * @param viewEvent DOCUMENT ME!
0405:             */
0406:            public void viewEvent(ViewEvent viewEvent) {
0407:                if (viewEvent.getType() == ViewEvent.VIEW_REMOVED) {
0408:                    if (viewEvent.getSource() instanceof  DockedEditorView) {
0409:                        File f = ((DockedEditorView) viewEvent.getSource())
0410:                                .getFile();
0411:                        for (int i = 0; i < openFiles.size(); i++) {
0412:                            File z = (File) openFiles.elementAt(i);
0413:                            if (f.equals(z)) {
0414:                                CVSFileNode n = context.getViewManager()
0415:                                        .findNodeForPath(
0416:                                                context.getViewManager()
0417:                                                        .getRootNode(), z,
0418:                                                false);
0419:                                if (n != null) {
0420:                                    n.reset();
0421:                                }
0422:                                openFiles.removeElementAt(i);
0423:                                break;
0424:                            }
0425:                        }
0426:                        gruntspud.repaint();
0427:                    }
0428:                }
0429:            }
0430:
0431:            private static Properties loadProperties(File file)
0432:                    throws IOException {
0433:                Properties p = new Properties();
0434:                File old = new File(file.getAbsolutePath() + ".old");
0435:                if (old.exists()) {
0436:                    int opt = JOptionPane
0437:                            .showConfirmDialog(
0438:                                    null,
0439:                                    "An old preferences file exists. This was probably caused\n"
0440:                                            + "an error whilst shutting down a previous instance and your\n"
0441:                                            + "preferences may have been corrupted. Do you wish to revert\n"
0442:                                            + "to these settings?",
0443:                                    "Old preferences exist",
0444:                                    JOptionPane.YES_NO_OPTION,
0445:                                    JOptionPane.WARNING_MESSAGE);
0446:                    if (opt == JOptionPane.YES_OPTION) {
0447:                        if (!file.delete())
0448:                            throw new IOException(
0449:                                    "Could not delete current preferences file "
0450:                                            + file.getAbsolutePath());
0451:                        if (!old.renameTo(file))
0452:                            throw new IOException("Could not rename "
0453:                                    + old.getAbsolutePath() + " to "
0454:                                    + file.getAbsolutePath());
0455:                    }
0456:                    if (opt == JOptionPane.CANCEL_OPTION)
0457:                        throw new IOException(
0458:                                "User cancelled loading of preferences.");
0459:                    if (!old.delete()) {
0460:                        Constants.SYSTEM_LOG
0461:                                .warn("Could not remove old preferences file "
0462:                                        + old.getAbsolutePath());
0463:                    }
0464:                }
0465:                if (file.exists()) {
0466:                    InputStream in = null;
0467:                    try {
0468:                        in = new FileInputStream(file);
0469:                        p.load(in);
0470:                    } finally {
0471:                        if (in != null) {
0472:                            in.close();
0473:                        }
0474:                    }
0475:                }
0476:                return p;
0477:            }
0478:
0479:            /**
0480:             * Gets the property attribute of the JEditPlugin object
0481:             * 
0482:             * @return The property value
0483:             */
0484:            public JComponent getAccessoryComponent() {
0485:                return console;
0486:            }
0487:
0488:            /**
0489:             * If this host is capable of displaying HTML, this method should return a
0490:             * name for the HTML viewer.
0491:             * 
0492:             * @return the name of the diff viewer
0493:             */
0494:            public String getHTMLViewerName() {
0495:                return "Gruntspud HTML viewer";
0496:            }
0497:
0498:            /**
0499:             * View some HTML given a URL.
0500:             * 
0501:             * @param u Description of the Parameter
0502:             */
0503:            public void viewHTML(URL u) {
0504:                if (getBooleanProperty(PROP_USE_INTERNAL_HTML_VIEWER, true)) {
0505:                    if (getBooleanProperty(PROP_DOCK_HTML_VIEWER_AS_TAB, false)) {
0506:                        HTMLViewerView v = null;
0507:                        if (!getBooleanProperty(
0508:                                PROP_HTML_VIEWER_SINGLE_INSTANCE, true)) {
0509:                            Constants.UI_LOG
0510:                                    .debug("Opening new instance of docked Gruntspud HTML viewer for "
0511:                                            + u);
0512:                            v = new HTMLViewerView(context, u);
0513:                            context.getViewManager().addView(v);
0514:                        } else {
0515:                            Constants.UI_LOG
0516:                                    .debug("Using single instance of docked Gruntspud HTML viewer for "
0517:                                            + u);
0518:                            int c = context.getViewManager().getViewCount();
0519:                            for (int i = 0; (i < c) && (v == null); i++) {
0520:                                View view = context.getViewManager().getViewAt(
0521:                                        i);
0522:                                if (view.getClass()
0523:                                        .equals(HTMLViewerView.class)) {
0524:                                    v = (HTMLViewerView) view;
0525:                                }
0526:                            }
0527:                            if (v == null) {
0528:                                v = new HTMLViewerView(context, u);
0529:                                context.getViewManager().addView(v);
0530:                            } else {
0531:                                v.setURL(u);
0532:                            }
0533:                        }
0534:                        context.getViewManager().setSelectedView(v);
0535:                    } else {
0536:                        if (!getBooleanProperty(
0537:                                PROP_HTML_VIEWER_SINGLE_INSTANCE, false)) {
0538:                            Constants.UI_LOG
0539:                                    .debug("Opening new instance of docked Gruntspud HTML viewer for "
0540:                                            + u);
0541:                            new HTMLViewerFrame(context, u);
0542:                        } else {
0543:                            Constants.UI_LOG
0544:                                    .debug("Using single instance of docked Gruntspud HTML viewer for "
0545:                                            + u);
0546:                            if (htmlViewerFrame == null) {
0547:                                htmlViewerFrame = new HTMLViewerFrame(context,
0548:                                        u);
0549:                            } else {
0550:                                htmlViewerFrame.setURL(u);
0551:                                htmlViewerFrame.setVisible(true);
0552:                            }
0553:                        }
0554:                    }
0555:                } else {
0556:                    try {
0557:                        Constants.SYSTEM_LOG.info("Opening URL "
0558:                                + u.toExternalForm());
0559:                        BrowserLauncher.openURL(u.toExternalForm());
0560:                    } catch (IOException ioe) {
0561:                        GruntspudUtil.showErrorMessage(this , "Error", ioe);
0562:                    }
0563:                }
0564:            }
0565:
0566:            /**
0567:             * Gets the property attribute of the JEditPlugin object
0568:             * 
0569:             * @return The property value
0570:             */
0571:            public JComponent getMainComponent() {
0572:                return gruntspud;
0573:            }
0574:
0575:            /**
0576:             * DOCUMENT ME!
0577:             */
0578:            public void reset() {
0579:                if (getBooleanProperty(
0580:                        Constants.OPTIONS_OTHER_SOCKS_PROXY_ENABLED, false)) {
0581:                    System.setProperty("socksProxyHost", getProperty(
0582:                            Constants.OPTIONS_OTHER_SOCKS_PROXY_HOST,
0583:                            "localhost"));
0584:                    System.setProperty("socksProxyPort", String
0585:                            .valueOf(getIntegerProperty(
0586:                                    Constants.OPTIONS_OTHER_SOCKS_PROXY_PORT,
0587:                                    1080)));
0588:                } else {
0589:                    System.getProperties().remove("socksProxyHost");
0590:                    System.getProperties().remove("socksProxyPort");
0591:                }
0592:                if (getBooleanProperty(
0593:                        Constants.OPTIONS_OTHER_HTTP_PROXY_ENABLED, false)) {
0594:                    System.setProperty("http.proxySet", "true");
0595:                    System.setProperty("http.proxyHost", getProperty(
0596:                            Constants.OPTIONS_OTHER_HTTP_PROXY_HOST,
0597:                            "localhost"));
0598:                    System.setProperty("host.proxyPort", String
0599:                            .valueOf(getIntegerProperty(
0600:                                    Constants.OPTIONS_OTHER_HTTP_PROXY_PORT,
0601:                                    8080)));
0602:                    System.setProperty("http.nonProxyHosts", getProperty(
0603:                            Constants.OPTIONS_OTHER_HTTP_NON_PROXY_HOSTS, ""));
0604:                } else {
0605:                    System.getProperties().remove("http.proxySet");
0606:                    System.getProperties().remove("http.proxyHost");
0607:                    System.getProperties().remove("http.proxyPort");
0608:                    System.getProperties().remove("http.nonProxyHosts");
0609:                }
0610:                getJMenuBar().setVisible(
0611:                        getBooleanProperty(PROP_SHOW_MENU_BAR, true));
0612:                gruntspud.init();
0613:                gruntspud.setToolBarVisible(getBooleanProperty(
0614:                        PROP_SHOW_TOOL_BAR, true));
0615:                console.init();
0616:                writeToConsole(context.getTextStyleModel().getStyle(
0617:                        Constants.OPTIONS_STYLE_GRUNTSPUD),
0618:                        Gruntspud.APPLICATION_NAME + " - "
0619:                                + Gruntspud.APPLICATION_VERSION);
0620:                writeToConsole(context.getTextStyleModel().getStyle(
0621:                        Constants.OPTIONS_STYLE_GRUNTSPUD),
0622:                        "See Help -> About for more information.");
0623:            }
0624:
0625:            /**
0626:             *  
0627:             */
0628:            public boolean isExitActionAvailable() {
0629:                return true;
0630:            }
0631:
0632:            /**
0633:             * DOCUMENT ME!
0634:             * 
0635:             * @return DOCUMENT ME!
0636:             */
0637:            public boolean canExit() {
0638:                if (commandRunning) {
0639:                    if (JOptionPane
0640:                            .showConfirmDialog(
0641:                                    this ,
0642:                                    "A command is running, are you sure?",
0643:                                    "Exit Gruntspud",
0644:                                    JOptionPane.YES_NO_OPTION,
0645:                                    JOptionPane.WARNING_MESSAGE,
0646:                                    UIUtil
0647:                                            .getCachedIcon(Constants.ICON_TOOL_LARGE_EXIT)) == JOptionPane.NO_OPTION) {
0648:                        return false;
0649:                    }
0650:                }
0651:                return true;
0652:            }
0653:
0654:            /**
0655:             * DOCUMENT ME!
0656:             */
0657:            public void exit() {
0658:                cleanUp();
0659:                System.exit(0);
0660:            }
0661:
0662:            /**
0663:             * DOCUMENT ME!
0664:             * 
0665:             * @param resource DOCUMENT ME!
0666:             */
0667:            public void showHelp(String resource) {
0668:                if (helpDialog == null) {
0669:                    java.awt.Window w = (java.awt.Window) SwingUtilities
0670:                            .getAncestorOfClass(java.awt.Window.class,
0671:                                    getMainComponent());
0672:                    if ((w != null) && w instanceof  JFrame) {
0673:                        helpDialog = new JDialog((JFrame) w, "Gruntspud Help",
0674:                                false);
0675:                    } else {
0676:                        helpDialog = new JDialog((JFrame) null,
0677:                                "Gruntspud Help", false);
0678:                    }
0679:                    helpDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
0680:                    try {
0681:                        URL url = HelpSet.findHelpSet(null,
0682:                                "help/javahelp/jhelpset.hs");
0683:                        HelpSet helpset = new HelpSet(null, url);
0684:                        help = new JHelp(helpset);
0685:                        helpUI = new GruntspudHelpUI(help, context);
0686:                        helpUI.setDividerLocation(getIntegerProperty(
0687:                                PROP_HELP_DIVIDER_LOCATION, 247));
0688:                        help.setUI(helpUI);
0689:                        helpDialog.getContentPane().add(help,
0690:                                BorderLayout.CENTER);
0691:                        if (!context.getHost().isGeometryStored(
0692:                                JDK13GruntspudHost.PROP_HELP_GEOMETRY)) {
0693:                            helpDialog.setSize(680, 480);
0694:                            helpDialog.setLocation(40, 40);
0695:                        } else {
0696:                            loadGeometry(helpDialog, PROP_HELP_GEOMETRY);
0697:                        }
0698:                    } catch (HelpSetException hse) {
0699:                        GruntspudUtil.showErrorMessage(this , "Error", hse);
0700:                        return;
0701:                    }
0702:                }
0703:                helpDialog.setVisible(!helpDialog.isVisible());
0704:            }
0705:
0706:            /**
0707:             * Return the name of the host
0708:             * 
0709:             * @return DOCUMENT ME!
0710:             * 
0711:             * @exception IOException Description of the Exception
0712:             */
0713:            public String getName() {
0714:                return "Gruntspud";
0715:            }
0716:
0717:            /**
0718:             * Inform of when a command starts running and stops running
0719:             * 
0720:             * @param commandRunning command is running
0721:             */
0722:            public void setCommandRunning(boolean commandRunning) {
0723:                this .commandRunning = commandRunning;
0724:                console.setCommandRunning(commandRunning);
0725:            }
0726:
0727:            /**
0728:             * Gets the property attribute of the JEditPlugin object
0729:             * 
0730:             * @param key Description of the Parameter
0731:             */
0732:            public void unsetProperty(String key) {
0733:                properties.remove(key);
0734:            }
0735:
0736:            /**
0737:             * Description of the Method
0738:             * 
0739:             * @param f1 Description of the Parameter
0740:             * @param title1 DOCUMENT ME!
0741:             * @param f2 Description of the Parameter
0742:             * @param title2 DOCUMENT ME!
0743:             */
0744:            public void diff(File f1, String title1, File f2, String title2,
0745:                    String encoding) {
0746:                writeToConsole(context.getTextStyleModel().getStyle(
0747:                        Constants.OPTIONS_STYLE_GRUNTSPUD), "Diffing "
0748:                        + f1.getAbsolutePath() + " with "
0749:                        + f2.getAbsolutePath() + " using encoding " + encoding);
0750:                DiffViewerView v = new DiffViewerView(context, f1, title1, f2,
0751:                        title2, encoding);
0752:                context.getViewManager().addView(v);
0753:                context.getViewManager().setSelectedView(v);
0754:            }
0755:
0756:            /**
0757:             * Gets the tmpDir attribute of the JDK14GruntspudHost object
0758:             * 
0759:             * @return The tmpDir value
0760:             */
0761:            public File getTmpDir() {
0762:                return tmpDir;
0763:            }
0764:
0765:            /**
0766:             * Gets the diffViewerName attribute of the JDK14GruntspudHost object
0767:             * 
0768:             * @return The diffViewerName value
0769:             */
0770:            public String getDiffViewerName() {
0771:                return "Gruntspud Diff Viewer";
0772:            }
0773:
0774:            /**
0775:             * Gets the localizedString attribute of the JDK14GruntspudHost object
0776:             * 
0777:             * @param name Description of the Parameter
0778:             * @param defaultValue Description of the Parameter
0779:             * 
0780:             * @return The localizedString value
0781:             */
0782:            public String getLocalizedString(String name, String defaultValue) {
0783:                return defaultValue;
0784:            }
0785:
0786:            /**
0787:             * Description of the Method
0788:             * 
0789:             * @param c Description of the Parameter
0790:             * @param message Description of the Parameter
0791:             */
0792:            public void writeToConsole(TextStyle s, String message) {
0793:                console.writeMessage(s, message);
0794:            }
0795:
0796:            /**
0797:             * Description of the Method
0798:             * 
0799:             * @param c Description of the Parameter
0800:             * @param message Description of the Parameter
0801:             * @param icon DOCUMENT ME!
0802:             */
0803:            public void writeToStatusLine(Color c, String message, Icon icon) {
0804:                console.writeToStatusLine(c, message, icon);
0805:            }
0806:
0807:            /**
0808:             * Description of the Method
0809:             * 
0810:             * @param c Description of the Parameter
0811:             * @param message Description of the Parameter
0812:             * @param icon DOCUMENT ME!
0813:             */
0814:            public void writeToInfoLine(Color c, String message, Icon icon) {
0815:                console.writeToInfoLine(c, message, icon);
0816:            }
0817:
0818:            /**
0819:             * Description of the Method
0820:             * 
0821:             * @param t Description of the Parameter
0822:             */
0823:            public void showException(Throwable t) {
0824:                showException(t, null);
0825:            }
0826:
0827:            /**
0828:             * Description of the Method
0829:             * 
0830:             * @param t Description of the Parameter
0831:             * @param message Description of the Parameter
0832:             */
0833:            public void showException(Throwable t, String message) {
0834:                if (message != null) {
0835:                    System.err.println(message);
0836:                }
0837:                t.printStackTrace();
0838:            }
0839:
0840:            /**
0841:             * Gets the property attribute of the JEditPlugin object
0842:             * 
0843:             * @return The property value
0844:             */
0845:            public Properties getProperties() {
0846:                return properties;
0847:            }
0848:
0849:            /**
0850:             * Gets the property attribute of the JDK14GruntspudHost object
0851:             * 
0852:             * @param key Description of the Parameter
0853:             * 
0854:             * @return The property value
0855:             */
0856:            public String getProperty(String key) {
0857:                return getProperty(key, null);
0858:            }
0859:
0860:            /**
0861:             * Gets the property attribute of the JDK14GruntspudHost object
0862:             * 
0863:             * @param key Description of the Parameter
0864:             * @param defaultValue Description of the Parameter
0865:             * 
0866:             * @return The property value
0867:             */
0868:            public String getProperty(String key, String defaultValue) {
0869:                String val = properties.getProperty(key, defaultValue);
0870:                return val;
0871:            }
0872:
0873:            /**
0874:             * Gets the booleanProperty attribute of the JDK14GruntspudHost object
0875:             * 
0876:             * @param key Description of the Parameter
0877:             * 
0878:             * @return The booleanProperty value
0879:             */
0880:            public boolean getBooleanProperty(String key) {
0881:                return getBooleanProperty(key, false);
0882:            }
0883:
0884:            /**
0885:             * Gets the booleanProperty attribute of the JDK14GruntspudHost object
0886:             * 
0887:             * @param key Description of the Parameter
0888:             * @param defaultValue Description of the Parameter
0889:             * 
0890:             * @return The booleanProperty value
0891:             */
0892:            public boolean getBooleanProperty(String key, boolean defaultValue) {
0893:                String p = getProperty(key, String.valueOf(defaultValue));
0894:                return (p != null) && p.equalsIgnoreCase("true");
0895:            }
0896:
0897:            /**
0898:             * Gets the booleanProperty attribute of the GruntspudHost object
0899:             * 
0900:             * @param key Description of the Parameter
0901:             * 
0902:             * @return The booleanProperty value
0903:             */
0904:            public int getIntegerProperty(String key) {
0905:                return getIntegerProperty(key, 0);
0906:            }
0907:
0908:            /**
0909:             * Gets the booleanProperty attribute of the GruntspudHost object
0910:             * 
0911:             * @param key Description of the Parameter
0912:             * @param defaultValue DOCUMENT ME!
0913:             * 
0914:             * @return The booleanProperty value
0915:             */
0916:            public int getIntegerProperty(String key, int defaultValue) {
0917:                try {
0918:                    return Integer.parseInt(getProperty(key, String
0919:                            .valueOf(defaultValue)));
0920:                } catch (NumberFormatException nfe) {
0921:                    return defaultValue;
0922:                }
0923:            }
0924:
0925:            /**
0926:             * Sets the booleanProperty attribute of the GruntspudHost object
0927:             * 
0928:             * @param key The new booleanProperty value
0929:             * @param value The new booleanProperty value
0930:             */
0931:            public void setIntegerProperty(String key, int value) {
0932:                setProperty(key, String.valueOf(value));
0933:            }
0934:
0935:            /**
0936:             * Sets the property attribute of the JDK14GruntspudHost object
0937:             * 
0938:             * @param key The new property value
0939:             * @param value The new property value
0940:             */
0941:            public void setProperty(String key, String value) {
0942:                if (value == null) {
0943:                    properties.remove(key);
0944:                } else {
0945:                    properties.put(key, value);
0946:                }
0947:            }
0948:
0949:            /**
0950:             * Sets the booleanProperty attribute of the JDK14GruntspudHost object
0951:             * 
0952:             * @param key The new booleanProperty value
0953:             * @param value The new booleanProperty value
0954:             */
0955:            public void setBooleanProperty(String key, boolean value) {
0956:                setProperty(key, String.valueOf(value));
0957:            }
0958:
0959:            /**
0960:             * Description of the Method
0961:             * 
0962:             * @param node Description of the Parameter
0963:             * 
0964:             * @exception IOException Description of the Exception
0965:             */
0966:            public void openNode(final CVSFileNode node) throws IOException {
0967:                if (node.isLeaf()
0968:                        && node.getFile().exists()
0969:                        && node.getFile().canRead()
0970:                        && (CVSSubstType.CVS_SUBST_TYPE_BINARY != node
0971:                                .getCVSSubstType())) {
0972:                    for (int i = 0; i < openFiles.size(); i++) {
0973:                        if (((File) openFiles.elementAt(i)).equals(node
0974:                                .getFile())) {
0975:                            Toolkit.getDefaultToolkit().beep();
0976:                            return;
0977:                        }
0978:                    }
0979:                    String encoding = CVSUtil.getEncodingForRoot(context, node
0980:                            .getCVSRoot());
0981:                    openFiles.addElement(node.getFile());
0982:                    node.reset();
0983:                    gruntspud.repaint();
0984:                    boolean conflict = (node.getEntry() != null)
0985:                            && node.getEntry().hadConflicts();
0986:                    if (getBooleanProperty(PROP_DOCK_EDITOR_AS_TAB, false)) {
0987:                        DockedEditorView v = new DockedEditorView(context, node
0988:                                .getIcon(false), conflict);
0989:                        context.getViewManager().addView(v);
0990:                        context.getViewManager().setSelectedView(v);
0991:                        v.openFile(node.getFile(), encoding);
0992:                    } else {
0993:                        SimpleEditorFrame f = new SimpleEditorFrame(context,
0994:                                conflict);
0995:                        f.openFile(node.getFile(), encoding);
0996:                        f.addWindowListener(new WindowAdapter() {
0997:                            public void windowClosed(WindowEvent evt) {
0998:                                openFiles.removeElement(node.getFile());
0999:                                node.reset();
1000:                                gruntspud.repaint();
1001:                            }
1002:                        });
1003:                    }
1004:                }
1005:            }
1006:
1007:            /**
1008:             * Description of the Method
1009:             * 
1010:             * @param component Description of the Parameter
1011:             * @param key Description of the Parameter
1012:             */
1013:            public void saveGeometry(java.awt.Window component, String key) {
1014:                StringBuffer buf = new StringBuffer();
1015:                buf.append(component.getLocation().x);
1016:                buf.append(',');
1017:                buf.append(component.getLocation().y);
1018:                buf.append(',');
1019:                buf.append(component.getSize().width);
1020:                buf.append(',');
1021:                buf.append(component.getSize().height);
1022:                setProperty(key, buf.toString());
1023:            }
1024:
1025:            /**
1026:             * Description of the Method
1027:             * 
1028:             * @param component Description of the Parameter
1029:             * @param key Description of the Parameter
1030:             */
1031:            public void loadGeometry(java.awt.Window component, String key) {
1032:                String geo = getProperty(key);
1033:                if (geo != null) {
1034:                    StringTokenizer t = new StringTokenizer(geo, ",");
1035:                    try {
1036:                        component.setLocation(Integer.parseInt(t.nextToken()),
1037:                                Integer.parseInt(t.nextToken()));
1038:                        component.setSize(Integer.parseInt(t.nextToken()),
1039:                                Integer.parseInt(t.nextToken()));
1040:                    } catch (Exception e) {
1041:                    }
1042:                } else {
1043:                    component.pack();
1044:                    UIUtil.positionComponent(SwingConstants.CENTER, component);
1045:                }
1046:            }
1047:
1048:            /**
1049:             * Description of the Method
1050:             * 
1051:             * @param key Description of the Parameter
1052:             * 
1053:             * @return DOCUMENT ME!
1054:             */
1055:            public boolean isGeometryStored(String key) {
1056:                return !getProperty(key, "").equals("");
1057:            }
1058:
1059:            /**
1060:             * Description of the Method
1061:             * 
1062:             * @param command Description of the Parameter
1063:             */
1064:            public void runCommand(String command) {
1065:                gruntspud.runCommand(command);
1066:            }
1067:
1068:            /**
1069:             * Gets the useCanonicalPaths attribute of the JDK14GruntspudHost object
1070:             * 
1071:             * @return The useCanonicalPaths value
1072:             */
1073:            public boolean isUseCanonicalPaths() {
1074:                return false;
1075:            }
1076:
1077:            /**
1078:             * Description of the Method
1079:             */
1080:            public void cleanUp() {
1081:                gruntspud.cleanUp();
1082:                saveGeometry(this , PROP_GEOMETRY);
1083:                if (help != null) {
1084:                    setIntegerProperty(PROP_HELP_DIVIDER_LOCATION, helpUI
1085:                            .getDividerLocation());
1086:                    saveGeometry(helpDialog, PROP_HELP_GEOMETRY);
1087:                }
1088:                FileOutputStream out = null;
1089:                /*
1090:                 * Write to a temporary file incase anything goes wrong during the write.
1091:                 * Preferences have been known to go missing when you get OutOfMemory for
1092:                 * example
1093:                 */
1094:                File old = new File(prefFile.getAbsolutePath() + ".old");
1095:                if (prefFile.exists() && !prefFile.renameTo(old)) {
1096:                    Constants.SYSTEM_LOG
1097:                            .error("Could not rename preferences file "
1098:                                    + prefFile.getAbsolutePath() + " to .old");
1099:                } else {
1100:                    try {
1101:                        out = new FileOutputStream(prefFile);
1102:                        properties.store(out, "Gruntspud");
1103:                        out.flush();
1104:                        if (old.exists() && !old.delete())
1105:                            throw new IOException(
1106:                                    "Could not delete old preferences file "
1107:                                            + old.getAbsolutePath());
1108:                    } catch (IOException ioe) {
1109:                        ioe.printStackTrace();
1110:                    } finally {
1111:                        GruntspudUtil.closeStream(out);
1112:                    }
1113:                }
1114:            }
1115:
1116:            /**
1117:             * Show a dialog containing the preferences for Gruntspud.
1118:             */
1119:            public void showPreferences() {
1120:                //        final Tabber preferences = new Tabber();
1121:                final ToolBarTabber preferences = new ToolBarTabber();
1122:                //        UIUtil.setTabLayoutPolicy(preferences, 1);
1123:                for (Iterator i = context.optionsTabs(); i.hasNext();) {
1124:                    Class c = (Class) i.next();
1125:                    try {
1126:                        OptionsTab o = (OptionsTab) c.newInstance();
1127:                        // horrid
1128:                        o.init(context);
1129:                        preferences.addTab(o, o.getTabTitle().equals(
1130:                                "Connection"));
1131:                    } catch (Throwable t) {
1132:                        t.printStackTrace();
1133:                        Constants.UI_LOG.error(t);
1134:                    }
1135:                }
1136:                OptionDialog.Option ok = new OptionDialog.Option("Ok", "Ok",
1137:                        'o');
1138:                OptionDialog.Option cancel = new OptionDialog.Option("Cancel",
1139:                        "Cancel", 'c');
1140:                OptionDialog.Option opt = OptionDialog.showOptionDialog(
1141:                        "Preferences", context, gruntspud,
1142:                        new OptionDialog.Option[] { ok, cancel }, preferences,
1143:                        "Preferences", ok, new OptionDialog.Callback() {
1144:                            public boolean canClose(OptionDialog dialog,
1145:                                    OptionDialog.Option option) {
1146:                                return preferences.validateTabs();
1147:                            }
1148:                        }, true, false, new Dimension(610, 530));
1149:                if (opt != ok) {
1150:                    return;
1151:                }
1152:                preferences.applyTabs();
1153:                reset();
1154:            }
1155:
1156:            /**
1157:             * Return all of the available look and feels
1158:             * 
1159:             * @return array of look and feel info
1160:             */
1161:            public static UIManager.LookAndFeelInfo[] getAllLookAndFeelInfo() {
1162:                return allLookAndFeelInfo;
1163:            }
1164:
1165:            /**
1166:             * Set the look and feel
1167:             * 
1168:             * @param context DOCUMENT ME!
1169:             * @param className laf class name
1170:             * 
1171:             * @throws Exception on any error setting the look and feel
1172:             */
1173:            public static void setLookAndFeel(GruntspudContext context,
1174:                    String className) throws Exception {
1175:                LookAndFeel laf = (LookAndFeel) Class.forName(className)
1176:                        .newInstance();
1177:                if (laf.getClass().getName().equals(
1178:                        "com.oyoaha.swing.plaf.oyoaha.OyoahaLookAndFeel")
1179:                        && !System.getProperty("oyoaha.theme").equals("")) {
1180:                    Method m = UIManager.getLookAndFeel().getClass().getMethod(
1181:                            "setOyoahaTheme", new Class[] { File.class });
1182:                    File f = new File(System.getProperty("oyoaha.theme"));
1183:                    m.invoke(laf, new File[] { f });
1184:                }
1185:                //  Now actually set the look and feel
1186:                Constants.SYSTEM_LOG.info("Setting look and feel "
1187:                        + laf.getName() + " (" + laf.getClass().getName()
1188:                        + ") - current is "
1189:                        + UIManager.getLookAndFeel().getClass());
1190:                if (laf != null
1191:                        && !laf.getClass().getName()
1192:                                .equals(
1193:                                        UIManager.getLookAndFeel().getClass()
1194:                                                .getName())) {
1195:                    UIManager.setLookAndFeel(laf);
1196:                    UIManager.put("EditorPane.font", UIManager
1197:                            .getFont("TextArea.font"));
1198:                }
1199:                //  Update the component tree
1200:                if (context != null) {
1201:                    SwingUtilities.updateComponentTreeUI(context.getHost()
1202:                            .getMainComponent());
1203:                    Window w = (Window) SwingUtilities.getAncestorOfClass(
1204:                            Window.class, context.getHost().getMainComponent());
1205:                    if (w != null) {
1206:                        SwingUtilities.updateComponentTreeUI(w);
1207:                    }
1208:                }
1209:                //  Change some of the icons
1210:                UIManager.put("OptionPane.errorIcon", new IconResource(
1211:                        "images/dialog-error4.png"));
1212:                UIManager.put("OptionPane.informationIcon", new IconResource(
1213:                        "images/dialog-information.png"));
1214:                UIManager.put("OptionPane.warningIcon", new IconResource(
1215:                        "images/dialog-warning2.png"));
1216:                UIManager.put("OptionPane.questionIcon", new IconResource(
1217:                        "images/dialog-question3.png"));
1218:            }
1219:
1220:            /**
1221:             * DOCUMENT ME!
1222:             */
1223:            public void updateComponentTreeUI() {
1224:                getDefaultIcons();
1225:                Frame[] frames = Frame.getFrames();
1226:                for (int i = 0; i < frames.length; i++) {
1227:                    SwingUtilities.updateComponentTreeUI(frames[i]);
1228:                    updateAllDialogComponentTreeUIs(frames[i]);
1229:                }
1230:                if (context != null) {
1231:                    if (context.getViewManager() != null)
1232:                        SwingUtilities.updateComponentTreeUI(context
1233:                                .getViewManager());
1234:                }
1235:            }
1236:
1237:            private static void updateAllDialogComponentTreeUIs(Window win) {
1238:                Window[] children = win.getOwnedWindows();
1239:                for (int i = 0; i < children.length; i++) {
1240:                    if (win instanceof  Frame) {
1241:                        continue;
1242:                    }
1243:                    SwingUtilities.updateComponentTreeUI(win);
1244:                    updateAllDialogComponentTreeUIs(win);
1245:                }
1246:            }
1247:
1248:            /**
1249:             * The main program for the JDK14GruntspudHost class
1250:             * 
1251:             * @param args The command line arguments
1252:             * 
1253:             * @exception Exception Description of the Exception
1254:             */
1255:            public static void main(String[] args) throws Exception {
1256:                //  Load the properties
1257:                File prefFile = GruntspudUtil.getPreferenceFile(
1258:                        "gruntspud.properties", false);
1259:                Properties p = loadProperties(prefFile);
1260:                //  Enabled logging if required
1261:                if ((VersionInfo.getVersion().equals("HEAD") && !System
1262:                        .getProperty("gruntspud.disableDebugging", "false")
1263:                        .equals("true"))
1264:                        || p.getProperty(Constants.OPTIONS_SYSTEM_DEBUG,
1265:                                "false").equals("true")) {
1266:                    //  First see if there is a log4j.xml in the preferences directory
1267:                    File log4jFile = GruntspudUtil.getPreferenceFile(
1268:                            "log4j.properties", false);
1269:                    URL log4jURL = (log4jFile.exists() && log4jFile.canRead()) ? log4jFile
1270:                            .toURL()
1271:                            : Gruntspud.class.getClassLoader().getResource(
1272:                                    "resources/log4j.properties");
1273:                    System.out.println("Loading log4j properties from "
1274:                            + log4jURL);
1275:                    PropertyConfigurator.configure(log4jURL);
1276:                }
1277:                //  Disable logging
1278:                else {
1279:                    BasicConfigurator.configure();
1280:                    Logger.getRootLogger().setLevel(Level.OFF);
1281:                }
1282:                //  Set the look and feel.
1283:                String laf = p.getProperty(PROP_LAF, CROSS_PLATFORM_LAF);
1284:                try {
1285:                    if (!laf.equals("")) {
1286:                        setLookAndFeel(null, laf);
1287:                    }
1288:                } catch (Exception e) {
1289:                    Constants.UI_LOG.error("Could not set look and feel.", e);
1290:                }
1291:                //  Create the host and watch for window closing events
1292:                final JDK13GruntspudHost h = new JDK13GruntspudHost(p, prefFile);
1293:                h.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
1294:                h.addWindowListener(new WindowAdapter() {
1295:                    public void windowClosing(WindowEvent evt) {
1296:                        if (h.canExit()) {
1297:                            h.exit();
1298:                        }
1299:                    }
1300:                });
1301:                //  Make Gruntspud visibile and initialise it
1302:                SwingUtilities.invokeLater(new Runnable() {
1303:                    public void run() {
1304:                        h.setVisible(true);
1305:                        h.reset();
1306:                    }
1307:                });
1308:                //  Show the tips
1309:                if (h.getBooleanProperty(
1310:                        JDK13GruntspudHost.PROP_SHOW_TIPS_ON_STARTUP, true)) {
1311:                    final JTips tips = new JTips(h, h.getIntegerProperty(
1312:                            JDK13GruntspudHost.PROP_NEXT_TIP_INDEX, 0), h
1313:                            .getContext());
1314:                    SwingUtilities.invokeLater(new Runnable() {
1315:                        public void run() {
1316:                            tips.setVisible(true);
1317:                            tips.dispose();
1318:                            h.setIntegerProperty(
1319:                                    JDK13GruntspudHost.PROP_NEXT_TIP_INDEX,
1320:                                    tips.getTipIndex() + 1);
1321:                            h
1322:                                    .setBooleanProperty(
1323:                                            JDK13GruntspudHost.PROP_SHOW_TIPS_ON_STARTUP,
1324:                                            tips.isShow());
1325:                        }
1326:                    });
1327:                }
1328:            }
1329:
1330:            class ToolBarTabber extends JPanel {
1331:                TabToolBar toolBar;
1332:
1333:                Vector tabs;
1334:
1335:                FolderBar folderBar;
1336:
1337:                JPanel viewPane;
1338:
1339:                CardLayout layout;
1340:
1341:                ScrollingPanel scrolling;
1342:
1343:                ToolBarTabber() {
1344:                    super (new BorderLayout());
1345:                    tabs = new Vector();
1346:                    toolBar = new TabToolBar();
1347:                    scrolling = new ScrollingPanel(toolBar);
1348:                    scrolling.setBorder(BorderFactory
1349:                            .createLoweredBevelBorder());
1350:                    folderBar = new FolderBar(" ", UIUtil.EMPTY_ICON,
1351:                            FolderBar.NORMAL_FOLDER_BAR);
1352:                    folderBar.setBorder(BorderFactory.createCompoundBorder(
1353:                            BorderFactory.createLoweredBevelBorder(),
1354:                            BorderFactory.createEmptyBorder(0, 0, 4, 0)));
1355:                    toolBar.setFolderBar(folderBar);
1356:                    JPanel centerPane = new JPanel(new BorderLayout());
1357:                    centerPane.setBorder(BorderFactory.createEmptyBorder(0, 4,
1358:                            0, 0));
1359:                    viewPane = new JPanel(layout = new CardLayout());
1360:                    centerPane.add(folderBar, BorderLayout.NORTH);
1361:                    centerPane.add(viewPane, BorderLayout.CENTER);
1362:                    add(scrolling, BorderLayout.WEST);
1363:                    add(centerPane, BorderLayout.CENTER);
1364:                }
1365:
1366:                public void applyTabs() {
1367:                    for (int i = 0; i < tabs.size(); i++) {
1368:                        ((Tab) tabs.elementAt(i)).applyTab();
1369:                    }
1370:                }
1371:
1372:                public boolean validateTabs() {
1373:                    for (int i = 0; i < tabs.size(); i++) {
1374:                        Tab t = (Tab) tabs.elementAt(i);
1375:                        if (!t.validateTab()) {
1376:                            return false;
1377:                        }
1378:                    }
1379:                    return true;
1380:                }
1381:
1382:                public void addTab(Tab tab) {
1383:                    addTab(tab, false);
1384:                }
1385:
1386:                public void addTab(Tab tab, boolean sel) {
1387:                    String c = (tab.getTabContext() == null) ? "Unknown" : tab
1388:                            .getTabContext();
1389:                    ToolAction action = new ToolAction(tab.getTabIcon(), tab
1390:                            .getTabLargeIcon(), tab.getTabTitle(), tab
1391:                            .getTabToolTipText(), tab.getTabMnemonic(), layout,
1392:                            viewPane, c);
1393:                    tabs.addElement(tab);
1394:                    viewPane.add(tab.getTabComponent(), tab.getTabTitle());
1395:                    toolBar.addIcon(action);
1396:                    if (sel) {
1397:                        layout.show(viewPane, tab.getTabTitle());
1398:                        folderBar.setAction(action);
1399:                        toolBar.setSelectedContext(c);
1400:                    }
1401:                    scrolling.setAvailableActions();
1402:                }
1403:            }
1404:
1405:            class ToolAction extends AbstractAction implements  GruntspudAction {
1406:                CardLayout layout;
1407:
1408:                JPanel viewPane;
1409:
1410:                ToolAction(Icon icon, Icon largeIcon, String name,
1411:                        String description, int mnemonic, CardLayout layout,
1412:                        JPanel viewPane, String context) {
1413:                    super (name);
1414:                    putValue(GruntspudAction.LARGE_ICON, largeIcon);
1415:                    putValue(GruntspudAction.ICON, icon);
1416:                    putValue(GruntspudAction.LONG_DESCRIPTION, description);
1417:                    putValue(GruntspudAction.CONTEXT, context);
1418:                    this .layout = layout;
1419:                    this .viewPane = viewPane;
1420:                }
1421:
1422:                public boolean checkAvailable() {
1423:                    return true;
1424:                }
1425:
1426:                public void actionPerformed(ActionEvent evt) {
1427:                    layout.show(viewPane, (String) getValue(Action.NAME));
1428:                }
1429:            }
1430:
1431:            static class JDK13GruntspudHostPolicy extends Policy {
1432:                PermissionCollection coll;
1433:
1434:                JDK13GruntspudHostPolicy() {
1435:                    super ();
1436:                    coll = new JDK13GruntspudHostPermissions();
1437:                    coll.add(new java.security.AllPermission());
1438:                }
1439:
1440:                public PermissionCollection getPermissions(
1441:                        ProtectionDomain domain) {
1442:                    return coll;
1443:                }
1444:
1445:                public PermissionCollection getPermissions(CodeSource codesource) {
1446:                    return coll;
1447:                }
1448:
1449:                public boolean implies(ProtectionDomain domain,
1450:                        Permission permission) {
1451:                    return true;
1452:                }
1453:
1454:                public void refresh() {
1455:                }
1456:            }
1457:
1458:            static class JDK13GruntspudHostPermissions extends
1459:                    PermissionCollection {
1460:                private Vector perms;
1461:
1462:                private boolean readOnly;
1463:
1464:                JDK13GruntspudHostPermissions() {
1465:                    perms = new Vector();
1466:                }
1467:
1468:                public void add(Permission permission) {
1469:                    perms.addElement(permission);
1470:                }
1471:
1472:                public boolean implies(Permission permission) {
1473:                    return true;
1474:                }
1475:
1476:                public Enumeration elements() {
1477:                    return perms.elements();
1478:                }
1479:
1480:                public void setReadOnly() {
1481:                    readOnly = true;
1482:                }
1483:
1484:                public boolean isReadOnly() {
1485:                    return readOnly;
1486:                }
1487:            }
1488:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.