View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.support;
14  
15  import java.awt.BorderLayout;
16  import java.awt.Color;
17  import java.awt.Component;
18  import java.awt.Cursor;
19  import java.awt.Dimension;
20  import java.awt.Event;
21  import java.awt.Frame;
22  import java.awt.GraphicsEnvironment;
23  import java.awt.Point;
24  import java.awt.Rectangle;
25  import java.awt.Toolkit;
26  import java.awt.Window;
27  import java.awt.event.ActionEvent;
28  import java.awt.event.KeyEvent;
29  import java.io.File;
30  import java.net.URL;
31  import java.util.ArrayList;
32  import java.util.HashMap;
33  import java.util.List;
34  import java.util.Map;
35  
36  import javax.swing.AbstractAction;
37  import javax.swing.Action;
38  import javax.swing.BorderFactory;
39  import javax.swing.ImageIcon;
40  import javax.swing.JButton;
41  import javax.swing.JComponent;
42  import javax.swing.JDialog;
43  import javax.swing.JFrame;
44  import javax.swing.JPanel;
45  import javax.swing.JPopupMenu;
46  import javax.swing.JProgressBar;
47  import javax.swing.JRootPane;
48  import javax.swing.JScrollPane;
49  import javax.swing.JSplitPane;
50  import javax.swing.JTabbedPane;
51  import javax.swing.JTable;
52  import javax.swing.KeyStroke;
53  import javax.swing.ScrollPaneConstants;
54  import javax.swing.UIManager;
55  import javax.swing.border.Border;
56  import javax.swing.table.TableCellEditor;
57  import javax.swing.table.TableColumn;
58  
59  import com.eviware.soapui.SoapUI;
60  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ToolHost;
61  import com.eviware.soapui.model.ModelItem;
62  import com.eviware.soapui.support.action.swing.ActionList;
63  import com.eviware.soapui.support.components.ConfigurationDialog;
64  import com.eviware.soapui.support.components.JButtonBar;
65  import com.eviware.soapui.support.components.JXToolBar;
66  import com.eviware.soapui.support.components.PreviewCorner;
67  import com.eviware.soapui.support.components.SwingConfigurationDialogImpl;
68  import com.eviware.soapui.support.swing.GradientPanel;
69  import com.eviware.soapui.support.swing.SoapUISplitPaneUI;
70  import com.eviware.soapui.support.swing.SwingUtils;
71  import com.eviware.soapui.ui.desktop.DesktopPanel;
72  import com.eviware.soapui.ui.desktop.SoapUIDesktop;
73  import com.eviware.x.dialogs.XDialogs;
74  import com.eviware.x.dialogs.XFileDialogs;
75  import com.eviware.x.impl.swing.SwingDialogs;
76  import com.eviware.x.impl.swing.SwingFileDialogs;
77  import com.jgoodies.looks.HeaderStyle;
78  import com.jgoodies.looks.Options;
79  
80  /***
81   * Facade for common UI-related tasks
82   * 
83   * @author Ole.Matzura
84   */
85  
86  public class UISupport
87  {
88  	public static final String TOOL_ICON_PATH = "/applications-system.png";
89  	public static final String OPTIONS_ICON_PATH = "/preferences-system.png";
90  
91  	// This is needed in Eclipse that has strict class loader constraints.
92  	private static List<ClassLoader> secondaryResourceLoaders = new ArrayList<ClassLoader>();
93  
94  	private static Component frame;
95  	private static Map<String, ImageIcon> iconCache = new HashMap<String, ImageIcon>();
96  	public static Dimension TOOLBAR_BUTTON_DIMENSION = new Dimension( 22, 21 );
97  	private static Boolean isWindows;
98  
99  	private static XDialogs dialogs;
100 	private static XFileDialogs fileDialogs;
101 	private static UIUtils uiUtils;
102 	private static ToolHost toolHost;
103 	private static Cursor hourglassCursor;
104 	private static Cursor defaultCursor;
105 
106 	static
107 	{
108 		setDialogs( new ConsoleDialogs() );
109 		uiUtils = new SwingUtils();
110 	}
111 
112 	public static ImageIcon TOOL_ICON = UISupport.createImageIcon( TOOL_ICON_PATH );
113 	public static ImageIcon OPTIONS_ICON = UISupport.createImageIcon( OPTIONS_ICON_PATH );
114 	public static ImageIcon HELP_ICON = UISupport.createImageIcon( "/help-browser.png" );
115 
116 	/***
117 	 * Add a classloader to find resources.
118 	 * 
119 	 * @param loader
120 	 */
121 	public static void addClassLoader( ClassLoader loader )
122 	{
123 		secondaryResourceLoaders.add( loader );
124 	}
125 
126 	/***
127 	 * Set the main frame of this application. This is only used when running
128 	 * under Swing.
129 	 * 
130 	 * @param frame
131 	 */
132 	public static void setMainFrame( Component frame )
133 	{
134 		UISupport.frame = frame;
135 		setDialogs( new SwingDialogs( frame ) );
136 		setFileDialogs( new SwingFileDialogs( frame ) );
137 	}
138 
139 	public static void setDialogs( XDialogs xDialogs )
140 	{
141 		dialogs = xDialogs;
142 	}
143 
144 	public static void setFileDialogs( XFileDialogs xFileDialogs )
145 	{
146 		fileDialogs = xFileDialogs;
147 	}
148 
149 	public static ToolHost getToolHost()
150 	{
151 		return toolHost;
152 	}
153 
154 	public static void setToolHost( ToolHost host )
155 	{
156 		toolHost = host;
157 	}
158 
159 	public static Frame getMainFrame()
160 	{
161 		return ( Frame ) ( frame instanceof Frame ? frame : null );
162 	}
163 
164 	public static XDialogs getDialogs()
165 	{
166 		return dialogs;
167 	}
168 
169 	public static XFileDialogs getFileDialogs()
170 	{
171 		return fileDialogs;
172 	}
173 
174 	/***
175 	 * @deprecated use XForm related classes instead
176 	 */
177 
178 	@Deprecated
179 	public static ConfigurationDialog createConfigurationDialog( String name, String helpUrl, String description,
180 				ImageIcon icon )
181 	{
182 		return new SwingConfigurationDialogImpl( name, helpUrl, description, icon );
183 	}
184 
185 	/***
186 	 * @deprecated use XForm related classes instead
187 	 */
188 
189 	@Deprecated
190 	public static ConfigurationDialog createConfigurationDialog( String name, String helpUrl )
191 	{
192 		return new SwingConfigurationDialogImpl( name, helpUrl, null, null );
193 	}
194 
195 	/***
196 	 * @deprecated use XForm related classes instead
197 	 */
198 
199 	@Deprecated
200 	public static ConfigurationDialog createConfigurationDialog( String name )
201 	{
202 		return new SwingConfigurationDialogImpl( name, null, null, null );
203 	}
204 
205 	public static void showErrorMessage( String message )
206 	{
207 		if( message.length() > 120 )
208 		{
209 			dialogs.showExtendedInfo( "Error", "An error occurred", message, null );
210 		}
211 		else
212 		{
213 			dialogs.showErrorMessage( message );
214 		}
215 	}
216 
217 	public static boolean confirm( String question, String title )
218 	{
219 		return dialogs.confirm( question, title );
220 	}
221 
222 	public static String prompt( String question, String title, String value )
223 	{
224 		return dialogs.prompt( question, title, value );
225 	}
226 
227 	/***
228 	 * @deprecated use prompt(String question, String title, String value)
229 	 *             instead
230 	 */
231 
232 	@Deprecated
233 	public static String prompt( String question, String title )
234 	{
235 		return dialogs.prompt( question, title );
236 	}
237 
238 	public static boolean stopCellEditing( JTable table )
239 	{
240 		try
241 		{
242 			int column = table.getEditingColumn();
243 			if( column > -1 )
244 			{
245 				TableCellEditor cellEditor = table.getColumnModel().getColumn( column ).getCellEditor();
246 				if( cellEditor == null )
247 				{
248 					cellEditor = table.getDefaultEditor( table.getColumnClass( column ) );
249 				}
250 				if( cellEditor != null )
251 				{
252 					cellEditor.stopCellEditing();
253 				}
254 			}
255 		}
256 		catch( RuntimeException e )
257 		{
258 			return false;
259 		}
260 		return true;
261 	}
262 
263 	public static JPanel createProgressBarPanel( JProgressBar progressBar, int space, boolean indeterimate )
264 	{
265 		JPanel panel = new JPanel( new BorderLayout() );
266 
267 		progressBar.setValue( 0 );
268 		progressBar.setStringPainted( true );
269 		progressBar.setString( "" );
270 		progressBar.setIndeterminate( indeterimate );
271 
272 		progressBar.setBorder( BorderFactory.createMatteBorder( 0, 0, 1, 1, Color.LIGHT_GRAY ) );
273 
274 		panel.setBorder( BorderFactory.createEmptyBorder( space, space, space, space ) );
275 		panel.add( progressBar, BorderLayout.CENTER );
276 
277 		return panel;
278 	}
279 
280 	public static JSplitPane createHorizontalSplit()
281 	{
282 		JSplitPane splitPane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT );
283 		splitPane.setUI( new SoapUISplitPaneUI() );
284 		splitPane.setDividerSize( 10 );
285 		splitPane.setOneTouchExpandable( true );
286 		return splitPane;
287 	}
288 
289 	public static JSplitPane createHorizontalSplit( Component leftComponent, Component rightComponent )
290 	{
291 		JSplitPane splitPane = createHorizontalSplit();
292 
293 		splitPane.setLeftComponent( leftComponent );
294 		splitPane.setRightComponent( rightComponent );
295 		return splitPane;
296 	}
297 
298 	public static JSplitPane createVerticalSplit()
299 	{
300 		JSplitPane splitPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT );
301 		splitPane.setUI( new SoapUISplitPaneUI() );
302 		splitPane.setDividerSize( 10 );
303 		splitPane.setOneTouchExpandable( true );
304 		splitPane.setBorder( null );
305 		return splitPane;
306 	}
307 
308 	public static JSplitPane createVerticalSplit( Component topComponent, Component bottomComponent )
309 	{
310 		JSplitPane splitPane = createVerticalSplit();
311 
312 		splitPane.setLeftComponent( topComponent );
313 		splitPane.setRightComponent( bottomComponent );
314 		return splitPane;
315 	}
316 
317 	public static void centerDialog( Window dialog )
318 	{
319 		centerDialog( dialog, dialog.getOwner() );
320 	}
321 
322 	public static void centerDialog( Window dialog, Window owner )
323 	{
324 		Dimension sz = dialog.getSize();
325 		Rectangle b = frame == null ? null : frame.getBounds();
326 
327 		if( owner.isVisible() )
328 		{
329 			b = owner.getBounds();
330 		}
331 		else if( b == null )
332 		{
333 			GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
334 			b = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds();
335 		}
336 
337 		dialog.setLocation( ( int ) ( ( b.getWidth() - sz.getWidth() ) / 2 ) + ( int ) b.getX(), ( int ) ( ( b
338 					.getHeight() - sz.getHeight() ) / 2 )
339 					+ ( int ) b.getY() );
340 	}
341 
342 	public static void showDialog( JDialog dialog )
343 	{
344 		centerDialog( dialog );
345 		dialog.setVisible( true );
346 	}
347 
348 	public static ImageIcon createImageIcon( String path )
349 	{
350 		if( iconCache.containsKey( path ) )
351 			return iconCache.get( path );
352 
353 		java.net.URL imgURL = null;
354 
355 		try
356 		{
357 			imgURL = SoapUI.class.getResource( path );
358 
359 			if( imgURL == null && path.endsWith( ".gif" ) )
360 			{
361 				imgURL = SoapUI.class.getResource( path.substring( 0, path.length() - 4 ) + ".png" );
362 			}
363 
364 			if( imgURL == null )
365 			{
366 				imgURL = loadFromSecondaryLoader( path );
367 			}
368 		}
369 		catch( Throwable t )
370 		{
371 			System.err.println( "Failed to create icon: " + t );
372 			return null;
373 		}
374 
375 		if( imgURL != null )
376 		{
377 			try
378 			{
379 				ImageIcon imageIcon = new ImageIcon( imgURL );
380 				iconCache.put( path, imageIcon );
381 				return imageIcon;
382 			}
383 			catch( Throwable e )
384 			{
385 				System.err.println( "Failed to create icon: " + e );
386 				return null;
387 			}
388 		}
389 		else
390 		{
391 			System.err.println( "Couldn't find icon file: " + path );
392 			return null;
393 		}
394 	}
395 
396 	private static URL loadFromSecondaryLoader( String path )
397 	{
398 		for( ClassLoader loader : secondaryResourceLoaders )
399 		{
400 			URL url = loader.getResource( path );
401 			if( url != null )
402 			{
403 				return url;
404 			}
405 		}
406 		return null;
407 	}
408 
409 	public static void showInfoMessage( String message )
410 	{
411 		dialogs.showInfoMessage( message );
412 	}
413 
414 	public static void showInfoMessage( String message, String title )
415 	{
416 		dialogs.showInfoMessage( message, title );
417 	}
418 
419 	@SuppressWarnings( "unchecked" )
420 	public static <T extends Object> T prompt( String question, String title, T[] objects )
421 	{
422 		return ( T ) dialogs.prompt( question, title, objects );
423 	}
424 
425 	@SuppressWarnings( "unchecked" )
426 	public static <T extends Object> T prompt( String question, String title, T[] objects, String value )
427 	{
428 		return ( T ) dialogs.prompt( question, title, objects, value );
429 	}
430 
431 	public static JButton createToolbarButton( Action action )
432 	{
433 		JButton result = new JButton( action );
434 		result.setPreferredSize( TOOLBAR_BUTTON_DIMENSION );
435 		result.setText( "" );
436 		return result;
437 	}
438 
439 	public static JButton createToolbarButton( Action action, boolean enabled )
440 	{
441 		JButton result = createToolbarButton( action );
442 		result.setEnabled( enabled );
443 		return result;
444 	}
445 
446 	public static JPanel createTabPanel( JTabbedPane tabs, boolean addBorder )
447 	{
448 		GradientPanel panel = new GradientPanel( new BorderLayout() );
449 
450 		Color color = UIManager.getDefaults().getColor( "Panel.background" );
451 		Color darker = color.darker();
452 		panel.setForeground( new Color( ( color.getRed() + darker.getRed() ) / 2,
453 					( color.getGreen() + darker.getGreen() ) / 2, ( color.getBlue() + darker.getBlue() ) / 2 ) );
454 
455 		if( tabs.getTabPlacement() == JTabbedPane.LEFT || tabs.getTabPlacement() == JTabbedPane.RIGHT )
456 			panel.setDirection( GradientPanel.VERTICAL );
457 
458 		panel.add( tabs, BorderLayout.CENTER );
459 
460 		if( addBorder )
461 		{
462 			if( tabs.getTabPlacement() == JTabbedPane.TOP )
463 				panel.setBorder( BorderFactory.createMatteBorder( 1, 1, 0, 0, Color.GRAY ) );
464 			else
465 				panel.setBorder( BorderFactory.createMatteBorder( 0, 1, 0, 0, Color.GRAY ) );
466 		}
467 
468 		tabs.setBorder( null );
469 
470 		return panel;
471 	}
472 
473 	public static void showPopup( JPopupMenu popup, JComponent invoker, Point p )
474 	{
475 		popup.setInvoker( invoker );
476 
477 		popup.setLocation( ( int ) ( invoker.getLocationOnScreen().getX() + p.getX() ), ( int ) ( invoker
478 					.getLocationOnScreen().getY() + p.getY() ) );
479 		popup.setVisible( true );
480 	}
481 
482 	public static DesktopPanel selectAndShow( ModelItem modelItem )
483 	{
484 		UISupport.select( modelItem );
485 		return showDesktopPanel( modelItem );
486 	}
487 
488 	public static DesktopPanel showDesktopPanel( ModelItem modelItem )
489 	{
490 		if( modelItem == null )
491 			return null;
492 
493 		try
494 		{
495 			UISupport.setHourglassCursor();
496 			SoapUIDesktop desktop = SoapUI.getDesktop();
497 			return desktop == null ? null : desktop.showDesktopPanel( modelItem );
498 		}
499 		finally
500 		{
501 			UISupport.resetCursor();
502 		}
503 	}
504 
505 	public static DesktopPanel showDesktopPanel( DesktopPanel desktopPanel )
506 	{
507 		try
508 		{
509 			UISupport.setHourglassCursor();
510 			SoapUIDesktop desktop = SoapUI.getDesktop();
511 			return desktop == null ? null : desktop.showDesktopPanel( desktopPanel );
512 		}
513 		finally
514 		{
515 			UISupport.resetCursor();
516 		}
517 	}
518 
519 	public static Boolean confirmOrCancel( String question, String title )
520 	{
521 		return dialogs.confirmOrCancel( question, title );
522 	}
523 
524 	public static JPanel buildPanelWithToolbar( JComponent top, JComponent content )
525 	{
526 		JPanel p = new JPanel( new BorderLayout() );
527 		p.add( top, BorderLayout.NORTH );
528 		p.add( content, BorderLayout.CENTER );
529 
530 		return p;
531 	}
532 
533 	public static JPanel buildPanelWithToolbarAndStatusBar( JComponent top, JComponent content, JComponent bottom )
534 	{
535 		JPanel p = new JPanel( new BorderLayout() );
536 		p.add( top, BorderLayout.NORTH );
537 		p.add( content, BorderLayout.CENTER );
538 		p.add( bottom, BorderLayout.SOUTH );
539 
540 		return p;
541 	}
542 
543 	public static Dimension getPreferredButtonSize()
544 	{
545 		return TOOLBAR_BUTTON_DIMENSION;
546 	}
547 
548 	public static void showErrorMessage( Throwable ex )
549 	{
550 		SoapUI.logError( ex );
551 
552 		if( ex.toString().length() > 100 )
553 		{
554 			dialogs.showExtendedInfo( "Error", "An error of type " + ex.getClass().getSimpleName() + " occured.", ex
555 						.toString(), null );
556 		}
557 		else
558 		{
559 			dialogs.showErrorMessage( ex.toString() );
560 		}
561 	}
562 
563 	public static Component wrapInEmptyPanel( JComponent component, Border border )
564 	{
565 		JPanel panel = new JPanel( new BorderLayout() );
566 		panel.add( component, BorderLayout.CENTER );
567 		panel.setBorder( border );
568 
569 		return panel;
570 	}
571 
572 	public static boolean isWindows()
573 	{
574 		if( isWindows == null )
575 			isWindows = new Boolean( System.getProperty( "os.name" ).indexOf( "Windows" ) >= 0 );
576 
577 		return isWindows.booleanValue();
578 	}
579 
580 	public static void setHourglassCursor()
581 	{
582 		if( frame == null )
583 			return;
584 
585 		if( hourglassCursor == null )
586 			hourglassCursor = new Cursor( Cursor.WAIT_CURSOR );
587 
588 		frame.setCursor( hourglassCursor );
589 	}
590 
591 	public static void resetCursor()
592 	{
593 		if( frame == null )
594 			return;
595 
596 		if( defaultCursor == null )
597 			defaultCursor = new Cursor( Cursor.DEFAULT_CURSOR );
598 
599 		frame.setCursor( defaultCursor );
600 	}
601 
602 	public static void setUIUtils( UIUtils utils )
603 	{
604 		UISupport.uiUtils = utils;
605 	}
606 
607 	public static void invokeLater( Runnable runnable )
608 	{
609 		uiUtils.invokeLater( runnable );
610 	}
611 
612 	public static void invokeAndWait( Runnable runnable ) throws Exception
613 	{
614 		uiUtils.invokeAndWait( runnable );
615 	}
616 
617 	public static JXToolBar createToolbar()
618 	{
619 		JXToolBar toolbar = new JXToolBar();
620 		toolbar.addSpace( 1 );
621 		toolbar.setRollover( true );
622 		toolbar.putClientProperty( Options.HEADER_STYLE_KEY, HeaderStyle.SINGLE );
623 		toolbar.setBorder( BorderFactory.createEmptyBorder( 3, 0, 3, 0 ) );
624 		return toolbar;
625 	}
626 
627 	public static JXToolBar createSmallToolbar()
628 	{
629 		JXToolBar toolbar = new JXToolBar();
630 		toolbar.addSpace( 1 );
631 		toolbar.setRollover( true );
632 		toolbar.putClientProperty( Options.HEADER_STYLE_KEY, HeaderStyle.SINGLE );
633 		toolbar.setBorder( BorderFactory.createEmptyBorder( 2, 2, 2, 2 ) );
634 		return toolbar;
635 	}
636 
637 	/***
638 	 * Replaces "menu" in the keyStroke with ctrl or meta depending on
639 	 * getMenuShortcutKeyMask
640 	 */
641 
642 	public static KeyStroke getKeyStroke( String keyStroke )
643 	{
644 		try
645 		{
646 			if( Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() == Event.META_MASK )
647 			{
648 				keyStroke = keyStroke.replaceAll( "menu", "meta" );
649 			}
650 			else
651 			{
652 				keyStroke = keyStroke.replaceAll( "menu", "ctrl" );
653 			}
654 		}
655 		catch( Throwable e )
656 		{
657 			keyStroke = keyStroke.replaceAll( "menu", "ctrl" );
658 		}
659 
660 		return KeyStroke.getKeyStroke( keyStroke );
661 	}
662 
663 	public static DescriptionPanel buildDescription( String title, String string, ImageIcon icon )
664 	{
665 		return new DescriptionPanel( title, string, icon );
666 	}
667 
668 	public static void setPreferredHeight( Component component, int heigth )
669 	{
670 		component.setPreferredSize( new Dimension( ( int ) component.getPreferredSize().getWidth(), heigth ) );
671 	}
672 
673 	public static JButtonBar initDialogActions( ActionList actions, final JDialog dialog )
674 	{
675 		return initWindowActions( actions, dialog.getRootPane(), dialog );
676 	}
677 	
678 	public static JButtonBar initFrameActions( ActionList actions, final JFrame frame )
679 	{
680 		return initWindowActions( actions, frame.getRootPane(), frame );
681 	}
682 	
683 	private static JButtonBar initWindowActions( ActionList actions, JRootPane rootPane, final Window dialog )
684 	{
685 		rootPane.getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ).put(
686 					KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "ESCAPE" );
687 		rootPane.getActionMap().put( "ESCAPE", new AbstractAction()
688 		{
689 			public void actionPerformed( ActionEvent e )
690 			{
691 				dialog.setVisible( false );
692 			}
693 		} );
694 
695 		if( actions != null )
696 		{
697 			JButtonBar buttons = new JButtonBar();
698 			buttons.addActions( actions );
699 			rootPane.setDefaultButton( buttons.getDefaultButton() );
700 
701 			for( int c = 0; c < actions.getActionCount(); c++ )
702 			{
703 				Action action = actions.getActionAt( c );
704 				if( action instanceof HelpActionMarker )
705 				{
706 					rootPane.getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ).put(
707 								KeyStroke.getKeyStroke( KeyEvent.VK_F1, 0 ), "HELP" );
708 					rootPane.getActionMap().put( "HELP", action );
709 					break;
710 				}
711 			}
712 
713 			return buttons;
714 		}
715 
716 		return null;
717 	}
718 
719 	public static void initDialogActions( final JDialog dialog, Action helpAction, JButton defaultButton )
720 	{
721 		dialog.getRootPane().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ).put(
722 					KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "ESCAPE" );
723 		dialog.getRootPane().getActionMap().put( "ESCAPE", new AbstractAction()
724 		{
725 			public void actionPerformed( ActionEvent e )
726 			{
727 				dialog.setVisible( false );
728 			}
729 		} );
730 
731 		if( defaultButton != null )
732 			dialog.getRootPane().setDefaultButton( defaultButton );
733 
734 		if( helpAction != null )
735 		{
736 			dialog.getRootPane().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ).put(
737 						KeyStroke.getKeyStroke( KeyEvent.VK_F1, 0 ), "HELP" );
738 			dialog.getRootPane().getActionMap().put( "HELP", helpAction );
739 		}
740 	}
741 
742 	public static <T extends JComponent> T addTitledBorder( T component, String title )
743 	{
744 		component.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder( 3, 0, 0, 0 ),
745 					BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder( BorderFactory.createEmptyBorder(),
746 								title ), component.getBorder() ) ) );
747 
748 		return component;
749 	}
750 
751 	public static void beep()
752 	{
753 		Toolkit.getDefaultToolkit().beep();
754 	}
755 
756 	@SuppressWarnings( "unchecked" )
757 	public static <T extends Object> T prompt( String question, String title, List<T> objects )
758 	{
759 		return ( T ) dialogs.prompt( question, title, objects.toArray() );
760 	}
761 
762 	@SuppressWarnings( "unchecked" )
763 	public static <T extends Object> T prompt( String question, String title, List<T> objects, String value )
764 	{
765 		return ( T ) dialogs.prompt( question, title, objects.toArray(), value );
766 	}
767 
768 	public static void showExtendedInfo( String title, String description, String content, Dimension size )
769 	{
770 		dialogs.showExtendedInfo( title, description, content, size );
771 	}
772 
773 	public static boolean confirmExtendedInfo( String title, String description, String content, Dimension size )
774 	{
775 		return dialogs.confirmExtendedInfo( title, description, content, size );
776 	}
777 
778 	public static Boolean confirmOrCancelExtendedInfo( String title, String description, String content, Dimension size )
779 	{
780 		return dialogs.confirmOrCancleExtendedInfo( title, description, content, size );
781 	}
782 
783 	public static void select( ModelItem modelItem )
784 	{
785 		if( SoapUI.getNavigator() != null )
786 			SoapUI.getNavigator().selectModelItem( modelItem );
787 	}
788 
789 	public static JButton createActionButton( Action action, boolean enabled )
790 	{
791 		JButton button = createToolbarButton( action, enabled );
792 		action.putValue( Action.NAME, null );
793 		return button;
794 	}
795 
796 	public static URL findSplash( String filename )
797 	{
798 		File file = new File( filename );
799 		URL url = null;
800 
801 		try
802 		{
803 			if( !file.exists() )
804 				url = SoapUI.class.getResource( "/" + filename );
805 			else
806 				url = file.toURI().toURL();
807 		}
808 		catch( Exception e1 )
809 		{
810 		}
811 
812 		try
813 		{
814 			if( url == null )
815 				url = new URL( "http://www.soapui.org/images/" + filename );
816 		}
817 		catch( Exception e2 )
818 		{
819 			SoapUI.logError( e2 );
820 		}
821 
822 		return url;
823 	}
824 
825 	public static String selectXPath( String title, String info, String xml, String xpath )
826 	{
827 		return dialogs.selectXPath( title, info, xml, xpath );
828 	}
829 
830 	public static PreviewCorner addPreviewCorner( JScrollPane scrollPane, boolean forceScrollbars )
831 	{
832 		ImageIcon previewIcon = UISupport.createImageIcon( "/previewscroller.gif" );
833 		PreviewCorner previewCorner = new PreviewCorner( scrollPane, previewIcon, true, JScrollPane.LOWER_RIGHT_CORNER );
834 		scrollPane.setCorner( JScrollPane.LOWER_RIGHT_CORNER, previewCorner );
835 
836 		if( forceScrollbars )
837 		{
838 			scrollPane.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS );
839 			scrollPane.setVerticalScrollBarPolicy( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );
840 		}
841 
842 		return previewCorner;
843 	}
844 
845 	public static <T extends JComponent> T setFixedSize( T component, Dimension size )
846 	{
847 		component.setMinimumSize( size );
848 		component.setMaximumSize( size );
849 		component.setPreferredSize( size );
850 		component.setSize( size );
851 
852 		return component;
853 	}
854 
855 	public static <T extends JComponent> T setFixedSize( T component, int i, int j )
856 	{
857 		return setFixedSize( component, new Dimension( i, j ) );
858 	}
859 
860 	public static void setFixedColumnSize( TableColumn column, int width )
861 	{
862 		column.setWidth( width );
863 		column.setPreferredWidth( width );
864 		column.setMaxWidth( width );
865 		column.setMinWidth( width );
866 	}
867 
868 	public static JButton createToolbarButton( ImageIcon icon )
869 	{
870 		JButton result = new JButton( icon );
871 		result.setPreferredSize( TOOLBAR_BUTTON_DIMENSION );
872 		return result;
873 	}
874 }