~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to javax/swing/plaf/metal/MetalSplitPaneDivider.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
package javax.swing.plaf.metal;
39
39
 
40
40
import java.awt.Color;
 
41
import java.awt.Component;
 
42
import java.awt.Container;
41
43
import java.awt.Dimension;
42
44
import java.awt.Graphics;
 
45
import java.awt.Insets;
 
46
import java.awt.LayoutManager;
 
47
import java.awt.Point;
43
48
 
 
49
import javax.swing.JSplitPane;
 
50
import javax.swing.SwingConstants;
 
51
import javax.swing.border.Border;
 
52
import javax.swing.plaf.basic.BasicArrowButton;
44
53
import javax.swing.plaf.basic.BasicSplitPaneDivider;
45
54
 
46
55
/**
56
65
 
57
66
  /** The light color in the pattern. */
58
67
  Color light;
 
68
  
 
69
  /** The JSplitPane the divider is on. */
 
70
  JSplitPane splitPane;
59
71
 
 
72
  /** The split pane orientation. */
 
73
  int orientation;
 
74
  
60
75
  /**
61
76
   * Creates a new instance of MetalSplitPaneDivider.
62
77
   *
65
80
  public MetalSplitPaneDivider(MetalSplitPaneUI ui, Color light, Color dark)
66
81
  {
67
82
    super(ui);
 
83
    setLayout(new MetalDividerLayout());
 
84
    this.splitPane = super.splitPane;
 
85
    this.orientation = super.orientation;
68
86
    this.light = light;
69
87
    this.dark = dark;
70
88
  }
76
94
   */
77
95
  public void paint(Graphics g)
78
96
  {
79
 
    //super.paint(g);
80
97
    Dimension s = getSize();
 
98
 
 
99
    // Paint border if one exists.
 
100
    Border border = getBorder();
 
101
    if (border != null)
 
102
      border.paintBorder(this, g, 0, 0, s.width, s.height);
 
103
 
81
104
    MetalUtils.fillMetalPattern(splitPane, g, 2, 2, s.width - 4, s.height - 4,
82
105
                                light, dark);
 
106
    if (splitPane.isOneTouchExpandable())
 
107
      {
 
108
        ((BasicArrowButton) rightButton).paint(g);
 
109
        ((BasicArrowButton) leftButton).paint(g);
 
110
      }
 
111
  }
 
112
  
 
113
  /**
 
114
   * This helper class acts as the Layout Manager for the divider.
 
115
   */
 
116
  public class MetalDividerLayout implements LayoutManager
 
117
  {
 
118
    /** The right button. */
 
119
    BasicArrowButton rb;
 
120
    
 
121
    /** The left button. */
 
122
    BasicArrowButton lb;
 
123
    
 
124
    /**
 
125
     * Creates a new DividerLayout object.
 
126
     */
 
127
    public MetalDividerLayout()
 
128
    {
 
129
      // Nothing to do here
 
130
    }
 
131
 
 
132
    /**
 
133
     * This method is called when a Component is added.
 
134
     *
 
135
     * @param string The constraints string.
 
136
     * @param c The Component to add.
 
137
     */
 
138
    public void addLayoutComponent(String string, Component c)
 
139
    {
 
140
      // Nothing to do here, constraints are set depending on
 
141
      // orientation in layoutContainer
 
142
    }
 
143
    
 
144
    /**
 
145
     * This method is called to lay out the container.
 
146
     *
 
147
     * @param c The container to lay out.
 
148
     */
 
149
    public void layoutContainer(Container c)
 
150
    {
 
151
      // The only components we care about setting up are the
 
152
      // one touch buttons.
 
153
      if (splitPane.isOneTouchExpandable())
 
154
        {
 
155
          if (c.getComponentCount() == 2)
 
156
            {
 
157
              Component c1 = c.getComponent(0);
 
158
              Component c2 = c.getComponent(1);
 
159
              if ((c1 instanceof BasicArrowButton)
 
160
                  && (c2 instanceof BasicArrowButton))
 
161
                {
 
162
                  lb = ((BasicArrowButton) c1);
 
163
                  rb = ((BasicArrowButton) c2);
 
164
                }
 
165
            }
 
166
          if (rb != null && lb != null)
 
167
            {
 
168
              Point p = getLocation();
 
169
              lb.setSize(lb.getPreferredSize());
 
170
              rb.setSize(rb.getPreferredSize());
 
171
              lb.setLocation(p.x, p.y);
 
172
              
 
173
              if (orientation == JSplitPane.HORIZONTAL_SPLIT)
 
174
                {
 
175
                  rb.setDirection(SwingConstants.EAST);
 
176
                  lb.setDirection(SwingConstants.WEST);
 
177
                  rb.setLocation(p.x, p.y + lb.getHeight());
 
178
                }
 
179
              else
 
180
                {
 
181
                  rb.setDirection(SwingConstants.SOUTH);
 
182
                  lb.setDirection(SwingConstants.NORTH);
 
183
                  rb.setLocation(p.x + lb.getWidth(), p.y);
 
184
                }
 
185
            }
 
186
        }
 
187
    }
 
188
 
 
189
    /**
 
190
     * This method returns the minimum layout size.
 
191
     *
 
192
     * @param c The container to calculate for.
 
193
     *
 
194
     * @return The minimum layout size.
 
195
     */
 
196
    public Dimension minimumLayoutSize(Container c)
 
197
    {
 
198
      return preferredLayoutSize(c);
 
199
    }
 
200
 
 
201
    /**
 
202
     * This method returns the preferred layout size.
 
203
     *
 
204
     * @param c The container to calculate for.
 
205
     *
 
206
     * @return The preferred layout size.
 
207
     */
 
208
    public Dimension preferredLayoutSize(Container c)
 
209
    {
 
210
      int dividerSize = getDividerSize();
 
211
      return new Dimension(dividerSize, dividerSize);
 
212
    }
 
213
 
 
214
    /**
 
215
     * This method is called when a component is removed.
 
216
     *
 
217
     * @param c The component to remove.
 
218
     */
 
219
    public void removeLayoutComponent(Component c)
 
220
    {
 
221
      // Nothing to do here. If buttons are removed
 
222
      // they will not be layed out when layoutContainer is 
 
223
      // called.
 
224
    }
83
225
  }
84
226
}