2016-09-06 16:49:11 +02:00
package org.hwo.pulscounter.ui ;
import java.awt.EventQueue ;
import javax.swing.JFrame ;
import java.awt.GridBagLayout ;
import java.awt.BorderLayout ;
import javax.swing.JToolBar ;
import javax.swing.JSplitPane ;
2016-09-09 00:57:02 +02:00
import javax.swing.JTextArea ;
2016-09-06 16:49:11 +02:00
import javax.swing.JPanel ;
import java.awt.GridBagConstraints ;
import javax.swing.border.TitledBorder ;
import org.hwo.Smoother ;
import org.hwo.datetime.DateTime ;
import org.hwo.io.NewSerialPort.NewSerialPort ;
import org.hwo.logging.Logging ;
2016-09-08 18:47:31 +02:00
import org.hwo.models.FlexibleObjectListModel ;
2016-09-06 16:49:11 +02:00
import org.hwo.platform.Platform ;
2016-09-08 18:47:31 +02:00
import org.hwo.pulscounter.PulsCounterApplication ;
2016-09-06 16:49:11 +02:00
import org.hwo.pulscounter.PulsCounterApplicationListener ;
2016-09-08 18:47:31 +02:00
import org.hwo.pulscounter.device.IDeviceConnector ;
2016-09-09 00:57:02 +02:00
import org.hwo.pulscounter.device.NoDeviceConnectionException ;
2016-09-13 10:53:46 +02:00
import org.hwo.pulscounter.device.ServiceLinkDeviceConnector ;
2016-09-06 16:49:11 +02:00
import org.hwo.servicelink.ServiceLinkException ;
import org.hwo.servicelink.ServiceLinkRequestFailedException ;
import org.hwo.tasklet.Tasklet ;
import org.hwo.tasklet.TaskletListener ;
import org.hwo.tasklet.TaskletManager ;
2016-09-09 00:57:02 +02:00
import org.hwo.ui.JObjectSelector ;
2016-09-06 16:49:11 +02:00
import org.hwo.ui.dialog.SerialPortChooser ;
import org.omg.CORBA.Environment ;
import javax.swing.JLabel ;
import javax.swing.JTextField ;
import java.awt.Insets ;
import javax.swing.DefaultListModel ;
import javax.swing.JButton ;
import java.awt.event.ActionListener ;
import java.awt.event.KeyEvent ;
import java.awt.event.WindowEvent ;
import java.awt.event.WindowListener ;
import java.awt.event.WindowStateListener ;
import java.io.IOException ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Calendar ;
import java.util.Enumeration ;
import java.util.Iterator ;
import java.util.List ;
import java.util.Timer ;
import java.util.TimerTask ;
import java.awt.event.ActionEvent ;
import java.awt.Color ;
import java.awt.Dialog.ModalityType ;
import javax.swing.JScrollPane ;
import javax.swing.JList ;
import java.awt.Font ;
import javax.swing.SwingConstants ;
import javax.swing.ToolTipManager ;
import javax.swing.UIManager ;
import javax.swing.UnsupportedLookAndFeelException ;
import java.awt.Dimension ;
import javax.swing.BoxLayout ;
import javax.swing.border.EmptyBorder ;
import javax.swing.JCheckBox ;
import javax.swing.event.ChangeListener ;
import javax.swing.plaf.metal.MetalBorders.ToolBarBorder ;
import javax.swing.event.ChangeEvent ;
import static org.hwo.logging.Logging.log ;
2016-09-09 00:57:02 +02:00
import static org.hwo.logging.LogLevel.* ;
2016-09-08 18:47:31 +02:00
import javax.swing.event.ListSelectionListener ;
import javax.swing.event.ListSelectionEvent ;
2016-09-09 00:57:02 +02:00
import java.awt.event.MouseAdapter ;
import java.awt.event.MouseEvent ;
import java.awt.event.WindowAdapter ;
2016-09-06 16:49:11 +02:00
public class NewMainWindow implements PulsCounterApplicationListener , TaskletListener {
2016-09-08 18:47:31 +02:00
private PulsCounterApplication pulsCounterApplication ;
private IDeviceConnector selectedDeviceInterface ;
private FlexibleObjectListModel < Class < IDeviceConnector > >
lmInterfaceClasses = new FlexibleObjectListModel < > ( ) ;
private FlexibleObjectListModel < IDeviceConnector >
lmInterfaces = new FlexibleObjectListModel < > ( ) ;
2016-09-09 00:57:02 +02:00
private BackgroundThread backgroundThread ;
2016-09-06 16:49:11 +02:00
private JFrame frmSynolog ;
private JSplitPane splitter ;
private JButton btnSetup ;
private DefaultListModel < String > messageListModel ;
private JList lMessages ;
private Timer timerReconnect ;
private JPanel pChannels ;
private ChannelDisplay [ ] channelDisplays ;
private JButton btnC ;
private JPanel panel_3 ;
private JScrollPane scrollPane_1 ;
private JList lTasklets ;
private DefaultListModel < Tasklet > knownTasklets ;
private Boolean connected ;
private JButton btnDatenExportieren ;
private Integer trimTicksOnConnect ;
private Long trimTimeOnConnect ;
private Integer trimDeviceTimeSlice ;
private JCheckBox cbTrimDevice ;
private Smoother smoothTrim ;
2016-09-08 18:47:31 +02:00
private JList lInterfaces ;
private JScrollPane scrollPane_2 ;
private JButton bIntfAdd ;
private JButton bIntfDel ;
private JPanel panel_4 ;
2016-09-09 00:57:02 +02:00
private JTextArea tfConnectionSettings ;
2016-09-06 16:49:11 +02:00
2016-09-08 18:47:31 +02:00
2016-09-06 16:49:11 +02:00
public static void startGUI ( ) {
try {
// Set cross-platform Java L&F (also called "Metal")
UIManager . setLookAndFeel (
UIManager . getCrossPlatformLookAndFeelClassName ( ) ) ;
}
catch ( UnsupportedLookAndFeelException e ) {
// handle exception
}
catch ( ClassNotFoundException e ) {
// handle exception
}
catch ( InstantiationException e ) {
// handle exception
}
catch ( IllegalAccessException e ) {
// handle exception
}
ToolTipManager . sharedInstance ( ) . setDismissDelay ( 20000 ) ;
ToolTipManager . sharedInstance ( ) . setInitialDelay ( 1250 ) ;
ToolTipManager . sharedInstance ( ) . setReshowDelay ( 500 ) ;
2016-09-08 18:47:31 +02:00
}
2016-09-06 16:49:11 +02:00
/ * *
* @wbp.parser.entryPoint
* /
2016-09-08 18:47:31 +02:00
public NewMainWindow ( PulsCounterApplication pulsCounterApplication ) {
startGUI ( ) ;
this . pulsCounterApplication = pulsCounterApplication ;
2016-09-06 16:49:11 +02:00
initialize ( ) ;
2016-09-08 18:47:31 +02:00
initializeChannelPanels ( ) ;
pulsCounterApplication . addPulsCounterApplicationListener ( this ) ;
if ( false ) {
2016-09-06 16:49:11 +02:00
2016-09-13 12:07:01 +02:00
this . connected = false ;
2016-09-06 16:49:11 +02:00
2016-09-13 12:07:01 +02:00
knownTasklets = new DefaultListModel < Tasklet > ( ) ;
lTasklets . setModel ( knownTasklets ) ;
TaskletManager . instance ( ) . addTaskletListener ( this ) ;
2016-09-06 16:49:11 +02:00
2016-09-13 12:07:01 +02:00
messageListModel = new DefaultListModel < String > ( ) ;
lMessages . setModel ( messageListModel ) ;
timerReconnect = new Timer ( "ReconnectThread" , true ) ;
application ( ) . addPulsCounterApplicationListener ( this ) ;
application ( ) . message ( "Synololog Applikation wurde gestartet." ) ;
2016-09-06 16:49:11 +02:00
2016-09-08 18:47:31 +02:00
}
2016-09-09 00:57:02 +02:00
frmSynolog . addWindowListener ( new WindowAdapter ( ) {
2016-09-06 16:49:11 +02:00
@Override
public void windowClosed ( WindowEvent e ) {
2016-09-09 00:57:02 +02:00
backgroundThread . exit ( ) ;
application ( ) . notifyUiIsFinished ( true ) ;
2016-09-06 16:49:11 +02:00
}
} ) ;
2016-09-09 00:57:02 +02:00
//lmInterfaces.setItems(pulsCounterApplication.getInterfaces());
if ( pulsCounterApplication . getInterfaces ( ) . size ( ) > 0 ) {
interfacesChanged ( pulsCounterApplication ) ;
lInterfaces . setSelectedIndex ( 0 ) ;
}
backgroundThread = new BackgroundThread ( ) ;
backgroundThread . start ( ) ;
2016-09-08 18:47:31 +02:00
frmSynolog . setVisible ( true ) ;
2016-09-06 16:49:11 +02:00
}
2016-09-08 18:47:31 +02:00
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 ) {
2016-09-13 10:53:46 +02:00
if ( descriptionText . startsWith ( "!\"§$%" ) ) {
if ( selectedDeviceInterface ! = null ) {
if ( ServiceLinkDeviceConnector . class . isInstance ( selectedDeviceInterface ) ) {
ServiceLinkDeviceConnector dc = ( ServiceLinkDeviceConnector ) selectedDeviceInterface ;
dc . setDeviceSerial ( Integer . parseInt ( descriptionText . substring ( 5 ) ) ) ;
}
}
}
2016-09-08 18:47:31 +02:00
}
} ) ;
pChannels . add ( channelDisplays [ i ] , gbc ) ;
}
}
2016-09-06 16:49:11 +02:00
/ * *
* Initialize the contents of the frame .
* /
private void initialize ( ) {
frmSynolog = new JFrame ( ) ;
frmSynolog . setTitle ( "Synololog" ) ;
frmSynolog . setBounds ( 100 , 100 , 1000 , 580 ) ;
2016-09-08 18:47:31 +02:00
frmSynolog . setDefaultCloseOperation ( JFrame . DISPOSE_ON_CLOSE ) ;
2016-09-06 16:49:11 +02:00
frmSynolog . getContentPane ( ) . setLayout ( new BorderLayout ( 0 , 0 ) ) ;
frmSynolog . setBackground ( Color . WHITE ) ;
JToolBar toolBar = new JToolBar ( ) ;
toolBar . setBorder ( new EmptyBorder ( 3 , 3 , 3 , 3 ) ) ;
toolBar . setBackground ( Color . WHITE ) ;
toolBar . setFloatable ( false ) ;
frmSynolog . getContentPane ( ) . add ( toolBar , BorderLayout . NORTH ) ;
btnSetup = new JButton ( "S" ) ;
btnSetup . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
AppSettingsFrame asf = new AppSettingsFrame ( ) ;
asf . setModalityType ( ModalityType . APPLICATION_MODAL ) ;
2016-09-13 12:07:01 +02:00
// if ((e.getModifiers() & ActionEvent.CTRL_MASK) != 0)
// asf.debugging();
2016-09-06 16:49:11 +02:00
asf . setVisible ( true ) ;
}
} ) ;
btnSetup . setToolTipText ( "<html>\n<b>Einstellungen</b><br/>\n<br/>\nEinstellungen der Synololog PC Software ändern.\n</html>" ) ;
toolBar . add ( btnSetup ) ;
btnC = new JButton ( "C" ) ;
btnC . setToolTipText ( "<html>\n<b>Konfiguration</b><br/>\n<br/>\nKonfiguration des Synololog bearbeiten.\n</html>" ) ;
btnC . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
DeviceConfiguration cc = new DeviceConfiguration ( ) ;
cc . setVisible ( true ) ;
}
} ) ;
toolBar . add ( btnC ) ;
btnDatenExportieren = new JButton ( "Daten exportieren..." ) ;
btnDatenExportieren . setToolTipText ( "<html>\n<b>Daten exportieren</b><br/>\n<br/>\nExport definitionen bearbeiten und ausführen.<br/>\nHiermit können die Aufzeichnungsdaten in Textdateien exportiert werden.<br/>\n</html>" ) ;
btnDatenExportieren . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
ExportFilesFrame eff = new ExportFilesFrame ( ) ;
eff . setVisible ( true ) ;
}
} ) ;
toolBar . add ( btnDatenExportieren ) ;
splitter = new JSplitPane ( ) ;
splitter . setBorder ( null ) ;
splitter . setOneTouchExpandable ( true ) ;
splitter . setResizeWeight ( 0.6 ) ;
frmSynolog . getContentPane ( ) . add ( splitter , BorderLayout . CENTER ) ;
JPanel panel = new JPanel ( ) ;
panel . setBackground ( Color . WHITE ) ;
splitter . setRightComponent ( panel ) ;
GridBagLayout gbl_panel = new GridBagLayout ( ) ;
gbl_panel . columnWidths = new int [ ] { 0 , 0 } ;
2016-09-09 00:57:02 +02:00
gbl_panel . rowHeights = new int [ ] { 0 , 0 , 0 , 0 } ;
2016-09-06 16:49:11 +02:00
gbl_panel . columnWeights = new double [ ] { 1.0 , Double . MIN_VALUE } ;
2016-09-09 00:57:02 +02:00
gbl_panel . rowWeights = new double [ ] { 0.0 , 1.0 , 0.0 , Double . MIN_VALUE } ;
2016-09-06 16:49:11 +02:00
panel . setLayout ( gbl_panel ) ;
JPanel panel_1 = new JPanel ( ) ;
panel_1 . setBackground ( Color . WHITE ) ;
panel_1 . setBorder ( new TitledBorder ( null , "Verbindung" , TitledBorder . LEADING , TitledBorder . TOP , null , null ) ) ;
GridBagConstraints gbc_panel_1 = new GridBagConstraints ( ) ;
gbc_panel_1 . insets = new Insets ( 0 , 0 , 5 , 0 ) ;
gbc_panel_1 . anchor = GridBagConstraints . NORTH ;
gbc_panel_1 . fill = GridBagConstraints . HORIZONTAL ;
gbc_panel_1 . gridx = 0 ;
gbc_panel_1 . gridy = 0 ;
panel . add ( panel_1 , gbc_panel_1 ) ;
GridBagLayout gbl_panel_1 = new GridBagLayout ( ) ;
2016-09-08 18:47:31 +02:00
gbl_panel_1 . columnWidths = new int [ ] { 0 , 0 , 0 } ;
2016-09-09 00:57:02 +02:00
gbl_panel_1 . rowHeights = new int [ ] { 0 , 0 , 0 , 0 , 0 } ;
2016-09-08 18:47:31 +02:00
gbl_panel_1 . columnWeights = new double [ ] { 1.0 , 1.0 , Double . MIN_VALUE } ;
2016-09-09 00:57:02 +02:00
gbl_panel_1 . rowWeights = new double [ ] { 0.0 , 1.0 , 1.0 , 0.0 , Double . MIN_VALUE } ;
2016-09-06 16:49:11 +02:00
panel_1 . setLayout ( gbl_panel_1 ) ;
2016-09-08 18:47:31 +02:00
bIntfAdd = new JButton ( "+" ) ;
bIntfAdd . addActionListener ( new ActionListener ( ) {
2016-09-06 16:49:11 +02:00
public void actionPerformed ( ActionEvent e ) {
2016-09-08 18:47:31 +02:00
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 ) ;
2016-09-09 00:57:02 +02:00
lInterfaces . addMouseListener ( new MouseAdapter ( ) {
@Override
public void mouseClicked ( MouseEvent e ) {
if ( ( e . getClickCount ( ) = = 2 ) & & ( e . getButton ( ) = = e . BUTTON1 ) ) {
if ( selectedDeviceInterface ! = null ) {
selectedDeviceInterface . showConnctionSetup ( ) ;
frmSynolog . repaint ( ) ;
}
}
}
} ) ;
2016-09-08 18:47:31 +02:00
lInterfaces . addListSelectionListener ( new ListSelectionListener ( ) {
public void valueChanged ( ListSelectionEvent e ) {
selectedInterfaceChanged ( ) ;
2016-09-06 16:49:11 +02:00
}
} ) ;
2016-09-08 18:47:31 +02:00
scrollPane_2 . setViewportView ( lInterfaces ) ;
2016-09-06 16:49:11 +02:00
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>" ) ;
cbTrimDevice . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
trimTicksOnConnect = null ;
if ( cbTrimDevice . isSelected ( ) ) {
2016-09-13 12:07:01 +02:00
// trimDevice();
2016-09-06 16:49:11 +02:00
}
}
} ) ;
2016-09-08 18:47:31 +02:00
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 ;
2016-09-09 00:57:02 +02:00
gbc_panel_4 . insets = new Insets ( 0 , 0 , 5 , 0 ) ;
2016-09-08 18:47:31 +02:00
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 ) ;
2016-09-09 00:57:02 +02:00
tfConnectionSettings = new JTextArea ( ) ;
2016-09-08 18:47:31 +02:00
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 ) ;
2016-09-06 16:49:11 +02:00
GridBagConstraints gbc_cbTrimDevice = new GridBagConstraints ( ) ;
2016-09-09 00:57:02 +02:00
gbc_cbTrimDevice . gridwidth = 2 ;
2016-09-06 16:49:11 +02:00
gbc_cbTrimDevice . anchor = GridBagConstraints . WEST ;
gbc_cbTrimDevice . gridx = 0 ;
2016-09-09 00:57:02 +02:00
gbc_cbTrimDevice . gridy = 3 ;
2016-09-06 16:49:11 +02:00
panel_1 . add ( cbTrimDevice , gbc_cbTrimDevice ) ;
JPanel panel_2 = new JPanel ( ) ;
panel_2 . setBackground ( Color . WHITE ) ;
panel_2 . setBorder ( new TitledBorder ( null , "Meldungen" , 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 ;
2016-09-09 00:57:02 +02:00
gbc_panel_2 . gridy = 1 ;
2016-09-06 16:49:11 +02:00
panel . add ( panel_2 , gbc_panel_2 ) ;
GridBagLayout gbl_panel_2 = new GridBagLayout ( ) ;
gbl_panel_2 . columnWidths = new int [ ] { 142 , 0 } ;
gbl_panel_2 . rowHeights = new int [ ] { 3 , 0 } ;
gbl_panel_2 . columnWeights = new double [ ] { 1.0 , Double . MIN_VALUE } ;
gbl_panel_2 . rowWeights = new double [ ] { 1.0 , Double . MIN_VALUE } ;
panel_2 . setLayout ( gbl_panel_2 ) ;
JScrollPane scrollPane = new JScrollPane ( ) ;
GridBagConstraints gbc_scrollPane = new GridBagConstraints ( ) ;
gbc_scrollPane . fill = GridBagConstraints . BOTH ;
gbc_scrollPane . gridx = 0 ;
gbc_scrollPane . gridy = 0 ;
panel_2 . add ( scrollPane , gbc_scrollPane ) ;
lMessages = new JList ( ) ;
lMessages . setFont ( new Font ( "Cantarell" , Font . PLAIN , 10 ) ) ;
scrollPane . setViewportView ( lMessages ) ;
panel_3 = new JPanel ( ) ;
panel_3 . setBackground ( Color . WHITE ) ;
panel_3 . setBorder ( new TitledBorder ( null , "Aktive Aufgaben" , TitledBorder . LEADING , TitledBorder . TOP , null , null ) ) ;
GridBagConstraints gbc_panel_3 = new GridBagConstraints ( ) ;
gbc_panel_3 . fill = GridBagConstraints . BOTH ;
gbc_panel_3 . gridx = 0 ;
2016-09-09 00:57:02 +02:00
gbc_panel_3 . gridy = 2 ;
2016-09-06 16:49:11 +02:00
panel . add ( panel_3 , gbc_panel_3 ) ;
panel_3 . setLayout ( new BoxLayout ( panel_3 , BoxLayout . X_AXIS ) ) ;
scrollPane_1 = new JScrollPane ( ) ;
panel_3 . add ( scrollPane_1 ) ;
lTasklets = new JList ( ) ;
scrollPane_1 . setViewportView ( lTasklets ) ;
pChannels = new JPanel ( ) ;
pChannels . setBorder ( new EmptyBorder ( 10 , 10 , 10 , 10 ) ) ;
pChannels . setBackground ( Color . WHITE ) ;
pChannels . setMinimumSize ( new Dimension ( 600 , 10 ) ) ;
splitter . setLeftComponent ( pChannels ) ;
GridBagLayout gbl_pChannels = new GridBagLayout ( ) ;
gbl_pChannels . columnWidths = new int [ ] { 0 } ;
gbl_pChannels . rowHeights = new int [ ] { 0 } ;
gbl_pChannels . columnWeights = new double [ ] { Double . MIN_VALUE } ;
gbl_pChannels . rowWeights = new double [ ] { Double . MIN_VALUE } ;
pChannels . setLayout ( gbl_pChannels ) ;
}
2016-09-08 18:47:31 +02:00
private PulsCounterApplication application ( ) {
return this . pulsCounterApplication ;
2016-09-06 16:49:11 +02:00
}
2016-09-08 18:47:31 +02:00
private void selectedInterfaceChanged ( ) {
selectedDeviceInterface = ( IDeviceConnector ) lInterfaces . getSelectedValue ( ) ;
/* ToDO: GUI Update */
if ( selectedDeviceInterface = = null ) {
bIntfDel . setEnabled ( false ) ;
tfConnectionSettings . setText ( "" ) ;
} else {
bIntfDel . setEnabled ( true ) ;
2016-09-09 00:57:02 +02:00
// tfConnectionSettings.setText(String.format("<html>%s</html>", selectedDeviceInterface.getConnectionSettingsText().replaceAll("\n", "<br/>")));
2016-09-08 18:47:31 +02:00
tfConnectionSettings . setText ( selectedDeviceInterface . getConnectionSettingsText ( ) ) ;
2016-09-09 00:57:02 +02:00
2016-09-08 18:47:31 +02:00
}
}
@Override
public void interfaceClassesChanged ( PulsCounterApplication pulsCounterApplication ) {
//lm.setItems(pulsCounterApplication.getInterfaceClasses());
}
@Override
public void interfacesChanged ( PulsCounterApplication pulsCounterApplication ) {
2016-09-09 00:57:02 +02:00
lmInterfaces . setItems ( pulsCounterApplication . getInterfaces ( ) ) ;
2016-09-08 18:47:31 +02:00
}
private void addInterface ( ) {
2016-09-09 00:57:02 +02:00
Class < IDeviceConnector > cidc ;
if ( pulsCounterApplication . getInterfaceClasses ( ) . size ( ) = = 1 ) {
cidc = pulsCounterApplication . getInterfaceClasses ( ) . get ( 0 ) ;
} else {
cidc = ( Class < IDeviceConnector > ) JObjectSelector . execute ( pulsCounterApplication . getInterfaceClasses ( ) . toArray ( ) ) ;
}
if ( cidc ! = null ) {
pulsCounterApplication . addInterface ( cidc , "" ) ;
} ;
2016-09-08 18:47:31 +02:00
}
private void removeInterface ( ) {
if ( selectedDeviceInterface ! = null ) {
pulsCounterApplication . removeInterface ( selectedDeviceInterface ) ;
lInterfaces . clearSelection ( ) ;
}
2016-09-06 16:49:11 +02:00
}
2016-09-09 00:57:02 +02:00
private synchronized void updateDeviceView ( ) {
if ( selectedDeviceInterface ! = null ) {
try {
int [ ] values = selectedDeviceInterface . getCounters ( ) ;
float [ ] analogs = selectedDeviceInterface . getAnalogs ( ) ;
int inputs ,
outputs ,
pullups ;
inputs = selectedDeviceInterface . getInputs ( ) ;
outputs = selectedDeviceInterface . getOutputs ( ) ;
pullups = selectedDeviceInterface . getPullups ( ) ;
for ( int n = 0 ; n < 32 ; n + + ) {
channelDisplays [ n ] . setEnabled ( true ) ;
channelDisplays [ n ] . setCounter ( values [ n ] ) ;
channelDisplays [ n ] . setInput ( ( ( inputs & ( 1 < < n ) ) ! = 0 ) ? true : false ) ;
channelDisplays [ n ] . setOutput ( ( ( outputs & ( 1 < < n ) ) ! = 0 ) ? true : false ) ;
channelDisplays [ n ] . setPullup ( ( ( pullups & ( 1 < < n ) ) ! = 0 ) ? true : false ) ;
}
for ( int n = 0 ; n < 8 ; n + + ) {
channelDisplays [ n ] . setVoltage ( ( double ) analogs [ n ] ) ;
}
2016-09-13 10:53:46 +02:00
2016-09-09 00:57:02 +02:00
} catch ( NoDeviceConnectionException e ) {
log ( "No Device" ) ;
} catch ( Exception e ) {
log ( e ) ;
}
} else {
for ( int n = 0 ; n < 32 ; n + + ) {
channelDisplays [ n ] . setEnabled ( false ) ;
}
}
2016-09-06 16:49:11 +02:00
}
2016-09-09 00:57:02 +02:00
/ *
2016-09-06 16:49:11 +02:00
@Override
public void connectionStateChanged ( Boolean connected ) {
if ( connected ) {
Integer version = application ( ) . getServiceLink ( ) . getServiceRegisterCache ( ) . getCachedInteger ( 13 , 0 , 0x001A ) ;
Integer uptime = application ( ) . getServiceLink ( ) . getServiceRegisterCache ( ) . getCachedInteger ( 13 , 0 , 0x0022 ) ;
Integer eesize = application ( ) . getServiceLink ( ) . getServiceRegisterCache ( ) . getCachedInteger ( 13 , 0 , 0x9000 ) ;
if ( version ! = null ) {
tfConnection . setText ( String . format ( "Version %d.%d.%d" , version > > 16 , ( version > > 8 ) & 0xff , version & 0xff ) ) ;
tfConnection . setBackground ( Color . GREEN ) ;
tfConnection . setForeground ( Color . BLACK ) ;
application ( ) . message ( String . format ( "Synololog verbunden (Version %d.%d.%d) (Uptime: %d:%d:%d)" , version > > 16 , ( version > > 8 ) & 0xff , version & 0xff , uptime / 3600 , ( uptime / 60 ) % 60 , uptime % 60 ) ) ;
application ( ) . message ( String . format ( "EEPROM Size: 0x%08x Bytes" , eesize ) ) ;
trimDeviceTimeSlice = application ( ) . getServiceLink ( ) . getServiceRegisterCache ( ) . getCachedInteger ( 13 , 0 , 0x1302 ) ;
2016-09-09 00:57:02 +02:00
// Trim helper initialisieren
2016-09-06 16:49:11 +02:00
trimTicksOnConnect = null ;
application ( ) . getSnapshotManager ( ) . notify ( Notification . FULLSYNC ) ;
} else {
tfConnection . setText ( "Version unbekannt" ) ;
tfConnection . setBackground ( Color . YELLOW ) ;
tfConnection . setForeground ( Color . BLACK ) ;
application ( ) . getServiceLink ( ) . close ( ) ;
}
} else {
tfConnection . setText ( "Nicht verbunden" ) ;
tfConnection . setBackground ( Color . RED ) ;
tfConnection . setForeground ( Color . WHITE ) ;
trimTicksOnConnect = null ;
if ( timerReconnect ! = null ) {
timerReconnect . schedule ( new TimerTask ( ) {
@Override
public void run ( ) {
if ( ! application ( ) . getServiceLink ( ) . isOpen ( ) ) {
try {
application ( ) . getServiceLink ( ) . open ( ) ;
} catch ( ServiceLinkException e ) {
e . printStackTrace ( ) ;
}
}
}
} , 3000 ) ;
}
if ( this . connected )
application ( ) . message ( "Verbindung getrennt" ) ;
}
this . connected = connected ;
}
2016-09-09 00:57:02 +02:00
* /
2016-09-13 10:53:46 +02:00
2016-09-06 16:49:11 +02:00
@Override
public synchronized void messageArrived ( String message ) {
if ( EventQueue . isDispatchThread ( ) ) {
int pos = messageListModel . size ( ) ;
String t = String . format ( "%s: %s" , DateTime . NOW ( ) . getSQLDateTime ( ) , message ) ;
messageListModel . addElement ( t ) ;
lMessages . ensureIndexIsVisible ( messageListModel . size ( ) - 1 ) ;
} else {
final String msg = message ;
EventQueue . invokeLater ( new Runnable ( ) {
@Override
public void run ( ) {
messageArrived ( msg ) ;
}
} ) ;
}
}
2016-09-13 12:07:01 +02:00
// private Integer trimDevice(){
// try {
//
// if (trimTicksOnConnect != null){
// long s1,s2,T;
// Integer device_us;
//
//
// s1 = System.currentTimeMillis();
// device_us = application().getServiceLink().readInt(13, 0, 0x1300);
// s2 = System.currentTimeMillis();
// T = (s1+s2)>>1;
//
// if (device_us < 0){
// trimTicksOnConnect = null;
// } else {
// long elapsed_us;
// long diff_us;
// long trim_ns_per_slice;
//
// elapsed_us = (T - trimTimeOnConnect) * 1000;
// diff_us = elapsed_us - device_us;
//
// System.err.println(String.format("Device Triming: Elapsed us: Dev: %d PC %d Diff: %d", device_us,elapsed_us,diff_us));
//
// trim_ns_per_slice = (diff_us * 1000) * trimDeviceTimeSlice / elapsed_us;
//
// smoothTrim.cycle((int)trim_ns_per_slice);
//
// System.err.println(String.format("Device Triming: Trim %dns / %dus",smoothTrim.getWert(),trimDeviceTimeSlice));
//
// application().getServiceLink().writeInt(13, 0, 0x1002, smoothTrim.getWert());
//
// application().message(String.format("Trimmung wurde korrigiert auf %dns / %dus",smoothTrim.getWert(),trimDeviceTimeSlice));
//
// }
// } else {
// long s1,s2,T;
//
// try {
// trimTicksOnConnect = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0027);
// s1 = System.currentTimeMillis();
// application().getServiceLink().writeInt(13, 0, 0x1301, 0);
// s2 = System.currentTimeMillis();
// trimTimeOnConnect = (s1+s2)>>1;
//
// smoothTrim = new Smoother();
// smoothTrim.setTn( 10 );
// smoothTrim.setWert( application().getServiceLink().readInt(13, 0, 0x1002) );
//
// } catch (Exception e){
// System.err.println("trimDevice(): init failed");
// e.printStackTrace();
// trimTicksOnConnect = null;
// }
// }
//
//
// } catch (Exception e){
// e.printStackTrace();
// }
// return null;
// }
//
//
// private void checkForAssertions(){
// Integer assert_error,assert_code;
//
// try
// {
// assert_error = -1;
// for (int i=0;i<8;i++){
// assert_error = application().getServiceLink().readInt(13, 0, 0x0026);
// assert_code = application().getServiceLink().readInt(13, 0, 0x0025);
//
// if (assert_error >= 0)
// break;
//
// application().message(String.format("Assertion: Error: 0x%08x (%d) Position: 0x%04x Mark: %d", assert_error,assert_error, assert_code & 0xffff, (assert_code >> 16) & 0xffff));
// application().getServiceLink().writeInt(13, 0, 0x0025, -1);
// };
// } catch (Exception ex){
// System.err.println("Exception while checking for assertions...");
// ex.printStackTrace();
// }
// }
2016-09-06 16:49:11 +02:00
@Override
public synchronized void taskletQueued ( final TaskletManager manager , final Tasklet tasklet ) {
if ( EventQueue . isDispatchThread ( ) )
knownTasklets . addElement ( tasklet ) ;
else {
EventQueue . invokeLater ( new Runnable ( ) {
@Override
public void run ( ) {
taskletQueued ( manager , tasklet ) ;
}
} ) ;
}
}
@Override
public synchronized void taskletStarted ( final TaskletManager manager , final Tasklet tasklet ) {
if ( EventQueue . isDispatchThread ( ) )
lTasklets . repaint ( ) ;
else
EventQueue . invokeLater ( new Runnable ( ) {
@Override
public void run ( ) {
taskletStarted ( manager , tasklet ) ;
}
} ) ;
}
@Override
public synchronized void taskletFinished ( final TaskletManager manager , final Tasklet tasklet ) {
if ( EventQueue . isDispatchThread ( ) )
knownTasklets . removeElement ( tasklet ) ;
else
EventQueue . invokeLater ( new Runnable ( ) {
@Override
public void run ( ) {
taskletFinished ( manager , tasklet ) ;
}
} ) ;
}
@Override
public synchronized void taskletProgressChanged ( final TaskletManager manager , final Tasklet tasklet ) {
if ( EventQueue . isDispatchThread ( ) )
lTasklets . repaint ( ) ;
else
EventQueue . invokeLater ( new Runnable ( ) {
@Override
public void run ( ) {
taskletProgressChanged ( manager , tasklet ) ;
}
} ) ;
}
private void channelReset ( ChannelDisplay display ) {
for ( int n = 0 ; n < 32 ; n + + ) {
if ( display = = channelDisplays [ n ] ) {
channelReset ( n , 0 ) ;
return ;
}
}
}
2016-09-08 18:47:31 +02:00
private void channelSetDescription ( ChannelDisplay display ) {
for ( int n = 0 ; n < 32 ; n + + ) {
if ( display = = channelDisplays [ n ] ) {
2016-09-13 12:07:01 +02:00
// application().setChannelDescription(n, display.getDescriptionText());
2016-09-08 18:47:31 +02:00
return ;
}
}
}
2016-09-06 16:49:11 +02:00
private void channelReset ( int channel , int setValue ) {
2016-09-09 00:57:02 +02:00
selectedDeviceInterface . setCounter ( channel , setValue ) ;
2016-09-06 16:49:11 +02:00
}
private void channelSet ( ChannelDisplay display , int setValue ) {
for ( int n = 0 ; n < 32 ; n + + ) {
if ( display = = channelDisplays [ n ] ) {
channelReset ( n , setValue ) ;
return ;
}
}
}
2016-09-09 00:57:02 +02:00
class BackgroundThread extends Thread {
private int timeout ;
private boolean exit ;
2016-09-13 12:07:01 +02:00
private int checkTimeout ;
2016-09-09 00:57:02 +02:00
public BackgroundThread ( ) {
timeout = 500 ;
2016-09-13 12:07:01 +02:00
checkTimeout = 0 ;
2016-09-09 00:57:02 +02:00
exit = false ;
}
public void exit ( ) {
synchronized ( this ) {
this . exit = true ;
notify ( ) ;
} ;
while ( isAlive ( ) ) {
try {
sleep ( 50 ) ;
} catch ( InterruptedException e ) {
}
}
}
public synchronized int getTimeout ( ) {
return timeout ;
}
public synchronized void setTimeout ( int timeout ) {
this . timeout = timeout ;
}
@Override
public void run ( ) {
synchronized ( this ) {
log ( INFO , "newMainWindow: backgroundThread: started" ) ;
while ( ! exit ) {
try {
wait ( timeout ) ;
updateDeviceView ( ) ;
2016-09-13 12:07:01 +02:00
if ( checkTimeout > 0 ) {
checkTimeout - - ;
} else {
checkTimeout = 10 ;
application ( ) . checkForSnapShots ( ) ;
}
2016-09-09 00:57:02 +02:00
} catch ( InterruptedException e ) {
}
}
log ( INFO , "newMainWindow: backgroundThread: exited" ) ;
}
}
}
2016-09-06 16:49:11 +02:00
}