Remote Control zum Einschalten des 3D-Druckers und Bewegen der ebCam im Hobbyraum Brand
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FSStatusBar.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. package ch.spherICIT.components.statusbar;
  2. import ch.spherICIT.main.ConnectionState;
  3. import ch.spherICIT.main.IConnectionState;
  4. import ch.spherICIT.main.ConnectionStateInfo;
  5. import com.formdev.flatlaf.ui.FlatLineBorder;
  6. import com.formdev.flatlaf.util.StringUtils;
  7. import javax.swing.ImageIcon;
  8. import javax.swing.JButton;
  9. import javax.swing.JComponent;
  10. import javax.swing.JLabel;
  11. import javax.swing.JPanel;
  12. import javax.swing.JProgressBar;
  13. import javax.swing.JSeparator;
  14. import javax.swing.border.CompoundBorder;
  15. import javax.swing.border.EmptyBorder;
  16. import javax.swing.plaf.FontUIResource;
  17. import javax.swing.text.StyleContext;
  18. import java.awt.Color;
  19. import java.awt.Dimension;
  20. import java.awt.Font;
  21. import java.awt.GridBagConstraints;
  22. import java.awt.GridBagLayout;
  23. import java.awt.Insets;
  24. import java.awt.event.ActionEvent;
  25. import java.awt.event.ActionListener;
  26. import java.util.Locale;
  27. public class FSStatusBar implements IConnectionState {
  28. private JPanel statusBarPnl;
  29. private JPanel connectionStatePnl;
  30. private JProgressBar connectionStatePrgBar;
  31. private JPanel portPnl;
  32. private JLabel connectionStateLbl;
  33. private JLabel portValueLbl;
  34. private JPanel versionPnl;
  35. private JLabel versionValueLbl;
  36. private JButton reconnectBtn;
  37. private ActionListener reconnectActionListener;
  38. public FSStatusBar() {
  39. $$$setupUI$$$();
  40. this.reconnectBtn.addActionListener(new ActionListener() {
  41. @Override
  42. public void actionPerformed(ActionEvent e) {
  43. if (FSStatusBar.this.reconnectActionListener != null) {
  44. FSStatusBar.this.reconnectActionListener.actionPerformed(e);
  45. }
  46. }
  47. });
  48. }
  49. public void setReconnectActionListener(ActionListener reconnectActionListener) {
  50. this.reconnectActionListener = reconnectActionListener;
  51. }
  52. @Override
  53. public void connectionStateChanged(ConnectionStateInfo connectionStateInfo) {
  54. this.reconnectBtn.setVisible(false);
  55. this.portValueLbl.setText(" ");
  56. this.versionValueLbl.setText(" ");
  57. if (connectionStateInfo.connectionState().equals(ConnectionState.CONNECTING)) {
  58. this.connectionStateLbl.setText("Am Verbinden...");
  59. this.connectionStatePrgBar.setString("Aufbau...");
  60. this.connectionStatePrgBar.setIndeterminate(true);
  61. } else if (connectionStateInfo.connectionState().equals(ConnectionState.CONNECTED)) {
  62. this.connectionStateLbl.setText("Verbunden!");
  63. this.connectionStatePrgBar.setString("OK!");
  64. this.connectionStatePrgBar.setIndeterminate(false);
  65. this.connectionStatePrgBar.setValue(100);
  66. this.portValueLbl.setText(StringUtils.isEmpty(connectionStateInfo.port()) ? " " : connectionStateInfo.port());
  67. this.versionValueLbl.setText(StringUtils.isEmpty(connectionStateInfo.version()) ? " " : connectionStateInfo.version());
  68. } else {
  69. this.connectionStateLbl.setText("Zeitüberschreitung!");
  70. this.connectionStatePrgBar.setString("Nicht verbunden");
  71. this.connectionStatePrgBar.setIndeterminate(false);
  72. this.connectionStatePrgBar.setValue(0);
  73. this.reconnectBtn.setVisible(true);
  74. }
  75. }
  76. /**
  77. * Method generated by IntelliJ IDEA GUI Designer
  78. * >>> IMPORTANT!! <<<
  79. * DO NOT edit this method OR call it in your code!
  80. *
  81. * @noinspection ALL
  82. */
  83. private void $$$setupUI$$$() {
  84. createUIComponents();
  85. statusBarPnl.setLayout(new GridBagLayout());
  86. final JPanel spacer1 = new JPanel();
  87. GridBagConstraints gbc;
  88. gbc = new GridBagConstraints();
  89. gbc.gridx = 0;
  90. gbc.gridy = 0;
  91. gbc.weightx = 1.0;
  92. gbc.fill = GridBagConstraints.HORIZONTAL;
  93. statusBarPnl.add(spacer1, gbc);
  94. connectionStatePnl = new JPanel();
  95. connectionStatePnl.setLayout(new GridBagLayout());
  96. gbc = new GridBagConstraints();
  97. gbc.gridx = 1;
  98. gbc.gridy = 0;
  99. gbc.weighty = 1.0;
  100. gbc.fill = GridBagConstraints.BOTH;
  101. statusBarPnl.add(connectionStatePnl, gbc);
  102. connectionStateLbl = new JLabel();
  103. Font connectionStateLblFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, connectionStateLbl.getFont());
  104. if (connectionStateLblFont != null) connectionStateLbl.setFont(connectionStateLblFont);
  105. connectionStateLbl.setHorizontalAlignment(11);
  106. connectionStateLbl.setText("Am Verbinden...");
  107. gbc = new GridBagConstraints();
  108. gbc.gridx = 0;
  109. gbc.gridy = 0;
  110. gbc.anchor = GridBagConstraints.EAST;
  111. gbc.insets = new Insets(5, 0, 0, 10);
  112. connectionStatePnl.add(connectionStateLbl, gbc);
  113. connectionStatePrgBar = new JProgressBar();
  114. connectionStatePrgBar.setForeground(new Color(-16738404));
  115. connectionStatePrgBar.setIndeterminate(true);
  116. connectionStatePrgBar.setMinimumSize(new Dimension(80, 20));
  117. connectionStatePrgBar.setPreferredSize(new Dimension(80, 20));
  118. connectionStatePrgBar.setRequestFocusEnabled(false);
  119. connectionStatePrgBar.setString("Aufbau...");
  120. connectionStatePrgBar.setStringPainted(true);
  121. gbc = new GridBagConstraints();
  122. gbc.gridx = 1;
  123. gbc.gridy = 0;
  124. gbc.fill = GridBagConstraints.BOTH;
  125. gbc.insets = new Insets(0, 0, 0, 10);
  126. connectionStatePnl.add(connectionStatePrgBar, gbc);
  127. final JSeparator separator1 = new JSeparator();
  128. separator1.setMinimumSize(new Dimension(5, 1));
  129. separator1.setOrientation(1);
  130. separator1.setPreferredSize(new Dimension(5, 0));
  131. gbc = new GridBagConstraints();
  132. gbc.gridx = 3;
  133. gbc.gridy = 0;
  134. gbc.weighty = 1.0;
  135. gbc.fill = GridBagConstraints.BOTH;
  136. connectionStatePnl.add(separator1, gbc);
  137. reconnectBtn = new JButton();
  138. reconnectBtn.setBorderPainted(false);
  139. reconnectBtn.setContentAreaFilled(false);
  140. reconnectBtn.setIcon(new ImageIcon(getClass().getResource("/cable_reconnect.png")));
  141. reconnectBtn.setLabel("");
  142. reconnectBtn.setMaximumSize(new Dimension(32, 32));
  143. reconnectBtn.setMinimumSize(new Dimension(32, 32));
  144. reconnectBtn.setPreferredSize(new Dimension(32, 32));
  145. reconnectBtn.setPressedIcon(new ImageIcon(getClass().getResource("/cable_reconnect_pr.png")));
  146. reconnectBtn.setText("");
  147. reconnectBtn.setVisible(false);
  148. gbc = new GridBagConstraints();
  149. gbc.gridx = 2;
  150. gbc.gridy = 0;
  151. gbc.insets = new Insets(0, 0, 0, 10);
  152. connectionStatePnl.add(reconnectBtn, gbc);
  153. portPnl = new JPanel();
  154. portPnl.setLayout(new GridBagLayout());
  155. gbc = new GridBagConstraints();
  156. gbc.gridx = 2;
  157. gbc.gridy = 0;
  158. gbc.fill = GridBagConstraints.BOTH;
  159. statusBarPnl.add(portPnl, gbc);
  160. final JLabel label1 = new JLabel();
  161. Font label1Font = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, label1.getFont());
  162. if (label1Font != null) label1.setFont(label1Font);
  163. label1.setHorizontalAlignment(11);
  164. label1.setText("Port:");
  165. gbc = new GridBagConstraints();
  166. gbc.gridx = 0;
  167. gbc.gridy = 0;
  168. gbc.anchor = GridBagConstraints.WEST;
  169. gbc.insets = new Insets(5, 0, 0, 10);
  170. portPnl.add(label1, gbc);
  171. portValueLbl = new JLabel();
  172. Font portValueLblFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, portValueLbl.getFont());
  173. if (portValueLblFont != null) portValueLbl.setFont(portValueLblFont);
  174. portValueLbl.setText(" ");
  175. gbc = new GridBagConstraints();
  176. gbc.gridx = 1;
  177. gbc.gridy = 0;
  178. gbc.anchor = GridBagConstraints.WEST;
  179. gbc.insets = new Insets(5, 0, 0, 10);
  180. portPnl.add(portValueLbl, gbc);
  181. final JSeparator separator2 = new JSeparator();
  182. separator2.setMinimumSize(new Dimension(5, 1));
  183. separator2.setOrientation(1);
  184. separator2.setPreferredSize(new Dimension(5, 0));
  185. gbc = new GridBagConstraints();
  186. gbc.gridx = 2;
  187. gbc.gridy = 0;
  188. gbc.weighty = 1.0;
  189. gbc.fill = GridBagConstraints.BOTH;
  190. portPnl.add(separator2, gbc);
  191. versionPnl = new JPanel();
  192. versionPnl.setLayout(new GridBagLayout());
  193. gbc = new GridBagConstraints();
  194. gbc.gridx = 3;
  195. gbc.gridy = 0;
  196. gbc.fill = GridBagConstraints.BOTH;
  197. statusBarPnl.add(versionPnl, gbc);
  198. final JLabel label2 = new JLabel();
  199. Font label2Font = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, label2.getFont());
  200. if (label2Font != null) label2.setFont(label2Font);
  201. label2.setHorizontalAlignment(11);
  202. label2.setText("Ver:");
  203. gbc = new GridBagConstraints();
  204. gbc.gridx = 0;
  205. gbc.gridy = 0;
  206. gbc.anchor = GridBagConstraints.WEST;
  207. gbc.insets = new Insets(5, 0, 0, 10);
  208. versionPnl.add(label2, gbc);
  209. versionValueLbl = new JLabel();
  210. Font versionValueLblFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 12, versionValueLbl.getFont());
  211. if (versionValueLblFont != null) versionValueLbl.setFont(versionValueLblFont);
  212. versionValueLbl.setText(" ");
  213. gbc = new GridBagConstraints();
  214. gbc.gridx = 1;
  215. gbc.gridy = 0;
  216. gbc.anchor = GridBagConstraints.WEST;
  217. gbc.insets = new Insets(5, 0, 0, 10);
  218. versionPnl.add(versionValueLbl, gbc);
  219. }
  220. /**
  221. * @noinspection ALL
  222. */
  223. private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
  224. if (currentFont == null) return null;
  225. String resultName;
  226. if (fontName == null) {
  227. resultName = currentFont.getName();
  228. } else {
  229. Font testFont = new Font(fontName, Font.PLAIN, 10);
  230. if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
  231. resultName = fontName;
  232. } else {
  233. resultName = currentFont.getName();
  234. }
  235. }
  236. Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());
  237. boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac");
  238. Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize());
  239. return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback);
  240. }
  241. /**
  242. * @noinspection ALL
  243. */
  244. public JComponent $$$getRootComponent$$$() {
  245. return statusBarPnl;
  246. }
  247. private void createUIComponents() {
  248. this.statusBarPnl = new JPanel();
  249. this.statusBarPnl.setMinimumSize(new Dimension(2, 36));
  250. this.statusBarPnl.setPreferredSize(new Dimension(2, 36));
  251. this.statusBarPnl.setBorder(new CompoundBorder(new EmptyBorder(3, 3, 3, 3),
  252. new FlatLineBorder(new Insets(3, 3, 3, 3), Color.LIGHT_GRAY, 1, 10)));
  253. }
  254. }