Browse Source

button handling

master
gituser 11 months ago
parent
commit
ef2d2d4ad9

+ 3
- 3
src/main/java/ch/spherICIT/components/statusbar/FSStatusBar.form View File

<properties> <properties>
<font name="Bahnschrift" size="12" style="0"/> <font name="Bahnschrift" size="12" style="0"/>
<horizontalAlignment value="11"/> <horizontalAlignment value="11"/>
<text value="Am Verbinden..."/>
<text value="Bereit"/>
</properties> </properties>
</component> </component>
<component id="e88e3" class="javax.swing.JProgressBar" binding="connectionStatePrgBar"> <component id="e88e3" class="javax.swing.JProgressBar" binding="connectionStatePrgBar">
</constraints> </constraints>
<properties> <properties>
<foreground color="-16738404"/> <foreground color="-16738404"/>
<indeterminate value="true"/>
<indeterminate value="false"/>
<minimumSize width="80" height="20"/> <minimumSize width="80" height="20"/>
<preferredSize width="80" height="20"/> <preferredSize width="80" height="20"/>
<requestFocusEnabled value="false"/> <requestFocusEnabled value="false"/>
<string value="Aufbau..."/>
<string value=""/>
<stringPainted value="true"/> <stringPainted value="true"/>
</properties> </properties>
</component> </component>

+ 8
- 6
src/main/java/ch/spherICIT/components/statusbar/FSStatusBar.java View File

this.reconnectBtn.setVisible(false); this.reconnectBtn.setVisible(false);
this.portValueLbl.setText(" "); this.portValueLbl.setText(" ");
this.versionValueLbl.setText(" "); this.versionValueLbl.setText(" ");
if (connectionStateInfo.connectionState().equals(ConnectionState.CONNECTING)) {
this.connectionStatePrgBar.setIndeterminate(false);
if (connectionStateInfo.connectionState().equals(ConnectionState.READY)) {
this.connectionStateLbl.setText("Bereit");
this.connectionStatePrgBar.setString("");
} else if (connectionStateInfo.connectionState().equals(ConnectionState.CONNECTING)) {
this.connectionStateLbl.setText("Am Verbinden..."); this.connectionStateLbl.setText("Am Verbinden...");
this.connectionStatePrgBar.setString("Aufbau..."); this.connectionStatePrgBar.setString("Aufbau...");
this.connectionStatePrgBar.setIndeterminate(true); this.connectionStatePrgBar.setIndeterminate(true);
} else if (connectionStateInfo.connectionState().equals(ConnectionState.CONNECTED)) { } else if (connectionStateInfo.connectionState().equals(ConnectionState.CONNECTED)) {
this.connectionStateLbl.setText("Verbunden!"); this.connectionStateLbl.setText("Verbunden!");
this.connectionStatePrgBar.setString("OK!"); this.connectionStatePrgBar.setString("OK!");
this.connectionStatePrgBar.setIndeterminate(false);
this.connectionStatePrgBar.setValue(100); this.connectionStatePrgBar.setValue(100);
this.portValueLbl.setText(StringUtils.isEmpty(connectionStateInfo.port()) ? " " : connectionStateInfo.port()); this.portValueLbl.setText(StringUtils.isEmpty(connectionStateInfo.port()) ? " " : connectionStateInfo.port());
this.versionValueLbl.setText(StringUtils.isEmpty(connectionStateInfo.version()) ? " " : connectionStateInfo.version()); this.versionValueLbl.setText(StringUtils.isEmpty(connectionStateInfo.version()) ? " " : connectionStateInfo.version());
} else { } else {
this.connectionStateLbl.setText("Zeitüberschreitung!"); this.connectionStateLbl.setText("Zeitüberschreitung!");
this.connectionStatePrgBar.setString("Nicht verbunden"); this.connectionStatePrgBar.setString("Nicht verbunden");
this.connectionStatePrgBar.setIndeterminate(false);
this.connectionStatePrgBar.setValue(0); this.connectionStatePrgBar.setValue(0);
this.reconnectBtn.setVisible(true); this.reconnectBtn.setVisible(true);
} }
Font connectionStateLblFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, connectionStateLbl.getFont()); Font connectionStateLblFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, connectionStateLbl.getFont());
if (connectionStateLblFont != null) connectionStateLbl.setFont(connectionStateLblFont); if (connectionStateLblFont != null) connectionStateLbl.setFont(connectionStateLblFont);
connectionStateLbl.setHorizontalAlignment(11); connectionStateLbl.setHorizontalAlignment(11);
connectionStateLbl.setText("Am Verbinden...");
connectionStateLbl.setText("Bereit");
gbc = new GridBagConstraints(); gbc = new GridBagConstraints();
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = 0; gbc.gridy = 0;
connectionStatePnl.add(connectionStateLbl, gbc); connectionStatePnl.add(connectionStateLbl, gbc);
connectionStatePrgBar = new JProgressBar(); connectionStatePrgBar = new JProgressBar();
connectionStatePrgBar.setForeground(new Color(-16738404)); connectionStatePrgBar.setForeground(new Color(-16738404));
connectionStatePrgBar.setIndeterminate(true);
connectionStatePrgBar.setIndeterminate(false);
connectionStatePrgBar.setMinimumSize(new Dimension(80, 20)); connectionStatePrgBar.setMinimumSize(new Dimension(80, 20));
connectionStatePrgBar.setPreferredSize(new Dimension(80, 20)); connectionStatePrgBar.setPreferredSize(new Dimension(80, 20));
connectionStatePrgBar.setRequestFocusEnabled(false); connectionStatePrgBar.setRequestFocusEnabled(false);
connectionStatePrgBar.setString("Aufbau...");
connectionStatePrgBar.setString("");
connectionStatePrgBar.setStringPainted(true); connectionStatePrgBar.setStringPainted(true);
gbc = new GridBagConstraints(); gbc = new GridBagConstraints();
gbc.gridx = 1; gbc.gridx = 1;

+ 1
- 1
src/main/java/ch/spherICIT/main/ConnectionState.java View File

package ch.spherICIT.main; package ch.spherICIT.main;


public enum ConnectionState { public enum ConnectionState {
CONNECTING, CONNECTED, TIMEOUT
READY, CONNECTING, CONNECTED, TIMEOUT
} }

+ 4
- 4
src/main/java/ch/spherICIT/main/MainPanel.form View File

<gridbag weightx="0.0" weighty="1.0"/> <gridbag weightx="0.0" weighty="1.0"/>
</constraints> </constraints>
</vspacer> </vspacer>
<component id="196b9" class="javax.swing.JComboBox" binding="serPortCboBox">
<component id="196b9" class="javax.swing.JComboBox" binding="serPortCboBox" custom-create="true">
<constraints> <constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
<gridbag top="10" left="0" bottom="10" right="10" weightx="0.0" weighty="0.0"/> <gridbag top="10" left="0" bottom="10" right="10" weightx="0.0" weighty="0.0"/>
<properties> <properties>
<font name="Bahnschrift" size="14" style="0"/> <font name="Bahnschrift" size="14" style="0"/>
<minimumSize width="120" height="32"/> <minimumSize width="120" height="32"/>
<model>
<item value="COM4"/>
</model>
<model/>
<preferredSize width="120" height="32"/> <preferredSize width="120" height="32"/>
</properties> </properties>
</component> </component>
</constraints> </constraints>
<properties> <properties>
<contentAreaFilled value="true"/> <contentAreaFilled value="true"/>
<enabled value="false"/>
<font name="Bahnschrift" size="14" style="0"/> <font name="Bahnschrift" size="14" style="0"/>
<hideActionText value="false"/> <hideActionText value="false"/>
<horizontalTextPosition value="0"/> <horizontalTextPosition value="0"/>
<gridbag top="10" left="10" bottom="10" right="10" weightx="0.0" weighty="0.0"/> <gridbag top="10" left="10" bottom="10" right="10" weightx="0.0" weighty="0.0"/>
</constraints> </constraints>
<properties> <properties>
<enabled value="false"/>
<font name="Bahnschrift" size="14" style="0"/> <font name="Bahnschrift" size="14" style="0"/>
<label value="Schliessen"/> <label value="Schliessen"/>
<minimumSize width="130" height="32"/> <minimumSize width="130" height="32"/>

+ 82
- 13
src/main/java/ch/spherICIT/main/MainPanel.java View File

package ch.spherICIT.main; package ch.spherICIT.main;


import ch.spherICIT.components.switchbtn.SwitchButton; import ch.spherICIT.components.switchbtn.SwitchButton;
import com.fazecast.jSerialComm.SerialPort;


import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
import java.util.Set; import java.util.Set;


public class MainPanel { public class MainPanel {


private JPanel mainPanel; private JPanel mainPanel;
private JLabel serPortLbl; private JLabel serPortLbl;
private JComboBox serPortCboBox;
private JComboBox<CommPort> serPortCboBox;
private JButton serPortOpenBtn; private JButton serPortOpenBtn;
private JButton serPortCloseBtn; private JButton serPortCloseBtn;
private JButton setZeroAzBtn; private JButton setZeroAzBtn;


private Set<IConnectionState> connectionStateListeners; private Set<IConnectionState> connectionStateListeners;
private ActionListener reconnectActionListener; private ActionListener reconnectActionListener;
private List<CommPort> commPorts;


/** /**
* Konstruktor. * Konstruktor.
public MainPanel() { public MainPanel() {
this.logWindow = new LogWindow(); this.logWindow = new LogWindow();
this.connectionStateListeners = new HashSet<>(); this.connectionStateListeners = new HashSet<>();
$$$setupUI$$$();
initCommPorts();

this.reconnectActionListener = new ActionListener() { this.reconnectActionListener = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
this.serPortOpenBtn.addActionListener(new ActionListener() { this.serPortOpenBtn.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
connectionStateListeners.iterator().next().connectionStateChanged(new ConnectionStateInfo(ConnectionState.CONNECTING, "", ""));
// connectionStateListeners.iterator().next().connectionStateChanged(new ConnectionStateInfo(ConnectionState.CONNECTING, "", ""));
getSelectedCommPort().get().getSerialPort().get().openPort();
serPortOpenBtn.setEnabled(false);
serPortCloseBtn.setEnabled(true);
} }
}); });
serPortCloseBtn.addActionListener(new ActionListener() {
this.serPortCloseBtn.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
connectionStateListeners.iterator().next().connectionStateChanged(new ConnectionStateInfo(ConnectionState.CONNECTED, "COM4", "v1.2.0"));
// connectionStateListeners.iterator().next().connectionStateChanged(new ConnectionStateInfo(ConnectionState.CONNECTED, "COM4", "v1.2.0"));
getSelectedCommPort().get().getSerialPort().get().closePort();
serPortOpenBtn.setEnabled(true);
serPortCloseBtn.setEnabled(false);
} }
}); });
setZeroAzBtn.addActionListener(new ActionListener() {
this.setZeroAzBtn.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
connectionStateListeners.iterator().next().connectionStateChanged(new ConnectionStateInfo(ConnectionState.TIMEOUT, "", "")); connectionStateListeners.iterator().next().connectionStateChanged(new ConnectionStateInfo(ConnectionState.TIMEOUT, "", ""));
} }
}); });
logWindowBtn.addActionListener(new ActionListener() {
this.logWindowBtn.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
logWindow.setVisible(true); logWindow.setVisible(true);
}); });
} }


private void initCommPorts() {
this.commPorts = new ArrayList<>();
this.commPorts.add(new CommPort(null));
for (SerialPort serialPort : SerialPort.getCommPorts()) {
this.commPorts.add(new CommPort(serialPort));
}
this.serPortCboBox.setModel(new DefaultComboBoxModel(this.commPorts.toArray()));
serPortCboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
Optional<CommPort> selCommPortOptional = getSelectedCommPort();
if (selCommPortOptional.isPresent() && selCommPortOptional.get().getSerialPort().isPresent()) {
selCommPortOptional.get().getSerialPort().get().openPort();
serPortOpenBtn.setEnabled(false);
serPortCloseBtn.setEnabled(true);
} else {
for (IConnectionState listener : connectionStateListeners) {
listener.connectionStateChanged(new ConnectionStateInfo(ConnectionState.READY, null, null));
serPortOpenBtn.setEnabled(false);
serPortCloseBtn.setEnabled(false);

}
}
}
});
this.serPortCboBox.setSelectedIndex(-1);
}

public void registerConnectionStateListener(IConnectionState connectionStateListener) { public void registerConnectionStateListener(IConnectionState connectionStateListener) {
this.connectionStateListeners.add(connectionStateListener); this.connectionStateListeners.add(connectionStateListener);
} }
return reconnectActionListener; return reconnectActionListener;
} }


private Optional<CommPort> getSelectedCommPort() {
return this.serPortCboBox.getSelectedIndex() != -1 ? Optional.of(this.serPortCboBox.getItemAt(this.serPortCboBox.getSelectedIndex())) : Optional.empty();
}


{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
private void createUIComponents() {
this.serPortCboBox = new JComboBox<>();
}


private class CommPort {

private SerialPort serialPort;

/**
* Constructor
*
* @param serialPort serial port from JSerialComm
*/
public CommPort(SerialPort serialPort) {
this.serialPort = serialPort;
}

public Optional<SerialPort> getSerialPort() {
return this.serialPort != null ? Optional.of(this.serialPort) : Optional.empty();
}

@Override
public String toString() {
return this.serialPort != null ? this.serialPort.getSystemPortName() : "";
}
} }


/** /**
* @noinspection ALL * @noinspection ALL
*/ */
private void $$$setupUI$$$() { private void $$$setupUI$$$() {
createUIComponents();
mainPanel = new JPanel(); mainPanel = new JPanel();
mainPanel.setLayout(new GridBagLayout()); mainPanel.setLayout(new GridBagLayout());
final JPanel spacer1 = new JPanel(); final JPanel spacer1 = new JPanel();
gbc.weighty = 1.0; gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.VERTICAL; gbc.fill = GridBagConstraints.VERTICAL;
mainPanel.add(spacer2, gbc); mainPanel.add(spacer2, gbc);
serPortCboBox = new JComboBox();
Font serPortCboBoxFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 14, serPortCboBox.getFont()); Font serPortCboBoxFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 14, serPortCboBox.getFont());
if (serPortCboBoxFont != null) serPortCboBox.setFont(serPortCboBoxFont); if (serPortCboBoxFont != null) serPortCboBox.setFont(serPortCboBoxFont);
serPortCboBox.setMinimumSize(new Dimension(120, 32)); serPortCboBox.setMinimumSize(new Dimension(120, 32));
final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel(); final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel();
defaultComboBoxModel1.addElement("COM4");
serPortCboBox.setModel(defaultComboBoxModel1); serPortCboBox.setModel(defaultComboBoxModel1);
serPortCboBox.setPreferredSize(new Dimension(120, 32)); serPortCboBox.setPreferredSize(new Dimension(120, 32));
gbc = new GridBagConstraints(); gbc = new GridBagConstraints();
mainPanel.add(serPortCboBox, gbc); mainPanel.add(serPortCboBox, gbc);
serPortOpenBtn = new JButton(); serPortOpenBtn = new JButton();
serPortOpenBtn.setContentAreaFilled(true); serPortOpenBtn.setContentAreaFilled(true);
serPortOpenBtn.setEnabled(false);
Font serPortOpenBtnFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 14, serPortOpenBtn.getFont()); Font serPortOpenBtnFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 14, serPortOpenBtn.getFont());
if (serPortOpenBtnFont != null) serPortOpenBtn.setFont(serPortOpenBtnFont); if (serPortOpenBtnFont != null) serPortOpenBtn.setFont(serPortOpenBtnFont);
serPortOpenBtn.setHideActionText(false); serPortOpenBtn.setHideActionText(false);
gbc.insets = new Insets(10, 10, 10, 10); gbc.insets = new Insets(10, 10, 10, 10);
mainPanel.add(serPortOpenBtn, gbc); mainPanel.add(serPortOpenBtn, gbc);
serPortCloseBtn = new JButton(); serPortCloseBtn = new JButton();
serPortCloseBtn.setEnabled(false);
Font serPortCloseBtnFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 14, serPortCloseBtn.getFont()); Font serPortCloseBtnFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 14, serPortCloseBtn.getFont());
if (serPortCloseBtnFont != null) serPortCloseBtn.setFont(serPortCloseBtnFont); if (serPortCloseBtnFont != null) serPortCloseBtn.setFont(serPortCloseBtnFont);
serPortCloseBtn.setLabel("Schliessen"); serPortCloseBtn.setLabel("Schliessen");

Loading…
Cancel
Save