Source Code Cross Referenced for ShortcutPanel.java in  » Installer » IzPack » com » izforge » izpack » panels » 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 » Installer » IzPack » com.izforge.izpack.panels 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
0003:         *
0004:         * http://www.izforge.com/izpack/ http://izpack.codehaus.org/
0005:         *
0006:         * Copyright 2002 Elmar Grom
0007:         *
0008:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
0009:         * in compliance with the License. You may obtain a copy of the License at
0010:         *
0011:         * http://www.apache.org/licenses/LICENSE-2.0
0012:         *
0013:         * Unless required by applicable law or agreed to in writing, software distributed under the License
0014:         * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
0015:         * or implied. See the License for the specific language governing permissions and limitations under
0016:         * the License.
0017:         */
0018:        package com.izforge.izpack.panels;
0019:
0020:        import java.awt.Dimension;
0021:        import java.awt.GridBagConstraints;
0022:        import java.awt.GridBagLayout;
0023:        import java.awt.GridLayout;
0024:        import java.awt.Insets;
0025:        import java.awt.event.ActionEvent;
0026:        import java.awt.event.ActionListener;
0027:        import java.io.File;
0028:        import java.io.FileWriter;
0029:        import java.io.InputStream;
0030:        import java.util.ArrayList;
0031:        import java.util.Enumeration;
0032:        import java.util.Vector;
0033:
0034:        import javax.swing.ButtonGroup;
0035:        import javax.swing.JButton;
0036:        import javax.swing.JCheckBox;
0037:        import javax.swing.JFileChooser;
0038:        import javax.swing.JLabel;
0039:        import javax.swing.JList;
0040:        import javax.swing.JPanel;
0041:        import javax.swing.JRadioButton;
0042:        import javax.swing.JScrollPane;
0043:        import javax.swing.JTextField;
0044:        import javax.swing.ListSelectionModel;
0045:        import javax.swing.border.Border;
0046:        import javax.swing.border.EmptyBorder;
0047:        import javax.swing.border.TitledBorder;
0048:        import javax.swing.event.ListSelectionEvent;
0049:        import javax.swing.event.ListSelectionListener;
0050:
0051:        import net.n3.nanoxml.NonValidator;
0052:        import net.n3.nanoxml.StdXMLParser;
0053:        import net.n3.nanoxml.StdXMLReader;
0054:        import net.n3.nanoxml.XMLElement;
0055:        import net.n3.nanoxml.XMLBuilderFactory;
0056:
0057:        import com.izforge.izpack.ExecutableFile;
0058:        import com.izforge.izpack.Pack;
0059:        import com.izforge.izpack.gui.ButtonFactory;
0060:        import com.izforge.izpack.gui.LabelFactory;
0061:        import com.izforge.izpack.installer.*;
0062:        import com.izforge.izpack.util.Debug;
0063:        import com.izforge.izpack.util.FileExecutor;
0064:        import com.izforge.izpack.util.MultiLineLabel;
0065:        import com.izforge.izpack.util.OsConstraint;
0066:        import com.izforge.izpack.util.OsVersion;
0067:        import com.izforge.izpack.util.StringTool;
0068:        import com.izforge.izpack.util.TargetFactory;
0069:        import com.izforge.izpack.util.VariableSubstitutor;
0070:        import com.izforge.izpack.util.os.Shortcut;
0071:        import com.izforge.izpack.util.os.unix.UnixHelper;
0072:        import com.izforge.izpack.util.xml.XMLHelper;
0073:
0074:        //
0075:        // import com.izforge.izpack.panels.ShortcutData;
0076:
0077:        /*---------------------------------------------------------------------------*/
0078:
0079:        /**
0080:         * This class implements a panel for the creation of shortcuts. The panel prompts the user to select
0081:         * a program group for shortcuts, accept the creation of desktop shortcuts and actually creates the
0082:         * shortcuts.
0083:         * 
0084:         * Use LateShortcutInstallListener to create the Shortcuts after the Files have been installed.
0085:         * 
0086:         * @version $Revision: 2061 $
0087:         */
0088:        public class ShortcutPanel extends IzPanel implements  ActionListener,
0089:                ListSelectionListener // ,//
0090:        // ShortcutConstants
0091:
0092:        {
0093:
0094:            // ~ Static fields/initializers *********************************************************
0095:            /** serialVersionUID = 3256722870838112311L */
0096:            private static final long serialVersionUID = 3256722870838112311L;
0097:
0098:            // ~ Static fields/initializers *********************************************************
0099:
0100:            /** SPEC_ATTRIBUTE_KDE_USERNAME ="KdeUsername" */
0101:            public final static String SPEC_ATTRIBUTE_KDE_USERNAME = "KdeUsername";
0102:
0103:            /** SPEC_ATTRIBUTE_KDE_SUBST_UID = "KdeSubstUID" */
0104:            public final static String SPEC_ATTRIBUTE_KDE_SUBST_UID = "KdeSubstUID";
0105:
0106:            /** SPEC_ATTRIBUTE_URL = "url" */
0107:            public final static String SPEC_ATTRIBUTE_URL = "url";
0108:
0109:            /** SPEC_ATTRIBUTE_TYPE = "type" */
0110:            public final static String SPEC_ATTRIBUTE_TYPE = "type";
0111:
0112:            /** SPEC_ATTRIBUTE_TERMINAL_OPTIONS = "terminalOptions" */
0113:            public final static String SPEC_ATTRIBUTE_TERMINAL_OPTIONS = "terminalOptions";
0114:
0115:            /** SPEC_ATTRIBUTE_TERMINAL = "terminal" */
0116:            public final static String SPEC_ATTRIBUTE_TERMINAL = "terminal";
0117:
0118:            /** SPEC_ATTRIBUTE_MIMETYPE = "mimetype" */
0119:            public final static String SPEC_ATTRIBUTE_MIMETYPE = "mimetype";
0120:
0121:            /** SPEC_ATTRIBUTE_ENCODING = "encoding" */
0122:            public final static String SPEC_ATTRIBUTE_ENCODING = "encoding";
0123:
0124:            /** LOCATION_APPLICATIONS=applications */
0125:            private static final String LOCATION_APPLICATIONS = "applications";
0126:
0127:            /** LOCATION_START_MENU = "startMenu" */
0128:            private static final String LOCATION_START_MENU = "startMenu";
0129:
0130:            /** SPEC_CATEGORIES = "categories" */
0131:            public static final String SPEC_CATEGORIES = "categories";
0132:
0133:            /** SPEC_TRYEXEC = "tryexec" */
0134:            public static final String SPEC_TRYEXEC = "tryexec";
0135:
0136:            /**
0137:             * SEPARATOR_LINE =
0138:             * "--------------------------------------------------------------------------------";
0139:             */
0140:            private static final String SEPARATOR_LINE = "--------------------------------------------------------------------------------";
0141:
0142:            /**
0143:             * The default file name for the text file in which the shortcut information should be stored,
0144:             * in case shortcuts can not be created on a particular target system. TEXT_FILE_NAME =
0145:             * "Shortcuts.txt"
0146:             */
0147:            private static final String TEXT_FILE_NAME = "Shortcuts.txt";
0148:
0149:            /**
0150:             * The name of the XML file that specifies the shortcuts SPEC_FILE_NAME = "shortcutSpec.xml";
0151:             */
0152:            private static final String SPEC_FILE_NAME = "shortcutSpec.xml";
0153:
0154:            // ------------------------------------------------------
0155:            // spec file section keys
0156:            // -----------------------------------------------------
0157:
0158:            /** SPEC_KEY_SKIP_IFNOT_SUPPORTED = "skipIfNotSupported" */
0159:            private static final String SPEC_KEY_SKIP_IFNOT_SUPPORTED = "skipIfNotSupported";
0160:
0161:            /** SPEC_KEY_NOT_SUPPORTED = "notSupported" */
0162:            private static final String SPEC_KEY_NOT_SUPPORTED = "notSupported";
0163:
0164:            /** SPEC_KEY_PROGRAM_GROUP = "programGroup" */
0165:            private static final String SPEC_KEY_PROGRAM_GROUP = "programGroup";
0166:
0167:            /** SPEC_KEY_SHORTCUT = "shortcut" */
0168:            private static final String SPEC_KEY_SHORTCUT = "shortcut";
0169:
0170:            /** SPEC_KEY_PACKS = "createForPack" */
0171:            private static final String SPEC_KEY_PACKS = "createForPack";
0172:
0173:            // ------------------------------------------------------
0174:            // spec file key attributes
0175:            // ------------------------------------------------------
0176:            /** SPEC_ATTRIBUTE_DEFAULT_GROUP = "defaultName" */
0177:            private static final String SPEC_ATTRIBUTE_DEFAULT_GROUP = "defaultName";
0178:
0179:            /** Support the InstallGroups like in Packs.
0180:             * SPEC_ATTRIBUTE_INSTALLGROUP = "installGroup" */
0181:            private static final String SPEC_ATTRIBUTE_INSTALLGROUP = "installGroup";
0182:
0183:            /** SPEC_ATTRIBUTE_LOCATION = "location" */
0184:            private static final String SPEC_ATTRIBUTE_LOCATION = "location";
0185:
0186:            /** SPEC_ATTRIBUTE_NAME = "name" */
0187:            private static final String SPEC_ATTRIBUTE_NAME = "name";
0188:
0189:            /** SPEC_ATTRIBUTE_SUBGROUP = "subgroup" */
0190:            private static final String SPEC_ATTRIBUTE_SUBGROUP = "subgroup";
0191:
0192:            /** SPEC_ATTRIBUTE_DESCRIPTION = "description" */
0193:            private static final String SPEC_ATTRIBUTE_DESCRIPTION = "description";
0194:
0195:            /** SPEC_ATTRIBUTE_TARGET = "target" */
0196:            private static final String SPEC_ATTRIBUTE_TARGET = "target";
0197:
0198:            /** SPEC_ATTRIBUTE_COMMAND = "commandLine" */
0199:            private static final String SPEC_ATTRIBUTE_COMMAND = "commandLine";
0200:
0201:            /** SPEC_ATTRIBUTE_ICON "iconFile" */
0202:            private static final String SPEC_ATTRIBUTE_ICON = "iconFile";
0203:
0204:            /** SPEC_ATTRIBUTE_ICON_INDEX "iconIndex" */
0205:            private static final String SPEC_ATTRIBUTE_ICON_INDEX = "iconIndex";
0206:
0207:            /** SPEC_ATTRIBUTE_WORKING_DIR = "workingDirectory" */
0208:            private static final String SPEC_ATTRIBUTE_WORKING_DIR = "workingDirectory";
0209:
0210:            /** SPEC_ATTRIBUTE_INITIAL_STATE = "initialState" */
0211:            private static final String SPEC_ATTRIBUTE_INITIAL_STATE = "initialState";
0212:
0213:            /** SPEC_ATTRIBUTE_DESKTOP = "desktop" */
0214:            private static final String SPEC_ATTRIBUTE_DESKTOP = "desktop";
0215:
0216:            /** SPEC_ATTRIBUTE_APPLICATIONS = "applications" */
0217:            private static final String SPEC_ATTRIBUTE_APPLICATIONS = "applications";
0218:
0219:            /** SPEC_ATTRIBUTE_START_MENU = "startMenu" */
0220:            private static final String SPEC_ATTRIBUTE_START_MENU = "startMenu";
0221:
0222:            /** SPEC_ATTRIBUTE_STARTUP = "startup" */
0223:            private static final String SPEC_ATTRIBUTE_STARTUP = "startup";
0224:
0225:            /** SPEC_ATTRIBUTE_PROGRAM_GROUP = "programGroup" */
0226:            private static final String SPEC_ATTRIBUTE_PROGRAM_GROUP = "programGroup";
0227:
0228:            // ------------------------------------------------------
0229:            // spec file attribute values
0230:            // ------------------------------------------------------
0231:
0232:            /** SPEC_VALUE_APPLICATIONS = "applications" */
0233:            private static final String SPEC_VALUE_APPLICATIONS = "applications";
0234:
0235:            /** SPEC_VALUE_START_MENU = "startMenu" */
0236:            private static final String SPEC_VALUE_START_MENU = "startMenu";
0237:
0238:            /** SPEC_VALUE_NO_SHOW = "noShow" */
0239:            private static final String SPEC_VALUE_NO_SHOW = "noShow";
0240:
0241:            /** SPEC_VALUE_NORMAL = "normal" */
0242:            private static final String SPEC_VALUE_NORMAL = "normal";
0243:
0244:            /** SPEC_VALUE_MAXIMIZED = "maximized" */
0245:            private static final String SPEC_VALUE_MAXIMIZED = "maximized";
0246:
0247:            /** SPEC_VALUE_MINIMIZED = "minimized" */
0248:            private static final String SPEC_VALUE_MINIMIZED = "minimized";
0249:
0250:            // ------------------------------------------------------
0251:            // automatic script section keys
0252:            // ------------------------------------------------------
0253:
0254:            /** AUTO_KEY_PROGRAM_GROUP = SPEC_KEY_PROGRAM_GROUP = "programGroup" */
0255:            public static final String AUTO_KEY_PROGRAM_GROUP = SPEC_KEY_PROGRAM_GROUP;
0256:
0257:            /** AUTO_KEY_SHORTCUT = SPEC_KEY_SHORTCUT = "shortcut" */
0258:            public static final String AUTO_KEY_SHORTCUT = SPEC_KEY_SHORTCUT;
0259:
0260:            // ------------------------------------------------------
0261:            // automatic script keys attributes
0262:            // ------------------------------------------------------
0263:
0264:            /** AUTO_ATTRIBUTE_NAME = "name" */
0265:            public static final String AUTO_ATTRIBUTE_NAME = "name";
0266:
0267:            /** AUTO_ATTRIBUTE_GROUP = "group" */
0268:            public static final String AUTO_ATTRIBUTE_GROUP = "group";
0269:
0270:            /** AUTO_ATTRIBUTE_TYPE "type" */
0271:            public static final String AUTO_ATTRIBUTE_TYPE = "type";
0272:
0273:            /** AUTO_ATTRIBUTE_COMMAND = "commandLine" */
0274:            public static final String AUTO_ATTRIBUTE_COMMAND = "commandLine";
0275:
0276:            /** AUTO_ATTRIBUTE_DESCRIPTION = "description" */
0277:            public static final String AUTO_ATTRIBUTE_DESCRIPTION = "description";
0278:
0279:            /** AUTO_ATTRIBUTE_ICON = "icon" */
0280:            public static final String AUTO_ATTRIBUTE_ICON = "icon";
0281:
0282:            /** AUTO_ATTRIBUTE_ICON_INDEX = "iconIndex" */
0283:            public static final String AUTO_ATTRIBUTE_ICON_INDEX = "iconIndex";
0284:
0285:            /** AUTO_ATTRIBUTE_INITIAL_STATE = "initialState" */
0286:            public static final String AUTO_ATTRIBUTE_INITIAL_STATE = "initialState";
0287:
0288:            /** AUTO_ATTRIBUTE_TARGET = "target" */
0289:            public static final String AUTO_ATTRIBUTE_TARGET = "target";
0290:
0291:            /** AUTO_ATTRIBUTE_WORKING_DIR = "workingDirectory" */
0292:            public static final String AUTO_ATTRIBUTE_WORKING_DIR = "workingDirectory";
0293:
0294:            // permission flags
0295:
0296:            /** CREATE_FOR_ALL = "createForAll" */
0297:            public static final String CREATE_FOR_ALL = "createForAll";
0298:
0299:            private static ShortcutPanel self = null;
0300:
0301:            private static boolean firstTime = true;
0302:
0303:            /** internal flag: create */
0304:            static boolean create;
0305:
0306:            /** 
0307:             * May be switched by an installerlistener to false.
0308:             * Installerlistener may then perform the creation of the shortcuts after the files have been installed...
0309:             * Default is true.
0310:             */
0311:            public static boolean createImmediately = true;
0312:
0313:            /** internal flag isRootUser */
0314:            private static boolean isRootUser;
0315:
0316:            // ~ Instance fields ********************************************************************
0317:
0318:            // ~ Instance fields ********************************************************************
0319:
0320:            /** a VectorList of Files wich should be make executable */
0321:            private Vector<ExecutableFile> execFiles = new Vector<ExecutableFile>();
0322:
0323:            // ------------------------------------------------------------------------
0324:            // Variable Declarations
0325:            // ------------------------------------------------------------------------
0326:
0327:            /** UI element to label the list of existing program groups */
0328:            private JLabel listLabel;
0329:
0330:            /** UI element to present the list of existing program groups for selection */
0331:            private JList groupList;
0332:
0333:            /** UI element for listing the intended shortcut targets */
0334:            private JList targetList;
0335:
0336:            /**
0337:             * UI element to present the default name for the program group and to support editing of this
0338:             * name.
0339:             */
0340:            private JTextField programGroup;
0341:
0342:            /** UI element to allow the user to revert to the default name of the program group */
0343:            private JButton defaultButton;
0344:
0345:            /** UI element to allow the user to save a text file with the shortcut information */
0346:            private JButton saveButton;
0347:
0348:            /**
0349:             * UI element to allow the user to decide if shortcuts should be placed on the desktop or not.
0350:             */
0351:            private JCheckBox allowDesktopShortcut;
0352:
0353:            /** Checkbox to enable/disable to chreate ShortCuts */
0354:            private JCheckBox createShortcuts;
0355:
0356:            /** UI element instruct this panel to create shortcuts for the current user only */
0357:            private JRadioButton currentUser;
0358:
0359:            /** UI element instruct this panel to create shortcuts for all users */
0360:            private JRadioButton allUsers;
0361:
0362:            /** The layout for this panel */
0363:            private GridBagLayout layout;
0364:
0365:            /** The contraints object to use whan creating the layout */
0366:            private GridBagConstraints constraints;
0367:
0368:            /**
0369:             * The default name to use for the program group. This comes from the XML specification.
0370:             */
0371:            private String suggestedProgramGroup;
0372:
0373:            /** The name chosen by the user for the program group, */
0374:            private String groupName;
0375:
0376:            /** The icon for the group in XDG/unix menu */
0377:            private String programGroupIconFile;
0378:
0379:            /** Comment for XDG/unix group */
0380:            private String programGroupComment;
0381:
0382:            /**
0383:             * The location for placign the program group. This is the same as the location (type) of a
0384:             * shortcut, only that it applies to the program group. Note that there are only two locations
0385:             * that make sense as location for a program group: <br>
0386:             * applications start menu
0387:             */
0388:            private int groupLocation;
0389:
0390:            /** The parsed result from reading the XML specification from the file */
0391:            private XMLElement spec;
0392:
0393:            /** Set to true by analyzeShortcutSpec() if there are any desktop shortcuts to create. */
0394:            private boolean hasDesktopShortcuts = false;
0395:
0396:            /** Tells wether to skip if the platform is not supported. */
0397:            private boolean skipIfNotSupported = false;
0398:
0399:            /** the one shortcut instance for reuse in many locations */
0400:            private Shortcut shortcut;
0401:
0402:            /**
0403:             * A list of ShortcutData> objects. Each object is the complete specification for one shortcut
0404:             * that must be created.
0405:             */
0406:            private Vector shortcuts = new Vector();
0407:
0408:            /**
0409:             * Holds a list of all the shortcut files that have been created. Note: this variable contains
0410:             * valid data only after createShortcuts() has been called. This list is created so that the
0411:             * files can be added to the uninstaller.
0412:             */
0413:            private Vector<String> files = new Vector<String>();
0414:
0415:            /**
0416:             * If true it indicates that there are shortcuts to create. The value is set by
0417:             * analyzeShortcutSpec()
0418:             */
0419:            private boolean shortcutsToCreate = false;
0420:
0421:            /** If true it indicates that the spec file is existing and could be read. */
0422:            private boolean haveShortcutSpec = false;
0423:
0424:            /**
0425:             * This is set to true if the shortcut spec instructs to simulate running on an operating system
0426:             * that is not supported.
0427:             */
0428:            private boolean simulteNotSupported = false;
0429:
0430:            /** Avoids bogus behaviour when the user goes back then returns to this panel. */
0431:
0432:            // private boolean firstTime = true;
0433:            private File itsProgramFolder;
0434:
0435:            /** itsUserType */
0436:            private int itsUserType;
0437:
0438:            /** USER_TYPE = "usertype" to store this information in the automated.xml  */
0439:            public final static String USER_TYPE = "usertype";
0440:
0441:            /** shortCuts */
0442:            private Vector<String> shortCuts;
0443:
0444:            /** internal line counter */
0445:            int line;
0446:
0447:            /** internal column counter */
0448:            int col;
0449:
0450:            // ~ Constructors ***********************************************************************
0451:
0452:            // ~ Constructors ***********************************************************************
0453:
0454:            /*
0455:             * --------------------------------------------------------------------------
0456:             */
0457:
0458:            /**
0459:             * Constructor.
0460:             * 
0461:             * @param parent reference to the application frame
0462:             * @param installData shared information about the installation
0463:             */
0464:
0465:            /*
0466:             * --------------------------------------------------------------------------
0467:             */
0468:            public ShortcutPanel(InstallerFrame parent, InstallData installData) {
0469:                super (parent, installData, "link16x16");
0470:
0471:                layout = (GridBagLayout) super .getLayout();
0472:                Object con = getLayoutHelper().getDefaultConstraints();
0473:                if (con instanceof  GridBagConstraints)
0474:                    constraints = (GridBagConstraints) con;
0475:                else
0476:                    con = new GridBagConstraints();
0477:                setLayout(super .getLayout());
0478:
0479:                if (self != null)
0480:                    throw new RuntimeException(this .getClass().getName()
0481:                            + " is not allowed to instantiate more than once!");
0482:
0483:                self = this ;
0484:            }
0485:
0486:            // ~ Methods ****************************************************************************
0487:
0488:            // ~ Methods ****************************************************************************
0489:            // **************************************************************************************************************************************************
0490:
0491:            /*--------------------------------------------------------------------------*/
0492:
0493:            /**
0494:             * This method represents the ActionListener interface, invoked when an action occurs.
0495:             * 
0496:             * @param event the action event.
0497:             */
0498:
0499:            /*--------------------------------------------------------------------------*/
0500:            public void actionPerformed(ActionEvent event) {
0501:                Object eventSource = event.getSource();
0502:
0503:                /*
0504:                 * if (eventSource != null) { System.out.println("Instance Of : " +
0505:                 * eventSource.getClass().getName()); }
0506:                 */
0507:
0508:                // ----------------------------------------------------
0509:                // create shortcut for the current user was selected
0510:                // refresh the list of program groups accordingly and
0511:                // reset the program group to the default setting.
0512:                // ----------------------------------------------------
0513:                if (eventSource.equals(currentUser)) {
0514:                    if (groupList != null)
0515:                        groupList.setListData(shortcut
0516:                                .getProgramGroups(Shortcut.CURRENT_USER));
0517:                    programGroup.setText(suggestedProgramGroup);
0518:                    shortcut.setUserType(itsUserType = Shortcut.CURRENT_USER);
0519:
0520:                }
0521:
0522:                // ----------------------------------------------------
0523:                // create shortcut for all users was selected
0524:                // refresh the list of program groups accordingly and
0525:                // reset the program group to the default setting.
0526:                // ----------------------------------------------------
0527:                else if (eventSource.equals(allUsers)) {
0528:                    if (groupList != null)
0529:                        groupList.setListData(shortcut
0530:                                .getProgramGroups(Shortcut.ALL_USERS));
0531:                    programGroup.setText(suggestedProgramGroup);
0532:                    shortcut.setUserType(itsUserType = Shortcut.ALL_USERS);
0533:
0534:                }
0535:
0536:                // ----------------------------------------------------
0537:                // The reset button was pressed.
0538:                // - clear the selection in the list box, because the
0539:                // selection is no longer valid
0540:                // - refill the program group edit control with the
0541:                // suggested program group name
0542:                // ----------------------------------------------------
0543:                else if (eventSource.equals(defaultButton)) {
0544:                    if (groupList != null
0545:                            && groupList.getSelectionModel() != null)
0546:                        groupList.getSelectionModel().clearSelection();
0547:                    programGroup.setText(suggestedProgramGroup);
0548:
0549:                }
0550:
0551:                // ----------------------------------------------------
0552:                // the save button was pressed. This is a request to
0553:                // save shortcut information to a text file.
0554:                // ----------------------------------------------------
0555:                else if (eventSource.equals(saveButton)) {
0556:                    saveToFile();
0557:
0558:                    // add the file to the uninstaller
0559:                    addToUninstaller();
0560:
0561:                } else if (eventSource.equals(createShortcuts)) {
0562:                    create = createShortcuts.isSelected();
0563:
0564:                    if (groupList != null) {
0565:                        groupList.setEnabled(create);
0566:                    }
0567:
0568:                    programGroup.setEnabled(create);
0569:                    currentUser.setEnabled(create);
0570:                    defaultButton.setEnabled(create);
0571:
0572:                    // ** There where no Desktop Links or not allowed, this may be null: **//
0573:                    if (allowDesktopShortcut != null) {
0574:                        allowDesktopShortcut.setEnabled(create);
0575:                    }
0576:
0577:                    if (isRootUser) {
0578:                        allUsers.setEnabled(create);
0579:                    }
0580:                }
0581:            }
0582:
0583:            /*--------------------------------------------------------------------------*/
0584:
0585:            /**
0586:             * Returns true when all selections have valid settings. This indicates that it is legal to
0587:             * procede to the next panel.
0588:             * 
0589:             * @return true if it is legal to procede to the next panel, otherwise false.
0590:             */
0591:
0592:            /*--------------------------------------------------------------------------*/
0593:            public boolean isValidated() {
0594:                try {
0595:                    groupName = programGroup.getText();
0596:                } catch (Throwable exception) {
0597:                    groupName = "";
0598:                }
0599:
0600:                create = createShortcuts.isSelected();
0601:
0602:                if (createImmediately) {
0603:                    createAndRegisterShortcuts();
0604:                }
0605:
0606:                return (true);
0607:            }
0608:
0609:            /*--------------------------------------------------------------------------*/
0610:
0611:            /**
0612:             * Called when the panel is shown to the user.
0613:             */
0614:
0615:            /*--------------------------------------------------------------------------*/
0616:            public void panelActivate() {
0617:                try {
0618:                    readShortcutSpec();
0619:                } catch (Throwable exception) {
0620:                    System.out.println("could not read shortcut spec!");
0621:                    exception.printStackTrace();
0622:                }
0623:
0624:                // Create the UI elements
0625:                try {
0626:                    shortcut = (Shortcut) (TargetFactory.getInstance()
0627:                            .makeObject("com.izforge.izpack.util.os.Shortcut"));
0628:                    shortcut.initialize(Shortcut.APPLICATIONS, "-");
0629:                } catch (Throwable exception) {
0630:                    System.out.println("could not create shortcut instance");
0631:                    exception.printStackTrace();
0632:                }
0633:
0634:                analyzeShortcutSpec();
0635:
0636:                if (shortcutsToCreate && !OsVersion.IS_OSX) {
0637:                    if (shortcut.supported() && !simulteNotSupported) {
0638:                        File allUsersProgramsFolder = getProgramsFolder(Shortcut.ALL_USERS);
0639:
0640:                        Debug.log("All UsersProgramsFolder: '"
0641:                                + allUsersProgramsFolder + "'");
0642:
0643:                        File forceTest = new File(allUsersProgramsFolder
0644:                                + File.separator
0645:                                + System.getProperty("user.name")
0646:                                + System.currentTimeMillis());
0647:
0648:                        try {
0649:                            isRootUser = forceTest.createNewFile();
0650:                        } catch (Exception e) {
0651:                            isRootUser = false;
0652:                            Debug.log("IOException: " + "'"
0653:                                    + e.getLocalizedMessage() + "'");
0654:                            Debug.log("You cannot create '" + forceTest + "'");
0655:
0656:                        }
0657:
0658:                        if (forceTest.exists()) {
0659:                            Debug.log("Delete temporary File: '" + forceTest
0660:                                    + "'");
0661:                            forceTest.delete();
0662:                        }
0663:
0664:                        String perm = isRootUser ? "can" : "cannot";
0665:
0666:                        Debug.log("You " + perm + " write into '"
0667:                                + allUsersProgramsFolder + "'");
0668:
0669:                        if (isRootUser) {
0670:                            itsUserType = Shortcut.ALL_USERS;
0671:                        } else {
0672:                            itsUserType = Shortcut.CURRENT_USER;
0673:                        }
0674:
0675:                        if (firstTime)
0676:                            buildUI(getProgramsFolder(isRootUser ? Shortcut.ALL_USERS
0677:                                    : Shortcut.CURRENT_USER));
0678:
0679:                        // addSelectionList();
0680:                        // add( shortCutsArea );
0681:                        // JList shortCutList = null;
0682:                        // addList( shortCuts, ListSelectionModel.SINGLE_SELECTION, shortCutList, col,
0683:                        // line+6, 1, 1, GridBagConstraints.BOTH );
0684:                    } else {
0685:                        // TODO MEP: Test
0686:                        if (firstTime)
0687:                            buildAlternateUI();
0688:
0689:                        // parent.unlockNextButton();
0690:                        // parent.lockPrevButton();
0691:                    }
0692:                    firstTime = false;
0693:                } else {
0694:                    // Skip on OS X
0695:                    parent.skipPanel();
0696:                }
0697:            }
0698:
0699:            /**
0700:             * Returns the ProgramsFolder for the current User
0701:             * 
0702:             * @param userType DOCUMENT ME!
0703:             * 
0704:             * @return The Basedir
0705:             */
0706:            private File getProgramsFolder(int userType) {
0707:                String path = shortcut.getProgramsFolder(userType);
0708:
0709:                return (new File(path));
0710:
0711:                // }
0712:                // else
0713:                // {
0714:                // TODO
0715:                // 0ptional: Test if KDE is installed.
0716:                // boolean isKdeInstalled = UnixHelper.kdeIsInstalled();
0717:                // 1. Test if User can write into
0718:                // File kdeRootShareApplinkDir = getKDERootShareApplinkDir();
0719:                // if so: return getKDERootShareApplinkDir()
0720:                // else
0721:                // return getKDEUsersShareApplinkDir() +
0722:                // }
0723:                // return(result);
0724:            }
0725:
0726:            /**
0727:             * This method is called by the groupList when the user makes a selection. It updates the
0728:             * content of the programGroup with the result of the selection.
0729:             * 
0730:             * @param event the list selection event
0731:             */
0732:
0733:            /*--------------------------------------------------------------------------*/
0734:            public void valueChanged(ListSelectionEvent event) {
0735:                if (programGroup == null) {
0736:                    return;
0737:                }
0738:
0739:                String value = "";
0740:
0741:                try {
0742:                    value = (String) groupList.getSelectedValue();
0743:                } catch (ClassCastException exception) {
0744:                }
0745:
0746:                if (value == null) {
0747:                    value = "";
0748:                }
0749:
0750:                programGroup.setText(value + File.separator
0751:                        + suggestedProgramGroup);
0752:            }
0753:
0754:            /*--------------------------------------------------------------------------*/
0755:
0756:            /**
0757:             * Reads the XML specification for the shortcuts to create. The result is stored in spec.
0758:             * 
0759:             * @exception Exception for any problems in reading the specification
0760:             */
0761:
0762:            /*--------------------------------------------------------------------------*/
0763:            private void readShortcutSpec() throws Exception {
0764:                // open an input stream
0765:                InputStream input = null;
0766:
0767:                try {
0768:                    input = ResourceManager.getInstance()
0769:                            .getInputStream(
0770:                                    TargetFactory.getCurrentOSPrefix()
0771:                                            + SPEC_FILE_NAME);
0772:                } catch (ResourceNotFoundException rnfE) {
0773:                    input = ResourceManager.getInstance().getInputStream(
0774:                            SPEC_FILE_NAME);
0775:                }
0776:
0777:                if (input == null) {
0778:                    haveShortcutSpec = false;
0779:
0780:                    return;
0781:                }
0782:
0783:                // if( input == null )
0784:                // {
0785:                // haveShortcutSpec = false;
0786:                // return;
0787:                // }
0788:                // initialize the parser
0789:                VariableSubstitutor substitutor = new VariableSubstitutor(idata
0790:                        .getVariables());
0791:
0792:                // input.
0793:                String substitutedSpec = substitutor.substitute(input, "xml");
0794:
0795:                /*
0796:                 * TODO: internal flag mapped if( idata.isDebug() ) { System.out.println( "SUBSTITUDED
0797:                 * SHORTCUT SPEC" ); System.out.println(
0798:                 * "==================================================================" );
0799:                 * System.out.println( "==================================================================" );
0800:                 * System.out.println( substitutedSpec ); System.out.println(
0801:                 * "==================================================================" );
0802:                 * System.out.println( "==================================================================" ); }
0803:                 */
0804:                StdXMLParser parser = new StdXMLParser();
0805:                parser.setBuilder(XMLBuilderFactory.createXMLBuilder());
0806:                parser.setValidator(new NonValidator());
0807:                parser.setReader(StdXMLReader.stringReader(substitutedSpec));
0808:
0809:                // get the data
0810:                spec = (XMLElement) parser.parse();
0811:
0812:                // close the stream
0813:                input.close();
0814:                haveShortcutSpec = true;
0815:            }
0816:
0817:            /*--------------------------------------------------------------------------*/
0818:
0819:            /**
0820:             * This method analyzes the specifications for creating shortcuts and builds a list of all the
0821:             * Shortcuts that need to be created.
0822:             */
0823:
0824:            /*--------------------------------------------------------------------------*/
0825:            private void analyzeShortcutSpec() {
0826:                if (!haveShortcutSpec) {
0827:                    shortcutsToCreate = false;
0828:
0829:                    return;
0830:                }
0831:
0832:                XMLElement skipper = spec
0833:                        .getFirstChildNamed(SPEC_KEY_SKIP_IFNOT_SUPPORTED);
0834:                skipIfNotSupported = (skipper != null);
0835:
0836:                // ----------------------------------------------------
0837:                // find out if we should simulate a not supported
0838:                // scenario
0839:                // ----------------------------------------------------
0840:                XMLElement support = spec
0841:                        .getFirstChildNamed(SPEC_KEY_NOT_SUPPORTED);
0842:
0843:                if (support != null) {
0844:                    simulteNotSupported = true;
0845:                }
0846:
0847:                // ----------------------------------------------------
0848:                // find out in which program group the shortcuts should
0849:                // be placed and where this program group should be
0850:                // located
0851:                // ----------------------------------------------------
0852:
0853:                XMLElement group = null;
0854:                Vector<XMLElement> groupSpecs = spec
0855:                        .getChildrenNamed(SPEC_KEY_PROGRAM_GROUP);
0856:                String selectedInstallGroup = idata
0857:                        .getVariable("INSTALL_GROUP");
0858:                if (selectedInstallGroup != null) {
0859:                    //The user selected an InstallGroup before.
0860:                    //We may have some restrictions on the Installationgroup
0861:                    //search all defined ProgramGroups for the given InstallGroup
0862:                    for (XMLElement g : groupSpecs) {
0863:                        String instGrp = g
0864:                                .getAttribute(SPEC_ATTRIBUTE_INSTALLGROUP);
0865:                        if (instGrp != null
0866:                                && selectedInstallGroup
0867:                                        .equalsIgnoreCase(instGrp)) {
0868:                            group = g;
0869:                            break;
0870:                        }
0871:                    }
0872:                }
0873:                if (group == null) {
0874:                    //default (old) behavior
0875:                    group = spec.getFirstChildNamed(SPEC_KEY_PROGRAM_GROUP);
0876:                }
0877:
0878:                String location = null;
0879:                hasDesktopShortcuts = false;
0880:
0881:                if (group != null) {
0882:                    suggestedProgramGroup = group.getAttribute(
0883:                            SPEC_ATTRIBUTE_DEFAULT_GROUP, "");
0884:                    programGroupIconFile = group.getAttribute("iconFile", "");
0885:                    programGroupComment = group.getAttribute("comment", "");
0886:                    location = group.getAttribute(SPEC_ATTRIBUTE_LOCATION,
0887:                            SPEC_VALUE_APPLICATIONS);
0888:                } else {
0889:                    suggestedProgramGroup = "";
0890:                    location = SPEC_VALUE_APPLICATIONS;
0891:                }
0892:
0893:                if (location.equals(SPEC_VALUE_APPLICATIONS)) {
0894:                    groupLocation = Shortcut.APPLICATIONS;
0895:                } else if (location.equals(SPEC_VALUE_START_MENU)) {
0896:                    groupLocation = Shortcut.START_MENU;
0897:                }
0898:
0899:                // ----------------------------------------------------
0900:                // create a list of all shortcuts that need to be
0901:                // created, containing all details about each shortcut
0902:                // ----------------------------------------------------
0903:                // String temp;
0904:                Vector<XMLElement> shortcutSpecs = spec
0905:                        .getChildrenNamed(SPEC_KEY_SHORTCUT);
0906:                XMLElement shortcutSpec;
0907:                ShortcutData data;
0908:
0909:                shortCuts = new Vector<String>();
0910:
0911:                for (int i = 0; i < shortcutSpecs.size(); i++) {
0912:                    // System.out.println( "Processing shortcut: " + i );
0913:                    shortcutSpec = shortcutSpecs.elementAt(i);
0914:
0915:                    if (!OsConstraint.oneMatchesCurrentSystem(shortcutSpec)) {
0916:                        continue;
0917:                    }
0918:
0919:                    Debug.log("Checking Condition for "
0920:                            + shortcutSpec.getAttribute(SPEC_ATTRIBUTE_NAME));
0921:                    if (!checkConditions(shortcutSpec)) {
0922:                        continue;
0923:                    }
0924:
0925:                    Debug.log("Checked Condition for "
0926:                            + shortcutSpec.getAttribute(SPEC_ATTRIBUTE_NAME));
0927:                    data = new ShortcutData();
0928:
0929:                    data.name = shortcutSpec.getAttribute(SPEC_ATTRIBUTE_NAME);
0930:                    data.subgroup = shortcutSpec.getAttribute(
0931:                            SPEC_ATTRIBUTE_SUBGROUP, "");
0932:                    data.description = shortcutSpec.getAttribute(
0933:                            SPEC_ATTRIBUTE_DESCRIPTION, "");
0934:
0935:                    // ** Linux **//
0936:                    data.deskTopEntryLinux_Encoding = shortcutSpec
0937:                            .getAttribute(SPEC_ATTRIBUTE_ENCODING, "");
0938:                    data.deskTopEntryLinux_MimeType = shortcutSpec
0939:                            .getAttribute(SPEC_ATTRIBUTE_MIMETYPE, "");
0940:                    data.deskTopEntryLinux_Terminal = shortcutSpec
0941:                            .getAttribute(SPEC_ATTRIBUTE_TERMINAL, "");
0942:                    data.deskTopEntryLinux_TerminalOptions = shortcutSpec
0943:                            .getAttribute(SPEC_ATTRIBUTE_TERMINAL_OPTIONS, "");
0944:                    data.deskTopEntryLinux_Type = shortcutSpec.getAttribute(
0945:                            SPEC_ATTRIBUTE_TYPE, "");
0946:
0947:                    data.deskTopEntryLinux_URL = shortcutSpec.getAttribute(
0948:                            SPEC_ATTRIBUTE_URL, "");
0949:
0950:                    data.deskTopEntryLinux_X_KDE_SubstituteUID = shortcutSpec
0951:                            .getAttribute(SPEC_ATTRIBUTE_KDE_SUBST_UID, "false");
0952:
0953:                    data.deskTopEntryLinux_X_KDE_UserName = shortcutSpec
0954:                            .getAttribute(SPEC_ATTRIBUTE_KDE_USERNAME, "root");
0955:
0956:                    data.Categories = shortcutSpec.getAttribute(
0957:                            SPEC_CATEGORIES, "Application;Development");
0958:
0959:                    data.TryExec = shortcutSpec.getAttribute(SPEC_TRYEXEC, "");
0960:
0961:                    data.createForAll = Boolean.valueOf(shortcutSpec
0962:                            .getAttribute(CREATE_FOR_ALL, "false"));
0963:
0964:                    // ** EndOf LINUX **//
0965:                    // temp =
0966:                    data.target = fixSeparatorChar(shortcutSpec.getAttribute(
0967:                            SPEC_ATTRIBUTE_TARGET, ""));
0968:
0969:                    // temp =
0970:                    data.commandLine = shortcutSpec.getAttribute(
0971:                            SPEC_ATTRIBUTE_COMMAND, "");
0972:
0973:                    // temp =
0974:                    data.iconFile = fixSeparatorChar(shortcutSpec.getAttribute(
0975:                            SPEC_ATTRIBUTE_ICON, ""));
0976:                    data.iconIndex = Integer.parseInt(shortcutSpec
0977:                            .getAttribute(SPEC_ATTRIBUTE_ICON_INDEX, "0"));
0978:
0979:                    // temp =
0980:                    data.workingDirectory = fixSeparatorChar(shortcutSpec
0981:                            .getAttribute(SPEC_ATTRIBUTE_WORKING_DIR, ""));
0982:
0983:                    String initialState = shortcutSpec.getAttribute(
0984:                            SPEC_ATTRIBUTE_INITIAL_STATE, "");
0985:
0986:                    if (initialState.equals(SPEC_VALUE_NO_SHOW)) {
0987:                        data.initialState = Shortcut.HIDE;
0988:                    } else if (initialState.equals(SPEC_VALUE_NORMAL)) {
0989:                        data.initialState = Shortcut.NORMAL;
0990:                    } else if (initialState.equals(SPEC_VALUE_MAXIMIZED)) {
0991:                        data.initialState = Shortcut.MAXIMIZED;
0992:                    } else if (initialState.equals(SPEC_VALUE_MINIMIZED)) {
0993:                        data.initialState = Shortcut.MINIMIZED;
0994:                    } else {
0995:                        data.initialState = Shortcut.NORMAL;
0996:                    }
0997:
0998:                    // LOG System.out.println("data.initialState: " + data.initialState);
0999:
1000:                    // --------------------------------------------------
1001:                    // if the minimal data requirements are met to create
1002:                    // the shortcut, create one entry each for each of
1003:                    // the requested types.
1004:                    // Eventually this will cause the creation of one
1005:                    // shortcut in each of the associated locations.
1006:                    // --------------------------------------------------
1007:                    // without a name we can not create a shortcut
1008:                    if (data.name == null) {
1009:                        continue;
1010:                    }
1011:
1012:                    // 1. Elmar: "Without a target we can not create a shortcut."
1013:                    // 2. Marc: "No, Even on Linux a Link can be an URL and has no target."
1014:                    if (data.target == null) {
1015:                        // TODO: write log info INFO.warn( "Shortcut: " + data + " has no target" );
1016:                        data.target = "";
1017:                    }
1018:                    // the shortcut is not actually required for any of the selected packs
1019:
1020:                    // the shortcut is not actually required for any of the selected packs // the shortcut
1021:                    // is not actually required for any of the selected packs
1022:                    Vector<XMLElement> forPacks = shortcutSpec
1023:                            .getChildrenNamed(SPEC_KEY_PACKS);
1024:
1025:                    if (!shortcutRequiredFor(forPacks)) {
1026:                        continue;
1027:                    }
1028:                    // --------------------------------------------------
1029:                    // This section is executed if we don't skip.
1030:                    // --------------------------------------------------
1031:                    // For each of the categories set the type and if
1032:                    // the link should be placed in the program group,
1033:                    // then clone the data set to obtain an independent
1034:                    // instance and add this to the list of shortcuts
1035:                    // to be created. In this way, we will set up an
1036:                    // identical copy for each of the locations at which
1037:                    // a shortcut should be placed. Therefore you must
1038:                    // not use 'else if' statements!
1039:                    // --------------------------------------------------
1040:                    {
1041:                        if (XMLHelper.attributeIsTrue(shortcutSpec,
1042:                                SPEC_ATTRIBUTE_DESKTOP)) {
1043:                            hasDesktopShortcuts = true;
1044:                            data.addToGroup = false;
1045:                            data.type = Shortcut.DESKTOP;
1046:                            shortcuts.add(data.clone());
1047:                        }
1048:
1049:                        if (XMLHelper.attributeIsTrue(shortcutSpec,
1050:                                SPEC_ATTRIBUTE_APPLICATIONS)) {
1051:                            data.addToGroup = false;
1052:                            data.type = Shortcut.APPLICATIONS;
1053:                            shortcuts.add(data.clone());
1054:                        }
1055:
1056:                        if (XMLHelper.attributeIsTrue(shortcutSpec,
1057:                                SPEC_ATTRIBUTE_START_MENU)) {
1058:                            data.addToGroup = false;
1059:                            data.type = Shortcut.START_MENU;
1060:                            shortcuts.add(data.clone());
1061:                        }
1062:
1063:                        if (XMLHelper.attributeIsTrue(shortcutSpec,
1064:                                SPEC_ATTRIBUTE_STARTUP)) {
1065:                            data.addToGroup = false;
1066:                            data.type = Shortcut.START_UP;
1067:                            shortcuts.add(data.clone());
1068:                        }
1069:
1070:                        if (XMLHelper.attributeIsTrue(shortcutSpec,
1071:                                SPEC_ATTRIBUTE_PROGRAM_GROUP)) {
1072:                            data.addToGroup = true;
1073:                            data.type = Shortcut.APPLICATIONS;
1074:                            shortcuts.add(data.clone());
1075:                        }
1076:
1077:                        // / TODO: write log INFO.info( "data.name: " + data.name );
1078:                        shortCuts.add((data.name == null) ? "" : data.name); // + " -> " + data.target +
1079:
1080:                        // " Type: " + data.type );
1081:                    }
1082:                }
1083:
1084:                // ----------------------------------------------------
1085:                // signal if there are any shortcuts to create
1086:                // ----------------------------------------------------
1087:                if (shortcuts.size() > 0) {
1088:                    shortcutsToCreate = true;
1089:                }
1090:            }
1091:
1092:            /**
1093:             * This returns true if a Shortcut should or can be created. Returns false to suppress Creation
1094:             * 
1095:             * @param shortcutSpec
1096:             * 
1097:             * @return true if condtion is resolved positive - currently unimplemented: returns always true.
1098:             */
1099:            private boolean checkConditions(XMLElement shortcutSpec) {
1100:                /*
1101:                 * Vector conditions = shortcutSpec.getChildrenNamed( Condition.CONDITION );
1102:                 * 
1103:                 * for( int i = 0; i < conditions.size(); i++ ) { Condition condition = new Condition(
1104:                 * conditions.elementAt( i ) );
1105:                 * 
1106:                 * //System.out.println( "Readed: " + condition.toString( true ) ); boolean result =
1107:                 * condition.eval();
1108:                 * 
1109:                 * if( result == false ) { System.out.println( "Unresolved Condition: " + condition );
1110:                 * 
1111:                 * return result; } }
1112:                 */
1113:                return true; // If there is no Condition defined, just create the shortcut.
1114:            }
1115:
1116:            /*--------------------------------------------------------------------------*/
1117:
1118:            /**
1119:             * Enables Shortcutcreation from outside, e.g. from an InstallerListener.
1120:             * The Installerlistener can switch the flag "createImmediately" to false on initialisation, and call this method when afterpacks is performed.
1121:             * This makes only sense, if the ShorcutPanel is displayed before the files are copied onto the disk.
1122:             */
1123:            public void createAndRegisterShortcuts() {
1124:                createShortcuts();
1125:                addToUninstaller();
1126:            }
1127:
1128:            private String createXDGMenu(ArrayList shortcuts, String menuName) {
1129:                String menuConfigText = "<Menu>\n"
1130:                        + "<Name>Applications</Name>\n"
1131:                        + "<Menu>\n"
1132:                        +
1133:                        // Ubuntu can't handle spaces, replace with "-"
1134:                        "<Directory>" + menuName.replaceAll(" ", "-")
1135:                        + "-izpack.directory</Directory>\n" + "<Name>"
1136:                        + menuName + "</Name>\n" + "<Include>\n";
1137:
1138:                for (Object shortcut1 : shortcuts) {
1139:                    String shortcutFile = (String) shortcut1;
1140:                    menuConfigText += "<Filename>" + shortcutFile
1141:                            + "</Filename>\n";
1142:                }
1143:                menuConfigText += "</Include>\n</Menu>\n</Menu>";
1144:                return menuConfigText;
1145:
1146:            }
1147:
1148:            private String createXDGDirectory(String menuName, String icon,
1149:                    String comment) {
1150:                String menuDirectoryDescriptor = "[Desktop Entry]\n"
1151:                        + "Name=$Name\n" + "Comment=$Comment\n"
1152:                        + "Icon=$Icon\n" + "Type=Directory\n"
1153:                        + "Encoding=UTF-8";
1154:                menuDirectoryDescriptor = StringTool.replace(
1155:                        menuDirectoryDescriptor, "$Name", menuName);
1156:                menuDirectoryDescriptor = StringTool.replace(
1157:                        menuDirectoryDescriptor, "$Comment", comment);
1158:                menuDirectoryDescriptor = StringTool.replace(
1159:                        menuDirectoryDescriptor, "$Icon", icon);
1160:                return menuDirectoryDescriptor;
1161:            }
1162:
1163:            private void writeXDGMenuFile(ArrayList desktopFileNames,
1164:                    String groupName, String icon, String comment) {
1165:                if ("".equals(suggestedProgramGroup)
1166:                        || suggestedProgramGroup == null)
1167:                    return; // No group name means the shortcuts
1168:                // will be placed by category
1169:                if (OsVersion.IS_UNIX) {
1170:                    String menuFile = createXDGMenu(desktopFileNames, groupName);
1171:                    String dirFile = createXDGDirectory(groupName, icon,
1172:                            comment);
1173:                    String menuFolder;
1174:                    String directoryFolder;
1175:                    if (itsUserType == Shortcut.ALL_USERS) {
1176:                        menuFolder = "/etc/xdg/menus/applications-merged/";
1177:                        directoryFolder = "/usr/share/desktop-directories/";
1178:                    } else {
1179:                        menuFolder = System.getProperty("user.home")
1180:                                + File.separator
1181:                                + ".config/menus/applications-merged/";
1182:                        directoryFolder = System.getProperty("user.home")
1183:                                + File.separator
1184:                                + ".local/share/desktop-directories/";
1185:                    }
1186:                    File menuFolderFile = new File(menuFolder);
1187:                    File directoryFolderFile = new File(directoryFolder);
1188:                    String menuFilePath = menuFolder + groupName + ".menu";
1189:                    // Ubuntu can't handle spaces in the directory file name
1190:                    String dirFilePath = directoryFolder
1191:                            + groupName.replaceAll(" ", "-")
1192:                            + "-izpack.directory";
1193:                    menuFolderFile.mkdirs();
1194:                    directoryFolderFile.mkdirs();
1195:                    writeString(menuFile, menuFilePath);
1196:                    writeString(dirFile, dirFilePath);
1197:                }
1198:
1199:            }
1200:
1201:            private void writeString(String str, String file) {
1202:                boolean failed = false;
1203:                try {
1204:                    FileWriter writer = new FileWriter(file);
1205:                    writer.write(str);
1206:                    writer.close();
1207:                } catch (Exception ignore) {
1208:                    failed = true;
1209:                    Debug.log("Failed to create menu for gnome.");
1210:                }
1211:                if (!failed)
1212:                    UninstallData.getInstance().addFile(file, true);
1213:            }
1214:
1215:            /*--------------------------------------------------------------------------*/
1216:
1217:            /**
1218:             * Creates all shortcuts based on the information in shortcuts.
1219:             */
1220:
1221:            /*--------------------------------------------------------------------------*/
1222:            private void createShortcuts() {
1223:                if (!create) {
1224:                    Debug.log(this .getClass().getName()
1225:                            + "::createShortcuts():create=" + create);
1226:                    return;
1227:                }
1228:
1229:                ShortcutData data;
1230:
1231:                //fix: don't influence other shortcuts when altering group name...
1232:                String gn = groupName;
1233:
1234:                ArrayList startMenuShortcuts = new ArrayList();
1235:                for (int i = 0; i < shortcuts.size(); i++) {
1236:                    data = (ShortcutData) shortcuts.elementAt(i);
1237:
1238:                    try {
1239:                        gn = groupName + data.subgroup;
1240:                        shortcut.setUserType(itsUserType);
1241:                        shortcut.setLinkName(data.name);
1242:                        shortcut.setLinkType(data.type);
1243:                        shortcut.setArguments(data.commandLine);
1244:                        shortcut.setDescription(data.description);
1245:                        shortcut.setIconLocation(data.iconFile, data.iconIndex);
1246:
1247:                        shortcut.setShowCommand(data.initialState);
1248:                        shortcut.setTargetPath(data.target);
1249:                        shortcut.setWorkingDirectory(data.workingDirectory);
1250:                        shortcut.setEncoding(data.deskTopEntryLinux_Encoding);
1251:                        shortcut.setMimetype(data.deskTopEntryLinux_MimeType);
1252:
1253:                        shortcut.setTerminal(data.deskTopEntryLinux_Terminal);
1254:                        shortcut
1255:                                .setTerminalOptions(data.deskTopEntryLinux_TerminalOptions);
1256:                        shortcut.setType(data.deskTopEntryLinux_Type);
1257:                        shortcut
1258:                                .setKdeSubstUID(data.deskTopEntryLinux_X_KDE_SubstituteUID);
1259:                        shortcut
1260:                                .setKdeUserName(data.deskTopEntryLinux_X_KDE_UserName);
1261:                        shortcut.setURL(data.deskTopEntryLinux_URL);
1262:                        shortcut.setTryExec(data.TryExec);
1263:                        shortcut.setCategories(data.Categories);
1264:                        shortcut.setCreateForAll(data.createForAll);
1265:
1266:                        shortcut.setUninstaller(UninstallData.getInstance());
1267:
1268:                        if (data.addToGroup) {
1269:                            shortcut.setProgramGroup(gn);
1270:                        } else {
1271:                            shortcut.setProgramGroup("");
1272:                        }
1273:
1274:                        try {
1275:                            // ----------------------------------------------
1276:                            // save the shortcut only if it is either not on
1277:                            // the desktop or if it is on the desktop and
1278:                            // the user has signalled that it is ok to place
1279:                            // shortcuts on the desktop.
1280:                            // ----------------------------------------------
1281:                            if ((data.type != Shortcut.DESKTOP)
1282:                                    || ((data.type == Shortcut.DESKTOP) && allowDesktopShortcut
1283:                                            .isSelected())) {
1284:
1285:                                // save the shortcut
1286:                                shortcut.save();
1287:
1288:                                if (data.type == Shortcut.APPLICATIONS
1289:                                        || data.addToGroup) {
1290:                                    if (shortcut instanceof  com.izforge.izpack.util.os.Unix_Shortcut) {
1291:                                        com.izforge.izpack.util.os.Unix_Shortcut unixcut = (com.izforge.izpack.util.os.Unix_Shortcut) shortcut;
1292:                                        Object f = unixcut.getWrittenFileName();
1293:                                        if (f != null)
1294:                                            startMenuShortcuts.add(f);
1295:                                    }
1296:                                }
1297:                                // add the file and directory name to the file list
1298:                                String fileName = shortcut.getFileName();
1299:                                files.add(0, fileName);
1300:
1301:                                File file = new File(fileName);
1302:                                File base = new File(shortcut.getBasePath());
1303:                                Vector<File> intermediates = new Vector<File>();
1304:
1305:                                // String directoryName = shortcut.getDirectoryCreated ();
1306:                                execFiles.add(new ExecutableFile(fileName,
1307:                                        ExecutableFile.UNINSTALL,
1308:                                        ExecutableFile.IGNORE,
1309:                                        new ArrayList<OsConstraint>(), false));
1310:
1311:                                files.add(fileName);
1312:
1313:                                while ((file = file.getParentFile()) != null) {
1314:                                    if (file.equals(base)) {
1315:                                        break;
1316:                                    }
1317:
1318:                                    intermediates.add(file);
1319:                                }
1320:
1321:                                if (file != null) {
1322:                                    Enumeration<File> filesEnum = intermediates
1323:                                            .elements();
1324:
1325:                                    while (filesEnum.hasMoreElements()) {
1326:                                        files.add(0, filesEnum.nextElement()
1327:                                                .toString());
1328:                                    }
1329:                                }
1330:                            }
1331:                        } catch (Exception exception) {
1332:                        }
1333:                    } catch (Throwable exception) {
1334:                    }
1335:                }
1336:                if (OsVersion.IS_UNIX)
1337:                    writeXDGMenuFile(startMenuShortcuts, groupName,
1338:                            programGroupIconFile, programGroupComment);
1339:                shortcut.execPostAction();
1340:
1341:                try {
1342:                    if (execFiles != null) {
1343:                        FileExecutor executor = new FileExecutor(execFiles);
1344:
1345:                        // 
1346:                        // TODO: Hi Guys,
1347:                        // TODO The following commented-out line sometimes produces an uncatchable
1348:                        // nullpointer Exception!
1349:                        // TODO evaluate for what reason the files should exec.
1350:                        // TODO if there is a serious explanation, why to do that,
1351:                        // TODO the code must be more robust
1352:                        // evaluate executor.executeFiles( ExecutableFile.NEVER, null );
1353:                    }
1354:                } catch (NullPointerException nep) {
1355:                    nep.printStackTrace();
1356:                } catch (RuntimeException cannot) {
1357:                    cannot.printStackTrace();
1358:                }
1359:
1360:                shortcut.cleanUp();
1361:            }
1362:
1363:            /*--------------------------------------------------------------------------*/
1364:
1365:            /**
1366:             * Verifies if the shortcut is required for any of the packs listed. The shortcut is required
1367:             * for a pack in the list if that pack is actually selected for installation. Note: If the list
1368:             * of selected packs is empty then true is always returnd. The same is true if the packs list is
1369:             * empty.
1370:             * 
1371:             * @param packs a Vector of Strings. Each of the strings denotes a pack for which the schortcut
1372:             * should be created if the pack is actually installed.
1373:             * 
1374:             * @return true if the shortcut is required for at least on pack in the list, otherwise returns
1375:             * false.
1376:             */
1377:
1378:            /*--------------------------------------------------------------------------*/
1379:            /*
1380:             * $ @design
1381:             * 
1382:             * The information about the installed packs comes from InstallData.selectedPacks. This assumes
1383:             * that this panel is presented to the user AFTER the PacksPanel.
1384:             * --------------------------------------------------------------------------
1385:             */
1386:            private boolean shortcutRequiredFor(Vector<XMLElement> packs) {
1387:                String selected;
1388:                String required;
1389:
1390:                if (packs.size() == 0) {
1391:                    return (true);
1392:                }
1393:
1394:                for (int i = 0; i < idata.selectedPacks.size(); i++) {
1395:                    selected = ((Pack) idata.selectedPacks.get(i)).name;
1396:
1397:                    for (int k = 0; k < packs.size(); k++) {
1398:                        required = (packs.elementAt(k)).getAttribute(
1399:                                SPEC_ATTRIBUTE_NAME, "");
1400:
1401:                        if (selected.equals(required)) {
1402:                            return (true);
1403:                        }
1404:                    }
1405:                }
1406:
1407:                return (false);
1408:            }
1409:
1410:            /*--------------------------------------------------------------------------*/
1411:
1412:            /**
1413:             * Replaces any ocurrence of '/' or '\' in a path string with the correct version for the
1414:             * operating system.
1415:             * 
1416:             * @param path a system path
1417:             * 
1418:             * @return a path string that uniformely uses the proper version of the separator character.
1419:             */
1420:
1421:            /*--------------------------------------------------------------------------*/
1422:            private String fixSeparatorChar(String path) {
1423:                String newPath = path.replace('/', File.separatorChar);
1424:                newPath = newPath.replace('\\', File.separatorChar);
1425:
1426:                return (newPath);
1427:            }
1428:
1429:            /*--------------------------------------------------------------------------*/
1430:
1431:            /**
1432:             * This method creates the UI for this panel.
1433:             * 
1434:             * @param groups A Vector that contains Strings with all the names of the existing program
1435:             * groups. These will be placed in the groupList.
1436:             */
1437:
1438:            /*--------------------------------------------------------------------------*/
1439:            private void buildUI(File groups) {
1440:                constraints.insets = new Insets(10, 10, 0, 0);
1441:
1442:                // Add a CheckBox which enables the user to entirely supress shortcut creation.
1443:                String menuKind = parent.langpack
1444:                        .getString("ShortcutPanel.regular.StartMenu:Start-Menu");
1445:
1446:                if (OsVersion.IS_UNIX && UnixHelper.kdeIsInstalled()) {
1447:                    menuKind = parent.langpack
1448:                            .getString("ShortcutPanel.regular.StartMenu:K-Menu");
1449:                }
1450:
1451:                createShortcuts = new JCheckBox(StringTool.replace(
1452:                        parent.langpack
1453:                                .getString("ShortcutPanel.regular.create"),
1454:                        "StartMenu", menuKind), true);
1455:                createShortcuts.addActionListener(this );
1456:                constraints.gridx = col;
1457:                constraints.gridy = line + 1;
1458:                constraints.gridwidth = 1;
1459:                constraints.gridheight = 1;
1460:
1461:                // constraints.weightx = 0.1;
1462:                // constraints.weighty = 0.2;
1463:                constraints.fill = GridBagConstraints.HORIZONTAL;
1464:                constraints.anchor = GridBagConstraints.NORTHWEST;
1465:
1466:                layout.addLayoutComponent(createShortcuts, constraints);
1467:                add(createShortcuts);
1468:
1469:                constraints.insets = new Insets(0, 10, 0, 0);
1470:
1471:                // ----------------------------------------------------
1472:                // check box to allow the user to decide if a desktop
1473:                // shortcut should be created.
1474:                // this should only be created if needed and requested
1475:                // in the definition file.
1476:                // ----------------------------------------------------
1477:                if (hasDesktopShortcuts) {
1478:                    String initialAllowedValue = idata
1479:                            .getVariable("DesktopShortcutCheckboxEnabled");
1480:                    boolean initialAllowedFlag = false;
1481:
1482:                    if (initialAllowedValue == null) {
1483:                        initialAllowedFlag = false;
1484:                    } else if (Boolean.TRUE.toString().equals(
1485:                            initialAllowedValue)) {
1486:                        initialAllowedFlag = true;
1487:                    }
1488:
1489:                    allowDesktopShortcut = new JCheckBox(parent.langpack
1490:                            .getString("ShortcutPanel.regular.desktop"),
1491:                            initialAllowedFlag);
1492:                    constraints.gridx = col;
1493:                    constraints.gridy = line + 2;
1494:                    constraints.gridwidth = 1;
1495:                    constraints.gridheight = 1;
1496:
1497:                    // constraints.weighty = 0.2;
1498:                    // constraints.weighty = 1.0;
1499:                    // constraints.weighty = 0.5;
1500:                    layout
1501:                            .addLayoutComponent(allowDesktopShortcut,
1502:                                    constraints);
1503:                    add(allowDesktopShortcut);
1504:                }
1505:
1506:                listLabel = LabelFactory.create(parent.langpack
1507:                        .getString("ShortcutPanel.regular.list"),
1508:                        JLabel.LEADING);
1509:                if (OsVersion.IS_WINDOWS) {
1510:                    constraints.gridx = col;
1511:                    constraints.gridy = line + 3;
1512:
1513:                    constraints.gridwidth = 1;
1514:                    constraints.gridheight = 1;
1515:
1516:                    constraints.insets = new Insets(10, 10, 0, 0);
1517:
1518:                    constraints.fill = GridBagConstraints.HORIZONTAL;
1519:                    constraints.anchor = GridBagConstraints.NORTHWEST;
1520:                } else {
1521:                    constraints.gridx = col;
1522:                    constraints.gridy = line + 4;
1523:
1524:                    constraints.gridwidth = 1;
1525:                    constraints.gridheight = 1;
1526:
1527:                    constraints.insets = new Insets(10, 10, 0, 0);
1528:
1529:                    constraints.fill = GridBagConstraints.HORIZONTAL;
1530:                    constraints.anchor = GridBagConstraints.SOUTHWEST;
1531:                }
1532:                layout.addLayoutComponent(listLabel, constraints);
1533:                add(listLabel);
1534:
1535:                // ----------------------------------------------------
1536:                // list box to list all of already existing folders as program groups
1537:                // at the intended destination
1538:                // ----------------------------------------------------
1539:                Vector<String> dirEntries = new Vector<String>();
1540:
1541:                File[] entries = groups.listFiles();
1542:
1543:                // Quickfix prevent NullPointer on non default compliant Linux - KDEs
1544:                // i.e Mandrake 2005 LE stores from now also in "applnk" instead in prior "applnk-mdk":
1545:                if (entries != null && !OsVersion.IS_UNIX) {
1546:                    for (File entry : entries) {
1547:                        if (entry.isDirectory()) {
1548:                            dirEntries.add(entry.getName());
1549:                        }
1550:                    }
1551:                }
1552:                if (OsVersion.IS_WINDOWS) {
1553:                    if (groupList == null) {
1554:                        groupList = new JList();
1555:                    }
1556:
1557:                    groupList = addList(dirEntries,
1558:                            ListSelectionModel.SINGLE_SELECTION, groupList,
1559:                            col, line + 4, 1, 1, GridBagConstraints.BOTH);
1560:                }
1561:
1562:                // ----------------------------------------------------
1563:                // radio buttons to select current user or all users.
1564:                // ----------------------------------------------------
1565:                if (shortcut.multipleUsers()) {
1566:                    JPanel usersPanel = new JPanel(new GridLayout(2, 1));
1567:                    ButtonGroup usersGroup = new ButtonGroup();
1568:                    currentUser = new JRadioButton(parent.langpack
1569:                            .getString("ShortcutPanel.regular.currentUser"),
1570:                            !isRootUser);
1571:                    currentUser.addActionListener(this );
1572:                    usersGroup.add(currentUser);
1573:                    usersPanel.add(currentUser);
1574:                    allUsers = new JRadioButton(parent.langpack
1575:                            .getString("ShortcutPanel.regular.allUsers"),
1576:                            isRootUser);
1577:
1578:                    Debug.log("allUsers.setEnabled(), I'm Root: " + isRootUser);
1579:
1580:                    allUsers.setEnabled(isRootUser);
1581:
1582:                    allUsers.addActionListener(this );
1583:                    usersGroup.add(allUsers);
1584:                    usersPanel.add(allUsers);
1585:
1586:                    TitledBorder border = new TitledBorder(new EmptyBorder(2,
1587:                            2, 2, 2), parent.langpack
1588:                            .getString("ShortcutPanel.regular.userIntro"));
1589:                    usersPanel.setBorder(border);
1590:                    if (OsVersion.IS_WINDOWS) {
1591:                        constraints.gridx = col + 1;
1592:                        constraints.gridy = line + 4;
1593:                        constraints.gridwidth = 1;
1594:                        constraints.gridheight = 1;
1595:                    } else {
1596:                        constraints.insets = new Insets(10, 10, 20, 0);
1597:                        constraints.gridx = col;
1598:                        constraints.gridy = line + 4;
1599:                        constraints.gridwidth = 2;
1600:                        constraints.gridheight = 1;
1601:                        constraints.anchor = GridBagConstraints.EAST;
1602:                    }
1603:
1604:                    // constraints.weighty = 1.0;
1605:                    // constraints.weightx = 1.0;
1606:                    constraints.fill = GridBagConstraints.HORIZONTAL;
1607:                    layout.addLayoutComponent(usersPanel, constraints);
1608:                    add(usersPanel);
1609:                }
1610:
1611:                // ----------------------------------------------------
1612:                // edit box that contains the suggested program group
1613:                // name, which can be modfied or substituted from the
1614:                // list by the user
1615:                // ----------------------------------------------------
1616:                programGroup = new JTextField(suggestedProgramGroup, 40); // 40?
1617:
1618:                constraints.gridx = col;
1619:                constraints.gridy = line + 5;
1620:                constraints.gridwidth = 1;
1621:                constraints.gridheight = 1;
1622:
1623:                // constraints.weighty = 1.0;
1624:                // constraints.weightx = 1.0;
1625:                constraints.fill = GridBagConstraints.HORIZONTAL;
1626:                layout.addLayoutComponent(programGroup, constraints);
1627:                add(programGroup);
1628:
1629:                // ----------------------------------------------------
1630:                // reset button that allows the user to revert to the
1631:                // original suggestion for the program group
1632:                // ----------------------------------------------------
1633:                defaultButton = ButtonFactory.createButton(parent.langpack
1634:                        .getString("ShortcutPanel.regular.default"),
1635:                        idata.buttonsHColor);
1636:                defaultButton.addActionListener(this );
1637:
1638:                constraints.gridx = col + 1;
1639:                constraints.gridy = line + 5;
1640:                constraints.gridwidth = 1;
1641:                constraints.gridheight = 1;
1642:                constraints.fill = GridBagConstraints.HORIZONTAL;
1643:                layout.addLayoutComponent(defaultButton, constraints);
1644:                add(defaultButton);
1645:
1646:                if (suggestedProgramGroup == null
1647:                        || "".equals(suggestedProgramGroup)) {
1648:                    programGroup.setVisible(false);
1649:                    defaultButton.setVisible(false);
1650:                    listLabel.setVisible(false);
1651:                }
1652:            }
1653:
1654:            /**
1655:             * Adds the grouplist to the panel
1656:             * 
1657:             * @param Entries the entries to display
1658:             * @param ListModel the model to use
1659:             * @param aJList the JList to use
1660:             * @param aGridx The X position in the gridbag layout.
1661:             * @param aGridy The Y position in the gridbag layout.
1662:             * @param aGridwidth the gridwith to use in the gridbag layout.
1663:             * @param aGridheight the gridheight to use in the gridbag layout.
1664:             * @param aFill the FILL to use in the gridbag layout.
1665:             * 
1666:             * @return the filled JList
1667:             */
1668:            private JList addList(Vector<String> Entries, int ListModel,
1669:                    JList aJList, int aGridx, int aGridy, int aGridwidth,
1670:                    int aGridheight, int aFill) {
1671:                if (aJList == null) {
1672:                    aJList = new JList(Entries);
1673:                } else {
1674:                    aJList.setListData(Entries);
1675:                }
1676:
1677:                aJList.setSelectionMode(ListModel);
1678:                aJList.getSelectionModel().addListSelectionListener(this );
1679:
1680:                JScrollPane scrollPane = new JScrollPane(aJList);
1681:
1682:                constraints.gridx = aGridx;
1683:                constraints.gridy = aGridy;
1684:                constraints.gridwidth = aGridwidth;
1685:                constraints.gridheight = aGridheight;
1686:                constraints.weightx = 2.0;
1687:                constraints.weighty = 1.5;
1688:                constraints.insets = new Insets(5, 5, 5, 5);
1689:                constraints.fill = aFill;
1690:                layout.addLayoutComponent(scrollPane, constraints);
1691:                add(scrollPane);
1692:
1693:                return aJList;
1694:            }
1695:
1696:            /**
1697:             * This method creates an alternative UI for this panel. This UI can be used when the creation
1698:             * of shortcuts is not supported on the target system. It displays an apology for the inability
1699:             * to create shortcuts on this system, along with information about the intended targets. In
1700:             * addition, there is a button that allows the user to save more complete information in a text
1701:             * file. Based on this information the user might be able to create the necessary shortcut him
1702:             * or herself. At least there will be information about how to launch the application.
1703:             */
1704:
1705:            /*--------------------------------------------------------------------------*/
1706:            private void buildAlternateUI() {
1707:                layout = new GridBagLayout();
1708:                constraints = new GridBagConstraints();
1709:                setLayout(layout);
1710:
1711:                // ----------------------------------------------------
1712:                // static text a the top of the panel, that apologizes
1713:                // about the fact that we can not create shortcuts on
1714:                // this particular target OS.
1715:                // ----------------------------------------------------
1716:                MultiLineLabel apologyLabel = new MultiLineLabel(
1717:                        parent.langpack
1718:                                .getString("ShortcutPanel.alternate.apology"),
1719:                        0, 0);
1720:
1721:                constraints.gridx = 0;
1722:                constraints.gridy = 0;
1723:                constraints.gridwidth = 1;
1724:                constraints.gridheight = 1;
1725:                constraints.weightx = 1.0;
1726:                constraints.weighty = 1.0;
1727:                constraints.insets = new Insets(5, 5, 5, 5);
1728:                constraints.fill = GridBagConstraints.HORIZONTAL;
1729:                constraints.anchor = GridBagConstraints.WEST;
1730:                layout.addLayoutComponent(apologyLabel, constraints);
1731:                add(apologyLabel);
1732:
1733:                // ----------------------------------------------------
1734:                // label that explains the significance ot the list box
1735:                // ----------------------------------------------------
1736:                MultiLineLabel listLabel = new MultiLineLabel(parent.langpack
1737:                        .getString("ShortcutPanel.alternate.targetsLabel"), 0,
1738:                        0);
1739:
1740:                constraints.gridx = 0;
1741:                constraints.gridy = 1;
1742:                constraints.gridwidth = 1;
1743:                constraints.gridheight = 1;
1744:                constraints.weightx = 1.0;
1745:                constraints.weighty = 1.0;
1746:                layout.addLayoutComponent(listLabel, constraints);
1747:                add(listLabel);
1748:
1749:                // ----------------------------------------------------
1750:                // list box to list all of the intended shortcut targets
1751:                // ----------------------------------------------------
1752:                Vector<String> targets = new Vector<String>();
1753:
1754:                for (int i = 0; i < shortcuts.size(); i++) {
1755:                    targets.add(((ShortcutData) shortcuts.elementAt(i)).target);
1756:                }
1757:
1758:                targetList = new JList(targets);
1759:
1760:                JScrollPane scrollPane = new JScrollPane(targetList);
1761:
1762:                constraints.gridx = 0;
1763:                constraints.gridy = 2;
1764:                constraints.fill = GridBagConstraints.BOTH;
1765:                layout.addLayoutComponent(scrollPane, constraints);
1766:                add(scrollPane);
1767:
1768:                // ----------------------------------------------------
1769:                // static text that explains about the text file
1770:                // ----------------------------------------------------
1771:                MultiLineLabel fileExplanation = new MultiLineLabel(
1772:                        parent.langpack
1773:                                .getString("ShortcutPanel.alternate.textFileExplanation"),
1774:                        0, 0);
1775:
1776:                constraints.gridx = 0;
1777:                constraints.gridy = 3;
1778:                constraints.weightx = 1.0;
1779:                constraints.weighty = 1.0;
1780:                constraints.fill = GridBagConstraints.HORIZONTAL;
1781:                layout.addLayoutComponent(fileExplanation, constraints);
1782:                add(fileExplanation);
1783:
1784:                // ----------------------------------------------------
1785:                // button to save the text file
1786:                // ----------------------------------------------------
1787:                saveButton = ButtonFactory.createButton(parent.langpack
1788:                        .getString("ShortcutPanel.alternate.saveButton"),
1789:                        idata.buttonsHColor);
1790:                saveButton.addActionListener(this );
1791:
1792:                constraints.gridx = 0;
1793:                constraints.gridy = 4;
1794:                constraints.gridwidth = 1;
1795:                constraints.gridheight = 1;
1796:                constraints.fill = GridBagConstraints.NONE;
1797:                constraints.anchor = GridBagConstraints.CENTER;
1798:                layout.addLayoutComponent(saveButton, constraints);
1799:                add(saveButton);
1800:            }
1801:
1802:            /*--------------------------------------------------------------------------*/
1803:
1804:            /**
1805:             * Overriding the superclass implementation. This method returns the size of the container.
1806:             * 
1807:             * @return the size of the container
1808:             */
1809:
1810:            /*--------------------------------------------------------------------------*/
1811:            public Dimension getSize() {
1812:                Dimension size = getParent().getSize();
1813:                Insets insets = getInsets();
1814:                Border border = getBorder();
1815:                Insets borderInsets = new Insets(0, 0, 0, 0);
1816:
1817:                if (border != null) {
1818:                    borderInsets = border.getBorderInsets(this );
1819:                }
1820:
1821:                size.height = size.height - insets.top - insets.bottom
1822:                        - borderInsets.top - borderInsets.bottom - 50;
1823:                size.width = size.width - insets.left - insets.right
1824:                        - borderInsets.left - borderInsets.right - 50;
1825:
1826:                return (size);
1827:            }
1828:
1829:            /*--------------------------------------------------------------------------*/
1830:
1831:            /**
1832:             * This method saves all shortcut information to a text file.
1833:             */
1834:
1835:            /*--------------------------------------------------------------------------*/
1836:            private void saveToFile() {
1837:                File file = null;
1838:
1839:                // ----------------------------------------------------
1840:                // open a file chooser dialog to get a path / file name
1841:                // ----------------------------------------------------
1842:                JFileChooser fileDialog = new JFileChooser(idata
1843:                        .getInstallPath());
1844:                fileDialog.setSelectedFile(new File(TEXT_FILE_NAME));
1845:
1846:                if (fileDialog.showSaveDialog(this ) == JFileChooser.APPROVE_OPTION) {
1847:                    file = fileDialog.getSelectedFile();
1848:                } else {
1849:                    return;
1850:                }
1851:
1852:                // ----------------------------------------------------
1853:                // save to the file
1854:                // ----------------------------------------------------
1855:                FileWriter output = null;
1856:                StringBuffer buffer = new StringBuffer();
1857:                String header = parent.langpack
1858:                        .getString("ShortcutPanel.textFile.header");
1859:
1860:                String newline = System.getProperty("line.separator", "\n");
1861:
1862:                try {
1863:                    output = new FileWriter(file);
1864:                } catch (Throwable exception) {
1865:                    // !!! show an error dialog
1866:                    return;
1867:                }
1868:
1869:                // ----------------------------------------------------
1870:                // break the header down into multiple lines based
1871:                // on '\n' line breaks.
1872:                // ----------------------------------------------------
1873:                int nextIndex = 0;
1874:                int currentIndex = 0;
1875:
1876:                do {
1877:                    nextIndex = header.indexOf("\\n", currentIndex);
1878:
1879:                    if (nextIndex > -1) {
1880:                        buffer
1881:                                .append(header.substring(currentIndex,
1882:                                        nextIndex));
1883:                        buffer.append(newline);
1884:                        currentIndex = nextIndex + 2;
1885:                    } else {
1886:                        buffer.append(header.substring(currentIndex, header
1887:                                .length()));
1888:                        buffer.append(newline);
1889:                    }
1890:                } while (nextIndex > -1);
1891:
1892:                buffer.append(SEPARATOR_LINE);
1893:                buffer.append(newline);
1894:                buffer.append(newline);
1895:
1896:                for (int i = 0; i < shortcuts.size(); i++) {
1897:                    ShortcutData data = (ShortcutData) shortcuts.elementAt(i);
1898:
1899:                    buffer.append(parent.langpack
1900:                            .getString("ShortcutPanel.textFile.name"));
1901:                    buffer.append(data.name);
1902:                    buffer.append(newline);
1903:
1904:                    buffer.append(parent.langpack
1905:                            .getString("ShortcutPanel.textFile.location"));
1906:
1907:                    switch (data.type) {
1908:                    case Shortcut.DESKTOP: {
1909:                        buffer.append(parent.langpack
1910:                                .getString("ShortcutPanel.location.desktop"));
1911:
1912:                        break;
1913:                    }
1914:
1915:                    case Shortcut.APPLICATIONS: {
1916:                        buffer
1917:                                .append(parent.langpack
1918:                                        .getString("ShortcutPanel.location.applications"));
1919:
1920:                        break;
1921:                    }
1922:
1923:                    case Shortcut.START_MENU: {
1924:                        buffer.append(parent.langpack
1925:                                .getString("ShortcutPanel.location.startMenu"));
1926:
1927:                        break;
1928:                    }
1929:
1930:                    case Shortcut.START_UP: {
1931:                        buffer.append(parent.langpack
1932:                                .getString("ShortcutPanel.location.startup"));
1933:
1934:                        break;
1935:                    }
1936:                    }
1937:
1938:                    buffer.append(newline);
1939:
1940:                    buffer.append(parent.langpack
1941:                            .getString("ShortcutPanel.textFile.description"));
1942:                    buffer.append(data.description);
1943:                    buffer.append(newline);
1944:
1945:                    buffer.append(parent.langpack
1946:                            .getString("ShortcutPanel.textFile.target"));
1947:                    buffer.append(data.target);
1948:                    buffer.append(newline);
1949:
1950:                    buffer.append(parent.langpack
1951:                            .getString("ShortcutPanel.textFile.command"));
1952:                    buffer.append(data.commandLine);
1953:                    buffer.append(newline);
1954:
1955:                    buffer.append(parent.langpack
1956:                            .getString("ShortcutPanel.textFile.iconName"));
1957:                    buffer.append(data.iconFile);
1958:                    buffer.append(newline);
1959:
1960:                    buffer.append(parent.langpack
1961:                            .getString("ShortcutPanel.textFile.iconIndex"));
1962:                    buffer.append(data.iconIndex);
1963:                    buffer.append(newline);
1964:
1965:                    buffer.append(parent.langpack
1966:                            .getString("ShortcutPanel.textFile.work"));
1967:                    buffer.append(data.workingDirectory);
1968:                    buffer.append(newline);
1969:
1970:                    buffer.append(newline);
1971:                    buffer.append(SEPARATOR_LINE);
1972:                    buffer.append(newline);
1973:                    buffer.append(newline);
1974:                }
1975:
1976:                try {
1977:                    output.write(buffer.toString());
1978:                } catch (Throwable exception) {
1979:                } finally {
1980:                    try {
1981:                        output.flush();
1982:                        output.close();
1983:                        files.add(file.getPath());
1984:                    } catch (Throwable exception) {
1985:                        // not really anything I can do here, maybe should show a dialog that
1986:                        // tells the user that data might not have been saved completely!?
1987:                    }
1988:                }
1989:            }
1990:
1991:            /*--------------------------------------------------------------------------*/
1992:
1993:            /**
1994:             * Adds all files and directories to the uninstaller.
1995:             */
1996:
1997:            /*--------------------------------------------------------------------------*/
1998:            private void addToUninstaller() {
1999:                UninstallData uninstallData = UninstallData.getInstance();
2000:
2001:                for (int i = 0; i < files.size(); i++) {
2002:                    uninstallData.addFile(files.elementAt(i), true);
2003:                }
2004:            }
2005:
2006:            /*--------------------------------------------------------------------------*/
2007:
2008:            /**
2009:             * Returns Instance of themself 
2010:             */
2011:            public static ShortcutPanel getInstance() {
2012:                return self;
2013:            }
2014:
2015:            /*--------------------------------------------------------------------------*/
2016:            /*
2017:             * 
2018:             * 
2019:             * The information needed to create shortcuts has been collected in the Vector 'shortcuts'. Take
2020:             * the data from there and package it in XML form for storage by the installer. The group name
2021:             * is only stored once in a separate XML element, since there is only one.
2022:             * --------------------------------------------------------------------------
2023:             */
2024:            public void makeXMLData(XMLElement panelRoot) {
2025:                // ----------------------------------------------------
2026:                // if there are no shortcuts to create, shortcuts are
2027:                // not supported, or we should simulate that they are
2028:                // not supported, then we have nothing to add. Just
2029:                // return
2030:                // ----------------------------------------------------
2031:                Debug.log("entering makeXMLData");
2032:
2033:                if (!shortcutsToCreate || !shortcut.supported()
2034:                        || (groupName == null) || simulteNotSupported
2035:                        || !create) {
2036:                    Debug.log("abort makeXMLData!");
2037:                    return;
2038:                }
2039:
2040:                ShortcutData data;
2041:                XMLElement dataElement;
2042:
2043:                // ----------------------------------------------------
2044:                // add the item that defines the name of the program group
2045:                // ----------------------------------------------------
2046:                dataElement = new XMLElement(AUTO_KEY_PROGRAM_GROUP);
2047:                dataElement.setAttribute(AUTO_ATTRIBUTE_NAME, groupName);
2048:                panelRoot.addChild(dataElement);
2049:
2050:                // ----------------------------------------------------
2051:                // add the details for each of the shortcuts
2052:                // ----------------------------------------------------
2053:                for (int i = 0; i < shortcuts.size(); i++) {
2054:                    Debug.log("entering makeXMLData");
2055:                    data = (ShortcutData) shortcuts.elementAt(i);
2056:                    dataElement = new XMLElement(AUTO_KEY_SHORTCUT);
2057:
2058:                    dataElement.setAttribute(AUTO_ATTRIBUTE_NAME, data.name);
2059:                    dataElement.setAttribute(AUTO_ATTRIBUTE_GROUP,
2060:                            (data.addToGroup ? Boolean.TRUE : Boolean.FALSE)
2061:                                    .toString());
2062:
2063:                    // Boolean.valueOf(data.addToGroup)
2064:                    if (OsVersion.IS_WINDOWS)
2065:
2066:                        dataElement.setAttribute(AUTO_ATTRIBUTE_TYPE, Integer
2067:                                .toString(data.type));
2068:                    dataElement.setAttribute(AUTO_ATTRIBUTE_COMMAND,
2069:                            data.commandLine);
2070:                    dataElement.setAttribute(AUTO_ATTRIBUTE_DESCRIPTION,
2071:                            data.description);
2072:                    dataElement
2073:                            .setAttribute(AUTO_ATTRIBUTE_ICON, data.iconFile);
2074:                    dataElement.setAttribute(AUTO_ATTRIBUTE_ICON_INDEX, Integer
2075:                            .toString(data.iconIndex));
2076:                    dataElement.setAttribute(AUTO_ATTRIBUTE_INITIAL_STATE,
2077:                            Integer.toString(data.initialState));
2078:                    dataElement
2079:                            .setAttribute(AUTO_ATTRIBUTE_TARGET, data.target);
2080:                    dataElement.setAttribute(AUTO_ATTRIBUTE_WORKING_DIR,
2081:                            data.workingDirectory);
2082:
2083:                    dataElement.setAttribute(SPEC_ATTRIBUTE_ENCODING,
2084:                            data.deskTopEntryLinux_Encoding);
2085:                    dataElement.setAttribute(SPEC_ATTRIBUTE_MIMETYPE,
2086:                            data.deskTopEntryLinux_MimeType);
2087:                    dataElement.setAttribute(SPEC_ATTRIBUTE_TERMINAL,
2088:                            data.deskTopEntryLinux_Terminal);
2089:                    dataElement.setAttribute(SPEC_ATTRIBUTE_TERMINAL_OPTIONS,
2090:                            data.deskTopEntryLinux_TerminalOptions);
2091:                    if (!OsVersion.IS_WINDOWS)
2092:                        dataElement.setAttribute(SPEC_ATTRIBUTE_TYPE,
2093:                                data.deskTopEntryLinux_Type);
2094:
2095:                    dataElement.setAttribute(SPEC_ATTRIBUTE_URL,
2096:                            data.deskTopEntryLinux_URL);
2097:
2098:                    dataElement.setAttribute(SPEC_ATTRIBUTE_KDE_SUBST_UID,
2099:                            data.deskTopEntryLinux_X_KDE_SubstituteUID);
2100:                    dataElement.setAttribute(SPEC_CATEGORIES, data.Categories);
2101:                    dataElement.setAttribute(SPEC_TRYEXEC, data.TryExec);
2102:
2103:                    dataElement.setAttribute(CREATE_FOR_ALL, data.createForAll
2104:                            .toString());// ? Boolean.TRUE : Boolean.FALSE).toString() );
2105:                    dataElement.setAttribute(USER_TYPE, Integer
2106:                            .toString(data.userType));
2107:
2108:                    //TODO: Add Linux.Attibutes
2109:
2110:                    // ----------------------------------------------
2111:                    // add the shortcut only if it is either not on
2112:                    // the desktop or if it is on the desktop and
2113:                    // the user has signalled that it is ok to place
2114:                    // shortcuts on the desktop.
2115:                    // ----------------------------------------------
2116:                    if ((data.type != Shortcut.DESKTOP)
2117:                            || ((data.type == Shortcut.DESKTOP) && allowDesktopShortcut
2118:                                    .isSelected())) {
2119:                        panelRoot.addChild(dataElement);
2120:                    }
2121:                }
2122:            }
2123:
2124:            /*--------------------------------------------------------------------------*/
2125:
2126:            /**
2127:             * Creates shortcuts based on teh information in panelRoot without UI.
2128:             * 
2129:             * @param panelRoot the root of the XML tree
2130:             */
2131:
2132:            /*--------------------------------------------------------------------------*/
2133:            /*
2134:             * 
2135:             * 
2136:             * Reconstitute the information needed to create shortcuts from XML data that was previously
2137:             * stored by the installer through makeXMLData(). Create a new Vector containing this data and
2138:             * stroe it in 'shortcuts' for use by createShortcuts(). Once this has been completed, call
2139:             * createShortcuts() to complete the operation.
2140:             * --------------------------------------------------------------------------
2141:             */
2142:
2143:        }
2144:
2145:        /*---------------------------------------------------------------------------*/
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.