This commit is contained in:
gac-S_Changer
2019-02-12 13:44:32 +01:00
parent 3359ffce53
commit 58f1402f73
3 changed files with 76 additions and 16 deletions

View File

@@ -13,6 +13,7 @@ import ch.psi.pshell.imaging.Source;
import ch.psi.pshell.scripting.ViewPreference;
import ch.psi.pshell.ui.App;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.Chrono;
import ch.psi.utils.State;
import ch.psi.utils.swing.SwingUtils;
import java.awt.BorderLayout;
@@ -22,6 +23,9 @@ import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Window;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import javax.swing.GroupLayout;
@@ -241,6 +245,14 @@ public class MainPanel extends Panel {
ledRoomTemperature.setColor(Color.BLACK);
labelRoomTemperature.setText("Room Temperature");
}
try {
if ((expertChrono!=null) && (expertChrono.isTimeout(10 * 60000))){ //After 10min
setExpertMode(false);
}
} catch (Exception ex) {
getLogger().log(Level.WARNING, null, ex);
}
Controller.getInstance().onTimer();
if (getState() == State.Ready) {
if (Boolean.TRUE.equals(Controller.getInstance().isPuckLoading())) {
@@ -439,6 +451,7 @@ public class MainPanel extends Panel {
}
void setExpertMode(boolean expert) {
boolean current = buttonExpertCommands.isVisible();
buttonExpertCommands.setVisible(expert);
buttonRecovery.setVisible(expert);
buttonCalibrateImage.setVisible(expert);
@@ -458,29 +471,33 @@ public class MainPanel extends Panel {
buttonDrawing.setSelected(true);
updateViewType();
}
if (current!=expert){
onModeChange(expert);
}
}
Plugin commandsPlugin;
void showCommandsPanel() {
Panel showCommandsPanel() {
if (commandsPlugin != null) {
getContext().getPluginManager().unloadPlugin(commandsPlugin);
}
commandsPlugin = getContext().getPluginManager().loadPlugin(getContext().getSetup().expandPath("{plugins}/Commands.java"));
((Panel) commandsPlugin).setDetached(true, getTopLevel());
getContext().getPluginManager().initializePlugin(commandsPlugin);
return ((Panel) commandsPlugin);
}
Plugin recoveryPlugin;
void showRecoveryPanel() {
Panel showRecoveryPanel() {
if (recoveryPlugin != null) {
getContext().getPluginManager().unloadPlugin(recoveryPlugin);
}
recoveryPlugin = getContext().getPluginManager().loadPlugin(getContext().getSetup().expandPath("{plugins}/Recovery.java"));
((Panel) recoveryPlugin).setDetached(true, getTopLevel());
getContext().getPluginManager().initializePlugin(recoveryPlugin);
return ((Panel) recoveryPlugin);
}
void setDefaultDetail() {
@@ -575,6 +592,32 @@ public class MainPanel extends Panel {
String ret = textSampleDatamatrix.getText();
return (ret != null) ? ret.trim() : "";
}
Chrono expertChrono;
final List<Window> expertWindows = new ArrayList<>();
void onExpertCommand(Window window){
expertChrono = new Chrono();
if ((window!=null) && (!expertWindows.contains(window))){
expertWindows.add(window);
}
}
void onModeChange(boolean expert){
if (expert){
expertChrono = new Chrono();
} else {
expertChrono = null;
for (Window w : expertWindows){
if ((w!=null) && (w.isShowing())){
w.setVisible(false);
w.dispose();
}
}
expertWindows.clear();
}
}
/**
* This method is called from within the constructor to initialize the form.
@@ -1512,8 +1555,9 @@ public class MainPanel extends Panel {
}//GEN-LAST:event_buttonCameraActionPerformed
private void buttonExpertCommandsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExpertCommandsActionPerformed
try {
showCommandsPanel();
try {
Panel panel = showCommandsPanel();
onExpertCommand(SwingUtils.getWindow(panel));
} catch (Exception ex) {
showException(ex);
}
@@ -1572,8 +1616,8 @@ public class MainPanel extends Panel {
if (dlg.getResult() == false) {
checkExpert.setSelected(false);
return;
}
}
}
}
setExpertMode(checkExpert.isSelected());
}//GEN-LAST:event_checkExpertActionPerformed
@@ -1599,14 +1643,16 @@ public class MainPanel extends Panel {
}//GEN-LAST:event_btViewRTActionPerformed
private void buttonRecoveryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRecoveryActionPerformed
try {
showRecoveryPanel();
try {
Panel panel = showRecoveryPanel();
onExpertCommand(SwingUtils.getWindow(panel));
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonRecoveryActionPerformed
private void buttonCalibrateImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCalibrateImageActionPerformed
onExpertCommand(null);
execute("imgproc/CameraCalibration", null, false, true);
}//GEN-LAST:event_buttonCalibrateImageActionPerformed
@@ -1628,11 +1674,13 @@ public class MainPanel extends Panel {
}//GEN-LAST:event_buttonDetectCoverActionPerformed
private void buttonCalibrateCoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCalibrateCoverActionPerformed
onExpertCommand(null);
execute("imgproc/CoverDetectionCalibration", null, false, true);
}//GEN-LAST:event_buttonCalibrateCoverActionPerformed
private void buttonConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigActionPerformed
this.showSettingsEditor(false);
onExpertCommand(null);
this.showSettingsEditor(true);
}//GEN-LAST:event_buttonConfigActionPerformed
private void buttonReleaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReleaseActionPerformed