zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
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
package Frame;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
 
import ColorAndFont.English;
import ColorAndFont.NothJPanel;
import ColorAndFont.UIColor;
import ColorAndFont.buttonTitle;
import DataBase.DatabaseManagement;
import Method.GetDeskPath;
import PbuliClass.FileIn;
import PbuliClass.JButtonModel;
import PbuliClass.JlableModel;
import PbuliClass.ShowMessage;
import PbuliClass.Systems;
import PbuliClass.WarningMessage;
import PbuliClass.greateTables;
import PbuliClass.jinternalFrame;
import tbDataModel.Tbicon;
import tbDataModel_Dell.Dell_Tbicon;
@SuppressWarnings("rawtypes")
/**
 * ´ËÀàÓÃÓÚ¹ÜÀí±êǩͼ±ê*/
public class IconManagement extends jinternalFrame{    
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    jinternalFrame jinerFrame=null;
    JInternalFrame jinFrame=null;
    JButtonModel xin_zeng_button=null;//ÐÂÔöͼ±ê°´Å¥
    JlableModel  iconName=null;//ͼ±êÃû³Æ
    JTextField iconFile=null;//Îı¾¿ò
    JButtonModel addicon=null;//ÐÂÔö°´Å¥
    JButtonModel altericon=null;//Ð޸ıêÇ©
    JButtonModel deleteicon=null;//ɾ³ý±êÇ©
    JButtonModel shua_xin=null;//ˢбêÇ©
    JScrollPane gdmb=null;//¹ö¶¯Ãæ°å
    Vector<Vector<String>> serchrowData=null;//ËÑË÷Ò³±í¸ñÏòÁ¿
    DefaultTableModel tableModel=null;
    Vector<String> columnName=null;
    Iterator iterator=null;//ÉêÃ÷µü´úÆ÷
    JTable table=null;//ÉêÃ÷±í¸ñ
    Vector rowData=null;
    List list=null ;
    JPanel centerPanel=null;//Öв¿Ãæ°å
    NothJPanel southJpan=null;//Äϲ¿Ãæ°å
    JButtonModel button=null;
    String fileName="";//Îı¾¿òÄÚÈÝ
    String path;//ͼ±ê±£´æµØÖ·
    String path2;//ͼ±ê±£´æµØÖ·
    Container rq;
 
 
    public IconManagement() {
        rowData=new Vector();
        String title="ͼ±ê¹ÜÀí";
        if(Systems.sys().getLanguage().equals("English")) {
            title="Tag Icon management";
        }
        this.setTitle(title);
        rq=getContentPane();//»ñÈ¡ÈÝÆ÷
        rq.setLayout(new BorderLayout());
        rq.setBackground(UIColor.getNorth_color());
        rq.add(getSouthJpan(),BorderLayout.NORTH);
        rq.add(getGdmb());
        this.setFrameIcon(new ImageIcon("image/icon/iconManage.png"));//ÉèÖô°Ìåͼ±ê        
 
    }
 
 
    public JScrollPane getGdmb() {//»ñµÃ¹ö¶¯Ãæ°å
        if(gdmb==null) {
            gdmb=new JScrollPane(getTable());//¹ö¶¯Ãæ°å
            gdmb.getViewport().setBackground(UIColor.getNorth_color());
        }
        return gdmb;
    }
 
    public JTable getTable() {//»ñÈ¡table
        if(table==null) {
            String[] name1= {"ͼ±êÃû³Æ","ͼ±êÔ¤ÀÀ ","Ìí¼Óʱ¼ä","±¸×¢"};//±í¸ñÁÐÃû
            String[] name2= {"Icon name", "Icon preview", "Add time", "Remarks"};//±í¸ñÁÐÃû
            String[] columnNames=English.columnNames(name1, name2);
            //Ìí¼Ó±í¸ñÁÐÏòÁ¿
            columnName=new Vector<>();
            for(int i=0;i<columnNames.length;i++){
                columnName.add(columnNames[i]);            
            }
            //Ìí¼Ó±í¸ñÐÐÏòÁ¿Êý¾Ý
            rowData=new Vector<>();    
            
            greateTables tables=new greateTables();
            tableModel=new DefaultTableModel(rowData, columnName){  
                /**
                 * 
                 */
                private static final long serialVersionUID = 1L;
 
                //  ÊµÏÖÈÃÕû¸ö±í¸ñ²»²»ÔÊÐí±»±à¼­
                public boolean isCellEditable(int row,int column){  
                    return false;  
                }  
            };
 
            table=tables.getTable(tableModel);    
            getRowData(Dell_Tbicon.getTbicon_vector());
            
            table.getColumnModel().getColumn(1).setPreferredWidth(100);// ÉèÖõÚ3Áпí
            TableColumn column = table.getColumnModel().getColumn(1);// »ñÈ¡±í¸ñµÚ1ÁжÔÏó
            table.setRowHeight(40);//ÉèÖñí¸ñÐиß
            column.setCellRenderer(new TableCellRenderer() {// ÉèÖõÚ2ÁеÄäÖȾÆ÷                
                public Component getTableCellRendererComponent(
                        JTable table, Object value, boolean isSelected,
                        boolean hasFocus, int row, int column) {
                    ImageIcon icon = (ImageIcon) value;
                    JLabel label = new JLabel(icon);// ´´½¨Í¼±ê
                    label.setBackground(table.getSelectionBackground());
                    // °ÑÑ¡ÔñµÄ±êÇ©ÉèÖÃΪ͸Ã÷                    
                    label.setOpaque(true);                    
                    
                    if (row % 2 == 0) {
                        label.setBackground(UIColor.getTable_1());
                    } else {
                        label.setBackground(UIColor.getTable_2());
                    }
                    
                    if(isSelected) {
                        label.setBackground(UIColor.getTable_sekected());    
                    }
                    return label;// °Ñͼ±ê×÷ΪΪäÖȾ¿Ø¼þ
                }
            });
 
        }
        return table;
 
    }
 
 
 
 
    public JLabel getIconName() {//»ñͼ±êÃû³Æ±êÇ©
        if(iconName==null) {            
            iconName=new JlableModel();    
            iconName.setText("ͼ±êÃû³Æ£º");
        }
        return iconName;
    }
 
    public JTextField getIconFile() {//»ñÎı¾¿ò
        if(iconFile==null) {            
            iconFile=new JTextField(10);
 
 
        }
        return iconFile;
    }
 
    public  void setIconFile(String fileName) {//ÉèÖÃÃû³ÆÎı¾¿òÄÚÈÝ
        this.fileName=fileName;
        getIconFile().setText(fileName);
 
    }
 
 
 
    public JButtonModel getAltericon() {//»ñȡɾ³ý¸Ä°´Å¥
        if(altericon==null) {
            altericon=new JButtonModel("ɾ ³ý");        
            altericon.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {                    
                    int[] selectedRows=table.getSelectedRows();//±»Ñ¡ÖÐÐеÄË÷Òý¼¯ºÏ
                    if(selectedRows.length !=0) {
                        for(int i=0;i<selectedRows.length;i++){    
                            String name1=(String) table.getValueAt(selectedRows[i], 0);
                            if(name1.equals("default.png")) {
                                ShowMessage.zidingyi("ϵͳĬÈϽûֹɾ³ý£¡");
                                return;
                            }
                            Dell_Tbicon.delete_tbicon(name1);
 
                        }
                                                
                        //ɾ³ý³É¹¦ÌáʾÐÅÏ¢
                        ShowMessage.zidingyi(selectedRows.length+"Ìõ¼Ç¼ɾ³ý³É¹¦£¡");
                        updateTable();//µ÷ÓÃˢбí¸ñ·½                        
                    }
                    else {
                        ShowMessage.zidingyi( "ÇëÑ¡ÔñÐèҪɾ³ýµÄÄÚÈÝ£¡");                
                    }
                }
            });
        }
        return altericon;
    }
 
 
    public JButtonModel getDeleteicon() {//»ñȡɾ³ý°´Å¥
        if(deleteicon==null) {
            deleteicon=new JButtonModel(buttonTitle.getDeleteall());            
            deleteicon.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    //Ñ¡Ôñ¶Ô»°¿òÈçyes·µ»Ø0£¬NO·µ»Ø1£¬È¡Ïû·µ»Ø2
                    WarningMessage warning=new WarningMessage();
                    warning.setMessage("Ñ¡Ôñɾ³ýÈ«²¿½«»á°Ñ±í¸ñÊý¾ÝÈ«²¿É¾³ýÈ·¶¨Âð£¿");
                    int warn=warning.getwarMss(getSouthJpan());
                    int tagnum=table.getRowCount();//±í¸ñ×ÜÐÐÊý
                    if(tagnum!=0 && warn==0) {
                        String deleteSql="TRUNCATE TABLE tb_icon ";
                        ShowMessage.deleteAll(DatabaseManagement.update(deleteSql));
                        Dell_Tbicon.delete_all_tbicon();
                        rq.repaint();
                    }
                }
            });
        }
        return deleteicon;
    }
 
    public NothJPanel getSouthJpan() {//»ñÈ¡Äϲ¿Ãæ°å
        if(southJpan==null) {
            southJpan=new NothJPanel();            
            Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷
            topicBox.add(get_shua_xin());//ÉÏ´«Í¼±ê°´Å¥Ìí¼Ó
            topicBox.add(Box.createHorizontalStrut(30));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(get_xin_zeng_button());//ÉÏ´«Í¼±ê°´Å¥Ìí¼Ó
            topicBox.add(Box.createHorizontalStrut(30));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(getAltericon());
//            topicBox.add(Box.createHorizontalStrut(30));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
//            topicBox.add(getDeleteicon());
            southJpan.add(topicBox );
        }   
        return southJpan;
    }
 
 
    /**ˢбí¸ñ·½·¨*/
 
    public void updateTable() {            
        if(tableModel !=null) {
            tableModel.getDataVector().clear();
            getRowData(Dell_Tbicon.getTbicon_vector());
            gdmb.validate();
            }
    }
 
    /**Ìí¼Ó±í¸ñÐÐÏòÁ¿Êý¾Ý·½·¨*/ 
    @SuppressWarnings("unchecked")
    
    public void getRowData( Vector<Tbicon> vc ) {
        Iterator<Tbicon> iterator = vc.iterator();//´´½¨µü´úÆ÷        
        while (iterator.hasNext()) {//µü´úÆ÷´æÔÚÔªËØ            
            Tbicon tbi=  iterator.next();//½«µü´úÆ÷ÀïÃæµÄÔªËØ¸øµ½list¼¯ºÏ
            Vector row = new Vector();
            row.add(tbi.getIcon_name());
            row.add(tbi.getIcon());
            row.add(tbi.getAdd_time());
            row.add(tbi.getBeizhu());
            tableModel.addRow(row);
        }
    }
    
    
 
 
    /**ÐÂÔöͼ±ê°´Å¥*/
    public JButtonModel get_xin_zeng_button() {
        if(xin_zeng_button==null) {
            xin_zeng_button=new JButtonModel("РÔö");
            xin_zeng_button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    new add_Dialog("ÐÂÔöͼ±ê");
                }
            });
        }
        return xin_zeng_button;
    }
 
 
    //ÄÚ²¿Àà
    class add_Dialog extends JDialog{
 
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
 
 
        JButtonModel que_ding=null;//È·¶¨°´Å¥
        JButtonModel qu_xiao=null;//È¡Ïû°´Å¥
        JButtonModel shang_chuang=null;//ÉÏ´«Í¼Æ¬°´Å¥
        JPanel mb=null;//ÉêÃ÷Ò»¸öÃæ°å
        JTextField iconNametext=null;//ÊäÈëͼ±êÃû³Æ
 
 
        public add_Dialog(String title) {
            this.setAlwaysOnTop(true);//×ÜÊÇÖö¥
            Toolkit toolkit = getToolkit();// »ñµÃ´°Ì幤¾ß°ü
            Dimension screenSize = toolkit.getScreenSize();// »ñÈ¡ÆÁÄ»´óС
            int width = (int) (screenSize.width* 0.5);// ¼ÆËã´°Ìåпí¶È
            int height = (int) (screenSize.height * 0.5);// ¼ÆËã´°Ìåпí¶È
            int x0=width-170;//´°Ìåx0×ø±ê
            int y0=height-90;//´°Ìåy0×ø±ê
            Container rq=getContentPane();
            rq.add(getMb());
            this.setTitle(title);
            this.setBounds(x0, y0, 340,180);
            this.setVisible(true);
        }
 
        /**»ñÈ¡Ãæ°å*/
        public JPanel getMb() {
            if(mb==null){
                mb=new JPanel();
                mb.setLayout(null);
                iconNametext=new JTextField(10);
 
                get_shang_chuang().setBounds(30, 30,80,25);
                iconNametext.setBounds(120, 30, 100,25);
                getQue_ding().setBounds(30, 90, 50, 25);
                getQu_xiao().setBounds(110, 90, 50, 25);
 
 
                mb.add(get_shang_chuang());
                mb.add(iconNametext);
                mb.add(getQue_ding());
                mb.add(getQu_xiao());
 
            }
 
            return mb;
        }
 
        /**»ñȡȷ¶¨°´Å¥µÄ·½·¨*/    
        public JButtonModel getQue_ding() {//»ñÈ¡±£´æ°´Å¥
            if(que_ding==null) {
                que_ding=new JButtonModel(buttonTitle.getSave());    
                que_ding.addActionListener(new ActionListener() {//Ìí¼Óʼþ¼àÌý
                    public void actionPerformed(ActionEvent e) {
 
                        //±êÇ©Ãû³ÆÊÇ¿Õʱºòµ¯³ö
                        if (iconNametext.getText().equals("") ) {
                            ShowMessage.zidingyi("±êÇ©Ãû³Æ²»ÄÜΪ¿Õ");
                            return;
                        }
                        
                        String iconName=iconNametext.getText().trim();
                        //ͼ±êÐòºÅidĬÈÏ×ÔÔö(default)ΪÕûÐÍ                        
                        Dell_Tbicon.add_tbicon(iconName, path);
                        updateTable();//µ÷ÓÃˢбí¸ñ·½
 
                    }
                });
            }
            return que_ding;
        }
 
 
        /**»ñȡȡÏû°´Å¥µÄ·½·¨*/    
        public JButtonModel getQu_xiao() {
            if(qu_xiao==null){
                qu_xiao=new JButtonModel("È¡Ïû");
                qu_xiao.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        closeTagDialog();
                    }
                });
 
            }
            return qu_xiao;
        }        
 
 
        /**¹Ø±Õ¶Ô»°¿ò·½·¨*/
        public void closeTagDialog() {
            this.dispose();
        }
 
        /**ÉÏ´«Í¼Æ¬°´Å¥*/
        public JButtonModel get_shang_chuang() {//»ñÈ¡ÉÏ´«°´Å¥
            if(shang_chuang==null) {
                shang_chuang=new JButtonModel("ÉÏ´«Í¼±ê");
                shang_chuang.addActionListener(new ActionListener() {
                    JFileChooser fileChooser=new JFileChooser(GetDeskPath.path());//ÎļþÑ¡ÔñÆ÷
                    public void actionPerformed(ActionEvent e) { 
                        FileNameExtensionFilter filter=new FileNameExtensionFilter("ͼƬ", "JPG","PNG","JPEG");//Îļþ¹ýÂËÆ÷
                        fileChooser.setFileFilter(filter);//Ìí¼ÓÎļþ¹ýÂËÆ÷
                        int i=fileChooser.showOpenDialog(getSouthJpan());//ÏÔʾѡÔñÎļþ¶Ô»°¿ò
                        if(i==JFileChooser.APPROVE_OPTION) {//Èç¹ûÓû§Ñ¡ÔñµÄÊÇ¡°´ò¿ª¡±°´Å¥
                            File file=fileChooser.getSelectedFile();//»ñȡѡÖеÄÎļþ                
                            String fileName=file.getName();//ÎļþÃû³Æ    
                            setIconFile(fileName);
                            //µØÍ¼Í¼Æ¬µ¼Èë
                            path="image/targeticon/"+fileName;//ͼƬ±£´æÂ·¾¶
                            FileIn imageImport=new FileIn();
                            imageImport.SaveFileIn(file,path);    
                            ShowMessage.zidingyi( "ͼƬÒѾ­´æÈë"+path);
                            iconNametext.setText(fileName);
 
                        }
                        else {
                            return;
                        }
 
                    }
                });
 
            }
            return shang_chuang;
        }
 
    }
    
    public JButtonModel get_shua_xin() {
        if(shua_xin==null) {
            shua_xin=new JButtonModel("Ë¢ ÐÂ");
            shua_xin.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    updateTable();
                }
            });
            
        }
        return shua_xin;
    }
}