All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.fedora.client.objecteditor.ImportDialog Maven / Gradle / Ivy

Go to download

The Fedora Client is a Java Library that allows API access to a Fedora Repository. The client is typically one part of a full Fedora installation.

The newest version!
/*
 * -----------------------------------------------------------------------------
 *
 * 

License and Copyright: The contents of this file are subject to the * Apache License, Version 2.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of * the License at * http://www.fedora-commons.org/licenses.

* *

Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License.

* *

The entire file consists of original code.

*

Copyright © 2008 Fedora Commons, Inc.
*

Copyright © 2002-2007 The Rector and Visitors of the University of * Virginia and Cornell University
* All rights reserved.

* * ----------------------------------------------------------------------------- */ package fedora.client.objecteditor; import java.awt.BorderLayout; import java.awt.Container; import java.awt.FlowLayout; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import javax.swing.AbstractAction; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.JRadioButton; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import fedora.client.Administrator; /** * Launch a dialog for getting a local file or a URL in order to import * content. If a URL is chosen, download the content ensure that the public * file member points to it. The URL must be resolvable and return a response * code of 200 in order for this to work. In the case where the file's content * comes from a URL, it will request deleteOnExit(). * * When this dialog closes, if file is null, it was canceled. * If it was not canceled, file will point to the content. * If url is not null, it means the import occurred from a url and that * is the source. * * @author [email protected] * @version $Id: ImportDialog.java 5162 2006-10-25 00:49:06Z eddie $ */ public class ImportDialog extends JDialog { private static final long serialVersionUID = 1L; public File file=null; public String url=null; private JTextField m_fileField; private JTextField m_urlField; private JRadioButton m_fileButton; private JRadioButton m_urlButton; private ImportDialog m_importDialog; public ImportDialog() { super(JOptionPane.getFrameForComponent(Administrator.getDesktop()), "Import Content", true); m_importDialog=this; 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); } public void addRows(JComponent[] left, JComponent[] right, GridBagLayout gridBag, Container container) { GridBagConstraints c=new GridBagConstraints(); c.insets=new Insets(0, 4, 4, 4); for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy