1 package org.telscenter.pas.ui.dialog;
2
3 import java.awt.Dimension;
4 import java.awt.Toolkit;
5 import java.awt.event.WindowAdapter;
6 import java.awt.event.WindowEvent;
7
8 import javax.swing.Icon;
9 import javax.swing.JDialog;
10 import javax.swing.JFrame;
11 import javax.swing.JPanel;
12 import javax.swing.SwingUtilities;
13
14 import org.xito.dialog.CustomDialog;
15 import org.xito.dialog.DialogDescriptor;
16 import org.xito.dialog.DialogManager;
17
18 public class PasDialogManager {
19
20 public PasDialogManager() {
21 super();
22
23 }
24
25 public static CustomDialog showPasMessageDialog(String title,
26 JPanel contentPanel, JFrame rootFrame) {
27 return PasDialogManager.showPasMessageDialog(title, null, null,
28 contentPanel, rootFrame, false, true, false, 0, 0);
29 }
30
31 public static CustomDialog showPasMessageDialog(String title,
32 JPanel contentPanel, JFrame rootFrame, boolean model) {
33 return PasDialogManager.showPasMessageDialog(title, null, null,
34 contentPanel, rootFrame, false, true, model, 0, 0);
35 }
36
37 public static CustomDialog showPasMessageDialog(String title,
38 JPanel contentPanel, JFrame rootFrame, boolean resizable, boolean model) {
39 return PasDialogManager.showPasMessageDialog(title, null, null,
40 contentPanel, rootFrame, resizable, true, model, 0, 0);
41 }
42
43 public static CustomDialog showPasMessageDialog(String title,
44 JPanel contentPanel, JFrame rootFrame, boolean model, int width,
45 int height) {
46 return PasDialogManager.showPasMessageDialog(title, null, null,
47 contentPanel, rootFrame, false, true, model, width, height);
48 }
49
50 public static CustomDialog showPasMessageDialog(String title,
51 String description, Icon icon, JPanel contentPanel,
52 JFrame rootFrame, boolean model) {
53 return PasDialogManager.showPasMessageDialog(title, description, icon,
54 contentPanel, rootFrame, false, true, model, 0, 0);
55 }
56
57 public static CustomDialog showPasMessageDialog(String title,
58 String description, Icon icon, final JPanel contentPanel,
59 JFrame rootFrame, boolean resizable, boolean defaultClose,
60 boolean modal, int width, int height) {
61
62 DialogDescriptor descriptor = new DialogDescriptor();
63
64 if (description != null) {
65 descriptor.setTitle(title);
66 descriptor.setSubtitle(description);
67 }
68 if (icon != null) {
69 descriptor.setIcon(icon);
70 }
71
72 descriptor.setWindowTitle(title);
73 descriptor.setCustomPanel(contentPanel);
74 descriptor.setShowButtonSeparator(false);
75 descriptor.setType(DialogManager.NONE);
76
77 final CustomDialog cd = new CustomDialog(rootFrame, descriptor, modal);
78 cd.setFocusable(true);
79 cd.setResizable(resizable);
80 if (defaultClose)
81 cd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
82 else
83 cd.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
84
85 cd.addWindowListener(new WindowAdapter() {
86
87 public void windowActivated(WindowEvent e) {
88 cd.toFront();
89 contentPanel.requestFocusInWindow();
90 }
91
92 public void windowClosing(WindowEvent we) {
93 cd.setVisible(false);
94 }
95 });
96
97
98 Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
99 double newHeight;
100 double newWidth;
101
102
103
104
105
106
107
108
109
110
111 if (width != 0 && height != 0) {
112 newWidth = width;
113 newHeight = height;
114 } else {
115 if (contentPanel.getPreferredSize().getHeight() > dim.getHeight()) {
116 newHeight = dim.getHeight() - 75;
117 } else {
118 newHeight = contentPanel.getPreferredSize().getHeight();
119 }
120 if (contentPanel.getPreferredSize().getWidth() > dim.getWidth()) {
121 newWidth = dim.getWidth() - 20;
122 } else {
123 newWidth = contentPanel.getPreferredSize().getWidth();
124 }
125 }
126
127 contentPanel.setPreferredSize(new Dimension((int) newWidth,
128 (int) newHeight));
129
130
131
132
133
134 SwingUtilities.invokeLater(new Runnable(){
135 public void run(){
136 cd.pack();
137 cd.setVisible(true);
138 }
139 });
140
141 return cd;
142 }
143 }