WIP 20160908

WIP-PC2
Harald Wolff 2016-09-08 18:47:31 +02:00
parent ea5c02edc0
commit 876db0c37b
25 changed files with 1085 additions and 1680 deletions

View File

@ -3,9 +3,9 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo"/>
<classpathentry kind="lib" path="postgresql-9.1-901.jdbc4.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo.ui"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo.servicelink"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo.platform"/>
<classpathentry kind="lib" path="/data/src/java/external/hsqldb-2.3.4/hsqldb/lib/hsqldb.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ chnames.prop
*.dat
*.log
*.old
*.cfg

Binary file not shown.

View File

@ -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();
}
}

View File

@ -125,7 +125,7 @@ public class ExportSetting {
}
public void export(){
SnapshotManager ssm = PulsCounter2Application.getApplication().getSnapshotManager();
SnapshotManager ssm = PulsCounterApplication.getApplication().getSnapshotManager();
Hashtable<String, CSV> hash = new Hashtable<String, CSV>();

View File

@ -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<AppSettingsListener> appSettingsListeners;
private List<PulsCounterApplicationListener> applicationListeners;
private boolean snapshotLock;
private Vector<String> unseenMessages;
private SnapshotManager snapshotManager;
private List<ExportSetting> exportSettings;
private Scheduler scheduler;
public PulsCounter2Application() {
appSettingsListeners = new LinkedList<AppSettingsListener>();
applicationListeners = new LinkedList<PulsCounterApplicationListener>();
unseenMessages = new Vector<String>();
exportSettings = new LinkedList<ExportSetting>();
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<exportSettings.size();n++){
prefs.put(String.format("export.configuration.%d", n), ConfigurableObjects.getConfiguration(exportSettings.get(n)));
}
prefs.putInt("export.configurations", exportSettings.size());
};
try {
prefs.flush();
} catch (BackingStoreException e)
{
e.printStackTrace();
}
}
private void loadPrefs(){
Preferences prefs = getPreferencesNode();
String sn = prefs.get("io.port", null);
if (sn != null){
NewSerialPort nsp = new NewSerialPort(sn);
setSerialPort(nsp);
}
exportSettings.clear();
int nESC = prefs.getInt("export.configurations", 0);
for (int n=0;n<nESC;n++){
ExportSetting es = new ExportSetting();
ConfigurableObjects.setConfiguration(es, prefs.get(String.format("export.configuration.%d", n), ""));
exportSettings.add(es);
}
System.out.println(String.format("loadPrefs(): %d exportSettings geladen.", nESC));
}
@Override
public void connectionStateChanged(Boolean connected) {
fireConnectionStateChanged(connected);
}
public SnapshotManager getSnapshotManager() {
return snapshotManager;
}
public List<ExportSetting> getExportSettings() {
return exportSettings;
}
public void shutdown(){
System.err.println("Shutting down...");
this.scheduler.shutdown();
this.snapshotManager.doShutdown();
TaskletManager.instance().shutdown();
this.getServiceLink().close();
}
}

View File

@ -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<IDeviceConnector> deviceConnectors;
private Object uiSynchronization;
private boolean uiIsFinished;
private boolean shouldSaveConfiguration;
private List<PulsCounterApplicationListener>
applicationListeners;
private Vector<String> unseenMessages;
private List<Class<IDeviceConnector>>
interfaceClasses;
private List<IDeviceConnector> interfaces;
private NewSerialPort serialPort;
private ServiceLink serviceLink;
private List<AppSettingsListener> appSettingsListeners;
private boolean snapshotLock;
private SnapshotManager snapshotManager;
private List<ExportSetting> 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<PulsCounterApplicationListener>();
unseenMessages = new Vector<String>();
interfaceClasses = new ArrayList<>();
interfaces = new ArrayList<>();
/* Prepare for Startup */
loadApplicationConfiguration();
/* Parse Command Line Arguments */
Iterator<String> 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<IDeviceConnector> clazz = (Class<IDeviceConnector>)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<nIntf;n++){
Class<IDeviceConnector> 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<interfaces.size();n++){
applicationConfiguration.setProperty(String.format("interfaces.%d.class", n), interfaces.get(0).getClass().getCanonicalName());
applicationConfiguration.setProperty(String.format("interfaces.%d.settings", n), interfaces.get(0).getConnectionSettings());
}
try {
log(INFO,"Save application configuration");
FileOutputStream fos = new FileOutputStream("synololog.cfg");
applicationConfiguration.storeToXML(fos, "Synololog Application Configuration");
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
log(ERROR,"synololog.cfg could not be created/opened for writing");
} catch (IOException e) {
log(ERROR,"synololog.cfg could not be written");
}
}
/*
this.scheduler.shutdown();
this.snapshotManager.doShutdown();
TaskletManager.instance().shutdown();
this.getServiceLink().close();
this.savePrefs();
*/
}
private void waitUiFinished(){
synchronized (uiSynchronization) {
while (!uiIsFinished){
try {
uiSynchronization.wait(250);
} catch (InterruptedException e){
log(e);
}
}
}
log(INFO,"UI notified finish");
}
public void notifyUiIsFinished(boolean saveApplicationConfiguration){
synchronized (uiSynchronization) {
uiIsFinished = true;
shouldSaveConfiguration = saveApplicationConfiguration;
uiSynchronization.notify();
}
}
/* Interface Types */
public List<Class<IDeviceConnector>> getInterfaceClasses(){
return this.interfaceClasses;
}
private Class<IDeviceConnector> getInterfaceClass(String className){
for (Class<IDeviceConnector> c:interfaceClasses){
if (c.getCanonicalName().equals(className))
return c;
}
return null;
}
/* Physical Interfaces */
public List<IDeviceConnector> getInterfaces(){
return this.interfaces;
}
public void addInterface(Class<IDeviceConnector> 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<AppSettingsListener>();
exportSettings = new LinkedList<ExportSetting>();
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<exportSettings.size();n++){
prefs.put(String.format("export.configuration.%d", n), ConfigurableObjects.getConfiguration(exportSettings.get(n)));
}
prefs.putInt("export.configurations", exportSettings.size());
};
Preferences nChannels = prefs.node("channels");
for (int n=0;n<32;n++){
nChannels.put(String.format("%d.description", n), channelDescriptions[n]);
}
try {
prefs.flush();
} catch (BackingStoreException e)
{
e.printStackTrace();
}
}
private void loadPrefs(){
Preferences prefs = getPreferencesNode();
String sn = prefs.get("io.port", null);
if (sn != null){
NewSerialPort nsp = new NewSerialPort(sn);
setSerialPort(nsp);
}
exportSettings.clear();
int nESC = prefs.getInt("export.configurations", 0);
for (int n=0;n<nESC;n++){
ExportSetting es = new ExportSetting();
ConfigurableObjects.setConfiguration(es, prefs.get(String.format("export.configuration.%d", n), ""));
exportSettings.add(es);
}
System.out.println(String.format("loadPrefs(): %d exportSettings geladen.", nESC));
Preferences nChannels = prefs.node("channels");
for (int n=0;n<32;n++){
channelDescriptions[n] = nChannels.get(String.format("%d.description", n), "");
}
}
public String getChannelDescription(int n){
return ""; // channelDescriptions[n];
}
public void setChannelDescription(int n,String desc){
channelDescriptions[n] = desc;
}
@Override
public void connectionStateChanged(Boolean connected) {
fireConnectionStateChanged(connected);
}
public SnapshotManager getSnapshotManager() {
return snapshotManager;
}
public List<ExportSetting> getExportSettings() {
return exportSettings;
}
}

View File

@ -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);

View File

@ -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){

View File

@ -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<WorkShift> workShifts;
Connection db;
public InspectorApplication(){
workShifts = new LinkedList<WorkShift>();
/*
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", );
***/

View File

@ -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);
}

View File

@ -0,0 +1,5 @@
package org.hwo.pulscounter.device;
public class NoDeviceConnectionException extends RuntimeException {
}

View File

@ -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
}
}

View File

@ -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(){

View File

@ -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<ssm.size();n++){
SnapShot ss = ssm.loadSnapShot(n);

View File

@ -1,31 +1,34 @@
package org.hwo.pulscounter.ui;
import org.hwo.pulscounter.ExportSetting;
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;
public class BatchRunner implements PulsCounterApplicationListener{
public PulsCounter2Application application(){
return PulsCounter2Application.getApplication();
}
private PulsCounterApplication pulsCounterApplication;
public BatchRunner(){
public BatchRunner(PulsCounterApplication pulsCounterApplication){
this.pulsCounterApplication = pulsCounterApplication;
application().addPulsCounterApplicationListener(this);
pulsCounterApplication.addPulsCounterApplicationListener(this);
pulsCounterApplication.notifyUiIsFinished(true);
// run();
}
public void run(){
try {
application().getServiceLink().open();
pulsCounterApplication.getServiceLink().open();
Thread.sleep(500);
application().getSnapshotManager().doFullSync();
pulsCounterApplication.getSnapshotManager().doFullSync();
for (ExportSetting es: application().getExportSettings()){
for (ExportSetting es: pulsCounterApplication.getExportSettings()){
if (es.getAutostart()){
es.export();
}
@ -37,9 +40,8 @@ public class BatchRunner implements PulsCounterApplicationListener{
// TODO Auto-generated catch block
e.printStackTrace();
}
application().shutdown();
pulsCounterApplication.notifyUiIsFinished(false);
}
@Override
@ -57,6 +59,18 @@ public class BatchRunner implements PulsCounterApplicationListener{
public void messageArrived(String message) {
System.err.println(message);
}
@Override
public void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication) {
// TODO Auto-generated method stub
}
@Override
public void interfacesChanged(PulsCounterApplication pulsCounterApplication) {
// TODO Auto-generated method stub
}

View File

@ -57,6 +57,7 @@ public class ChannelDisplay extends JPanel {
private JPopupMenu popupMenu;
private List<ChannelDisplayListener> 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("<html>\n<b>Analog Messwert</b><br/>\n<br/>\nZeigt die an diesem Kanal gemessene Spannung.\n</html>");
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("<html>\n<b>Ausgang</b><br/>\n<br/>\nZeigt, ob die Ausgangsschaltung für diesen Kanal aktiv ist.\n</html>");
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("<html>\n<b>Analog Messwert</b><br/>\n<br/>\nZeigt die an diesem Kanal gemessene Spannung.\n</html>");
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();
}
}

View File

@ -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);
}

View File

@ -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<WorkShiftRecord.ChannelRecords.ChannelRecord> 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<WorkShiftRecord.ChannelRecords.ChannelRecord>());
cbChannel.setItems(workShiftRecord.getChannels());
selectedWorkShift = workShiftRecord;
}
void selectChannel(){
if (selectedWorkShift != null){
Integer ch = (Integer)cbChannel.getSelectedItem();
flexibleJTable.setRows(selectedWorkShift.getChannelRecords(ch).getRecords());
}
}
}

View File

@ -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);

View File

@ -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<String> 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
}
}

View File

@ -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();

View File

@ -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<shifts.length;s++){
System.out.println(shifts[s].getName() + ": " + shifts[s].getShiftBegins(d).getSQLDateTime() + " - " + shifts[s].getShiftEnds(d).getSQLDateTime() );
}
}
}
});
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
gbc_btnNewButton.gridx = 0;
gbc_btnNewButton.gridy = 0;
panel.add(btnNewButton, gbc_btnNewButton);
JPanel panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(null, "Einstellungen", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
gbc_panel_1.fill = GridBagConstraints.BOTH;
gbc_panel_1.gridx = 0;
gbc_panel_1.gridy = 1;
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[]{0.0, Double.MIN_VALUE};
gbl_panel_1.rowWeights = new double[]{0.0, Double.MIN_VALUE};
panel_1.setLayout(gbl_panel_1);
JButton btnSchichten = new JButton("Schichten");
btnSchichten.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
GridBagConstraints gbc_btnSchichten = new GridBagConstraints();
gbc_btnSchichten.gridx = 0;
gbc_btnSchichten.gridy = 0;
panel_1.add(btnSchichten, gbc_btnSchichten);
}
}

View File

@ -1,664 +0,0 @@
package org.hwo.pulscounter.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.border.EmptyBorder;
import org.hwo.datetime.JTimeOfDay;
import org.hwo.io.SerialPortExeption;
import org.hwo.servicelink.ServiceLink;
import org.hwo.servicelink.ServiceLinkException;
import org.hwo.servicelink.ServiceLinkRequestFailedException;
import org.hwo.ui.MousePopupListener;
import org.hwo.pulscounter.CounterChannel;
import org.hwo.pulscounter.PulsCounter2Application;
import org.postgresql.util.UnixCrypt;
import java.awt.GridBagLayout;
import java.io.IOException;
import java.io.ObjectOutputStream.PutField;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JToggleButton;
import javax.swing.SwingConstants;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.border.TitledBorder;
import java.awt.GridLayout;
import javax.swing.JTextField;
import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.border.LineBorder;
public class LiveViewFrame extends JFrame implements AppSettingsListener {
private JPanel contentPane;
private Timer liveViewTimer;
private ServiceLink serviceLink;
private JLabel[] inputButtons;
private JToggleButton[] pullupButtons;
private JToggleButton[] outputButtons;
private JLabel[] analogLabels;
private JPanel pDisplay;
private JPanel pPullups;
private JPanel pAnalog;
private JPanel pOutputs;
private Integer pinputs,
inputs,
outputs,
pullups;
private JPanel pDateTime;
private JLabel lblUnixZeitstempel;
private JTextField tfUnixTime;
private JLabel lblAktuellesDatum;
private JTextField tfHumanDateTime;
private JButton btnSynchronisieren;
private JPanel panel;
private JScrollPane scrollPane;
private JList lMessages;
private JPanel panel_1;
private JButton btnSnapshot;
private JButton btnLeeren;
private JButton btnLaufzeitKorrigieren;
/**
* Create the frame.
*/
public LiveViewFrame() {
setTitle("Live Ansicht");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 1037, 875);
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, 0, 0, 0, 0};
gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
gbl_contentPane.rowWeights = new double[]{1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
contentPane.setLayout(gbl_contentPane);
pDisplay = new JPanel();
pDisplay.setBorder(new TitledBorder(null, "Eing\u00E4nge", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GridBagConstraints gbc_pDisplay = new GridBagConstraints();
gbc_pDisplay.insets = new Insets(0, 0, 5, 0);
gbc_pDisplay.fill = GridBagConstraints.BOTH;
gbc_pDisplay.gridx = 0;
gbc_pDisplay.gridy = 0;
contentPane.add(pDisplay, gbc_pDisplay);
GridBagLayout gbl_pDisplay = new GridBagLayout();
gbl_pDisplay.columnWidths = new int[] {50, 50, 50, 50, 50, 50, 50, 50};
gbl_pDisplay.rowHeights = new int[] {25, 25, 25, 25};
gbl_pDisplay.columnWeights = new double[]{1.0, 1.0,1.0, 1.0,1.0, 1.0,1.0, 1.0};
gbl_pDisplay.rowWeights = new double[]{1.0, 1.0,1.0, 1.0};
pDisplay.setLayout(gbl_pDisplay);
pPullups = new JPanel();
pPullups.setBorder(new TitledBorder(null, "PullUPs", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GridBagConstraints gbc_pPullups = new GridBagConstraints();
gbc_pPullups.insets = new Insets(0, 0, 5, 0);
gbc_pPullups.fill = GridBagConstraints.BOTH;
gbc_pPullups.gridx = 0;
gbc_pPullups.gridy = 1;
contentPane.add(pPullups, gbc_pPullups);
GridBagLayout gbl_pPullups = new GridBagLayout();
gbl_pPullups.columnWidths = new int[] {50, 50, 50, 50, 50, 50, 50, 50};
gbl_pPullups.rowHeights = new int[] {25, 25, 25, 25};
gbl_pPullups.columnWeights = new double[]{1.0, 1.0,1.0, 1.0,1.0, 1.0,1.0, 1.0};
gbl_pPullups.rowWeights = new double[]{1.0, 1.0,1.0, 1.0};
pPullups.setLayout(gbl_pPullups);
pOutputs = new JPanel();
pOutputs.setBorder(new TitledBorder(null, "Ausg\u00E4nge", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GridBagConstraints gbc_pOutputs = new GridBagConstraints();
gbc_pOutputs.insets = new Insets(0, 0, 5, 0);
gbc_pOutputs.fill = GridBagConstraints.BOTH;
gbc_pOutputs.gridx = 0;
gbc_pOutputs.gridy = 2;
contentPane.add(pOutputs, gbc_pOutputs);
GridBagLayout gbl_pOutputs = new GridBagLayout();
gbl_pOutputs.columnWidths = new int[] {50, 50, 50, 50, 50, 50, 50, 50};
gbl_pOutputs.rowHeights = new int[] {25, 25, 25, 25};
gbl_pOutputs.columnWeights = new double[]{1.0, 1.0,1.0, 1.0,1.0, 1.0,1.0, 1.0};
gbl_pOutputs.rowWeights = new double[]{1.0, 1.0,1.0, 1.0};
pOutputs.setLayout(gbl_pOutputs);
pAnalog = new JPanel();
pAnalog.setBorder(new TitledBorder(null, "Analogkan\u00E4le", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GridBagConstraints gbc_pAnalog = new GridBagConstraints();
gbc_pAnalog.insets = new Insets(0, 0, 5, 0);
gbc_pAnalog.fill = GridBagConstraints.BOTH;
gbc_pAnalog.gridx = 0;
gbc_pAnalog.gridy = 3;
contentPane.add(pAnalog, gbc_pAnalog);
pAnalog.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
pDateTime = new JPanel();
pDateTime.setBorder(new TitledBorder(null, "Datum und Zeit", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GridBagConstraints gbc_pDateTime = new GridBagConstraints();
gbc_pDateTime.insets = new Insets(0, 0, 5, 0);
gbc_pDateTime.fill = GridBagConstraints.BOTH;
gbc_pDateTime.gridx = 0;
gbc_pDateTime.gridy = 4;
contentPane.add(pDateTime, gbc_pDateTime);
GridBagLayout gbl_pDateTime = new GridBagLayout();
gbl_pDateTime.columnWidths = new int[]{0, 0, 0, 0, 0};
gbl_pDateTime.rowHeights = new int[]{0, 0, 0};
gbl_pDateTime.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
gbl_pDateTime.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
pDateTime.setLayout(gbl_pDateTime);
lblUnixZeitstempel = new JLabel("Unix Zeitstempel:");
GridBagConstraints gbc_lblUnixZeitstempel = new GridBagConstraints();
gbc_lblUnixZeitstempel.insets = new Insets(0, 0, 5, 5);
gbc_lblUnixZeitstempel.anchor = GridBagConstraints.EAST;
gbc_lblUnixZeitstempel.gridx = 0;
gbc_lblUnixZeitstempel.gridy = 0;
pDateTime.add(lblUnixZeitstempel, gbc_lblUnixZeitstempel);
tfUnixTime = new JTextField();
GridBagConstraints gbc_tfUnixTime = new GridBagConstraints();
gbc_tfUnixTime.insets = new Insets(0, 0, 5, 5);
gbc_tfUnixTime.fill = GridBagConstraints.HORIZONTAL;
gbc_tfUnixTime.gridx = 1;
gbc_tfUnixTime.gridy = 0;
pDateTime.add(tfUnixTime, gbc_tfUnixTime);
tfUnixTime.setColumns(10);
lblAktuellesDatum = new JLabel("Aktuelles Datum:");
GridBagConstraints gbc_lblAktuellesDatum = new GridBagConstraints();
gbc_lblAktuellesDatum.insets = new Insets(0, 0, 5, 5);
gbc_lblAktuellesDatum.anchor = GridBagConstraints.EAST;
gbc_lblAktuellesDatum.gridx = 2;
gbc_lblAktuellesDatum.gridy = 0;
pDateTime.add(lblAktuellesDatum, gbc_lblAktuellesDatum);
tfHumanDateTime = new JTextField();
GridBagConstraints gbc_tfHumanDateTime = new GridBagConstraints();
gbc_tfHumanDateTime.insets = new Insets(0, 0, 5, 0);
gbc_tfHumanDateTime.fill = GridBagConstraints.HORIZONTAL;
gbc_tfHumanDateTime.gridx = 3;
gbc_tfHumanDateTime.gridy = 0;
pDateTime.add(tfHumanDateTime, gbc_tfHumanDateTime);
tfHumanDateTime.setColumns(10);
btnSynchronisieren = new JButton("Synchronisieren");
btnSynchronisieren.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
syncUnixTime();
}
});
GridBagConstraints gbc_btnSynchronisieren = new GridBagConstraints();
gbc_btnSynchronisieren.insets = new Insets(0, 0, 0, 5);
gbc_btnSynchronisieren.gridx = 1;
gbc_btnSynchronisieren.gridy = 1;
pDateTime.add(btnSynchronisieren, gbc_btnSynchronisieren);
btnLaufzeitKorrigieren = new JButton("Laufzeit korrigieren");
btnLaufzeitKorrigieren.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
quartzCorrect();
}
});
GridBagConstraints gbc_btnLaufzeitKorrigieren = new GridBagConstraints();
gbc_btnLaufzeitKorrigieren.gridx = 3;
gbc_btnLaufzeitKorrigieren.gridy = 1;
pDateTime.add(btnLaufzeitKorrigieren, gbc_btnLaufzeitKorrigieren);
panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), "Kommandos", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51)));
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
gbc_panel_1.fill = GridBagConstraints.BOTH;
gbc_panel_1.insets = new Insets(0, 0, 5, 0);
gbc_panel_1.gridx = 0;
gbc_panel_1.gridy = 5;
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[]{0.0, Double.MIN_VALUE};
gbl_panel_1.rowWeights = new double[]{0.0, Double.MIN_VALUE};
panel_1.setLayout(gbl_panel_1);
btnSnapshot = new JButton("SnapShot");
btnSnapshot.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
manualSnapshot();
}
});
GridBagConstraints gbc_btnSnapshot = new GridBagConstraints();
gbc_btnSnapshot.gridx = 0;
gbc_btnSnapshot.gridy = 0;
panel_1.add(btnSnapshot, gbc_btnSnapshot);
panel = new JPanel();
panel.setBorder(new TitledBorder(null, "Meldungen", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GridBagConstraints gbc_panel = new GridBagConstraints();
gbc_panel.fill = GridBagConstraints.BOTH;
gbc_panel.gridx = 0;
gbc_panel.gridy = 6;
contentPane.add(panel, gbc_panel);
GridBagLayout gbl_panel = new GridBagLayout();
gbl_panel.columnWidths = new int[]{383, 0};
gbl_panel.rowHeights = new int[]{0, 131, 0, 0};
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
gbl_panel.rowWeights = new double[]{1.0, 1.0, 0.0, Double.MIN_VALUE};
panel.setLayout(gbl_panel);
scrollPane = new JScrollPane();
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
gbc_scrollPane.fill = GridBagConstraints.BOTH;
gbc_scrollPane.gridx = 0;
gbc_scrollPane.gridy = 1;
panel.add(scrollPane, gbc_scrollPane);
lMessages = new JList();
scrollPane.setViewportView(lMessages);
btnLeeren = new JButton("leeren");
btnLeeren.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
((DefaultListModel)lMessages.getModel()).clear();
}
});
GridBagConstraints gbc_btnLeeren = new GridBagConstraints();
gbc_btnLeeren.gridx = 0;
gbc_btnLeeren.gridy = 2;
panel.add(btnLeeren, gbc_btnLeeren);
initialize();
}
@Override
public void dispose() {
PulsCounter2Application pc2a = PulsCounter2Application.getApplication();
pc2a.removeAppSettingsListener(this);
liveViewTimer.cancel();
super.dispose();
}
private void initialize(){
PulsCounter2Application pc2a = PulsCounter2Application.getApplication();
lMessages.setModel(new DefaultListModel<String>());
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<<i))!=0){
inputButtons[i].setBackground(Color.GREEN);
} else {
inputButtons[i].setBackground(Color.WHITE);
}
if (values[i] != null){
inputButtons[i].setText(String.format("<html><center>%d<br/>[%d]</center></html>", i, values[i]));
} else {
inputButtons[i].setText(String.format("<html><center>%d<br/>N.A.</center></html>", i));
};
if ((outputs & (1<<i))!=0){
outputButtons[i].setBackground(Color.GREEN);
outputButtons[i].setSelected(true);
} else {
outputButtons[i].setBackground(Color.WHITE);
outputButtons[i].setSelected(false);
}
if ((pullups & (1<<i))!=0){
pullupButtons[i].setBackground(Color.BLUE);
pullupButtons[i].setSelected(true);
} else {
pullupButtons[i].setBackground(Color.WHITE);
pullupButtons[i].setSelected(false);
}
}
for (int i=0;i<8;i++){
Float analog = serviceLink.getServiceRegisterCache().getCachedFloat(13, 0, 0x8000 + i );
if (analog != null){
analogLabels[i].setText(String.format("%5.3fV", (analog * 10.0f)));
}
}
Integer assert_error,assert_code;
try
{
assert_error = -1;
for (int i=0;i<8;i++){
assert_error = serviceLink.readInt(13, 0, 0x0026);
assert_code = serviceLink.readInt(13, 0, 0x0025);
if (assert_error >= 0)
break;
DefaultListModel<String> lm = (DefaultListModel<String>)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<<ch);
} else {
pullups &= ~(1<<ch);
}
try {
serviceLink.writeInt((byte)13, (byte)0, 0x0683, pullups);
} catch (ServiceLinkRequestFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceLinkException e) {
e.printStackTrace();
}
}
}
private void syncUnixTime(){
Calendar calendar = Calendar.getInstance();
if (this.serviceLink != null){
try {
this.serviceLink.writeInt((byte)13, (byte)0, 0x001C, (int)(calendar.getTimeInMillis() / 1000L));
} catch (ServiceLinkRequestFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceLinkException e) {
e.printStackTrace();
}
}
}
private void manualSnapshot(){
if (this.serviceLink != null){
try {
Integer emask = this.serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x9001);
System.err.println(String.format("EMASK: 0x%08x", emask));
this.serviceLink.writeInt((byte)13, (byte)0, 0x1001, 2);
} catch (ServiceLinkRequestFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceLinkException e) {
e.printStackTrace();
}
}
}
private void message(String msg){
((DefaultListModel<String>)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();
}
};
}
}

View File

@ -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<Class<IDeviceConnector>>
lmInterfaceClasses = new FlexibleObjectListModel<>();
private FlexibleObjectListModel<IDeviceConnector>
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<String> 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("<html>\n<b>Ausgewählter Anschluss</b><br/>\n<br/>\nHier wird der momentan gewählte Anschluss gezeigt,<br/>\ndurch den die Software mit dem Synololog kommuniziert.\n</html>");
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("<html>\n<b>Auswahl eines anderen Anschlusses</b>\n</html>");
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("<html>\n<b>Abgleich der Zeitmessung</b><br/>\n<br/>\nDiese Funktion gleicht die Geschwindigkeit der Echtzeituhr des<br/>\nSynololog mit der des Rechners ab und korrigiert diese Laufzeitdifferenz.<br/>\n<br/>\nHierdurch kann der Synololog auch ohne angeschlossenen Rechner über<br/>\nmehrere Tage hinweg eine genaue Systemzeit vorhalten.<br/>\n<br/>\nDie Trimmung sollte vor allem dann ausgeführt werden, wenn die durchschnittliche<br/>\nUmgebungstemperatur am Einsatzort des Synololog sich stark verändert.\n</html>");
@ -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 {