示例#1
0
  public void setUpFile() {
    removeAll();

    boolean currentFileIsDir = false;
    File tmp = ((FileSourcedConverter) m_dsLoader.getLoader()).retrieveFile();
    String tmpString = tmp.toString();
    if (Environment.containsEnvVariables(tmpString)) {
      try {
        tmpString = m_env.substitute(tmpString);
      } catch (Exception ex) {
        // ignore
      }
    }
    File tmp2 = new File((new File(tmpString)).getAbsolutePath());

    if (tmp2.isDirectory()) {
      m_fileChooser.setCurrentDirectory(tmp2);
      currentFileIsDir = true;
    } else {
      m_fileChooser.setSelectedFile(tmp2);
    }

    FileSourcedConverter loader = (FileSourcedConverter) m_dsLoader.getLoader();
    String[] ext = loader.getFileExtensions();
    ExtensionFileFilter firstFilter = null;
    for (int i = 0; i < ext.length; i++) {
      ExtensionFileFilter ff =
          new ExtensionFileFilter(ext[i], loader.getFileDescription() + " (*" + ext[i] + ")");
      if (i == 0) firstFilter = ff;
      m_fileChooser.addChoosableFileFilter(ff);
    }
    if (firstFilter != null) m_fileChooser.setFileFilter(firstFilter);
    JPanel about = m_LoaderEditor.getAboutPanel();
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BorderLayout());
    if (about != null) {
      northPanel.add(about, BorderLayout.NORTH);
    }
    add(northPanel, BorderLayout.NORTH);

    final EnvironmentField ef = new EnvironmentField();
    JPanel efHolder = new JPanel();
    efHolder.setLayout(new BorderLayout());

    ef.setEnvironment(m_env);
    /*int width = ef.getPreferredSize().width;
        int height = ef.getPreferredSize().height;
    //    ef.setMinimumSize(new Dimension(width * 2, height));
        ef.setPreferredSize(new Dimension(width * 2, height)); */
    m_fileText = ef;

    // only set the text on the EnvironmentField if the current file is not a directory
    if (!currentFileIsDir) {
      ef.setText(tmp.toString());
    }

    efHolder.add(ef, BorderLayout.CENTER);
    JButton browseBut = new JButton("Browse...");
    browseBut.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              // final JFrame jf = new JFrame("Choose file");
              final JDialog jf =
                  new JDialog(
                      (JDialog) LoaderCustomizer.this.getTopLevelAncestor(), "Choose file", true);
              jf.setLayout(new BorderLayout());
              // jf.getContentPane().setLayout(new BorderLayout());
              jf.getContentPane().add(m_fileChooser, BorderLayout.CENTER);
              m_fileChooserFrame = jf;
              jf.pack();
              jf.setVisible(true);
            } catch (Exception ex) {
              ex.printStackTrace();
            }
          }
        });

    JPanel bP = new JPanel();
    bP.setLayout(new BorderLayout());
    bP.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 5));
    bP.add(browseBut, BorderLayout.CENTER);
    efHolder.add(bP, BorderLayout.EAST);
    JPanel alignedP = new JPanel();
    alignedP.setBorder(BorderFactory.createTitledBorder("File"));
    alignedP.setLayout(new BorderLayout());
    JLabel efLab = new JLabel("Filename", SwingConstants.RIGHT);
    efLab.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    alignedP.add(efLab, BorderLayout.WEST);
    alignedP.add(efHolder, BorderLayout.CENTER);

    northPanel.add(alignedP, BorderLayout.SOUTH);

    JPanel butHolder = new JPanel();
    // butHolder.setLayout(new GridLayout(1,2));
    butHolder.setLayout(new FlowLayout());
    JButton OKBut = new JButton("OK");
    OKBut.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              ((FileSourcedConverter) m_dsLoader.getLoader()).setFile(new File(ef.getText()));
              // tell the loader that a new file has been selected so
              // that it can attempt to load the header
              // m_dsLoader.setLoader(m_dsLoader.getLoader());
              m_dsLoader.newFileSelected();
            } catch (Exception ex) {
              ex.printStackTrace();
            }
            if (m_modifyListener != null) {
              m_modifyListener.setModifiedStatus(LoaderCustomizer.this, true);
            }
            m_parentWindow.dispose();
          }
        });

    JButton CancelBut = new JButton("Cancel");
    CancelBut.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (m_modifyListener != null) {
              m_modifyListener.setModifiedStatus(LoaderCustomizer.this, false);
            }

            if (m_backup != null) {
              m_dsLoader.setLoader(m_backup);
            }

            m_parentWindow.dispose();
          }
        });

    butHolder.add(OKBut);
    butHolder.add(CancelBut);

    JPanel optionsHolder = new JPanel();
    optionsHolder.setLayout(new BorderLayout());
    optionsHolder.setBorder(BorderFactory.createTitledBorder("Other options"));

    optionsHolder.add(m_LoaderEditor, BorderLayout.SOUTH);
    JScrollPane scroller = new JScrollPane(optionsHolder);

    add(scroller, BorderLayout.CENTER);

    add(butHolder, BorderLayout.SOUTH);
  }
示例#2
0
  public void setUpFile() {
    removeAll();

    boolean currentFileIsDir = false;
    File tmp = ((FileSourcedConverter) m_dsLoader.getLoader()).retrieveFile();
    String tmpString = tmp.toString();
    if (Environment.containsEnvVariables(tmpString)) {
      try {
        tmpString = m_env.substitute(tmpString);
      } catch (Exception ex) {
        // ignore
      }
    }
    File tmp2 = new File((new File(tmpString)).getAbsolutePath());

    if (tmp2.isDirectory()) {
      m_fileChooser.setCurrentDirectory(tmp2);
      currentFileIsDir = true;
    } else {
      m_fileChooser.setSelectedFile(tmp2);
    }

    FileSourcedConverter loader = (FileSourcedConverter) m_dsLoader.getLoader();
    String[] ext = loader.getFileExtensions();
    ExtensionFileFilter firstFilter = null;
    for (int i = 0; i < ext.length; i++) {
      ExtensionFileFilter ff =
          new ExtensionFileFilter(ext[i], loader.getFileDescription() + " (*" + ext[i] + ")");
      if (i == 0) firstFilter = ff;
      m_fileChooser.addChoosableFileFilter(ff);
    }
    if (firstFilter != null) m_fileChooser.setFileFilter(firstFilter);
    JPanel about = m_LoaderEditor.getAboutPanel();
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BorderLayout());
    if (about != null) {
      northPanel.add(about, BorderLayout.NORTH);
    }
    add(northPanel, BorderLayout.NORTH);
    final EnvironmentField ef = new EnvironmentField();
    JPanel efHolder = new JPanel();
    efHolder.setLayout(new BorderLayout());

    ef.setEnvironment(m_env);
    /*int width = ef.getPreferredSize().width;
        int height = ef.getPreferredSize().height;
    //    ef.setMinimumSize(new Dimension(width * 2, height));
        ef.setPreferredSize(new Dimension(width * 2, height)); */
    m_fileText = ef;

    // only set the text on the EnvironmentField if the current file is not a directory
    if (!currentFileIsDir) {
      ef.setText(tmp.toString());
    }

    efHolder.add(ef, BorderLayout.CENTER);
    JButton browseBut = new JButton("Browse...");
    browseBut.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              final JFrame jf = new JFrame("Choose file");
              jf.getContentPane().setLayout(new BorderLayout());
              jf.getContentPane().add(m_fileChooser, BorderLayout.CENTER);
              jf.pack();
              jf.setVisible(true);
              m_fileChooserFrame = jf;
            } catch (Exception ex) {
              ex.printStackTrace();
            }
          }
        });

    JPanel bP = new JPanel();
    bP.setLayout(new BorderLayout());
    bP.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 5));
    bP.add(browseBut, BorderLayout.CENTER);
    efHolder.add(bP, BorderLayout.EAST);
    JPanel alignedP = new JPanel();
    GridBagLayout gbLayout = new GridBagLayout();
    alignedP.setLayout(gbLayout);
    JLabel efLab = new JLabel("Filename", SwingConstants.RIGHT);
    efLab.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.anchor = GridBagConstraints.EAST;
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.gridy = 0;
    gbConstraints.gridx = 0;
    gbLayout.setConstraints(efLab, gbConstraints);
    alignedP.add(efLab);

    gbConstraints = new GridBagConstraints();
    gbConstraints.anchor = GridBagConstraints.EAST;
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.gridy = 0;
    gbConstraints.gridx = 1;
    gbConstraints.weightx = 5;
    gbLayout.setConstraints(efHolder, gbConstraints);
    alignedP.add(efHolder);

    northPanel.add(alignedP, BorderLayout.SOUTH);

    // add(m_fileChooser, BorderLayout.CENTER);

    // m_relativeFilePath = new JCheckBox("Use relative file paths");
    m_relativeFilePath = new JCheckBox();
    m_relativeFilePath.setSelected(
        ((FileSourcedConverter) m_dsLoader.getLoader()).getUseRelativePath());

    m_relativeFilePath.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ((FileSourcedConverter) m_dsLoader.getLoader())
                .setUseRelativePath(m_relativeFilePath.isSelected());
          }
        });

    JLabel relativeLab = new JLabel("Use relative file paths", SwingConstants.RIGHT);
    relativeLab.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    gbConstraints = new GridBagConstraints();
    gbConstraints.anchor = GridBagConstraints.EAST;
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.gridy = 1;
    gbConstraints.gridx = 0;
    gbLayout.setConstraints(relativeLab, gbConstraints);
    alignedP.add(relativeLab);

    gbConstraints = new GridBagConstraints();
    gbConstraints.anchor = GridBagConstraints.EAST;
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.gridy = 1;
    gbConstraints.gridx = 1;
    gbLayout.setConstraints(m_relativeFilePath, gbConstraints);
    alignedP.add(m_relativeFilePath);

    JPanel butHolder = new JPanel();
    // butHolder.setLayout(new GridLayout(1,2));
    butHolder.setLayout(new FlowLayout());
    JButton OKBut = new JButton("OK");
    OKBut.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              ((FileSourcedConverter) m_dsLoader.getLoader()).setFile(new File(ef.getText()));
              // tell the loader that a new file has been selected so
              // that it can attempt to load the header
              m_dsLoader.setLoader(m_dsLoader.getLoader());
              m_dsLoader.newFileSelected();
            } catch (Exception ex) {
              ex.printStackTrace();
            }

            m_parentFrame.dispose();
          }
        });

    JButton CancelBut = new JButton("Cancel");
    CancelBut.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            m_parentFrame.dispose();
          }
        });

    butHolder.add(OKBut);
    butHolder.add(CancelBut);

    add(butHolder, BorderLayout.SOUTH);
  }