protected void selectFile() {
    ResourceManager rm = ResourceManager.all(FilePropertyEditor.class);

    JFileChooser chooser = UserPreferences.getDefaultDirectoryChooser();

    chooser.setDialogTitle(rm.getString("DirectoryPropertyEditor.dialogTitle"));
    chooser.setApproveButtonText(rm.getString("DirectoryPropertyEditor.approveButtonText"));
    chooser.setApproveButtonMnemonic(rm.getChar("DirectoryPropertyEditor.approveButtonMnemonic"));

    File oldFile = (File) getValue();
    if (oldFile != null && oldFile.isDirectory()) {
      try {
        chooser.setCurrentDirectory(oldFile.getCanonicalFile());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(editor)) {
      File newFile = chooser.getSelectedFile();
      String text = newFile.getAbsolutePath();
      textfield.setText(text);
      firePropertyChange(oldFile, newFile);
    }
  }
 private void setupFileChooser() {
   fileChooser = new JFileChooser();
   fileChooser.setDialogTitle("Select directory to output ISArchive to...");
   fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
   fileChooser.setApproveButtonText("Output to selected directory");
   fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
 }
Exemple #3
0
  /**
   * Displays a custom file chooser sheet with a custom approve button.
   *
   * @param chooser the chooser
   * @param parent the parent component of the dialog; can be {@code null}
   * @param approveButtonText the text of the {@code ApproveButton}
   * @param listener The listener for SheetEvents.
   */
  public static void showSheet(
      final JFileChooser chooser,
      Component parent,
      String approveButtonText,
      SheetListener listener) {
    if (approveButtonText != null) {
      chooser.setApproveButtonText(approveButtonText);
      chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    }

    // Begin Create Dialog
    Frame frame =
        parent instanceof Frame
            ? (Frame) parent
            : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);

    String title = chooser.getUI().getDialogTitle(chooser);
    chooser.getAccessibleContext().setAccessibleDescription(title);

    final JSheet sheet = new JSheet(frame);
    sheet.addSheetListener(listener);

    Container contentPane = sheet.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(chooser, BorderLayout.CENTER);
    // End Create Dialog

    final ActionListener actionListener =
        new ActionListener() {

          public void actionPerformed(ActionEvent evt) {
            int option;
            if (evt.getActionCommand().equals("ApproveSelection")) {
              option = JFileChooser.APPROVE_OPTION;
            } else {
              option = JFileChooser.CANCEL_OPTION;
            }
            sheet.hide();
            sheet.fireOptionSelected(chooser, option);
            chooser.removeActionListener(this);
          }
        };
    chooser.addActionListener(actionListener);
    sheet.addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            sheet.fireOptionSelected(chooser, JFileChooser.CANCEL_OPTION);
            chooser.removeActionListener(actionListener);
          }
        });
    chooser.rescanCurrentDirectory();
    sheet.pack();
    sheet.show();
    sheet.toFront();
  }
 private String getFileName(String title, String okButton, String currentDirectory) {
   JFileChooser fileChooser = new JFileChooser();
   fileChooser.setDialogTitle(title);
   fileChooser.setApproveButtonText(okButton);
   fileChooser.setCurrentDirectory(new File(currentDirectory));
   int result = fileChooser.showOpenDialog(this);
   if (result == JFileChooser.APPROVE_OPTION) {
     File selectedFile = fileChooser.getSelectedFile();
     return selectedFile.getAbsolutePath();
   }
   return null;
 }
  private void selectFolder() {

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(new File(textFolder.getText()));
    fileChooser.setDialogTitle(CAPTION_SELECT_FOLDER);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setApproveButtonText("Select");
    fileChooser.setApproveButtonToolTipText(TOOL_TIP_SELECT_FOLDER);

    if (fileChooser.showOpenDialog(FileTransferServer.this) == JFileChooser.APPROVE_OPTION) {
      // Get the selected file
      String path = fileChooser.getSelectedFile().getPath() + "\\";
      textFolder.setText(path);
    }
  }
Exemple #6
0
  public void init() {
    tabbedPane.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
              contextMenu.show(e.getComponent(), e.getX(), e.getY());
            }
          }

          public void mouseReleased(MouseEvent e) {}
        });
    fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Save file");
    fileChooser.setApproveButtonText("Save file");
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
  }
  /** Constructor */
  public SaverCustomizer() {

    try {
      m_SaverEditor.addPropertyChangeListener(
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
              repaint();
              if (m_dsSaver != null) {
                System.err.println("Property change!!");
                m_dsSaver.setSaver(m_dsSaver.getSaver());
              }
            }
          });
      repaint();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    setLayout(new BorderLayout());
    m_fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    m_fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    m_fileChooser.setApproveButtonText("Select directory");
    m_fileChooser.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION)) {
              try {
                File selectedFile = m_fileChooser.getSelectedFile();
                m_directoryText.setText(selectedFile.toString());

                /* (m_dsSaver.getSaver()).setFilePrefix(m_prefixText.getText());
                (m_dsSaver.getSaver()).setDir(m_fileChooser.getSelectedFile().getPath());
                m_dsSaver.
                  setRelationNameForFilename(m_relationNameForFilename.isSelected()); */

              } catch (Exception ex) {
                ex.printStackTrace();
              }
            }
            // closing
            if (m_fileChooserFrame != null) {
              m_fileChooserFrame.dispose();
            }
          }
        });
  }
  /**
   * Create the JPanel to allow users to save the mappings created to be used in a proceeding
   * mapping activity!
   *
   * @return JLayeredPane containing the gui to allow a user to save the mapping file!
   */
  private JLayeredPane createSaveMappings() {
    JPanel saveMappingFilesCont = new JPanel();
    saveMappingFilesCont.setSize(new Dimension(400, 300));
    saveMappingFilesCont.setLayout(new BoxLayout(saveMappingFilesCont, BoxLayout.PAGE_AXIS));

    saveMappingFilesCont.add(
        UIHelper.wrapComponentInPanel(new JLabel(saveMappingHelp, SwingConstants.CENTER)));
    saveMappingFilesCont.add(Box.createVerticalStrut(10));
    saveMappingFilesCont.add(
        UIHelper.wrapComponentInPanel(
            UIHelper.createLabel(
                ""
                    + "<html>"
                    + "Please be aware, the mappings saved are saved on a field by field basis. "
                    + "This means that regardless of what assay you selected to do this/these mappings,"
                    + " common fields amongst all assays automatically inherit the mapping information. This has a number"
                    + " of benefits and a number of negative points. "
                    + "<br/>"
                    + "<p>The <strong>main benefit</strong> being that common field mappings are transportable regardless of assay types.<p>"
                    + "<p>The <strong>main problem</strong> is that because fields are saved on a field name basis, duplicate fields like"
                    + " <strong>Protocol REF</strong> columns are not saved. This mechanism for saving will be changed in the next release!</p>"
                    + "<br/>"
                    + "<br/>"
                    + "<br/>"
                    + "</html>",
                UIHelper.VER_11_PLAIN,
                UIHelper.GREY_COLOR)));

    // create selector for mapping files
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Choose where and what to save the file as...");
    chooser.setApproveButtonText("Select file");

    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    JPanel selectMappingPanel = new JPanel();
    selectMappingPanel.setLayout(new BoxLayout(selectMappingPanel, BoxLayout.PAGE_AXIS));
    selectMappingPanel.setOpaque(false);

    // need a jcheckbox to ask users if they wish to use a mapping
    JPanel useMappingContainer = new JPanel(new BorderLayout());
    useMappingContainer.setOpaque(false);

    final JPanel savedMappingsPanel = new JPanel();
    savedMappingsPanel.setLayout(new BoxLayout(savedMappingsPanel, BoxLayout.PAGE_AXIS));
    savedMappingsPanel.setOpaque(false);
    savedMappingsPanel.setVisible(false);

    final JLabel saveStatusInfo =
        UIHelper.createLabel("", UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR);

    final FileSelectionPanel savedMappingsFile =
        new FileSelectionPanel(
            "<html>select <strong>where</strong> to save file and <strong>it's name</strong>: </html>",
            chooser,
            FileSelectionPanel.SAVE);

    final JCheckBox useMapping = new JCheckBox("save mapping?");
    UIHelper.renderComponent(useMapping, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false);
    useMapping.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            savedMappingsPanel.setVisible(useMapping.isSelected());
            saveStatusInfo.setText("");
          }
        });

    useMappingContainer.add(useMapping, BorderLayout.WEST);
    selectMappingPanel.add(useMappingContainer);

    // add button to save mappings
    final JLabel saveMappingsButton = new JLabel(saveMappingsButtonIcon);
    saveMappingsButton.setVerticalAlignment(JLabel.BOTTOM);
    saveMappingsButton.addMouseListener(
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            saveMappingsButton.setIcon(saveMappingsButtonIconOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            saveMappingsButton.setIcon(saveMappingsButtonIcon);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            // save the mapping

            MappingXMLCreator mappingCreator = new MappingXMLCreator();
            try {
              if (useMapping.isSelected()) {
                if (!savedMappingsFile.getSelectedFilePath().equals("")) {
                  nextButton.setEnabled(false);
                  backButton.setEnabled(false);
                  mappingCreator.createXMLFile(
                      savedMappingsFile.getSelectedFilePath(), mappingsToSave, assaysToBeDefined);
                  saveStatusInfo.setText("mappings saved successfully...");
                } else {
                  saveStatusInfo.setText("please select a file...");
                }
              }
            } catch (FileNotFoundException e) {
              e.printStackTrace();
              saveStatusInfo.setText("mappings not saved..." + e.getMessage());
            } finally {
              nextButton.setEnabled(true);
              backButton.setEnabled(true);
            }
          }
        });

    final JLayeredPane finalPanel =
        getGeneralLayout(saveMappingsHeader, breadcrumb7, "", saveMappingFilesCont, getHeight());

    final MouseListener[] listeners = new MouseListener[2];

    listeners[0] =
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            backButton.setIcon(backOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            backButton.setIcon(back);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            backButton.setIcon(back);
            saveStatusInfo.setText("");
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    HistoryComponent hc = previousPage.pop();
                    setCurrentPage(hc.getDisplayComponent());
                    assignListenerToLabel(backButton, hc.getListeners()[0]);
                    assignListenerToLabel(nextButton, hc.getListeners()[1]);
                  }
                });
          }
        };

    assignListenerToLabel(backButton, listeners[0]);

    listeners[1] =
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            nextButton.setIcon(nextOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            nextButton.setIcon(next);
          }

          public void mousePressed(MouseEvent mouseEvent) {

            nextButton.setIcon(next);
            Thread performMappingLogic =
                new Thread(
                    new Runnable() {
                      public void run() {
                        investigation =
                            MappingLogic.createInvestigation(
                                definitions, assaySelections, dataEntryEnvironment);
                        // now we need to construct the investigation from the defined table
                        // reference objects and the
                        ApplicationManager.assignDataEntryToISASection(
                            investigation,
                            new InvestigationDataEntry(investigation, dataEntryEnvironment));

                        investigation.setConfigurationCreateWith(
                            ApplicationManager.getCurrentApplicationInstance()
                                .getLoadedConfiguration());
                        investigation.setLastConfigurationUsed(
                            ApplicationManager.getCurrentApplicationInstance()
                                .getLoadedConfiguration());

                        dataEntryEnvironment.createGUIFromInvestigation(investigation);

                        previousPage.push(new HistoryComponent(finalPanel, listeners));
                        ApplicationManager.getCurrentApplicationInstance().hideGlassPane();
                        ApplicationManager.getCurrentApplicationInstance()
                            .setCurDataEntryPanel(dataEntryEnvironment);
                        ApplicationManager.getCurrentApplicationInstance()
                            .setCurrentPage(dataEntryEnvironment);
                      }
                    });

            setCurrentPage(workingProgressScreen);
            performMappingLogic.start();
          }
        };

    JPanel saveMappingsSection = new JPanel();
    saveMappingsSection.setLayout(new BoxLayout(saveMappingsSection, BoxLayout.LINE_AXIS));

    saveMappingsSection.add(savedMappingsFile);
    saveMappingsSection.add(Box.createHorizontalStrut(10));

    JPanel saveButtonContainer = new JPanel(new BorderLayout());
    saveButtonContainer.add(saveMappingsButton, BorderLayout.SOUTH);

    saveMappingsSection.add(UIHelper.wrapComponentInPanel(saveButtonContainer));

    savedMappingsPanel.add(saveMappingsSection);
    selectMappingPanel.add(savedMappingsPanel);

    saveMappingFilesCont.add(selectMappingPanel);
    saveMappingFilesCont.add(UIHelper.wrapComponentInPanel(saveStatusInfo));

    assignListenerToLabel(nextButton, listeners[1]);
    return finalPanel;
  }
  /**
   * Create JPanel asking users to select the file or directory containing files to be mapped and an
   * existing mapping file if they have one.
   *
   * @return JPanel containing elements!
   */
  private JLayeredPane createSelectFilesPanel() {
    // create overall panel

    final JPanel selectFilesContainer = new JPanel();
    selectFilesContainer.setSize(new Dimension(400, 100));
    selectFilesContainer.setLayout(new BoxLayout(selectFilesContainer, BoxLayout.PAGE_AXIS));

    // create selector for mapping files
    final FileSelectionPanel fileToMapFSP =
        new FileSelectionPanel(
            "<html>please select file(s) to be mapped (txt, csv or xls (Excel). Please ensure "
                + "that this file has <b>no empty columns</b> and if possible, please remove any special characters, e.g. &mu;</html>",
            fileChooser);
    selectFilesContainer.add(fileToMapFSP);

    JPanel selectMappingPanel = new JPanel();
    selectMappingPanel.setLayout(new BoxLayout(selectMappingPanel, BoxLayout.PAGE_AXIS));
    selectMappingPanel.setOpaque(false);

    // need a jcheckbox to ask users if they wish to use a mapping
    JPanel useMappingContainer = new JPanel(new BorderLayout());
    useMappingContainer.setOpaque(false);

    // need a file selection panel to select the file.
    JFileChooser mappingFileChooser = new JFileChooser();
    mappingFileChooser.setDialogTitle("Choose mapping file (XML)");
    mappingFileChooser.setApproveButtonText("select file");
    mappingFileChooser.setFont(UIHelper.VER_11_PLAIN);
    mappingFileChooser.setFileFilter(new CustomizableFileFilter("xml"));

    final FileSelectionPanel savedMappingsFile =
        new FileSelectionPanel(
            "<html>please select saved mapping file (xml): </html>", mappingFileChooser);
    savedMappingsFile.setVisible(false);

    final JCheckBox useMapping = new JCheckBox("use a previous mapping?");
    UIHelper.renderComponent(useMapping, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false);
    useMapping.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            savedMappingsFile.setVisible(useMapping.isSelected());
          }
        });

    useMappingContainer.add(useMapping, BorderLayout.WEST);

    selectMappingPanel.add(useMappingContainer);

    selectMappingPanel.add(savedMappingsFile);

    selectFilesContainer.add(selectMappingPanel);

    final RoundedJTextField rowOffset = new RoundedJTextField(3);
    rowOffset.setEnabled(false);
    rowOffset.setSize(new Dimension(20, 20));
    rowOffset.setText("1");

    final JCheckBox overrideRowPosition = new JCheckBox("override row start position?");
    UIHelper.renderComponent(overrideRowPosition, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false);
    overrideRowPosition.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            rowOffset.setEnabled(overrideRowPosition.isSelected());
          }
        });

    Box fileInputPanel = Box.createHorizontalBox();
    fileInputPanel.setSize(new Dimension(100, 20));
    fileInputPanel.add(overrideRowPosition);
    fileInputPanel.add(Box.createHorizontalStrut(5));
    fileInputPanel.add(rowOffset);

    selectFilesContainer.add(fileInputPanel);

    selectFilesContainer.add(selectMappingPanel);

    final JCheckBox mapToBlankFieldsCheckbox = new JCheckBox("Do not remove blank fields?", false);
    UIHelper.renderComponent(
        mapToBlankFieldsCheckbox, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false);
    mapToBlankFieldsCheckbox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            mapToBlankFields = mapToBlankFieldsCheckbox.isSelected();
          }
        });

    JPanel removeBlanksContainer = new JPanel(new BorderLayout());
    removeBlanksContainer.setOpaque(false);

    removeBlanksContainer.add(mapToBlankFieldsCheckbox, BorderLayout.WEST);

    selectFilesContainer.add(removeBlanksContainer);

    JPanel statusPanel = new JPanel(new GridLayout(1, 1));
    statusPanel.setPreferredSize(new Dimension(400, 30));
    final JLabel statusLab = UIHelper.createLabel("", UIHelper.VER_11_BOLD, UIHelper.RED_COLOR);
    statusPanel.add(statusLab);

    selectFilesContainer.add(statusPanel);

    final JLayeredPane finalLayout =
        getGeneralLayout(selectFilesHeader, breadcrumb1, "", selectFilesContainer, getHeight());

    final MouseListener[] listeners = new MouseListener[2];

    listeners[0] =
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            backButton.setIcon(backOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            backButton.setIcon(back);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            backButton.setIcon(back);
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    ApplicationManager.getCurrentApplicationInstance().setCurrentPage(menuPanels);
                    ApplicationManager.getCurrentApplicationInstance()
                        .setGlassPanelContents(menuPanels.getCreateISAMenuGUI());
                    menuPanels.startAnimation();
                  }
                });
          }
        };

    assignListenerToLabel(backButton, listeners[0]);

    listeners[1] =
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            nextButton.setIcon(nextOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            nextButton.setIcon(next);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            nextButton.setIcon(next);

            Thread loadFile =
                new Thread(
                    new Runnable() {
                      public void run() {
                        ISAcreatorProperties.setProperty(
                            "isacreator.rowOffset",
                            rowOffset.isEnabled() ? rowOffset.getText() : "1");

                        if (useMapping.isSelected()) {

                          if (!savedMappingsFile.getSelectedFilePath().trim().equals("")) {

                            MappingXMLLoader loader =
                                new MappingXMLLoader(savedMappingsFile.getSelectedFilePath());
                            try {
                              preExistingMapping = loader.loadMappings();
                            } catch (XmlException e) {
                              log.error(e.getMessage());
                              statusLab.setText(
                                  "<html>problem found in xml for saved mapping: "
                                      + e.getMessage()
                                      + " </html>");
                              setCurrentPage(lastPage);
                              return;
                            } catch (IOException e) {
                              log.error(e.getMessage());
                              statusLab.setText(
                                  "<html>problem found when resolving file for saved mapping: "
                                      + e.getMessage()
                                      + " </html>");
                              setCurrentPage(lastPage);
                              return;
                            }
                          } else {
                            statusLab.setText(
                                "<html>please select a file containing previous mappings...</html>");
                            setCurrentPage(lastPage);
                            return;
                          }
                        } else {
                          log.info("Mapping is not selected");
                          statusLab.setText("");
                        }

                        if (fileToMapFSP.notEmpty()) {
                          previousPage.push(new HistoryComponent(finalLayout, listeners));
                          statusLab.setText("");
                          SwingUtilities.invokeLater(
                              new Runnable() {
                                public void run() {
                                  setCurrentPage(
                                      createAssayUsedPanel(fileToMapFSP.getSelectedFilePath()));
                                }
                              });
                        } else {
                          statusLab.setText(
                              "<html>please <strong>select</strong> a file to map!</html>");
                          setCurrentPage(lastPage);
                        }
                      }
                    });

            if (fileToMapFSP.notEmpty()
                && fileToMapFSP.checkFileExtensionValid("xls", "csv", "txt")) {
              statusLab.setText("");
              lastPage = currentPage;
              setCurrentPage(workingProgressScreen);
              loadFile.start();
            } else {
              statusLab.setText(
                  "<html>please select a file with the extension <strong>.xls</strong>, <strong>.csv</strong> or <strong>.txt</strong>...</html>");
            }
          }
        };
    assignListenerToLabel(nextButton, listeners[1]);
    return finalLayout;
  }
 private void createFileChooser() {
   fileChooser = new JFileChooser("Choose file or directory to load...");
   fileChooser.setDialogTitle("Choose file or directory to load...");
   fileChooser.setApproveButtonText("Select for mapping");
   setStartingDirectory();
 }