1 package org.lcsim.plugin.conditions;
2
3 import hep.graphics.heprep.HepRep;
4 import hep.graphics.heprep.HepRepFactory;
5 import hep.graphics.heprep.HepRepReader;
6 import java.io.BufferedInputStream;
7 import java.io.FileInputStream;
8 import java.io.InputStream;
9 import java.util.zip.GZIPInputStream;
10 import javax.swing.event.ChangeEvent;
11 import javax.swing.event.ChangeListener;
12 import org.freehep.application.Application;
13 import org.freehep.jas.util.OpenLocalFilePanel;
14 import org.freehep.swing.ExtensionFileFilter;
15 import org.freehep.swing.wizard.Finishable;
16 import org.freehep.swing.wizard.WizardPage;
17 import org.lcsim.conditions.ConditionsReader;
18 import org.lcsim.util.loop.DummyConditionsConverter;
19
20
21
22
23
24
25 class HepRepSelectWizardPage extends WizardPage implements Finishable, ChangeListener
26 {
27 private ConditionsWizardPage wp;
28 private OpenLocalFilePanel olfp;
29
30 HepRepSelectWizardPage(ConditionsWizardPage wp)
31 {
32 this.wp = wp;
33 this.olfp = new OpenLocalFilePanel("heprep",new HepRepFileFilter(),false,true);
34 initComponents();
35 olfp.addChangeListener(this);
36 stateChanged(null);
37 }
38
39
40
41
42
43
44
45 private void initComponents()
46 {
47 java.awt.GridBagConstraints gridBagConstraints;
48
49 jPanel1 = olfp;
50 jLabel2 = new javax.swing.JLabel();
51 jTextField2 = new javax.swing.JTextField();
52
53 setLayout(new java.awt.GridBagLayout());
54
55 gridBagConstraints = new java.awt.GridBagConstraints();
56 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
57 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
58 add(jPanel1, gridBagConstraints);
59
60 jLabel2.setText("Field:");
61 gridBagConstraints = new java.awt.GridBagConstraints();
62 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
63 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
64 gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
65 add(jLabel2, gridBagConstraints);
66
67 jTextField2.setColumns(10);
68 jTextField2.setText("5");
69 gridBagConstraints = new java.awt.GridBagConstraints();
70 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
71 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
72 add(jTextField2, gridBagConstraints);
73
74 }
75
76 public void onFinish()
77 {
78 try
79 {
80 InputStream in = new FileInputStream(olfp.getFile());
81 try
82 {
83 double field = Double.parseDouble(jTextField2.getText());
84
85 if (olfp.getGZIPed()) in = new GZIPInputStream(in);
86 else in = new BufferedInputStream(in);
87 HepRepReader reader = HepRepFactory.create().createHepRepReader(in);
88 HepRep hepRep = reader.next();
89
90 String detectorName = wp.getDetectorName();
91 InteractiveConditionsManagerImplementation cm = wp.getConditionsManager();
92 ConditionsReader dummyReader = ConditionsReader.createDummy();
93 cm.setConditionsReader(dummyReader, detectorName);
94 HepRepOnlyDetector detector = new HepRepOnlyDetector(detectorName, hepRep, field);
95 cm.registerConditionsConverter(new DummyConditionsConverter(detector));
96 cm.setDetectorFound(true);
97
98 olfp.saveState();
99 dispose();
100 }
101 finally
102 {
103 in.close();
104 }
105
106
107 }
108 catch (Exception x)
109 {
110 Application.error(this,"Error handling heprep",x);
111 }
112 }
113
114 public void stateChanged(ChangeEvent e)
115 {
116 this.setFinishEnabled(olfp.isFileSelected());
117 }
118
119
120
121 private javax.swing.JLabel jLabel2;
122 private javax.swing.JPanel jPanel1;
123 private javax.swing.JTextField jTextField2;
124
125
126 private class HepRepFileFilter extends ExtensionFileFilter
127 {
128 HepRepFileFilter()
129 {
130 super(new String[]{".heprep", ".heprep.gz"}, "HepRep file");
131 }
132 }
133 }