/** Update the arrow head type on the currently selected links. */
  private void onUpdateArrowType(int nArrowType) {
    if (!bJustSetting) {

      UIViewFrame frame = ProjectCompendium.APP.getCurrentFrame();
      Model oModel = (Model) ProjectCompendium.APP.getModel();
      if (frame instanceof UIMapViewFrame) {

        Vector vtUpdateLinks = new Vector();
        UIMapViewFrame oMapFrame = (UIMapViewFrame) frame;
        UIViewPane pane = oMapFrame.getViewPane();
        UILink link = null;
        LinkProperties props = null;
        for (Enumeration e = pane.getSelectedLinks(); e.hasMoreElements(); ) {
          link = (UILink) e.nextElement();
          props = link.getLinkProperties();
          if (nArrowType != props.getArrowType()) {
            vtUpdateLinks.addElement(props);
          }
        }
        if (vtUpdateLinks.size() > 0) {
          try {
            ((ViewService) oModel.getViewService())
                .setArrowType(
                    oModel.getSession(), pane.getView().getId(), vtUpdateLinks, nArrowType);
            int count = vtUpdateLinks.size();
            for (int i = 0; i < count; i++) {
              props = (LinkProperties) vtUpdateLinks.elementAt(i);
              props.setArrowType(nArrowType);
            }
          } catch (SQLException ex) {
            ProjectCompendium.APP.displayError(
                LanguageProperties.getString(
                        LanguageProperties.TOOLBARS_BUNDLE,
                        "UIToolBarFormatLink.unableUpdateArrowType")
                    + ":\n\n"
                    + ex.getMessage()); // $NON-NLS-1$
          }
        }
      }
    }
  }
  /**
   * Does Nothing
   *
   * @param selected, true to enable, false to disable.
   */
  public void setNodeOrLinkSelected(boolean selected) {
    if (tbrToolBar != null) {

      UIViewFrame frame = ProjectCompendium.APP.getCurrentFrame();
      if (selected && frame instanceof UIMapViewFrame) {
        UIMapViewFrame oMapFrame = (UIMapViewFrame) frame;
        UIViewPane pane = oMapFrame.getViewPane();

        int nLinkCount = pane.getNumberOfSelectedLinks();
        if (nLinkCount == 0) return;

        bJustSetting = true;

        int i = 0;
        UILink link = null;
        LinkProperties linkProps = null;
        boolean bDefaultLinkStyle = false;
        boolean bDefaultLinkDashed = false;
        boolean bDefaultLinkWeight = false;
        boolean bDefaultLinkColour = false;
        boolean bDefaultArrowType = false;

        LinkProperties defaultprops = UIUtilities.getLinkProperties("");
        int linkstyle = defaultprops.getLinkStyle();
        int linkdashed = defaultprops.getLinkDashed();
        int linkweight = defaultprops.getLinkWeight();
        int linkcolour = defaultprops.getLinkColour();
        int arrowtype = defaultprops.getArrowType();

        for (Enumeration e = pane.getSelectedLinks(); e.hasMoreElements(); ) {
          link = (UILink) e.nextElement();
          linkProps = link.getLinkProperties();
          if (i == 0) {
            linkstyle = linkProps.getLinkStyle();
            linkdashed = linkProps.getLinkDashed();
            linkweight = linkProps.getLinkWeight();
            linkcolour = linkProps.getLinkColour();
            arrowtype = linkProps.getArrowType();
            i++;
          } else {
            if (arrowtype != linkProps.getArrowType()) {
              bDefaultArrowType = true;
            }
            if (linkstyle != linkProps.getLinkStyle()) {
              bDefaultLinkStyle = true;
            }
            if (linkdashed != linkProps.getLinkDashed()) {
              bDefaultLinkDashed = true;
            }
            if (linkweight != linkProps.getLinkWeight()) {
              bDefaultLinkWeight = true;
            }
            if (linkcolour != linkProps.getLinkColour()) {
              bDefaultLinkColour = true;
            }
          }
        }

        tbrToolBar.setEnabled(true);

        if (bDefaultLinkColour) {
          selectedLinkColour = new Color(defaultprops.getLinkColour());
        } else {
          selectedLinkColour = new Color(linkcolour);
        }

        linkColourPanel.setEnabled(true);
        txtLinkColour.setEnabled(true);

        cbLineWeight.setEnabled(true);
        if (bDefaultLinkWeight) {
          cbLineWeight.setSelectedIndex(defaultprops.getLinkWeight() - 1);
        } else {
          cbLineWeight.setSelectedIndex(linkweight - 1);
        }

        cbArrows.setEnabled(true);
        if (bDefaultArrowType) {
          cbArrows.setSelectedIndex(defaultprops.getArrowType());
        } else {
          cbArrows.setSelectedIndex(arrowtype);
        }

        cbLinkStyle.setEnabled(true);
        if (bDefaultLinkStyle) {
          cbLinkStyle.setSelectedIndex(defaultprops.getLinkStyle());
        } else {
          cbLinkStyle.setSelectedIndex(linkstyle);
        }

        cbLinkDashed.setEnabled(true);
        if (bDefaultLinkDashed) {
          cbLinkDashed.setSelectedIndex(defaultprops.getLinkDashed());
        } else {
          cbLinkDashed.setSelectedIndex(linkdashed);
        }

        bJustSetting = false;

      } else if (!selected) {

        bJustSetting = true;

        linkColourPanel.setEnabled(false);
        txtLinkColour.setEnabled(false);
        tbrToolBar.setEnabled(false);
        cbArrows.setEnabled(false);
        cbLineWeight.setEnabled(false);
        cbLinkStyle.setEnabled(false);
        cbLinkDashed.setEnabled(false);

        bJustSetting = false;
      }
    }
  }
  /**
   * Load the default data if any is specified in the System.ini file.
   *
   * @param sHomeViewID the id of the home view to load the data into.
   * @return true if completely successful.
   * @exception IOException if there is an IO or Zip error.
   */
  private boolean loadDefaultData(String sHomeViewID) throws IOException {

    String defaultDataPath = SystemProperties.projectDefaultDataFile;
    if (!defaultDataPath.equals("")) { // $NON-NLS-1$
      String sXMLFile = defaultDataPath;

      if (defaultDataPath.endsWith(".zip")) { // $NON-NLS-1$
        ZipFile zipFile = new ZipFile(defaultDataPath);
        Enumeration entries = zipFile.entries();
        ZipEntry entry = null;
        String sTemp = ""; // $NON-NLS-1$

        while (entries.hasMoreElements()) {
          entry = (ZipEntry) entries.nextElement();
          sTemp = entry.getName();
          if (sTemp.endsWith(".xml") && sTemp.startsWith("Exports")) { // $NON-NLS-1$ //$NON-NLS-2$
            sXMLFile = sTemp;
          }
          // AVOID Thumbs.db files
          if (sTemp.endsWith(".db")) { // $NON-NLS-1$
            continue;
          }

          int len = 0;
          byte[] buffer = new byte[1024];
          InputStream in = zipFile.getInputStream(entry);

          String sFileName = ""; // $NON-NLS-1$
          String sLinkedFiles = "Linked Files/"; // $NON-NLS-1$
          if (sTemp.startsWith(sLinkedFiles)) {
            sFileName =
                UIUtilities.sGetLinkedFilesLocation() + sTemp.substring(sLinkedFiles.length());
          } else {
            sFileName = entry.getName();
          }
          File file = new File(sFileName);
          if (file.getParentFile() != null) {
            file.getParentFile().mkdirs();
          }

          OutputStream out = new BufferedOutputStream(new FileOutputStream(sFileName));
          while ((len = in.read(buffer)) >= 0) {
            out.write(buffer, 0, len);
          }
          in.close();
          out.close();
        }

        zipFile.close();
      }

      // IMPORT THE XML
      if (!sXMLFile.equals("") && sXMLFile.endsWith(".xml")) { // $NON-NLS-1$ //$NON-NLS-2$
        File oXMLFile = new File(sXMLFile);
        if (oXMLFile.exists()) {
          boolean importAuthorAndDate = false;
          boolean includeOriginalAuthorDate = false;
          boolean preserveIDs = true;
          boolean transclude = true;
          boolean updateTranscludedNodes = false;

          File oXMLFile2 = new File(sXMLFile);
          if (oXMLFile2.exists()) {
            DBNode.setImportAsTranscluded(transclude);
            DBNode.setPreserveImportedIds(preserveIDs);
            DBNode.setUpdateTranscludedNodes(updateTranscludedNodes);
            DBNode.setNodesMarkedSeen(true);

            UIViewFrame frame = ProjectCompendium.APP.getCurrentFrame();
            if (frame instanceof UIMapViewFrame) {
              UIMapViewFrame mapFrame = (UIMapViewFrame) frame;
              UIViewPane oViewPane = mapFrame.getViewPane();
              ViewPaneUI oViewPaneUI = oViewPane.getUI();
              if (oViewPaneUI != null) {
                oViewPaneUI.setSmartImport(importAuthorAndDate);
                oViewPaneUI.onImportXMLFile(sXMLFile, includeOriginalAuthorDate);
              }
            } else if (frame instanceof UIListViewFrame) {
              UIListViewFrame listFrame = (UIListViewFrame) frame;
              UIList uiList = listFrame.getUIList();
              if (uiList != null) {
                uiList.getListUI().setSmartImport(importAuthorAndDate);
                uiList.getListUI().onImportXMLFile(sXMLFile, includeOriginalAuthorDate);
              }
            }
            return true;
          }
        } else {
          ProjectCompendium.APP.displayError(
              LanguageProperties.getString(
                      LanguageProperties.DIALOGS_BUNDLE, "UINewDatabaseDialog.missingFileA")
                  + "\n\n"
                  + LanguageProperties.getString(
                      LanguageProperties.DIALOGS_BUNDLE, "UINewDatabaseDialog.missingFileB")
                  + "\n"); //$NON-NLS-1$
          return false;
        }
      } else {
        return true; // there is allowed to be no default data to load.
      }
      return false;
    }
    return true;
  }