| CWScrollPane.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * Copyright: 2007
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: CWScrollPane.java 2050 2010-12-09 15:31:45Z dmsmith $
21 */
22 package org.crosswire.common.swing;
23
24 import java.awt.Component;
25
26 import javax.swing.JScrollBar;
27 import javax.swing.JScrollPane;
28 import javax.swing.ScrollPaneConstants;
29
30 import org.crosswire.common.util.OSType;
31
32 /**
33 * A ScrollPane that give appropriate cross platform behavior. Specifically, on
34 * the Mac the vertical and horizontal scrollbars should always appear. Further,
35 * scroll bars should show proper RTL or LTR component orientation.
36 *
37 * @see gnu.lgpl.License for license details.<br>
38 * The copyright to this program is held by it's authors.
39 * @author DM Smith [dmsmith555 at yahoo dot com]
40 */
41 public class CWScrollPane extends JScrollPane {
42 public CWScrollPane() {
43 this(null);
44 }
45
46 public CWScrollPane(Component view) {
47 super(view, verticalPolicy, horizontalPolicy);
48 GuiUtil.applyDefaultOrientation(this);
49 }
50
51 private static int getXPlatformVerticalScrollBarPolicy() {
52 if (OSType.MAC.equals(OSType.getOSType())) {
53 return ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
54 }
55 return ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
56 }
57
58 private static int getXPlatformHorizontalScrollBarPolicy() {
59 if (OSType.MAC.equals(OSType.getOSType())) {
60 return ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
61 }
62 return ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
63 }
64
65 /*
66 * (non-Javadoc)
67 *
68 * @see javax.swing.JScrollPane#createHorizontalScrollBar()
69 */
70 @Override
71 public JScrollBar createHorizontalScrollBar() {
72 JScrollBar scroller = super.createHorizontalScrollBar();
73 GuiUtil.applyDefaultOrientation(this);
74 return scroller;
75 }
76
77 /*
78 * (non-Javadoc)
79 *
80 * @see javax.swing.JScrollPane#createVerticalScrollBar()
81 */
82 @Override
83 public JScrollBar createVerticalScrollBar() {
84 JScrollBar scroller = super.createVerticalScrollBar();
85 GuiUtil.applyDefaultOrientation(this);
86 return scroller;
87 }
88
89 private static int verticalPolicy = getXPlatformVerticalScrollBarPolicy();
90 private static int horizontalPolicy = getXPlatformHorizontalScrollBarPolicy();
91
92 /**
93 * Serialization ID
94 */
95 private static final long serialVersionUID = -7774104652833574820L;
96 }
97