1 package fr.orsay.lri.varna.views;
3 import java.awt.CardLayout;
4 import java.awt.Dimension;
5 import java.awt.GridLayout;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.io.FileNotFoundException;
9 import java.io.FileReader;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.io.InputStreamReader;
13 import java.io.Reader;
14 import java.net.MalformedURLException;
16 import java.net.URLConnection;
18 import javax.swing.ButtonGroup;
19 import javax.swing.JButton;
20 import javax.swing.JCheckBox;
21 import javax.swing.JFileChooser;
22 import javax.swing.JLabel;
23 import javax.swing.JPanel;
24 import javax.swing.JRadioButton;
25 import javax.swing.JTextField;
27 import fr.orsay.lri.varna.VARNAPanel;
29 public class VueLoadColorMapValues extends JPanel implements ActionListener {
33 private static final long serialVersionUID = -1648400107478203724L;
36 public VueLoadColorMapValues(VARNAPanel vp)
41 JRadioButton urlCB = new JRadioButton("URL");
42 JRadioButton fileCB = new JRadioButton("File");
43 JPanel urlAux = new JPanel();
44 JPanel fileAux = new JPanel();
45 CardLayout l = new CardLayout();
46 JPanel input = new JPanel();
47 JTextField urlTxt = new JTextField();
48 JTextField fileTxt = new JTextField();
49 JButton load = new JButton("Choose file");
53 setLayout(new GridLayout(2,1));
54 JPanel choice = new JPanel();
55 urlCB.addActionListener(this);
56 fileCB.addActionListener(this);
57 ButtonGroup group = new ButtonGroup();
60 choice.add(new JLabel("Choose input source:"));
64 urlTxt.setPreferredSize(new Dimension(300,30));
65 fileTxt.setPreferredSize(new Dimension(300,30));
69 input.add(fileAux,"file");
70 input.add(urlAux,"url");
71 group.setSelected(fileCB.getModel(), true);
72 load.addActionListener(this);
77 public void actionPerformed(ActionEvent e) {
78 if (e.getSource() instanceof JRadioButton)
80 if (urlCB.isSelected())
86 l.show(input, "file");
89 else if (e.getSource() instanceof JButton)
91 JFileChooser fc = new JFileChooser();
92 if (fc.showOpenDialog(_vp) == JFileChooser.APPROVE_OPTION)
94 this.fileTxt.setText(fc.getSelectedFile().getAbsolutePath());
99 public Reader getReader() throws IOException
101 if (urlCB.isSelected())
103 URL url = new URL(urlTxt.getText());
104 URLConnection connexion = url.openConnection();
105 connexion.setUseCaches(false);
106 InputStream r = connexion.getInputStream();
107 return new InputStreamReader(r);
111 return new FileReader(fileTxt.getText());