826220679@qq.com
2025-08-07 4d6cd980c5c69e4d9d150669c89734642297e0cd
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
package dell_Fence;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.geom.Point2D;
import java.util.ResourceBundle;
import java.util.Vector;
 
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
 
import dell_Fence.FenceDrawerFrame.SaveFenceCallback;
import publicsWay.Xialajihe;
 
//ΧÀ¸ÐÅÏ¢¶Ô»°¿òÀà
public class FenceInfoDialog extends JDialog {
    private final ResourceBundle messages; // ¹ú¼Ê»¯×ÊÔ´
    private final int currentShape; // µ±Ç°ÐÎ×´
    private final Vector<Point2D.Double> drawingPoints; // »æÖƵã
    private final SaveFenceCallback saveCallback; // ±£´æ»Øµ÷½Ó¿Ú
 
    public FenceInfoDialog(Frame parent, ResourceBundle messages, // ¹¹Ô캯Êý
            int currentShape, Vector<Point2D.Double> drawingPoints,
            SaveFenceCallback saveCallback) {
        super(parent, messages.getString("FENCE_INFO_TITLE"), true); // ÉèÖñêÌâºÍģ̬
        this.messages = messages; // ³õʼ»¯×ÊÔ´
        this.currentShape = currentShape; // ³õʼ»¯ÐÎ×´
        this.drawingPoints = drawingPoints; // ³õʼ»¯µã¼¯
        this.saveCallback = saveCallback; // ³õʼ»¯»Øµ÷
 
        setSize(600, 700); //  ÉèÖô°¿Ú´óС
        setLayout(new BorderLayout()); // ÉèÖò¼¾Ö
        initUI(); // ³õʼ»¯½çÃæ
    }
 
    private void initUI() { // ³õʼ»¯½çÃæ
        JPanel mainPanel = new JPanel(null); // Ö÷Ãæ°å£¬¾ø¶Ô²¼¾Ö
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); // ÉèÖñ߿ò
 
        int x = 20; // X×ø±êÆðʼ
        int y = 20; // Y×ø±êÆðʼ
        int labelWidth = 120; // ±êÇ©¿í¶È
        int fieldWidth = 350; // ÊäÈë¿ò¿í¶È
        int height = 30; // ¸ß¶È
        int spacing = 40; // ´¹Ö±¼ä¾à
 
        // Î§À¸Ãû³Æ
        JLabel nameLabel = new JLabel(getMessage("FENCE_NAME") + ":"); // Ãû³Æ±êÇ©
        nameLabel.setBounds(x, y, labelWidth, height); // ÉèÖÃλÖÃ
        JTextField nameField = new JTextField(); // Ãû³ÆÊäÈë¿ò
        nameField.setBounds(x + labelWidth, y, fieldWidth, height); // ÉèÖÃλÖÃ
        mainPanel.add(nameLabel); // Ìí¼Óµ½Ãæ°å
        mainPanel.add(nameField); // Ìí¼Óµ½Ãæ°å
        y += spacing; // ÏÂÒÆ
        
        JLabel coordLabel = new JLabel(getMessage("FENCE_COORDINATES") + ":"); // Î§À¸×ø±ê±êÇ©
        coordLabel.setBounds(x, y, labelWidth, height);
        
        // Éú³É×ø±ê×Ö·û´®
        StringBuilder coordsBuilder = new StringBuilder();
        for (Point2D.Double point : drawingPoints) {
            coordsBuilder.append(String.format("(%.0f, %.0f), ", point.x, point.y));
        }
        String fullCoords = coordsBuilder.toString();
        // ÒƳý×îºóÒ»¸ö¶ººÅºÍ¿Õ¸ñ
        if (fullCoords.length() > 0) {
            fullCoords = fullCoords.substring(0, fullCoords.length() - 2);
        }
        
        // ½ØÈ¡Ç°100×Ö·û£¨¿¼ÂÇÊ¡ÂÔºÅռ룩
        String displayCoords = fullCoords;
                
        // ´´½¨Îı¾ÇøÓò£¨¶àÐÐÎı¾¿ò£©
        JTextArea coordTextArea = new JTextArea(displayCoords);
        coordTextArea.setEditable(false); // ÉèÖÃΪֻ¶Á
        coordTextArea.setLineWrap(true);  // ×Ô¶¯»»ÐÐ
        coordTextArea.setWrapStyleWord(true); // °´µ¥´Ê»»ÐÐ
        
        // ½«Îı¾¿ò·ÅÈë¹ö¶¯Ãæ°å
        JScrollPane coordScrollPane = new JScrollPane(coordTextArea);
        coordScrollPane.setBounds(x + labelWidth, y, fieldWidth, 80); // ÉèÖÃÊʵ±¸ß¶È
        coordScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        
        // Ìí¼ÓÌáʾÎı¾£¨ÍêÕû×ø±ê£©
        coordTextArea.setToolTipText(fullCoords.length() > 100 ? fullCoords : null);
        
        mainPanel.add(coordLabel);
        mainPanel.add(coordScrollPane); // Ìí¼Ó¹ö¶¯Ãæ°å¶ø·ÇÎı¾¿ò
        y += 90; // Ôö¼Ó¶îÍâ¸ß¶È
 
        // Î§À¸ÀàÐÍ
        JLabel typeLabel = new JLabel(getMessage("FENCE_TYPE") + ":"); // ÀàÐͱêÇ©
        typeLabel.setBounds(x, y, labelWidth, height); // ÉèÖÃλÖà        
        JComboBox<String> typeComboBox= new JComboBox<>(new String[]{ // ÀàÐÍÏÂÀ­¿ò
                getMessage("ATTENDANCE_AREA"),
                getMessage("ENTRY_ALARM"), 
                getMessage("EXIT_ALARM"), 
                getMessage("OVERSTAFFED_ALARM"), 
                getMessage("UNDERSTAFFED_ALARM"), 
                getMessage("CROWD_GATHERING_ALARM"), 
                getMessage("INDOOR_AREA"), 
                getMessage("LOCATION_AREA"), 
                getMessage("INVALID_AREA"), 
                getMessage("PATROL_AREA"), 
                getMessage("VIDEO_AREA"), 
                getMessage("FLOOR_HEIGHT_FENCE"), 
                getMessage("SAFE_AREA"), 
                getMessage("WORK_AREA"), 
        });
 
        typeComboBox.setBounds(x + labelWidth, y, fieldWidth, height); // ÉèÖÃλÖÃ
        mainPanel.add(typeLabel); // Ìí¼Óµ½Ãæ°å
        mainPanel.add(typeComboBox); // Ìí¼Óµ½Ãæ°å
        y += spacing; // ÏÂÒÆ
 
        // ¹ÜÀí²¿ÃÅ
        JLabel deptLabel = new JLabel(getMessage("MANAGE_DEPT") + ":"); // ²¿ÃűêÇ©
        deptLabel.setBounds(x, y, labelWidth, height); // ÉèÖÃλÖÃ
        JComboBox<String> deptComboBox = new JComboBox<>(); // ²¿ÃÅÏÂÀ­¿ò
        for (String dept : Xialajihe.AllDepartmentNames) { // ±éÀú²¿ÃÅÁбí
            deptComboBox.addItem(dept); // Ìí¼Óµ½ÏÂÀ­¿ò
        }
        deptComboBox.setBounds(x + labelWidth, y, fieldWidth, height); // ÉèÖÃλÖÃ
        mainPanel.add(deptLabel); // Ìí¼Óµ½Ãæ°å
        mainPanel.add(deptComboBox); // Ìí¼Óµ½Ãæ°å
        y += spacing; // ÏÂÒÆ
 
        // Î§À¸ÑÕÉ«
        JLabel colorLabel = new JLabel(getMessage("FENCE_COLOR") + ":"); // ÑÕÉ«±êÇ©
        colorLabel.setBounds(x, y, labelWidth, height); // ÉèÖÃλÖÃ
        JComboBox<String> colorComboBox = new JComboBox<>(new String[]{ // ÑÕÉ«ÏÂÀ­¿ò
                getMessage("RED"), // ºìÉ«
                getMessage("GREEN"), // ÂÌÉ«
                getMessage("BLUE"), // À¶É«
                getMessage("BLACK"), // ºÚÉ«
                getMessage("WHITE"), // °×É«
                getMessage("MAGENTA") // Æ·ºì
        });
        colorComboBox.setBounds(x + labelWidth, y, fieldWidth, height); // ÉèÖÃλÖÃ
        mainPanel.add(colorLabel); // Ìí¼Óµ½Ãæ°å
        mainPanel.add(colorComboBox); // Ìí¼Óµ½Ãæ°å
        y += spacing; // ÏÂÒÆ
 
        // Ñ¡Ôñ¹«Ë¾
        JLabel companyLabel = new JLabel(getMessage("SELECT_COMPANY") + ":"); // ¹«Ë¾±êÇ©
        companyLabel.setBounds(x, y, labelWidth, height); // ÉèÖÃλÖÃ
        JComboBox<String> companyComboBox = new JComboBox<>(); // ¹«Ë¾ÏÂÀ­¿ò
        for (String company : Xialajihe.AllCompanyNames) { // ±éÀú¹«Ë¾Áбí
            companyComboBox.addItem(company); // Ìí¼Óµ½ÏÂÀ­¿ò
        }
        companyComboBox.setBounds(x + labelWidth, y, fieldWidth, height); // ÉèÖÃλÖÃ
        mainPanel.add(companyLabel); // Ìí¼Óµ½Ãæ°å
        mainPanel.add(companyComboBox); // Ìí¼Óµ½Ãæ°å
        y += spacing; // ÏÂÒÆ
 
        // ËùÊôͼ²ã
        JLabel layerLabel = new JLabel(getMessage("BELONG_LAYER") + ":"); // Í¼²ã±êÇ©
        layerLabel.setBounds(x, y, labelWidth, height); // ÉèÖÃλÖÃ
        JComboBox<String> layerComboBox = new JComboBox<>(); // Í¼²ãÏÂÀ­¿ò
        for (String layer : Xialajihe.AllLayerNumbers) { // ±éÀúͼ²ãÁбí
            layerComboBox.addItem(layer); // Ìí¼Óµ½ÏÂÀ­¿ò
        }
        layerComboBox.setBounds(x + labelWidth, y, fieldWidth, height); // ÉèÖÃλÖÃ
        mainPanel.add(layerLabel); // Ìí¼Óµ½Ãæ°å
        mainPanel.add(layerComboBox); // Ìí¼Óµ½Ãæ°å
        y += spacing; // ÏÂÒÆ
 
        // ÉúЧʱ¼ä
        JLabel startTimeLabel = new JLabel(getMessage("START_TIME") + ":"); // ¿ªÊ¼Ê±¼ä±êÇ©
        startTimeLabel.setBounds(x, y, labelWidth, height); // ÉèÖÃλÖÃ
        JTextField startTimeField = new JTextField("00:00:00"); // Ä¬ÈÏʱ¼ä
        startTimeField.setBounds(x + labelWidth, y, fieldWidth, height); // ÉèÖÃλÖÃ
        mainPanel.add(startTimeLabel); // Ìí¼Óµ½Ãæ°å
        mainPanel.add(startTimeField); // Ìí¼Óµ½Ãæ°å
        y += spacing; // ÏÂÒÆ
 
        // Ê§Ð§Ê±¼ä
        JLabel endTimeLabel = new JLabel(getMessage("END_TIME") + ":"); // ½áÊøÊ±¼ä±êÇ©
        endTimeLabel.setBounds(x, y, labelWidth, height); // ÉèÖÃλÖÃ
        JTextField endTimeField = new JTextField("23:59:59"); // Ä¬ÈÏʱ¼ä
        endTimeField.setBounds(x + labelWidth, y, fieldWidth, height); // ÉèÖÃλÖÃ
        mainPanel.add(endTimeLabel); // Ìí¼Óµ½Ãæ°å
        mainPanel.add(endTimeField); // Ìí¼Óµ½Ãæ°å
        y += spacing; // ÏÂÒÆ
 
        // ÊÇ·ñÆôÓÃ
        JLabel enableLabel = new JLabel(getMessage("ENABLE") + ":"); // ÆôÓñêÇ©
        enableLabel.setBounds(x, y, labelWidth, height); // ÉèÖÃλÖÃ
        JPanel enablePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0)); // ÆôÓÃÃæ°å
        enablePanel.setBounds(x + labelWidth, y, fieldWidth, height); // ÉèÖÃλÖÃ
        JRadioButton enableYes = new JRadioButton(getMessage("YES")); // Êǵ¥Ñ¡°´Å¥
        enableYes.setSelected(true); // Ä¬ÈÏÑ¡ÖÐ
        JRadioButton enableNo = new JRadioButton(getMessage("NO")); // ·ñµ¥Ñ¡°´Å¥
        ButtonGroup enableGroup = new ButtonGroup(); // °´Å¥×é
        enableGroup.add(enableYes); // Ìí¼Óµ½×é
        enableGroup.add(enableNo); // Ìí¼Óµ½×é
        enablePanel.add(enableYes); // Ìí¼Óµ½Ãæ°å
        enablePanel.add(enableNo); // Ìí¼Óµ½Ãæ°å
        mainPanel.add(enableLabel); // Ìí¼Óµ½Ö÷Ãæ°å
        mainPanel.add(enablePanel); // Ìí¼Óµ½Ö÷Ãæ°å
        y += spacing; // ÏÂÒÆ
 
        // °´Å¥Ãæ°å
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10)); // ÓÒ¶ÔÆë°´Å¥Ãæ°å
        buttonPanel.setBounds(0, y + 20, 460, 50); // ÉèÖÃλÖÃ
 
        JButton saveButton = new JButton(getMessage("SAVE")); // ±£´æ°´Å¥
        saveButton.addActionListener(e -> { // ±£´æÊ¼þ
            String fenceName = nameField.getText().trim(); // »ñÈ¡Ãû³Æ
            if (fenceName.isEmpty()) { // Èç¹ûΪ¿Õ
                JOptionPane.showMessageDialog(this, // µ¯³ö¾¯¸æ
                        getMessage("FENCE_NAME") + getMessage("CANNOT_EMPTY"), // ÌáʾÐÅÏ¢
                        getMessage("WARNING"), JOptionPane.WARNING_MESSAGE); // ±êÌâºÍͼ±ê
                return; // ·µ»Ø
            }
 
            if (fenceName.length() > 50) { // Èç¹û³¬¹ý50×Ö·û
                JOptionPane.showMessageDialog(this, // µ¯³ö¾¯¸æ
                        getMessage("FENCE_NAME") + getMessage("LENGTH_LIMIT") + "50", // ÌáʾÐÅÏ¢
                        getMessage("WARNING"), JOptionPane.WARNING_MESSAGE); // ±êÌâºÍͼ±ê
                return; // ·µ»Ø
            }
 
            if (Dell_Fence.isFenceNameExists(fenceName)) { // Èç¹ûÃû³ÆÒÑ´æÔÚ
                JOptionPane.showMessageDialog(this, // µ¯³ö¾¯¸æ
                        fenceName + getMessage("ALREADY_EXISTS"), // ÌáʾÐÅÏ¢
                        getMessage("WARNING"), JOptionPane.WARNING_MESSAGE); // ±êÌâºÍͼ±ê
                return; // ·µ»Ø
            }
            
            // Ìí¼Ó×ø±ê·Ç¿ÕÑéÖ¤
            if (drawingPoints.isEmpty()) {
                JOptionPane.showMessageDialog(this,
                    getMessage("FENCE_COORDINATES_EMPTY"),
                    getMessage("WARNING"), JOptionPane.WARNING_MESSAGE);
                return;
            }
 
            saveCallback.save( // µ÷Óñ£´æ»Øµ÷
                    fenceName, // Ãû³Æ
                    (String) typeComboBox.getSelectedItem(), // ÀàÐÍ
                    (String) deptComboBox.getSelectedItem(), // ²¿ÃÅ
                    (String) colorComboBox.getSelectedItem(), // ÑÕÉ«
                    (String) companyComboBox.getSelectedItem(), // ¹«Ë¾
                    (String) layerComboBox.getSelectedItem(), // Í¼²ã
                    startTimeField.getText(), // ¿ªÊ¼Ê±¼ä
                    endTimeField.getText(), // ½áÊøÊ±¼ä
                    enableYes.isSelected() ? "1" : "0" // ÊÇ·ñÆôÓÃ
                    );
 
            dispose(); // ¹Ø±Õ¶Ô»°¿ò
        });
 
        JButton cancelButton = new JButton(getMessage("CANCEL")); // È¡Ïû°´Å¥
        cancelButton.addActionListener(e -> dispose()); // È¡ÏûʼþÖ±½Ó¹Ø±Õ
 
        buttonPanel.add(saveButton); // Ìí¼Ó±£´æ°´Å¥
        buttonPanel.add(cancelButton); // Ìí¼ÓÈ¡Ïû°´Å¥
        mainPanel.add(buttonPanel); // Ìí¼Óµ½Ö÷Ãæ°å
 
        add(mainPanel, BorderLayout.CENTER); // Ö÷Ãæ°åÌí¼Óµ½´°¿ÚÖмä
    }
 
    private String getMessage(String key) { // »ñÈ¡¹ú¼Ê»¯Îı¾
        try {
            return messages.getString(key); // ´Ó×ÊÔ´°ü»ñÈ¡
        } catch (Exception e) {
            return "[" + key + "]"; // Òì³£·µ»Ø¼üÃû
        }
    }
}