diff --git a/src/main/java/plugins/tprovoost/Microscopy/MicroManager/MicroManager.java b/src/main/java/plugins/tprovoost/Microscopy/MicroManager/MicroManager.java index 6717a895f4c3b3a1a9d4e0c9d7d28e4d892d4fcb..b2ecf10a64ca0ac4defcee6a8a1ced6da6759aae 100644 --- a/src/main/java/plugins/tprovoost/Microscopy/MicroManager/MicroManager.java +++ b/src/main/java/plugins/tprovoost/Microscopy/MicroManager/MicroManager.java @@ -64,6 +64,9 @@ public class MicroManager static MMMainFrame instance = null; static Thread liveManager = null; + static boolean inConfigSet = false; + static String lastPresetSet = ""; + /** * @return the MicroManager main frame instance. */ @@ -1143,8 +1146,7 @@ public class MicroManager if (getBinningAsInt(getBinningAsString(core, camera), value) != value) { // get possible values - final StrVector availableBinnings = core.getAllowedPropertyValues(camera, - MMCoreJ.getG_Keyword_Binning()); + final StrVector availableBinnings = core.getAllowedPropertyValues(camera, MMCoreJ.getG_Keyword_Binning()); lock(); try @@ -1407,11 +1409,13 @@ public class MicroManager return; // config changed ? - if (!getCurrentConfig(group).equals(preset)) + if (!StringUtil.equals(getCurrentConfig(group), preset)) { lock(); try { + inConfigSet = true; + // stop acquisition if needed stopAcquisition(); @@ -1421,6 +1425,9 @@ public class MicroManager if (liveRunning) stopLiveMode(); + // save internally + lastPresetSet = preset; + core.setConfig(group, preset); if (wait) core.waitForConfig(group, preset); @@ -1431,11 +1438,23 @@ public class MicroManager } finally { + inConfigSet = false; unlock(); } } } + /** + * @return internal preset name set on last call to {@link #setConfigForGroup(String, String, boolean)} method (workaround for MM empty preset name bug) + */ + public static String getInternalSetPreset() + { + if (inConfigSet) + return lastPresetSet; + + return ""; + } + /** * @return current channel group (camera / channel / objective...) */ @@ -1631,8 +1650,7 @@ public class MicroManager // || version.isGreater(new Version("1.4.22"))) { MessageDialog.showDialog("Error while loading Micro-Manager", - "Your version of Micro-Manager seems to not be compatible !\n" - + "This plugin is only compatible with version 1.4.19 or above.\n" + "Your version of Micro-Manager seems to not be compatible !\n" + "This plugin is only compatible with version 1.4.19 or above.\n" + "Also check that you are using the same architecture for Icy and Micro-Manager (32/64 bits)\n" + "You need to restart Icy to redefine the Micro-Manager folder.", MessageDialog.ERROR_MESSAGE); @@ -1646,8 +1664,7 @@ public class MicroManager return; // show loading message - final LoadingFrame loadingFrame = new LoadingFrame( - " Please wait while loading Micro-Manager, Icy interface may not respond... "); + final LoadingFrame loadingFrame = new LoadingFrame(" Please wait while loading Micro-Manager, Icy interface may not respond... "); loadingFrame.show(); try { @@ -1659,8 +1676,7 @@ public class MicroManager catch (Throwable e) { IcyExceptionHandler.showErrorMessage(e, true, true); - MessageDialog.showDialog("Error while loading Micro-Manager", - e.getMessage() + "\nYou may try to restart Icy to fix the issue.", + MessageDialog.showDialog("Error while loading Micro-Manager", e.getMessage() + "\nYou may try to restart Icy to fix the issue.", MessageDialog.ERROR_MESSAGE); return; } @@ -1714,8 +1730,7 @@ public class MicroManager catch (Throwable e) { IcyExceptionHandler.showErrorMessage(e, true, true); - new FailedAnnounceFrame( - "An error occured while initializing Micro-Manager (see console output for more details)."); + new FailedAnnounceFrame("An error occured while initializing Micro-Manager (see console output for more details)."); // shutdown everything shutdown(); @@ -1728,11 +1743,11 @@ public class MicroManager catch (Throwable t) { // cannot load class --> version mismatch probably - MessageDialog.showDialog("Cannot load Micro-Manager", - "Your version of Micro-Manager seems to not be compatible !\n" - + "This plugin is only compatible with version 1.4.19 or above.\n" - + "Also check that you are using the same architecture for Icy and Micro-Manager (32/64 bits).", - MessageDialog.ERROR_MESSAGE); + MessageDialog + .showDialog("Cannot load Micro-Manager", + "Your version of Micro-Manager seems to not be compatible !\n" + "This plugin is only compatible with version 1.4.19 or above.\n" + + "Also check that you are using the same architecture for Icy and Micro-Manager (32/64 bits).", + MessageDialog.ERROR_MESSAGE); } } @@ -1783,8 +1798,7 @@ public class MicroManager // error default: - new FailedAnnounceFrame("Error while loading configuration file, please restart Micro-Manager.", - 2); + new FailedAnnounceFrame("Error while loading configuration file, please restart Micro-Manager.", 2); break; } } @@ -1884,8 +1898,8 @@ public class MicroManager final JSONObject tags = image.tags; - boolean firstImage = (MDUtils.getPositionIndex(tags) == 0) && (MDUtils.getFrameIndex(tags) == 0) - && (MDUtils.getChannelIndex(tags) == 0) && (MDUtils.getSliceIndex(tags) == 0); + boolean firstImage = (MDUtils.getPositionIndex(tags) == 0) && (MDUtils.getFrameIndex(tags) == 0) && (MDUtils.getChannelIndex(tags) == 0) + && (MDUtils.getSliceIndex(tags) == 0); boolean newAcquisition = (acquisitionManager == null) || acquisitionManager.isDone(); // first acquisition image or new acquisition --> create the new acquisition diff --git a/src/main/java/plugins/tprovoost/Microscopy/MicroManager/gui/ConfigurationPanel.java b/src/main/java/plugins/tprovoost/Microscopy/MicroManager/gui/ConfigurationPanel.java index f7456ffa951224e37a0c4a2f7b1221b0983c3c0b..485886f76f80f0e165da90d96e1d97de90efbfb3 100644 --- a/src/main/java/plugins/tprovoost/Microscopy/MicroManager/gui/ConfigurationPanel.java +++ b/src/main/java/plugins/tprovoost/Microscopy/MicroManager/gui/ConfigurationPanel.java @@ -96,7 +96,7 @@ public class ConfigurationPanel extends JPanel @Override public void run() { - refresgGroupNow(groupNameRefresh, configName); + refreshGroupNow(groupNameRefresh, configName); } }); } @@ -402,7 +402,7 @@ public class ConfigurationPanel extends JPanel return getMMStudio().getCore(); } - public void refresgGroupNow(String group, String config) + public void refreshGroupNow(String group, String config) { groupPad.refreshGroup(group, config); } diff --git a/src/main/java/plugins/tprovoost/Microscopy/MicroManager/gui/MMMainFrame.java b/src/main/java/plugins/tprovoost/Microscopy/MicroManager/gui/MMMainFrame.java index 09599ea335ffeb334cd6f591d36f1ff7d0fefeaf..18c33797cf8aad94c7a4a11047dd50517b1fc041 100644 --- a/src/main/java/plugins/tprovoost/Microscopy/MicroManager/gui/MMMainFrame.java +++ b/src/main/java/plugins/tprovoost/Microscopy/MicroManager/gui/MMMainFrame.java @@ -12,9 +12,11 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; import java.util.prefs.Preferences; +import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JMenu; import javax.swing.JMenuItem; +import javax.swing.JTable; import javax.swing.KeyStroke; import javax.swing.WindowConstants; @@ -302,10 +304,8 @@ public class MMMainFrame extends IcyFrame } }); - final ToolTipFrame tooltip = new ToolTipFrame( - "<html>You can access more Micro-Manager options from menu by clicking on top left icon:<br>" - + "<img src=\"" + getClass().getResource("/image/menu_tip.jpg").toString() + "\" /></html>", - 30, "MicroManager.HiddenMenu.Tip"); + final ToolTipFrame tooltip = new ToolTipFrame("<html>You can access more Micro-Manager options from menu by clicking on top left icon:<br>" + + "<img src=\"" + getClass().getResource("/image/menu_tip.jpg").toString() + "\" /></html>", 30, "MicroManager.HiddenMenu.Tip"); tooltip.setSize(264, 192); } @@ -315,8 +315,8 @@ public class MMMainFrame extends IcyFrame { if (!Icy.isExiting() && (pluginsPanel.getRunningPluginsCount() > 0)) { - if (!ConfirmDialog.confirm( - "Some Micro-Manager plugins are still running.\nClosing this frame will interrupt all Micro-Manager activities. Continue ?")) + if (!ConfirmDialog + .confirm("Some Micro-Manager plugins are still running.\nClosing this frame will interrupt all Micro-Manager activities. Continue ?")) return; } @@ -405,10 +405,8 @@ public class MMMainFrame extends IcyFrame if (pluginsPanel.getRunningPluginsCount() > 0) { // need confirmation - if (!ConfirmDialog.confirm("Are you sure ?", - "<html>Loading the Configuration Wizard will unload all the devices" - + " and pause all running acquisitions.</br>" - + " Are you sure you want to continue ?</html>")) + if (!ConfirmDialog.confirm("Are you sure ?", "<html>Loading the Configuration Wizard will unload all the devices" + + " and pause all running acquisitions.</br>" + " Are you sure you want to continue ?</html>")) return; } @@ -421,8 +419,7 @@ public class MMMainFrame extends IcyFrame mmstudio.logError(e1); } - ConfiguratorDlg2 configurator = new ConfiguratorDlg2(mmstudio.getCore(), - MicroManager.getDefaultConfigFileName()); + ConfiguratorDlg2 configurator = new ConfiguratorDlg2(mmstudio.getCore(), MicroManager.getDefaultConfigFileName()); configurator.setVisible(true); // define new default config file @@ -436,8 +433,7 @@ public class MMMainFrame extends IcyFrame JMenuItem menuPxSizeConfigItem = new JMenuItem("Pixel Size Config"); menuPxSizeConfigItem.setIcon(new IcyIcon(ResourceUtil.ICON_PROPERTIES)); - menuPxSizeConfigItem.setAccelerator( - KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); + menuPxSizeConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); menuPxSizeConfigItem.addActionListener(new ActionListener() { @Override @@ -454,8 +450,7 @@ public class MMMainFrame extends IcyFrame }); JMenuItem loadConfigItem = new JMenuItem("Load Configuration"); - loadConfigItem.setAccelerator( - KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); + loadConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); loadConfigItem.setIcon(new IcyIcon(ResourceUtil.ICON_OPEN)); loadConfigItem.addActionListener(new ActionListener() { @@ -487,8 +482,7 @@ public class MMMainFrame extends IcyFrame }); JMenuItem saveConfigItem = new JMenuItem("Save Configuration"); - saveConfigItem.setAccelerator( - KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); + saveConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); saveConfigItem.setIcon(new IcyIcon(ResourceUtil.ICON_SAVE)); saveConfigItem.addActionListener(new ActionListener() { @@ -553,8 +547,7 @@ public class MMMainFrame extends IcyFrame { // so user can change the defined MM folder MMUtils.resetLibrayPath(); - MessageDialog.showDialog("Information", - "You need to restart Icy now to change the defined Micro-Manager folder.", + MessageDialog.showDialog("Information", "You need to restart Icy now to change the defined Micro-Manager folder.", MessageDialog.INFORMATION_MESSAGE); } }); @@ -592,10 +585,8 @@ public class MMMainFrame extends IcyFrame if (options == null) return; - final OptionsPanel optionsPanel = new OptionsPanel(MMMainFrame.this, options, - mmstudio.getCore()); - final ActionDialog optionsDialog = new ActionDialog("Micro-Manager Options", optionsPanel, - Icy.getMainInterface().getMainFrame()); + final OptionsPanel optionsPanel = new OptionsPanel(MMMainFrame.this, options, mmstudio.getCore()); + final ActionDialog optionsDialog = new ActionDialog("Micro-Manager Options", optionsPanel, Icy.getMainInterface().getMainFrame()); optionsDialog.setOkAction(optionsPanel); optionsDialog.pack(); optionsDialog.setResizable(false); @@ -686,8 +677,7 @@ public class MMMainFrame extends IcyFrame public void loadConfig(final String filePath) { // show loading message - final LoadingFrame loadingFrame = new LoadingFrame( - " Please wait while loading Micro-Manager configuration, it may take a while... "); + final LoadingFrame loadingFrame = new LoadingFrame(" Please wait while loading Micro-Manager configuration, it may take a while... "); loadingFrame.show(); try @@ -708,9 +698,8 @@ public class MMMainFrame extends IcyFrame } catch (Exception e) { - MessageDialog.showDialog( - "Error while initializing the microscope: please check if all devices are correctly turned on " - + "and recognized by the computer and quit any program using those devices. Pleas check also that your configuration file is correct.", + MessageDialog.showDialog("Error while initializing the microscope: please check if all devices are correctly turned on " + + "and recognized by the computer and quit any program using those devices. Pleas check also that your configuration file is correct.", MessageDialog.ERROR_MESSAGE); } finally @@ -735,8 +724,7 @@ public class MMMainFrame extends IcyFrame model.loadFromFile(MicroManager.getDefaultConfigFileName()); model.createSetupConfigsFromHardware(mmstudio.getCore()); model.createResolutionsFromHardware(mmstudio.getCore()); - String path = SaveDialog.chooseFile("Save the configuration file", FileUtil.getApplicationDirectory(), - "myConfig", ".cfg"); + String path = SaveDialog.chooseFile("Save the configuration file", FileUtil.getApplicationDirectory(), "myConfig", ".cfg"); if (path != null) model.saveToFile(path); } @@ -970,16 +958,42 @@ public class MMMainFrame extends IcyFrame @Override public void onConfigGroupChanged(String groupName, String newConfig) { - super.onConfigGroupChanged(groupName, newConfig); + // default + String config = newConfig; + // can happen sometime --> try to get it from internal if possible + if (StringUtil.isEmpty(config)) + config = MicroManager.getInternalSetPreset(); + + // still empty ? --> try to get it from the config table component + if (StringUtil.isEmpty(config) && (configPanel != null)) + { + final JTable table = (JTable) configPanel.groupPad.getViewport().getView(); + final JComboBox editor = (JComboBox) table.getEditorComponent(); + + if (editor != null) + config = (String) editor.getSelectedItem(); + + // still empty ? --> exit + if (StringUtil.isEmpty(config)) + return; + } + + // changed ? --> set it again + // if (!StringUtil.equals(config, newConfig)) + // MicroManager.setConfigForGroup(groupName, config, true); + + super.onConfigGroupChanged(groupName, config); + + // set it directly in the config table if (configPanel != null) - configPanel.refreshGroup(groupName); + configPanel.groupPad.refreshGroup(groupName, config); if (acquisitionInfoPanel != null) acquisitionInfoPanel.refresh(); // dispatch to listeners for (CoreListener listener : MicroManager.getCoreListeners()) - listener.onConfigGroupChanged(groupName, newConfig); + listener.onConfigGroupChanged(groupName, config); } @Override