Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / panels / ShortcutPanel.java @ 15280

History | View | Annotate | Download (58.7 KB)

1
/*
2
 * $Id: ShortcutPanel.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
3
 *
4
 * IzPack
5
 * File is Copyright (C) 2002 Elmar Grom
6
 *
7
 * File :               ShortcutPanel.java
8
 * Description :        A panel to prompt the user to select a program group
9
 *                      and to accept creation of a desktop shortcut. This
10
 *                      panel creates shortcuts.
11
 * Author's email :     elmar@grom.net
12
 * Author's Website :   http://www.izforge.com
13
 *
14
 * This program is free software; you can redistribute it and/or
15
 * modify it under the terms of the GNU General Public License
16
 * as published by the Free Software Foundation; either version 2
17
 * of the License, or any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU General Public License
25
 * along with this program; if not, write to the Free Software
26
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27
 */
28

    
29
package   com.izforge.izpack.panels;
30

    
31
import java.awt.Dimension;
32
import java.awt.GridBagConstraints;
33
import java.awt.GridBagLayout;
34
import java.awt.GridLayout;
35
import java.awt.Insets;
36
import java.awt.event.ActionEvent;
37
import java.awt.event.ActionListener;
38
import java.io.File;
39
import java.io.FileWriter;
40
import java.io.InputStream;
41
import java.util.Iterator;
42
import java.util.Vector;
43
import java.util.ArrayList;
44

    
45
import javax.swing.ButtonGroup;
46
import javax.swing.JButton;
47
import javax.swing.JCheckBox;
48
import javax.swing.JFileChooser;
49
import javax.swing.JLabel;
50
import javax.swing.JList;
51
import javax.swing.JPanel;
52
import javax.swing.JRadioButton;
53
import javax.swing.JScrollPane;
54
import javax.swing.JTextField;
55
import javax.swing.ListSelectionModel;
56
import javax.swing.border.Border;
57
import javax.swing.border.EmptyBorder;
58
import javax.swing.border.TitledBorder;
59
import javax.swing.event.ListSelectionEvent;
60
import javax.swing.event.ListSelectionListener;
61

    
62
import net.n3.nanoxml.NonValidator;
63
import net.n3.nanoxml.StdXMLBuilder;
64
import net.n3.nanoxml.StdXMLParser;
65
import net.n3.nanoxml.StdXMLReader;
66
import net.n3.nanoxml.XMLElement;
67

    
68
import com.izforge.izpack.Pack;
69
import com.izforge.izpack.gui.ButtonFactory;
70
import com.izforge.izpack.gui.LabelFactory;
71
import com.izforge.izpack.installer.InstallData;
72
import com.izforge.izpack.installer.InstallerFrame;
73
import com.izforge.izpack.installer.IzPanel;
74
import com.izforge.izpack.installer.ResourceNotFoundException;
75
import com.izforge.izpack.installer.UninstallData;
76
import com.izforge.izpack.installer.VariableSubstitutor;
77
import com.izforge.izpack.util.FileExecutor;
78
import com.izforge.izpack.util.MultiLineLabel;
79

    
80
import com.izforge.izpack.util.OsConstraint;
81
import com.izforge.izpack.util.OsVersion;
82
import com.izforge.izpack.util.TargetFactory;
83
import com.izforge.izpack.util.os.ShellLink;
84
import com.izforge.izpack.util.os.Shortcut;
85

    
86
import com.izforge.izpack.ExecutableFile;
87
//
88
//import com.izforge.izpack.panels.ShortcutData;
89

    
90
/*---------------------------------------------------------------------------*/
91
/**
92
 * This class implements a panel for the creation of shortcuts.
93
 * The panel prompts the user to select a program group for shortcuts, accept
94
 * the creation of desktop shortcuts and actually creates the shortcuts.
95
 *
96
 * <h4>Important</h4>
97
 * It is neccesary that the installation has been completed before this panel
98
 * is called. To successfully create shortcuts this panel needs to have the
99
 * following in place: <br><br>
100
 * <ul>
101
 * <li>the launcher files that the shortcuts point to must exist
102
 * <li>it must be known which packs are installed
103
 * <li>where the launcher for the uninstaller is located
104
 * </ul>
105
 * It is ok to present other panels after this one, as long as these
106
 * conditions are met.
107
 *
108
 * @see      com.izforge.izpack.util.os.ShellLink
109
 *
110
 * @version  0.0.1 / 2/26/02
111
 * @author   Elmar Grom
112
 */
113
/*---------------------------------------------------------------------------*/
114
// !!! To Do !
115
//
116
// - see if I can't get multiple instances of the shortcut to work
117
// - need a clean way to get pack name
118

    
119

    
120

    
121
public class ShortcutPanel extends IzPanel implements ActionListener,
122
                                                      ListSelectionListener
123
{
124
  /** a VectorList of Files wich should be make executable */
125
  private Vector execFiles = new Vector();
126

    
127
  private final static String SPEC_ATTRIBUTE_KDE_SUBST_UID = "KdeSubstUID";
128
  private final static String SPEC_ATTRIBUTE_URL = "url";
129
  private final static String SPEC_ATTRIBUTE_TYPE = "type";
130
  private final static String SPEC_ATTRIBUTE_TERMINAL_OPTIONS = "terminalOptions";
131
  private final static String SPEC_ATTRIBUTE_TERMINAL = "terminal";
132
  private final static String SPEC_ATTRIBUTE_MIMETYPE = "mimetype";
133
  private final static String SPEC_ATTRIBUTE_ENCODING = "encoding";
134
  /** LOCATION_APPLICATIONS=applications **/
135
  private static final String LOCATION_APPLICATIONS     = "applications";
136
  /** LOCATION_START_MENU       = "startMenu" **/
137
  private static final String LOCATION_START_MENU       = "startMenu";
138
  /** SEPARATOR_LINE            = "--------------------------------------------------------------------------------"; **/
139
  private static final String SEPARATOR_LINE            = "--------------------------------------------------------------------------------";
140

    
141
  /** The default file name for the text file in which the shortcut
142
      information should be stored, in case shortcuts can not be
143
      created on a particular target system. */
144
  private static final String TEXT_FILE_NAME                = "Shortcuts.txt";
145

    
146
  /** The name of the XML file that specifies the shortcuts */
147
  private static final String SPEC_FILE_NAME                = "shortcutSpec.xml";
148

    
149

    
150
  // ------------------------------------------------------
151
  // spec file section keys
152
  // ------------------------------------------------------
153
  private static final String SPEC_KEY_SKIP_IFNOT_SUPPORTED = "skipIfNotSupported";
154
  private static final String SPEC_KEY_NOT_SUPPORTED        = "notSupported";
155
  private static final String SPEC_KEY_PROGRAM_GROUP        = "programGroup";
156
  private static final String SPEC_KEY_SHORTCUT             = "shortcut";
157
  private static final String SPEC_KEY_PACKS                = "createForPack";
158

    
159
  // ------------------------------------------------------
160
  // spec file key attributes
161
  // ------------------------------------------------------
162
  private static final String SPEC_ATTRIBUTE_DEFAULT_GROUP  = "defaultName";
163
  private static final String SPEC_ATTRIBUTE_LOCATION       = "location";
164
  private static final String SPEC_ATTRIBUTE_NAME           = "name";
165
  private static final String SPEC_ATTRIBUTE_SUBGROUP       = "subgroup";
166
  private static final String SPEC_ATTRIBUTE_DESCRIPTION    = "description";
167
  private static final String SPEC_ATTRIBUTE_TARGET         = "target";
168
  private static final String SPEC_ATTRIBUTE_COMMAND        = "commandLine";
169
  private static final String SPEC_ATTRIBUTE_ICON           = "iconFile";
170
  private static final String SPEC_ATTRIBUTE_ICON_INDEX     = "iconIndex";
171
  private static final String SPEC_ATTRIBUTE_WORKING_DIR    = "workingDirectory";
172
  private static final String SPEC_ATTRIBUTE_INITIAL_STATE  = "initialState";
173
  private static final String SPEC_ATTRIBUTE_DESKTOP        = "desktop";
174
  private static final String SPEC_ATTRIBUTE_APPLICATIONS   = "applications";
175
  private static final String SPEC_ATTRIBUTE_START_MENU     = "startMenu";
176
  private static final String SPEC_ATTRIBUTE_STARTUP        = "startup";
177
  private static final String SPEC_ATTRIBUTE_PROGRAM_GROUP  = "programGroup";
178

    
179
  // ------------------------------------------------------
180
  // spec file attribute values
181
  // ------------------------------------------------------
182
  private static final String SPEC_VALUE_APPLICATIONS       = "applications";
183
  private static final String SPEC_VALUE_START_MENU         = "startMenu";
184
  private static final String SPEC_VALUE_NO_SHOW            = "noShow";
185
  private static final String SPEC_VALUE_NORMAL             = "normal";
186
  private static final String SPEC_VALUE_MAXIMIZED          = "maximized";
187
  private static final String SPEC_VALUE_MINIMIZED          = "minimized";
188

    
189
  // ------------------------------------------------------
190
  // automatic script section keys
191
  // ------------------------------------------------------
192
  private static final String AUTO_KEY_PROGRAM_GROUP        = "programGroup";
193
  private static final String AUTO_KEY_SHORTCUT             = "shortcut";
194

    
195
  // ------------------------------------------------------
196
  // automatic script keys attributes
197
  // ------------------------------------------------------
198
  private static final String AUTO_ATTRIBUTE_NAME           = "name";
199
  private static final String AUTO_ATTRIBUTE_GROUP          = "group";
200
  private static final String AUTO_ATTRIBUTE_TYPE           = "type";
201
  private static final String AUTO_ATTRIBUTE_COMMAND        = "commandLine";
202
  private static final String AUTO_ATTRIBUTE_DESCRIPTION    = "description";
203
  private static final String AUTO_ATTRIBUTE_ICON           = "icon";
204
  private static final String AUTO_ATTRIBUTE_ICON_INDEX     = "iconIndex";
205
  private static final String AUTO_ATTRIBUTE_INITIAL_STATE  = "initialState";
206
  private static final String AUTO_ATTRIBUTE_TARGET         = "target";
207
  private static final String AUTO_ATTRIBUTE_WORKING_DIR    = "workingDirectory";
208

    
209

    
210
  // ------------------------------------------------------------------------
211
  // Variable Declarations
212
  // ------------------------------------------------------------------------
213

    
214
  /**  UI element to label the list of existing program groups */
215
  private JLabel listLabel;
216
  /**  UI element to present the list of existing program groups for selection */
217
  private JList groupList;
218
  /**  UI element for listing the intended shortcut targets */
219
  private JList targetList;
220
  /**
221
   *  UI element to present the default name for the program group and to
222
   *  support editing of this name.
223
   */
224
  private JTextField programGroup;
225
  /**
226
   *  UI element to allow the user to revert to the default name of the program
227
   *  group
228
   */
229
  private JButton defaultButton;
230
  /**
231
   *  UI element to allow the user to save a text file with the shortcut
232
   *  information
233
   */
234
  private JButton saveButton;
235
  /**
236
   *  UI element to allow the user to decide if shortcuts should be placed on
237
   *  the desktop or not.
238
   */
239
  private JCheckBox allowDesktopShortcut;
240
  /**
241
   *  UI element instruct this panel to create shortcuts for the current user
242
   *  only
243
   */
244
  private JRadioButton currentUser;
245
  /**  UI element instruct this panel to create shortcuts for all users */
246
  private JRadioButton allUsers;
247
  /**  The layout for this panel */
248
  private GridBagLayout layout;
249
  /**  The contraints object to use whan creating the layout */
250
  private GridBagConstraints constraints;
251

    
252
  /**
253
   *  The default name to use for the program group. This comes from the XML
254
   *  specification.
255
   */
256
  private String suggestedProgramGroup;
257
  /**  The name chosen by the user for the program group, */
258
  private String groupName;
259
  /**
260
   *  The location for placign the program group. This is the same as the
261
   *  location (type) of a shortcut, only that it applies to the program group.
262
   *  Note that there are only two locations that make sense as location for a
263
   *  program group: <br>
264
   *
265
   *  <ul>
266
   *    <li> applications
267
   *    <li> start manu
268
   *  </ul>
269
   *
270
   */
271
  private int groupLocation;
272

    
273
  /**  The parsed result from reading the XML specification from the file */
274
  private XMLElement spec;
275
  /**
276
   *  Set to <code>true</code> by <code>analyzeShortcutSpec()</code> if there
277
   *  are any desktop shortcuts to create.
278
   */
279
  private boolean hasDesktopShortcuts = false;
280

    
281
  /** Tells wether to skip if the platform is not supported. */
282
  private boolean skipIfNotSupported = false;
283

    
284
  /**  the one shortcut instance for reuse in many locations */
285
  private Shortcut shortcut;
286
  /**
287
   *  A list of <code>ShortcutData</code> objects. Each object is the complete
288
   *  specification for one shortcut that must be created.
289
   */
290
  private Vector shortcuts = new Vector();
291
  /**
292
   *  Holds a list of all the shortcut files that have been created. <b>Note:
293
   *  </b> this variable contains valid data only after <code>createShortcuts()</code>
294
   *  has been called. This list is created so that the files can be added to
295
   *  the uninstaller.
296
   */
297
  private Vector files = new Vector();
298
  /**
299
   *  If <code>true</code> it indicates that there are shortcuts to create. The
300
   *  value is set by <code>analyzeShortcutSpec()</code>
301
   */
302
  private boolean shortcutsToCreate = false;
303
  /**
304
   *  If <code>true</code> it indicates that the spec file is existing and could
305
   *  be read.
306
   */
307
  private boolean haveShortcutSpec = false;
308
  /**
309
   *  This is set to true if the shortcut spec instructs to simulate running on
310
   *  an operating system that is not supported.
311
   */
312
  private boolean simulteNotSupported = false;
313
  /**  Avoids bogus behaviour when the user goes back then returns to this panel. */
314
  private boolean firstTime = true;
315

    
316

    
317
  /*
318
   *  --------------------------------------------------------------------------
319
   */
320
  /**
321
   *  Constructor.
322
   *
323
   * @param  parent       reference to the application frame
324
   * @param  installData  shared information about the installation
325
   */
326
  /*
327
   *  --------------------------------------------------------------------------
328
   */
329
  public ShortcutPanel(InstallerFrame parent,
330
                       InstallData installData)
331
  {
332
    super (parent, installData);
333

    
334
    // read the XML file
335
    try
336
    {
337
      readShortcutSpec ();
338
    }
339
    catch (Throwable exception)
340
    {
341
      System.out.println ("could not read shortcut spec!");
342
      exception.printStackTrace ();
343
    }
344

    
345
    layout      = new GridBagLayout ();
346
    constraints = new GridBagConstraints ();
347
    setLayout(layout);
348

    
349
    // Create the UI elements
350
    try
351
    {
352
      shortcut = (Shortcut)(TargetFactory.getInstance ().makeObject ("com.izforge.izpack.util.os.Shortcut"));
353
      shortcut.initialize (Shortcut.APPLICATIONS, "-");
354
    }
355
    catch (Throwable exception)
356
    {
357
      System.out.println ("could not create shortcut instance");
358
      exception.printStackTrace ();
359
    }
360
  }
361
 /*--------------------------------------------------------------------------*/
362
 /**
363
  * This method represents the <code>ActionListener</code> interface, invoked
364
  * when an action occurs.
365
  *
366
  * @param     event    the action event.
367
  */
368
 /*--------------------------------------------------------------------------*/
369
  public void actionPerformed (ActionEvent event)
370
  {
371
    Object eventSource = event.getSource ();
372

    
373
    // ----------------------------------------------------
374
    // create shortcut for the current user was selected
375
    // refresh the list of program groups accordingly and
376
    // reset the program group to the default setting.
377
    // ----------------------------------------------------
378
    if (eventSource.equals (currentUser))
379
    {
380
      groupList.setListData (shortcut.getProgramGroups (Shortcut.CURRENT_USER));
381
      programGroup.setText  (suggestedProgramGroup);
382
      shortcut.setUserType  (Shortcut.CURRENT_USER);
383
    }
384
    // ----------------------------------------------------
385
    // create shortcut for all users was selected
386
    // refresh the list of program groups accordingly and
387
    // reset the program group to the default setting.
388
    // ----------------------------------------------------
389
    else if (eventSource.equals (allUsers))
390
    {
391
      groupList.setListData (shortcut.getProgramGroups (Shortcut.ALL_USERS));
392
      programGroup.setText  (suggestedProgramGroup);
393
      shortcut.setUserType  (Shortcut.ALL_USERS);
394
    }
395
    // ----------------------------------------------------
396
    // The reset button was pressed.
397
    // - clear the selection in the list box, because the
398
    //   selection is no longer valid
399
    // - refill the program group edit control with the
400
    //   suggested program group name
401
    // ----------------------------------------------------
402
    else if (eventSource.equals (defaultButton))
403
    {
404
      groupList.getSelectionModel ().clearSelection ();
405
      programGroup.setText (suggestedProgramGroup);
406
    }
407
    // ----------------------------------------------------
408
    // the save button was pressed. This is a request to
409
    // save shortcut information to a text file.
410
    // ----------------------------------------------------
411
    else if (eventSource.equals (saveButton))
412
    {
413
      saveToFile ();
414

    
415
      // add the file to the uninstaller
416
      addToUninstaller ();
417
    }
418
  }
419
 /*--------------------------------------------------------------------------*/
420
 /**
421
  * Returns <code>true</code> when all selections have valid settings. This
422
  * indicates that it is legal to procede to the next panel.
423
  *
424
  * @return    <code>true</code> if it is legal to procede to the next panel,
425
  *            otherwise <code>false</code>.
426
  */
427
 /*--------------------------------------------------------------------------*/
428
  public boolean isValidated ()
429
  {
430
        try
431
        {
432
          groupName = programGroup.getText ();
433
        }
434
        catch (Throwable exception)
435
        {
436
          groupName = "";
437
        }
438

    
439
        createShortcuts ();
440

    
441
        // add files and directories to the uninstaller
442
        addToUninstaller ();
443

    
444
    return (true);
445
  }
446
 /*--------------------------------------------------------------------------*/
447
 /**
448
  * Called when the panel is shown to the user.
449
  */
450
 /*--------------------------------------------------------------------------*/
451
  public void panelActivate ()
452
  {
453
    if (firstTime)
454
      firstTime = false;
455
    else
456
      return;
457

    
458
    analyzeShortcutSpec ();
459

    
460
    if (shortcutsToCreate)
461
    {
462
      if (shortcut.supported () && !simulteNotSupported)
463
      {
464
        buildUI (shortcut.getProgramGroups (ShellLink.CURRENT_USER), true);  // always start out with the current user
465
      }
466
      else
467
      {
468
        if (skipIfNotSupported)
469
        {
470
          parent.skipPanel();
471
        }
472
        else
473
        {
474
          buildAlternateUI ();
475
          parent.unlockNextButton();
476
          parent.lockPrevButton ();
477
        }
478
      }
479
    }
480
    else
481
    {
482
      parent.skipPanel ();
483
    }
484
  }
485
 /*--------------------------------------------------------------------------*/
486
 /**
487
  * This method is called by the <code>groupList</code> when the user makes
488
  * a selection. It updates the content of the <code>programGroup</code>
489
  * with the result of the selection.
490
  *
491
  * @param     event the list selection event
492
  */
493
 /*--------------------------------------------------------------------------*/
494
  public void valueChanged (ListSelectionEvent event)
495
  {
496
    if (programGroup ==  null)
497
    {
498
      return;
499
    }
500

    
501
    String value = "";
502
    try
503
    {
504
      value = (String)groupList.getSelectedValue ();
505
    }
506
    catch (ClassCastException exception) {}
507

    
508
    if (value == null)
509
    {
510
      value = "";
511
    }
512

    
513
    programGroup.setText( value + File.separator + suggestedProgramGroup );
514
  }
515
 /*--------------------------------------------------------------------------*/
516
 /**
517
  * Reads the XML specification for the shortcuts to create. The result is
518
  * stored in spec.
519
  *
520
  *
521
  */
522
 /*--------------------------------------------------------------------------*/
523
  private void readShortcutSpec () throws Exception
524
  {
525
    // open an input stream
526
    InputStream input = null;
527

    
528
    try
529
 {
530
      input = parent.getResource( TargetFactory.getCurrentOSPrefix() + SPEC_FILE_NAME );
531
 }
532

    
533
    catch( ResourceNotFoundException e )
534
    {
535

    
536
      input = parent.getResource( SPEC_FILE_NAME );
537
      if( input == null )
538
      {
539

    
540
        haveShortcutSpec = false;
541
        return;
542
      }
543

    
544
    }
545

    
546

    
547

    
548

    
549

    
550
    // initialize the parser
551
    StdXMLParser parser = new StdXMLParser ();
552
    parser.setBuilder   (new StdXMLBuilder ());
553
    parser.setValidator (new NonValidator ());
554
    parser.setReader    (new StdXMLReader (input));
555

    
556
    // get the data
557
    spec = (XMLElement) parser.parse ();
558

    
559
    // close the stream
560
    input.close ();
561
    haveShortcutSpec = true;
562
  }
563
 /*--------------------------------------------------------------------------*/
564
 /**
565
  * This method analyzes the specifications for creating shortcuts and
566
  * builds a list of all the Shortcuts that need to be created.
567
  *
568
  */
569
 /*--------------------------------------------------------------------------*/
570
  private void analyzeShortcutSpec ()
571
  {
572
    if (!haveShortcutSpec)
573
    {
574
      shortcutsToCreate = false;
575
      return;
576
    }
577

    
578
    XMLElement skipper = spec.getFirstChildNamed(SPEC_KEY_SKIP_IFNOT_SUPPORTED);
579
    skipIfNotSupported = (skipper != null);
580

    
581
    // ----------------------------------------------------
582
    // find out if we should simulate a not supported
583
    // scenario
584
    // ----------------------------------------------------
585
    XMLElement support = spec.getFirstChildNamed (SPEC_KEY_NOT_SUPPORTED);
586

    
587
    if (support != null)
588
    {
589
      simulteNotSupported = true;
590
    }
591

    
592
    // ----------------------------------------------------
593
    // find out in which program group the shortcuts should
594
    // be placed and where this program group should be
595
    // located
596
    // ----------------------------------------------------
597
    XMLElement  group     = spec.getFirstChildNamed (SPEC_KEY_PROGRAM_GROUP);
598
    String      location  = null;
599
    hasDesktopShortcuts   = false;
600

    
601
    if (group != null)
602
    {
603
      suggestedProgramGroup = group.getAttribute (SPEC_ATTRIBUTE_DEFAULT_GROUP, "");
604
      location              = group.getAttribute (SPEC_ATTRIBUTE_LOCATION, SPEC_VALUE_APPLICATIONS);
605
    }
606
    else
607
    {
608
      suggestedProgramGroup = "";
609
      location              = SPEC_VALUE_APPLICATIONS;
610
    }
611

    
612
    if (location.equals (SPEC_VALUE_APPLICATIONS))
613
    {
614
      groupLocation = Shortcut.APPLICATIONS;
615
    }
616
    else if (location.equals (SPEC_VALUE_START_MENU))
617
    {
618
      groupLocation = Shortcut.START_MENU;
619
    }
620

    
621
    // ----------------------------------------------------
622
    // create a list of all shortcuts that need to be
623
    // created, containing all details about each shortcut
624
    // ----------------------------------------------------
625
    VariableSubstitutor substitutor   = new VariableSubstitutor (idata.getVariables());
626
    String              temp;
627
    Vector              shortcutSpecs = spec.getChildrenNamed (SPEC_KEY_SHORTCUT);
628
    XMLElement          shortcutSpec;
629
    ShortcutData        data;
630

    
631
    for (int i = 0; i < shortcutSpecs.size (); i++)
632
    {
633
      shortcutSpec      = (XMLElement)shortcutSpecs.elementAt (i);
634

    
635
      if (! OsConstraint.oneMatchesCurrentSystem(shortcutSpec))
636
        continue;
637

    
638
      data              = new ShortcutData ();
639

    
640
      data.name               = shortcutSpec.getAttribute( SPEC_ATTRIBUTE_NAME );
641
      data.subgroup           = shortcutSpec.getAttribute( SPEC_ATTRIBUTE_SUBGROUP );
642
      data.description        = shortcutSpec.getAttribute( SPEC_ATTRIBUTE_DESCRIPTION, "" );
643
      //** Linux **//
644
      data.deskTopEntryLinux_Encoding = shortcutSpec.getAttribute( SPEC_ATTRIBUTE_ENCODING, "" );
645
      data.deskTopEntryLinux_MimeType = shortcutSpec.getAttribute( SPEC_ATTRIBUTE_MIMETYPE, "" );
646
      data.deskTopEntryLinux_Terminal = shortcutSpec.getAttribute( SPEC_ATTRIBUTE_TERMINAL, "" );
647
      data.deskTopEntryLinux_TerminalOptions = shortcutSpec.getAttribute( SPEC_ATTRIBUTE_TERMINAL_OPTIONS, "" );
648
      data.deskTopEntryLinux_Type = shortcutSpec.getAttribute( SPEC_ATTRIBUTE_TYPE, "" );
649

    
650
      data.deskTopEntryLinux_URL  = substitutor.substitute( shortcutSpec.getAttribute( SPEC_ATTRIBUTE_URL, "" ), null );
651

    
652
      data.deskTopEntryLinux_X_KDE_SubstituteUID = shortcutSpec.getAttribute( SPEC_ATTRIBUTE_KDE_SUBST_UID, "" );
653
      //** EndOf LINUX **//
654
      temp                    = fixSeparatorChar( shortcutSpec.getAttribute( SPEC_ATTRIBUTE_TARGET, "" ) );
655
      data.target             = substitutor.substitute( temp, null );
656

    
657
      temp                    = shortcutSpec.getAttribute( SPEC_ATTRIBUTE_COMMAND, "" );
658
      data.commandLine        = substitutor.substitute( temp, null );
659

    
660
      temp                    = fixSeparatorChar( shortcutSpec.getAttribute( SPEC_ATTRIBUTE_ICON, "" ) );
661
      data.iconFile           = substitutor.substitute( temp, null );
662
      data.iconIndex          = Integer.parseInt( shortcutSpec.getAttribute( SPEC_ATTRIBUTE_ICON_INDEX, "0" ) );
663

    
664
      temp                    = fixSeparatorChar( shortcutSpec.getAttribute( SPEC_ATTRIBUTE_WORKING_DIR, "" ) );
665
      data.workingDirectory   = substitutor.substitute( temp, null );
666

    
667
      String initialState     = shortcutSpec.getAttribute (SPEC_ATTRIBUTE_INITIAL_STATE, "");
668
      if (initialState.equals (SPEC_VALUE_NO_SHOW))
669
      {
670
        data.initialState     = Shortcut.HIDE;
671
      }
672
      else if (initialState.equals (SPEC_VALUE_NORMAL))
673
      {
674
        data.initialState     = Shortcut.NORMAL;
675
      }
676
      else if (initialState.equals (SPEC_VALUE_MAXIMIZED))
677
      {
678
        data.initialState     = Shortcut.MAXIMIZED;
679
      }
680
      else if (initialState.equals (SPEC_VALUE_MINIMIZED))
681
      {
682
        data.initialState     = Shortcut.MINIMIZED;
683
      }
684
      else
685
      {
686
        data.initialState     = Shortcut.NORMAL;
687
      }
688

    
689
      // --------------------------------------------------
690
      // if the minimal data requirements are met to create
691
      // the shortcut, create one entry each for each of
692
      // the requested types.
693
      // Eventually this will cause the creation of one
694
      // shortcut in each of the associated locations.
695
      // --------------------------------------------------
696

    
697
      // without a name we can not create a shortcut
698
      if (data.name == null)
699
      {
700
        continue;
701
      }
702
      //1. Elmar: "Without a target we can not create a shortcut."
703
      //2. Marc: "No, Even on Linux a Link can be an URL and has no target."
704
      if( data.target == null )
705
      {
706
        continue;
707
      }
708
      // the shortcut is not actually required for any of the selected packs
709
      Vector forPacks = shortcutSpec.getChildrenNamed (SPEC_KEY_PACKS);
710
      if (!shortcutRequiredFor (forPacks))
711
      {
712
        continue;
713
      }
714

    
715
      // --------------------------------------------------
716
      // This section is executed if we don't skip.
717
      // --------------------------------------------------
718
      // For each of the categories set the type and if
719
      // the link should be placed in the program group,
720
      // then clone the data set to obtain an independent
721
      // instance and add this to the list of shortcuts
722
      // to be created. In this way, we will set up an
723
      // identical copy for each of the locations at which
724
      // a shortcut should be placed. Therefore you must
725
      // not use 'else if' statements!
726
      // --------------------------------------------------
727
      {
728
        if (attributeIsTrue (shortcutSpec, SPEC_ATTRIBUTE_DESKTOP))
729
        {
730
          hasDesktopShortcuts = true;
731
          data.addToGroup     = false;
732
          data.type           = Shortcut.DESKTOP;
733
          shortcuts.add (data.clone ());
734
        }
735
        if (attributeIsTrue (shortcutSpec, SPEC_ATTRIBUTE_APPLICATIONS))
736
        {
737
          data.addToGroup     = false;
738
          data.type           = Shortcut.APPLICATIONS;
739
          shortcuts.add (data.clone ());
740
        }
741
        if (attributeIsTrue (shortcutSpec, SPEC_ATTRIBUTE_START_MENU))
742
        {
743
          data.addToGroup     = false;
744
          data.type           = Shortcut.START_MENU;
745
          shortcuts.add (data.clone ());
746
        }
747
        if (attributeIsTrue (shortcutSpec, SPEC_ATTRIBUTE_STARTUP))
748
        {
749
          data.addToGroup     = false;
750
          data.type           = Shortcut.START_UP;
751
          shortcuts.add (data.clone ());
752
        }
753
        if (attributeIsTrue (shortcutSpec, SPEC_ATTRIBUTE_PROGRAM_GROUP))
754
        {
755
          data.addToGroup     = true;
756
          data.type           = Shortcut.APPLICATIONS;
757
          shortcuts.add (data.clone ());
758
        }
759
      }
760
    }
761

    
762
    // ----------------------------------------------------
763
    // signal if there are any shortcuts to create
764
    // ----------------------------------------------------
765
    if (shortcuts.size () > 0)
766
    {
767
      shortcutsToCreate = true;
768
    }
769
  }
770
 /*--------------------------------------------------------------------------*/
771
 /**
772
  * Creates all shortcuts based on the information in <code>shortcuts</code>.
773
  */
774
 /*--------------------------------------------------------------------------*/
775
  private void createShortcuts ()
776
  {
777
    ShortcutData  data;
778

    
779
    for (int i = 0; i < shortcuts.size (); i++)
780
    {
781
      data     = (ShortcutData)shortcuts.elementAt (i);
782
      try
783
      {
784
        groupName = groupName + data.subgroup;
785

    
786
        shortcut.setLinkName(           data.name );
787
        shortcut.setLinkType(           data.type );
788
        shortcut.setArguments(          data.commandLine );
789
        shortcut.setDescription(        data.description );
790
        shortcut.setIconLocation(       data.iconFile, data.iconIndex );
791

    
792
        shortcut.setShowCommand(        data.initialState);
793
        shortcut.setTargetPath(         data.target      );
794
        shortcut.setWorkingDirectory(   data.workingDirectory );
795
        shortcut.setEncoding(           data.deskTopEntryLinux_Encoding );
796
        shortcut.setMimetype(           data.deskTopEntryLinux_MimeType );
797

    
798
        shortcut.setTerminal(           data.deskTopEntryLinux_Terminal );
799
        shortcut.setTerminalOptions(    data.deskTopEntryLinux_TerminalOptions );
800
        shortcut.setType(               data.deskTopEntryLinux_Type );
801
        shortcut.setKdeSubstUID(        data.deskTopEntryLinux_X_KDE_SubstituteUID );
802
        shortcut.setURL(                data.deskTopEntryLinux_URL );
803

    
804
        if( data.addToGroup )
805
        {
806
          shortcut.setProgramGroup    (groupName);
807
        }
808
        else
809
        {
810
          shortcut.setProgramGroup    ("");
811
        }
812

    
813
        try
814
        {
815
          // ----------------------------------------------
816
          // save the shortcut only if it is either not on
817
          // the desktop or if it is on the desktop and
818
          // the user has signalled that it is ok to place
819
          // shortcuts on the desktop.
820
          // ----------------------------------------------
821
          if ( (data.type != Shortcut.DESKTOP)                                         ||
822
              ((data.type == Shortcut.DESKTOP) && allowDesktopShortcut.isSelected ())     )
823
          {
824
            // save the shortcut
825
            shortcut.save ();
826

    
827
            // add the file and directory name to the file list
828
            String fileName       = shortcut.getFileName ();
829
            files.add (0, fileName);
830

    
831
            File file = new File(fileName);
832
            File base = new File(shortcut.getBasePath());
833
            Vector intermediates = new Vector();
834

    
835
            //String directoryName  = shortcut.getDirectoryCreated ();
836
            execFiles.add( new ExecutableFile( fileName, 2, ExecutableFile.NEVER, new ArrayList(), false ) );
837

    
838
            files.add( fileName );
839

    
840
            while ( ( file = file.getParentFile()) != null)
841
            {
842
              if (file.equals( base ))
843
                break;
844
                intermediates.add(file);
845
            }
846
            if (file != null)
847
            {
848
              for (Iterator iter = intermediates.iterator(); iter.hasNext(); )
849
                files.add (0, iter.next().toString());
850
            }
851
          }
852
        }
853
        catch (Exception exception)
854
        {
855
        }
856
      }
857
      catch (Throwable exception)
858
      {
859
        continue;
860
      }
861

    
862

    
863
    }
864
    //System.out.println( "files:" + files );
865
    try
866
    {
867
      FileExecutor executor = new FileExecutor( execFiles );
868
      executor.executeFiles( ExecutableFile.NEVER, null );
869
    }
870
    catch( Exception cannot ){ cannot.printStackTrace(); }
871

    
872
    parent.unlockNextButton();
873
  }
874
 /*--------------------------------------------------------------------------*/
875
 /**
876
  * Verifies if the shortcut is required for any of the packs listed. The
877
  * shortcut is required for a pack in the list if that pack is actually
878
  * selected for installation.
879
  * <br><br>
880
  * <b>Note:</b><br>
881
  * If the list of selected packs is empty then <code>true</code> is always
882
  * returnd. The same is true if the <code>packs</code> list is empty.
883
  *
884
  * @param     packs  a <code>Vector</code> of <code>String</code>s. Each of
885
  *                   the strings denotes a pack for which the schortcut
886
  *                   should be created if the pack is actually installed.
887
  *
888
  * @return    <code>true</code> if the shortcut is required for at least
889
  *            on pack in the list, otherwise returns <code>false</code>.
890
  */
891
 /*--------------------------------------------------------------------------*/
892
 /*$
893
  * @design
894
  *
895
  * The information about the installed packs comes from
896
  * InstallData.selectedPacks. This assumes that this panel is presented to
897
  * the user AFTER the PacksPanel.
898
  *--------------------------------------------------------------------------*/
899
  private boolean shortcutRequiredFor (Vector packs)
900
  {
901
    String selected;
902
    String required;
903

    
904
    if (packs.size () == 0)
905
    {
906
      return (true);
907
    }
908

    
909
    for (int i = 0; i < idata.selectedPacks.size (); i++)
910
    {
911
      selected = ((Pack)idata.selectedPacks.get (i)).name;
912

    
913
      for (int k = 0; k < packs.size (); k++)
914
      {
915
        required = (String)((XMLElement)packs.elementAt (k)).getAttribute (SPEC_ATTRIBUTE_NAME, "");
916
        if (selected.equals (required))
917
        {
918
          return (true);
919
        }
920
      }
921
    }
922

    
923
    return (false);
924
  }
925
 /*--------------------------------------------------------------------------*/
926
 /**
927
  * Determines if the named attribute in true. True is represented by any of
928
  * the following strings and is not case sensitive. <br>
929
  * <ul>
930
  * <li>yes
931
  * <li>1
932
  * <li>true
933
  * <li>on
934
  * </ul><br>
935
  * Every other string, including the empty string as well as the non-existence
936
  * of the attribute will cuase <code>false</code> to be returned.
937
  *
938
  * @param     element    the <code>XMLElement</code> to search for the attribute.
939
  * @param     name       the name of the attribute to test.
940
  *
941
  * @return    <code>true</code> if the attribute value equals one of the
942
  *            pre-defined strings, <code>false</code> otherwise.
943
  */
944
 /*--------------------------------------------------------------------------*/
945
  private boolean attributeIsTrue (XMLElement element,
946
                                   String     name)
947
  {
948
    String value = element.getAttribute (name, "").toUpperCase ();
949

    
950
    if (value.equals ("YES"))
951
    {
952
      return (true);
953
    }
954
    else if (value.equals ("TRUE"))
955
    {
956
      return (true);
957
    }
958
    else if (value.equals ("ON"))
959
    {
960
      return (true);
961
    }
962
    else if (value.equals ("1"))
963
    {
964
      return (true);
965
    }
966

    
967
    return (false);
968
  }
969
 /*--------------------------------------------------------------------------*/
970
 /**
971
  * Replaces any ocurrence of '/' or '\' in a path string with the correct
972
  * version for the operating system.
973
  *
974
  * @param     path     a system path
975
  *
976
  * @return    a path string that uniformely uses the proper version of the
977
  *            separator character.
978
  */
979
 /*--------------------------------------------------------------------------*/
980
  private String fixSeparatorChar (String path)
981
  {
982
    String newPath  = path.replace ('/', File.separatorChar);
983
    newPath         = newPath.replace ('\\', File.separatorChar);
984

    
985
    return (newPath);
986
  }
987
 /*--------------------------------------------------------------------------*/
988
 /**
989
  * This method creates the UI for this panel.
990
  *
991
  * @param     groups           A <code>Vector</code> that contains
992
  *                             <code>Strings</code> with all the names of the
993
  *                             existing program groups. These will be placed
994
  *                             in the <code>groupList</code>.
995
  * @param    currentUserList   if <code>true</code> it indicates that the
996
  *                             list of groups is valid for the current user,
997
  *                             otherwise it is considered valid for all users.
998
  */
999
 /*--------------------------------------------------------------------------*/
1000
  private void buildUI (Vector  groups,
1001
                        boolean currentUserList)
1002
  {
1003
    layout      = new GridBagLayout ();
1004
    constraints = new GridBagConstraints ();
1005
    setLayout(layout);
1006

    
1007
    // ----------------------------------------------------
1008
    // label a the top of the panel, that gives the
1009
    // basic instructions
1010
    // ----------------------------------------------------
1011
    listLabel = LabelFactory.create (parent.langpack.getString ("ShortcutPanel.regular.list"),
1012
                            JLabel.LEADING);
1013

    
1014
    constraints.gridx       = 0;
1015
    constraints.gridy       = 0;
1016
    constraints.gridwidth   = 1;
1017
    constraints.gridheight  = 1;
1018
    constraints.weightx     = 1.0;
1019
    constraints.weighty     = 1.0;
1020
    constraints.insets      = new Insets (5, 5, 5, 5);
1021
    constraints.fill        = GridBagConstraints.NONE;
1022
    constraints.anchor      = GridBagConstraints.WEST;
1023
    layout.addLayoutComponent (listLabel, constraints);
1024
    add (listLabel);
1025

    
1026
    // ----------------------------------------------------
1027
    // list box to list all of the existing program groups
1028
    // at the intended destination
1029
    // ----------------------------------------------------
1030
    groupList = new JList  (groups);
1031
    groupList.setSelectionMode  (ListSelectionModel.SINGLE_SELECTION);
1032
    groupList.getSelectionModel ().addListSelectionListener (this);
1033
    JScrollPane scrollPane  = new JScrollPane (groupList);
1034

    
1035
    constraints.gridx       = 0;
1036
    constraints.gridy       = 1;
1037
    constraints.gridwidth   = 1;
1038
    constraints.gridheight  = 1;
1039
    constraints.fill        = GridBagConstraints.BOTH;
1040
    layout.addLayoutComponent (scrollPane, constraints);
1041
    add (scrollPane);
1042

    
1043
    // ----------------------------------------------------
1044
    // radio buttons to select current user or all users.
1045
    // ----------------------------------------------------
1046
    if (shortcut.multipleUsers ())
1047
    {
1048
      JPanel       usersPanel  = new JPanel (new GridLayout (2, 1));
1049
      ButtonGroup  usersGroup  = new ButtonGroup ();
1050
      currentUser              = new JRadioButton (parent.langpack.getString ("ShortcutPanel.regular.currentUser"), currentUserList);
1051
      currentUser.addActionListener (this);
1052
      usersGroup.add (currentUser);
1053
      usersPanel.add (currentUser);
1054
      allUsers                 = new JRadioButton (parent.langpack.getString ("ShortcutPanel.regular.allUsers"), !currentUserList);
1055
      if( ! OsVersion.IS_WINDOWS )
1056
        allUsers.setEnabled( false );
1057
      allUsers.addActionListener (this);
1058
      usersGroup.add (allUsers);
1059
      usersPanel.add (allUsers);
1060
      TitledBorder  border     = new TitledBorder (new EmptyBorder(2, 2, 2, 2), parent.langpack.getString ("ShortcutPanel.regular.userIntro"));
1061
      usersPanel.setBorder (border);
1062

    
1063
      constraints.gridx       = 1;
1064
      constraints.gridy       = 1;
1065
      constraints.gridwidth   = 1;
1066
      constraints.gridheight  = 1;
1067
      constraints.fill        = GridBagConstraints.NONE;
1068
      layout.addLayoutComponent (usersPanel, constraints);
1069
      add (usersPanel);
1070
    }
1071

    
1072
    // ----------------------------------------------------
1073
    // edit box that contains the suggested program group
1074
    // name, which can be modfied or substituted from the
1075
    // list by the user
1076
    // ----------------------------------------------------
1077
    programGroup = new JTextField (suggestedProgramGroup, 40); // 40?
1078

    
1079
    constraints.gridx       = 0;
1080
    constraints.gridy       = 2;
1081
    constraints.gridwidth   = 1;
1082
    constraints.gridheight  = 1;
1083
    constraints.fill        = GridBagConstraints.HORIZONTAL;
1084
    layout.addLayoutComponent (programGroup, constraints);
1085
    add (programGroup);
1086

    
1087
    // ----------------------------------------------------
1088
    // reset button that allows the user to revert to the
1089
    // original suggestion for the program group
1090
    // ----------------------------------------------------
1091
    defaultButton = ButtonFactory.createButton(
1092
      parent.langpack.getString("ShortcutPanel.regular.default"),
1093
      idata.buttonsHColor);
1094
    defaultButton.addActionListener(this);
1095

    
1096
    constraints.gridx = 1;
1097
    constraints.gridy = 2;
1098
    constraints.gridwidth = 1;
1099
    constraints.gridheight = 1;
1100
    constraints.fill = GridBagConstraints.NONE;
1101
    layout.addLayoutComponent(defaultButton, constraints);
1102
    add(defaultButton);
1103

    
1104
    // ----------------------------------------------------
1105
    // check box to allow the user to decide if a desktop
1106
    // shortcut should be created.
1107
    // this should only be created if needed and requested
1108
    // in the definition file.
1109
    // ----------------------------------------------------
1110
    allowDesktopShortcut = new JCheckBox (parent.langpack.getString ("ShortcutPanel.regular.desktop"), true);
1111

    
1112
    constraints.gridx       = 0;
1113
    constraints.gridy       = 3;
1114
    constraints.gridwidth   = 1;
1115
    constraints.gridheight  = 1;
1116

    
1117
    if (hasDesktopShortcuts)
1118
    {
1119
      layout.addLayoutComponent (allowDesktopShortcut, constraints);
1120
      add (allowDesktopShortcut);
1121
    }
1122
  }
1123
 /*--------------------------------------------------------------------------*/
1124
 /**
1125
  * This method creates an alternative UI for this panel. This UI can be
1126
  * used when the creation of shortcuts is not supported on the target system.
1127
  * It displays an apology for the inability to create shortcuts on this
1128
  * system, along with information about the intended targets. In addition,
1129
  * there is a button that allows the user to save more complete information
1130
  * in a text file. Based on this information the user might be able to create
1131
  * the necessary shortcut him or herself. At least there will be information
1132
  * about how to launch the application.
1133
  */
1134
 /*--------------------------------------------------------------------------*/
1135
  private void buildAlternateUI ()
1136
  {
1137
    layout      = new GridBagLayout ();
1138
    constraints = new GridBagConstraints ();
1139
    setLayout (layout);
1140

    
1141
    // ----------------------------------------------------
1142
    // static text a the top of the panel, that apologizes
1143
    // about the fact that we can not create shortcuts on
1144
    // this particular target OS.
1145
    // ----------------------------------------------------
1146
    MultiLineLabel apologyLabel = new MultiLineLabel (parent.langpack.getString ("ShortcutPanel.alternate.apology"), 0, 0);
1147

    
1148
    constraints.gridx       = 0;
1149
    constraints.gridy       = 0;
1150
    constraints.gridwidth   = 1;
1151
    constraints.gridheight  = 1;
1152
    constraints.weightx     = 1.0;
1153
    constraints.weighty     = 1.0;
1154
    constraints.insets      = new Insets (5, 5, 5, 5);
1155
    constraints.fill        = GridBagConstraints.HORIZONTAL;
1156
    constraints.anchor      = GridBagConstraints.WEST;
1157
    layout.addLayoutComponent (apologyLabel, constraints);
1158
    add (apologyLabel);
1159

    
1160
    // ----------------------------------------------------
1161
    // label that explains the significance ot the list box
1162
    // ----------------------------------------------------
1163
    MultiLineLabel listLabel = new MultiLineLabel (parent.langpack.getString ("ShortcutPanel.alternate.targetsLabel"), 0, 0);
1164

    
1165
    constraints.gridx       = 0;
1166
    constraints.gridy       = 1;
1167
    constraints.gridwidth   = 1;
1168
    constraints.gridheight  = 1;
1169
    constraints.weightx     = 1.0;
1170
    constraints.weighty     = 1.0;
1171
    layout.addLayoutComponent (listLabel, constraints);
1172
    add (listLabel);
1173

    
1174
    // ----------------------------------------------------
1175
    // list box to list all of the intended shortcut targets
1176
    // ----------------------------------------------------
1177
    Vector targets = new Vector ();
1178
    for (int i = 0; i < shortcuts.size (); i++)
1179
    {
1180
      targets.add (((ShortcutData)shortcuts.elementAt (i)).target);
1181
    }
1182

    
1183
    targetList = new JList  (targets);
1184
    JScrollPane scrollPane  = new JScrollPane (targetList);
1185

    
1186
    constraints.gridx       = 0;
1187
    constraints.gridy       = 2;
1188
    constraints.fill        = GridBagConstraints.BOTH;
1189
    layout.addLayoutComponent (scrollPane, constraints);
1190
    add (scrollPane);
1191

    
1192
    // ----------------------------------------------------
1193
    // static text that explains about the text file
1194
    // ----------------------------------------------------
1195
    MultiLineLabel fileExplanation = new MultiLineLabel (parent.langpack.getString ("ShortcutPanel.alternate.textFileExplanation"), 0, 0);
1196

    
1197
    constraints.gridx       = 0;
1198
    constraints.gridy       = 3;
1199
    constraints.weightx     = 1.0;
1200
    constraints.weighty     = 1.0;
1201
    constraints.fill        = GridBagConstraints.HORIZONTAL;
1202
    layout.addLayoutComponent (fileExplanation, constraints);
1203
    add (fileExplanation);
1204

    
1205
    // ----------------------------------------------------
1206
    // button to save the text file
1207
    // ----------------------------------------------------
1208
    saveButton = ButtonFactory.createButton(
1209
      parent.langpack.getString("ShortcutPanel.alternate.saveButton"),
1210
      idata.buttonsHColor);
1211
    saveButton.addActionListener(this);
1212

    
1213
    constraints.gridx = 0;
1214
    constraints.gridy = 4;
1215
    constraints.gridwidth = 1;
1216
    constraints.gridheight = 1;
1217
    constraints.fill = GridBagConstraints.NONE;
1218
    constraints.anchor = GridBagConstraints.CENTER;
1219
    layout.addLayoutComponent(saveButton, constraints);
1220
    add(saveButton);
1221
  }
1222
 /*--------------------------------------------------------------------------*/
1223
 /**
1224
  * Overriding the superclass implementation. This method returns the size of
1225
  * the container.
1226
  *
1227
  * @return    the size of the container
1228
  */
1229
 /*--------------------------------------------------------------------------*/
1230
  public Dimension getSize ()
1231
  {
1232
    Dimension size          = getParent ().getSize ();
1233
    Insets    insets        = getInsets ();
1234
    Border    border        = getBorder ();
1235
    Insets    borderInsets  = new Insets (0, 0, 0, 0);
1236

    
1237
    if (border != null)
1238
    {
1239
      borderInsets = border.getBorderInsets (this);
1240
    }
1241

    
1242
    size.height = size.height - insets.top  - insets.bottom - borderInsets.top  - borderInsets.bottom - 50;
1243
    size.width  = size.width  - insets.left - insets.right  - borderInsets.left - borderInsets.right  - 50;
1244

    
1245
    return (size);
1246
  }
1247
 /*--------------------------------------------------------------------------*/
1248
 /**
1249
  * This method saves all shortcut information to a text file.
1250
  */
1251
 /*--------------------------------------------------------------------------*/
1252
  private void saveToFile ()
1253
  {
1254
    File file = null;
1255

    
1256
    // ----------------------------------------------------
1257
    // open a file chooser dialog to get a path / file name
1258
    // ----------------------------------------------------
1259
    JFileChooser fileDialog = new JFileChooser (idata.getInstallPath ());
1260
    fileDialog.setSelectedFile (new File (TEXT_FILE_NAME));
1261
    if(fileDialog.showSaveDialog (this) == JFileChooser.APPROVE_OPTION)
1262
    {
1263
      file = fileDialog.getSelectedFile ();
1264
    }
1265
    else
1266
    {
1267
      return;
1268
    }
1269

    
1270
    // ----------------------------------------------------
1271
    // save to the file
1272
    // ----------------------------------------------------
1273
    FileWriter      output  = null;
1274
    StringBuffer    buffer  = new StringBuffer ();
1275
    String          header  = parent.langpack.getString ("ShortcutPanel.textFile.header");
1276

    
1277
    String newline = System.getProperty ("line.separator", "\n");
1278

    
1279
    try
1280
    {
1281
      output = new FileWriter (file);
1282
    }
1283
    catch (Throwable exception)
1284
    {
1285
      // !!! show an error dialog
1286
      return;
1287
    }
1288

    
1289
    // ----------------------------------------------------
1290
    // break the header down into multiple lines based
1291
    // on '\n' line breaks.
1292
    // ----------------------------------------------------
1293
    int nextIndex     = 0;
1294
    int currentIndex  = 0;
1295

    
1296
    do
1297
    {
1298
      nextIndex = header.indexOf ("\\n", currentIndex);
1299

    
1300
      if (nextIndex > -1)
1301
      {
1302
        buffer.append (header.substring (currentIndex, nextIndex));
1303
        buffer.append (newline);
1304
        currentIndex =  nextIndex + 2;
1305
      }
1306
      else
1307
      {
1308
        buffer.append (header.substring (currentIndex, header.length ()));
1309
        buffer.append (newline);
1310
      }
1311
    }
1312
    while (nextIndex > -1);
1313

    
1314
    buffer.append (SEPARATOR_LINE);
1315
    buffer.append (newline);
1316
    buffer.append (newline);
1317

    
1318
    for (int i = 0; i < shortcuts.size (); i++)
1319
    {
1320
      ShortcutData data = (ShortcutData)shortcuts.elementAt (i);
1321

    
1322
      buffer.append (parent.langpack.getString ("ShortcutPanel.textFile.name"));
1323
      buffer.append (data.name);
1324
      buffer.append (newline);
1325

    
1326
      buffer.append (parent.langpack.getString ("ShortcutPanel.textFile.location"));
1327
      switch (data.type)
1328
      {
1329
        case Shortcut.DESKTOP :
1330
          {
1331
            buffer.append (parent.langpack.getString ("ShortcutPanel.location.desktop"));
1332
            break;
1333
          }
1334
        case Shortcut.APPLICATIONS :
1335
          {
1336
            buffer.append (parent.langpack.getString ("ShortcutPanel.location.applications"));
1337
            break;
1338
          }
1339
        case Shortcut.START_MENU :
1340
          {
1341
            buffer.append (parent.langpack.getString ("ShortcutPanel.location.startMenu"));
1342
            break;
1343
          }
1344
        case Shortcut.START_UP :
1345
          {
1346
            buffer.append (parent.langpack.getString ("ShortcutPanel.location.startup"));
1347
            break;
1348
          }
1349
      }
1350
      buffer.append (newline);
1351

    
1352
      buffer.append (parent.langpack.getString ("ShortcutPanel.textFile.description"));
1353
      buffer.append (data.description);
1354
      buffer.append (newline);
1355

    
1356
      buffer.append (parent.langpack.getString ("ShortcutPanel.textFile.target"));
1357
      buffer.append (data.target);
1358
      buffer.append (newline);
1359

    
1360
      buffer.append (parent.langpack.getString ("ShortcutPanel.textFile.command"));
1361
      buffer.append (data.commandLine);
1362
      buffer.append (newline);
1363

    
1364
      buffer.append (parent.langpack.getString ("ShortcutPanel.textFile.iconName"));
1365
      buffer.append (data.iconFile);
1366
      buffer.append (newline);
1367

    
1368
      buffer.append (parent.langpack.getString ("ShortcutPanel.textFile.iconIndex"));
1369
      buffer.append (data.iconIndex);
1370
      buffer.append (newline);
1371

    
1372
      buffer.append (parent.langpack.getString ("ShortcutPanel.textFile.work"));
1373
      buffer.append (data.workingDirectory);
1374
      buffer.append (newline);
1375

    
1376
      buffer.append (newline);
1377
      buffer.append (SEPARATOR_LINE);
1378
      buffer.append (newline);
1379
      buffer.append (newline);
1380
    }
1381

    
1382
    try
1383
    {
1384
      output.write (buffer.toString ());
1385
    }
1386
    catch (Throwable exception)
1387
    {
1388
    }
1389
    finally
1390
    {
1391
      try
1392
      {
1393
        output.flush ();
1394
        output.close ();
1395
        files.add (file.getPath ());
1396
      }
1397
      catch (Throwable exception)
1398
      {
1399
        // not really anything I can do here, maybe should show a dialog that
1400
        // tells the user that data might not have been saved completely!?
1401
      }
1402
    }
1403
  }
1404
 /*--------------------------------------------------------------------------*/
1405
 /**
1406
  * Adds all files and directories to the uninstaller.
1407
  */
1408
 /*--------------------------------------------------------------------------*/
1409
  private void addToUninstaller ()
1410
  {
1411
    UninstallData uninstallData = UninstallData.getInstance ();
1412

    
1413
    for (int i = 0; i < files.size (); i++)
1414
    {
1415
      uninstallData.addFile ((String)files.elementAt (i));
1416
    }
1417
  }
1418
 /*--------------------------------------------------------------------------*/
1419
 /**
1420
  * Adds iformation about the shortcuts that have been created during the
1421
  * installation to the XML tree.
1422
  *
1423
  * @param     panelRoot    the root of the XML tree
1424
  */
1425
 /*--------------------------------------------------------------------------*/
1426
 /*$
1427
  * @design
1428
  *
1429
  * The information needed to create shortcuts has been collected in the
1430
  * Vector 'shortcuts'. Take the data from there and package it in XML form
1431
  * for storage by the installer. The group name is only stored once in a
1432
  * separate XML element, since there is only one.
1433
  *--------------------------------------------------------------------------*/
1434
  public void makeXMLData (XMLElement panelRoot)
1435
  {
1436
    // ----------------------------------------------------
1437
    // if there are no shortcuts to create, shortcuts are
1438
    // not supported, or we should simulate that they are
1439
    // not supported, then we have nothing to add. Just
1440
    // return
1441
    // ----------------------------------------------------
1442
    if (!shortcutsToCreate     ||
1443
        !shortcut.supported () ||
1444
        groupName == null      ||
1445
         simulteNotSupported      )
1446
    {
1447
      return;
1448
    }
1449

    
1450
    ShortcutData  data;
1451
    XMLElement    dataElement;
1452

    
1453
    // ----------------------------------------------------
1454
    // add the item that defines the name of the program group
1455
    // ----------------------------------------------------
1456
    dataElement = new XMLElement (AUTO_KEY_PROGRAM_GROUP);
1457
    dataElement.setAttribute (AUTO_ATTRIBUTE_NAME, groupName);
1458
    panelRoot.addChild (dataElement);
1459

    
1460
    // ----------------------------------------------------
1461
    // add the details for each of the shortcuts
1462
    // ----------------------------------------------------
1463
    for (int i = 0; i < shortcuts.size (); i++)
1464
    {
1465
      data        = (ShortcutData)shortcuts.elementAt (i);
1466
      dataElement = new XMLElement (AUTO_KEY_SHORTCUT);
1467

    
1468
      dataElement.setAttribute (AUTO_ATTRIBUTE_NAME,          data.name);
1469
      dataElement.setAttribute (AUTO_ATTRIBUTE_GROUP,         Boolean.valueOf(data.addToGroup).toString ());
1470
      dataElement.setAttribute (AUTO_ATTRIBUTE_TYPE,          Integer.toString (data.type));
1471
      dataElement.setAttribute (AUTO_ATTRIBUTE_COMMAND,       data.commandLine);
1472
      dataElement.setAttribute (AUTO_ATTRIBUTE_DESCRIPTION,   data.description);
1473
      dataElement.setAttribute (AUTO_ATTRIBUTE_ICON,          data.iconFile);
1474
      dataElement.setAttribute (AUTO_ATTRIBUTE_ICON_INDEX,    Integer.toString (data.iconIndex));
1475
      dataElement.setAttribute (AUTO_ATTRIBUTE_INITIAL_STATE, Integer.toString (data.initialState));
1476
      dataElement.setAttribute (AUTO_ATTRIBUTE_TARGET,        data.target);
1477
      dataElement.setAttribute (AUTO_ATTRIBUTE_WORKING_DIR,   data.workingDirectory);
1478

    
1479
      // ----------------------------------------------
1480
      // add the shortcut only if it is either not on
1481
      // the desktop or if it is on the desktop and
1482
      // the user has signalled that it is ok to place
1483
      // shortcuts on the desktop.
1484
      // ----------------------------------------------
1485
      if ( (data.type != Shortcut.DESKTOP)                                         ||
1486
          ((data.type == Shortcut.DESKTOP) && allowDesktopShortcut.isSelected ())     )
1487
      {
1488
        panelRoot.addChild (dataElement);
1489
      }
1490
    }
1491
  }
1492
 /*--------------------------------------------------------------------------*/
1493
 /**
1494
  * Creates shortcuts based on teh information in <code>panelRoot</code>
1495
  * without UI.
1496
  *
1497
  * @param     panelRoot    the root of the XML tree
1498
  */
1499
 /*--------------------------------------------------------------------------*/
1500
 /*$
1501
  * @design
1502
  *
1503
  * Reconstitute the information needed to create shortcuts from XML data
1504
  * that was previously stored by the installer through makeXMLData(). Create
1505
  * a new Vector containing this data and stroe it in 'shortcuts' for use by
1506
  * createShortcuts().
1507
  * Once this has been completed, call createShortcuts() to complete the
1508
  * operation.
1509
  *--------------------------------------------------------------------------*/
1510
  public void runAutomated (XMLElement panelRoot)
1511
  {
1512
    // ----------------------------------------------------
1513
    // if shortcuts are not supported, then we can not
1514
    // create shortcuts, even if there was any install
1515
    // data. Just return.
1516
    // ----------------------------------------------------
1517
    if (!shortcut.supported ())
1518
    {
1519
      return;
1520
    }
1521

    
1522
    if (! OsConstraint.oneMatchesCurrentSystem(panelRoot))
1523
    {
1524
      return;
1525
    }
1526

    
1527
    shortcuts     = new Vector ();
1528
    Vector        shortcutElements;
1529
    ShortcutData  data;
1530
    XMLElement    dataElement;
1531

    
1532
    // ----------------------------------------------------
1533
    // set the name of the program group
1534
    // ----------------------------------------------------
1535
    dataElement = panelRoot.getFirstChildNamed (AUTO_KEY_PROGRAM_GROUP);
1536
    groupName   = dataElement.getAttribute (AUTO_ATTRIBUTE_NAME);
1537

    
1538
    if (groupName == null)
1539
    {
1540
      groupName = "";
1541
    }
1542

    
1543
    // ----------------------------------------------------
1544
    // add the details for each of the shortcuts
1545
    // ----------------------------------------------------
1546
    shortcutElements = panelRoot.getChildrenNamed (AUTO_KEY_SHORTCUT);
1547

    
1548
    for (int i = 0; i < shortcutElements.size (); i++)
1549
    {
1550
      data        = new ShortcutData ();
1551
      dataElement = (XMLElement)shortcutElements.elementAt (i);
1552

    
1553
      data.name             = dataElement.getAttribute (AUTO_ATTRIBUTE_NAME);
1554
      data.addToGroup       = Boolean.valueOf (dataElement.getAttribute (AUTO_ATTRIBUTE_GROUP)).booleanValue ();
1555
      data.type             = Integer.valueOf (dataElement.getAttribute (AUTO_ATTRIBUTE_TYPE)).intValue ();
1556
      data.commandLine      = dataElement.getAttribute (AUTO_ATTRIBUTE_COMMAND);
1557
      data.description      = dataElement.getAttribute (AUTO_ATTRIBUTE_DESCRIPTION);
1558
      data.iconFile         = dataElement.getAttribute (AUTO_ATTRIBUTE_ICON);
1559
      data.iconIndex        = Integer.valueOf (dataElement.getAttribute (AUTO_ATTRIBUTE_ICON_INDEX)).intValue ();
1560
      data.initialState     = Integer.valueOf (dataElement.getAttribute (AUTO_ATTRIBUTE_INITIAL_STATE)).intValue ();
1561
      data.target           = dataElement.getAttribute (AUTO_ATTRIBUTE_TARGET);
1562
      data.workingDirectory = dataElement.getAttribute (AUTO_ATTRIBUTE_WORKING_DIR);
1563

    
1564
      shortcuts.add (data);
1565
    }
1566

    
1567
    createShortcuts ();
1568
  }
1569
}
1570
/*---------------------------------------------------------------------------*/