| | |
| | | |
| | | import java.awt.*; |
| | | import java.awt.event.*; |
| | | import java.awt.geom.RoundRectangle2D; |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | */ |
| | | public class Sets extends JDialog { |
| | | private static final long serialVersionUID = 1L; |
| | | private static final int ROW_HEIGHT = 40; |
| | | private static final int ROW_SPACING = 25; |
| | | private static final int ROW_HEIGHT = 50; // å¢å è¡é«ä»¥éåºåå²çº¿ |
| | | private static final int ITEM_PADDING = 16; // å表项å
è¾¹è· |
| | | |
| | | // 主é¢é¢è² |
| | | private final Color THEME_COLOR; |
| | | private final Color BACKGROUND_COLOR = new Color(250, 250, 250); |
| | | private final Color PANEL_BACKGROUND = new Color(255, 255, 255); |
| | | private final Color BORDER_COLOR = new Color(220, 220, 220); |
| | | private final Color BACKGROUND_COLOR = new Color(245, 247, 250); // æ´æåçæµ
ç°è²èæ¯ |
| | | private final Color PANEL_BACKGROUND = new Color(255, 255, 255); // ç½è²é¢æ¿ |
| | | private final Color BORDER_COLOR = new Color(233, 236, 239); // æµ
è¾¹æ¡è² |
| | | private final Color DIVIDER_COLOR = new Color(233, 236, 239); // åå²çº¿é¢è² |
| | | |
| | | // 设置项ç»ä»¶ |
| | | private JLabel mowerIdLabel; |
| | |
| | | private JLabel firmwareVersionLabel; |
| | | private JLabel appVersionLabel; |
| | | private JLabel idleTrailDurationLabel; |
| | | private JLabel boundaryLengthVisibleLabel; |
| | | |
| | | private JButton mowerIdEditBtn; |
| | | private JButton baseStationIdEditBtn; |
| | |
| | | setLocationRelativeTo(getParent()); |
| | | setResizable(false); |
| | | |
| | | // å建主å
容颿¿ |
| | | // å建主å
容颿¿ï¼ä½¿ç¨æ´æåçæµ
ç°è²èæ¯ï¼ |
| | | JPanel mainPanel = new JPanel(); |
| | | mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); |
| | | mainPanel.setLayout(new BorderLayout()); |
| | | mainPanel.setBackground(BACKGROUND_COLOR); |
| | | mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); |
| | | |
| | | // åå»ºè®¾ç½®é¡¹é¢æ¿ |
| | | // åå»ºè®¾ç½®é¡¹é¢æ¿ï¼åè§ç½è²é¢æ¿ï¼ |
| | | JPanel settingsPanel = createSettingsPanel(); |
| | | |
| | | // æ·»å ç»ä»¶å°ä¸»é¢æ¿ |
| | | mainPanel.add(settingsPanel); |
| | | mainPanel.add(Box.createVerticalGlue()); |
| | | mainPanel.add(settingsPanel, BorderLayout.CENTER); |
| | | |
| | | add(mainPanel, BorderLayout.CENTER); |
| | | } |
| | | |
| | | private JPanel createSettingsPanel() { |
| | | // å建åè§ç½è²é¢æ¿å®¹å¨ |
| | | JPanel container = new JPanel() { |
| | | @Override |
| | | protected void paintComponent(Graphics g) { |
| | | Graphics2D g2d = (Graphics2D) g.create(); |
| | | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| | | g2d.setColor(PANEL_BACKGROUND); |
| | | // ç»å¶åè§ç©å½¢èæ¯ |
| | | g2d.fillRoundRect(0, 0, getWidth(), getHeight(), 16, 16); |
| | | g2d.dispose(); |
| | | } |
| | | }; |
| | | container.setLayout(new BorderLayout()); |
| | | container.setOpaque(false); |
| | | |
| | | // å
容颿¿ |
| | | JPanel panel = new JPanel(); |
| | | panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); |
| | | panel.setBackground(PANEL_BACKGROUND); |
| | | panel.setBorder(BorderFactory.createCompoundBorder( |
| | | BorderFactory.createLineBorder(BORDER_COLOR), |
| | | BorderFactory.createEmptyBorder(20, 20, 20, 20) |
| | | )); |
| | | panel.setOpaque(false); |
| | | panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0)); |
| | | |
| | | // å²èæºç¼å· |
| | | JPanel mowerIdPanel = createSettingItemPanel("å²èæºç¼å·", |
| | |
| | | formatIdleTrailDurationValue(), true); |
| | | idleTrailDurationLabel = (JLabel) idleTrailPanel.getClientProperty("valueLabel"); |
| | | idleTrailEditBtn = (JButton) idleTrailPanel.getClientProperty("editButton"); |
| | | |
| | | // æ¾ç¤ºè¾¹çè·ç¦»è®¾ç½®é¡¹ |
| | | JPanel boundaryLengthPanel = createBoundaryLengthPanel(); |
| | | boundaryLengthVisibleLabel = (JLabel) boundaryLengthPanel.getClientProperty("valueLabel"); |
| | | |
| | | JPanel feedbackPanel = createFeedbackPanel(); |
| | | |
| | | // APPçæ¬ |
| | | JPanel appVersionPanel = createAppVersionPanel(); |
| | | |
| | | addRowWithSpacing(panel, mowerIdPanel); |
| | | addRowWithSpacing(panel, baseStationIdPanel); |
| | | addRowWithSpacing(panel, handheldPanel); |
| | | addRowWithSpacing(panel, simCardPanel); |
| | | addRowWithSpacing(panel, baseStationSimPanel); |
| | | addRowWithSpacing(panel, firmwarePanel); |
| | | addRowWithSpacing(panel, idleTrailPanel); |
| | | addRowWithSpacing(panel, feedbackPanel); |
| | | addRowWithSpacing(panel, appVersionPanel); |
| | | // æ·»å 设置项ï¼ä½¿ç¨åå²çº¿åé |
| | | addSettingItem(panel, mowerIdPanel, true); |
| | | addSettingItem(panel, baseStationIdPanel, true); |
| | | addSettingItem(panel, handheldPanel, true); |
| | | addSettingItem(panel, simCardPanel, true); |
| | | addSettingItem(panel, baseStationSimPanel, true); |
| | | addSettingItem(panel, firmwarePanel, true); |
| | | addSettingItem(panel, idleTrailPanel, true); |
| | | addSettingItem(panel, boundaryLengthPanel, true); |
| | | addSettingItem(panel, feedbackPanel, true); |
| | | addSettingItem(panel, appVersionPanel, false); // æåä¸é¡¹ä¸å åå²çº¿ |
| | | |
| | | return panel; |
| | | container.add(panel, BorderLayout.CENTER); |
| | | return container; |
| | | } |
| | | |
| | | /** |
| | | * æ·»å 设置项ï¼å¸¦åå²çº¿ï¼ |
| | | */ |
| | | private void addSettingItem(JPanel container, JPanel itemPanel, boolean showDivider) { |
| | | container.add(itemPanel); |
| | | if (showDivider) { |
| | | // æ·»å åå²çº¿ |
| | | JSeparator divider = new JSeparator(); |
| | | divider.setForeground(DIVIDER_COLOR); |
| | | divider.setMaximumSize(new Dimension(Integer.MAX_VALUE, 1)); |
| | | divider.setAlignmentX(Component.LEFT_ALIGNMENT); |
| | | container.add(divider); |
| | | } |
| | | } |
| | | |
| | | private String formatIdleTrailDurationValue() { |
| | |
| | | return seconds + "ç§"; |
| | | } |
| | | |
| | | private void addRowWithSpacing(JPanel container, JPanel row) { |
| | | container.add(row); |
| | | container.add(Box.createRigidArea(new Dimension(0, ROW_SPACING))); |
| | | } |
| | | |
| | | private JPanel createSettingItemPanel(String title, String value, boolean editable) { |
| | | JPanel panel = new JPanel(new GridBagLayout()); |
| | | panel.setBackground(PANEL_BACKGROUND); |
| | | panel.setOpaque(false); // éæèæ¯ï¼ç±å®¹å¨ç»å¶ |
| | | panel.setAlignmentX(Component.LEFT_ALIGNMENT); |
| | | panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT)); |
| | | panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT)); |
| | | panel.setMinimumSize(new Dimension(0, ROW_HEIGHT)); |
| | | panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING)); |
| | | |
| | | GridBagConstraints gbc = new GridBagConstraints(); |
| | | |
| | |
| | | |
| | | private JPanel createAppVersionPanel() { |
| | | JPanel panel = new JPanel(new GridBagLayout()); |
| | | panel.setBackground(PANEL_BACKGROUND); |
| | | panel.setOpaque(false); // éæèæ¯ |
| | | panel.setAlignmentX(Component.LEFT_ALIGNMENT); |
| | | panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT)); |
| | | panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT)); |
| | | panel.setMinimumSize(new Dimension(0, ROW_HEIGHT)); |
| | | panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING)); |
| | | |
| | | GridBagConstraints gbc = new GridBagConstraints(); |
| | | |
| | |
| | | |
| | | private JPanel createFeedbackPanel() { |
| | | JPanel panel = new JPanel(new GridBagLayout()); |
| | | panel.setBackground(PANEL_BACKGROUND); |
| | | panel.setOpaque(false); // éæèæ¯ |
| | | panel.setAlignmentX(Component.LEFT_ALIGNMENT); |
| | | panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT)); |
| | | panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT)); |
| | | panel.setMinimumSize(new Dimension(0, ROW_HEIGHT)); |
| | | panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING)); |
| | | |
| | | GridBagConstraints gbc = new GridBagConstraints(); |
| | | |
| | |
| | | return panel; |
| | | } |
| | | |
| | | /** |
| | | * å建æ¾ç¤ºè¾¹çè·ç¦»è®¾ç½®é¢æ¿ |
| | | */ |
| | | private JPanel createBoundaryLengthPanel() { |
| | | JPanel panel = new JPanel(new GridBagLayout()); |
| | | panel.setOpaque(false); // éæèæ¯ |
| | | panel.setAlignmentX(Component.LEFT_ALIGNMENT); |
| | | panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT)); |
| | | panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT)); |
| | | panel.setMinimumSize(new Dimension(0, ROW_HEIGHT)); |
| | | panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING)); |
| | | |
| | | GridBagConstraints gbc = new GridBagConstraints(); |
| | | |
| | | JLabel titleLabel = new JLabel("æ¾ç¤ºè¾¹çè·ç¦»"); |
| | | titleLabel.setFont(new Font("微软é
é»", Font.BOLD, 14)); |
| | | titleLabel.setForeground(Color.BLACK); |
| | | titleLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| | | gbc.gridx = 0; |
| | | gbc.gridy = 0; |
| | | gbc.weightx = 0; |
| | | gbc.anchor = GridBagConstraints.EAST; |
| | | gbc.insets = new Insets(0, 0, 0, 12); |
| | | panel.add(titleLabel, gbc); |
| | | |
| | | boundaryLengthVisibleLabel = new JLabel(setData.isBoundaryLengthVisible() ? "å·²å¼å¯" : "å·²å
³é"); |
| | | boundaryLengthVisibleLabel.setFont(new Font("微软é
é»", Font.PLAIN, 14)); |
| | | boundaryLengthVisibleLabel.setForeground(Color.DARK_GRAY); |
| | | gbc = new GridBagConstraints(); |
| | | gbc.gridx = 1; |
| | | gbc.gridy = 0; |
| | | gbc.weightx = 1.0; |
| | | gbc.anchor = GridBagConstraints.EAST; |
| | | panel.add(boundaryLengthVisibleLabel, gbc); |
| | | |
| | | panel.putClientProperty("valueLabel", boundaryLengthVisibleLabel); |
| | | |
| | | // åå»ºåæ¢æé®ï¼ä½¿ç¨å¾æ ï¼ |
| | | JButton toggleBtn = createBoundaryLengthToggleButton(); |
| | | gbc = new GridBagConstraints(); |
| | | gbc.gridx = 2; |
| | | gbc.gridy = 0; |
| | | gbc.weightx = 0; |
| | | gbc.anchor = GridBagConstraints.EAST; |
| | | panel.add(toggleBtn, gbc); |
| | | panel.putClientProperty("toggleButton", toggleBtn); |
| | | |
| | | return panel; |
| | | } |
| | | |
| | | /** |
| | | * å建边çè·ç¦»æ¾ç¤ºåæ¢æé® |
| | | */ |
| | | private JButton createBoundaryLengthToggleButton() { |
| | | JButton button = new JButton(); |
| | | button.setContentAreaFilled(false); |
| | | button.setBorder(null); |
| | | button.setFocusPainted(false); |
| | | button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
| | | button.setPreferredSize(new Dimension(32, 32)); |
| | | button.setMinimumSize(new Dimension(32, 32)); |
| | | button.setMaximumSize(new Dimension(32, 32)); |
| | | |
| | | updateBoundaryLengthToggleButton(button); |
| | | |
| | | button.addActionListener(e -> toggleBoundaryLengthVisible(button)); |
| | | |
| | | return button; |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°è¾¹çè·ç¦»åæ¢æé®å¾æ |
| | | */ |
| | | private void updateBoundaryLengthToggleButton(JButton button) { |
| | | boolean isVisible = setData.isBoundaryLengthVisible(); |
| | | try { |
| | | String iconPath = isVisible ? "image/open.png" : "image/close.png"; |
| | | ImageIcon icon = new ImageIcon(iconPath); |
| | | if (icon.getIconWidth() > 0) { |
| | | Image scaledImage = icon.getImage().getScaledInstance(32, 32, Image.SCALE_SMOOTH); |
| | | button.setIcon(new ImageIcon(scaledImage)); |
| | | button.setText(null); |
| | | } else { |
| | | button.setIcon(null); |
| | | button.setText(isVisible ? "å¼" : "å
³"); |
| | | } |
| | | } catch (Exception e) { |
| | | button.setIcon(null); |
| | | button.setText(isVisible ? "å¼" : "å
³"); |
| | | System.err.println("æ æ³å 载边çè·ç¦»å¾æ : " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åæ¢è¾¹çè·ç¦»æ¾ç¤ºç¶æ |
| | | */ |
| | | private void toggleBoundaryLengthVisible(JButton button) { |
| | | boolean newValue = !setData.isBoundaryLengthVisible(); |
| | | setData.setBoundaryLengthVisible(newValue); |
| | | |
| | | // ä¿åå°é
ç½®æä»¶ |
| | | setData.updateProperty("boundaryLengthVisible", String.valueOf(newValue)); |
| | | |
| | | // æ´æ°UI |
| | | if (boundaryLengthVisibleLabel != null) { |
| | | boundaryLengthVisibleLabel.setText(newValue ? "å·²å¼å¯" : "å·²å
³é"); |
| | | } |
| | | updateBoundaryLengthToggleButton(button); |
| | | |
| | | // éç¥MapRendereræ´æ° |
| | | Shouye shouye = Shouye.getInstance(); |
| | | if (shouye != null) { |
| | | MapRenderer renderer = shouye.getMapRenderer(); |
| | | if (renderer != null) { |
| | | renderer.setBoundaryLengthVisible(newValue); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private JButton createEditButton() { |
| | | JButton button = new JButton(); |
| | | try { |
| | |
| | | idleTrailDurationLabel.setText(formatIdleTrailDurationValue()); |
| | | } |
| | | |
| | | // æ´æ°æ¾ç¤ºè¾¹çè·ç¦»ç¶æ |
| | | if (boundaryLengthVisibleLabel != null) { |
| | | boundaryLengthVisibleLabel.setText(setData.isBoundaryLengthVisible() ? "å·²å¼å¯" : "å·²å
³é"); |
| | | } |
| | | // æ´æ°åæ¢æé®å¾æ |
| | | JPanel boundaryLengthPanel = (JPanel) boundaryLengthVisibleLabel.getParent(); |
| | | if (boundaryLengthPanel != null) { |
| | | JButton toggleBtn = (JButton) boundaryLengthPanel.getClientProperty("toggleButton"); |
| | | if (toggleBtn != null) { |
| | | updateBoundaryLengthToggleButton(toggleBtn); |
| | | } |
| | | } |
| | | |
| | | // æ´æ°APPçæ¬æ¾ç¤º |
| | | if (appVersionLabel != null) { |
| | | appVersionLabel.setText(setData.getAppVersion() != null ? |