diff --git a/src/org/hwo/pulscounter/SnapShot.java b/src/org/hwo/pulscounter/SnapShot.java index ceab098..b380372 100644 --- a/src/org/hwo/pulscounter/SnapShot.java +++ b/src/org/hwo/pulscounter/SnapShot.java @@ -9,6 +9,7 @@ import java.util.Arrays; import java.util.Date; import org.hwo.csv.CSVRecord; +import org.hwo.models.TableMapper.TableColumn; import org.hwo.servicelink.ServiceLink; import org.hwo.servicelink.ServiceLinkException; @@ -21,19 +22,24 @@ public class SnapShot { Integer[] values; Integer[] analog; + Integer[] merker; Integer inputmask, outputmask, pullupmask, invertmask, triggermask; - + + static SimpleDateFormat + df = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); + public SnapShot(int deviceSerial){ this.deviceSerial = deviceSerial; this.values = new Integer[32]; this.analog = new Integer[8]; + this.merker = new Integer[24]; } @@ -74,6 +80,7 @@ public class SnapShot { } } + @TableColumn(label="Gerät",order=5,width=80) public Integer getDeviceSerial() { return deviceSerial; } @@ -81,6 +88,7 @@ public class SnapShot { this.deviceSerial = deviceSerial; } + @TableColumn(label="HW-Index",order=0,width=80) public Integer getIndex() { return index; } @@ -97,6 +105,7 @@ public class SnapShot { public void setTimestamp(Integer timestamp) { this.timestamp = timestamp; } + public Integer getTimestamp() { return timestamp; } @@ -141,7 +150,9 @@ public class SnapShot { return this.values[ch]; } return null; - } + } + + @TableColumn(label="Zähler #%d",order=50,fieldlength=32, width=80) public Integer[] getValues(){ return Arrays.copyOf(this.values, this.values.length); } @@ -172,7 +183,12 @@ public class SnapShot { public int getSource(){ return (field0 >> 8) & 0xff; } + + @TableColumn(label="Zeitstempel",order=10,width=100) + public String getTimeStampFormated(){ + return df.format(new Date(((long)timestamp)*1000)); + } public byte[] toBytes(){ byte[] buffer = new byte[256]; @@ -226,7 +242,6 @@ public class SnapShot { if (extended) record.appendValue(timestamp); - SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); record.appendValue(df.format(new Date(((long)timestamp)*1000))); diff --git a/src/org/hwo/pulscounter/db/PulsCounterDatabase.java b/src/org/hwo/pulscounter/db/PulsCounterDatabase.java index 79f040f..41fd336 100644 --- a/src/org/hwo/pulscounter/db/PulsCounterDatabase.java +++ b/src/org/hwo/pulscounter/db/PulsCounterDatabase.java @@ -267,7 +267,7 @@ public class PulsCounterDatabase { simpleScript.getId(), simpleScript.getName(), simpleScript.getDescription(), - simpleScript.getSimpleScriptElementsAsInt() + simpleScript.getSimpleScriptElementsAsInteger() ); } diff --git a/src/org/hwo/pulscounter/device/IDeviceConnector.java b/src/org/hwo/pulscounter/device/IDeviceConnector.java index 657d5f3..c78b2c4 100644 --- a/src/org/hwo/pulscounter/device/IDeviceConnector.java +++ b/src/org/hwo/pulscounter/device/IDeviceConnector.java @@ -1,5 +1,7 @@ package org.hwo.pulscounter.device; +import java.awt.Component; + import org.hwo.pulscounter.SnapShot; public interface IDeviceConnector { @@ -9,7 +11,7 @@ public interface IDeviceConnector { public Integer getDeviceSerial(); - public boolean showConnctionSetup(); + public boolean showConnctionSetup(Component parent); public String getConnectionSettings(); public void setConnectionSettings(String connectionSettings); public String getConnectionSettingsText(); @@ -51,7 +53,10 @@ public interface IDeviceConnector { public int[] getWindows(); public void setWindows(int[] windows); - + + public int[] getIncrements(); + public void setIncrements(int[] increments); + public int getInterval(int iNo); public boolean isIntervalDailyBased(int iNo); public void setInterval(int iNo,int intervall,boolean dailyBase); diff --git a/src/org/hwo/pulscounter/device/ServiceLinkDeviceConnector.java b/src/org/hwo/pulscounter/device/ServiceLinkDeviceConnector.java index 4de7c51..7467ae4 100644 --- a/src/org/hwo/pulscounter/device/ServiceLinkDeviceConnector.java +++ b/src/org/hwo/pulscounter/device/ServiceLinkDeviceConnector.java @@ -1,5 +1,6 @@ package org.hwo.pulscounter.device; +import java.awt.Component; import java.io.IOException; import java.text.DateFormat; import java.util.ArrayList; @@ -10,6 +11,7 @@ import java.util.List; import org.hwo.io.NewSerialPort.NewSerialPort; import org.hwo.pulscounter.SnapShot; +import org.hwo.pulscounter.simplescript.SimpleScript.SimpleScriptElement; import org.hwo.pulscounter.ui.DeviceConfiguration; import org.hwo.servicelink.ServiceLink; import org.hwo.servicelink.ServiceLinkException; @@ -84,8 +86,8 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector { } @Override - public boolean showConnctionSetup() { - NewSerialPort newSerialPort = SerialPortChooser.execute(serviceLink.getSerialPort().getPortName()); + public boolean showConnctionSetup(Component parent) { + NewSerialPort newSerialPort = SerialPortChooser.execute(parent,serviceLink.getSerialPort().getPortName()); if (newSerialPort != null){ serviceLink.close(); serviceLink.getSerialPort().setPortName(newSerialPort.getPortName()); @@ -161,13 +163,55 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector { @Override public int[] getSimpleScript() { - // TODO Auto-generated method stub + try { + Integer l = serviceLink.readInt(13, 0, 0x0700); + + log(DEBUG,"%d ScriptElements on Device.",l); + + if (l<0) + return new int[0]; + + int[] script = new int[l]; + int p; + + serviceLink.writeInt(13, 0, 0x0701, 0); + for (p=0;p B") ; static ScriptCondition scriptConditions[] = { @@ -175,20 +212,31 @@ public class SimpleScript { A_LT_B, A_GT_B }; - + static ScriptCondition get(int code){ return scriptConditions[code]; } private int code; + private String desc; - ScriptCondition(int code){ + ScriptCondition(int code,String desc){ this.code = code; + this.desc = desc; } public int getCode(){ return this.code; } + + public String getDesc() { + return desc; + } + + @Override + public String toString() { + return desc; + } } public static class SimpleScriptElement{ @@ -244,10 +292,10 @@ public class SimpleScript { } public int getCondition(){ - return (code >> 24) & 0xff; + return (code >> 24) & 0x07; } public int getOperation(){ - return (code >> 27) & 0xff; + return (code >> 27) & 0x1f; } public void setA(int a){ @@ -272,7 +320,7 @@ public class SimpleScript { } @TableColumn(label="Operation",order=50) - ScriptOperation getScriptOperation(){ + public ScriptOperation getScriptOperation(){ return ScriptOperation.get(getOperation()); } public void setScriptOperation(ScriptOperation scriptOperation){ diff --git a/src/org/hwo/pulscounter/simplescript/SimpleScriptAddress.java b/src/org/hwo/pulscounter/simplescript/SimpleScriptAddress.java index fadf960..c0aa7e9 100644 --- a/src/org/hwo/pulscounter/simplescript/SimpleScriptAddress.java +++ b/src/org/hwo/pulscounter/simplescript/SimpleScriptAddress.java @@ -10,6 +10,13 @@ public class SimpleScriptAddress{ this.address = a; } + public int getAddress() { + return address; + } + public void setAddress(int address) { + this.address = address; + } + @Override public String toString() { return toString(address); @@ -28,8 +35,10 @@ public class SimpleScriptAddress{ return String.format("Ausgang %d", address - 96); } else if (address < 160){ return String.format("Inverter %d", address - 128); + } else if (address < 192){ + return String.format("Eingang %d", address - 160); } else { - return String.format("Variable %d", address - 160); + return String.format("Variable %d", address - 192); } } diff --git a/src/org/hwo/pulscounter/ui/DeviceConfiguration.java b/src/org/hwo/pulscounter/ui/DeviceConfiguration.java index 2515c5e..0e4590b 100644 --- a/src/org/hwo/pulscounter/ui/DeviceConfiguration.java +++ b/src/org/hwo/pulscounter/ui/DeviceConfiguration.java @@ -20,9 +20,14 @@ import javax.swing.JTabbedPane; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import javax.swing.JLabel; +import javax.swing.JOptionPane; + import java.awt.Insets; +import java.awt.Dialog.ModalityType; import java.awt.Dimension; import javax.swing.JComboBox; +import javax.swing.JDialog; + import java.awt.event.ActionListener; import java.io.IOException; import java.math.BigInteger; @@ -44,7 +49,7 @@ import java.awt.event.FocusEvent; import javax.swing.JScrollPane; import javax.swing.JTable; -public class DeviceConfiguration extends JFrame { +public class DeviceConfiguration extends JDialog { private JPanel contentPane; @@ -64,10 +69,16 @@ public class DeviceConfiguration extends JFrame { trigger; int[] filter, - windows; + windows, + increments; + private JTable tSettings; private IDeviceConnector deviceConnector; + private JPanel pManagement; + private JButton btnSnapshotSpeicherZurcksetzen; + private JButton btnSnapshotSpeicherAuf; + private JButton btnAlleZhlerLschen; /** * Create the frame. @@ -75,6 +86,8 @@ public class DeviceConfiguration extends JFrame { public DeviceConfiguration(IDeviceConnector deviceConnector) { this.deviceConnector = deviceConnector; + setModalityType(ModalityType.APPLICATION_MODAL); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 860, 498); contentPane = new JPanel(); @@ -224,47 +237,6 @@ public class DeviceConfiguration extends JFrame { gbc_tseI3.gridy = 4; panel_2.add(tseI3, gbc_tseI3); - JButton btnSnapshotSpeicherZurcksetzen = new JButton("SnapShot Speicher zurücksetzen"); - btnSnapshotSpeicherZurcksetzen.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - resetSnapShots(); - } - }); - GridBagConstraints gbc_btnSnapshotSpeicherZurcksetzen = new GridBagConstraints(); - gbc_btnSnapshotSpeicherZurcksetzen.gridwidth = 2; - gbc_btnSnapshotSpeicherZurcksetzen.fill = GridBagConstraints.HORIZONTAL; - gbc_btnSnapshotSpeicherZurcksetzen.insets = new Insets(0, 0, 5, 0); - gbc_btnSnapshotSpeicherZurcksetzen.gridx = 0; - gbc_btnSnapshotSpeicherZurcksetzen.gridy = 5; - panel_2.add(btnSnapshotSpeicherZurcksetzen, gbc_btnSnapshotSpeicherZurcksetzen); - - JButton btnAlleZhlerLschen = new JButton("Alle Zähler zurücksetzen"); - btnAlleZhlerLschen.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - resetCounters(); - } - }); - - JButton btnSnapshotSpeicherAuf = new JButton("SnapShot Speicher auf letzten bekannten SnapShot setzen"); - btnSnapshotSpeicherAuf.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - resetSnapShots(true); - } - }); - GridBagConstraints gbc_btnSnapshotSpeicherAuf = new GridBagConstraints(); - gbc_btnSnapshotSpeicherAuf.fill = GridBagConstraints.HORIZONTAL; - gbc_btnSnapshotSpeicherAuf.gridwidth = 2; - gbc_btnSnapshotSpeicherAuf.insets = new Insets(0, 0, 5, 0); - gbc_btnSnapshotSpeicherAuf.gridx = 0; - gbc_btnSnapshotSpeicherAuf.gridy = 6; - panel_2.add(btnSnapshotSpeicherAuf, gbc_btnSnapshotSpeicherAuf); - GridBagConstraints gbc_btnAlleZhlerLschen = new GridBagConstraints(); - gbc_btnAlleZhlerLschen.gridwidth = 2; - gbc_btnAlleZhlerLschen.fill = GridBagConstraints.HORIZONTAL; - gbc_btnAlleZhlerLschen.gridx = 0; - gbc_btnAlleZhlerLschen.gridy = 7; - panel_2.add(btnAlleZhlerLschen, gbc_btnAlleZhlerLschen); - JPanel panel_1 = new JPanel(); tabbedPane.addTab("Kanäle", null, panel_1, null); GridBagLayout gbl_panel_1 = new GridBagLayout(); @@ -287,6 +259,62 @@ public class DeviceConfiguration extends JFrame { tSettings.setCellSelectionEnabled(true); scrollPane.setViewportView(tSettings); + pManagement = new JPanel(); + tabbedPane.addTab("Speicherverwaltung", null, pManagement, null); + GridBagLayout gbl_pManagement = new GridBagLayout(); + gbl_pManagement.columnWidths = new int[] {100}; + gbl_pManagement.rowHeights = new int[]{25, 0, 0, 0, 0}; + gbl_pManagement.columnWeights = new double[]{1.0}; + gbl_pManagement.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; + pManagement.setLayout(gbl_pManagement); + + btnAlleZhlerLschen = new JButton("Alle Zähler zurücksetzen"); + btnAlleZhlerLschen.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + resetCounters(); + } + }); + GridBagConstraints gbc_btnAlleZhlerLschen_1_1 = new GridBagConstraints(); + gbc_btnAlleZhlerLschen_1_1.fill = GridBagConstraints.HORIZONTAL; + gbc_btnAlleZhlerLschen_1_1.gridx = 0; + gbc_btnAlleZhlerLschen_1_1.gridy = 0; + gbc_btnAlleZhlerLschen_1_1.insets = new Insets(0, 0, 5, 0); + pManagement.add(btnAlleZhlerLschen, gbc_btnAlleZhlerLschen_1_1); + + JLabel lblNurNachRcksprache = new JLabel("Nur nach Rücksprache mit Support:"); + GridBagConstraints gbc_lblNurNachRcksprache = new GridBagConstraints(); + gbc_lblNurNachRcksprache.fill = GridBagConstraints.HORIZONTAL; + gbc_lblNurNachRcksprache.insets = new Insets(0, 0, 5, 0); + gbc_lblNurNachRcksprache.gridx = 0; + gbc_lblNurNachRcksprache.gridy = 1; + pManagement.add(lblNurNachRcksprache, gbc_lblNurNachRcksprache); + + btnSnapshotSpeicherZurcksetzen = new JButton("SnapShot Speicher zurücksetzen"); + btnSnapshotSpeicherZurcksetzen.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + resetSnapShots(); + } + }); + + btnSnapshotSpeicherAuf = new JButton("SnapShot Speicher auf letzten bekannten SnapShot setzen"); + btnSnapshotSpeicherAuf.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + resetSnapShots(true); + } + }); + GridBagConstraints gbc_btnSnapshotSpeicherAuf_1_1 = new GridBagConstraints(); + gbc_btnSnapshotSpeicherAuf_1_1.fill = GridBagConstraints.HORIZONTAL; + gbc_btnSnapshotSpeicherAuf_1_1.insets = new Insets(0, 0, 5, 0); + gbc_btnSnapshotSpeicherAuf_1_1.gridx = 0; + gbc_btnSnapshotSpeicherAuf_1_1.gridy = 2; + pManagement.add(btnSnapshotSpeicherAuf, gbc_btnSnapshotSpeicherAuf_1_1); + GridBagConstraints gbc_btnSnapshotSpeicherZurcksetzen_1_1 = new GridBagConstraints(); + gbc_btnSnapshotSpeicherZurcksetzen_1_1.fill = GridBagConstraints.HORIZONTAL; + gbc_btnSnapshotSpeicherZurcksetzen_1_1.gridx = 0; + gbc_btnSnapshotSpeicherZurcksetzen_1_1.gridy = 3; + pManagement.add(btnSnapshotSpeicherZurcksetzen, gbc_btnSnapshotSpeicherZurcksetzen_1_1); + + JButton btnSchliessen = new JButton("abbrechen"); btnSchliessen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -326,6 +354,8 @@ public class DeviceConfiguration extends JFrame { currentChannel = -1; filter = new int[32]; windows = new int[32]; + increments = new int[32]; + tmSettings = new TableMapper(ChannelConfiguration.class, tSettings); BitField bf = new BitField(); @@ -344,17 +374,22 @@ public class DeviceConfiguration extends JFrame { } private void resetSnapShots(){ - resetSnapShots(false); + resetSnapShots(false); } private void resetSnapShots(boolean toLastKnown){ - deviceConnector.reset(toLastKnown ? PulsCounterApplication.getApplication().getDatabase().highestSnapShot(deviceConnector.getDeviceSerial()) : -1); + if (JOptionPane.showConfirmDialog(null, "Diese Funktion sollte nur auf Aufforderung durch den Support ausgeführt werden.
Soll der Snapshot Index auf dem Gerät wirklich zurückgesetzt werden?", "Snapshot Index zurücksetzen", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){ + deviceConnector.reset(toLastKnown ? PulsCounterApplication.getApplication().getDatabase().highestSnapShot(deviceConnector.getDeviceSerial()) : -1); + } } private void resetCounters(){ - int[] zero = new int[32]; - Arrays.fill(zero, 0); - deviceConnector.setCounters(zero); + + if (JOptionPane.showConfirmDialog(null, "Wollen Sie wirklich alle Zählerstände auf 0 zurücksetzen?", "Alle Zählerstände zurücksetzen", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){ + int[] zero = new int[32]; + Arrays.fill(zero, 0); + deviceConnector.setCounters(zero); + } } private void readDevice(){ @@ -363,12 +398,13 @@ public class DeviceConfiguration extends JFrame { outputs = intOr0(deviceConnector.getConfigOutputs()); pullups = intOr0(deviceConnector.getConfigPullups()); inverts = intOr0(deviceConnector.getConfigInverts()); - trigger = intOr0(deviceConnector.getConfigTriggers()); + trigger = intOr0(deviceConnector.getConfigTriggers()); bfeIntervall.setIntValue(deviceConnector.getDailyBaseMask()); filter = deviceConnector.getDebounce(); windows = deviceConnector.getWindows(); + increments = deviceConnector.getIncrements(); tseI0.setValue( deviceConnector.getInterval(0) ); tseI1.setValue( deviceConnector.getInterval(1) ); @@ -390,6 +426,7 @@ public class DeviceConfiguration extends JFrame { deviceConnector.setDebounce(filter); deviceConnector.setWindows(windows); + deviceConnector.setIncrements(increments); deviceConnector.syncConfigToLive(); } @@ -402,7 +439,7 @@ public class DeviceConfiguration extends JFrame { this.channel = channel; } - @TableColumn(label="Channel",width=80,order=0) + @TableColumn(label="Kanal",width=60,order=0,format="%02d") public int getChannel(){ return channel; } @@ -467,6 +504,14 @@ public class DeviceConfiguration extends JFrame { filter[channel] = value; } + @TableColumn(label="Inkrement",width=80,order=190) + public Integer getIncrement(){ + return increments[channel]; + } + public void setIncrement(Integer increment){ + increments[channel] = increment; + } + } diff --git a/src/org/hwo/pulscounter/ui/ExportFilesFrame.java b/src/org/hwo/pulscounter/ui/ExportFilesFrame.java index 8aadc80..998d1fd 100644 --- a/src/org/hwo/pulscounter/ui/ExportFilesFrame.java +++ b/src/org/hwo/pulscounter/ui/ExportFilesFrame.java @@ -17,6 +17,8 @@ import org.hwo.pulscounter.PulsCounterApplication; import java.awt.GridBagLayout; import javax.swing.JButton; +import javax.swing.JDialog; + import java.awt.GridBagConstraints; import javax.swing.JScrollPane; import java.awt.Insets; @@ -26,8 +28,10 @@ import java.awt.event.ActionEvent; import javax.swing.JToolBar; import javax.swing.ListSelectionModel; import javax.swing.JSeparator; +import java.awt.Dialog.ModalExclusionType; +import java.awt.Dialog.ModalityType; -public class ExportFilesFrame extends JFrame { +public class ExportFilesFrame extends JDialog { private JPanel contentPane; private JTable tExportSettings; @@ -47,6 +51,8 @@ public class ExportFilesFrame extends JFrame { * Create the frame. */ public ExportFilesFrame() { + setModalityType(ModalityType.APPLICATION_MODAL); + setTitle("Export Einstellungen..."); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 825, 433); diff --git a/src/org/hwo/pulscounter/ui/ExportSettingsEditorDialog.java b/src/org/hwo/pulscounter/ui/ExportSettingsEditorDialog.java index 16840f2..5169398 100644 --- a/src/org/hwo/pulscounter/ui/ExportSettingsEditorDialog.java +++ b/src/org/hwo/pulscounter/ui/ExportSettingsEditorDialog.java @@ -107,6 +107,7 @@ public class ExportSettingsEditorDialog extends JDialog implements IObjectEditor } }); cbTriggerType.addItem(TriggerType.ALL); + cbTriggerType.addItem(TriggerType.Trigger); cbTriggerType.addItem(TriggerType.Intervall); cbTriggerType.addItem(TriggerType.Timer); cbTriggerType.addItem(TriggerType.Manual); diff --git a/src/org/hwo/pulscounter/ui/NewMainWindow.java b/src/org/hwo/pulscounter/ui/NewMainWindow.java index d057f98..914c811 100644 --- a/src/org/hwo/pulscounter/ui/NewMainWindow.java +++ b/src/org/hwo/pulscounter/ui/NewMainWindow.java @@ -126,6 +126,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis private JPanel panel_4; private JTextArea tfConnectionSettings; private JButton btnSkripte; + private JButton btnAufzeichnungenVerwalten; public static void startGUI(){ @@ -276,7 +277,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis */ private void initialize() { frmSynolog = new JFrame(); - frmSynolog.setTitle("Synololog"); + frmSynolog.setTitle("SYNOLO-LOG"); frmSynolog.setBounds(100, 100, 1000, 580); frmSynolog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frmSynolog.getContentPane().setLayout(new BorderLayout(0, 0)); @@ -294,6 +295,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis public void actionPerformed(ActionEvent e) { if (selectedDeviceInterface != null){ DeviceConfiguration cc = new DeviceConfiguration(selectedDeviceInterface); + cc.setLocationRelativeTo(frmSynolog); cc.setVisible(true); } } @@ -305,6 +307,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis btnDatenExportieren.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ExportFilesFrame eff = new ExportFilesFrame(); + eff.setLocationRelativeTo(frmSynolog); eff.setVisible(true); } }); @@ -320,6 +323,14 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis }); toolBar.add(btnSkripte); + btnAufzeichnungenVerwalten = new JButton("Aufzeichnungen verwalten"); + btnAufzeichnungenVerwalten.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + SnapshotManager.show(frmSynolog); + } + }); + toolBar.add(btnAufzeichnungenVerwalten); + splitter = new JSplitPane(); splitter.setBorder(null); splitter.setOneTouchExpandable(true); @@ -395,7 +406,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis public void mouseClicked(MouseEvent e) { if ((e.getClickCount()==2)&&(e.getButton()==e.BUTTON1)){ if (selectedDeviceInterface != null){ - selectedDeviceInterface.showConnctionSetup(); + selectedDeviceInterface.showConnctionSetup(frmSynolog); frmSynolog.repaint(); } } diff --git a/src/org/hwo/pulscounter/ui/SimpleScriptAddressEditor.java b/src/org/hwo/pulscounter/ui/SimpleScriptAddressEditor.java index d300d26..e913f48 100644 --- a/src/org/hwo/pulscounter/ui/SimpleScriptAddressEditor.java +++ b/src/org/hwo/pulscounter/ui/SimpleScriptAddressEditor.java @@ -5,7 +5,14 @@ import java.awt.GridBagLayout; import javax.swing.JComboBox; import java.awt.GridBagConstraints; import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + import javax.swing.JSpinner; +import javax.swing.SpinnerNumberModel; + +import org.hwo.pulscounter.simplescript.SimpleScriptAddress; +import org.hwo.ui.JComboBoxEx; public class SimpleScriptAddressEditor extends JPanel { @@ -16,8 +23,15 @@ public class SimpleScriptAddressEditor extends JPanel { new AddressRange("PullUp Status", 64, 32), new AddressRange("Ausgang", 96, 32), new AddressRange("Inverter", 128, 32), - new AddressRange("Variable", 160, 96) + new AddressRange("Eingang", 160, 32), + new AddressRange("Variable", 192, 64) }; + private JComboBoxEx cbRange; + private JSpinner spValue; + private SpinnerNumberModel numberModel = new SpinnerNumberModel(0, 0, 0, 1); + + private int + address; /** * Create the panel. @@ -30,23 +44,72 @@ public class SimpleScriptAddressEditor extends JPanel { gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE}; setLayout(gridBagLayout); - JComboBox comboBox = new JComboBox(); - GridBagConstraints gbc_comboBox = new GridBagConstraints(); - gbc_comboBox.insets = new Insets(0, 0, 0, 5); - gbc_comboBox.fill = GridBagConstraints.BOTH; - gbc_comboBox.gridx = 0; - gbc_comboBox.gridy = 0; - add(comboBox, gbc_comboBox); + cbRange = new JComboBoxEx(); + GridBagConstraints gbc_cbRange = new GridBagConstraints(); + gbc_cbRange.insets = new Insets(0, 0, 0, 5); + gbc_cbRange.fill = GridBagConstraints.BOTH; + gbc_cbRange.gridx = 0; + gbc_cbRange.gridy = 0; + cbRange.setItems(addressRanges); + cbRange.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + syncNumberFormat(); + } + }); + add(cbRange, gbc_cbRange); - JSpinner spinner = new JSpinner(); - GridBagConstraints gbc_spinner = new GridBagConstraints(); - gbc_spinner.fill = GridBagConstraints.BOTH; - gbc_spinner.gridx = 1; - gbc_spinner.gridy = 0; - add(spinner, gbc_spinner); + spValue = new JSpinner(); + GridBagConstraints gbc_spValue = new GridBagConstraints(); + gbc_spValue.fill = GridBagConstraints.BOTH; + gbc_spValue.gridx = 1; + gbc_spValue.gridy = 0; + spValue.setModel(numberModel); + add(spValue, gbc_spValue); + cbRange.setSelectedIndex(0); + } + + private AddressRange getSelectedRange(){ + return (AddressRange)cbRange.getSelectedItem(); + } + private int getSelectedDisplayValue(){ + return (Integer)spValue.getValue(); } + private void syncNumberFormat(){ + AddressRange range = getSelectedRange(); + numberModel.setMaximum(range.getSize()-1); + + if (range.getSize() <= getSelectedDisplayValue()){ + numberModel.setValue(range.getSize()-1); + } + } + + public int getAddress() { + this.address = getSelectedRange().scriptValue(((Integer)numberModel.getValue()).intValue()); + return address; + } + public void setAddress(int address) { + this.address = address; + + cbRange.setEnabled(true); + cbRange.setSelectedItem(findRange(address)); + syncNumberFormat(); + + numberModel.setValue(getSelectedRange().displayValue(address)); + } + + private AddressRange findRange(int address){ + for (AddressRange range: addressRanges){ + if (range.contains(address)) + return range; + } + return null; + } + + private class AddressRange{ @@ -70,6 +133,21 @@ public class SimpleScriptAddressEditor extends JPanel { return name; } + public boolean contains(int address){ + return (base <= address) && (address < (base+size)); + } + + public int displayValue(int address){ + return address - base; + } + public int scriptValue(int displayAddress){ + return displayAddress + base; + } + + @Override + public String toString() { + return name; + } } } diff --git a/src/org/hwo/pulscounter/ui/SimpleScriptEditor.java b/src/org/hwo/pulscounter/ui/SimpleScriptEditor.java index 4e3131e..e71b557 100644 --- a/src/org/hwo/pulscounter/ui/SimpleScriptEditor.java +++ b/src/org/hwo/pulscounter/ui/SimpleScriptEditor.java @@ -7,9 +7,12 @@ import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JPanel; +import javax.swing.JPopupMenu; import javax.swing.border.EmptyBorder; import org.hwo.models.TableMapper.TableColumn; +import org.hwo.models.TableMapper.TableMapper; +import org.hwo.models.TableMapper.TableMapperListener; import org.hwo.pulscounter.simplescript.SimpleScript; import org.hwo.pulscounter.simplescript.SimpleScript.ScriptCondition; import org.hwo.pulscounter.simplescript.SimpleScript.SimpleScriptElement; @@ -22,13 +25,20 @@ import javax.swing.JTable; import java.awt.GridBagConstraints; import javax.swing.JScrollPane; import javax.swing.JLabel; +import javax.swing.JMenuItem; + import java.awt.Insets; +import java.awt.MenuItem; + import javax.swing.JTextField; import javax.swing.JTextArea; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Dialog.ModalExclusionType; import java.awt.Dialog.ModalityType; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; public class SimpleScriptEditor extends JDialog { @@ -56,13 +66,13 @@ public class SimpleScriptEditor extends JDialog { private JMappedTable mtScriptElements; private JTextField tfName; private JTextArea taDescription; + private JScrollPane spElementTable; /** * Create the dialog. */ public SimpleScriptEditor() { setModalityType(ModalityType.APPLICATION_MODAL); - setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setBounds(100, 100, 921, 474); getContentPane().setLayout(new BorderLayout()); @@ -74,6 +84,77 @@ public class SimpleScriptEditor extends JDialog { gbl_contentPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; gbl_contentPanel.rowWeights = new double[]{0.0, 1.0, 1.0, Double.MIN_VALUE}; contentPanel.setLayout(gbl_contentPanel); + + MouseAdapter popupAdapter = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + checkPopup(e); + } + @Override + public void mousePressed(MouseEvent e) { + if ((e.getComponent() == spElementTable)){ + mtScriptElements.clearSelection(); + } + checkPopup(e); + } + @Override + public void mouseReleased(MouseEvent e) { + checkPopup(e); + } + + private void checkPopup(MouseEvent e){ + if (e.isPopupTrigger()){ + JPopupMenu popupMenu = new JPopupMenu(); + + JMenuItem miAdd = new JMenuItem("1x neu"); + miAdd.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + SimpleScriptElement sse = (SimpleScriptElement)mtScriptElements.getTableMapper().getSelectedRow(); + mtScriptElements.getTableMapper().addRow(new SimpleScriptElement(),sse); + } + }); + popupMenu.add(miAdd); + + JMenuItem miAdd5 = new JMenuItem("5x neu"); + miAdd5.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + SimpleScriptElement sse = (SimpleScriptElement)mtScriptElements.getTableMapper().getSelectedRow(); + + mtScriptElements.getTableMapper().addRows(new SimpleScriptElement[]{ + new SimpleScriptElement(), + new SimpleScriptElement(), + new SimpleScriptElement(), + new SimpleScriptElement(), + new SimpleScriptElement() + }, sse); + } + }); + popupMenu.add(miAdd5); + + SimpleScriptElement sse = (SimpleScriptElement)mtScriptElements.getTableMapper().getSelectedRow(); + if (sse != null){ + JMenuItem miRemove = new JMenuItem("Entfernen"); + miRemove.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + SimpleScriptElement[] selected = mtScriptElements.getTableMapper().getSelectedRows(new SimpleScriptElement[0]); + for (SimpleScriptElement se: selected){ + mtScriptElements.getTableMapper().removeRow(se); + } + } + }); + popupMenu.add(miRemove); + } + + popupMenu.show(e.getComponent(), e.getX(), e.getY()); + } + } + + }; + { JLabel lblBezeichnung = new JLabel("Bezeichnung:"); GridBagConstraints gbc_lblBezeichnung = new GridBagConstraints(); @@ -115,16 +196,18 @@ public class SimpleScriptEditor extends JDialog { contentPanel.add(taDescription, gbc_taDescription); } { - JScrollPane scrollPane = new JScrollPane(); - GridBagConstraints gbc_scrollPane = new GridBagConstraints(); - gbc_scrollPane.gridwidth = 2; - gbc_scrollPane.fill = GridBagConstraints.BOTH; - gbc_scrollPane.gridx = 0; - gbc_scrollPane.gridy = 2; - contentPanel.add(scrollPane, gbc_scrollPane); + spElementTable = new JScrollPane(); + GridBagConstraints gbc_spElementTable = new GridBagConstraints(); + gbc_spElementTable.gridwidth = 2; + gbc_spElementTable.fill = GridBagConstraints.BOTH; + gbc_spElementTable.gridx = 0; + gbc_spElementTable.gridy = 2; + spElementTable.addMouseListener(popupAdapter); + contentPanel.add(spElementTable, gbc_spElementTable); { mtScriptElements = new JMappedTable(SimpleScriptElement.class); - scrollPane.setViewportView(mtScriptElements); + mtScriptElements.addMouseListener(popupAdapter); + spElementTable.setViewportView(mtScriptElements); } } { @@ -153,16 +236,38 @@ public class SimpleScriptEditor extends JDialog { buttonPane.add(cancelButton); } } + + + mtScriptElements.addTableMapperListener(new TableMapperListener() { + + @Override + public boolean editorRequest(TableMapper tableMapper, Object row) { + SimpleScriptElement e = (SimpleScriptElement)row; + if (e != null){ + if (SimpleScriptElementEditor.show(SimpleScriptEditor.this, e)){ + mtScriptElements.repaint(); + } + } + return true; + } + + @Override + public void ValueChanged(int row, int column) { + // TODO Auto-generated method stub + + } + }); + mtScriptElements.getTableMapper().setEditorEnabled(true); + initialize(); - } private void accept(){ simpleScript.setName(tfName.getText()); simpleScript.setDescription(taDescription.getText()); - + simpleScript.setSimpleScriptElements(mtScriptElements.getTableMapper().getRows(SimpleScriptElement.class).toArray(new SimpleScriptElement[0])); accepted = true; setVisible(false); @@ -182,8 +287,7 @@ public class SimpleScriptEditor extends JDialog { tfName.setText(simpleScript.getName()); taDescription.setText(simpleScript.getDescription()); - mtScriptElements.getTableMapper().setRows(simpleScript.getSimpleScriptElements().toArray(new SimpleScriptElement[0])); - + mtScriptElements.getTableMapper().setRows(new ArrayList(simpleScript.getSimpleScriptElements())); mtScriptElements.getTableMapper().setSortingEnabled(false); } diff --git a/src/org/hwo/pulscounter/ui/SimpleScriptElementEditor.java b/src/org/hwo/pulscounter/ui/SimpleScriptElementEditor.java index e81c789..1db90a5 100644 --- a/src/org/hwo/pulscounter/ui/SimpleScriptElementEditor.java +++ b/src/org/hwo/pulscounter/ui/SimpleScriptElementEditor.java @@ -9,46 +9,215 @@ import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; +import org.hwo.pulscounter.simplescript.SimpleScript; +import org.hwo.pulscounter.simplescript.SimpleScript.ScriptCondition; +import org.hwo.pulscounter.simplescript.SimpleScript.ScriptOperation; import org.hwo.pulscounter.simplescript.SimpleScript.SimpleScriptElement; +import org.hwo.ui.JComboBoxEx; + import java.awt.Dialog.ModalExclusionType; import java.awt.Dialog.ModalityType; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Insets; +import javax.swing.border.TitledBorder; +import javax.swing.border.LineBorder; +import java.awt.Color; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JComboBox; +import java.awt.Font; public class SimpleScriptElementEditor extends JDialog { public static boolean show(Component parent,SimpleScriptElement simpleScriptElement){ - return false; + SimpleScriptElementEditor editor = new SimpleScriptElementEditor(); + if (parent != null){ + editor.setLocationRelativeTo(parent); + } + editor.setSimpleScriptElement(simpleScriptElement); + editor.setVisible(true); + return editor.isAccepted(); } private SimpleScriptElement simpleScriptElement; private boolean accepted; private final JPanel contentPanel = new JPanel(); + private SimpleScriptAddressEditor ssaA; + private SimpleScriptAddressEditor ssaB; + private SimpleScriptAddressEditor ssaZ; + private JComboBoxEx cbCondition; + private JComboBoxEx cbOperation; /** * Create the dialog. */ public SimpleScriptElementEditor() { + setResizable(false); + setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setTitle("Skriptelement bearbeiten"); setModalityType(ModalityType.APPLICATION_MODAL); setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); - setBounds(100, 100, 519, 370); + setBounds(100, 100, 519, 350); getContentPane().setLayout(new BorderLayout()); - contentPanel.setLayout(new FlowLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); + GridBagLayout gbl_contentPanel = new GridBagLayout(); + gbl_contentPanel.columnWidths = new int[]{0, 0, 0}; + gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0}; + gbl_contentPanel.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE}; + gbl_contentPanel.rowWeights = new double[]{0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE}; + contentPanel.setLayout(gbl_contentPanel); + { + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), "Eingangswert A", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51))); + GridBagConstraints gbc_panel = new GridBagConstraints(); + gbc_panel.insets = new Insets(0, 0, 5, 5); + gbc_panel.fill = GridBagConstraints.BOTH; + gbc_panel.gridx = 0; + gbc_panel.gridy = 0; + contentPanel.add(panel, gbc_panel); + GridBagLayout gbl_panel = new GridBagLayout(); + gbl_panel.columnWidths = new int[]{0, 0}; + gbl_panel.rowHeights = new int[]{0, 0}; + gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE}; + panel.setLayout(gbl_panel); + { + ssaA = new SimpleScriptAddressEditor(); + GridBagConstraints gbc_ssaA = new GridBagConstraints(); + gbc_ssaA.fill = GridBagConstraints.BOTH; + gbc_ssaA.gridx = 0; + gbc_ssaA.gridy = 0; + panel.add(ssaA, gbc_ssaA); + } + } + { + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), "Eingangswert B", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51))); + GridBagConstraints gbc_panel = new GridBagConstraints(); + gbc_panel.insets = new Insets(0, 0, 5, 0); + gbc_panel.fill = GridBagConstraints.BOTH; + gbc_panel.gridx = 1; + gbc_panel.gridy = 0; + contentPanel.add(panel, gbc_panel); + GridBagLayout gbl_panel = new GridBagLayout(); + gbl_panel.columnWidths = new int[]{0, 0}; + gbl_panel.rowHeights = new int[]{0, 0}; + gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE}; + panel.setLayout(gbl_panel); + { + ssaB = new SimpleScriptAddressEditor(); + GridBagConstraints gbc_ssaB = new GridBagConstraints(); + gbc_ssaB.fill = GridBagConstraints.BOTH; + gbc_ssaB.gridx = 0; + gbc_ssaB.gridy = 0; + panel.add(ssaB, gbc_ssaB); + } + } + { + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), "Bedingung", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51))); + GridBagConstraints gbc_panel = new GridBagConstraints(); + gbc_panel.insets = new Insets(0, 0, 5, 0); + gbc_panel.gridwidth = 2; + gbc_panel.fill = GridBagConstraints.BOTH; + gbc_panel.gridx = 0; + gbc_panel.gridy = 1; + contentPanel.add(panel, gbc_panel); + GridBagLayout gbl_panel = new GridBagLayout(); + gbl_panel.columnWidths = new int[]{0, 0}; + gbl_panel.rowHeights = new int[]{0, 0}; + gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE}; + panel.setLayout(gbl_panel); + { + cbCondition = new JComboBoxEx(); + cbCondition.setFont(new Font("Courier", Font.BOLD, 14)); + GridBagConstraints gbc_cbCondition = new GridBagConstraints(); + gbc_cbCondition.fill = GridBagConstraints.HORIZONTAL; + gbc_cbCondition.gridx = 0; + gbc_cbCondition.gridy = 0; + cbCondition.setItems(SimpleScript.ScriptCondition.values()); + panel.add(cbCondition, gbc_cbCondition); + } + } + { + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), "Operation", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51))); + GridBagConstraints gbc_panel = new GridBagConstraints(); + gbc_panel.insets = new Insets(0, 0, 5, 0); + gbc_panel.gridwidth = 2; + gbc_panel.fill = GridBagConstraints.BOTH; + gbc_panel.gridx = 0; + gbc_panel.gridy = 2; + contentPanel.add(panel, gbc_panel); + GridBagLayout gbl_panel = new GridBagLayout(); + gbl_panel.columnWidths = new int[]{0, 0}; + gbl_panel.rowHeights = new int[]{0, 0}; + gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE}; + panel.setLayout(gbl_panel); + { + cbOperation = new JComboBoxEx(); + cbOperation.setFont(new Font("Courier", Font.BOLD, 14)); + GridBagConstraints gbc_cbOperation = new GridBagConstraints(); + gbc_cbOperation.fill = GridBagConstraints.HORIZONTAL; + gbc_cbOperation.gridx = 0; + gbc_cbOperation.gridy = 0; + cbOperation.setItems(SimpleScript.ScriptOperation.values()); + panel.add(cbOperation, gbc_cbOperation); + } + } + { + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), "Ausgangswert Z", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51))); + GridBagConstraints gbc_panel = new GridBagConstraints(); + gbc_panel.insets = new Insets(0, 0, 0, 5); + gbc_panel.fill = GridBagConstraints.BOTH; + gbc_panel.gridx = 0; + gbc_panel.gridy = 3; + contentPanel.add(panel, gbc_panel); + GridBagLayout gbl_panel = new GridBagLayout(); + gbl_panel.columnWidths = new int[]{0, 0}; + gbl_panel.rowHeights = new int[]{0, 0}; + gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE}; + panel.setLayout(gbl_panel); + { + ssaZ = new SimpleScriptAddressEditor(); + GridBagConstraints gbc_ssaZ = new GridBagConstraints(); + gbc_ssaZ.fill = GridBagConstraints.BOTH; + gbc_ssaZ.gridx = 0; + gbc_ssaZ.gridy = 0; + panel.add(ssaZ, gbc_ssaZ); + } + } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton okButton = new JButton("OK"); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + accept(); + } + }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + cancel(); + } + }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } @@ -60,13 +229,23 @@ public class SimpleScriptElementEditor extends JDialog { } public void setSimpleScriptElement(SimpleScriptElement simpleScriptElement) { this.simpleScriptElement = simpleScriptElement; + + ssaA.setAddress( simpleScriptElement.getA() ); + ssaB.setAddress( simpleScriptElement.getB() ); + ssaZ.setAddress( simpleScriptElement.getZ() ); + cbCondition.setSelectedItem(simpleScriptElement.getScriptCondition()); + cbOperation.setSelectedItem(simpleScriptElement.getScriptOperation()); } private void accept(){ + + simpleScriptElement.setA(ssaA.getAddress()); + simpleScriptElement.setB(ssaB.getAddress()); + simpleScriptElement.setZ(ssaZ.getAddress()); + simpleScriptElement.setScriptOperation((ScriptOperation)cbOperation.getSelectedItem()); + simpleScriptElement.setScriptCondition((ScriptCondition)cbCondition.getSelectedItem()); + accepted = true; - - - setVisible(false); } private void cancel(){ diff --git a/src/org/hwo/pulscounter/ui/SimpleScriptSetup.java b/src/org/hwo/pulscounter/ui/SimpleScriptSetup.java index b7416dc..41adb6e 100644 --- a/src/org/hwo/pulscounter/ui/SimpleScriptSetup.java +++ b/src/org/hwo/pulscounter/ui/SimpleScriptSetup.java @@ -6,6 +6,7 @@ import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.event.ListSelectionEvent; @@ -16,18 +17,25 @@ import java.awt.GridBagConstraints; import java.awt.Insets; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import javax.swing.border.BevelBorder; import javax.swing.JButton; +import javax.swing.JDialog; + import java.awt.FlowLayout; import org.hwo.models.TableMapper.TableMapper; import org.hwo.models.TableMapper.TableMapperListener; import org.hwo.pulscounter.PulsCounterApplication; +import org.hwo.pulscounter.device.IDeviceConnector; import org.hwo.pulscounter.simplescript.SimpleScript; import org.hwo.ui.JMappedTable; +import org.hwo.ui.JObjectSelector; + import javax.swing.JScrollPane; import java.awt.event.ActionListener; +import java.text.DateFormat; import java.awt.event.ActionEvent; import static org.hwo.logging.Logging.*; @@ -58,8 +66,10 @@ import org.hwo.ui.JMappedTable; import javax.swing.JScrollPane; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; +import java.awt.Dialog.ModalExclusionType; +import java.awt.Dialog.ModalityType; -public class SimpleScriptSetup extends JFrame { +public class SimpleScriptSetup extends JDialog { private JPanel contentPane; private JMappedTable scriptTable; @@ -68,9 +78,12 @@ public class SimpleScriptSetup extends JFrame { private JButton btnEntfernen; private JButton btnBearbeiten; private JButton btnNeu; + private JButton btnTransmit; + private JButton btnReceive; public SimpleScriptSetup() { setTitle("Formeln"); + setModalityType(ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 831, 406); contentPane = new JPanel(); @@ -103,6 +116,11 @@ public class SimpleScriptSetup extends JFrame { panel.add(btnNeu); btnBearbeiten = new JButton("bearbeiten..."); + btnBearbeiten.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + scriptTable.getTableMapper().openEditor(); + } + }); btnBearbeiten.setEnabled(false); panel.add(btnBearbeiten); @@ -117,6 +135,23 @@ public class SimpleScriptSetup extends JFrame { }); panel.add(btnEntfernen); + btnTransmit = new JButton("auf Zähler übertragen...."); + btnTransmit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + transmit(); + } + }); + btnTransmit.setEnabled(false); + panel.add(btnTransmit); + + btnReceive = new JButton("von Zähler holen...."); + btnReceive.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + receive(); + } + }); + panel.add(btnReceive); + JScrollPane scrollPane = new JScrollPane(); GridBagConstraints gbc_scrollPane = new GridBagConstraints(); gbc_scrollPane.fill = GridBagConstraints.BOTH; @@ -163,9 +198,11 @@ public class SimpleScriptSetup extends JFrame { if (scriptTable.getTableMapper().getSelectedRow() == null){ btnBearbeiten.setEnabled(false); btnEntfernen.setEnabled(false); + btnTransmit.setEnabled(false); } else { btnBearbeiten.setEnabled(true); btnEntfernen.setEnabled(true); + btnTransmit.setEnabled(true); } } }); @@ -177,6 +214,7 @@ public class SimpleScriptSetup extends JFrame { if (SimpleScriptEditor.show(SimpleScriptSetup.this,(SimpleScript)row)){ log(INFO,"store SimpleScript"); PulsCounterApplication.getApplication().getDatabase().storeSimpleScript((SimpleScript)row); + scriptTable.repaint(); } return true; } @@ -185,11 +223,54 @@ public class SimpleScriptSetup extends JFrame { @Override public void ValueChanged(int row, int column) { - // TODO Auto-generated method stub } }); } - + + private void transmit(){ + IDeviceConnector[] connectors = PulsCounterApplication.getApplication().getInterfaces().toArray(new IDeviceConnector[0]); + IDeviceConnector connector = JObjectSelector.execute( + connectors, + this, + "Schnittstelle wählen...", + "Wählen Sie die Schnittstelle über die das Skript übertragen werden soll." + ); + + if (connector != null){ + log(INFO,"Übertrage Skript an Synololog an Schnittstelle %s", connector); + + connector.setSimpleScript(((SimpleScript)scriptTable.getTableMapper().getSelectedRow()).getSimpleScriptElementsAsInt()); + + } + } + private void receive(){ + IDeviceConnector[] connectors = PulsCounterApplication.getApplication().getInterfaces().toArray(new IDeviceConnector[0]); + IDeviceConnector connector = JObjectSelector.execute( + connectors, + this, + "Schnittstelle wählen...", + "Wählen Sie die Schnittstelle über die das Skript empfangen werden soll." + ); + + if (connector != null){ + log(INFO,"Übertrage Skript von Synololog an Schnittstelle %s", connector); + + int[] scriptElements = connector.getSimpleScript(); + + if (scriptElements == null){ + JOptionPane.showMessageDialog(this, "Es konnte kein Skript vom gerät empfangen werden."); + } else { + SimpleScript simpleScript = new SimpleScript(); + simpleScript.setSimpleScriptElements(scriptElements); + simpleScript.setName(String.format("Von Gerät %s geholt am %s", connector.getDeviceSerial(), DateFormat.getDateTimeInstance().format(new Date()))); + + scriptTable.getTableMapper().addRow(simpleScript); + PulsCounterApplication.getApplication().getDatabase().storeSimpleScript(simpleScript); + } + } + } + + } diff --git a/src/org/hwo/pulscounter/ui/SnapshotManager.java b/src/org/hwo/pulscounter/ui/SnapshotManager.java new file mode 100644 index 0000000..d7f94de --- /dev/null +++ b/src/org/hwo/pulscounter/ui/SnapshotManager.java @@ -0,0 +1,358 @@ +package org.hwo.pulscounter.ui; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.FlowLayout; + +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.border.EmptyBorder; +import java.awt.Dialog.ModalExclusionType; +import java.awt.Dialog.ModalityType; +import java.awt.GridBagLayout; +import javax.swing.JSplitPane; +import java.awt.GridBagConstraints; + +import org.hwo.ObjectTable; +import org.hwo.pulscounter.PulsCounterApplication; +import org.hwo.pulscounter.SnapShot; +import org.hwo.ui.JMappedTable; +import org.hwo.ui.MousePopupListener; +import org.hwo.ui.diagram.LinePlotPainter; +import org.hwo.ui.diagram.SimplePlotProvider; + +import javax.swing.JScrollPane; +import javax.swing.JList; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.ListSelectionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.ScrollPaneConstants; +import javax.swing.ListSelectionModel; +import java.awt.Insets; +import javax.swing.JTabbedPane; +import javax.swing.BoxLayout; +import org.hwo.ui.JDiagram; +import javax.swing.JCheckBox; +import java.awt.Dimension; + +public class SnapshotManager extends JDialog { + + public static Color[] plotColors = new Color[32]; + + public static void show(Component parent){ + + SnapshotManager sm = new SnapshotManager(); + if (parent != null) + { + sm.setLocationRelativeTo(parent); + } + sm.setVisible(true); + + } + + private final JPanel contentPanel = new JPanel(); + private JList lDevices; + private JMappedTable mtSnapshots; + private JScrollPane scrollPane_1; + private JDiagram diaSnapshots; + private JCheckBox cbDifferenzen; + private JPanel paIndex; + + /** + * Create the dialog. + */ + public SnapshotManager() { + setModal(true); + setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + setModalityType(ModalityType.APPLICATION_MODAL); + setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); + setBounds(100, 100, 991, 547); + getContentPane().setLayout(new BorderLayout()); + contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + getContentPane().add(contentPanel, BorderLayout.CENTER); + GridBagLayout gbl_contentPanel = new GridBagLayout(); + gbl_contentPanel.columnWidths = new int[]{0, 0}; + gbl_contentPanel.rowHeights = new int[]{0, 0}; + gbl_contentPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_contentPanel.rowWeights = new double[]{1.0, Double.MIN_VALUE}; + contentPanel.setLayout(gbl_contentPanel); + { + JSplitPane splitPane = new JSplitPane(); + splitPane.setResizeWeight(0.2); + GridBagConstraints gbc_splitPane = new GridBagConstraints(); + gbc_splitPane.fill = GridBagConstraints.BOTH; + gbc_splitPane.gridx = 0; + gbc_splitPane.gridy = 0; + contentPanel.add(splitPane, gbc_splitPane); + { + JPanel panel = new JPanel(); + splitPane.setLeftComponent(panel); + GridBagLayout gbl_panel = new GridBagLayout(); + gbl_panel.columnWidths = new int[]{0, 0}; + gbl_panel.rowHeights = new int[]{0, 0}; + gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE}; + panel.setLayout(gbl_panel); + { + JScrollPane scrollPane = new JScrollPane(); + GridBagConstraints gbc_scrollPane = new GridBagConstraints(); + gbc_scrollPane.fill = GridBagConstraints.BOTH; + gbc_scrollPane.gridx = 0; + gbc_scrollPane.gridy = 0; + panel.add(scrollPane, gbc_scrollPane); + { + lDevices = new JList(); + lDevices.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + showSnapshots(); + } + }); + scrollPane.setViewportView(lDevices); + } + } + } + { + JPanel panel = new JPanel(); + splitPane.setRightComponent(panel); + GridBagLayout gbl_panel = new GridBagLayout(); + gbl_panel.columnWidths = new int[]{0, 0}; + gbl_panel.rowHeights = new int[] {0}; + gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_panel.rowWeights = new double[]{1.0}; + panel.setLayout(gbl_panel); + { + JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); + GridBagConstraints gbc_tabbedPane = new GridBagConstraints(); + gbc_tabbedPane.fill = GridBagConstraints.BOTH; + gbc_tabbedPane.gridx = 0; + gbc_tabbedPane.gridy = 0; + panel.add(tabbedPane, gbc_tabbedPane); + { + JPanel panel_1 = new JPanel(); + tabbedPane.addTab("Tabelle", null, panel_1, null); + panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS)); + { + scrollPane_1 = new JScrollPane(); + panel_1.add(scrollPane_1); + scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); + scrollPane_1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + { + mtSnapshots = new JMappedTable(SnapShot.class); + mtSnapshots.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + mtSnapshots.setFillsViewportHeight(true); + mtSnapshots.setColumnSelectionAllowed(true); + scrollPane_1.setViewportView(mtSnapshots); + } + } + } + { + JPanel panel_1 = new JPanel(); + tabbedPane.addTab("Diagramm", null, panel_1, null); + tabbedPane.setBackgroundAt(1, Color.WHITE); + panel_1.setLayout(new BorderLayout(0, 0)); + { + diaSnapshots = new JDiagram(); + diaSnapshots.setBackground(Color.WHITE); + diaSnapshots.setPreferLabelHints(true); + diaSnapshots.setDrawVerticalGrid(true); + diaSnapshots.setAutoScale(true); + panel_1.add(diaSnapshots); + } + { + JPanel panel_2 = new JPanel(); + panel_1.add(panel_2, BorderLayout.NORTH); + GridBagLayout gbl_panel_2 = new GridBagLayout(); + gbl_panel_2.columnWidths = new int[]{0, 0}; + gbl_panel_2.rowHeights = new int[]{0, 0}; + gbl_panel_2.columnWeights = new double[]{0.0, Double.MIN_VALUE}; + gbl_panel_2.rowWeights = new double[]{0.0, Double.MIN_VALUE}; + panel_2.setLayout(gbl_panel_2); + { + cbDifferenzen = new JCheckBox("Differenzen"); + cbDifferenzen.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + updateDiagram(); + } + }); + GridBagConstraints gbc_cbDifferenzen = new GridBagConstraints(); + gbc_cbDifferenzen.gridx = 0; + gbc_cbDifferenzen.gridy = 0; + panel_2.add(cbDifferenzen, gbc_cbDifferenzen); + } + } + { + paIndex = new JPanel(); + paIndex.setBackground(Color.WHITE); + paIndex.setPreferredSize(new Dimension(80, 10)); + panel_1.add(paIndex, BorderLayout.EAST); + paIndex.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5)); + } + } + } + } + } + { + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); + getContentPane().add(buttonPane, BorderLayout.SOUTH); + { + JButton cancelButton = new JButton("schliessen"); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + setVisible(false); + } + }); + cancelButton.setActionCommand("Cancel"); + buttonPane.add(cancelButton); + } + } + + initialize(); + } + + private void initialize(){ + Integer[] deviceSerials = PulsCounterApplication.getApplication().getDatabase().getKnownDevices(); + DefaultListModel lm = new DefaultListModel<>(); + + for (Integer serial: deviceSerials){ + lm.addElement(serial); + } + + lDevices.setModel(lm); + + mtSnapshots.getTableMapper().setReadOnly(true); + mtSnapshots.getTableMapper().addListSelectionListener(new ListSelectionListener() { + + @Override + public void valueChanged(ListSelectionEvent e) { + updateDiagram(); + } + }); + + for (int i=0;i<32;i++){ + JLabel l = new JLabel(String.format("#%02d", i)); + l.setForeground(plotColors[i]); + + paIndex.add(l); + } + + mtSnapshots.addMouseListener(new MousePopupListener() { + + @Override + public void popupTriggered(int x, int y) { + SnapShot[] selRows = mtSnapshots.getTableMapper().getSelectedRows(new SnapShot[0]); + + if ((selRows != null)&&(selRows.length>0)){ + JPopupMenu popupMenu = new JPopupMenu(); + JMenuItem mi = new JMenuItem("Entfernen..."); + mi.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + if (JOptionPane.showConfirmDialog(mtSnapshots, "Sollen die markierten Snapshots wirklich gelöscht werden?","Aufzeichnungen entfernen",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){ + for (SnapShot ss: selRows){ + mtSnapshots.getTableMapper().removeRow(ss); + } + mtSnapshots.repaint(); + } + } + }); + popupMenu.add(mi); + + popupMenu.show(mtSnapshots, x, y); + + } + + + } + }); + } + + private void showSnapshots(){ + + Integer deviceSerial = (Integer)lDevices.getSelectedValue(); + if (deviceSerial != null){ + SnapShot[] snapshots = PulsCounterApplication.getApplication().getDatabase().loadSnapshots(0, deviceSerial); + mtSnapshots.getTableMapper().setRows(snapshots); + } else { + mtSnapshots.getTableMapper().clear(); + } + updateDiagram(); + } + + private void updateDiagram(){ + System.gc(); + + SnapShot[] rows = mtSnapshots.getTableMapper().getSelectedRows(new SnapShot[0]); + + if ((rows == null)||(rows.length==0)){ + rows = mtSnapshots.getTableMapper().getRows(SnapShot.class).toArray(new SnapShot[0]); + } + + int plotLength = rows.length; + + if (cbDifferenzen.isSelected()){ + plotLength--; + } + + if (plotLength > 1024) + plotLength = 1024; + + SimplePlotProvider pp = new SimplePlotProvider(32, plotLength); + diaSnapshots.setPlotProvider(pp); + + for (int p=0;p<32;p++){ + Float[] v = new Float[ plotLength ]; + + for (int i=0;i