| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- package ch.spherICIT.components.statusbar;
-
- import ch.spherICIT.main.ConnectionState;
- import ch.spherICIT.main.IConnectionState;
- import ch.spherICIT.main.ConnectionStateInfo;
- import com.formdev.flatlaf.ui.FlatLineBorder;
- import com.formdev.flatlaf.util.StringUtils;
-
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JComponent;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JProgressBar;
- import javax.swing.JSeparator;
- import javax.swing.border.CompoundBorder;
- import javax.swing.border.EmptyBorder;
- import javax.swing.plaf.FontUIResource;
- import javax.swing.text.StyleContext;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.Locale;
-
- public class FSStatusBar implements IConnectionState {
-
-
- private JPanel statusBarPnl;
- private JPanel connectionStatePnl;
- private JProgressBar connectionStatePrgBar;
- private JPanel portPnl;
- private JLabel connectionStateLbl;
- private JLabel portValueLbl;
- private JPanel versionPnl;
- private JLabel versionValueLbl;
- private JButton reconnectBtn;
-
- private ActionListener reconnectActionListener;
-
-
- public FSStatusBar() {
- $$$setupUI$$$();
- this.reconnectBtn.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- if (FSStatusBar.this.reconnectActionListener != null) {
- FSStatusBar.this.reconnectActionListener.actionPerformed(e);
- }
- }
- });
- }
-
- public void setReconnectActionListener(ActionListener reconnectActionListener) {
- this.reconnectActionListener = reconnectActionListener;
- }
-
- @Override
- public void connectionStateChanged(ConnectionStateInfo connectionStateInfo) {
- this.reconnectBtn.setVisible(false);
- this.portValueLbl.setText(" ");
- this.versionValueLbl.setText(" ");
- 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);
- }
- }
-
- /**
- * Method generated by IntelliJ IDEA GUI Designer
- * >>> IMPORTANT!! <<<
- * DO NOT edit this method OR call it in your code!
- *
- * @noinspection ALL
- */
- private void $$$setupUI$$$() {
- createUIComponents();
- statusBarPnl.setLayout(new GridBagLayout());
- final JPanel spacer1 = new JPanel();
- GridBagConstraints gbc;
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.weightx = 1.0;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- statusBarPnl.add(spacer1, gbc);
- connectionStatePnl = new JPanel();
- connectionStatePnl.setLayout(new GridBagLayout());
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.BOTH;
- statusBarPnl.add(connectionStatePnl, gbc);
- connectionStateLbl = new JLabel();
- Font connectionStateLblFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, connectionStateLbl.getFont());
- if (connectionStateLblFont != null) connectionStateLbl.setFont(connectionStateLblFont);
- connectionStateLbl.setHorizontalAlignment(11);
- connectionStateLbl.setText("Am Verbinden...");
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.anchor = GridBagConstraints.EAST;
- gbc.insets = new Insets(5, 0, 0, 10);
- connectionStatePnl.add(connectionStateLbl, gbc);
- connectionStatePrgBar = new JProgressBar();
- connectionStatePrgBar.setForeground(new Color(-16738404));
- connectionStatePrgBar.setIndeterminate(true);
- connectionStatePrgBar.setMinimumSize(new Dimension(80, 20));
- connectionStatePrgBar.setPreferredSize(new Dimension(80, 20));
- connectionStatePrgBar.setRequestFocusEnabled(false);
- connectionStatePrgBar.setString("Aufbau...");
- connectionStatePrgBar.setStringPainted(true);
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 0;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.insets = new Insets(0, 0, 0, 10);
- connectionStatePnl.add(connectionStatePrgBar, gbc);
- final JSeparator separator1 = new JSeparator();
- separator1.setMinimumSize(new Dimension(5, 1));
- separator1.setOrientation(1);
- separator1.setPreferredSize(new Dimension(5, 0));
- gbc = new GridBagConstraints();
- gbc.gridx = 3;
- gbc.gridy = 0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.BOTH;
- connectionStatePnl.add(separator1, gbc);
- reconnectBtn = new JButton();
- reconnectBtn.setBorderPainted(false);
- reconnectBtn.setContentAreaFilled(false);
- reconnectBtn.setIcon(new ImageIcon(getClass().getResource("/cable_reconnect.png")));
- reconnectBtn.setLabel("");
- reconnectBtn.setMaximumSize(new Dimension(32, 32));
- reconnectBtn.setMinimumSize(new Dimension(32, 32));
- reconnectBtn.setPreferredSize(new Dimension(32, 32));
- reconnectBtn.setPressedIcon(new ImageIcon(getClass().getResource("/cable_reconnect_pr.png")));
- reconnectBtn.setText("");
- reconnectBtn.setVisible(false);
- gbc = new GridBagConstraints();
- gbc.gridx = 2;
- gbc.gridy = 0;
- gbc.insets = new Insets(0, 0, 0, 10);
- connectionStatePnl.add(reconnectBtn, gbc);
- portPnl = new JPanel();
- portPnl.setLayout(new GridBagLayout());
- gbc = new GridBagConstraints();
- gbc.gridx = 2;
- gbc.gridy = 0;
- gbc.fill = GridBagConstraints.BOTH;
- statusBarPnl.add(portPnl, gbc);
- final JLabel label1 = new JLabel();
- Font label1Font = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, label1.getFont());
- if (label1Font != null) label1.setFont(label1Font);
- label1.setHorizontalAlignment(11);
- label1.setText("Port:");
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.anchor = GridBagConstraints.WEST;
- gbc.insets = new Insets(5, 0, 0, 10);
- portPnl.add(label1, gbc);
- portValueLbl = new JLabel();
- Font portValueLblFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, portValueLbl.getFont());
- if (portValueLblFont != null) portValueLbl.setFont(portValueLblFont);
- portValueLbl.setText(" ");
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 0;
- gbc.anchor = GridBagConstraints.WEST;
- gbc.insets = new Insets(5, 0, 0, 10);
- portPnl.add(portValueLbl, gbc);
- final JSeparator separator2 = new JSeparator();
- separator2.setMinimumSize(new Dimension(5, 1));
- separator2.setOrientation(1);
- separator2.setPreferredSize(new Dimension(5, 0));
- gbc = new GridBagConstraints();
- gbc.gridx = 2;
- gbc.gridy = 0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.BOTH;
- portPnl.add(separator2, gbc);
- versionPnl = new JPanel();
- versionPnl.setLayout(new GridBagLayout());
- gbc = new GridBagConstraints();
- gbc.gridx = 3;
- gbc.gridy = 0;
- gbc.fill = GridBagConstraints.BOTH;
- statusBarPnl.add(versionPnl, gbc);
- final JLabel label2 = new JLabel();
- Font label2Font = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, label2.getFont());
- if (label2Font != null) label2.setFont(label2Font);
- label2.setHorizontalAlignment(11);
- label2.setText("Ver:");
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.anchor = GridBagConstraints.WEST;
- gbc.insets = new Insets(5, 0, 0, 10);
- versionPnl.add(label2, gbc);
- versionValueLbl = new JLabel();
- Font versionValueLblFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, versionValueLbl.getFont());
- if (versionValueLblFont != null) versionValueLbl.setFont(versionValueLblFont);
- versionValueLbl.setText(" ");
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 0;
- gbc.anchor = GridBagConstraints.WEST;
- gbc.insets = new Insets(5, 0, 0, 10);
- versionPnl.add(versionValueLbl, gbc);
- }
-
- /**
- * @noinspection ALL
- */
- private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
- if (currentFont == null) return null;
- String resultName;
- if (fontName == null) {
- resultName = currentFont.getName();
- } else {
- Font testFont = new Font(fontName, Font.PLAIN, 10);
- if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
- resultName = fontName;
- } else {
- resultName = currentFont.getName();
- }
- }
- Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());
- boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac");
- Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize());
- return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback);
- }
-
- /**
- * @noinspection ALL
- */
- public JComponent $$$getRootComponent$$$() {
- return statusBarPnl;
- }
-
- private void createUIComponents() {
- this.statusBarPnl = new JPanel();
- this.statusBarPnl.setMinimumSize(new Dimension(2, 36));
- this.statusBarPnl.setPreferredSize(new Dimension(2, 36));
- this.statusBarPnl.setBorder(new CompoundBorder(new EmptyBorder(3, 3, 3, 3),
- new FlatLineBorder(new Insets(3, 3, 3, 3), Color.LIGHT_GRAY, 1, 10)));
-
-
- }
- }
|