2016-09-06 16:49:11 +02:00
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 javax.swing.event.ListSelectionEvent ;
import javax.swing.event.ListSelectionListener ;
import org.hwo.interactiveobjects.ObjectEditorUI ;
import org.hwo.interactiveobjects.ObjectEditorUIHelper ;
import org.hwo.models.TableMapper.TableMapper ;
import org.hwo.pulscounter.ExportSetting ;
2016-09-08 18:47:31 +02:00
import org.hwo.pulscounter.PulsCounterApplication ;
2016-09-06 16:49:11 +02:00
import java.awt.GridBagLayout ;
import javax.swing.JButton ;
import java.awt.GridBagConstraints ;
import javax.swing.JScrollPane ;
import java.awt.Insets ;
import javax.swing.JTable ;
import java.awt.event.ActionListener ;
import java.awt.event.ActionEvent ;
import javax.swing.JToolBar ;
import javax.swing.ListSelectionModel ;
import javax.swing.JSeparator ;
public class ExportFilesFrame extends JFrame {
private JPanel contentPane ;
private JTable tExportSettings ;
private TableMapper tmExportSettings ;
private JButton bRemove ;
private JButton bEdit ;
private JButton bAdd ;
private ExportSetting selectedExportSetting ;
private JSeparator separator ;
private JButton btnExec ;
/ * *
* Create the frame .
* /
public ExportFilesFrame ( ) {
setTitle ( "Export Einstellungen..." ) ;
setDefaultCloseOperation ( JFrame . DISPOSE_ON_CLOSE ) ;
setBounds ( 100 , 100 , 825 , 433 ) ;
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 , 0 , 0 } ;
gbl_contentPane . rowHeights = new int [ ] { 0 , 0 , 0 , 0 } ;
gbl_contentPane . columnWeights = new double [ ] { 1.0 , 0.0 , 0.0 , Double . MIN_VALUE } ;
gbl_contentPane . rowWeights = new double [ ] { 0.0 , 1.0 , 0.0 , Double . MIN_VALUE } ;
contentPane . setLayout ( gbl_contentPane ) ;
JToolBar toolBar = new JToolBar ( ) ;
toolBar . setFloatable ( false ) ;
GridBagConstraints gbc_toolBar = new GridBagConstraints ( ) ;
gbc_toolBar . fill = GridBagConstraints . BOTH ;
gbc_toolBar . gridwidth = 3 ;
gbc_toolBar . insets = new Insets ( 0 , 0 , 5 , 5 ) ;
gbc_toolBar . gridx = 0 ;
gbc_toolBar . gridy = 0 ;
contentPane . add ( toolBar , gbc_toolBar ) ;
bAdd = new JButton ( "+" ) ;
bAdd . setToolTipText ( "<html>\n<b>Neue Exportkonfiguration hinzufügen</b><br/>\n</html>" ) ;
bAdd . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
ExportSetting es = new ExportSetting ( ) ;
tmExportSettings . addRow ( es ) ;
}
} ) ;
toolBar . add ( bAdd ) ;
bEdit = new JButton ( "e" ) ;
bEdit . setToolTipText ( "<html>\n<b>Ausgewählte Exportkonfiguration bearbeiten</b>\n</html>" ) ;
bEdit . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
ExportSetting es = ( ExportSetting ) tmExportSettings . getSelectedRow ( ) ;
if ( es ! = null ) {
if ( ObjectEditorUIHelper . edit ( es ) ) {
tmExportSettings . fireTableDataChanged ( ) ;
}
}
}
} ) ;
bEdit . setEnabled ( false ) ;
toolBar . add ( bEdit ) ;
bRemove = new JButton ( "-" ) ;
bRemove . setToolTipText ( "<html>\n<b>Ausgewählte Exportkonfiguration entfernen</b>\n</html>" ) ;
bRemove . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
if ( selectedExportSetting ! = null ) {
ExportSetting es = selectedExportSetting ;
tmExportSettings . removeRow ( es ) ;
}
}
} ) ;
bRemove . setEnabled ( false ) ;
toolBar . add ( bRemove ) ;
separator = new JSeparator ( ) ;
toolBar . add ( separator ) ;
btnExec = new JButton ( "EXEC" ) ;
btnExec . setToolTipText ( "<html>\n<b>Ausgewählte Exportkonfiguration jetzt ausführen</b><br/>\n</html>" ) ;
btnExec . setEnabled ( false ) ;
btnExec . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
doExport ( ) ;
}
} ) ;
toolBar . add ( btnExec ) ;
JScrollPane scrollPane = new JScrollPane ( ) ;
scrollPane . setToolTipText ( "<html>\n<b>Exportkonfigurationen</b><br/>\nZeigt eine Übersicht über die aktuell vorhandenen Exportkonfigurationen\n</html>" ) ;
GridBagConstraints gbc_scrollPane = new GridBagConstraints ( ) ;
gbc_scrollPane . gridwidth = 3 ;
gbc_scrollPane . insets = new Insets ( 0 , 0 , 5 , 0 ) ;
gbc_scrollPane . fill = GridBagConstraints . BOTH ;
gbc_scrollPane . gridx = 0 ;
gbc_scrollPane . gridy = 1 ;
contentPane . add ( scrollPane , gbc_scrollPane ) ;
tExportSettings = new JTable ( ) ;
tExportSettings . setSelectionMode ( ListSelectionModel . SINGLE_SELECTION ) ;
tmExportSettings = new TableMapper ( ExportSetting . class , tExportSettings ) ;
tmExportSettings . addListSelectionListener ( new ListSelectionListener ( ) {
@Override
public void valueChanged ( ListSelectionEvent e ) {
ExportSetting es = ( ExportSetting ) tmExportSettings . getSelectedRow ( ) ;
setSelectedExportSetting ( es ) ;
}
} ) ;
2016-09-08 18:47:31 +02:00
tmExportSettings . setRows ( PulsCounterApplication . getApplication ( ) . getExportSettings ( ) ) ;
2016-09-06 16:49:11 +02:00
scrollPane . setViewportView ( tExportSettings ) ;
JButton btnSchliessen = new JButton ( "schliessen" ) ;
btnSchliessen . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
setVisible ( false ) ;
2016-09-08 18:47:31 +02:00
PulsCounterApplication . getApplication ( ) . savePrefs ( ) ;
2016-09-06 16:49:11 +02:00
}
} ) ;
GridBagConstraints gbc_btnSchliessen = new GridBagConstraints ( ) ;
gbc_btnSchliessen . gridx = 2 ;
gbc_btnSchliessen . gridy = 2 ;
contentPane . add ( btnSchliessen , gbc_btnSchliessen ) ;
}
public ExportSetting getSelectedExportSetting ( ) {
return selectedExportSetting ;
}
public void setSelectedExportSetting ( ExportSetting selectedExportSetting ) {
this . selectedExportSetting = selectedExportSetting ;
if ( this . selectedExportSetting ! = null ) {
bEdit . setEnabled ( true ) ;
bRemove . setEnabled ( true ) ;
btnExec . setEnabled ( true ) ;
} else {
bEdit . setEnabled ( false ) ;
bRemove . setEnabled ( false ) ;
btnExec . setEnabled ( false ) ;
}
}
public void doExport ( ) {
( ( ExportSetting ) tmExportSettings . getSelectedRow ( ) ) . export ( ) ;
}
}