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