826220679@qq.com
2025-08-09 ccb681ec3a4ef38da878ac3a01c498853e9be4ca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
package dell_anchor;
 
import databases.DBConnector;
import dell_targets.Dell_BaseStation;
 
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;
import java.util.*;
import java.util.List;
import java.util.ResourceBundle;
import java.util.regex.Pattern;
import targets.LocationBaseStation;
 
public class BaseStationManagementPanel extends JPanel {
    private static final long serialVersionUID = 1L;
    private JTable baseStationTable;
    private DefaultTableModel tableModel;
    private JTextField searchField;
    private List<LocationBaseStation> allBaseStations;
    private ResourceBundle messages;
 
    public BaseStationManagementPanel(ResourceBundle messages) {
        this.messages = messages;
        setLayout(new BorderLayout());
        setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        
        // ´´½¨ËÑË÷Ãæ°å
        JPanel searchPanel = new JPanel(new BorderLayout(5, 5));
        searchPanel.setBorder(BorderFactory.createTitledBorder(getMessage("SEARCH")));
        
        // ´´½¨ËÑË÷×é¼þ
        searchField = new JTextField(15);
        JButton searchButton = new JButton(getMessage("SEARCH"));
        JButton refreshButton = new JButton(getMessage("REFRESH"));
        JButton addButton = new JButton(getMessage("ADD"));
        JButton editButton = new JButton(getMessage("EDIT"));
        JButton deleteButton = new JButton(getMessage("DELETE"));
        refreshButton.addActionListener(e -> loadBaseStationData());
 
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
        buttonPanel.add(searchButton);
        buttonPanel.add(refreshButton);
        buttonPanel.add(addButton);
        buttonPanel.add(editButton);
        buttonPanel.add(deleteButton);
 
        searchPanel.add(searchField, BorderLayout.CENTER);
        searchPanel.add(buttonPanel, BorderLayout.EAST);
        
        // Ìí¼Ó°´Å¥Ê¼þ¼àÌýÆ÷
        addButton.addActionListener(e -> addNewBaseStation());
        editButton.addActionListener(e -> editSelectedBaseStation());
        deleteButton.addActionListener(e -> deleteSelectedBaseStations());
        searchButton.addActionListener(new SearchAction());
       
        // ´´½¨±í¸ñÁÐÃû
        String[] columnNames = {
            getMessage("INDEX"),
            getMessage("BASE_STATION_ID"), 
            getMessage("BASE_STATION_STATUS"), 
            getMessage("X_COORD"), 
            getMessage("Y_COORD"), 
            getMessage("Z_COORD"), 
            getMessage("LAYER"), 
            getMessage("GROUP"), 
            getMessage("PORT"), 
            getMessage("FIRMWARE_VERSION"), 
            getMessage("ONLINE_TIME"), 
            getMessage("COMPANY")
        };
        
        // ´´½¨±í¸ñÄ£ÐÍ
        tableModel = new DefaultTableModel(columnNames, 0) {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        
        // ´´½¨±í¸ñ
        baseStationTable = new JTable(tableModel);
        baseStationTable.setAutoCreateRowSorter(true);
        baseStationTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        
        // ÉèÖÃÁпí
        TableColumnModel columnModel = baseStationTable.getColumnModel();
        columnModel.getColumn(0).setPreferredWidth(30);  // ÐòºÅ
        columnModel.getColumn(1).setPreferredWidth(100); // »ùÕ¾±àºÅ
        columnModel.getColumn(2).setPreferredWidth(70);  // ×´Ì¬
        columnModel.getColumn(3).setPreferredWidth(70);  // X×ø±ê
        columnModel.getColumn(4).setPreferredWidth(70);  // Y×ø±ê
        columnModel.getColumn(5).setPreferredWidth(70);  // Z×ø±ê
        columnModel.getColumn(6).setPreferredWidth(70);  // ËùÔÚ²ã
        columnModel.getColumn(7).setPreferredWidth(70);  // ËùÔÚ×é
        columnModel.getColumn(8).setPreferredWidth(70);  // ¶Ë¿Ú
        columnModel.getColumn(9).setPreferredWidth(100); // ¹Ì¼þ°æ±¾
        columnModel.getColumn(10).setPreferredWidth(120); // ÉÏÏßʱ¼ä
        columnModel.getColumn(11).setPreferredWidth(100); // ËùÊô¹«Ë¾
        
        // ÉèÖñíÍ·Ñùʽ
        JTableHeader header = baseStationTable.getTableHeader();
        // ÉèÖñíÍ·×ó¶ÔÆë
        header.setDefaultRenderer(new DefaultTableCellRenderer() {
            @Override
            public Component getTableCellRendererComponent(JTable table, Object value,
                    boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                setHorizontalAlignment(SwingConstants.LEFT);
                setBackground(Color.GRAY);
                setForeground(Color.WHITE);
                setFont(getFont().deriveFont(Font.BOLD));
                return this;
            }
        });
        
        JScrollPane scrollPane = new JScrollPane(baseStationTable);
        scrollPane.setPreferredSize(new Dimension(1200, 500));
        
        // Ìí¼Ó×é¼þ
        add(searchPanel, BorderLayout.NORTH);
        add(scrollPane, BorderLayout.CENTER);
        
        // ¼ÓÔØÊý¾Ý
        loadBaseStationData();
    }
    
    private void loadBaseStationData() {
        try {
            allBaseStations = Dell_BaseStation.getBaseStations();
            updateTable(allBaseStations);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, getMessage("DATA_LOAD_ERROR") + ": " + ex.getMessage(), 
                                         getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
        }
    }
    
    private void updateTable(List<LocationBaseStation> baseStations) {
        tableModel.setRowCount(0); // Çå¿Õ±í¸ñ
        
        int index = 1;
        for (LocationBaseStation bs : baseStations) {
            // ×ª»»ÔÚÏß״̬
            String status = "1".equals(bs.getStatus()) ? 
                getMessage("ONLINE") : getMessage("OFFLINE");
            
            // Ìí¼ÓÐÐÊý¾Ý
            tableModel.addRow(new Object[]{
                index++,
                bs.getCode(),
                status,
                bs.getXCoordinate(),
                bs.getYCoordinate(),
                bs.getZCoordinate(),
                bs.getFloor(),
                bs.getGroup(),
                bs.getPort(),
                bs.getFirmwareVersion(),
                bs.getOnlineTime(),
                bs.getCompany()
            });
        }
    }
    
    // Ìí¼ÓлùÕ¾
    private void addNewBaseStation() {
        BaseStationEditDialog dialog = new BaseStationEditDialog(
            (Frame) SwingUtilities.getWindowAncestor(this), 
            messages, 
            true, 
            null
        );
        dialog.setVisible(true);
        
        if (dialog.isConfirmed()) {
            LocationBaseStation newBaseStation = dialog.getBaseStation();
            
            // ÑéÖ¤ÊäÈë
            if (validateInput(newBaseStation)) {
                // ¼ì²éÉ豸IDÊÇ·ñΨһ
                if (isDeviceIdExists(newBaseStation.getCode())) {
                    JOptionPane.showMessageDialog(this, getMessage("DEVICE_ID_EXISTS"),
                                                getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
                    return;
                }
                
                // ÉèÖÃĬÈÏÖµ
                newBaseStation.setStatus("1"); // Ä¬ÈÏÔÚÏß
                newBaseStation.setOnlineTime(new Date().toString()); // µ±Ç°Ê±¼ä×÷ΪÉÏÏßʱ¼ä
                
                // ±£´æµ½Êý¾Ý¿â
                if (saveBaseStationToDatabase(newBaseStation)) {
                    // ¸üÐÂÄÚ´æÊý¾Ý
                    allBaseStations.add(newBaseStation);
                    updateTable(allBaseStations);
                    JOptionPane.showMessageDialog(this, getMessage("SAVE_SUCCESS"),
                                                getMessage("SUCCESS"), JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(this, getMessage("SAVE_FAILED"),
                                                getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
    
    // ±à¼­Ñ¡ÖеĻùÕ¾
    private void editSelectedBaseStation() {
        int selectedRow = baseStationTable.getSelectedRow();
        if (selectedRow == -1) {
            JOptionPane.showMessageDialog(this, getMessage("SELECT_BASE_STATION_TO_EDIT"),
                                        getMessage("WARNING"), JOptionPane.WARNING_MESSAGE);
            return;
        }
        
        // »ñȡѡÖеĻùÕ¾ID
        int modelRow = baseStationTable.convertRowIndexToModel(selectedRow);
        String deviceId = (String) tableModel.getValueAt(modelRow, 1);
        LocationBaseStation bs = findBaseStationById(deviceId);
        
        if (bs == null) {
            JOptionPane.showMessageDialog(this, getMessage("BASE_STATION_NOT_FOUND"),
                                        getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        BaseStationEditDialog dialog = new BaseStationEditDialog(
            (Frame) SwingUtilities.getWindowAncestor(this), 
            messages, 
            false, 
            bs
        );
        dialog.setVisible(true);
        
        if (dialog.isConfirmed()) {
            LocationBaseStation updatedBs = dialog.getBaseStation();
            
            // ÑéÖ¤ÊäÈë
            if (validateInput(updatedBs)) {
                // ¸üлùÕ¾ÐÅÏ¢
                bs.setXCoordinate(updatedBs.getXCoordinate());
                bs.setYCoordinate(updatedBs.getYCoordinate());
                bs.setZCoordinate(updatedBs.getZCoordinate());
                bs.setFloor(updatedBs.getFloor());
                bs.setGroup(updatedBs.getGroup());
                bs.setPort(updatedBs.getPort());
                bs.setFirmwareVersion(updatedBs.getFirmwareVersion());
                bs.setCompany(updatedBs.getCompany());
                
                // ¸üÐÂÊý¾Ý¿â
                if (updateBaseStationInDatabase(bs)) {
                    // ¸üбí¸ñ
                    updateTable(allBaseStations);
                    JOptionPane.showMessageDialog(this, getMessage("UPDATE_SUCCESS"),
                                                getMessage("SUCCESS"), JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(this, getMessage("UPDATE_FAILED"),
                                                getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
    
    // ÑéÖ¤ÊäÈë
    private boolean validateInput(LocationBaseStation bs) {
        // É豸ID²»ÄÜΪ¿ÕÇÒΪHEX¸ñʽ
        if (bs.getCode() == null || bs.getCode().trim().isEmpty()) {
            JOptionPane.showMessageDialog(this, getMessage("DEVICE_ID_REQUIRED"),
                                        getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
            return false;
        }
        
        // HEX¸ñʽÑéÖ¤£¨0-9, A-F£©
        if (!Pattern.matches("[0-9A-Fa-f]+", bs.getCode())) {
            JOptionPane.showMessageDialog(this, getMessage("INVALID_HEX_FORMAT"),
                                        getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
            return false;
        }
        
        // É豸ID³¤¶È²»³¬¹ý10
        if (bs.getCode().length() > 10) {
            JOptionPane.showMessageDialog(this, getMessage("DEVICE_ID_TOO_LONG"),
                                        getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
            return false;
        }
        
        // ÑéÖ¤Êý×Ö×Ö¶Î
        String[] numberFields = {
            bs.getXCoordinate(), bs.getYCoordinate(), bs.getZCoordinate(),
            bs.getFloor(), bs.getGroup(), bs.getPort()
        };
        
        for (String field : numberFields) {
            if (field != null && !field.isEmpty() && !isValidInteger(field)) {
                JOptionPane.showMessageDialog(this, getMessage("INVALID_NUMBER"),
                                            getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
                return false;
            }
        }
        
        // ¹«Ë¾Ãû³Æ³¤¶ÈÑéÖ¤
        if (bs.getCompany() != null && bs.getCompany().length() > 20) {
            JOptionPane.showMessageDialog(this, 
                getMessage("FIELD_TOO_LONG").replace("{0}", "20"),
                getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
            return false;
        }
        
        return true;
    }
    
    // ¼ì²éÊÇ·ñΪÓÐЧÕûÊý
    private boolean isValidInteger(String value) {
        try {
            Integer.parseInt(value);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }
    
    // É¾³ýÑ¡ÖеĻùÕ¾
    private void deleteSelectedBaseStations() {
        int[] selectedRows = baseStationTable.getSelectedRows();
        if (selectedRows.length == 0) {
            JOptionPane.showMessageDialog(this, getMessage("SELECT_BASE_STATION_TO_DELETE"),
                                        getMessage("WARNING"), JOptionPane.WARNING_MESSAGE);
            return;
        }
        
        // È·ÈÏɾ³ý
        int confirm = JOptionPane.showConfirmDialog(this, 
            getMessage("CONFIRM_DELETE") + " " + selectedRows.length + " " + getMessage("BASE_STATIONS") + "?",
            getMessage("CONFIRM"), JOptionPane.YES_NO_OPTION);
        
        if (confirm == JOptionPane.YES_OPTION) {
            int successCount = 0;
            int failCount = 0;
            
            // µ¹Ðòɾ³ý±ÜÃâË÷Òý±ä»¯
            Arrays.sort(selectedRows);
            for (int i = selectedRows.length - 1; i >= 0; i--) {
                int viewRow = selectedRows[i];
                int modelRow = baseStationTable.convertRowIndexToModel(viewRow);
                
                String deviceId = (String) tableModel.getValueAt(modelRow, 1);
                LocationBaseStation bs = findBaseStationById(deviceId);
                
                if (bs != null) {
                    // ´ÓÊý¾Ý¿âɾ³ý
                    if (deleteBaseStationFromDatabase(bs)) {
                        // ´ÓÄÚ´æÊý¾Ýɾ³ý
                        allBaseStations.remove(bs);
                        successCount++;
                    } else {
                        failCount++;
                    }
                }
            }
            
            // ¸üбí¸ñ
            updateTable(allBaseStations);
            
            // ÏÔʾ½á¹û
            String message = String.format(getMessage("DELETE_RESULT"), successCount, failCount);
            JOptionPane.showMessageDialog(this, message,
                                        getMessage("INFO"), JOptionPane.INFORMATION_MESSAGE);
        }
    }
    
    // ¼ì²éÉ豸IDÊÇ·ñ´æÔÚ
    private boolean isDeviceIdExists(String deviceId) {
        for (LocationBaseStation bs : allBaseStations) {
            if (bs.getCode().equals(deviceId)) {
                return true;
            }
        }
        return false;
    }
    
    // ¸ù¾ÝID²éÕÒ»ùÕ¾
    private LocationBaseStation findBaseStationById(String deviceId) {
        for (LocationBaseStation bs : allBaseStations) {
            if (bs.getCode().equals(deviceId)) {
                return bs;
            }
        }
        return null;
    }
    
    // ±£´æ»ùÕ¾µ½Êý¾Ý¿â
    private boolean saveBaseStationToDatabase(LocationBaseStation bs) {
        Map<String, String> fieldValues = new HashMap<>();
        fieldValues.put("base_station_id", bs.getCode());
        fieldValues.put("x_coordinate", bs.getXCoordinate());
        fieldValues.put("y_coordinate", bs.getYCoordinate());
        fieldValues.put("z_coordinate", bs.getZCoordinate());
        fieldValues.put("located_layer", bs.getFloor());
        fieldValues.put("located_group", bs.getGroup());
        fieldValues.put("ports", bs.getPort());
        fieldValues.put("firmware_version", bs.getFirmwareVersion());
        fieldValues.put("online_time", bs.getOnlineTime());
        fieldValues.put("statuss", bs.getStatus());
        fieldValues.put("company", bs.getCompany());
        
        int result = DBConnector.insertData("location_base_station", fieldValues);
        return result > 0;
    }
    
    // ¸üÐÂÊý¾Ý¿âÖеĻùÕ¾
    private boolean updateBaseStationInDatabase(LocationBaseStation bs) {
        Map<String, String> fieldValues = new HashMap<>();
        fieldValues.put("x_coordinate", bs.getXCoordinate());
        fieldValues.put("y_coordinate", bs.getYCoordinate());
        fieldValues.put("z_coordinate", bs.getZCoordinate());
        fieldValues.put("located_layer", bs.getFloor());
        fieldValues.put("located_group", bs.getGroup());
        fieldValues.put("ports", bs.getPort());
        fieldValues.put("firmware_version", bs.getFirmwareVersion());
        fieldValues.put("company", bs.getCompany());
        
        // ÕÒµ½Êý¾Ý¿âID
        int dbId = -1;
        for (LocationBaseStation b : allBaseStations) {
            if (b.getCode().equals(bs.getCode())) {
                dbId = (int) b.getId();
                break;
            }
        }
        
        if (dbId == -1) {
            return false;
        }
        
        int result = DBConnector.updateData("location_base_station", fieldValues, dbId);
        return result > 0;
    }
    
    // ´ÓÊý¾Ý¿âɾ³ý»ùÕ¾
    private boolean deleteBaseStationFromDatabase(LocationBaseStation bs) {
        // ÕÒµ½Êý¾Ý¿âID
        int dbId = (int) bs.getId();
        int result = DBConnector.deleteDataById("location_base_station", dbId);
        return result > 0;
    }
    
    // ËÑË÷¹¦ÄÜ
    private class SearchAction implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            String keyword = searchField.getText().trim();
            if (keyword.isEmpty()) {
                updateTable(allBaseStations);
                return;
            }
            
            List<LocationBaseStation> filteredList = new ArrayList<>();
            for (LocationBaseStation bs : allBaseStations) {
                if (matchesKeyword(bs, keyword)) {
                    filteredList.add(bs);
                }
            }
            
            updateTable(filteredList);
        }
        
        private boolean matchesKeyword(LocationBaseStation bs, String keyword) {
            return (bs.getCode() != null && bs.getCode().contains(keyword)) ||
                   (bs.getCompany() != null && bs.getCompany().contains(keyword));
        }
    }
    
    private String getMessage(String key) {
        try {
            return messages.getString(key);
        } catch (Exception e) {
            return "[" + key + "]";
        }
    }
}
 
// »ùÕ¾±à¼­¶Ô»°¿ò
class BaseStationEditDialog extends JDialog {
    private ResourceBundle messages;
    private JTextField idField;
    private JTextField xField;
    private JTextField yField;
    private JTextField zField;
    private JTextField floorField;
    private JTextField groupField;
    private JTextField portField;
    private JTextField firmwareField;
    private JTextField companyField;
    private boolean confirmed = false;
    private LocationBaseStation baseStation;
 
    public BaseStationEditDialog(Frame parent, ResourceBundle messages, boolean isAddDialog, LocationBaseStation existingBs) {
        super(parent, isAddDialog ? messages.getString("ADD_BASE_STATION") : messages.getString("EDIT_BASE_STATION"), true);
        this.messages = messages;
        this.baseStation = existingBs;
 
        setLayout(new BorderLayout());
        setSize(500, 400);
        setLocationRelativeTo(parent);
 
        JPanel formPanel = new JPanel(new GridLayout(9, 2, 5, 5));
        formPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
 
        // »ùÕ¾±àºÅ
        JLabel idLabel = new JLabel(messages.getString("BASE_STATION_ID") + ": *");
        idField = new JTextField();
        formPanel.add(idLabel);
        formPanel.add(idField);
 
        // X×ø±ê
        JLabel xLabel = new JLabel(messages.getString("X_COORD") + ":");
        xField = new JTextField();
        formPanel.add(xLabel);
        formPanel.add(xField);
 
        // Y×ø±ê
        JLabel yLabel = new JLabel(messages.getString("Y_COORD") + ":");
        yField = new JTextField();
        formPanel.add(yLabel);
        formPanel.add(yField);
 
        // Z×ø±ê
        JLabel zLabel = new JLabel(messages.getString("Z_COORD") + ":");
        zField = new JTextField();
        formPanel.add(zLabel);
        formPanel.add(zField);
 
        // ËùÔÚ²ã
        JLabel floorLabel = new JLabel(messages.getString("LAYER") + ":");
        floorField = new JTextField();
        formPanel.add(floorLabel);
        formPanel.add(floorField);
 
        // ËùÔÚ×é
        JLabel groupLabel = new JLabel(messages.getString("GROUP") + ":");
        groupField = new JTextField();
        formPanel.add(groupLabel);
        formPanel.add(groupField);
 
        // ¶Ë¿Ú
        JLabel portLabel = new JLabel(messages.getString("PORT") + ":");
        portField = new JTextField();
        formPanel.add(portLabel);
        formPanel.add(portField);
 
        // ¹Ì¼þ°æ±¾
        JLabel firmwareLabel = new JLabel(messages.getString("FIRMWARE_VERSION") + ":");
        firmwareField = new JTextField();
        formPanel.add(firmwareLabel);
        formPanel.add(firmwareField);
 
        // ËùÊô¹«Ë¾
        JLabel companyLabel = new JLabel(messages.getString("COMPANY") + ":");
        companyField = new JTextField();
        formPanel.add(companyLabel);
        formPanel.add(companyField);
 
        add(formPanel, BorderLayout.CENTER);
 
        // Èç¹ûÊDZ༭ģʽ£¬Ìî³äÏÖÓÐÊý¾Ý
        if (!isAddDialog && existingBs != null) {
            idField.setText(existingBs.getCode());
            idField.setEditable(false); // ±à¼­Ê±²»¿ÉÐÞ¸ÄID
            xField.setText(existingBs.getXCoordinate());
            yField.setText(existingBs.getYCoordinate());
            zField.setText(existingBs.getZCoordinate());
            floorField.setText(existingBs.getFloor());
            groupField.setText(existingBs.getGroup());
            portField.setText(existingBs.getPort());
            firmwareField.setText(existingBs.getFirmwareVersion());
            companyField.setText(existingBs.getCompany());
        }
 
        // °´Å¥Ãæ°å
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        JButton okButton = new JButton(messages.getString("OK"));
        JButton cancelButton = new JButton(messages.getString("CANCEL"));
 
        okButton.addActionListener(e -> {
            confirmed = true;
            dispose();
        });
 
        cancelButton.addActionListener(e -> dispose());
 
        buttonPanel.add(okButton);
        buttonPanel.add(cancelButton);
        add(buttonPanel, BorderLayout.SOUTH);
    }
 
    public LocationBaseStation getBaseStation() {
        if (!confirmed) {
            return null;
        }
        LocationBaseStation result = new LocationBaseStation();
        result.setCode(idField.getText());
        result.setXCoordinate(xField.getText());
        result.setYCoordinate(yField.getText());
        result.setZCoordinate(zField.getText());
        result.setFloor(floorField.getText());
        result.setGroup(groupField.getText());
        result.setPort(portField.getText());
        result.setFirmwareVersion(firmwareField.getText());
        result.setCompany(companyField.getText());
        return result;
    }
 
    public boolean isConfirmed() {
        return confirmed;
    }
}