1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.support;
14
15 import java.awt.Component;
16 import java.awt.Dimension;
17 import java.awt.GraphicsEnvironment;
18 import java.awt.Rectangle;
19
20 import javax.swing.JDialog;
21 import javax.swing.JFrame;
22 import javax.swing.JOptionPane;
23 import javax.swing.JSplitPane;
24
25 /***
26 * Facade for common UI-related tasks
27 *
28 * @author Ole.Matzura
29 */
30
31 public class UISupport
32 {
33 private static JFrame frame;
34
35 public static void setMainFrame( JFrame frame )
36 {
37 UISupport.frame = frame;
38 }
39
40 public static JFrame getMainFrame()
41 {
42 return frame;
43 }
44
45 public static void showErrorMessage(String message)
46 {
47 JOptionPane.showMessageDialog( frame, message, "Error", JOptionPane.ERROR_MESSAGE );
48 }
49
50 public static boolean confirm(String question, String title)
51 {
52 return JOptionPane.showConfirmDialog( frame, question, title, JOptionPane.OK_CANCEL_OPTION ) ==
53 JOptionPane.OK_OPTION;
54 }
55
56 public static String prompt(String question, String title, String value)
57 {
58 return (String) JOptionPane.showInputDialog( frame, question, title, JOptionPane.QUESTION_MESSAGE,
59 null, null, value );
60 }
61
62 public static String prompt(String question, String title)
63 {
64 return JOptionPane.showInputDialog(frame, question, title, JOptionPane.QUESTION_MESSAGE );
65 }
66
67 public static JSplitPane createHorizontalSplit()
68 {
69 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
70 splitPane.setUI( new SoapUISplitPaneUI() );
71 splitPane.setDividerSize( 10 );
72 splitPane.setOneTouchExpandable( true );
73 return splitPane;
74 }
75
76 public static JSplitPane createHorizontalSplit( Component leftComponent, Component rightComponent )
77 {
78 JSplitPane splitPane = createHorizontalSplit();
79
80 splitPane.setLeftComponent( leftComponent );
81 splitPane.setRightComponent( rightComponent );
82 return splitPane;
83 }
84
85 public static JSplitPane createVerticalSplit()
86 {
87 JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
88 splitPane.setUI( new SoapUISplitPaneUI() );
89 splitPane.setDividerSize( 10 );
90 splitPane.setOneTouchExpandable( true );
91 return splitPane;
92 }
93
94 public static JSplitPane createVerticalSplit( Component topComponent, Component bottomComponent )
95 {
96 JSplitPane splitPane = createVerticalSplit();
97
98 splitPane.setLeftComponent( topComponent );
99 splitPane.setRightComponent( bottomComponent );
100 return splitPane;
101 }
102
103 public static void centerDialog(JDialog dialog)
104 {
105 Dimension sz = dialog.getSize();
106 if( dialog.getOwner().isVisible() )
107 {
108 Rectangle b = dialog.getOwner().getBounds();
109 dialog.setLocation( (int) ( ( b.getWidth() - sz.getWidth() ) / 2 ), (int) ( ( b.getHeight() - sz.getHeight() ) / 2 ) );
110 }
111 else
112 {
113 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
114 Rectangle b = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds();
115 dialog.setLocation( (int) ( ( b.getWidth() - sz.getWidth() ) / 2 ), (int) ( ( b.getHeight() - sz.getHeight() ) / 2 ) );
116 }
117 }
118
119 public static void showDialog(JDialog dialog)
120 {
121 centerDialog( dialog );
122 dialog.setVisible( true );
123 }
124 }