configName = configName.replace("*", "").trim();
if (!configName.isEmpty()) {
try {
// Write config
TangoAttribute attribute = new TangoAttribute(getModel() + "/configuration");
Configuration config = tabbedPane.getConfiguration(index);
String unparsedConfig = ConfigParser.getInstance().deParse(config, getPlugins());
attribute.write(unparsedConfig);
// Start scan
TangoCommand startCommand = new TangoCommand(getModel(), "Start");
startCommand.execute();
} catch (DevFailed e) {
String message = DevFailedUtils.toString(e);
LOGGER.log(Level.SEVERE, message);
// System.err.println(message);
}
}
}
}
});
GridBagConstraints startButtonGridBagConstraints = new GridBagConstraints();
startButtonGridBagConstraints.gridx = 0;
startButtonGridBagConstraints.gridy = 0;
startButtonGridBagConstraints.weightx = 0.25;
startButtonGridBagConstraints.weighty = 0;
startButtonGridBagConstraints.ipadx = 0;
startButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
startButtonGridBagConstraints.anchor = GridBagConstraints.EAST;
startButtonGridBagConstraints.insets = new Insets(5, 5, 5, 0);
buttonPanel.add(startButton, startButtonGridBagConstraints);
stopButton = new StringButton();
stopButton.setIcon(Utilities.ICONS.getIcon("flyscan.stop"));
stopButton.setButtonLook(true);
GridBagConstraints stopButtonGridBagConstraints = new GridBagConstraints();
stopButtonGridBagConstraints.gridx = 1;
stopButtonGridBagConstraints.gridy = 0;
stopButtonGridBagConstraints.weightx = 0.25;
stopButtonGridBagConstraints.weighty = 0;
stopButtonGridBagConstraints.ipadx = 0;
stopButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
stopButtonGridBagConstraints.anchor = GridBagConstraints.EAST;
stopButtonGridBagConstraints.insets = new Insets(5, 5, 5, 0);
buttonPanel.add(stopButton, stopButtonGridBagConstraints);
pauseButton = new StringButton();
pauseButton.setIcon(Utilities.ICONS.getIcon("flyscan.pause"));
pauseButton.setButtonLook(true);
GridBagConstraints pauseButtonGridBagConstraints = new GridBagConstraints();
pauseButtonGridBagConstraints.gridx = 2;
pauseButtonGridBagConstraints.gridy = 0;
pauseButtonGridBagConstraints.weightx = 0.25;
pauseButtonGridBagConstraints.weighty = 0;
pauseButtonGridBagConstraints.ipadx = 0;
pauseButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
pauseButtonGridBagConstraints.anchor = GridBagConstraints.EAST;
pauseButtonGridBagConstraints.insets = new Insets(5, 5, 5, 0);
buttonPanel.add(pauseButton, pauseButtonGridBagConstraints);
restartButton = new StringButton();
restartButton.setIcon(Utilities.ICONS.getIcon("flyscan.resume"));
restartButton.setButtonLook(true);
GridBagConstraints restartButtonGridBagConstraints = new GridBagConstraints();
restartButtonGridBagConstraints.gridx = 3;
restartButtonGridBagConstraints.gridy = 0;
restartButtonGridBagConstraints.weightx = 0.25;
restartButtonGridBagConstraints.weighty = 0;
restartButtonGridBagConstraints.ipadx = 0;
restartButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
restartButtonGridBagConstraints.anchor = GridBagConstraints.EAST;
restartButtonGridBagConstraints.insets = new Insets(5, 5, 5, 5);
buttonPanel.add(restartButton, restartButtonGridBagConstraints);
GridBagConstraints buttonPanelGridBagConstraints = new GridBagConstraints();
buttonPanelGridBagConstraints.gridx = 2;
buttonPanelGridBagConstraints.gridy = 0;
buttonPanelGridBagConstraints.weightx = 0.1;
buttonPanelGridBagConstraints.weighty = 0;
buttonPanelGridBagConstraints.insets = new Insets(5, 5, 5, 5);
buttonPanelGridBagConstraints.fill = GridBagConstraints.NONE;
buttonPanelGridBagConstraints.anchor = GridBagConstraints.WEST;
scanInfoAndCommandsPanel.add(buttonPanel, buttonPanelGridBagConstraints);
scanProgressPanel = new JPanel(new GridBagLayout());
GridBagConstraints gc1 = new GridBagConstraints();
gc1.gridx = 0;
gc1.gridy = 0;
gc1.weightx = 0.05;
gc1.weighty = 0;
gc1.fill = GridBagConstraints.NONE;
gc1.anchor = GridBagConstraints.WEST;
scanProgressPanel.add(new JLabel("Scan Progress: "), gc1);
GridBagConstraints gc2 = new GridBagConstraints();
gc2.gridx = 1;
gc2.gridy = 0;
gc2.weightx = 0.95;
gc2.weighty = 0;
gc2.fill = GridBagConstraints.HORIZONTAL;
gc2.anchor = GridBagConstraints.WEST;
scanProgressPanel.add(scanProgressBar, gc2);
GridBagConstraints progressPanelGridBagConstraints = new GridBagConstraints();
progressPanelGridBagConstraints.gridx = 3;
progressPanelGridBagConstraints.gridy = 0;
progressPanelGridBagConstraints.weightx = 0.8;
progressPanelGridBagConstraints.weighty = 0;
progressPanelGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
progressPanelGridBagConstraints.anchor = GridBagConstraints.WEST;
progressPanelGridBagConstraints.insets = new Insets(5, 5, 5, 5);
scanInfoAndCommandsPanel.add(scanProgressPanel, progressPanelGridBagConstraints);
JPanel currentConfigNamePanel = new JPanel(new BorderLayout());
currentConfigNamePanel.add(new JLabel("Current config name: "), BorderLayout.WEST);
currentConfigNamePanel.add(currentConfigNameLabel, BorderLayout.CENTER);
scanPositionPanel = new JPanel(new BorderLayout());
scanPositionPanel.add(new JLabel("Scan Position: "), BorderLayout.WEST);
scanPositionPanel.add(scanPositionLabel, BorderLayout.CENTER);
GridBagConstraints currentConfigNamePanelGridBagConstraints = new GridBagConstraints();
currentConfigNamePanelGridBagConstraints.gridx = 0;
currentConfigNamePanelGridBagConstraints.gridy = 0;
currentConfigNamePanelGridBagConstraints.weightx = 0.1;
currentConfigNamePanelGridBagConstraints.weighty = 0;
currentConfigNamePanelGridBagConstraints.insets = new Insets(5, 5, 5, 5);
currentConfigNamePanelGridBagConstraints.fill = GridBagConstraints.NONE;
currentConfigNamePanelGridBagConstraints.anchor = GridBagConstraints.WEST;
scanInfoAndCommandsPanel.add(currentConfigNamePanel, currentConfigNamePanelGridBagConstraints);
GridBagConstraints positionPanelGridBagConstraints = new GridBagConstraints();
positionPanelGridBagConstraints.gridx = 1;
positionPanelGridBagConstraints.gridy = 0;
positionPanelGridBagConstraints.weightx = 0.1;
positionPanelGridBagConstraints.weighty = 0;
positionPanelGridBagConstraints.insets = new Insets(5, 5, 5, 5);
positionPanelGridBagConstraints.fill = GridBagConstraints.NONE;
positionPanelGridBagConstraints.anchor = GridBagConstraints.WEST;
scanInfoAndCommandsPanel.add(scanPositionPanel, positionPanelGridBagConstraints);
monitoredDevicesPanel = new JPanel(new BorderLayout());
monitoredDevicesPanel.add(monitoredDevices, BorderLayout.CENTER);
GridBagConstraints monitoredPanelGridBagConstraints = new GridBagConstraints();
monitoredPanelGridBagConstraints.gridx = 0;
monitoredPanelGridBagConstraints.gridy = 1;
monitoredPanelGridBagConstraints.weightx = 1;
monitoredPanelGridBagConstraints.weighty = 0;
monitoredPanelGridBagConstraints.gridwidth = 4;
monitoredPanelGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
monitoredPanelGridBagConstraints.anchor = GridBagConstraints.CENTER;
monitoredPanelGridBagConstraints.insets = new Insets(5, 5, 5, 5);
scanInfoAndCommandsPanel.add(monitoredDevicesPanel, monitoredPanelGridBagConstraints);
final GridBagConstraints scanInfoAndCommandsPanelConstraints = new GridBagConstraints();
scanInfoAndCommandsPanelConstraints.gridx = 0;
scanInfoAndCommandsPanelConstraints.gridy = 2;
scanInfoAndCommandsPanelConstraints.weightx = 1;
scanInfoAndCommandsPanelConstraints.weighty = 0;
scanInfoAndCommandsPanelConstraints.fill = GridBagConstraints.HORIZONTAL;
scanInfoAndCommandsPanelConstraints.anchor = GridBagConstraints.CENTER;
configDevicePanel.add(scanInfoAndCommandsPanel, scanInfoAndCommandsPanelConstraints);
this.add(configDevicePanel, devicePanelConstraints);
tabbedPane = new CloseSaveButtonTabbedPane(expert);
tabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (e.getSource() instanceof JTabbedPane) {
JTabbedPane pane = (JTabbedPane) e.getSource();
final int selectedIndex = pane.getSelectedIndex();
boolean atLeastOneTabisDisplayed = (selectedIndex > -1);
boolean currentConfigPaneisSelected = false;
// If current config tab is selected, disable start button
if (selectedIndex > -1) {
String title = tabbedPane.getTitleAt(selectedIndex);
if ((title != null) && (title.equalsIgnoreCase(CURRENT_CONFIG))) {
currentConfigPaneisSelected = true;
}
}
startButton.setEnabled(atLeastOneTabisDisplayed && !(currentConfigPaneisSelected));
}
}
});
ActionListener menuItemActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem flyScanMenuItem = (JMenuItem) e.getSource();
loadAndDisplayConfig(isExpert, flyScanMenuItem.getText());
JPopupMenu popupMenu = (JPopupMenu) ((FlyScanPanelMenuElement) flyScanMenuItem.getParent()).getParent();
popupMenu.setVisible(false);
}
};
ActionListener currentConfigMenuItemActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem flyScanMenuItem = (JMenuItem) e.getSource();
loadAndDisplayCurrentConfig(isExpert, false);
JPopupMenu popupMenu = (JPopupMenu) flyScanMenuItem.getParent();
popupMenu.setVisible(false);
startButton.setEnabled(false);
}
};
KeyListener searchFieldKeyListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
FlyScanMenu flyScanMenu = searchFlyScanMenu(e.getComponent());
if (flyScanMenu != null) {
for (JMenuItem item : flyScanMenu.getItems()) {
if (item.isArmed()) {
loadAndDisplayConfig(isExpert, item.getText().trim());
}
}
// Close menu
flyScanMenu.getPopupMenu().setVisible(false);
}
}
}
};
configurationMenu = new FlyScanMenu(menuItemActionListener, searchFieldKeyListener,
currentConfigMenuItemActionListener, new FlyScanFilter());
configurationMenu.setText("Configurations");
if (useMock) {
// Mock to load a config file without using the device
mockMenu = new JMenu("Mock");
// Create a file chooser
final JFileChooser fcConfig = new JFileChooser();
JMenuItem mockConfigMenuItem = new JMenuItem("Load config file");
mockConfigMenuItem.setToolTipText("First load a plugin file");
mockConfigMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Handle open button action.
int returnVal = fcConfig.showOpenDialog(FlyScanTangoBox.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fcConfig.getSelectedFile();
loadAndDisplayMockConfig(isExpert, file);
}
}
});
mockMenu.add(mockConfigMenuItem);
// Create a file chooser
final JFileChooser fcPlugin = new JFileChooser();
JMenuItem mockPluginMenuItem = new JMenuItem("Load plugin file");
mockPluginMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Handle open button action.
int returnVal = fcPlugin.showOpenDialog(FlyScanTangoBox.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fcPlugin.getSelectedFile();
mockPlugins = getMockPlugins(file);
}
}
});
mockMenu.add(mockPluginMenuItem);
}
pluginTarget = new FlyScanTarget();
currentConfigTarget = new FlyScanTarget() {
@Override
public void setFlatStringMatrix(String[] value, int width, int height) {
super.setFlatStringMatrix(value, width, height);
// When current config change, reload current config tab if it is open
refreshCurrentConfigTab();
Configuration configuration = getCurrentConfiguration();
if (configuration != null) {
String configurationName = getConfigurationName(configuration);
currentConfigNameLabel.setText(configurationName);
}
}
protected void refreshCurrentConfigTab() {
int index = getConfigurationTabIndex(CURRENT_CONFIG);
if (index > -1) {
loadAndDisplayCurrentConfig(isExpert, true);
}
}
@Override
public void setStringMatrix(String[][] value) {
super.setStringMatrix(value);
// When current config change, reload current config tab if it is open
refreshCurrentConfigTab();
Configuration configuration = getCurrentConfiguration();
if (configuration != null) {
String configurationName = getConfigurationName(configuration);
currentConfigNameLabel.setText(configurationName);
}
}