Example #1
0
  private JButton createButton(String text, String command) {
    JButton btn = UIUtilities.createCustomButton(text, this);
    btn.setActionCommand(command);

    return btn;
  }
  /** Handle the import action request. */
  public void onImport() {

    String finalFile = ""; // $NON-NLS-1$

    if (file == null) {
      UIFileFilter filter =
          new UIFileFilter(new String[] {"xml"}, "XML Files"); // $NON-NLS-1$ //$NON-NLS-2$

      UIFileChooser fileDialog = new UIFileChooser();
      fileDialog.setDialogTitle(
          LanguageProperties.getString(
              LanguageProperties.DIALOGS_BUNDLE,
              "UIImportFlashMeetingXMLDialog.chooseFile2")); //$NON-NLS-1$
      fileDialog.setFileFilter(filter);
      fileDialog.setApproveButtonText(
          LanguageProperties.getString(
              LanguageProperties.DIALOGS_BUNDLE,
              "UIImportFlashMeetingXMLDialog.importButton")); //$NON-NLS-1$
      fileDialog.setRequiredExtension(".xml"); // $NON-NLS-1$

      // FIX FOR MAC - NEEDS '/' ON END TO DENOTE A FOLDER
      if (!UIImportFlashMeetingXMLDialog.lastFileDialogDir.equals("")) { // $NON-NLS-1$
        File file =
            new File(UIImportFlashMeetingXMLDialog.lastFileDialogDir + ProjectCompendium.sFS);
        if (file.exists()) {
          fileDialog.setCurrentDirectory(file);
        }
      }

      UIUtilities.centerComponent(fileDialog, ProjectCompendium.APP);
      int retval = fileDialog.showOpenDialog(ProjectCompendium.APP);
      if (retval == JFileChooser.APPROVE_OPTION) {
        if ((fileDialog.getSelectedFile()) != null) {

          String fileName = fileDialog.getSelectedFile().getAbsolutePath();
          File fileDir = fileDialog.getCurrentDirectory();
          String dir = fileDir.getPath();

          if (fileName != null) {
            UIImportFlashMeetingXMLDialog.lastFileDialogDir = dir;
            finalFile = fileName;
          }
        }
      }
    } else {
      finalFile = file.getAbsolutePath();
    }

    if (finalFile != null) {
      if ((new File(finalFile)).exists()) {
        setVisible(false);
        Vector choices = new Vector();

        if (cbIncludeKeywords.isSelected()) {
          choices.addElement(FlashMeetingXMLImport.KEYWORDS_LABEL);
        }
        if (cbIncludeAttendees.isSelected()) {
          choices.addElement(FlashMeetingXMLImport.ATTENDEE_LABEL);
        }
        if (cbIncludePlayList.isSelected()) {
          choices.addElement(FlashMeetingXMLImport.PLAYLIST_LABEL);
        }
        if (cbIncludeURLs.isSelected()) {
          choices.addElement(FlashMeetingXMLImport.URL_LABEL);
        }
        if (cbIncludeChats.isSelected()) {
          choices.addElement(FlashMeetingXMLImport.CHAT_LABEL);
        }
        if (cbIncludeWhiteboard.isSelected()) {
          choices.addElement(FlashMeetingXMLImport.WHITEBOARD_LABEL);
        }
        if (cbIncludeFileData.isSelected()) {
          choices.addElement(FlashMeetingXMLImport.FILEDATA_LABEL);
        }
        if (cbIncludeAnnotations.isSelected()) {
          choices.addElement(FlashMeetingXMLImport.ANNOTATIONS_LABEL);
        }
        if (cbIncludeVotes.isSelected()) {
          choices.addElement(FlashMeetingXMLImport.VOTING_LABEL);
        }

        DBNode.setNodesMarkedSeen(cbMarkSeen.isSelected());

        FlashMeetingXMLImport xmlImport =
            new FlashMeetingXMLImport(finalFile, ProjectCompendium.APP.getModel(), choices);
        xmlImport.start();

        dispose();
        ProjectCompendium.APP.setStatus(""); // $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;
      }
    }
  }
  /**
   * Get the contents of a URL and return it as an image.
   *
   * @return a String representing the path the file was actually saved to, or empty string if
   *     something failed.
   */
  public static String loadWebImageToLinkedFiles(String address, String sFileName, String sPath)
      throws Exception {

    ProjectCompendium.APP.setWaitCursor();

    File newFile = new File(sPath + sFileName);

    String imgAddress = address.toLowerCase();

    if ((imgAddress.startsWith("www")
            || imgAddress.startsWith("http")
            || imgAddress.startsWith("https")) // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        && isImage(imgAddress)) { // $NON-NLS-1$

      if (newFile.exists()) {
        int response =
            JOptionPane.showConfirmDialog(
                ProjectCompendium.APP,
                LanguageProperties.getString(
                        LanguageProperties.UI_GENERAL_BUNDLE, "UIImages.nameExistsMessage1a")
                    + "\n"
                    + //$NON-NLS-1$ //$NON-NLS-2$
                    LanguageProperties.getString(
                        LanguageProperties.UI_GENERAL_BUNDLE, "UIImages.nameExistsMessage1b")
                    + "\n\n"
                    + //$NON-NLS-1$ //$NON-NLS-2$
                    "("
                    + LanguageProperties.getString(
                        LanguageProperties.UI_GENERAL_BUNDLE, "UIImages.nameExistsMessage1c")
                    + ")\n\n", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                LanguageProperties.getString(
                    LanguageProperties.UI_GENERAL_BUNDLE, "UIImages.externalDragAndDrop"),
                JOptionPane.YES_NO_OPTION); // $NON-NLS-1$

        if (response == JOptionPane.YES_OPTION) {

          UIFileChooser fileDialog = new UIFileChooser();
          fileDialog.setDialogType(JFileChooser.SAVE_DIALOG);
          fileDialog.setDialogTitle(
              LanguageProperties.getString(
                  LanguageProperties.UI_GENERAL_BUNDLE, "UIImages.changeFileName")); // $NON-NLS-1$
          fileDialog.setApproveButtonText(
              LanguageProperties.getString(
                  LanguageProperties.UI_GENERAL_BUNDLE, "UIImages.saveButton")); // $NON-NLS-1$
          fileDialog.setCurrentDirectory(new File(newFile.getParent() + ProjectCompendium.sFS));
          fileDialog.setSelectedFile(newFile);
          UIUtilities.centerComponent(fileDialog, ProjectCompendium.APP);
          int retval = fileDialog.showSaveDialog(ProjectCompendium.APP);
          if (retval == JFileChooser.APPROVE_OPTION) {
            if ((fileDialog.getSelectedFile()) != null) {

              String fileName2 = fileDialog.getSelectedFile().getName();
              if (fileName2 != null) {
                sFileName = fileName2;
                File fileDir = fileDialog.getCurrentDirectory();

                if (ProjectCompendium.isMac)
                  sPath = fileDir.getAbsolutePath() + ProjectCompendium.sFS;
                else sPath = fileDir.getPath();
              }
            }
          } else {
            return new String(""); // $NON-NLS-1$
          }
        }
      }

      URL url = new URL(address);
      URLConnection conn = url.openConnection();
      conn.connect();

      DataInputStream stream = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
      FileOutputStream output = new FileOutputStream(sPath + sFileName);
      int count = conn.getContentLength();
      if (count > 0) {
        for (int i = 0; i < count; i++) {
          output.write(stream.read());
        }
      } else {
        sFileName = ""; // $NON-NLS-1$
      }

      stream.close();
      output.flush();
      output.close();

      ProjectCompendium.APP.setDefaultCursor();
      return sPath + sFileName;

    } else {
      ProjectCompendium.APP.setDefaultCursor();
      return new String(""); // $NON-NLS-1$
    }
  }