1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.support;
14
15 import java.awt.Component;
16 import java.awt.Container;
17 import java.awt.Cursor;
18 import java.awt.Dimension;
19 import java.awt.Graphics;
20 import java.awt.LayoutManager;
21
22 import javax.swing.ImageIcon;
23 import javax.swing.JButton;
24 import javax.swing.JComponent;
25 import javax.swing.JSplitPane;
26 import javax.swing.plaf.basic.BasicSplitPaneDivider;
27 import javax.swing.plaf.basic.BasicSplitPaneUI;
28
29 import com.eviware.soapui.SoapUI;
30
31 /***
32 * SplitPaneUI that draws nicer buttons and enables/disables them appropriately
33 *
34 * @author Ole.Matzura
35 */
36
37 public class SoapUISpliPaneUI extends BasicSplitPaneUI
38 {
39 private boolean gradient;
40 private final static ImageIcon upArrow = SoapUI.createImageIcon( "/up_arrow.gif");
41 private final static ImageIcon leftArrow = SoapUI.createImageIcon( "/left_arrow.gif");
42 private final static ImageIcon rightArrow = SoapUI.createImageIcon( "/right_arrow.gif");
43 private final static ImageIcon downArrow = SoapUI.createImageIcon( "/down_arrow.gif");
44
45 public SoapUISpliPaneUI( )
46 {
47 super();
48 }
49
50 public BasicSplitPaneDivider createDefaultDivider()
51 {
52 return new SoapUIDivider( this );
53 }
54
55 private class SoapUIDivider extends BasicSplitPaneDivider
56 {
57 public SoapUIDivider( BasicSplitPaneUI ui )
58 {
59 super( ui );
60
61 setLayout( new SoapUIDividerLayout() );
62 }
63
64 protected JButton createLeftOneTouchButton()
65 {
66 if (getSplitPane().getOrientation() == JSplitPane.VERTICAL_SPLIT)
67 {
68 JButton b = new JButton( upArrow );
69
70 b.setMinimumSize( new Dimension( 8, 6 ) );
71 b.setFocusPainted( false );
72 b.setBorderPainted( false );
73 b.setRequestFocusEnabled( false );
74 b.setBorder( null );
75 b.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
76
77 return b;
78 }
79 else
80 {
81 JButton b = new JButton( leftArrow );
82
83 b.setMinimumSize( new Dimension( 6, 8 ) );
84 b.setFocusPainted( false );
85 b.setBorderPainted( false );
86 b.setRequestFocusEnabled( false );
87 b.setBorder( null );
88 b.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
89
90 return b;
91 }
92 }
93
94 protected JButton createRightOneTouchButton()
95 {
96 if (getSplitPane().getOrientation() == JSplitPane.VERTICAL_SPLIT)
97 {
98 JButton b = new JButton( downArrow );
99
100 b.setMinimumSize( new Dimension( 8, 6 ) );
101 b.setFocusPainted( false );
102 b.setBorderPainted( false );
103 b.setRequestFocusEnabled( false );
104 b.setBorder( null );
105 b.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
106
107 return b;
108 }
109 else
110 {
111 JButton b = new JButton( rightArrow );
112
113 b.setMinimumSize( new Dimension( 6, 8 ) );
114 b.setFocusPainted( false );
115 b.setBorderPainted( false );
116 b.setRequestFocusEnabled( false );
117 b.setBorder( null );
118 b.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
119
120 return b;
121 }
122 }
123
124 protected class SoapUIDividerLayout implements LayoutManager
125 {
126 private int lastOrientation;
127
128 public SoapUIDividerLayout()
129 {
130 lastOrientation = getOrientation();
131 }
132
133 public void layoutContainer( Container c )
134 {
135 int offset = 0;
136
137 if( lastOrientation != getOrientation() )
138 {
139 leftButton.setIcon( getOrientation() == JSplitPane.VERTICAL_SPLIT ? upArrow : leftArrow );
140 leftButton.setMinimumSize( getOrientation() == JSplitPane.VERTICAL_SPLIT ?
141 new Dimension( 8, 6 ) : new Dimension( 6, 8 ));
142
143 rightButton.setIcon( getOrientation() == JSplitPane.VERTICAL_SPLIT ? downArrow : rightArrow );
144 rightButton.setMinimumSize( getOrientation() == JSplitPane.VERTICAL_SPLIT ?
145 new Dimension( 8, 6 ) : new Dimension( 6, 8 ));
146
147 lastOrientation = getOrientation();
148 }
149
150 if (getOrientation() == JSplitPane.VERTICAL_SPLIT)
151 {
152 leftButton.setBounds( 2, 2, 8, 6 );
153 rightButton.setBounds( 12, 2, 8, 6 );
154 }
155 else
156 {
157 leftButton.setBounds( 2, 2, 6, 8 );
158 rightButton.setBounds( 2, 12, 6, 8 );
159 }
160 }
161
162 public Dimension preferredLayoutSize( Container c )
163 {
164 return minimumLayoutSize( c );
165 }
166
167 public void removeLayoutComponent( Component c )
168 {
169 }
170
171 public void addLayoutComponent( String string, Component c )
172 {
173 }
174
175 public Dimension minimumLayoutSize( Container parent )
176 {
177 return new Dimension( 10, 10 );
178 }
179 }
180
181 public JButton getLeftButton()
182 {
183 return leftButton;
184 }
185
186 public JButton getRightButton()
187 {
188 return rightButton;
189 }
190 }
191
192 public void setDividerLocation(JSplitPane jc, int location)
193 {
194 super.setDividerLocation(jc, location);
195 enableOneTouchButtons(jc, location);
196 }
197
198 public void update(Graphics g, JComponent c)
199 {
200 super.update(g, c);
201 enableOneTouchButtons( getSplitPane(), getSplitPane().getDividerLocation());
202 }
203
204 private void enableOneTouchButtons(JSplitPane jc, int location)
205 {
206 JButton leftButton = ((SoapUIDivider)getDivider()).getLeftButton();
207 JButton rightButton = ((SoapUIDivider)getDivider()).getRightButton();
208
209 if( leftButton != null )
210 leftButton.setEnabled( location > jc.getMinimumDividerLocation() && jc.getRightComponent().isVisible());
211
212 if( rightButton != null )
213 rightButton.setEnabled( location < jc.getMaximumDividerLocation() && jc.getLeftComponent().isVisible());
214 }
215 }