Commit c795c870 authored by Vincent van Beveren's avatar Vincent van Beveren

Started on clone tool. Added some icons.

Changed device module serial to module name
parent c0e74b50
......@@ -29,7 +29,7 @@ public interface SFPDevice extends Comparable<SFPDevice>
*
* @return the serial, or null if non is connected.
*/
public String getModuleSerial(int bay);
public String getModuleName(int bay);
/**
* Returns a I2CLink to the specified device.
......
......@@ -33,7 +33,7 @@ public abstract class SFPDeviceBase implements SFPDevice {
* @see nl.nikhef.sfp.SFPDevice#getModuleSerial(int)
*/
@Override
public String getModuleSerial(int bay) {
public String getModuleName(int bay) {
if (isModulePresent(bay))
{
......
......@@ -78,7 +78,7 @@ public class MultiSFPTest {
@Override
public void sfpModuleStateChanged(SFPDevice dev, int bay) {
if (dev.isModulePresent(bay)) {
System.out.printf("Module added to bay %d: %s\n", bay, dev.getModuleSerial(bay));
System.out.printf("Module added to bay %d: %s\n", bay, dev.getModuleName(bay));
if (bay == 1) {
try {
......
......@@ -89,7 +89,7 @@ public class ModuleManager implements BaySelectionListener
{
_ctx = _ctxCache.getContextFor(dev, bay);
_moduleName = dev.getModuleSerial(bay);
_moduleName = dev.getModuleName(bay);
_binExport.setEnabled(true);
} else {
_ctx = null;
......
......@@ -41,6 +41,7 @@ import org.codejargon.feather.Provides;
import nl.nikhef.safaripark.devmgr.BaySelectionListener;
import nl.nikhef.safaripark.devmgr.DeviceManager;
import nl.nikhef.safaripark.dolly.DollyModel;
import nl.nikhef.safaripark.dolly.DollyPanel;
import nl.nikhef.safaripark.editpane.EditPane;
import nl.nikhef.safaripark.extra.GuiUtils;
......@@ -83,7 +84,7 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
}
};
private Action _saveBinary = new ExtendedAbstractAction("Save module contents", Resources.getIcon("document-export-4"), "Save a binary export") {
private Action _saveBinary = new ExtendedAbstractAction("Save binary content", Resources.getIcon("document-export-4"), "Save a binary export") {
@Override
public void actionPerformed(ActionEvent e)
......@@ -109,7 +110,7 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
setTitle("SaFariPark " + getFullRevision());
setSize(640, 480);
setIconImage(loadImage("res/appicon.png"));
setIconImage(Resources.getImage("appicon"));
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
_sfpManager = sfpMgr;
......@@ -126,13 +127,15 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
_status = new StatusBar();
_modMgr = new ModuleManager(_saveBinary, _loader, _ctxCache);
_devMgr.addDeviceSelectedListener(_modMgr);
_dp = new DollyPanel(_loader);
_dp = new DollyPanel(_loader, new DollyModel());
makeToolbar();
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
split.setDividerLocation(300);
JSplitPane split3 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
split3.setTopComponent(_devMgr);
split3.setBottomComponent(_dp);
split3.setDividerLocation(300);
split.setLeftComponent(split3);
JSplitPane split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
......@@ -360,26 +363,7 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
return true;
}
public static ImageIcon loadImageIcon(String path,
String description) {
java.net.URL imgURL = SaFariPark.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
public static BufferedImage loadImage(String path) {
java.net.URL imgURL = SaFariPark.class.getResource(path);
try {
return ImageIO.read(imgURL);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
......
package nl.nikhef.safaripark;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.UIManager;
......@@ -16,5 +17,10 @@ public class Title extends JLabel {
setForeground(UIManager.getColor("activeCaptionText"));
}
public Title(String name, Icon icon) {
this(name);
setIcon(icon);
}
}
......@@ -16,6 +16,7 @@ import nl.nikhef.safaripark.SaFariPark;
import nl.nikhef.safaripark.Title;
import nl.nikhef.safaripark.devmgr.DeviceManagerModel.DeviceBayNode;
import nl.nikhef.safaripark.devmgr.DeviceManagerModel.DeviceNode;
import nl.nikhef.safaripark.res.Resources;
import nl.nikhef.sfp.SFPDevice;
import nl.nikhef.sfp.SFPDeviceListener;
import nl.nikhef.sfp.SFPManager;
......@@ -38,9 +39,9 @@ public class DeviceManager extends JPanel implements TreeSelectionListener, SFPD
private TreeRenderer()
{
setOpenIcon(SaFariPark.loadImageIcon("res/pcb16.png", "Device"));
setClosedIcon(SaFariPark.loadImageIcon("res/pcb16.png", "Device"));
setLeafIcon(SaFariPark.loadImageIcon("res/eye16_off.png", "Device"));
setOpenIcon(Resources.getIcon("pcb16"));
setClosedIcon(Resources.getIcon("pcb16"));
setLeafIcon(Resources.getIcon("connect"));
}
......@@ -70,7 +71,7 @@ public class DeviceManager extends JPanel implements TreeSelectionListener, SFPD
JScrollPane sp = new JScrollPane(_tree);
expandAll();
add(new Title("Device Manager"), BorderLayout.NORTH);
add(new Title("Device Manager", Resources.getIcon("network-wired")), BorderLayout.NORTH);
add(sp, BorderLayout.CENTER);
}
......
......@@ -177,7 +177,7 @@ public class DeviceManagerModel implements SFPProviderListener, SFPDeviceListene
SFPDevice dev = _parent.getDevice();
if (dev.isModulePresent(pos)) {
String serial = dev.getModuleSerial(pos);
String serial = dev.getModuleName(pos);
// small window between isPresent and reading serial may allow for null value to be returned
if (serial == null) serial = "<none>";
......
package nl.nikhef.safaripark.dolly;
import javax.swing.DefaultComboBoxModel;
import nl.nikhef.safaripark.devmgr.BaySelectionListener;
import nl.nikhef.sfp.SFPDevice;
import nl.nikhef.sfp.SFPDeviceListener;
public class DollyModel implements SFPDeviceListener, BaySelectionListener {
private DefaultComboBoxModel<Module> _dcb;
public DollyModel()
{
}
@Override
public void sfpModuleStateChanged(SFPDevice dev, int bay)
......
......@@ -2,9 +2,23 @@ package nl.nikhef.safaripark.dolly;
import java.awt.BorderLayout;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.plaf.basic.BasicBorders.RadioButtonBorder;
import net.miginfocom.swing.MigLayout;
import nl.nikhef.safaripark.Title;
import nl.nikhef.safaripark.res.Resources;
import nl.nikhef.safaripark.vsp.ValueSelectionPane;
import nl.nikhef.sfp.ddmi.DDMIElement;
import nl.nikhef.sfp.ddmi.DDMILoader;
......@@ -15,16 +29,65 @@ public class DollyPanel extends JPanel {
private ValueSelectionPane _vsp;
public DollyPanel(DDMILoader loader) {
private JRadioButton _sourceFile = new JRadioButton("File:");
private JLabel _sourceFileName = new JLabel("<none>");
private JButton _sourceFileSelect = new JButton("...");
private JRadioButton _sourceDevice = new JRadioButton("Device:");
private JCheckBox _targetFile = new JCheckBox("File: ");
private JLabel _targetFileName = new JLabel("<none>");
private JButton _targetFileSelect = new JButton("...");
private JButton _clone = new JButton("Clone");
private DollyModel _model;
public DollyPanel(DDMILoader loader, DollyModel model) {
_model = model;
setLayout(new BorderLayout());
add(new Title("Clone Tool"), BorderLayout.NORTH);
add(new Title("Clone Tool", Resources.getIcon("emblem-documents")), BorderLayout.NORTH);
_vsp = new ValueSelectionPane(loader);
JPanel core = new JPanel();
core.setLayout(new BorderLayout());
JPanel source = new JPanel();
source.setLayout(new MigLayout("","[][grow][]",""));
source.add(new JLabel("Source"), "wrap");
source.add(new JSeparator(),"growx, span 3, wrap");
ButtonGroup bg = new ButtonGroup();
bg.add(_sourceDevice);
bg.add(_sourceFile);
_sourceDevice.setSelected(true);
source.add(_sourceDevice);
source.add(new JComboBox<String>(),"growx, span 2,wrap");
source.add(_sourceFile);
source.add(_sourceFileName);
source.add(_sourceFileSelect,"wrap");
core.add(source, BorderLayout.NORTH);
_vsp.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8));
core.add(_vsp, BorderLayout.CENTER);
JPanel target = new JPanel();
target.setLayout(new MigLayout("", "[][grow][]", ""));
target.add(new JLabel("Targets"), "wrap");
target.add(new JSeparator(),"growx, span 3, wrap");
target.add(new JLabel("Devices: "));
target.add(new JScrollPane(new JList<String>()),"growx, span 2, wrap");
target.add(_targetFile);
target.add(_targetFileName);
target.add(_targetFileSelect,"wrap");
core.add(target, BorderLayout.SOUTH);
_vsp.init(new Filter<DDMIElement>() {
@Override
......@@ -46,6 +109,13 @@ public class DollyPanel extends JPanel {
}, "dolly");
add(core, BorderLayout.CENTER);
JPanel buttons = new JPanel();
buttons.setLayout(new BorderLayout());
buttons.add(_clone, BorderLayout.EAST);
add(buttons, BorderLayout.SOUTH);
}
}
package nl.nikhef.safaripark.extra;
import nl.nikhef.sfp.SFPDevice;
public class Module {
public final SFPDevice dev;
public final int bay;
public Module(SFPDevice dev, int bay) {
this.dev = dev;
this.bay = bay;
}
public boolean isPresent()
{
return dev.isModulePresent(bay);
}
public String toString()
{
return dev.getModuleName(bay);
}
}
......@@ -135,7 +135,7 @@ public class MonitorModel extends AbstractTableModel implements SFPDeviceListene
DevAndBay dab = _rows.get(row);
if (col == 0) {
return dab.dev.getModuleSerial(dab.bay);
return dab.dev.getModuleName(dab.bay);
} else {
if (dab.data != null && (col - 1) < dab.data.length)
{
......@@ -224,7 +224,7 @@ public class MonitorModel extends AbstractTableModel implements SFPDeviceListene
{
DevAndBay dab = _rows.get(i);
logFile.print(dab.dev.getModuleSerial(dab.bay));
logFile.print(dab.dev.getModuleName(dab.bay));
for (int j = 0; j < _columns.size(); j++)
{
......
package nl.nikhef.safaripark.res;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
......@@ -8,6 +9,8 @@ import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import nl.nikhef.safaripark.SaFariPark;
public class Resources {
public static final Icon getIcon(String name) {
......@@ -19,5 +22,16 @@ public class Resources {
}
return null;
}
public static Image getImage(String name) {
URL imgURL = Resources.class.getResource(name + ".png");
try {
return ImageIO.read(imgURL);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
......@@ -49,7 +49,7 @@ import nl.nikhef.tools.Filter;
public class ValueSelectionPane extends JPanel implements ItemListener {
private JTree tree = new JTree();
private static final Dimension MIN_SIZE = new Dimension(400, 400);
// private static final Dimension MIN_SIZE = new Dimension(400, 400);
private CheckableTreeNode _root;
private DDMI _ddmi;
......@@ -154,8 +154,8 @@ public class ValueSelectionPane extends JPanel implements ItemListener {
JScrollPane scrollPane = new JScrollPane(tree);
add(scrollPane, BorderLayout.CENTER);
setMinimumSize(MIN_SIZE);
setPreferredSize(MIN_SIZE);
//setMinimumSize(MIN_SIZE);
//setPreferredSize(MIN_SIZE);
_ddmi = loader.getDDMI();
_root = new CheckableTreeNode(_ddmi, "DDMI");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment