Added samples info editor

This commit is contained in:
2023-04-27 16:14:20 +02:00
parent fa7bc1712a
commit 5266ef751b
2 changed files with 111 additions and 9 deletions

View File

@@ -31,7 +31,7 @@
<Group type="102" alignment="1" attributes="0">
<Component id="panelTop" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="panelBottom" pref="80" max="32767" attributes="0"/>
<Component id="panelBottom" pref="79" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
</Group>
</Group>
@@ -346,9 +346,9 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace pref="18" max="32767" attributes="0"/>
<EmptySpace pref="17" max="32767" attributes="0"/>
<Component id="hexiposiPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="13" max="32767" attributes="0"/>
<EmptySpace pref="12" max="32767" attributes="0"/>
<Component id="buttonDetectCover" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
@@ -384,12 +384,12 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="15" max="32767" attributes="0"/>
<EmptySpace pref="21" max="32767" attributes="0"/>
<Group type="103" groupAlignment="2" attributes="0">
<Component id="buttonDrawing" linkSize="25" alignment="2" min="-2" max="-2" attributes="0"/>
<Component id="buttonCamera" linkSize="25" alignment="2" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="15" max="32767" attributes="0"/>
<EmptySpace pref="21" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -896,7 +896,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="panelDetail" pref="112" max="32767" attributes="0"/>
<Component id="panelDetail" pref="111" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="panelDevices" min="-2" pref="280" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
@@ -1004,9 +1004,9 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="devicesPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="26" max="32767" attributes="0"/>
<EmptySpace pref="22" max="32767" attributes="0"/>
<Component id="panelExpert" min="-2" pref="93" max="-2" attributes="0"/>
<EmptySpace pref="27" max="32767" attributes="0"/>
<EmptySpace pref="22" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -1016,7 +1016,7 @@
<EmptySpace pref="10" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="panelExpert" max="32767" attributes="0"/>
<Component id="devicesPanel" pref="237" max="32767" attributes="0"/>
<Component id="devicesPanel" pref="236" max="32767" attributes="0"/>
</Group>
<EmptySpace pref="10" max="32767" attributes="0"/>
</Group>

View File

@@ -4,6 +4,7 @@
package ch.psi.mxsc;
import ch.psi.mxsc.BasePlatePanel.SelectionMode;
import ch.psi.pshell.core.Context;
import ch.psi.pshell.core.Plugin;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.DeviceAdapter;
@@ -11,11 +12,16 @@ import ch.psi.pshell.imaging.Renderer;
import ch.psi.pshell.imaging.RendererMode;
import ch.psi.pshell.imaging.Source;
import ch.psi.pshell.scripting.ViewPreference;
import ch.psi.pshell.swing.ScriptEditor;
import ch.psi.pshell.ui.App;
import ch.psi.pshell.ui.Panel;
import ch.psi.pshell.ui.StatusBar;
import ch.psi.utils.Chrono;
import ch.psi.utils.State;
import ch.psi.utils.swing.Document;
import ch.psi.utils.swing.DocumentListener;
import ch.psi.utils.swing.Editor;
import ch.psi.utils.swing.JsonTableEditor;
import ch.psi.utils.swing.SwingUtils;
import java.awt.BorderLayout;
import java.awt.Color;
@@ -25,14 +31,21 @@ import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Window;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptException;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
@@ -151,6 +164,9 @@ public class MainPanel extends Panel {
});
}
JMenuItem menuEditSamples;
JsonTableEditor samplesInfoEditor;
@Override
protected void onLoaded() {
if (App.isDetached()) {
@@ -164,7 +180,26 @@ public class MainPanel extends Panel {
statusBar = (StatusBar) SwingUtils.getComponentsByType(getTopLevel(), StatusBar.class)[0];
} catch (Exception ex){
}
if (getView() != null) {
JMenuBar menu = getView().getMenu();
JMenu menuFile = (JMenu) SwingUtils.getComponentByName(menu, "menuFile");
menuEditSamples = new JMenuItem("Edit Samples Info");
menuFile.insert(menuEditSamples,0);
menuEditSamples.addActionListener((e) -> {
samplesInfoEditor = openSamplesInfo();
});
}
}
@Override
protected void onUnloaded() {
if (getView() != null) {
JMenuBar menu = getView().getMenu();
JMenu menuFile = (JMenu) SwingUtils.getComponentByName(menu, "menuFile");
menuFile.remove(menuEditSamples);
}
}
@Override
public void onInitialize(int runCount) {
@@ -676,6 +711,73 @@ public class MainPanel extends Panel {
expertWindows.clear();
}
}
JsonTableEditor openSamplesInfo(){
try{
String file = getContext().getSetup().expandPath("{context}/samples_info.json");
for (Editor ed : getView().getEditors()) {
if (ed instanceof JsonTableEditor) {
if (file.equals(ed.getFileName())){
if (ed.changedOnDisk()){
getView().closeFile(file);
} else {
getView().selectPanel(ed);
return (JsonTableEditor) ed;
}
}
}
}
String[] columns = new String[]{ "userName", "dewarName",
"puckName", "puckType", "puckBarcode", "puckAddress",
"sampleName", "samplePosition", "sampleBarcode", "sampleStatus", "sampleMountCount"
};
Class[] types = null;
JsonTableEditor editor = new JsonTableEditor(columns, types);
editor.getDocument().addListener(new DocumentListener() {
@Override
public void onDocumentChanged(Document doc) {
updateSamplesInfoTitle();
}
@Override
public void onDocumentSaved(Document doc) {
try {
eval("restore_samples_info()", true);
} catch (Exception ex) {
showException(ex);
}
}
});
getView().openComponent(new File(file).getName(), editor);
editor.load(file);
return editor;
} catch (Exception ex) {
showException(ex);
return null;
}
}
void updateSamplesInfoTitle() {
try {
if ((samplesInfoEditor!=null) &&(samplesInfoEditor.isDisplayable())){
String title = new File(samplesInfoEditor.getFileName()).getName()+ (samplesInfoEditor.hasChanged() ? "*" : "");
int index = getView().getDocumentsTab().indexOfComponent(samplesInfoEditor);
if (index>=0){
if (!title.equals(getView().getDocumentsTab().getTitleAt(index))) {
getView().getDocumentsTab().setTitleAt(index, title);
SwingUtils.CloseButtonTabComponent tabComponent = (SwingUtils.CloseButtonTabComponent) getView().getDocumentsTab().getTabComponentAt(index);
tabComponent.updateUI();
}
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, null, ex);
}
}
/**
* This method is called from within the constructor to initialize the form.