| | |
| | | import baseStation.BaseStation; |
| | | import gecaoji.Device; |
| | | import gecaoji.MowerSafetyDistanceCalculator; |
| | | |
| | | import publicway.buttonset; |
| | | import zhuye.MapRenderer; |
| | | import zhuye.Shouye; |
| | | import zhuye.buttonset; |
| | | import zhuye.celiangmoshi; |
| | | import javax.swing.*; |
| | | import javax.swing.filechooser.FileNameExtensionFilter; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | import denglu.Denglu; |
| | | import denglu.UserChuShiHua; |
| | | |
| | | /** |
| | | * 设置对话框 - 参考Shouye.java样式 |
| | |
| | | // 创建设置项面板(圆角白色面板) |
| | | JPanel settingsPanel = createSettingsPanel(); |
| | | |
| | | // 创建滚动面板 |
| | | JScrollPane scrollPane = new JScrollPane(settingsPanel); |
| | | scrollPane.setBorder(null); // 去除边框 |
| | | scrollPane.getViewport().setBackground(BACKGROUND_COLOR); // 设置视口背景色与主背景一致 |
| | | scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); // 禁止水平滚动 |
| | | scrollPane.getVerticalScrollBar().setUnitIncrement(16); // 增加滚动速度 |
| | | |
| | | // 添加组件到主面板 |
| | | mainPanel.add(settingsPanel, BorderLayout.CENTER); |
| | | mainPanel.add(scrollPane, BorderLayout.CENTER); |
| | | |
| | | add(mainPanel, BorderLayout.CENTER); |
| | | } |
| | | |
| | | private JPanel createSettingsPanel() { |
| | | // 创建圆角白色面板容器 |
| | | JPanel container = new JPanel() { |
| | | JPanel container = new ScrollablePanel() { |
| | | @Override |
| | | protected void paintComponent(Graphics g) { |
| | | Graphics2D g2d = (Graphics2D) g.create(); |
| | |
| | | JPanel manualBoundaryDrawingPanel = createManualBoundaryDrawingPanel(); |
| | | manualBoundaryDrawingModeLabel = (JLabel) manualBoundaryDrawingPanel.getClientProperty("valueLabel"); |
| | | |
| | | // 修改密码设置项 |
| | | JPanel changePasswordPanel = createChangePasswordPanel(); |
| | | |
| | | JPanel feedbackPanel = createFeedbackPanel(); |
| | | |
| | | // APP版本 |
| | | JPanel appVersionPanel = createAppVersionPanel(); |
| | | |
| | | // 退出登录 |
| | | JPanel logoutPanel = createLogoutPanel(); |
| | | |
| | | // 添加设置项,使用分割线分隔 |
| | | addSettingItem(panel, mowerIdPanel, true); |
| | | addSettingItem(panel, mowerSizePanel, true); |
| | |
| | | addSettingItem(panel, boundaryLengthPanel, true); |
| | | addSettingItem(panel, measurementModePanel, true); |
| | | addSettingItem(panel, manualBoundaryDrawingPanel, true); |
| | | addSettingItem(panel, changePasswordPanel, true); |
| | | addSettingItem(panel, feedbackPanel, true); |
| | | addSettingItem(panel, appVersionPanel, false); // 最后一项不加分割线 |
| | | addSettingItem(panel, appVersionPanel, true); |
| | | addSettingItem(panel, logoutPanel, false); // 最后一项不加分割线 |
| | | |
| | | container.add(panel, BorderLayout.CENTER); |
| | | return container; |
| | |
| | | timer.start(); |
| | | } |
| | | |
| | | /** |
| | | * 可滚动的面板,强制宽度适应视口 |
| | | */ |
| | | private class ScrollablePanel extends JPanel implements Scrollable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @Override |
| | | public Dimension getPreferredScrollableViewportSize() { |
| | | return getPreferredSize(); |
| | | } |
| | | |
| | | @Override |
| | | public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { |
| | | return 16; |
| | | } |
| | | |
| | | @Override |
| | | public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { |
| | | return 16; |
| | | } |
| | | |
| | | @Override |
| | | public boolean getScrollableTracksViewportWidth() { |
| | | return true; // 强制宽度适应视口,防止水平滚动 |
| | | } |
| | | |
| | | @Override |
| | | public boolean getScrollableTracksViewportHeight() { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void setVisible(boolean visible) { |
| | | if (visible) { |
| | |
| | | } |
| | | super.setVisible(visible); |
| | | } |
| | | |
| | | |
| | | private JPanel createLogoutPanel() { |
| | | JPanel panel = new JPanel(new GridBagLayout()); |
| | | panel.setOpaque(false); |
| | | panel.setAlignmentX(Component.LEFT_ALIGNMENT); |
| | | panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT + 20)); |
| | | panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING)); |
| | | |
| | | JButton logoutBtn = new JButton("退出登录"); |
| | | logoutBtn.setFont(new Font("微软雅黑", Font.BOLD, 14)); |
| | | logoutBtn.setForeground(Color.WHITE); |
| | | logoutBtn.setBackground(new Color(220, 53, 69)); // Red color |
| | | logoutBtn.setFocusPainted(false); |
| | | logoutBtn.setBorderPainted(false); |
| | | logoutBtn.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
| | | logoutBtn.setPreferredSize(new Dimension(200, 40)); |
| | | |
| | | logoutBtn.addActionListener(e -> { |
| | | int confirm = JOptionPane.showConfirmDialog(this, |
| | | "确定要退出登录吗?", "退出确认", |
| | | JOptionPane.YES_NO_OPTION); |
| | | |
| | | if (confirm == JOptionPane.YES_OPTION) { |
| | | // Reset Remember Me |
| | | UserChuShiHua.updateProperty("rememberPassword", "0"); |
| | | |
| | | // Close current dialog |
| | | dispose(); |
| | | |
| | | // Close all windows and open Login |
| | | for (Window window : Window.getWindows()) { |
| | | if (window.isDisplayable()) { |
| | | window.dispose(); |
| | | } |
| | | } |
| | | |
| | | SwingUtilities.invokeLater(() -> { |
| | | new Denglu().setVisible(true); |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | GridBagConstraints gbc = new GridBagConstraints(); |
| | | gbc.gridx = 0; |
| | | gbc.gridy = 0; |
| | | gbc.weightx = 1.0; |
| | | gbc.anchor = GridBagConstraints.CENTER; |
| | | panel.add(logoutBtn, gbc); |
| | | |
| | | return panel; |
| | | } |
| | | |
| | | /** |
| | | * 创建修改密码设置面板 |
| | | */ |
| | | private JPanel createChangePasswordPanel() { |
| | | 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); |
| | | |
| | | JLabel valueLabel = new JLabel("******"); |
| | | valueLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14)); |
| | | valueLabel.setForeground(Color.DARK_GRAY); |
| | | gbc = new GridBagConstraints(); |
| | | gbc.gridx = 1; |
| | | gbc.gridy = 0; |
| | | gbc.weightx = 1.0; |
| | | gbc.anchor = GridBagConstraints.EAST; |
| | | panel.add(valueLabel, gbc); |
| | | |
| | | JButton editBtn = createEditButton(); |
| | | editBtn.addActionListener(e -> { |
| | | SwingUtilities.invokeLater(() -> { |
| | | xiugaimima dialog = new xiugaimima((Frame) SwingUtilities.getWindowAncestor(this)); |
| | | dialog.setVisible(true); |
| | | }); |
| | | }); |
| | | |
| | | gbc = new GridBagConstraints(); |
| | | gbc.gridx = 2; |
| | | gbc.gridy = 0; |
| | | gbc.weightx = 0; |
| | | gbc.anchor = GridBagConstraints.EAST; |
| | | panel.add(editBtn, gbc); |
| | | |
| | | return panel; |
| | | } |
| | | } |