View Javadoc
1   /*
2    * GUIHelperMethods.java
3    * Copyright (C) 2004  Pal Brattberg <pal@eminds.se>
4    * 
5    * This program is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation; either version 2 of the License, or
8    * (at your option) any later version.
9    * 
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   * 
19   * File created: 2004-nov-13
20   */
21  package se.perfectfools.localizer.gui;
22  
23  import java.awt.Component;
24  import java.awt.Dimension;
25  import java.awt.Frame;
26  
27  import javax.swing.JScrollPane;
28  import javax.swing.UIManager;
29  
30  import com.jgoodies.plaf.FontSizeHints;
31  import com.jgoodies.plaf.LookUtils;
32  import com.jgoodies.plaf.Options;
33  
34  /***
35   * <code>GUIHelperMethods</code>
36   * 
37   * @author P&aring;l Brattberg &lt;<a href="mailto:pal@eminds.se">pal@eminds.se</a>&gt;
38   * @version $Id: GUIHelperMethods.java,v 1.1 2004/11/13 14:44:18 pal Exp $
39   */
40  public class GUIHelperMethods {
41      
42      /***
43       * Creates and returns a <code>JScrollpane</code> that has no border.
44       */
45      public static JScrollPane createStrippedScrollPane(Component c) {
46          JScrollPane scrollPane = new JScrollPane(c);
47          scrollPane.setBorder(null);
48          return scrollPane;
49      }
50      
51      /***
52       * Locates the frame on the screen center.
53       */
54      public static void centerOnScreen(Frame frame) {
55          Dimension paneSize = frame.getSize();
56          Dimension screenSize = frame.getToolkit().getScreenSize();
57          frame.setLocation((screenSize.width - paneSize.width) / 2, (screenSize.height - paneSize.height) / 2);
58      }
59  
60      /***
61       * Configures the UI; tries to set the system look on Mac, <code>ExtWindowsLookAndFeel</code>
62       * on general Windows, and <code>Plastic3DLookAndFeel</code> on Windows XP and all other OS.
63       * <p>
64       * 
65       * The JGoodies Swing Suite's <code>ApplicationStarter</code>,<code>ExtUIManager</code>,
66       * and <code>LookChoiceStrategies</code> classes provide a much more fine grained algorithm to
67       * choose and restore a look and theme.
68       */
69      public static void configureUI() {
70          UIManager.put(Options.USE_SYSTEM_FONTS_APP_KEY, Boolean.TRUE);
71          Options.setGlobalFontSizeHints(FontSizeHints.MIXED);
72          Options.setDefaultIconSize(new Dimension(18, 18));
73  
74          String lafName = LookUtils.IS_OS_WINDOWS_XP ? Options.getSystemLookAndFeelClassName() : Options
75                  .getCrossPlatformLookAndFeelClassName();
76  
77          try {
78              UIManager.setLookAndFeel(lafName);
79          } catch (Exception e) {
80              System.err.println("Can't set look & feel:" + e); //$NON-NLS-1$
81          }
82      }
83  }