diff --git a/.classpath b/.classpath index 47daea1..34fa454 100644 --- a/.classpath +++ b/.classpath @@ -3,9 +3,9 @@ - + diff --git a/.gitignore b/.gitignore index 06a51e8..327c612 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ chnames.prop *.dat *.log *.old +*.cfg diff --git a/postgresql-9.1-901.jdbc4.jar b/postgresql-9.1-901.jdbc4.jar deleted file mode 100644 index 203d5a1..0000000 Binary files a/postgresql-9.1-901.jdbc4.jar and /dev/null differ diff --git a/src/org/hwo/pulscounter/Application.java b/src/org/hwo/pulscounter/Application.java new file mode 100644 index 0000000..a10982c --- /dev/null +++ b/src/org/hwo/pulscounter/Application.java @@ -0,0 +1,17 @@ +package org.hwo.pulscounter; + +import static org.hwo.logging.Logging.log; + +import org.hwo.logging.LogLevel; + +public class Application { + + public static void main(String[] args) { + PulsCounterApplication application = new PulsCounterApplication(args); + + log(LogLevel.INFO,"Application initialized, starting up user interface"); + + application.start(); + + } +} diff --git a/src/org/hwo/pulscounter/ExportSetting.java b/src/org/hwo/pulscounter/ExportSetting.java index 2e330b5..b2dffeb 100644 --- a/src/org/hwo/pulscounter/ExportSetting.java +++ b/src/org/hwo/pulscounter/ExportSetting.java @@ -125,7 +125,7 @@ public class ExportSetting { } public void export(){ - SnapshotManager ssm = PulsCounter2Application.getApplication().getSnapshotManager(); + SnapshotManager ssm = PulsCounterApplication.getApplication().getSnapshotManager(); Hashtable hash = new Hashtable(); diff --git a/src/org/hwo/pulscounter/PulsCounter2Application.java b/src/org/hwo/pulscounter/PulsCounter2Application.java deleted file mode 100644 index ee1c938..0000000 --- a/src/org/hwo/pulscounter/PulsCounter2Application.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.hwo.pulscounter; - -import java.io.FileNotFoundException; -import java.util.LinkedList; -import java.util.List; -import java.util.Vector; -import java.util.prefs.BackingStoreException; -import java.util.prefs.Preferences; - -import org.hwo.configuration.ConfigurableObjects; -import org.hwo.io.SerialPort; -import org.hwo.io.NewSerialPort.NewSerialPort; -import org.hwo.servicelink.ServiceLink; -import org.hwo.servicelink.ServiceLinkListener; -import org.hwo.tasklet.TaskletManager; -import org.hwo.pulscounter.SnapshotManager.Notification; -import org.hwo.pulscounter.ui.AppSettingsListener; -import org.hwo.scheduler.Scheduler; - -public class PulsCounter2Application implements ServiceLinkListener{ - - static PulsCounter2Application _application; - public static PulsCounter2Application getApplication(){ - if (_application == null) - _application = new PulsCounter2Application(); - - return _application; - } - - private NewSerialPort serialPort; - private ServiceLink serviceLink; - - private List appSettingsListeners; - private List applicationListeners; - - private boolean snapshotLock; - - private Vector unseenMessages; - - private SnapshotManager snapshotManager; - - private List exportSettings; - - private Scheduler scheduler; - - public PulsCounter2Application() { - appSettingsListeners = new LinkedList(); - applicationListeners = new LinkedList(); - unseenMessages = new Vector(); - exportSettings = new LinkedList(); - scheduler = new Scheduler(); - - loadPrefs(); - - try { - snapshotManager = new SnapshotManager(); - snapshotManager.notify(Notification.INITIALIZE); - - } catch (FileNotFoundException e){ - e.printStackTrace(); - } - - } - - - - public void addAppSettingsListener(AppSettingsListener listener){ - appSettingsListeners.add(listener); - } - public void removeAppSettingsListener(AppSettingsListener listener){ - appSettingsListeners.remove(listener); - } - - public void addPulsCounterApplicationListener(PulsCounterApplicationListener listener){ - applicationListeners.add(listener); - } - public void removePulsCounterApplicationListener(PulsCounterApplicationListener listener){ - applicationListeners.remove(listener); - } - - - public void fireServiceLinkChanged(){ - for (AppSettingsListener l: appSettingsListeners){ - l.ServiceLinkChanged(serviceLink); - } - } - - public void fireSerialPortChanged(){ - for (PulsCounterApplicationListener listener: applicationListeners){ - listener.serialPortChanged(); - } - } - - public void fireConnectionStateChanged(){ - fireConnectionStateChanged(getServiceLink().isOpen()); - } - - public void fireConnectionStateChanged(Boolean connected){ - for (PulsCounterApplicationListener listener: applicationListeners){ - listener.connectionStateChanged(connected); - } - } - - public void message(String message){ - - if (applicationListeners.size() == 0){ - unseenMessages.addElement(message); - } else { - while (!unseenMessages.isEmpty()){ - String msg = unseenMessages.remove(0); - for (PulsCounterApplicationListener listener: applicationListeners){ - listener.messageArrived(msg); - } - } - - for (PulsCounterApplicationListener listener: applicationListeners){ - listener.messageArrived(message); - } - }; - } - - public synchronized NewSerialPort getSerialPort() { - if (serialPort == null){ - serialPort = new NewSerialPort("COM1:"); - } - return serialPort; - } - public synchronized void setSerialPort(NewSerialPort serialPort) { - if (serviceLink != null){ - serviceLink.close(); - serviceLink = null; - } - this.serialPort = serialPort; - - getServiceLink(); - - fireServiceLinkChanged(); - fireSerialPortChanged(); - } - - public synchronized ServiceLink getServiceLink() { - if (serviceLink == null){ - serviceLink = new ServiceLink(getSerialPort()); - serviceLink.getSerialPort().setTimeOut(200); - serviceLink.addServiceLinkListener(this); - } - return serviceLink; - } - public synchronized void setServiceLink(ServiceLink serviceLink) { - if (serviceLink != null){ - serviceLink.close(); - } - this.serviceLink = serviceLink; - - fireServiceLinkChanged(); - } - - private Preferences getPreferencesNode(){ - return Preferences.userNodeForPackage(getClass()); - } - - public void savePrefs(){ - Preferences prefs = getPreferencesNode(); - - if (serialPort != null) - prefs.put("io.port", serialPort.getPortName()); - - System.out.println(String.format("savePrefs(): %d exportSettings werden gesichert.", exportSettings.size())); - if (exportSettings.size()>0) - { - for (int n=0;n getExportSettings() { - return exportSettings; - } - - public void shutdown(){ - System.err.println("Shutting down..."); - this.scheduler.shutdown(); - this.snapshotManager.doShutdown(); - TaskletManager.instance().shutdown(); - - this.getServiceLink().close(); - } - - -} diff --git a/src/org/hwo/pulscounter/PulsCounterApplication.java b/src/org/hwo/pulscounter/PulsCounterApplication.java new file mode 100644 index 0000000..69c61da --- /dev/null +++ b/src/org/hwo/pulscounter/PulsCounterApplication.java @@ -0,0 +1,559 @@ +package org.hwo.pulscounter; + +import static org.hwo.logging.Logging.log; +import static org.hwo.logging.LogLevel.*; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.InvalidPropertiesFormatException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; +import java.util.Vector; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; + +import org.hwo.StringHelper; +import org.hwo.configuration.ConfigurableObjects; +import org.hwo.io.NewSerialPort.NewSerialPort; +import org.hwo.platform.Platform; +import org.hwo.servicelink.ServiceLink; +import org.hwo.servicelink.ServiceLinkListener; +import org.hwo.pulscounter.device.IDeviceConnector; +import org.hwo.pulscounter.device.ServiceLinkDeviceConnector; +import org.hwo.pulscounter.ui.AppSettingsListener; +import org.hwo.pulscounter.ui.BatchRunner; +import org.hwo.pulscounter.ui.NewMainWindow; +import org.hwo.scheduler.Scheduler; + +public class PulsCounterApplication implements ServiceLinkListener{ + + static PulsCounterApplication _application; + public static PulsCounterApplication getApplication(){ + if (_application == null) + _application = new PulsCounterApplication(null); + + return _application; + } + + private Properties applicationConfiguration; + private List deviceConnectors; + + private Object uiSynchronization; + private boolean uiIsFinished; + private boolean shouldSaveConfiguration; + + private List + applicationListeners; + + private Vector unseenMessages; + + private List> + interfaceClasses; + private List interfaces; + + + + + + private NewSerialPort serialPort; + private ServiceLink serviceLink; + + private List appSettingsListeners; + + private boolean snapshotLock; + + + private SnapshotManager snapshotManager; + + private List exportSettings; + + private Scheduler scheduler; + + private String[] channelDescriptions; + + public PulsCounterApplication(String[] args) { + /* Initialize Logging Framework */ + logStartup(); + + /* Check... */ + if (_application != null){ + throw new InstantiationError("Only one Instance of PulsCounterApplication can exist!"); + } else { + _application = this; + } + + /* Initialize fields... */ + uiIsFinished = false; + uiSynchronization = new Object(); + deviceConnectors = new ArrayList<>(); + applicationListeners = new LinkedList(); + unseenMessages = new Vector(); + + interfaceClasses = new ArrayList<>(); + interfaces = new ArrayList<>(); + + /* Prepare for Startup */ + loadApplicationConfiguration(); + + /* Parse Command Line Arguments */ + Iterator options = Arrays.asList(args).iterator(); + + while (options.hasNext()){ + String option = options.next(); + + switch (option){ + case "--gui": + if (!options.hasNext()){ + log(FATAL,"Argument to --gui is missing"); + throw new IllegalArgumentException("Argument to --gui is missing"); + } else { + applicationConfiguration.setProperty("ui.class", options.next()); + } + break; + case "--batch": + case "-B": + applicationConfiguration.setProperty("ui.class", BatchRunner.class.getCanonicalName()); + break; + case "-G": + applicationConfiguration.setProperty("ui.class", NewMainWindow.class.getCanonicalName()); + break; + default: + log(WARN,"Unknown command line parameter: %s", option); + } + } + + + + + /* Old stuff... */ + // this.initialize(); + } + + + private void loadApplicationConfiguration(){ + applicationConfiguration = new Properties(); + + /* Initialize default configuration */ + applicationConfiguration.setProperty("ui.class", NewMainWindow.class.getCanonicalName()); + applicationConfiguration.setProperty("interface.classes", StringHelper.join(new String[]{ServiceLinkDeviceConnector.class.getCanonicalName() }, ",")); + + + try { + /* Try to load configuration from file */ + FileInputStream fis = new FileInputStream("synololog.cfg"); + applicationConfiguration.loadFromXML(fis); + fis.close(); + + } catch (InvalidPropertiesFormatException e) { + log(WARN,"synololog.cfg is misformated"); + } catch (FileNotFoundException e) { + log(WARN,"synololog.cfg not found"); + } catch (IOException e) { + log(ERROR,"I/O Error reading synololog.cfg"); + } + + } + + public Properties getApplicationConfiguration(){ + return this.applicationConfiguration; + } + + private static void logStartup(){ + log("Synololog Application Startup"); + + log("JAVA Environment: %s (%s)", System.getProperty("java.version"), + System.getProperty("java.vendor")); + + log("Operating System: %s [%s] %s", System.getProperty("os.name"), + System.getProperty("os.arch"), + System.getProperty("os.version")); + + log("User Environment: %s (%s) (CWD:%s)", System.getProperty("user.name"), + System.getProperty("user.home"), + System.getProperty("user.dir")); + + log("Hostname: %s",Platform.getHostName()); + log("OS Search Path: %s", System.getenv("PATH")); + } + + + public void start(){ + + initialize(); + + String uiClassName = applicationConfiguration.getProperty("ui.class"); + + try { + Class uiClazz = PulsCounterApplication.class.getClassLoader().loadClass(uiClassName); + + Constructor constructor = uiClazz.getConstructor(PulsCounterApplication.class); + Object ui = (Object) constructor.newInstance(this); + + } catch (ClassNotFoundException e) { + log(FATAL,"user interface class could not be loaded [%s] %s",uiClassName,e.getMessage()); + } catch (NoSuchMethodException e) { + log(FATAL,"user interface class misses valid constructor [%s] %s",uiClassName,e.getMessage()); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (Exception e) { + log(FATAL,"user interface class could not be instantiated. [%s] %s",uiClassName,e.getMessage()); + e.printStackTrace(); + } + + waitUiFinished(); + + try { + shutdown(); + + } catch (Exception e){ + log(e); + } + + } + + private void initialize(){ + + String[] interfaceClassNames = applicationConfiguration.getProperty("interface.classes").split(","); + for (String interfaceClassName: interfaceClassNames){ + + try { + + Class clazz = (Class)PulsCounterApplication.class.getClassLoader().loadClass(interfaceClassName); + interfaceClasses.add(clazz); + + } catch (ClassNotFoundException e) { + log(ERROR,"Interface class could not be loaded: %s",interfaceClassName); + } + + } + + Integer nIntf = Integer.parseInt(applicationConfiguration.getProperty("interfaces.n","0")); + for (int n=0;n clazz = getInterfaceClass(applicationConfiguration.getProperty(String.format("interfaces.%d.class",n))); + addInterface(clazz, applicationConfiguration.getProperty(String.format("interfaces.%d.settings",n))); + } + + } + + private void shutdown(){ + + log(INFO,"Application shutdown..."); + + + + if (shouldSaveConfiguration){ + + applicationConfiguration.setProperty("interfaces.n", Integer.toString(interfaces.size())); + for (int n=0;n> getInterfaceClasses(){ + return this.interfaceClasses; + } + + private Class getInterfaceClass(String className){ + for (Class c:interfaceClasses){ + if (c.getCanonicalName().equals(className)) + return c; + } + return null; + } + + /* Physical Interfaces */ + public List getInterfaces(){ + return this.interfaces; + } + public void addInterface(Class clazz,String connectionSettings){ + + try { + IDeviceConnector idc = clazz.newInstance(); + idc.setConnectionSettings(connectionSettings); + interfaces.add(idc); + fireinterfacesChanged(); + + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + } + public void removeInterface(IDeviceConnector intf){ + interfaces.remove(intf); + fireinterfacesChanged(); + } + + private void fireinterfacesChanged(){ + log(INFO,"interfaces changed"); + + for (PulsCounterApplicationListener l: applicationListeners){ + l.interfacesChanged(this); + } + } + + + + +/* ToDO: Upgrade the old stuff ... */ + +/* + private void initialize(){ + appSettingsListeners = new LinkedList(); + exportSettings = new LinkedList(); + scheduler = new Scheduler(); + + channelDescriptions = new String[32]; + + loadPrefs(); + + try { + snapshotManager = new SnapshotManager(); + snapshotManager.notify(Notification.INITIALIZE); + + } catch (FileNotFoundException e){ + e.printStackTrace(); + } + } + */ + + public void addAppSettingsListener(AppSettingsListener listener){ + appSettingsListeners.add(listener); + } + public void removeAppSettingsListener(AppSettingsListener listener){ + appSettingsListeners.remove(listener); + } + + public void addPulsCounterApplicationListener(PulsCounterApplicationListener listener){ + applicationListeners.add(listener); + } + public void removePulsCounterApplicationListener(PulsCounterApplicationListener listener){ + applicationListeners.remove(listener); + } + + + public void fireServiceLinkChanged(){ + for (AppSettingsListener l: appSettingsListeners){ + l.ServiceLinkChanged(serviceLink); + } + } + + public void fireSerialPortChanged(){ + for (PulsCounterApplicationListener listener: applicationListeners){ + listener.serialPortChanged(); + } + } + + public void fireConnectionStateChanged(){ + fireConnectionStateChanged(getServiceLink().isOpen()); + } + + public void fireConnectionStateChanged(Boolean connected){ + for (PulsCounterApplicationListener listener: applicationListeners){ + listener.connectionStateChanged(connected); + } + } + + public void message(String message){ + + if (applicationListeners.size() == 0){ + unseenMessages.addElement(message); + } else { + while (!unseenMessages.isEmpty()){ + String msg = unseenMessages.remove(0); + for (PulsCounterApplicationListener listener: applicationListeners){ + listener.messageArrived(msg); + } + } + + for (PulsCounterApplicationListener listener: applicationListeners){ + listener.messageArrived(message); + } + }; + } + + public synchronized NewSerialPort getSerialPort() { + if (serialPort == null){ + serialPort = new NewSerialPort("COM1:"); + } + return serialPort; + } + public synchronized void setSerialPort(NewSerialPort serialPort) { + if (serviceLink != null){ + serviceLink.close(); + serviceLink = null; + } + this.serialPort = serialPort; + + getServiceLink(); + + fireServiceLinkChanged(); + fireSerialPortChanged(); + } + + public synchronized ServiceLink getServiceLink() { + if (serviceLink == null){ + serviceLink = new ServiceLink(getSerialPort()); + serviceLink.getSerialPort().setTimeOut(200); + serviceLink.addServiceLinkListener(this); + } + return serviceLink; + } + public synchronized void setServiceLink(ServiceLink serviceLink) { + if (serviceLink != null){ + serviceLink.close(); + } + this.serviceLink = serviceLink; + + fireServiceLinkChanged(); + } + + private Preferences getPreferencesNode(){ + return Preferences.userNodeForPackage(getClass()); + } + + public void savePrefs(){ + Preferences prefs = getPreferencesNode(); + + if (serialPort != null) + prefs.put("io.port", getSerialPort().getPortName()); + + System.out.println(String.format("savePrefs(): %d exportSettings werden gesichert.", exportSettings.size())); + if (exportSettings.size()>0) + { + for (int n=0;n getExportSettings() { + return exportSettings; + } + + + +} diff --git a/src/org/hwo/pulscounter/PulsCounterApplicationListener.java b/src/org/hwo/pulscounter/PulsCounterApplicationListener.java index 974a53e..46915ce 100644 --- a/src/org/hwo/pulscounter/PulsCounterApplicationListener.java +++ b/src/org/hwo/pulscounter/PulsCounterApplicationListener.java @@ -4,6 +4,10 @@ public interface PulsCounterApplicationListener { void serialPortChanged(); void connectionStateChanged(Boolean connected); + + + void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication); + void interfacesChanged(PulsCounterApplication pulsCounterApplication); void messageArrived(String message); diff --git a/src/org/hwo/pulscounter/SnapshotManager.java b/src/org/hwo/pulscounter/SnapshotManager.java index 9914df4..662d330 100644 --- a/src/org/hwo/pulscounter/SnapshotManager.java +++ b/src/org/hwo/pulscounter/SnapshotManager.java @@ -41,8 +41,8 @@ public class SnapshotManager { } - private PulsCounter2Application application(){ - return PulsCounter2Application.getApplication(); + private PulsCounterApplication application(){ + return PulsCounterApplication.getApplication(); } public synchronized void notify(Notification notification){ diff --git a/src/org/hwo/pulscounter/application/InspectorApplication.java b/src/org/hwo/pulscounter/application/InspectorApplication.java deleted file mode 100644 index b477206..0000000 --- a/src/org/hwo/pulscounter/application/InspectorApplication.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.hwo.pulscounter.application; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.LinkedList; -import java.util.List; - -import org.hwo.pulscounter.elements.WorkShift; - -public class InspectorApplication { - List workShifts; - - Connection db; - - public InspectorApplication(){ - workShifts = new LinkedList(); -/* - workShifts.add(new WorkShift()); - workShifts.add(new WorkShift()); - - workShifts.get(0).setName("Frühschicht"); - workShifts.get(0).getBegins().setHours(6); - workShifts.get(0).getBegins().setMinutes(0); - workShifts.get(0).getEnds().setHours(15); - workShifts.get(0).getEnds().setMinutes(0); - workShifts.get(1).setName("Frühschicht"); - workShifts.get(1).getBegins().setHours(15); - workShifts.get(1).getBegins().setMinutes(0); - workShifts.get(1).getEnds().setHours(3); - workShifts.get(1).getEnds().setMinutes(0); - */ - connect(); - - try { - Statement stat = db.createStatement(); - ResultSet result = stat.executeQuery("SELECT * from workshifts"); - - while (result.next()){ - WorkShift shift = new WorkShift(); - shift.setName(result.getString("name")); - shift.getBegins().setTime( result.getTime("begins")); - shift.getEnds().setTime( result.getTime("ends")); - workShifts.add(shift); - } - - result.close(); - stat.close(); - - } catch (Exception e) - { - e.printStackTrace(); - } - } - - public void connect(){ - try { - Class.forName("org.postgresql.Driver"); - - db = DriverManager.getConnection("jdbc:postgresql://10.112.1.1/pulscounter", "haraldwolff","diekleinefeine"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public WorkShift[] getWorkShifts(){ - return workShifts.toArray(new WorkShift[0]); - } - - - public Connection getConnection() { - return db; - } - - - -} - -/*** - - properties.put("hibernate.connection.driver", "org.postgresql.Driver"); - properties.put("hibernate.connection.url", ); -***/ \ No newline at end of file diff --git a/src/org/hwo/pulscounter/device/IDeviceConnector.java b/src/org/hwo/pulscounter/device/IDeviceConnector.java new file mode 100644 index 0000000..ae38eb2 --- /dev/null +++ b/src/org/hwo/pulscounter/device/IDeviceConnector.java @@ -0,0 +1,31 @@ +package org.hwo.pulscounter.device; + +public interface IDeviceConnector { + + public String getDeviceSerial(); + + public boolean showConnctionSetup(); + public String getConnectionSettings(); + public void setConnectionSettings(String connectionSettings); + public String getConnectionSettingsText(); + + public int[] getCounters(); + public void setCounters(int[] values); + + public int getCounter(int channel); + public void setCounter(int channel,int counter); + + public int[] getSimpleScript(); + public void setSimpleScript(int[] simpleScript); + + public int getInputs(); + public void setInputs(int inputs); + public int getOutputs(); + public void setOutputs(int outputs); + public int getPullups(); + public void setPullups(int pullups); + public int getInverts(); + public void setInverts(int inverts); + + +} diff --git a/src/org/hwo/pulscounter/device/NoDeviceConnectionException.java b/src/org/hwo/pulscounter/device/NoDeviceConnectionException.java new file mode 100644 index 0000000..1136291 --- /dev/null +++ b/src/org/hwo/pulscounter/device/NoDeviceConnectionException.java @@ -0,0 +1,5 @@ +package org.hwo.pulscounter.device; + +public class NoDeviceConnectionException extends RuntimeException { + +} diff --git a/src/org/hwo/pulscounter/device/ServiceLinkDeviceConnector.java b/src/org/hwo/pulscounter/device/ServiceLinkDeviceConnector.java new file mode 100644 index 0000000..09ee38d --- /dev/null +++ b/src/org/hwo/pulscounter/device/ServiceLinkDeviceConnector.java @@ -0,0 +1,138 @@ +package org.hwo.pulscounter.device; + +import org.hwo.io.NewSerialPort.NewSerialPort; +import org.hwo.servicelink.ServiceLink; + +public class ServiceLinkDeviceConnector implements IDeviceConnector { + + private ServiceLink serviceLink; + + public ServiceLinkDeviceConnector() { + serviceLink = new ServiceLink(new NewSerialPort("COM1:")); + } + + @Override + public String toString() { + return String.format("Serial [%s]", this.serviceLink.getSerialPort().getPortName()); + } + + @Override + public String getDeviceSerial() { + // TODO Auto-generated method stub + return null; + } + + public void setDeviceSerial() { + + } + + @Override + public boolean showConnctionSetup() { + // TODO Auto-generated method stub + return false; + } + + @Override + public String getConnectionSettings() { + return serviceLink.getSerialPort().getPortName(); + } + + @Override + public void setConnectionSettings(String connectionSettings) { + serviceLink.close(); + serviceLink.getSerialPort().setPortName(connectionSettings); + } + + @Override + public String getConnectionSettingsText() { + return String.format("Port: %s",getConnectionSettings()); + } + + + @Override + public int[] getCounters() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setCounters(int[] values) { + // TODO Auto-generated method stub + + } + + @Override + public int getCounter(int channel) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setCounter(int channel, int counter) { + // TODO Auto-generated method stub + + } + + @Override + public int[] getSimpleScript() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setSimpleScript(int[] simpleScript) { + // TODO Auto-generated method stub + + } + + @Override + public int getInputs() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setInputs(int inputs) { + // TODO Auto-generated method stub + + } + + @Override + public int getOutputs() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setOutputs(int outputs) { + // TODO Auto-generated method stub + + } + + @Override + public int getPullups() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setPullups(int pullups) { + // TODO Auto-generated method stub + + } + + @Override + public int getInverts() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setInverts(int inverts) { + // TODO Auto-generated method stub + + } + + + +} diff --git a/src/org/hwo/pulscounter/elements/WorkShiftRecord.java b/src/org/hwo/pulscounter/elements/WorkShiftRecord.java index 29d0ddd..de8d943 100644 --- a/src/org/hwo/pulscounter/elements/WorkShiftRecord.java +++ b/src/org/hwo/pulscounter/elements/WorkShiftRecord.java @@ -10,10 +10,6 @@ import java.util.List; import org.hwo.datetime.Date; import org.hwo.datetime.DateTime; -<<<<<<< HEAD -======= -import org.hwo.pulscounter.PulsCounter; ->>>>>>> a886cb917c05a82eb85921d7d9c387835aa3f888 public class WorkShiftRecord { @@ -89,47 +85,6 @@ public class WorkShiftRecord { } void loadRecords(){ -<<<<<<< HEAD -/* try { -======= - try { ->>>>>>> a886cb917c05a82eb85921d7d9c387835aa3f888 - PreparedStatement stat = PulsCounter.getInspectorApplication().getConnection().prepareStatement("SELECT tstamp,channel,chvalue FROM rawvalues WHERE tstamp >= ? AND tstamp < ? ORDER BY channel,tstamp"); - - stat.setTimestamp(1, workShift.getShiftBegins(date).getTimeStamp()); - stat.setTimestamp(2, workShift.getShiftEnds(date).getTimeStamp()); - - ResultSet result = stat.executeQuery(); - - while (result.next()){ - int channel = result.getInt("channel"); - - if (!records.containsKey(channel)){ - records.put(channel, new ChannelRecords(channel)); - } - - // System.err.println("Record: " + result.getString("tstamp") + " [" + result.getString("channel") + "] " + result.getString("chvalue") ); - - records.get(channel).addValue(new DateTime(result.getTimestamp("tstamp")),result.getInt("chvalue")); - - - } - - result.close(); - stat.close(); - - for (WorkShiftRecord.ChannelRecords record: records.values().toArray(new WorkShiftRecord.ChannelRecords[0])){ - record.sort(); - } - - - } catch (SQLException e) { - e.printStackTrace(); - } -<<<<<<< HEAD - */ -======= ->>>>>>> a886cb917c05a82eb85921d7d9c387835aa3f888 } public Integer[] getChannels(){ diff --git a/src/org/hwo/pulscounter/ui/AppSettingsFrame.java b/src/org/hwo/pulscounter/ui/AppSettingsFrame.java index e8161b7..a472003 100644 --- a/src/org/hwo/pulscounter/ui/AppSettingsFrame.java +++ b/src/org/hwo/pulscounter/ui/AppSettingsFrame.java @@ -26,7 +26,7 @@ import javax.swing.JButton; import org.hwo.csv.CSV; import org.hwo.io.SerialPort; import org.hwo.io.NewSerialPort.NewSerialPort; -import org.hwo.pulscounter.PulsCounter2Application; +import org.hwo.pulscounter.PulsCounterApplication; import org.hwo.pulscounter.SnapShot; import org.hwo.pulscounter.SnapshotManager; import org.hwo.servicelink.ServiceLink; @@ -402,7 +402,7 @@ public class AppSettingsFrame extends JDialog { } private void initialize(){ - PulsCounter2Application pc2a = PulsCounter2Application.getApplication(); + PulsCounterApplication pc2a = PulsCounterApplication.getApplication(); selectedSerialPort = pc2a.getSerialPort(); formerSerialPort = selectedSerialPort; @@ -452,8 +452,8 @@ public class AppSettingsFrame extends JDialog { tabbedPane.addTab("DEBUG", null, debugPanel, null); } - private PulsCounter2Application application(){ - return PulsCounter2Application.getApplication(); + private PulsCounterApplication application(){ + return PulsCounterApplication.getApplication(); } @@ -477,7 +477,7 @@ public class AppSettingsFrame extends JDialog { } private void chooseSerialPort(){ - PulsCounter2Application pc2a = PulsCounter2Application.getApplication(); + PulsCounterApplication pc2a = PulsCounterApplication.getApplication(); SerialPortChooser spc = new SerialPortChooser(); @@ -494,7 +494,7 @@ public class AppSettingsFrame extends JDialog { } private void doRESETDevice(){ - PulsCounter2Application pc2a = PulsCounter2Application.getApplication(); + PulsCounterApplication pc2a = PulsCounterApplication.getApplication(); ServiceLink sl = pc2a.getServiceLink(); try { @@ -508,7 +508,7 @@ public class AppSettingsFrame extends JDialog { } private void doRAMImage(){ - PulsCounter2Application pc2a = PulsCounter2Application.getApplication(); + PulsCounterApplication pc2a = PulsCounterApplication.getApplication(); ServiceLink sl = pc2a.getServiceLink(); try { @@ -569,7 +569,7 @@ public class AppSettingsFrame extends JDialog { void readDebug(){ Integer v; - PulsCounter2Application pc2a = PulsCounter2Application.getApplication(); + PulsCounterApplication pc2a = PulsCounterApplication.getApplication(); ServiceLink sl = pc2a.getServiceLink(); try { @@ -600,7 +600,7 @@ public class AppSettingsFrame extends JDialog { } void dumpSnapshots(){ -SnapshotManager ssm = PulsCounter2Application.getApplication().getSnapshotManager(); +SnapshotManager ssm = PulsCounterApplication.getApplication().getSnapshotManager(); for (int n=0;n channelDisplayListeners; + private JTextField lName; /** * Create the panel. @@ -124,6 +125,20 @@ public class ChannelDisplay extends JPanel { add(tfCounter, gbc_tfCounter); tfCounter.setColumns(10); + tfAnalog = new JTextField(); + tfAnalog.setToolTipText("\nAnalog Messwert
\n
\nZeigt die an diesem Kanal gemessene Spannung.\n"); + tfAnalog.setEditable(false); + tfAnalog.setHorizontalAlignment(SwingConstants.RIGHT); + tfAnalog.setInheritsPopupMenu(true); + GridBagConstraints gbc_tfAnalog = new GridBagConstraints(); + gbc_tfAnalog.gridwidth = 2; + gbc_tfAnalog.insets = new Insets(0, 0, 0, 5); + gbc_tfAnalog.fill = GridBagConstraints.HORIZONTAL; + gbc_tfAnalog.gridx = 0; + gbc_tfAnalog.gridy = 1; + add(tfAnalog, gbc_tfAnalog); + tfAnalog.setColumns(10); + lblA = new JLabel(""); lblA.setToolTipText("\nAusgang
\n
\nZeigt, ob die Ausgangsschaltung für diesen Kanal aktiv ist.\n"); lblA.setIcon(new ImageIcon(ChannelDisplay.class.getResource("/org/hwo/pulscounter/ui/sym_a_passiv.png"))); @@ -134,17 +149,15 @@ public class ChannelDisplay extends JPanel { gbc_lblA.gridy = 1; add(lblA, gbc_lblA); - tfAnalog = new JTextField(); - tfAnalog.setToolTipText("\nAnalog Messwert
\n
\nZeigt die an diesem Kanal gemessene Spannung.\n"); - tfAnalog.setEditable(false); - tfAnalog.setHorizontalAlignment(SwingConstants.RIGHT); - tfAnalog.setInheritsPopupMenu(true); - GridBagConstraints gbc_tfAnalog = new GridBagConstraints(); - gbc_tfAnalog.fill = GridBagConstraints.HORIZONTAL; - gbc_tfAnalog.gridx = 3; - gbc_tfAnalog.gridy = 1; - add(tfAnalog, gbc_tfAnalog); - tfAnalog.setColumns(10); + lName = new JTextField(); + lName.setEditable(false); + lName.setForeground(Color.LIGHT_GRAY); + lName.setInheritsPopupMenu(true); + GridBagConstraints gbc_lName = new GridBagConstraints(); + gbc_lName.fill = GridBagConstraints.HORIZONTAL; + gbc_lName.gridx = 3; + gbc_lName.gridy = 1; + add(lName, gbc_lName); this.initialize(); } @@ -181,6 +194,23 @@ public class ChannelDisplay extends JPanel { }); popupMenu.add(tf); + + popupMenu.addSeparator(); + + JLabel l2 = new JLabel("Beschreibung:"); + popupMenu.add(l2); + + final JTextField tf2 = new JTextField(); + tf2.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + setDescriptionText(tf2.getText()); + fireChannelDisplayDescriptionSet(tf2.getText()); + popupMenu.setVisible(false); + } + }); + popupMenu.add( tf2 ); } @@ -206,6 +236,11 @@ public class ChannelDisplay extends JPanel { l.set(this, setValue); } } + private void fireChannelDisplayDescriptionSet(String desc){ + for (ChannelDisplayListener l:channelDisplayListeners){ + l.setDescriptionText(this, desc); + } + } public void setAnalog(boolean isAnalog) { this.isAnalog = isAnalog; @@ -275,4 +310,11 @@ public class ChannelDisplay extends JPanel { return channelName; } + public void setDescriptionText(String desc){ + lName.setText(desc); + } + public String getDescriptionText(){ + return lName.getText(); + } + } diff --git a/src/org/hwo/pulscounter/ui/ChannelDisplayListener.java b/src/org/hwo/pulscounter/ui/ChannelDisplayListener.java index bf021ba..1a2065e 100644 --- a/src/org/hwo/pulscounter/ui/ChannelDisplayListener.java +++ b/src/org/hwo/pulscounter/ui/ChannelDisplayListener.java @@ -5,4 +5,6 @@ public interface ChannelDisplayListener { public void reset (ChannelDisplay sender); public void set (ChannelDisplay sender,int setValue); + public void setDescriptionText(ChannelDisplay sender,String descriptionText); + } diff --git a/src/org/hwo/pulscounter/ui/CheckWorkshiftRecords.java b/src/org/hwo/pulscounter/ui/CheckWorkshiftRecords.java deleted file mode 100644 index 4aff814..0000000 --- a/src/org/hwo/pulscounter/ui/CheckWorkshiftRecords.java +++ /dev/null @@ -1,302 +0,0 @@ -package org.hwo.pulscounter.ui; - -import java.awt.BorderLayout; -import java.awt.EventQueue; - -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; - -import java.awt.GridBagLayout; -import java.awt.GridBagConstraints; - -import javax.swing.border.TitledBorder; - -import java.awt.Insets; - -import javax.swing.JLabel; -import javax.swing.JTextField; -import javax.swing.JButton; - -import org.hwo.datetime.Date; -import org.hwo.pulscounter.PulsCounter; -import org.hwo.pulscounter.elements.WorkShift; -import org.hwo.pulscounter.elements.WorkShiftRecord; - -import javax.swing.JComboBox; - -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.util.LinkedList; - -import javax.swing.JTable; - -import org.hwo.ui.FlexibleJTable; -import org.hwo.ui.JComboBoxEx; - -import javax.swing.JScrollPane; - -public class CheckWorkshiftRecords extends JFrame { - - private Date selectedDate; - private WorkShiftRecord selectedWorkShift; - - - private JPanel contentPane; - private JTextField tfDatum; - private JComboBox cbWorkShift; - private JTextField tfBegins; - private JTextField tfEnds; - private FlexibleJTable flexibleJTable; - private JComboBoxEx cbChannel; - - /** - * Launch the application. - */ - public static void main(String[] args) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - CheckWorkshiftRecords frame = new CheckWorkshiftRecords(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - - /** - * Create the frame. - */ - public CheckWorkshiftRecords() { - setTitle("Schichtdaten prüfen"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setBounds(100, 100, 938, 686); - contentPane = new JPanel(); - contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); - setContentPane(contentPane); - GridBagLayout gbl_contentPane = new GridBagLayout(); - gbl_contentPane.columnWidths = new int[]{0, 0}; - gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0}; - gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE}; - gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE}; - contentPane.setLayout(gbl_contentPane); - - JPanel panel = new JPanel(); - panel.setBorder(new TitledBorder(null, "Auswahl", TitledBorder.LEADING, TitledBorder.TOP, null, null)); - GridBagConstraints gbc_panel = new GridBagConstraints(); - gbc_panel.insets = new Insets(0, 0, 5, 0); - gbc_panel.fill = GridBagConstraints.BOTH; - gbc_panel.gridx = 0; - gbc_panel.gridy = 0; - contentPane.add(panel, gbc_panel); - GridBagLayout gbl_panel = new GridBagLayout(); - gbl_panel.columnWidths = new int[]{0, 0, 0, 0, 0, 0}; - gbl_panel.rowHeights = new int[]{0, 0, 0, 0}; - gbl_panel.columnWeights = new double[]{0.0, 1.0, 1.0, 0.0, 0.0, Double.MIN_VALUE}; - gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE}; - panel.setLayout(gbl_panel); - - JLabel lblDatum = new JLabel("Datum:"); - GridBagConstraints gbc_lblDatum = new GridBagConstraints(); - gbc_lblDatum.insets = new Insets(0, 0, 5, 5); - gbc_lblDatum.anchor = GridBagConstraints.EAST; - gbc_lblDatum.gridx = 0; - gbc_lblDatum.gridy = 0; - panel.add(lblDatum, gbc_lblDatum); - - tfDatum = new JTextField(); - tfDatum.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - Date d = new Date(); - d.fromSQLDate(tfDatum.getText()); - selectDatum(d); - } - }); - GridBagConstraints gbc_tfDatum = new GridBagConstraints(); - gbc_tfDatum.gridwidth = 2; - gbc_tfDatum.insets = new Insets(0, 0, 5, 5); - gbc_tfDatum.fill = GridBagConstraints.HORIZONTAL; - gbc_tfDatum.gridx = 1; - gbc_tfDatum.gridy = 0; - panel.add(tfDatum, gbc_tfDatum); - tfDatum.setColumns(10); - - JButton btnGestern = new JButton("GESTERN"); - btnGestern.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - Date d = new Date(); - d.addDays(-1); - selectDatum(d); - } - }); - - JButton btnHeute = new JButton("HEUTE"); - btnHeute.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - selectDatum(new Date()); - } - }); - GridBagConstraints gbc_btnHeute = new GridBagConstraints(); - gbc_btnHeute.insets = new Insets(0, 0, 5, 5); - gbc_btnHeute.gridx = 3; - gbc_btnHeute.gridy = 0; - panel.add(btnHeute, gbc_btnHeute); - GridBagConstraints gbc_btnGestern = new GridBagConstraints(); - gbc_btnGestern.insets = new Insets(0, 0, 5, 0); - gbc_btnGestern.gridx = 4; - gbc_btnGestern.gridy = 0; - panel.add(btnGestern, gbc_btnGestern); - - JLabel lblSchicht = new JLabel("Schicht:"); - GridBagConstraints gbc_lblSchicht = new GridBagConstraints(); - gbc_lblSchicht.insets = new Insets(0, 0, 5, 5); - gbc_lblSchicht.gridx = 0; - gbc_lblSchicht.gridy = 1; - panel.add(lblSchicht, gbc_lblSchicht); - - cbWorkShift = new JComboBox(); - cbWorkShift.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - selectionChanged(); - } - }); - GridBagConstraints gbc_cbWorkShift = new GridBagConstraints(); - gbc_cbWorkShift.gridwidth = 2; - gbc_cbWorkShift.insets = new Insets(0, 0, 5, 5); - gbc_cbWorkShift.fill = GridBagConstraints.HORIZONTAL; - gbc_cbWorkShift.gridx = 1; - gbc_cbWorkShift.gridy = 1; - panel.add(cbWorkShift, gbc_cbWorkShift); - - JLabel lblSchichtgrenzen = new JLabel("Schichtgrenzen:"); - GridBagConstraints gbc_lblSchichtgrenzen = new GridBagConstraints(); - gbc_lblSchichtgrenzen.anchor = GridBagConstraints.EAST; - gbc_lblSchichtgrenzen.insets = new Insets(0, 0, 0, 5); - gbc_lblSchichtgrenzen.gridx = 0; - gbc_lblSchichtgrenzen.gridy = 2; - panel.add(lblSchichtgrenzen, gbc_lblSchichtgrenzen); - - tfBegins = new JTextField(); - GridBagConstraints gbc_tfBegins = new GridBagConstraints(); - gbc_tfBegins.insets = new Insets(0, 0, 0, 5); - gbc_tfBegins.fill = GridBagConstraints.HORIZONTAL; - gbc_tfBegins.gridx = 1; - gbc_tfBegins.gridy = 2; - panel.add(tfBegins, gbc_tfBegins); - tfBegins.setColumns(10); - - tfEnds = new JTextField(); - tfEnds.setColumns(10); - GridBagConstraints gbc_tfEnds = new GridBagConstraints(); - gbc_tfEnds.insets = new Insets(0, 0, 0, 5); - gbc_tfEnds.fill = GridBagConstraints.HORIZONTAL; - gbc_tfEnds.gridx = 2; - gbc_tfEnds.gridy = 2; - panel.add(tfEnds, gbc_tfEnds); - - JPanel panel_2 = new JPanel(); - panel_2.setBorder(new TitledBorder(null, "Kanal", TitledBorder.LEADING, TitledBorder.TOP, null, null)); - GridBagConstraints gbc_panel_2 = new GridBagConstraints(); - gbc_panel_2.insets = new Insets(0, 0, 5, 0); - gbc_panel_2.fill = GridBagConstraints.BOTH; - gbc_panel_2.gridx = 0; - gbc_panel_2.gridy = 1; - contentPane.add(panel_2, gbc_panel_2); - 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[]{1.0, Double.MIN_VALUE}; - gbl_panel_2.rowWeights = new double[]{0.0, Double.MIN_VALUE}; - panel_2.setLayout(gbl_panel_2); - - cbChannel = new JComboBoxEx(); - cbChannel.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent arg0) { - selectChannel(); - } - } - ); - GridBagConstraints gbc_cbChannel = new GridBagConstraints(); - gbc_cbChannel.fill = GridBagConstraints.HORIZONTAL; - gbc_cbChannel.gridx = 0; - gbc_cbChannel.gridy = 0; - panel_2.add(cbChannel, gbc_cbChannel); - - JPanel panel_1 = new JPanel(); - GridBagConstraints gbc_panel_1 = new GridBagConstraints(); - gbc_panel_1.fill = GridBagConstraints.BOTH; - gbc_panel_1.gridx = 0; - gbc_panel_1.gridy = 2; - contentPane.add(panel_1, gbc_panel_1); - GridBagLayout gbl_panel_1 = new GridBagLayout(); - gbl_panel_1.columnWidths = new int[]{0, 0}; - gbl_panel_1.rowHeights = new int[]{0, 0}; - gbl_panel_1.columnWeights = new double[]{1.0, Double.MIN_VALUE}; - gbl_panel_1.rowWeights = new double[]{1.0, Double.MIN_VALUE}; - panel_1.setLayout(gbl_panel_1); - - JScrollPane scrollPane = new JScrollPane(); - GridBagConstraints gbc_scrollPane = new GridBagConstraints(); - gbc_scrollPane.fill = GridBagConstraints.BOTH; - gbc_scrollPane.gridx = 0; - gbc_scrollPane.gridy = 0; - panel_1.add(scrollPane, gbc_scrollPane); - - flexibleJTable = new FlexibleJTable(WorkShiftRecord.ChannelRecords.ChannelRecord.class); - scrollPane.setViewportView(flexibleJTable); - - this.initialize(); - } - - void initialize(){ - for (WorkShift shift: PulsCounter.getInspectorApplication().getWorkShifts()){ - cbWorkShift.addItem(shift); - } - - flexibleJTable.addColumn("timestamp"); - flexibleJTable.addColumn("value"); - - - - selectDatum(new Date()); - } - - void selectDatum(Date date){ - tfDatum.setText(date.getSQLDate()); - selectedDate = date; - - selectionChanged(); - } - - void selectionChanged(){ - if (cbWorkShift.getSelectedItem()==null) - return; - if (selectedDate == null) - return; - - WorkShift shift = (WorkShift)cbWorkShift.getSelectedItem(); - - tfBegins.setText(shift.getShiftBegins(selectedDate).getSQLDateTime()); - tfEnds.setText(shift.getShiftEnds(selectedDate).getSQLDateTime()); - - WorkShiftRecord workShiftRecord = new WorkShiftRecord(shift, selectedDate); - - selectedWorkShift = null; - - flexibleJTable.setRows(new LinkedList()); - cbChannel.setItems(workShiftRecord.getChannels()); - - selectedWorkShift = workShiftRecord; - } - - void selectChannel(){ - if (selectedWorkShift != null){ - Integer ch = (Integer)cbChannel.getSelectedItem(); - flexibleJTable.setRows(selectedWorkShift.getChannelRecords(ch).getRecords()); - } - } - -} diff --git a/src/org/hwo/pulscounter/ui/DeviceConfiguration.java b/src/org/hwo/pulscounter/ui/DeviceConfiguration.java index 6fb891e..03fc0af 100644 --- a/src/org/hwo/pulscounter/ui/DeviceConfiguration.java +++ b/src/org/hwo/pulscounter/ui/DeviceConfiguration.java @@ -9,7 +9,7 @@ import javax.swing.border.EmptyBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import org.hwo.pulscounter.PulsCounter2Application; +import org.hwo.pulscounter.PulsCounterApplication; import org.hwo.servicelink.ServiceLink; import org.hwo.servicelink.ServiceLinkException; import org.hwo.servicelink.ServiceLinkRequestFailedException; @@ -111,7 +111,7 @@ public class DeviceConfiguration extends JFrame { tseI2.setDaysEnabled(((v & 0x04)==0)); tseI3.setDaysEnabled(((v & 0x08)==0)); - ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink(); + ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink(); try { sl.writeInt(13, 0, 0x1003, bfeIntervall.getIntValue()); @@ -156,7 +156,7 @@ public class DeviceConfiguration extends JFrame { @Override public void focusLost(FocusEvent e) { System.err.println("FOCUS LOST 0"); - ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink(); + ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink(); try { sl.writeInt(13, 0, 0x1010, (Integer)tseI0.getValue()); @@ -192,7 +192,7 @@ public class DeviceConfiguration extends JFrame { @Override public void focusLost(FocusEvent e) { - ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink(); + ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink(); try { sl.writeInt(13, 0, 0x1011, (Integer)tseI1.getValue()); @@ -227,7 +227,7 @@ public class DeviceConfiguration extends JFrame { tseI2.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink(); + ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink(); try { sl.writeInt(13, 0, 0x1012, (Integer)tseI2.getValue()); @@ -262,7 +262,7 @@ public class DeviceConfiguration extends JFrame { tseI3.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink(); + ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink(); try { sl.writeInt(13, 0, 0x1013, (Integer)tseI3.getValue()); @@ -363,7 +363,7 @@ public class DeviceConfiguration extends JFrame { private void readDevice(){ Integer v; - ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink(); + ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink(); outputs = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1008)); pullups = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1009)); @@ -401,7 +401,7 @@ public class DeviceConfiguration extends JFrame { } private void writeDevice(){ - ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink(); + ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink(); try { sl.writeInt(13, 0, 0x1008, outputs); sl.writeInt(13, 0, 0x1009, pullups); diff --git a/src/org/hwo/pulscounter/ui/DeviceTestFrame.java b/src/org/hwo/pulscounter/ui/DeviceTestFrame.java index 36838a7..e40aec4 100644 --- a/src/org/hwo/pulscounter/ui/DeviceTestFrame.java +++ b/src/org/hwo/pulscounter/ui/DeviceTestFrame.java @@ -8,7 +8,7 @@ import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import org.hwo.datetime.DateTime; -import org.hwo.pulscounter.PulsCounter2Application; +import org.hwo.pulscounter.PulsCounterApplication; import org.hwo.pulscounter.PulsCounterApplicationListener; import org.hwo.pulscounter.SnapshotManager.Notification; import org.hwo.servicelink.ServiceLinkException; @@ -42,11 +42,14 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis private JList lMessages; private DefaultListModel messageListModel; + private PulsCounterApplication pulsCounterApplication; /** * Create the frame. */ - public DeviceTestFrame() { + public DeviceTestFrame(PulsCounterApplication pulsCounterApplication) { + this.pulsCounterApplication = pulsCounterApplication; + setTitle("Device Test Frame"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 701, 464); @@ -174,8 +177,8 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis this.initialize(); } - private PulsCounter2Application application(){ - return PulsCounter2Application.getApplication(); + private PulsCounterApplication application(){ + return this.pulsCounterApplication; } private void initialize(){ @@ -187,6 +190,7 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis application().addPulsCounterApplicationListener(this); application().fireConnectionStateChanged(false); + setVisible(true); } @Override @@ -362,5 +366,18 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis } } + + + @Override + public void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication) { + // TODO Auto-generated method stub + + } + + @Override + public void interfacesChanged(PulsCounterApplication pulsCounterApplication) { + // TODO Auto-generated method stub + + } } diff --git a/src/org/hwo/pulscounter/ui/ExportFilesFrame.java b/src/org/hwo/pulscounter/ui/ExportFilesFrame.java index b4961c0..85bc210 100644 --- a/src/org/hwo/pulscounter/ui/ExportFilesFrame.java +++ b/src/org/hwo/pulscounter/ui/ExportFilesFrame.java @@ -13,7 +13,7 @@ import org.hwo.interactiveobjects.ObjectEditorUI; import org.hwo.interactiveobjects.ObjectEditorUIHelper; import org.hwo.models.TableMapper.TableMapper; import org.hwo.pulscounter.ExportSetting; -import org.hwo.pulscounter.PulsCounter2Application; +import org.hwo.pulscounter.PulsCounterApplication; import java.awt.GridBagLayout; import javax.swing.JButton; @@ -141,14 +141,14 @@ public class ExportFilesFrame extends JFrame { setSelectedExportSetting(es); } }); - tmExportSettings.setRows(PulsCounter2Application.getApplication().getExportSettings()); + tmExportSettings.setRows(PulsCounterApplication.getApplication().getExportSettings()); scrollPane.setViewportView(tExportSettings); JButton btnSchliessen = new JButton("schliessen"); btnSchliessen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); - PulsCounter2Application.getApplication().savePrefs(); + PulsCounterApplication.getApplication().savePrefs(); } }); GridBagConstraints gbc_btnSchliessen = new GridBagConstraints(); diff --git a/src/org/hwo/pulscounter/ui/InspectionMainFrame.java b/src/org/hwo/pulscounter/ui/InspectionMainFrame.java deleted file mode 100644 index 4f21695..0000000 --- a/src/org/hwo/pulscounter/ui/InspectionMainFrame.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.hwo.pulscounter.ui; - -import java.awt.BorderLayout; -import java.awt.EventQueue; - -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; - -import java.awt.GridBagLayout; - -import javax.swing.JButton; - -import java.awt.GridBagConstraints; -import java.awt.Insets; - -import javax.swing.border.TitledBorder; - -import org.hwo.datetime.Date; -import org.hwo.pulscounter.PulsCounter; -import org.hwo.pulscounter.elements.WorkShift; - -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; - -public class InspectionMainFrame extends JFrame { - - private JPanel contentPane; - - /** - * Launch the application. - */ - public static void main(String[] args) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - InspectionMainFrame frame = new InspectionMainFrame(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - - /** - * Create the frame. - */ - public InspectionMainFrame() { - setTitle("Inspektor"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setBounds(100, 100, 841, 607); - contentPane = new JPanel(); - contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); - setContentPane(contentPane); - GridBagLayout gbl_contentPane = new GridBagLayout(); - gbl_contentPane.columnWidths = new int[]{0, 0}; - gbl_contentPane.rowHeights = new int[]{0, 0, 0}; - gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE}; - gbl_contentPane.rowWeights = new double[]{1.0, 1.0, Double.MIN_VALUE}; - contentPane.setLayout(gbl_contentPane); - - JPanel panel = new JPanel(); - GridBagConstraints gbc_panel = new GridBagConstraints(); - gbc_panel.insets = new Insets(0, 0, 5, 0); - gbc_panel.fill = GridBagConstraints.BOTH; - gbc_panel.gridx = 0; - gbc_panel.gridy = 0; - contentPane.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[]{0.0, Double.MIN_VALUE}; - gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE}; - panel.setLayout(gbl_panel); - - JButton btnNewButton = new JButton("Schichtdaten prüfen..."); - btnNewButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - WorkShift[] shifts = PulsCounter.getInspectorApplication().getWorkShifts(); - Date d = new Date(); - d.addDays(10); - for (int i=0;i<40;i++){ - - for (int s = 0;s()); - - inputButtons = new JLabel[32]; - outputButtons = new JToggleButton[32]; - pullupButtons = new JToggleButton[32]; - - for (int i=0;i<32;i++){ - final int n = i; - - inputButtons[i] = new JLabel(String.format("%d", i)); - inputButtons[i].setOpaque(true); - inputButtons[i].setHorizontalAlignment(SwingConstants.CENTER); - inputButtons[i].addMouseListener(new MousePopupListener() { - - @Override - public void popupTriggered(int x, int y) { - JPopupMenu popup = new JPopupMenu(); - JMenuItem mi = new JMenuItem(); - mi.setText("RESET"); - mi.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent arg0) { - if (serviceLink != null){ - try { - serviceLink.writeInt(13, 0, 0x0600 + n, 0); - } catch (ServiceLinkRequestFailedException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (ServiceLinkException e) { - e.printStackTrace(); - } - } - } - }); - popup.add(mi); - - popup.show(inputButtons[n], x, y); - - } - }); - - GridBagConstraints gbc = new GridBagConstraints(); - gbc.insets = new Insets(0, 0, 0, 0); - gbc.fill = GridBagConstraints.BOTH; - gbc.gridx = i % 8; - gbc.gridy = (i / 8); - - pDisplay.add(inputButtons[i], gbc); - - outputButtons[i] = new JToggleButton(String.format("%d", i)); - outputButtons[i].addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent arg0) { - setOutput(n, outputButtons[n].isSelected()); - } - }); - - pOutputs.add(outputButtons[i], gbc); - - pullupButtons[i] = new JToggleButton(String.format("%d", i)); - pullupButtons[i].addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent arg0) { - setPullUp(n, pullupButtons[n].isSelected()); - } - }); - pPullups.add(pullupButtons[i],gbc); - } - - analogLabels = new JLabel[8]; - - for (int i=0;i<8;i++){ - analogLabels[i] = new JLabel(String.format("---")); - analogLabels[i].setBorder(new TitledBorder(String.format("AN%d",i))); - pAnalog.add(analogLabels[i]); - } - - - liveViewTimer = new Timer(); - liveViewTimer.scheduleAtFixedRate(new TimerTask() { - - @Override - public void run() { - updateLiveView(); - } - }, 200, 500); - - pc2a.addAppSettingsListener(this); - - serviceLink = pc2a.getServiceLink(); - - } - - private synchronized void updateLiveView(){ - System.err.println("LiveView Update"); - long startTime = System.currentTimeMillis(); - - if (serviceLink != null){ - System.err.println("ServiceLink exists."); - try { - serviceLink.open(); - } catch (ServiceLinkException e) { - e.printStackTrace(); - } - - Integer brkval,heapend; - - brkval = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0020 ); - if (brkval == null) - brkval = 0; - - heapend = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0021 ); - if (heapend == null) - heapend = 0; - - System.err.println(String.format("PC2-BRKVAL: 0x%04x",brkval)); - System.err.println(String.format("PC2-HEAPEND: 0x%04x",heapend)); - - Calendar calendar = Calendar.getInstance(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - Integer deviceUnixTime = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x001C); - if (deviceUnixTime != null){ - calendar.setTimeInMillis(deviceUnixTime * 1000L); - - tfUnixTime.setText(String.format("%d",deviceUnixTime)); - tfHumanDateTime.setText(sdf.format(calendar.getTime())); - }; - - pinputs = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0680 ); - inputs = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0681 ); - outputs = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0682 ); - pullups = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0683 ); - - Integer[] values = new Integer[32]; - for (int i=0;i<32;i++){ - values[i] = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0600 + i); - }; - - - if (pinputs == null) - pinputs = 0; - if (inputs == null) - inputs = 0; - if (outputs == null) - outputs = 0; - if (pullups == null) - pullups = 0; - - System.err.println(String.format("Inputs State (Phys.): 0x%08x",pinputs)); - System.err.println(String.format("Inputs State: 0x%08x",inputs)); - System.err.println(String.format("Outputs State: 0x%08x",outputs)); - System.err.println(String.format("PullUP State: 0x%08x",pullups)); - - for (int i=0;i<32;i++){ - if ((inputs & (1<
%d
[%d]
", i, values[i])); - } else { - inputButtons[i].setText(String.format("
%d
N.A.
", i)); - }; - - - if ((outputs & (1<= 0) - break; - - DefaultListModel lm = (DefaultListModel)lMessages.getModel(); - lm.addElement(String.format("Assertion: Error: 0x%08x (%d) Position: 0x%04x Mark: %d", assert_error,assert_error, assert_code & 0xffff, (assert_code >> 16) & 0xffff)); - lMessages.ensureIndexIsVisible(lm.size()-1); - - serviceLink.writeInt(13, 0, 0x0025, -1); - }; - } catch (Exception ex){ - System.err.println("Exception while checking for assertions..."); - ex.printStackTrace(); - } - - - - - - } - long endTime = System.currentTimeMillis(); - - System.err.println(String.format("updateLiveView(): Time needed: %d", (endTime - startTime))); - - } - - @Override - public synchronized void ServiceLinkChanged(ServiceLink serviceLink) { - this.serviceLink = serviceLink; - } - - public synchronized void setOutput(int ch,boolean set){ - if (this.serviceLink != null){ - try { - if (set){ - serviceLink.writeInt((byte)13, (byte)0, 0x8100 + ch, 1); - } else { - serviceLink.writeInt((byte)13, (byte)0, 0x8100 + ch, 0); - } - } catch (ServiceLinkRequestFailedException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (ServiceLinkException e) { - e.printStackTrace(); - } - } - } - - public synchronized void setPullUp(int ch,boolean set){ - if (this.serviceLink != null){ - if (set){ - pullups |= (1<)lMessages.getModel()).addElement(msg); - } - - private void quartzCorrect(){ - long lStart,lEnd; - long rStart,rEnd; - long lDelta,rDelta; - long delta; - - if (this.serviceLink != null){ - try - { - - lStart = System.currentTimeMillis(); - rStart = serviceLink.readInt(13, 0, 0x0027); - - Thread.sleep(30000); - - lEnd = System.currentTimeMillis(); - rEnd = serviceLink.readInt(13, 0, 0x0027); - - lDelta = (lEnd - lStart)*1000; - rDelta = rEnd - rStart; - - delta = lDelta - rDelta; - - message(String.format("Local: %d Remote: %d Delta: %d", lDelta,rDelta,delta)); - - delta /= 30; - - message(String.format("Korrektur: %d", delta)); - - serviceLink.writeInt(13, 0, 0x1002, (int)delta); - - } catch (Exception e) - { - e.printStackTrace(); - } - }; - - } - -} diff --git a/src/org/hwo/pulscounter/ui/NewMainWindow.java b/src/org/hwo/pulscounter/ui/NewMainWindow.java index 0b5bdeb..36a11e6 100644 --- a/src/org/hwo/pulscounter/ui/NewMainWindow.java +++ b/src/org/hwo/pulscounter/ui/NewMainWindow.java @@ -15,10 +15,12 @@ import org.hwo.Smoother; import org.hwo.datetime.DateTime; import org.hwo.io.NewSerialPort.NewSerialPort; import org.hwo.logging.Logging; +import org.hwo.models.FlexibleObjectListModel; import org.hwo.platform.Platform; -import org.hwo.pulscounter.PulsCounter2Application; +import org.hwo.pulscounter.PulsCounterApplication; import org.hwo.pulscounter.PulsCounterApplicationListener; import org.hwo.pulscounter.SnapshotManager.Notification; +import org.hwo.pulscounter.device.IDeviceConnector; import org.hwo.servicelink.ServiceLinkException; import org.hwo.servicelink.ServiceLinkRequestFailedException; import org.hwo.tasklet.Tasklet; @@ -67,13 +69,21 @@ import javax.swing.event.ChangeListener; import javax.swing.plaf.metal.MetalBorders.ToolBarBorder; import javax.swing.event.ChangeEvent; import static org.hwo.logging.Logging.log; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.ListSelectionEvent; public class NewMainWindow implements PulsCounterApplicationListener, TaskletListener{ + private PulsCounterApplication pulsCounterApplication; + private IDeviceConnector selectedDeviceInterface; + + private FlexibleObjectListModel> + lmInterfaceClasses = new FlexibleObjectListModel<>(); + private FlexibleObjectListModel + lmInterfaces = new FlexibleObjectListModel<>(); + private JFrame frmSynolog; - private JTextField tfSerialPortName; private JSplitPane splitter; - private JButton btnNewButton; private JTextField tfConnection; private JButton btnSetup; @@ -100,68 +110,14 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis private JCheckBox cbTrimDevice; private Smoother smoothTrim; + private JList lInterfaces; + private JScrollPane scrollPane_2; + private JButton bIntfAdd; + private JButton bIntfDel; + private JPanel panel_4; + private JTextField tfConnectionSettings; - - /** - * Launch the application. - */ - public static void main(String[] args) { - - boolean batchRun = false; - boolean deviceSetup = false; - String logFileName = "synololog.log"; - - Iterator aiter = Arrays.asList(args).iterator(); - - while (aiter.hasNext()){ - String opt = aiter.next(); - - switch (opt){ - case "-b": - batchRun = true; - break; - case "--device-setup": - deviceSetup = true; - batchRun = false; - break; - case "--log": - logFileName = aiter.next(); - break; - } - } - - Logging.setLogFileName(logFileName); - - logStartup(); - - if (deviceSetup){ - startDeviceSetup(); - } else if (batchRun){ - startBATCH(); - } else { - startGUI(); - } - } - - private static void logStartup(){ - log("%s.logStartup()",NewMainWindow.class.getCanonicalName()); - log("Synololog Java Software startup"); - - log("JAVA Environment: %s (%s)", System.getProperty("java.version"), - System.getProperty("java.vendor")); - - log("Operating System: %s [%s] %s", System.getProperty("os.name"), - System.getProperty("os.arch"), - System.getProperty("os.version")); - - log("User Environment: %s (%s) (CWD:%s)", System.getProperty("user.name"), - System.getProperty("user.home"), - System.getProperty("user.dir")); - - log("Hostname: %s",Platform.getHostName()); - log("OS Search Path: %s", System.getenv("PATH")); - } - + public static void startGUI(){ try { @@ -186,44 +142,22 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis ToolTipManager.sharedInstance().setInitialDelay( 1250 ); ToolTipManager.sharedInstance().setReshowDelay( 500 ); - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - NewMainWindow window = new NewMainWindow(); - window.frmSynolog.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - - public static void startBATCH(){ - - BatchRunner batchRunner = new BatchRunner(); - batchRunner.run(); - - } - - public static void startDeviceSetup(){ - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - DeviceTestFrame deviceTestFrame = new DeviceTestFrame(); - deviceTestFrame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - + } /** * @wbp.parser.entryPoint */ - public NewMainWindow() { + public NewMainWindow(PulsCounterApplication pulsCounterApplication) { + startGUI(); + + this.pulsCounterApplication = pulsCounterApplication; + initialize(); + initializeChannelPanels(); + + pulsCounterApplication.addPulsCounterApplicationListener(this); + + if (false){ this.connected = false; @@ -242,39 +176,6 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis application().fireSerialPortChanged(); application().message("Synololog Applikation wurde gestartet."); - - channelDisplays = new ChannelDisplay[32]; - - for (int i=0;i<32;i++){ - channelDisplays[i] = new ChannelDisplay(); - channelDisplays[i].setChannelName(String.format("%02d",i)); - if (i > 7){ - channelDisplays[i].setAnalog(false); - } - GridBagConstraints gbc = new GridBagConstraints(); - gbc.insets = new Insets(2, 2, 2, 2); - gbc.anchor = GridBagConstraints.NORTHWEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.weightx = 1; - gbc.weighty = 1; - gbc.gridx = i & 0x03; - gbc.gridy = i >> 2; - - channelDisplays[i].addChannelDisplayListener(new ChannelDisplayListener() { - - @Override - public void set(ChannelDisplay sender, int setValue) { - channelSet(sender, setValue); - } - - @Override - public void reset(ChannelDisplay sender) { - channelReset(sender); - } - }); - - pChannels.add(channelDisplays[i], gbc); - } timerReconnect.scheduleAtFixedRate(new TimerTask() { @@ -307,6 +208,9 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis } }, 52000, 15000); + } + + frmSynolog.addWindowListener(new WindowListener() { @Override @@ -335,12 +239,11 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis @Override public void windowClosing(WindowEvent e) { - // TODO Auto-generated method stub - } @Override public void windowClosed(WindowEvent e) { + application().notifyUiIsFinished(true); } @@ -351,8 +254,53 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis } }); + lmInterfaces.setItems(pulsCounterApplication.getInterfaces()); + + frmSynolog.setVisible(true); } + + private void initializeChannelPanels(){ + channelDisplays = new ChannelDisplay[32]; + + for (int i=0;i<32;i++){ + channelDisplays[i] = new ChannelDisplay(); + channelDisplays[i].setChannelName(String.format("%02d",i)); + if (i > 7){ + channelDisplays[i].setAnalog(false); + } + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(2, 2, 2, 2); + gbc.anchor = GridBagConstraints.NORTHWEST; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.weightx = 1; + gbc.weighty = 1; + gbc.gridx = i & 0x03; + gbc.gridy = i >> 2; + + channelDisplays[i].addChannelDisplayListener(new ChannelDisplayListener() { + + @Override + public void set(ChannelDisplay sender, int setValue) { + channelSet(sender, setValue); + } + + @Override + public void reset(ChannelDisplay sender) { + channelReset(sender); + } + + @Override + public void setDescriptionText(ChannelDisplay sender, String descriptionText) { + } + }); + + channelDisplays[i].setDescriptionText( application().getChannelDescription(i)); + + pChannels.add(channelDisplays[i], gbc); + } + } + /** * Initialize the contents of the frame. */ @@ -360,7 +308,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis frmSynolog = new JFrame(); frmSynolog.setTitle("Synololog"); frmSynolog.setBounds(100, 100, 1000, 580); - frmSynolog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frmSynolog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frmSynolog.getContentPane().setLayout(new BorderLayout(0, 0)); frmSynolog.setBackground(Color.WHITE); @@ -432,39 +380,55 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis gbc_panel_1.gridy = 0; panel.add(panel_1, gbc_panel_1); GridBagLayout gbl_panel_1 = new GridBagLayout(); - gbl_panel_1.columnWidths = new int[]{0, 0, 0, 0}; - gbl_panel_1.rowHeights = new int[]{0, 0, 0, 0, 0, 0}; - gbl_panel_1.columnWeights = new double[]{1.0, 1.0, 0.0, Double.MIN_VALUE}; - gbl_panel_1.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; + gbl_panel_1.columnWidths = new int[]{0, 0, 0}; + gbl_panel_1.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0}; + gbl_panel_1.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE}; + gbl_panel_1.rowWeights = new double[]{0.0, 1.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; panel_1.setLayout(gbl_panel_1); - JLabel lblAnschluss = new JLabel("Anschluss:"); - GridBagConstraints gbc_lblAnschluss = new GridBagConstraints(); - gbc_lblAnschluss.insets = new Insets(0, 0, 5, 5); - gbc_lblAnschluss.anchor = GridBagConstraints.WEST; - gbc_lblAnschluss.gridx = 0; - gbc_lblAnschluss.gridy = 0; - panel_1.add(lblAnschluss, gbc_lblAnschluss); - - tfSerialPortName = new JTextField(); - tfSerialPortName.setToolTipText("\nAusgewählter Anschluss
\n
\nHier wird der momentan gewählte Anschluss gezeigt,
\ndurch den die Software mit dem Synololog kommuniziert.\n"); - tfSerialPortName.setEditable(false); - GridBagConstraints gbc_tfSerialPortName = new GridBagConstraints(); - gbc_tfSerialPortName.gridwidth = 3; - gbc_tfSerialPortName.insets = new Insets(0, 0, 5, 0); - gbc_tfSerialPortName.fill = GridBagConstraints.HORIZONTAL; - gbc_tfSerialPortName.gridx = 0; - gbc_tfSerialPortName.gridy = 1; - panel_1.add(tfSerialPortName, gbc_tfSerialPortName); - tfSerialPortName.setColumns(10); - - btnNewButton = new JButton("auswählen..."); - btnNewButton.setToolTipText("\nAuswahl eines anderen Anschlusses\n"); - btnNewButton.addActionListener(new ActionListener() { + bIntfAdd = new JButton("+"); + bIntfAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - chooseSerialPort(); + addInterface(); } }); + GridBagConstraints gbc_bIntfAdd = new GridBagConstraints(); + gbc_bIntfAdd.fill = GridBagConstraints.HORIZONTAL; + gbc_bIntfAdd.insets = new Insets(0, 0, 5, 5); + gbc_bIntfAdd.gridx = 0; + gbc_bIntfAdd.gridy = 0; + panel_1.add(bIntfAdd, gbc_bIntfAdd); + + bIntfDel = new JButton("-"); + bIntfDel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + removeInterface(); + } + }); + GridBagConstraints gbc_bIntfDel = new GridBagConstraints(); + gbc_bIntfDel.fill = GridBagConstraints.HORIZONTAL; + gbc_bIntfDel.insets = new Insets(0, 0, 5, 0); + gbc_bIntfDel.gridx = 1; + gbc_bIntfDel.gridy = 0; + panel_1.add(bIntfDel, gbc_bIntfDel); + + scrollPane_2 = new JScrollPane(); + scrollPane_2.setMinimumSize(new Dimension(22, 80)); + GridBagConstraints gbc_scrollPane_2 = new GridBagConstraints(); + gbc_scrollPane_2.gridwidth = 2; + gbc_scrollPane_2.fill = GridBagConstraints.BOTH; + gbc_scrollPane_2.insets = new Insets(0, 0, 5, 0); + gbc_scrollPane_2.gridx = 0; + gbc_scrollPane_2.gridy = 1; + panel_1.add(scrollPane_2, gbc_scrollPane_2); + + lInterfaces = new JList(lmInterfaces); + lInterfaces.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + selectedInterfaceChanged(); + } + }); + scrollPane_2.setViewportView(lInterfaces); cbTrimDevice = new JCheckBox("Trimmung justieren"); cbTrimDevice.setToolTipText("\nAbgleich der Zeitmessung
\n
\nDiese Funktion gleicht die Geschwindigkeit der Echtzeituhr des
\nSynololog mit der des Rechners ab und korrigiert diese Laufzeitdifferenz.
\n
\nHierdurch kann der Synololog auch ohne angeschlossenen Rechner über
\nmehrere Tage hinweg eine genaue Systemzeit vorhalten.
\n
\nDie Trimmung sollte vor allem dann ausgeführt werden, wenn die durchschnittliche
\nUmgebungstemperatur am Einsatzort des Synololog sich stark verändert.\n"); @@ -476,18 +440,38 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis } } }); + + panel_4 = new JPanel(); + panel_4.setBorder(new TitledBorder(null, "Anschlusseinstellungen", TitledBorder.LEADING, TitledBorder.TOP, null, null)); + GridBagConstraints gbc_panel_4 = new GridBagConstraints(); + gbc_panel_4.gridwidth = 2; + gbc_panel_4.insets = new Insets(0, 0, 5, 5); + gbc_panel_4.fill = GridBagConstraints.BOTH; + gbc_panel_4.gridx = 0; + gbc_panel_4.gridy = 2; + panel_1.add(panel_4, gbc_panel_4); + GridBagLayout gbl_panel_4 = new GridBagLayout(); + gbl_panel_4.columnWidths = new int[]{0, 0}; + gbl_panel_4.rowHeights = new int[]{0, 0}; + gbl_panel_4.columnWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_panel_4.rowWeights = new double[]{1.0, Double.MIN_VALUE}; + panel_4.setLayout(gbl_panel_4); + + tfConnectionSettings = new JTextField(); + tfConnectionSettings.setEditable(false); + GridBagConstraints gbc_tfConnectionSettings = new GridBagConstraints(); + gbc_tfConnectionSettings.fill = GridBagConstraints.BOTH; + gbc_tfConnectionSettings.gridx = 0; + gbc_tfConnectionSettings.gridy = 0; + panel_4.add(tfConnectionSettings, gbc_tfConnectionSettings); + tfConnectionSettings.setColumns(10); GridBagConstraints gbc_cbTrimDevice = new GridBagConstraints(); gbc_cbTrimDevice.anchor = GridBagConstraints.WEST; gbc_cbTrimDevice.insets = new Insets(0, 0, 5, 5); gbc_cbTrimDevice.gridx = 0; - gbc_cbTrimDevice.gridy = 2; + gbc_cbTrimDevice.gridy = 4; panel_1.add(cbTrimDevice, gbc_cbTrimDevice); - GridBagConstraints gbc_btnNewButton = new GridBagConstraints(); - gbc_btnNewButton.insets = new Insets(0, 0, 5, 0); - gbc_btnNewButton.gridx = 2; - gbc_btnNewButton.gridy = 2; - panel_1.add(btnNewButton, gbc_btnNewButton); tfConnection = new JTextField(); tfConnection.setHorizontalAlignment(SwingConstants.CENTER); @@ -496,9 +480,9 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis tfConnection.setEditable(false); GridBagConstraints gbc_tfConnection = new GridBagConstraints(); gbc_tfConnection.fill = GridBagConstraints.HORIZONTAL; - gbc_tfConnection.gridwidth = 3; + gbc_tfConnection.gridwidth = 2; gbc_tfConnection.gridx = 0; - gbc_tfConnection.gridy = 4; + gbc_tfConnection.gridy = 5; panel_1.add(tfConnection, gbc_tfConnection); tfConnection.setColumns(10); @@ -559,24 +543,57 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis } - private PulsCounter2Application application(){ - return PulsCounter2Application.getApplication(); + private PulsCounterApplication application(){ + return this.pulsCounterApplication; } - private void chooseSerialPort(){ - SerialPortChooser spc = new SerialPortChooser(); - NewSerialPort nsp = spc.execute( application().getSerialPort().getPortName() ); - if (nsp != null) - setSerialPort(nsp); + private void selectedInterfaceChanged(){ + selectedDeviceInterface = (IDeviceConnector)lInterfaces.getSelectedValue(); + + /* ToDO: GUI Update */ + if (selectedDeviceInterface == null){ + bIntfDel.setEnabled(false); + + tfConnectionSettings.setText(""); + } else { + bIntfDel.setEnabled(true); + + tfConnectionSettings.setText(selectedDeviceInterface.getConnectionSettingsText()); + } + + } + + + + @Override + public void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication) { + //lm.setItems(pulsCounterApplication.getInterfaceClasses()); + + } + + @Override + public void interfacesChanged(PulsCounterApplication pulsCounterApplication) { + lmInterfaces.setItems(pulsCounterApplication.getInterfaces()); + } + + + private void addInterface(){ + pulsCounterApplication.addInterface(pulsCounterApplication.getInterfaceClasses().get(0), ""); + + } + private void removeInterface(){ + if (selectedDeviceInterface != null){ + pulsCounterApplication.removeInterface(selectedDeviceInterface); + lInterfaces.clearSelection(); + } } private void setSerialPort(NewSerialPort serialPort){ - PulsCounter2Application.getApplication().setSerialPort(serialPort); + PulsCounterApplication.getApplication().setSerialPort(serialPort); } @Override public void serialPortChanged() { - tfSerialPortName.setText(application().getSerialPort().getPortName()); } @Override @@ -883,6 +900,15 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis } } + private void channelSetDescription(ChannelDisplay display){ + for (int n=0;n<32;n++){ + if (display == channelDisplays[n]){ + application().setChannelDescription(n, display.getDescriptionText()); + return; + } + } + } + private void channelReset(int channel,int setValue){ try {