package com.mes.ui; import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; import java.awt.*; /** * 弧焊客户端视觉主题:青绿工控底 + 琥珀强调(焊花感),避免花哨紫系。 */ public final class UiTheme { private UiTheme() { } /** 页面底 */ public static final Color BG = new Color(232, 238, 244); /** 卡片白底 */ public static final Color CARD = Color.WHITE; /** 分割线/边框 */ public static final Color LINE = new Color(198, 210, 222); /** 正文文字色 */ public static final Color TEXT = new Color(28, 40, 52); /** 次要/提示文字色 */ public static final Color MUTED = new Color(100, 118, 135); /** 顶栏渐变上沿 */ public static final Color HEADER_TOP = new Color(14, 42, 58); /** 顶栏渐变下沿 */ public static final Color HEADER_BOTTOM = new Color(22, 78, 98); /** 主强调:青绿 */ public static final Color ACCENT = new Color(0, 156, 148); /** 主强调深色(按下/描边) */ public static final Color ACCENT_DARK = new Color(0, 120, 114); /** 次强调:琥珀(取码主按钮) */ public static final Color AMBER = new Color(230, 145, 20); /** 琥珀深色(按钮渐变下沿) */ public static final Color AMBER_DARK = new Color(190, 115, 10); /** 成功态背景 */ public static final Color OK_BG = new Color(220, 245, 228); /** 成功态文字 */ public static final Color OK_FG = new Color(20, 110, 55); /** 运行态背景 */ public static final Color RUN_BG = new Color(220, 242, 248); /** 运行态文字 */ public static final Color RUN_FG = new Color(15, 100, 120); /** 错误态背景 */ public static final Color ERR_BG = new Color(255, 230, 228); /** 错误态文字 */ public static final Color ERR_FG = new Color(175, 45, 40); /** 警告态文字 */ public static final Color WARN_FG = new Color(220, 160, 70); /** 参数格色条:电压 */ public static final Color STRIPE_VOLT = new Color(0, 156, 148); /** 参数格色条:电流 */ public static final Color STRIPE_AMP = new Color(50, 130, 200); /** 参数格色条:加压/送丝类 */ public static final Color STRIPE_WIRE = new Color(90, 140, 80); /** 参数格色条:产量计数 */ public static final Color STRIPE_SIDE = new Color(230, 145, 20); /** 参数格色条:规范号 */ public static final Color STRIPE_JOB = new Color(120, 100, 180); /** 参数格色条:报警 */ public static final Color STRIPE_ERR = new Color(200, 70, 70); /** 参数格色条:设备类型 */ public static final Color STRIPE_DEV = new Color(80, 110, 140); /** 标题字体 */ public static final Font FONT_TITLE = new Font("微软雅黑", Font.BOLD, 20); /** 正文字体 */ public static final Font FONT_BODY = new Font("微软雅黑", Font.PLAIN, 14); /** 小标签字体 */ public static final Font FONT_LABEL = new Font("微软雅黑", Font.PLAIN, 12); /** 工件码大号字体 */ public static final Font FONT_SN = new Font("Consolas", Font.BOLD, 28); /** 参数值等宽字体 */ public static final Font FONT_VALUE = new Font("Consolas", Font.BOLD, 17); /** 主按钮字体 */ public static final Font FONT_BTN = new Font("微软雅黑", Font.BOLD, 15); public static void applyLookAndFeel() { try { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); UIManager.put("nimbusBase", HEADER_BOTTOM); UIManager.put("nimbusBlueGrey", new Color(70, 110, 125)); UIManager.put("control", BG); UIManager.put("nimbusSelectionBackground", ACCENT); UIManager.put("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter", null); return; } } UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ignored) { } } /** 顶栏渐变面板 */ public static JPanel gradientHeader() { return new JPanel(new BorderLayout(16, 0)) { /** 序列化版本号 */ private static final long serialVersionUID = 1L; @Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint gp = new GradientPaint(0, 0, HEADER_TOP, getWidth(), getHeight(), HEADER_BOTTOM); g2.setPaint(gp); g2.fillRect(0, 0, getWidth(), getHeight()); // 底部青绿细线 g2.setColor(ACCENT); g2.fillRect(0, getHeight() - 3, getWidth(), 3); g2.dispose(); } }; } public static Border cardBorder() { return BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(LINE), new EmptyBorder(14, 16, 14, 16)); } public static JPanel card() { JPanel p = new JPanel(); p.setBackground(CARD); p.setBorder(cardBorder()); return p; } /** 带左侧色条的参数格 */ public static JPanel paramTile(String label, JTextField field, Color stripe) { JPanel outer = new JPanel(new BorderLayout(0, 0)); outer.setOpaque(false); JPanel stripeBar = new JPanel(); stripeBar.setPreferredSize(new Dimension(4, 10)); stripeBar.setBackground(stripe); stripeBar.setOpaque(true); JPanel inner = new JPanel(new BorderLayout(0, 5)); inner.setBackground(new Color(248, 251, 252)); inner.setBorder(new EmptyBorder(8, 10, 8, 10)); JLabel lb = mutedLabel(label); inner.add(lb, BorderLayout.NORTH); field.setBackground(Color.WHITE); inner.add(field, BorderLayout.CENTER); outer.add(stripeBar, BorderLayout.WEST); outer.add(inner, BorderLayout.CENTER); outer.setBorder(BorderFactory.createLineBorder(LINE)); return outer; } public static JLabel mutedLabel(String text) { JLabel l = new JLabel(text); l.setFont(FONT_LABEL); l.setForeground(MUTED); return l; } public static JLabel sectionTitle(String text) { JLabel l = new JLabel(text); l.setFont(new Font("微软雅黑", Font.BOLD, 13)); l.setForeground(HEADER_BOTTOM); return l; } public static JTextField valueField() { JTextField f = new JTextField(); f.setEditable(false); f.setFont(FONT_VALUE); f.setForeground(TEXT); f.setBackground(Color.WHITE); f.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); return f; } public static JButton primaryBtn(String text) { JButton b = new JButton(text) { /** 序列化版本号 */ private static final long serialVersionUID = 1L; @Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint gp = new GradientPaint(0, 0, AMBER, 0, getHeight(), AMBER_DARK); g2.setPaint(gp); g2.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8); g2.dispose(); super.paintComponent(g); } }; b.setFont(FONT_BTN); b.setPreferredSize(new Dimension(132, 44)); b.setFocusPainted(false); b.setContentAreaFilled(false); b.setBorderPainted(false); b.setForeground(Color.WHITE); b.setOpaque(false); b.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); return b; } public static JButton ghostBtn(String text) { JButton b = new JButton(text); b.setFont(new Font("微软雅黑", Font.PLAIN, 14)); b.setPreferredSize(new Dimension(Math.max(92, text.length() * 15), 44)); b.setFocusPainted(false); b.setBackground(CARD); b.setForeground(HEADER_BOTTOM); b.setOpaque(true); b.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(new Color(170, 195, 205)), new EmptyBorder(6, 14, 6, 14))); b.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); return b; } /** PLC 状态小胶囊底色 */ public static void stylePlcPill(JLabel label, boolean ok) { label.setOpaque(true); label.setBorder(new EmptyBorder(6, 12, 6, 12)); if (ok) { label.setBackground(new Color(30, 90, 80)); label.setForeground(new Color(160, 240, 210)); } else { label.setBackground(new Color(70, 50, 30)); label.setForeground(WARN_FG); } } }