2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: ArrayViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.6 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 20:59:41 $ |
2 |
26 Feb 07 |
jari |
* $Author: caliente $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Cursor; |
2 |
26 Feb 07 |
jari |
15 |
import java.io.File; |
2 |
26 Feb 07 |
jari |
16 |
|
2 |
26 Feb 07 |
jari |
17 |
import javax.swing.JFileChooser; |
2 |
26 Feb 07 |
jari |
18 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
19 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.filechooser.FileFilter; |
2 |
26 Feb 07 |
jari |
22 |
|
2 |
26 Feb 07 |
jari |
23 |
import org.tigr.microarray.util.swing.SlideDataLoader; |
2 |
26 Feb 07 |
jari |
24 |
import org.tigr.microarray.util.swing.TAVFileFilter; |
2 |
26 Feb 07 |
jari |
25 |
import org.tigr.util.swing.FileTransferDialog; |
2 |
26 Feb 07 |
jari |
26 |
import org.tigr.util.swing.TXTFileFilter; |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
abstract public class ArrayViewer extends JPanel { |
2 |
26 Feb 07 |
jari |
29 |
|
2 |
26 Feb 07 |
jari |
30 |
protected JFrame mainframe; |
2 |
26 Feb 07 |
jari |
31 |
protected boolean firstLoad = true; |
2 |
26 Feb 07 |
jari |
32 |
protected String currentDataPath; |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
public ArrayViewer(JFrame mainframe) { |
2 |
26 Feb 07 |
jari |
35 |
this.mainframe = mainframe; |
2 |
26 Feb 07 |
jari |
36 |
} |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
public JFrame getFrame() { |
2 |
26 Feb 07 |
jari |
39 |
return mainframe; |
2 |
26 Feb 07 |
jari |
40 |
} |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
public void setCursor(int cursor) { |
2 |
26 Feb 07 |
jari |
43 |
setCursor(Cursor.getPredefinedCursor(cursor)); |
2 |
26 Feb 07 |
jari |
44 |
} |
2 |
26 Feb 07 |
jari |
45 |
|
2 |
26 Feb 07 |
jari |
46 |
private File selectFile() { |
2 |
26 Feb 07 |
jari |
47 |
return selectFile("Select a datafile to open", true); |
2 |
26 Feb 07 |
jari |
48 |
} |
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
50 |
|
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
private File selectFile(String title, boolean multiSelectionEnabled) { |
2 |
26 Feb 07 |
jari |
53 |
JFileChooser chooser; |
2 |
26 Feb 07 |
jari |
54 |
if(firstLoad) |
2 |
26 Feb 07 |
jari |
55 |
chooser = new JFileChooser(TMEV.getFile("data/")); |
2 |
26 Feb 07 |
jari |
56 |
else |
2 |
26 Feb 07 |
jari |
57 |
chooser = new JFileChooser(currentDataPath); |
2 |
26 Feb 07 |
jari |
58 |
|
2 |
26 Feb 07 |
jari |
59 |
chooser.setDialogTitle(title); |
2 |
26 Feb 07 |
jari |
60 |
|
2 |
26 Feb 07 |
jari |
61 |
chooser.addChoosableFileFilter(new TXTFileFilter()); |
2 |
26 Feb 07 |
jari |
62 |
chooser.addChoosableFileFilter(new TAVFileFilter()); |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
if (! multiSelectionEnabled) { // Using Stanford file |
2 |
26 Feb 07 |
jari |
65 |
chooser.setFileFilter(chooser.getAcceptAllFileFilter()); |
2 |
26 Feb 07 |
jari |
66 |
} |
2 |
26 Feb 07 |
jari |
67 |
chooser.setMultiSelectionEnabled(multiSelectionEnabled); |
2 |
26 Feb 07 |
jari |
68 |
if(firstLoad) |
2 |
26 Feb 07 |
jari |
69 |
chooser.setCurrentDirectory(new File("Data")); |
2 |
26 Feb 07 |
jari |
70 |
if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { |
2 |
26 Feb 07 |
jari |
71 |
File file = chooser.getSelectedFile(); |
2 |
26 Feb 07 |
jari |
72 |
firstLoad = false; |
2 |
26 Feb 07 |
jari |
73 |
currentDataPath = file.getParent(); |
2 |
26 Feb 07 |
jari |
74 |
if(currentDataPath == null) |
2 |
26 Feb 07 |
jari |
75 |
currentDataPath = file.getPath(); |
2 |
26 Feb 07 |
jari |
76 |
return file; |
2 |
26 Feb 07 |
jari |
77 |
} |
2 |
26 Feb 07 |
jari |
78 |
return null; |
2 |
26 Feb 07 |
jari |
79 |
} |
2 |
26 Feb 07 |
jari |
80 |
|
2 |
26 Feb 07 |
jari |
81 |
public ISlideData loadSlideData(ISlideMetaData slideMetaData) throws Exception { |
2 |
26 Feb 07 |
jari |
82 |
File file = selectFile(); |
2 |
26 Feb 07 |
jari |
83 |
if (file == null) { |
2 |
26 Feb 07 |
jari |
84 |
return null; |
2 |
26 Feb 07 |
jari |
85 |
} |
2 |
26 Feb 07 |
jari |
86 |
SlideDataLoader loader; |
2 |
26 Feb 07 |
jari |
87 |
if(this instanceof MultipleArrayViewer) |
2 |
26 Feb 07 |
jari |
88 |
loader = new SlideDataLoader(getFrame(), slideMetaData, file, false); |
2 |
26 Feb 07 |
jari |
89 |
else |
2 |
26 Feb 07 |
jari |
90 |
loader = new SlideDataLoader(getFrame(), slideMetaData, file, true); |
2 |
26 Feb 07 |
jari |
91 |
if (loader.showModal() != JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
92 |
return null; |
2 |
26 Feb 07 |
jari |
93 |
} |
2 |
26 Feb 07 |
jari |
94 |
return loader.getData(0); |
2 |
26 Feb 07 |
jari |
95 |
} |
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
97 |
public ISlideData[] loadDirectory(ISlideMetaData slideMetaData) throws Exception { |
2 |
26 Feb 07 |
jari |
98 |
String directory; |
2 |
26 Feb 07 |
jari |
99 |
if(firstLoad){ |
2 |
26 Feb 07 |
jari |
100 |
directory = TMEV.getFile("data/").getPath(); |
2 |
26 Feb 07 |
jari |
101 |
} else { |
2 |
26 Feb 07 |
jari |
102 |
directory = currentDataPath; |
2 |
26 Feb 07 |
jari |
103 |
} |
2 |
26 Feb 07 |
jari |
104 |
return loadSlideDataDirectory(directory, new FileFilter[] {new TAVFileFilter()}, slideMetaData); |
2 |
26 Feb 07 |
jari |
105 |
} |
2 |
26 Feb 07 |
jari |
106 |
|
2 |
26 Feb 07 |
jari |
107 |
private ISlideData[] loadSlideDataDirectory(String directory, FileFilter[] fileFilters, ISlideMetaData slideMetaData) throws Exception { |
2 |
26 Feb 07 |
jari |
108 |
FileTransferDialog dialog = new FileTransferDialog(getFrame(), directory, fileFilters); |
2 |
26 Feb 07 |
jari |
109 |
if (dialog.showModal() != JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
110 |
return null; |
2 |
26 Feb 07 |
jari |
111 |
} |
2 |
26 Feb 07 |
jari |
112 |
File[] files = dialog.getFiles(); |
2 |
26 Feb 07 |
jari |
113 |
if (files.length < 1) { |
2 |
26 Feb 07 |
jari |
114 |
return null; |
2 |
26 Feb 07 |
jari |
115 |
} |
2 |
26 Feb 07 |
jari |
116 |
if(firstLoad) |
2 |
26 Feb 07 |
jari |
117 |
firstLoad = false; |
2 |
26 Feb 07 |
jari |
118 |
currentDataPath = files[0].getParent(); |
2 |
26 Feb 07 |
jari |
119 |
if(currentDataPath == null) |
2 |
26 Feb 07 |
jari |
120 |
currentDataPath = files[0].getPath(); |
2 |
26 Feb 07 |
jari |
121 |
|
2 |
26 Feb 07 |
jari |
122 |
SlideDataLoader loader; |
2 |
26 Feb 07 |
jari |
123 |
|
2 |
26 Feb 07 |
jari |
124 |
if(this instanceof MultipleArrayViewer) |
2 |
26 Feb 07 |
jari |
125 |
loader = new SlideDataLoader(getFrame(), slideMetaData, files, false); |
2 |
26 Feb 07 |
jari |
126 |
else |
2 |
26 Feb 07 |
jari |
127 |
loader = new SlideDataLoader(getFrame(), slideMetaData, files, true); |
2 |
26 Feb 07 |
jari |
128 |
|
2 |
26 Feb 07 |
jari |
129 |
if (loader.showModal() != JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
130 |
return null; |
2 |
26 Feb 07 |
jari |
131 |
} |
2 |
26 Feb 07 |
jari |
132 |
return loader.getData(); |
2 |
26 Feb 07 |
jari |
133 |
} |
2 |
26 Feb 07 |
jari |
134 |
|
2 |
26 Feb 07 |
jari |
135 |
public ISlideData[] loadStanfordFile(String title) throws Exception { |
2 |
26 Feb 07 |
jari |
136 |
File file = selectFile(title, false); |
2 |
26 Feb 07 |
jari |
137 |
if (file == null) { |
2 |
26 Feb 07 |
jari |
138 |
return null; |
2 |
26 Feb 07 |
jari |
139 |
} |
2 |
26 Feb 07 |
jari |
140 |
|
2 |
26 Feb 07 |
jari |
141 |
SlideDataLoader loader = new SlideDataLoader(getFrame(), null, file, false); |
2 |
26 Feb 07 |
jari |
142 |
if (loader.showModal(true) != JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
143 |
return null; |
2 |
26 Feb 07 |
jari |
144 |
} |
2 |
26 Feb 07 |
jari |
145 |
return loader.getData(); |
2 |
26 Feb 07 |
jari |
146 |
} |
2 |
26 Feb 07 |
jari |
147 |
|
2 |
26 Feb 07 |
jari |
148 |
abstract public void systemDisable(int state); |
2 |
26 Feb 07 |
jari |
149 |
|
2 |
26 Feb 07 |
jari |
150 |
abstract public void systemEnable(int state); |
2 |
26 Feb 07 |
jari |
151 |
|
2 |
26 Feb 07 |
jari |
152 |
} |