-
Notifications
You must be signed in to change notification settings - Fork 2
/
ReplaceFile.jy
68 lines (52 loc) · 2.24 KB
/
ReplaceFile.jy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# label: Replace File...
# title: Replace filename references within the DOM, and reset xrange
from java.awt import BorderLayout
from javax.swing import JOptionPane, JPanel, JTextField, ImageIcon, JLabel, JButton, JFileChooser
if ( len( dom.controller.dataSourceFilter.uri )==0 ):
JOptionPane.showMessageDialog( None, "Nothing plotted" )
split= None
oldf= '' # it would be nice if I could just break out of here..
else:
from org.virbo.datasource import URISplit
split= URISplit.parse( dom.controller.dataSourceFilter.uri )
oldf= split.file
# define the file component
panel= JPanel( BorderLayout() )
text= JTextField(50)
panel.add( text )
panel.add( JLabel( "<html>Current file is<br>"+oldf+"<br><br>Enter New Filename: " ), BorderLayout.NORTH )
def pickFile(event):
chooser= JFileChooser()
current= java.io.File(text.getText())
print current.getParentFile()
chooser.setCurrentDirectory( current.getParentFile() )
chooser.setSelectedFile( current )
ret= chooser.showOpenDialog(event.source)
if ( ret==JFileChooser.APPROVE_OPTION ):
text.setText( chooser.getSelectedFile().toString() )
pick= JButton( "pick", actionPerformed=pickFile )
panel.add( pick, BorderLayout.EAST );
# end, define the file component
if ( split!=None ):
if ( oldf[0:5]=='file:' ): oldf= URL(oldf).getFile()
text.setText( oldf )
i= JOptionPane.showConfirmDialog( None, panel, "Change Files", JOptionPane.OK_CANCEL_OPTION )
if ( i==JOptionPane.OK_OPTION ):
newf= text.getText()
if ( newf!=None ):
dom.options.setAutoranging(False)
for i in dom.dataSourceFilters:
oldf1= i.uri
newf1= oldf1.replace( oldf, newf )
i.uri= newf1
dom.controller.waitUntilIdle()
dom.options.setAutoranging(True)
ds= dom.dataSourceFilters[0].controller.dataSet
from org.virbo.dataset import SemanticOps
from org.das2.datum import DatumRangeUtil
ext= SemanticOps.bounds(ds)
xbounds= ext.slice(0)
xunits= SemanticOps.getUnits( xbounds )
xdr= DatumRange( xbounds.value(0), xbounds.value(1), xunits )
if ( not xdr.intersects( dom.plots[0].xaxis.range ) ):
dom.plots[0].xaxis.range= xdr