00001 package GuiComponents.SctConf;
00002
00003 import sctConf.*;
00004
00005 import javax.swing.*;
00006 import java.awt.*;
00007 import java.awt.event.*;
00008
00009 import Sct.gui.SelectionDialog;
00010
00011 import org.omg.CORBA.IntHolder;
00012
00013 public class ModuleView extends JPanel {
00014 sctConf.Configuration config;
00015 Proxies.ModuleProxy module;
00016
00017 public ModuleView(sctConf.Configuration conf, Proxies.ModuleProxy mod) {
00018 module = mod;
00019 config = conf;
00020
00021 buildGUI();
00022 }
00023
00024 void buildGUI() {
00025 removeAll();
00026
00027 setLayout(new BorderLayout());
00028
00029 JPanel buttons = new JPanel();
00030
00031 JButton close = new JButton("Close");
00032 close.addActionListener(new ActionListener() {
00033 public void actionPerformed(ActionEvent e) {
00034 ((Window)getTopLevelAncestor()).dispose();
00035 }
00036 });
00037 buttons.add(close);
00038
00039 add(buttons, BorderLayout.SOUTH);
00040
00041 Box centre = Box.createVerticalBox();
00042
00043 centre.add(new JLabel(module.toString()));
00044 centre.add(getMURPanel());
00045 centre.add(getRODPanel());
00046 centre.add(new JLabel(module.getRRODString()));
00047 centre.add(getPhysicalPanel());
00048 centre.add(getPowerPanel());
00049
00050 add(centre, BorderLayout.CENTER);
00051 }
00052
00053 JPanel getMURPanel() {
00054 JPanel panel = new JPanel();
00055 panel.add(new JLabel(module.getMURString()));
00056
00057 JButton button = new JButton("Edit MUR Mapping");
00058 button.addActionListener(new ActionListener() {
00059 public void actionPerformed(ActionEvent e) {
00060 String [] labels = {"MUR id", "Position (1-6)", "Redundant MUR id", "Position on redundant MUR (1-6)"};
00061 String [] defaults = {"0", "1", "0", "1"};
00062
00063 try {
00064 IntHolder MUR = new IntHolder(), num = new IntHolder();
00065 config.translateFromSN(module.getSN(), MUR, num);
00066
00067 defaults[0] = "" + MUR.value;
00068 defaults[1] = "" + num.value;
00069
00070 IntHolder RMUR = new IntHolder(), rnum = new IntHolder();
00071 config.translateToRMUR(MUR.value, num.value, RMUR, rnum);
00072
00073 defaults[2] = "" + RMUR.value;
00074 defaults[3] = "" + rnum.value;
00075 } catch(ConfigurationException c) {
00076
00077 }
00078
00079 SelectionDialog dia = new SelectionDialog(null, "Edit Power mapping", labels, defaults);
00080
00081 dia.pack();
00082 dia.setVisible(true);
00083
00084 try {
00085 for(int i=0; i<4; i++) {
00086 System.out.println(labels[i] + ": " + dia.getIntFieldValue(i));
00087 }
00088
00089 try {
00090 config.mapModuleMUR(dia.getIntFieldValue(0), dia.getIntFieldValue(1),
00091 dia.getIntFieldValue(2), dia.getIntFieldValue(3),
00092 module.getSN());
00093 } catch(ConfigurationException cex) {
00094 JOptionPane.showMessageDialog(null, "Failed to remap module to MUR: " + cex.detail);
00095 return;
00096 }
00097
00098 buildGUI();
00099 validate();
00100 } catch(SelectionDialog.InvalidDialogException i) {
00101 JOptionPane.showMessageDialog(null, "Failed to interpret entry(ies)");
00102 } catch(SelectionDialog.CancelledDialogException i) {
00103
00104 }
00105 }
00106 });
00107 panel.add(button);
00108 return panel;
00109 }
00110
00111 JPanel getRODPanel() {
00112 JPanel panel = new JPanel();
00113 panel.add(new JLabel(module.getRODString()));
00114
00115 panel.add(new JLabel("Not editable at module level"));
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 return panel;
00133 }
00134
00135 JPanel getPowerPanel() {
00136 JPanel panel = new JPanel();
00137 panel.add(new JLabel(module.getPowerString()));
00138
00139 JButton button = new JButton("Edit Power Mapping");
00140 button.addActionListener(new ActionListener() {
00141 public void actionPerformed(ActionEvent e) {
00142 String [] labels = {"Partition", "Crate", "Channel (0-47)"};
00143 String [] defaults = {"0", "0", "0"};
00144
00145 try {
00146 IntHolder MUR = new IntHolder(), num = new IntHolder();
00147 config.translateFromSN(module.getSN(), MUR, num);
00148
00149 IntHolder partition = new IntHolder(), crate = new IntHolder(),
00150 channel = new IntHolder();
00151 config.translateToPowerSupply(MUR.value, num.value, partition, crate, channel);
00152 defaults[0] = "" + partition.value;
00153 defaults[1] = "" + crate.value;
00154 defaults[2] = "" + channel.value;
00155 } catch(ConfigurationException c) {
00156
00157 }
00158
00159 SelectionDialog dia = new SelectionDialog(null, "Edit Power mapping", labels, defaults);
00160
00161 dia.pack();
00162 dia.setVisible(true);
00163
00164 try {
00165 for(int i=0; i<3; i++) {
00166 System.out.println(labels[i] + ": " + dia.getIntFieldValue(i));
00167 }
00168
00169 IntHolder MUR = new IntHolder(), num = new IntHolder();
00170 try {
00171 config.translateFromSN(module.getSN(), MUR, num);
00172 } catch(ConfigurationException cex) {
00173 JOptionPane.showMessageDialog(null, "No mapping to MUR! (db inconsistent)");
00174 return;
00175 }
00176
00177 try {
00178 config.mapPowerChannel(MUR.value, num.value,
00179 dia.getIntFieldValue(0), dia.getIntFieldValue(1), dia.getIntFieldValue(2));
00180 } catch(ConfigurationException cex) {
00181 JOptionPane.showMessageDialog(null, "Failed to map Power Channel: " + cex.detail);
00182 return;
00183 }
00184
00185 buildGUI();
00186 validate();
00187 } catch(SelectionDialog.InvalidDialogException i) {
00188 JOptionPane.showMessageDialog(null, "Failed to interpret entry(ies)");
00189 } catch(SelectionDialog.CancelledDialogException i) {
00190
00191 }
00192 }
00193 });
00194 panel.add(button);
00195 return panel;
00196 }
00197
00198
00199 JPanel getPhysicalPanel() {
00200 JPanel panel = new JPanel();
00201 panel.add(new JLabel(module.getPhysicalString()));
00202
00203 panel.add(new JLabel("Not editable at module level"));
00204
00205 return panel;
00206 }
00207 }