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
package com.vci.client.ui.swing.components;
 
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
 
import javax.swing.JDialog;
 
import com.vci.client.ui.swing.VCISwingUtil;
 
/**
 * 
 * <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 VCIJDialog extends JDialog {
 
    public enum DialogResult{
        OK,
        CANCEL,
    }
    
    /**
     * 
     */
    private static final long serialVersionUID = 7577447673438065060L;
 
    private DialogResult dialogResult = DialogResult.CANCEL;
    
    public VCIJDialog() throws HeadlessException {
        this((Frame)null, false);
    }
 
    public VCIJDialog(Frame owner) throws HeadlessException {
        this(owner, false);
    }
 
    public VCIJDialog(Dialog owner) throws HeadlessException {
        this(owner, false);
    }
 
    public VCIJDialog(Frame owner, boolean modal) throws HeadlessException {
        this(owner, null, modal);
    }
 
    public VCIJDialog(Frame owner, String title) throws HeadlessException {
        this(owner, title, false);
    }
 
    public VCIJDialog(Dialog owner, boolean modal) throws HeadlessException {
        this(owner, null, modal);
    }
 
    public VCIJDialog(Dialog owner, String title) throws HeadlessException {
        this(owner, title, false);
    }
 
    public VCIJDialog(Frame owner, String title, boolean modal)
            throws HeadlessException {
        this(owner, title, modal, null);
    }
 
    public VCIJDialog(Dialog owner, String title, boolean modal)
            throws HeadlessException {
        this(owner, title, modal, null);
    }
 
    public VCIJDialog(Frame owner, String title, boolean modal,
            GraphicsConfiguration gc) {
        super(owner, title, modal, gc);
        customConstructor();
    }
 
    public VCIJDialog(Dialog owner, String title, boolean modal,
            GraphicsConfiguration gc) throws HeadlessException {
        super(owner, title, modal, gc);
        customConstructor();
    }
 
    private void customConstructor(){
        setFont(VCISwingUtil.FONT_DEFAULT);
    }
 
    public DialogResult getDialogResult() {
        return dialogResult;
    }
 
    public void setDialogResult(DialogResult dialogResult) {
        this.dialogResult = dialogResult;
    }
    private Object obj =  null;
    public Object getObj() {
        return obj;
    }
    public void setObj(Object obj) {
        this.obj = obj;
    }
    
    private Runnable dialogCallback = new Runnable(){public void run(){}};
    public Runnable getDialogCallback() {
        return dialogCallback;
    }
    public void setDialogCallback(Runnable dialogCallback) {
        this.dialogCallback = dialogCallback;
    }
    
    /**
     * 根据子对话框的大小,绘制子对话框的位置
     * @param width,对话框宽度
     * @param height,对话框长度
     */
    public void initDialogSize(int width, int height) {
        int px = (int)(this.getParent().getLocationOnScreen().getX());
        int py = (int)(this.getParent().getLocationOnScreen().getY());
        this.setSize(new Dimension(width, height));
        int pWidth = this.getParent().getBounds().width;
        int pHeight = this.getParent().getBounds().height;
        this.setLocation(px + (pWidth - width) / 2, py + (pHeight - height) / 2);
    }
    
    /**
     * 根据边距信息确定子对话框的位置
     * @param x, 距离父对话框左侧的边距值 
     * @param y, 距离父对话框上边的边距值
     */
    public void initDialogSizeByMargin(int x, int y) {
        int px = (int)(this.getParent().getLocationOnScreen().getX());
        int py = (int)(this.getParent().getLocationOnScreen().getY());
        int pWidth = this.getParent().getBounds().width;
        int pHeight = this.getParent().getBounds().height;
        int width = pWidth - 2 * x;
        int height = pHeight - 2 * y;
        this.setSize(new Dimension(width, height));
        this.setLocation(px + x, py + y);
    }
    
    /**
     * 自定义dialog的宽高和位置
     * @param width 
     * @param height 
     */
    public void setSizeAndLocation(int width, int height) {
        if(width > 0 && height > 0){            
            super.setSize(width, height);
            this.setLocationRelativeTo(null);//设置居中
        }
    }
}