UiTheme.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package com.mes.ui;
  2. import javax.swing.*;
  3. import javax.swing.border.Border;
  4. import javax.swing.border.EmptyBorder;
  5. import java.awt.*;
  6. /**
  7. * 弧焊客户端视觉主题:青绿工控底 + 琥珀强调(焊花感),避免花哨紫系。
  8. */
  9. public final class UiTheme {
  10. private UiTheme() {
  11. }
  12. /** 页面底 */
  13. public static final Color BG = new Color(232, 238, 244);
  14. /** 卡片白底 */
  15. public static final Color CARD = Color.WHITE;
  16. /** 分割线/边框 */
  17. public static final Color LINE = new Color(198, 210, 222);
  18. /** 正文文字色 */
  19. public static final Color TEXT = new Color(28, 40, 52);
  20. /** 次要/提示文字色 */
  21. public static final Color MUTED = new Color(100, 118, 135);
  22. /** 顶栏渐变上沿 */
  23. public static final Color HEADER_TOP = new Color(14, 42, 58);
  24. /** 顶栏渐变下沿 */
  25. public static final Color HEADER_BOTTOM = new Color(22, 78, 98);
  26. /** 主强调:青绿 */
  27. public static final Color ACCENT = new Color(0, 156, 148);
  28. /** 主强调深色(按下/描边) */
  29. public static final Color ACCENT_DARK = new Color(0, 120, 114);
  30. /** 次强调:琥珀(取码主按钮) */
  31. public static final Color AMBER = new Color(230, 145, 20);
  32. /** 琥珀深色(按钮渐变下沿) */
  33. public static final Color AMBER_DARK = new Color(190, 115, 10);
  34. /** 成功态背景 */
  35. public static final Color OK_BG = new Color(220, 245, 228);
  36. /** 成功态文字 */
  37. public static final Color OK_FG = new Color(20, 110, 55);
  38. /** 运行态背景 */
  39. public static final Color RUN_BG = new Color(220, 242, 248);
  40. /** 运行态文字 */
  41. public static final Color RUN_FG = new Color(15, 100, 120);
  42. /** 错误态背景 */
  43. public static final Color ERR_BG = new Color(255, 230, 228);
  44. /** 错误态文字 */
  45. public static final Color ERR_FG = new Color(175, 45, 40);
  46. /** 警告态文字 */
  47. public static final Color WARN_FG = new Color(220, 160, 70);
  48. /** 参数格色条:电压 */
  49. public static final Color STRIPE_VOLT = new Color(0, 156, 148);
  50. /** 参数格色条:电流 */
  51. public static final Color STRIPE_AMP = new Color(50, 130, 200);
  52. /** 参数格色条:加压/送丝类 */
  53. public static final Color STRIPE_WIRE = new Color(90, 140, 80);
  54. /** 参数格色条:产量计数 */
  55. public static final Color STRIPE_SIDE = new Color(230, 145, 20);
  56. /** 参数格色条:规范号 */
  57. public static final Color STRIPE_JOB = new Color(120, 100, 180);
  58. /** 参数格色条:报警 */
  59. public static final Color STRIPE_ERR = new Color(200, 70, 70);
  60. /** 参数格色条:设备类型 */
  61. public static final Color STRIPE_DEV = new Color(80, 110, 140);
  62. /** 标题字体 */
  63. public static final Font FONT_TITLE = new Font("微软雅黑", Font.BOLD, 20);
  64. /** 正文字体 */
  65. public static final Font FONT_BODY = new Font("微软雅黑", Font.PLAIN, 14);
  66. /** 小标签字体 */
  67. public static final Font FONT_LABEL = new Font("微软雅黑", Font.PLAIN, 12);
  68. /** 工件码大号字体 */
  69. public static final Font FONT_SN = new Font("Consolas", Font.BOLD, 28);
  70. /** 参数值等宽字体 */
  71. public static final Font FONT_VALUE = new Font("Consolas", Font.BOLD, 17);
  72. /** 主按钮字体 */
  73. public static final Font FONT_BTN = new Font("微软雅黑", Font.BOLD, 15);
  74. public static void applyLookAndFeel() {
  75. try {
  76. for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
  77. if ("Nimbus".equals(info.getName())) {
  78. UIManager.setLookAndFeel(info.getClassName());
  79. UIManager.put("nimbusBase", HEADER_BOTTOM);
  80. UIManager.put("nimbusBlueGrey", new Color(70, 110, 125));
  81. UIManager.put("control", BG);
  82. UIManager.put("nimbusSelectionBackground", ACCENT);
  83. UIManager.put("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter", null);
  84. return;
  85. }
  86. }
  87. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  88. } catch (Exception ignored) {
  89. }
  90. }
  91. /** 顶栏渐变面板 */
  92. public static JPanel gradientHeader() {
  93. return new JPanel(new BorderLayout(16, 0)) {
  94. /** 序列化版本号 */
  95. private static final long serialVersionUID = 1L;
  96. @Override
  97. protected void paintComponent(Graphics g) {
  98. Graphics2D g2 = (Graphics2D) g.create();
  99. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  100. GradientPaint gp = new GradientPaint(0, 0, HEADER_TOP, getWidth(), getHeight(), HEADER_BOTTOM);
  101. g2.setPaint(gp);
  102. g2.fillRect(0, 0, getWidth(), getHeight());
  103. // 底部青绿细线
  104. g2.setColor(ACCENT);
  105. g2.fillRect(0, getHeight() - 3, getWidth(), 3);
  106. g2.dispose();
  107. }
  108. };
  109. }
  110. public static Border cardBorder() {
  111. return BorderFactory.createCompoundBorder(
  112. BorderFactory.createLineBorder(LINE),
  113. new EmptyBorder(14, 16, 14, 16));
  114. }
  115. public static JPanel card() {
  116. JPanel p = new JPanel();
  117. p.setBackground(CARD);
  118. p.setBorder(cardBorder());
  119. return p;
  120. }
  121. /** 带左侧色条的参数格 */
  122. public static JPanel paramTile(String label, JTextField field, Color stripe) {
  123. JPanel outer = new JPanel(new BorderLayout(0, 0));
  124. outer.setOpaque(false);
  125. JPanel stripeBar = new JPanel();
  126. stripeBar.setPreferredSize(new Dimension(4, 10));
  127. stripeBar.setBackground(stripe);
  128. stripeBar.setOpaque(true);
  129. JPanel inner = new JPanel(new BorderLayout(0, 5));
  130. inner.setBackground(new Color(248, 251, 252));
  131. inner.setBorder(new EmptyBorder(8, 10, 8, 10));
  132. JLabel lb = mutedLabel(label);
  133. inner.add(lb, BorderLayout.NORTH);
  134. field.setBackground(Color.WHITE);
  135. inner.add(field, BorderLayout.CENTER);
  136. outer.add(stripeBar, BorderLayout.WEST);
  137. outer.add(inner, BorderLayout.CENTER);
  138. outer.setBorder(BorderFactory.createLineBorder(LINE));
  139. return outer;
  140. }
  141. public static JLabel mutedLabel(String text) {
  142. JLabel l = new JLabel(text);
  143. l.setFont(FONT_LABEL);
  144. l.setForeground(MUTED);
  145. return l;
  146. }
  147. public static JLabel sectionTitle(String text) {
  148. JLabel l = new JLabel(text);
  149. l.setFont(new Font("微软雅黑", Font.BOLD, 13));
  150. l.setForeground(HEADER_BOTTOM);
  151. return l;
  152. }
  153. public static JTextField valueField() {
  154. JTextField f = new JTextField();
  155. f.setEditable(false);
  156. f.setFont(FONT_VALUE);
  157. f.setForeground(TEXT);
  158. f.setBackground(Color.WHITE);
  159. f.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
  160. return f;
  161. }
  162. public static JButton primaryBtn(String text) {
  163. JButton b = new JButton(text) {
  164. /** 序列化版本号 */
  165. private static final long serialVersionUID = 1L;
  166. @Override
  167. protected void paintComponent(Graphics g) {
  168. Graphics2D g2 = (Graphics2D) g.create();
  169. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  170. GradientPaint gp = new GradientPaint(0, 0, AMBER, 0, getHeight(), AMBER_DARK);
  171. g2.setPaint(gp);
  172. g2.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);
  173. g2.dispose();
  174. super.paintComponent(g);
  175. }
  176. };
  177. b.setFont(FONT_BTN);
  178. b.setPreferredSize(new Dimension(132, 44));
  179. b.setFocusPainted(false);
  180. b.setContentAreaFilled(false);
  181. b.setBorderPainted(false);
  182. b.setForeground(Color.WHITE);
  183. b.setOpaque(false);
  184. b.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  185. return b;
  186. }
  187. public static JButton ghostBtn(String text) {
  188. JButton b = new JButton(text);
  189. b.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  190. b.setPreferredSize(new Dimension(Math.max(92, text.length() * 15), 44));
  191. b.setFocusPainted(false);
  192. b.setBackground(CARD);
  193. b.setForeground(HEADER_BOTTOM);
  194. b.setOpaque(true);
  195. b.setBorder(BorderFactory.createCompoundBorder(
  196. BorderFactory.createLineBorder(new Color(170, 195, 205)),
  197. new EmptyBorder(6, 14, 6, 14)));
  198. b.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  199. return b;
  200. }
  201. /** PLC 状态小胶囊底色 */
  202. public static void stylePlcPill(JLabel label, boolean ok) {
  203. label.setOpaque(true);
  204. label.setBorder(new EmptyBorder(6, 12, 6, 12));
  205. if (ok) {
  206. label.setBackground(new Color(30, 90, 80));
  207. label.setForeground(new Color(160, 240, 210));
  208. } else {
  209. label.setBackground(new Color(70, 50, 30));
  210. label.setForeground(WARN_FG);
  211. }
  212. }
  213. }