001 package de.mospace.swing;
002
003 /* Mp3dings - manage mp3 meta-information
004 * Copyright (C) 2006 Moritz Ringler
005 * $Id: URIInput.java 12 2007-07-27 09:48:53Z ringler $
006 *
007 * This program is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU General Public License
009 * as published by the Free Software Foundation; either version 2
010 * of the License, or (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with this program; if not, write to the Free Software
019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020 */
021
022 import java.net.URI;
023 import java.net.URISyntaxException;
024 import java.io.File;
025 import java.util.prefs.Preferences;
026
027 /**
028 * @author Moritz Ringler
029 * @version $Revision: 12 $ ($Date: 2007-07-27 11:48:53 +0200 (Fr, 27 Jul 2007) $)
030 */
031 public class URIInput extends PathInput{
032
033 public URIInput(String url){
034 super(url);
035 }
036
037 public URIInput(String url, int fileSelectionMode){
038 super(url, fileSelectionMode);
039 }
040
041 public URI getURI() throws URISyntaxException{
042 String path = getTextfield().getText();
043 File testfile = new File(path);
044 URI result = testfile.isAbsolute()
045 ? testfile.toURI()
046 : new URI(path);
047 getTextfield().setText(result.toString());
048 return result;
049 }
050
051 public String getPath(){
052 String result = getTextfield().getText();
053 try{
054 result = (new File(new URI(result))).toString();
055 } catch (Exception ignore){
056 }
057 return result;
058 }
059
060 protected void browse(){
061 URI oldURI = null;
062 try{
063 oldURI = getURI();
064 } catch (URISyntaxException ignore){
065 }
066 super.browse();
067 try{
068 getURI();
069 } catch (URISyntaxException ex){
070 if(oldURI == null){
071 getTextfield().setText("./");
072 } else {
073 getTextfield().setText(oldURI.toString());
074 }
075 }
076 }
077 }