ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
package com.vci.client.ui.swing;
 
import java.awt.Color;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.prefs.Preferences;
 
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.Border;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.plaf.FontUIResource;
 
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJLabel;
import com.vci.client.ui.swing.components.VCIJMenuItem;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.utils.excel.ExcelFileOperation;
 
import edu.stanford.smi.protege.util.LookAndFeelUtil;
 
/**
 * 
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2012</p>
 * <p>Company: VCI</p>
 * @author xchao
 * @time 2012-5-10
 * @version 1.0
 */
public class VCISwingUtil {
    public final static Color TEXTCOLOR = new Color(48, 70, 110);
    public final static Color TEXTCOLOR_LOST = new Color(150, 150, 150);
    public final static Color FRAMECOLOR = new Color(98, 140, 97);
    public final static Color TBC1 = new Color(239, 243, 249);
    public final static Color TBC2 = new Color(220, 229, 241);
    public final static Color TBC3 = new Color(187, 206, 229);
    public final static Color TBC4 = new Color(221, 232, 242);
    private static Frame CLIENT_MAIN_FRAME = null;
    public final static String FONT_FAMILY = "宋体";
    public final static Font FONT_SONTTI_PLAN_12 = new Font(FONT_FAMILY, Font.PLAIN, 12);
    public final static Font FONT_SONTTI_PLAN_13 = new Font(FONT_FAMILY, Font.PLAIN, 13);
    public final static Font FONT_SONTTI_PLAN_14 = new Font(FONT_FAMILY, Font.PLAIN, 14);
    public final static Font FONT_DEFAULT = FONT_SONTTI_PLAN_12;
    public final static Font ST12 = new Font("Dialog", Font.PLAIN, 12);
    public final static Font Font12B = new Font("Dialog", Font.BOLD, 12);
    public final static int JTEXT_FIELD_DEFAULT_HEIGHT = 23;
    public final static int JTEXT_FIELD_DEFAULT_WIDTH = 100;
    public final static Color JTEXT_FIELD_DEFAULT_BORDER_COLOR = new Color(160, 160, 160);
    public final static Color JTEXT_FIELD_MOUSE_ENTER_COLOR = new Color(77, 144, 254);//new Color(92, 163, 45);
    public final static Color JTEXT_FIELD_MOUSE_CLICK_COLOR = JTEXT_FIELD_MOUSE_ENTER_COLOR;
    public final static Color JTEXT_FIELD_MOUSE_EXITED_BACKGROUND_COLOR = Color.WHITE;
    public final static Color JTEXT_FIELD_MOUSE_CLICK_BACKGROUND_COLOR = new Color(254, 251, 189);
    public final static Border JTEXT_FIELD_BORDER_DEFAULT = BorderFactory.createLineBorder(JTEXT_FIELD_DEFAULT_BORDER_COLOR, 1);
    public final static Border JTEXT_FIELD_BORDER_MOUSE_ENTERED = BorderFactory.createLineBorder(JTEXT_FIELD_MOUSE_ENTER_COLOR, 1);
    public final static Border JTEXT_FIELD_BORDER_MOUSE_EXITED = BorderFactory.createLineBorder(JTEXT_FIELD_DEFAULT_BORDER_COLOR, 1);
    public final static Border JTEXT_FIELD_BORDER_MOUSE_CLICKED = BorderFactory.createLineBorder(JTEXT_FIELD_MOUSE_CLICK_COLOR, 1);
    public final static Border BORDER_EMPTY = BorderFactory.createEmptyBorder();
    public final static String IMAGE_PATH = "/resource/images/";
    public final static int JTABLE_ROW_HEIGHT = 25;
    public final static int JTABLE_HEADER_HEIGHT = JTABLE_ROW_HEIGHT;
    public final static Color JTABLE_ROW_BACKGROUND_COLOR_HOVER = new Color(255, 255, 225);
    public final static Color JTABLE_ROW_BACKGROUND_COLOR_CHECKED = new Color(255, 255, 200);
    public final static Color JTABLE_ROW_BACKGROUND_COLOR_ODD = new Color(242, 242, 242);
    public final static Color JTABLE_ROW_BACKGROUND_COLOR_EVEN = Color.WHITE;
    public final static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public final static String LOOK_AND_FEEL_MetalLookAndFeel = "com.sun.java.swing.plaf.metal.MetalLookAndFeel";
    public final static String LOOK_AND_FEEL_WindowsLookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    public final static String LOOK_AND_FEEL_AlloyLookAndFeel = "com.incors.plaf.alloy.AlloyLookAndFeel";
    public final static String LOOK_AND_FEEL_NimbusLookAndFeel= "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
    public final static String LOOK_AND_FEEL_PlasticLookAndFeel = "com.jgoodies.looks.plastic.PlasticLookAndFeel";
    public final static String LOOK_AND_FEEL_FlatLightLaf = "com.formdev.flatlaf.FlatLightLaf";
    
    /**
     * 设置客户端主Frame对象
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param frame
     */
    public static void setClientMainFrame(Frame frame){
        if(CLIENT_MAIN_FRAME == null){
            CLIENT_MAIN_FRAME = frame;
        }
    }
    
    
    /**
     * 返回客户端主Frame对象
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @return
     */
    public static Frame getClientMainFrame(){
        return CLIENT_MAIN_FRAME;
    }
    
    /**
     * 
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param icon
     * @return
     */
    public static ImageIcon createImageIconFromImagePath(String icon){
        return createImageIcon(VCISwingUtil.class, IMAGE_PATH + icon);
    }
    /**
     * 
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param icon
     * @return
     */
    public static ImageIcon createImageIcon(String icon){
        return createImageIcon(VCISwingUtil.class, icon);
    }
    /**
     * 
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param classes
     * @param icon
     * @return
     */
    public static ImageIcon createImageIcon(Class<?> classes, String icon){
        URL url = classes.getResource(icon);
        if(url == null){
            url = classes.getResource(IMAGE_PATH + icon);
        }
        return createImageIcon(url);
    }
    
    /**
     * 
     * @param classes
     * @param icon
     * @return
     */
    public static Image createImage(String icon){
        URL url = VCISwingUtil.class.getResource(icon);
        if(url == null){
            url = VCISwingUtil.class.getResource(IMAGE_PATH + icon);
        }
        
        ImageIcon imgIcon = createImageIcon(url);
        
        return imgIcon.getImage();
    }
    
    /**
     * 
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param url
     * @return
     */
    public static ImageIcon createImageIcon(URL url){
        //ClientWithLog4j.logger.debug("ImageUrl=" + url);
 
        return new ImageIcon(url);
    }
    
    public static String[] getImages() {
        try {
            //ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
            
            //Resource[] resources = resourceResolver.getResources("resource/images/*.*");
            
            String path = "resource/images/*.*";
            Enumeration<?> urlEnumeration = VCISwingUtil.class.getClassLoader().getResources(path);
            List<String> lstImage = new ArrayList<String>();
            while (urlEnumeration.hasMoreElements()) {
                URL url = (URL)urlEnumeration.nextElement();
                File file = new File(url.toString());
                String name = file.getName();
                lstImage.add(name);
            }
 
//            for (int i = 0; i < resources.length; i++) {
//                String name = resources[i].getFilename();
//                lstImage.add(name);
//            }
            
            return lstImage.toArray(new String[0]);
            
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new String[0];
    }
    
    
    /**
     * 
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param font
     */
    public static void setFont(Font font){
        FontUIResource fontUIResource = new FontUIResource(font);
        Enumeration<Object> keys = UIManager.getDefaults().keys();
        while(keys.hasMoreElements()){
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if(value instanceof java.awt.Font){
                UIManager.put(key, font);
            }
            if(value instanceof FontUIResource){
                UIManager.put(key, fontUIResource);
            }
        }
    }
    /**
     * 设置全部组件的默认字体
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     */
    public static void setFont(){
        setFont(FONT_DEFAULT);
    }
    /**
     * 设置默认的主题皮肤(NimbusLookAndFeel)
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     */
    public static void setLookAndFeel(){
        //setLookAndFeel(LOOK_AND_FEEL_NimbusLookAndFeel);
        //setLookAndFeel(LOOK_AND_FEEL_AlloyLookAndFeel);
        setLookAndFeel(LOOK_AND_FEEL_PlasticLookAndFeel);
        //setLookAndFeel(LOOK_AND_FEEL_FlatLightLaf);
        //setLookAndFeel(LOOK_AND_FEEL_WindowsLookAndFeel);
    }
    
    /**
     * 根据指定class来设置LookAndFeel
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param lafClass
     */
    public static void setLookAndFeel(String lafClass){
        try {
            String javaVersion = System.getProperty("java.version");
            if(javaVersion != null){
                String[] versions = javaVersion.split("_");
                if(versions.length == 2){
                    int major = Integer.valueOf(versions[0].replaceAll("1.", "").replaceAll(".0", ""));
                    int minor = Integer.valueOf(versions[1]);
                    /**
                     * LOOK_AND_FEEL_NimbusLookAndFeel 正确使用问题:
                     * 1、如果JAVA版本是6,但小版本低于10,则使用Windows主题
                     * 2、如果JAVA版本是5或更低,则使用Windows主题
                     */
                    if(major >= 6){
                        if(minor <= 10 && lafClass.equalsIgnoreCase(LOOK_AND_FEEL_NimbusLookAndFeel)){
                            lafClass = LOOK_AND_FEEL_WindowsLookAndFeel;
                        } 
                    } else{
                        lafClass = LOOK_AND_FEEL_WindowsLookAndFeel;
                    }
                }
            }
            
            LookAndFeel lookAndFeel = (LookAndFeel) Class.forName(lafClass).newInstance();
            LookAndFeelUtil.setUpPlasticLF();
            UIManager.put("ClassLoader", lookAndFeel.getClass().getClassLoader());
            UIManager.setLookAndFeel(lookAndFeel);
            JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
            setAllComponentFont();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
    }
    private static void setAllComponentFont(){
        Font font = FONT_DEFAULT;
        FontUIResource fontUIResource = new FontUIResource(font);
        java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
        while (keys.hasMoreElements())
        {
            Object key = keys.nextElement();
            Object obj = UIManager.get (key);
            if(obj instanceof Font){
                UIManager.put(key, font);
            }
            if(obj instanceof FontUIResource){
                UIManager.put(key, fontUIResource);
            }
        }
    }
    /**
     * 延时执行
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param doRun runnnable 
     * @param lazyMillis 延时时间(单位为毫秒)
     */
    public static void invokeLater(final Runnable doRun, final int lazyMillis){
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                try {
                    Thread.sleep(lazyMillis);
                    doRun.run();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    /**
     * 创建一个按钮对象
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param actionCommand
     * @param text
     * @param toolTip
     * @param icon
     * @return
     * @see     createVCIJButton
     */
    public static VCIJButton createVCIJButton(String actionCommand, String text, String toolTip, String icon){
        return createVCIJButton(actionCommand, text, toolTip, icon, null);
    }
    public static final Icon EMPTY_ICON = new Icon() {
        @Override
        public void paintIcon(Component c, Graphics g, int x, int y) {
        }
        @Override
        public int getIconWidth() {
            return 0;
        }
        @Override
        public int getIconHeight() {
            return 0;
        }
    }; 
    /**
     * 创建一个VCIJButton对象
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param actionCommand 按钮的 actionCommand
     * @param text text
     * @param toolTip toolTip
     * @param icon icon(如果icon在resource/images/包下,只需要写文件名,否则需要提供完整的路径)
     * @param actionListener actionListener
     * @return
     */
    public static VCIJButton createVCIJButton(String actionCommand, String text, String toolTip, String icon, ActionListener actionListener){
        VCIJButton btn = new VCIJButton(text);
        if(icon != null && !"".equals(icon.trim())){
            btn.setIcon(VCISwingUtil.createImageIcon(icon));
        } else {
            btn.setIcon(EMPTY_ICON);
        }
        if(actionListener != null){
            btn.addActionListener(actionListener);
        }
        btn.setActionCommand(actionCommand);
        btn.setToolTipText(toolTip);
        btn.setText(text);
        return btn;
    }
    public static VCIJMenuItem createVCIJMenuItem(String actionCommand, String text, String toolTip, String icon){
        return createVCIJMenuItem(actionCommand, text, toolTip, icon, null);
    }
    public static VCIJMenuItem createVCIJMenuItem(String actionCommand, String text, String toolTip, String icon, ActionListener actionListener){
        VCIJMenuItem menuItem = new VCIJMenuItem(text, VCISwingUtil.createImageIcon(icon));
        if(actionListener != null){
            menuItem.addActionListener(actionListener);
        }
        menuItem.setActionCommand(actionCommand);
        menuItem.setToolTipText(toolTip);
        menuItem.setText(text);
        return menuItem;
    }
    /**
     * 返回日期的字符串表现形式
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param date java.util.Date
     * @return
     */
    public static String getDateString(java.util.Date date){
        return SDF.format(date);
    }
    /**
     * 
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-5-19
     * @param date java.sql.Date
     * @return
     */
    public static String getDateString(java.sql.Date date){
        @SuppressWarnings("deprecation")
        java.util.Date utDate = new java.util.Date(
                date.getYear(), date.getMonth(), date.getDate(),
                date.getHours(), date.getMinutes(), date.getSeconds());
        return getDateString(utDate);
    }
    
 
    /**
     * 返回从文件选择框中选择的Excel文件完整的路径
     * <p>Description: </p>
     * @author xchao
     * @time 2013-7-8
     * @param parent 父容器对象
     * @param isSaveDialog 是否是保存文件模式
     * @param defaultFileName 默认文件名称
     * @param defaultVersionIs2003 首选文件格式是否是Excel 2003
     * @return
     */
    public static String getExcelFileURL(Component parent, boolean isSaveDialog, 
            String defaultFileName, boolean defaultVersionIs2003){
        LinkedHashMap<String, String> filterMap = new LinkedHashMap<String, String>();
        if(defaultVersionIs2003){
            filterMap.put("Excel 97-2003工作薄(*.xls)", "xls");
        }        
        filterMap.put("Excel 工作薄(*.xlsx)", "xlsx");
        if(!defaultVersionIs2003){
            filterMap.put("Excel 97-2003工作薄(*.xls)", "xls");
        }
        String filePath = getFileURL(parent, isSaveDialog, filterMap, defaultFileName);
        if(!isSaveDialog && filePath != null && !"".equals(filePath) 
                && !new ExcelFileOperation().isSupportExcelFormat(parent, filePath)){
            filePath = null;
        }
        return filePath;
    }
    /**
     * 返回从文件选择框中选择的Excel文件完整的路径
     * <p>Description: </p>
     * @author xchao
     * @time 2013-7-8
     * @param parent 父容器对象
     * @param isSaveDialog 是否是保存文件模式
     * @param defaultFileName 默认文件名称
     * @return
     */
    public static String getExcelFileURL(Component parent, boolean isSaveDialog, String defaultFileName){
        return getExcelFileURL(parent, isSaveDialog, defaultFileName, true);
    }
 
    /**
     * 
     * <p>Description: </p>
     * <p>Description: </p>
     * @author xchao
     * @time 2013-7-8
     * @param parent 父容器对象
     * @param isSaveDialog 是否是保存文件模式
     * @param filterMap 文件后续过滤map key:描述 value:后缀,如 xlsx或.xlsx
     * @param defaultFileName 默认文件名
     * @return
     */
    public static String getFileURL(Component parent, boolean isSaveDialog, Map<String, String> filterMap, String defaultFileName){
        String lastPath = "";
        Preferences pref = Preferences.userRoot().node(VCISwingUtil.class.getName());
        lastPath = pref.get("lastPath", "");
        if(lastPath != null && lastPath.equals("") || lastPath == null){
            lastPath = System.getProperty("user.home");
        }
        JFileChooser jfc = new JFileChooser(lastPath);
        jfc.setAcceptAllFileFilterUsed(true);
        jfc.setMultiSelectionEnabled(false);
        jfc.setFileHidingEnabled(false);
        jfc.setMultiSelectionEnabled(false);
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        String firstSuffix = "";
        if(filterMap != null){
            Iterator<String> keys = filterMap.keySet().iterator();
            FileNameExtensionFilter defaultFilter = null;
            while(keys.hasNext()){
                String key = keys.next();
                String value = filterMap.get(key);
                if((firstSuffix == null) || (firstSuffix.length() == 0)){
                    firstSuffix = value;
                }
                if(value.lastIndexOf(".") >= 0 ){
                    value = value.substring(value.lastIndexOf(".") + 1);
                }
                FileNameExtensionFilter filter = new FileNameExtensionFilter(key, value);
                jfc.addChoosableFileFilter(filter);
                
                if(defaultFilter == null){
                    defaultFilter = filter;
                }
            }
            // 设置对话框的默认扩展名
            jfc.setFileFilter(defaultFilter);
            jfc.setAcceptAllFileFilterUsed(false);
        }
        if(defaultFileName != null){
            jfc.setSelectedFile(new File(defaultFileName));
        }
        int result = -1;
        if(isSaveDialog){
            jfc.setDialogType(JFileChooser.SAVE_DIALOG);
            result = jfc.showSaveDialog(parent);
        } else{
            jfc.setDialogType(JFileChooser.OPEN_DIALOG);
            result = jfc.showOpenDialog(parent);
        }
        pref.put("lastPath", lastPath);
        if (result == JFileChooser.APPROVE_OPTION){
            pref.put("lastPath", jfc.getSelectedFile().getParent());
            String selectedFilePath = jfc.getSelectedFile().getAbsolutePath();
            boolean validSuffix = false;
            if(jfc.getFileFilter() instanceof FileNameExtensionFilter){
                FileNameExtensionFilter filter = (FileNameExtensionFilter) jfc.getFileFilter();
                String[] extensions = filter.getExtensions();
                for(int i = 0; i < extensions.length; i++){
                    String ext = extensions[i];
                    if(i == 0){
                        firstSuffix = ext;
                    }
                    if(selectedFilePath.endsWith("." + ext)){
                        validSuffix = true;
                    }
                }
            }
            if(!validSuffix){
                selectedFilePath += "." + firstSuffix;
            }
            if(selectedFilePath.endsWith(".")){
                selectedFilePath = selectedFilePath.substring(0, selectedFilePath.length() -1);
            }
            return selectedFilePath;
        }
        return null;
    }
 
    /**
     * 打开文件保存成功的消息提示框
     * @param parentComponent 父组件对象
     * @param file file对象
     * @param isOpen 
     * @throws IOException
     */
    public static void showOpenOrExplorerFileMessage(Component parentComponent, File file) throws IOException{
        Object[] message = {new VCIJLabel("<html><p>数据成功保存到:</p><p></p><p style='color:blue;font-size:14px;'>" + file.getAbsolutePath() + "</p><p>&nbsp;</p></html>")};
        Object[] options = {"打开(O)", "打开文件夹(F)", "关闭(C)"};
        int res = VCIJOptionPane.showOptionDialog(parentComponent, message, "数据导出成功", 
                VCIJOptionPane.DEFAULT_OPTION, VCIJOptionPane.INFORMATION_MESSAGE, null, 
                options, options[options.length-1]);
        if(res == 0){
            VCISwingUtil.openOrExplorerFile(parentComponent, file, true);
        } else if(res == 1){
            VCISwingUtil.openOrExplorerFile(parentComponent, file, false);
        } else if(res == 2){
        }
    }
    
    /**
     * 打开文件或打开文件所在的文件夹并选中文件
     * @param owner 父组件对象
     * @param file 文件对象
     * @param isOpen true:打开文件,false:打开文件所在的文件夹并选中文件
     */
    public static void openOrExplorerFile(Component parentComponent, File file, boolean isOpen){
        boolean isWindowsPlatform = System.getProperty("os.name").toLowerCase().contains("windows");
        String runCommand = "cmd.exe /C start \"{4}\" /D \"{1}\" \"{3}\"";
        runCommand = "explorer.exe /n, " + file.getAbsolutePath();
        String explorerCommand = "explorer.exe /select,\"{2}\"";
        
        boolean hasBlank = file.getAbsolutePath().contains(" ");
        
        if(!isWindowsPlatform){
            VCIJOptionPane.showMessage(parentComponent, "不支持本系统!");
            return;
        }
        String errorMessage = "执行打开文件或文件夹时发生错误!";
        String drive = null;
        String full_path = null;
        String parent_path = null;
        String file_name = null;
 
        full_path = file.getAbsolutePath();
        if (file.isDirectory()) {
            parent_path = file.getPath();
            file_name = "dir";
        } else {
            parent_path = file.getParent();
            file_name = file.getName();
        }
 
        if (full_path != null) {
            if (full_path.indexOf(":") != -1) {
                drive = full_path.substring(0, full_path.indexOf(":"));
            }
            try {
                String target = "";
                if (isOpen) {
                    target = runCommand;
                } else {
                    target = explorerCommand;
                }
                String[] args = new String[6];
                args[0] = drive;
                args[1] = parent_path;
                args[2] = full_path;
                args[3] = file_name;
                args[4] = file.getParent();
                args[5] = System.getProperty("line.separator");
                if(hasBlank){
                    if(isOpen){
                        //showOpening(parentComponent);
                        Desktop.getDesktop().open(file);
                    } else{
                        int msgRes = VCIJOptionPane.showConfirmDialog(parentComponent, 
                                "文件路径中存在空格,不支持打开文件路径存在空格的文件夹,\n" +
                                "您是否需要打开该文件?", 
                                "询问", VCIJOptionPane.YES_NO_OPTION    , VCIJOptionPane.QUESTION_MESSAGE);
                        if(msgRes == VCIJOptionPane.YES_OPTION){
                            showOpening(parentComponent);
                            Desktop.getDesktop().open(file);
                        }
                    }
                } else {
                    showOpening(parentComponent);
                    String cmd = MessageFormat.format(target, args);
                    Runtime.getRuntime().exec(cmd);
                }
            } catch (Exception e) {
                e.printStackTrace();
                VCIJOptionPane.showError(parentComponent, errorMessage);
            }
        } else {
            VCIJOptionPane.showError(parentComponent, errorMessage);
        }
     }
    
    private static void showOpening(final Component parentComponent){
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                VCIJOptionPane.showMessage(parentComponent, "正在打开,请稍候...");
//            }
//        }).start();
    }
    
    private static File getExcelFile() {
        File file = null;
        String filePath = VCISwingUtil.getExcelFileURL(null, true, "");
        if(filePath != null){
            file = new File(filePath);
        }
        return file;
    }
    
    private static File getRequiredFile(){
        File files = getExcelFile();
        // add by xchao 2014.04.15 begin
        // 有错误数据要输出时,必须选择有效的excel文件
        while(files == null){
            files = getExcelFile();
        }
        String fileName = files.getAbsolutePath();
        // 如果文件被打开着,则必须选择其它的未打开着的文件
        while (files.exists() && !files.renameTo(new File(fileName))) {
            VCIJOptionPane.showMessageDialog(null,
                    "另一个程序正在使用此文件,进程无法访问,请重新选择!");
            // 重新选择文件时,也必须选择有效的excel文件
            files = null;
            while(files == null){
                files = getExcelFile();
            }
            fileName = files.getAbsolutePath();
        }
        return files;
    }
    public static void main(String[] args){
        
//        writeExcelFileInfo("", "", null, null);
        
//        final boolean[] ress = new boolean[1];
//        final QANProcessBarFrame frame = new QANProcessBarFrame();
//        Thread t = new Thread() {
//            public void run() {
//                try{
//                File files = getRequiredFile();
//                ress[0] = true;
//                System.out.println(files.getAbsolutePath());
//                }catch(Exception e){
//                    e.printStackTrace();
//                }finally{
//                    frame.setProcessBarCancel(true);
//                }
//            }
//        };
//        QANProcessBar bar = new QANProcessBar(t, frame, frame, "断链检查", false);
//        bar.setVisible(true);
        System.exit(0);
    }
}