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