| | |
| | | |
| | | import java.awt.*; |
| | | import java.awt.event.ActionListener; |
| | | import java.awt.event.MouseAdapter; |
| | | import java.awt.event.MouseEvent; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | |
| | | updateTimeLabel = valueLabel; |
| | | } else if ("基准站位置:".equals(title)) { |
| | | positionLabel = valueLabel; |
| | | final Color clickableColor = THEME_COLOR != null ? THEME_COLOR : new Color(70, 130, 180); |
| | | titleLabel.setForeground(clickableColor); |
| | | titleLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
| | | titleLabel.setToolTipText("点击修改基准站位置"); |
| | | titleLabel.addMouseListener(new MouseAdapter() { |
| | | @Override |
| | | public void mouseClicked(MouseEvent e) { |
| | | if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1) { |
| | | promptEditBaseStationPosition(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void mouseEntered(MouseEvent e) { |
| | | titleLabel.setForeground(brightenColor(clickableColor)); |
| | | } |
| | | |
| | | @Override |
| | | public void mouseExited(MouseEvent e) { |
| | | titleLabel.setForeground(clickableColor); |
| | | } |
| | | }); |
| | | } else if ("基准站卡号:".equals(title)) { |
| | | simCardLabel = valueLabel; |
| | | } |
| | |
| | | |
| | | return panel; |
| | | } |
| | | |
| | | private void promptEditBaseStationPosition() { |
| | | if (baseStation == null) { |
| | | JOptionPane.showMessageDialog(this, |
| | | "基准站信息未初始化,无法修改位置。", |
| | | "错误", |
| | | JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | baseStation.load(); |
| | | |
| | | String currentRaw = baseStation.getInstallationCoordinates(); |
| | | String normalizedCurrent = currentRaw == null ? "-1" : currentRaw.trim(); |
| | | if (normalizedCurrent.isEmpty()) { |
| | | normalizedCurrent = "-1"; |
| | | } |
| | | |
| | | JTextField inputField = new JTextField("-1".equals(normalizedCurrent) ? "" : normalizedCurrent); |
| | | inputField.setColumns(28); |
| | | |
| | | JPanel dialogPanel = new JPanel(new BorderLayout(0, 8)); |
| | | JLabel hintLabel = new JLabel("请输入新的基准站坐标(格式示例:2324.194945,N,11330.938547,E)"); |
| | | hintLabel.setFont(new Font("微软雅黑", Font.PLAIN, 12)); |
| | | dialogPanel.add(hintLabel, BorderLayout.NORTH); |
| | | dialogPanel.add(inputField, BorderLayout.CENTER); |
| | | |
| | | JOptionPane optionPane = new JOptionPane(dialogPanel, |
| | | JOptionPane.PLAIN_MESSAGE, |
| | | JOptionPane.OK_CANCEL_OPTION); |
| | | JDialog dialog = optionPane.createDialog(this, "修改基准站位置"); |
| | | dialog.setModal(true); |
| | | dialog.pack(); |
| | | |
| | | Dimension packedSize = dialog.getSize(); |
| | | Window ownerWindow = getOwner(); |
| | | int referenceWidth = ownerWindow != null ? ownerWindow.getWidth() : getWidth(); |
| | | if (referenceWidth <= 0) { |
| | | referenceWidth = 400; |
| | | } |
| | | dialog.setSize(new Dimension(referenceWidth, packedSize.height)); |
| | | dialog.setResizable(false); |
| | | dialog.setLocationRelativeTo(this); |
| | | dialog.setVisible(true); |
| | | |
| | | Object selectedValue = optionPane.getValue(); |
| | | if (!(selectedValue instanceof Integer) || ((Integer) selectedValue) != JOptionPane.OK_OPTION) { |
| | | return; |
| | | } |
| | | |
| | | String userInput = inputField.getText(); |
| | | if (userInput == null) { |
| | | return; |
| | | } |
| | | |
| | | String trimmed = userInput.trim(); |
| | | if (trimmed.isEmpty()) { |
| | | int confirm = JOptionPane.showConfirmDialog(this, |
| | | "未输入坐标,保存后将视为未安装状态,是否继续?", |
| | | "确认", |
| | | JOptionPane.OK_CANCEL_OPTION, |
| | | JOptionPane.WARNING_MESSAGE); |
| | | if (confirm != JOptionPane.OK_OPTION) { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | String valueToSave = trimmed.isEmpty() ? "-1" : trimmed; |
| | | |
| | | if (!"-1".equals(valueToSave) && !looksLikeCoordinateFormat(valueToSave)) { |
| | | int confirm = JOptionPane.showConfirmDialog(this, |
| | | "坐标格式似乎不符合“纬度,方向,经度,方向”的预期,仍然保存吗?", |
| | | "格式确认", |
| | | JOptionPane.OK_CANCEL_OPTION, |
| | | JOptionPane.WARNING_MESSAGE); |
| | | if (confirm != JOptionPane.OK_OPTION) { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | if (valueToSave.equals(normalizedCurrent)) { |
| | | JOptionPane.showMessageDialog(this, |
| | | "基准站位置未发生变化。", |
| | | "提示", |
| | | JOptionPane.INFORMATION_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | baseStation.updateInstallationCoordinates(valueToSave); |
| | | baseStation.load(); |
| | | |
| | | if (device != null) { |
| | | device.setBaseStationCoordinates(valueToSave); |
| | | updatePropertiesFile("baseStationCoordinates", valueToSave); |
| | | } |
| | | |
| | | refreshLabels(); |
| | | |
| | | JOptionPane.showMessageDialog(this, |
| | | "基准站位置已更新。", |
| | | "更新成功", |
| | | JOptionPane.INFORMATION_MESSAGE); |
| | | } |
| | | |
| | | private boolean looksLikeCoordinateFormat(String value) { |
| | | if (value == null) { |
| | | return false; |
| | | } |
| | | String[] parts = value.split(","); |
| | | if (parts.length != 4) { |
| | | return false; |
| | | } |
| | | for (String part : parts) { |
| | | if (part.trim().isEmpty()) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private JPanel createActionPanel(String title, String buttonText, Color buttonColor, ActionListener actionListener) { |
| | | JPanel panel = new JPanel(); |