Browse Source

button handling

master
gituser 10 months ago
parent
commit
ef2d2d4ad9

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

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

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

@@ -64,21 +64,23 @@ public class FSStatusBar implements IConnectionState {
this.reconnectBtn.setVisible(false);
this.portValueLbl.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.connectionStatePrgBar.setString("Aufbau...");
this.connectionStatePrgBar.setIndeterminate(true);
} else if (connectionStateInfo.connectionState().equals(ConnectionState.CONNECTED)) {
this.connectionStateLbl.setText("Verbunden!");
this.connectionStatePrgBar.setString("OK!");
this.connectionStatePrgBar.setIndeterminate(false);
this.connectionStatePrgBar.setValue(100);
this.portValueLbl.setText(StringUtils.isEmpty(connectionStateInfo.port()) ? " " : connectionStateInfo.port());
this.versionValueLbl.setText(StringUtils.isEmpty(connectionStateInfo.version()) ? " " : connectionStateInfo.version());
} else {
this.connectionStateLbl.setText("Zeitüberschreitung!");
this.connectionStatePrgBar.setString("Nicht verbunden");
this.connectionStatePrgBar.setIndeterminate(false);
this.connectionStatePrgBar.setValue(0);
this.reconnectBtn.setVisible(true);
}
@@ -114,7 +116,7 @@ public class FSStatusBar implements IConnectionState {
Font connectionStateLblFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, connectionStateLbl.getFont());
if (connectionStateLblFont != null) connectionStateLbl.setFont(connectionStateLblFont);
connectionStateLbl.setHorizontalAlignment(11);
connectionStateLbl.setText("Am Verbinden...");
connectionStateLbl.setText("Bereit");
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
@@ -123,11 +125,11 @@ public class FSStatusBar implements IConnectionState {
connectionStatePnl.add(connectionStateLbl, gbc);
connectionStatePrgBar = new JProgressBar();
connectionStatePrgBar.setForeground(new Color(-16738404));
connectionStatePrgBar.setIndeterminate(true);
connectionStatePrgBar.setIndeterminate(false);
connectionStatePrgBar.setMinimumSize(new Dimension(80, 20));
connectionStatePrgBar.setPreferredSize(new Dimension(80, 20));
connectionStatePrgBar.setRequestFocusEnabled(false);
connectionStatePrgBar.setString("Aufbau...");
connectionStatePrgBar.setString("");
connectionStatePrgBar.setStringPainted(true);
gbc = new GridBagConstraints();
gbc.gridx = 1;

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

@@ -1,5 +1,5 @@
package ch.spherICIT.main;

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

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

@@ -29,7 +29,7 @@
<gridbag weightx="0.0" weighty="1.0"/>
</constraints>
</vspacer>
<component id="196b9" class="javax.swing.JComboBox" binding="serPortCboBox">
<component id="196b9" class="javax.swing.JComboBox" binding="serPortCboBox" custom-create="true">
<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"/>
<gridbag top="10" left="0" bottom="10" right="10" weightx="0.0" weighty="0.0"/>
@@ -37,9 +37,7 @@
<properties>
<font name="Bahnschrift" size="14" style="0"/>
<minimumSize width="120" height="32"/>
<model>
<item value="COM4"/>
</model>
<model/>
<preferredSize width="120" height="32"/>
</properties>
</component>
@@ -50,6 +48,7 @@
</constraints>
<properties>
<contentAreaFilled value="true"/>
<enabled value="false"/>
<font name="Bahnschrift" size="14" style="0"/>
<hideActionText value="false"/>
<horizontalTextPosition value="0"/>
@@ -67,6 +66,7 @@
<gridbag top="10" left="10" bottom="10" right="10" weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<enabled value="false"/>
<font name="Bahnschrift" size="14" style="0"/>
<label value="Schliessen"/>
<minimumSize width="130" height="32"/>

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

@@ -1,6 +1,7 @@
package ch.spherICIT.main;

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

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
@@ -20,15 +21,20 @@ import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
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.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;

public class MainPanel {

private JPanel mainPanel;
private JLabel serPortLbl;
private JComboBox serPortCboBox;
private JComboBox<CommPort> serPortCboBox;
private JButton serPortOpenBtn;
private JButton serPortCloseBtn;
private JButton setZeroAzBtn;
@@ -42,6 +48,7 @@ public class MainPanel {

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

/**
* Konstruktor.
@@ -49,6 +56,9 @@ public class MainPanel {
public MainPanel() {
this.logWindow = new LogWindow();
this.connectionStateListeners = new HashSet<>();
$$$setupUI$$$();
initCommPorts();

this.reconnectActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -58,22 +68,28 @@ public class MainPanel {
this.serPortOpenBtn.addActionListener(new ActionListener() {
@Override
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
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
public void actionPerformed(ActionEvent e) {
connectionStateListeners.iterator().next().connectionStateChanged(new ConnectionStateInfo(ConnectionState.TIMEOUT, "", ""));
}
});
logWindowBtn.addActionListener(new ActionListener() {
this.logWindowBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
logWindow.setVisible(true);
@@ -81,6 +97,34 @@ public class MainPanel {
});
}

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) {
this.connectionStateListeners.add(connectionStateListener);
}
@@ -93,12 +137,36 @@ public class MainPanel {
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() : "";
}
}

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

Loading…
Cancel
Save