public void actionPerformed(ActionEvent evt) { try { if (m_fileButton.isSelected()) { if (m_fileField.getText().equals("")) { throw new IOException("No filename entered."); } File f = new File(m_fileField.getText()); if (!f.exists()) { throw new IOException("File does not exist."); } file = f; } else { if (m_urlField.getText().equals("")) { throw new IOException("No URL entered."); } File f = File.createTempFile("fedora-ingest-", null); f.deleteOnExit(); try { Administrator.DOWNLOADER.get(m_urlField.getText(), new FileOutputStream(f)); } catch (Exception e) { throw new IOException("Download failed: " + m_urlField.getText()); } url = m_urlField.getText(); file = f; } dispose(); } catch (Exception e) { Administrator.showErrorDialog( Administrator.getDesktop(), "Import Error", e.getMessage(), e); } }
public ImportDialog() { super(JOptionPane.getFrameForComponent(Administrator.getDesktop()), "Import Content", true); ImportAction importAction = new ImportAction(); JButton importButton = new JButton(importAction); Administrator.constrainHeight(importButton); m_fileButton = new JRadioButton("From file"); m_urlButton = new JRadioButton("From URL"); ButtonGroup group = new ButtonGroup(); group.add(m_fileButton); group.add(m_urlButton); m_fileButton.setSelected(true); m_fileField = new JTextField(20); JButton browseButton = new JButton("Browse..."); Administrator.constrainHeight(browseButton); browseButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { JFileChooser browse; if (Administrator.getLastDir() == null) { browse = new JFileChooser(); } else { browse = new JFileChooser(Administrator.getLastDir()); } browse.setApproveButtonText("Import"); browse.setApproveButtonMnemonic('I'); browse.setApproveButtonToolTipText("Imports the selected file."); browse.setDialogTitle("Import New Datastream Content..."); int returnVal = browse.showOpenDialog(Administrator.getDesktop()); if (returnVal == JFileChooser.APPROVE_OPTION) { m_fileField.setText(browse.getSelectedFile().getPath()); } } }); JPanel fileValuePanel = new JPanel(); fileValuePanel.setLayout(new FlowLayout()); fileValuePanel.add(m_fileField); fileValuePanel.add(browseButton); m_urlField = new JTextField(20); JPanel inputPane = new JPanel(); inputPane.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createEtchedBorder()), BorderFactory.createEmptyBorder(4, 4, 4, 4))); GridBagLayout gridBag = new GridBagLayout(); inputPane.setLayout(gridBag); addRows( new JComponent[] {m_fileButton, m_urlButton}, new JComponent[] {fileValuePanel, m_urlField}, gridBag, inputPane); JButton cancelButton = new JButton( new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent evt) { dispose(); } }); cancelButton.setText("Cancel"); Administrator.constrainHeight(cancelButton); JPanel buttonPane = new JPanel(); buttonPane.add(importButton); buttonPane.add(cancelButton); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(inputPane, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.SOUTH); pack(); setLocation(Administrator.INSTANCE.getCenteredPos(getWidth(), getHeight())); setVisible(true); }