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

« back to all changes in this revision

Viewing changes to javax/swing/plaf/basic/BasicSplitPaneUI.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
 
39
39
package javax.swing.plaf.basic;
40
40
 
 
41
import gnu.classpath.NotImplementedException;
 
42
 
41
43
import java.awt.Canvas;
42
44
import java.awt.Color;
43
45
import java.awt.Component;
62
64
import javax.swing.UIManager;
63
65
import javax.swing.plaf.ComponentUI;
64
66
import javax.swing.plaf.SplitPaneUI;
 
67
import javax.swing.plaf.UIResource;
65
68
 
66
69
/**
67
70
 * This is the Basic Look and Feel implementation of the SplitPaneUI  class.
100
103
    protected int[] sizes = new int[3];
101
104
 
102
105
    /**
 
106
     * Creates a new instance. This is package private because the reference
 
107
     * implementation has no public constructor either. Still, we need to
 
108
     * call it from BasicVerticalLayoutManager.
 
109
     */
 
110
    BasicHorizontalLayoutManager()
 
111
    {
 
112
      // Nothing to do here.
 
113
    }
 
114
 
 
115
    /**
103
116
     * This method adds the component given to the JSplitPane. The position of
104
117
     * the component is given by the constraints object.
105
118
     *
126
139
    {
127
140
      int i = 0;
128
141
      if (place == null)
129
 
        i = 2;
 
142
        i = 2;
130
143
      else if (place.equals(JSplitPane.TOP) || place.equals(JSplitPane.LEFT))
131
 
        i = 0;
 
144
        i = 0;
132
145
      else if (place.equals(JSplitPane.BOTTOM)
133
146
               || place.equals(JSplitPane.RIGHT))
134
 
        i = 1;
 
147
        i = 1;
135
148
      else
136
 
        throw new IllegalArgumentException("Illegal placement in JSplitPane");
 
149
        throw new IllegalArgumentException("Illegal placement in JSplitPane");
137
150
      components[i] = component;
138
151
      resetSizeAt(i);
139
152
      splitPane.revalidate();
164
177
    protected int getInitialLocation(Insets insets)
165
178
    {
166
179
      if (insets != null)
167
 
        return insets.left;
 
180
        return insets.left;
168
181
      return 0;
169
182
    }
170
183
 
205
218
    {
206
219
      Dimension dims = c.getPreferredSize();
207
220
      if (dims != null)
208
 
        return dims.width;
 
221
        return dims.width;
209
222
      return 0;
210
223
    }
211
224
 
250
263
    {
251
264
      if (container instanceof JSplitPane)
252
265
        {
253
 
          JSplitPane split = (JSplitPane) container;
254
 
          distributeExtraSpace();
255
 
          Insets insets = split.getInsets();
256
 
          int width = getInitialLocation(insets);
257
 
          Dimension dims = split.getSize();
258
 
          for (int i = 0; i < components.length; i += 2)
259
 
            {
260
 
              if (components[i] == null)
261
 
                continue;
262
 
              setComponentToSize(components[i], sizes[i], width, insets, dims);
263
 
              width += sizes[i];
264
 
            }
265
 
          if (components[1] != null)
266
 
            {
267
 
              setComponentToSize(components[1], sizes[1], width, insets, dims);
268
 
              width += sizes[1];
269
 
            }
 
266
          JSplitPane split = (JSplitPane) container;
 
267
          distributeExtraSpace();
 
268
          Insets insets = split.getInsets();
 
269
          Dimension dims = split.getSize();
 
270
          int loc = getInitialLocation(insets);
 
271
          int available = getAvailableSize(dims, insets);
 
272
          sizes[0] = getDividerLocation(split) - loc;
 
273
          sizes[1] = available - sizes[0] - sizes[2];
 
274
          // The size of the divider won't change.
 
275
 
 
276
          // Layout component#1.
 
277
          setComponentToSize(components[0], sizes[0], loc, insets, dims);
 
278
          // Layout divider.
 
279
          loc += sizes[0];
 
280
          setComponentToSize(components[2], sizes[2], loc, insets, dims);
 
281
          // Layout component#2. 
 
282
          loc += sizes[2];
 
283
          setComponentToSize(components[1], sizes[1], loc, insets, dims);
270
284
        }
271
285
    }
272
286
 
297
311
    {
298
312
      if (target instanceof JSplitPane)
299
313
        {
300
 
          JSplitPane split = (JSplitPane) target;
301
 
          Insets insets = target.getInsets();
 
314
          JSplitPane split = (JSplitPane) target;
 
315
          Insets insets = target.getInsets();
302
316
 
303
 
          int height = 0;
304
 
          int width = 0;
305
 
          for (int i = 0; i < components.length; i++)
306
 
            {
307
 
              if (components[i] == null)
308
 
                continue;
309
 
              Dimension dims = components[i].getMinimumSize();
310
 
              if (dims != null)
311
 
                {
312
 
                  width += dims.width;
313
 
                  height = Math.max(height, dims.height);
314
 
                }
315
 
            }
316
 
          return new Dimension(width, height);
 
317
          int height = 0;
 
318
          int width = 0;
 
319
          for (int i = 0; i < components.length; i++)
 
320
            {
 
321
              if (components[i] == null)
 
322
                continue;
 
323
              Dimension dims = components[i].getMinimumSize();
 
324
              if (dims != null)
 
325
                {
 
326
                  width += dims.width;
 
327
                  height = Math.max(height, dims.height);
 
328
                }
 
329
            }
 
330
          return new Dimension(width, height);
317
331
        }
318
332
      return null;
319
333
    }
331
345
    {
332
346
      if (target instanceof JSplitPane)
333
347
        {
334
 
          JSplitPane split = (JSplitPane) target;
335
 
          Insets insets = target.getInsets();
 
348
          JSplitPane split = (JSplitPane) target;
 
349
          Insets insets = target.getInsets();
336
350
 
337
 
          int height = 0;
338
 
          int width = 0;
339
 
          for (int i = 0; i < components.length; i++)
340
 
            {
341
 
              if (components[i] == null)
342
 
                continue;
343
 
              Dimension dims = components[i].getPreferredSize();
344
 
              if (dims != null)
345
 
                {
346
 
                  width += dims.width;
347
 
                  if (! (components[i] instanceof BasicSplitPaneDivider))
348
 
                    height = Math.max(height, dims.height);
349
 
                }
350
 
            }
351
 
          return new Dimension(width, height);  
 
351
          int height = 0;
 
352
          int width = 0;
 
353
          for (int i = 0; i < components.length; i++)
 
354
            {
 
355
              if (components[i] == null)
 
356
                continue;
 
357
              Dimension dims = components[i].getPreferredSize();
 
358
              if (dims != null)
 
359
                {
 
360
                  width += dims.width;
 
361
                  if (!(components[i] instanceof BasicSplitPaneDivider))
 
362
                    height = Math.max(height, dims.height);
 
363
                }
 
364
            }
 
365
          return new Dimension(width, height);
352
366
        }
353
367
      return null;
354
368
    }
362
376
    {
363
377
      for (int i = 0; i < components.length; i++)
364
378
        {
365
 
          if (component == components[i])
366
 
            {
367
 
              components[i] = null;
368
 
              sizes[i] = 0;
369
 
            }
 
379
          if (component == components[i])
 
380
            {
 
381
              components[i] = null;
 
382
              sizes[i] = 0;
 
383
            }
370
384
        }
371
385
    }
372
386
 
378
392
    protected void resetSizeAt(int index)
379
393
    {
380
394
      if (components[index] != null)
381
 
        sizes[index] = getPreferredSizeOfComponent(components[index]);
 
395
        sizes[index] = getPreferredSizeOfComponent(components[index]);
382
396
    }
383
397
 
384
398
    /**
387
401
    public void resetToPreferredSizes()
388
402
    {
389
403
      for (int i = 0; i < components.length; i++)
390
 
        resetSizeAt(i);
 
404
        resetSizeAt(i);
 
405
      setDividerLocation(splitPane,
 
406
                         getInitialLocation(splitPane.getInsets()) + sizes[0]);
391
407
    }
392
408
 
393
409
    /**
433
449
 
434
450
      if (left != null)
435
451
        {
436
 
          components[0] = left;
437
 
          resetSizeAt(0);
 
452
          components[0] = left;
 
453
          resetSizeAt(0);
438
454
        }
439
455
      if (right != null)
440
456
        {
441
 
          components[1] = right;
442
 
          resetSizeAt(1);
 
457
          components[1] = right;
 
458
          resetSizeAt(1);
443
459
        }
444
460
      components[2] = divider;
445
461
      resetSizeAt(2);
451
467
     */
452
468
    void distributeExtraSpace()
453
469
    {
454
 
      int availSize = getAvailableSize(splitPane.getSize(),
455
 
                                       splitPane.getInsets());
456
 
      int[] newSizes = new int[3];
457
 
      double weight = splitPane.getResizeWeight();
458
 
 
459
 
      int oldLen = sizes[0] + sizes[1];
460
 
 
461
 
      // dividers don't change size.
462
 
      availSize -= sizes[2] + oldLen;
463
 
 
464
 
      int rightAlloc = (int) (availSize * (1 - weight));
465
 
      int leftAlloc = availSize - rightAlloc;
466
 
 
467
 
      sizes[0] += leftAlloc;
468
 
      sizes[1] += rightAlloc;
 
470
      // FIXME: This needs to be reimplemented correctly.
469
471
    }
470
472
 
471
473
    /**
480
482
    {
481
483
      Dimension dims = components[index].getMinimumSize();
482
484
      if (dims != null)
483
 
        return dims.width;
 
485
        return dims.width;
484
486
      else
485
 
        return 0;
 
487
        return 0;
486
488
    }
487
489
  } //end BasicHorizontalLayoutManager
488
490
 
534
536
    {
535
537
      Dimension dims = c.getPreferredSize();
536
538
      if (dims != null)
537
 
        return dims.height;
 
539
        return dims.height;
538
540
      return 0;
539
541
    }
540
542
 
563
565
    {
564
566
      if (container instanceof JSplitPane)
565
567
        {
566
 
          JSplitPane split = (JSplitPane) container;
567
 
          Insets insets = container.getInsets();
 
568
          JSplitPane split = (JSplitPane) container;
 
569
          Insets insets = container.getInsets();
568
570
 
569
 
          int height = 0;
570
 
          int width = 0;
571
 
          for (int i = 0; i < components.length; i++)
572
 
            {
573
 
              if (components[i] == null)
574
 
                continue;
575
 
              Dimension dims = components[i].getMinimumSize();
576
 
              if (dims != null)
577
 
                {
578
 
                  height += dims.height;
579
 
                  width = Math.max(width, dims.width);
580
 
                }
581
 
            }
582
 
          return new Dimension(width, height);
 
571
          int height = 0;
 
572
          int width = 0;
 
573
          for (int i = 0; i < components.length; i++)
 
574
            {
 
575
              if (components[i] == null)
 
576
                continue;
 
577
              Dimension dims = components[i].getMinimumSize();
 
578
              if (dims != null)
 
579
                {
 
580
                  height += dims.height;
 
581
                  width = Math.max(width, dims.width);
 
582
                }
 
583
            }
 
584
          return new Dimension(width, height);
583
585
        }
584
586
      return null;
585
587
    }
597
599
    {
598
600
      if (container instanceof JSplitPane)
599
601
        {
600
 
          JSplitPane split = (JSplitPane) container;
601
 
          Insets insets = container.getInsets();
 
602
          JSplitPane split = (JSplitPane) container;
 
603
          Insets insets = container.getInsets();
602
604
 
603
 
          int height = 0;
604
 
          int width = 0;
605
 
          for (int i = 0; i < components.length; i++)
606
 
            {
607
 
              if (components[i] == null)
608
 
                continue;
609
 
              Dimension dims = components[i].getPreferredSize();
610
 
              if (dims != null)
611
 
                {
612
 
                  height += dims.height;
613
 
                  width = Math.max(width, dims.width);
614
 
                }
615
 
            }
616
 
          return new Dimension(width, height);
 
605
          int height = 0;
 
606
          int width = 0;
 
607
          for (int i = 0; i < components.length; i++)
 
608
            {
 
609
              if (components[i] == null)
 
610
                continue;
 
611
              Dimension dims = components[i].getPreferredSize();
 
612
              if (dims != null)
 
613
                {
 
614
                  height += dims.height;
 
615
                  width = Math.max(width, dims.width);
 
616
                }
 
617
            }
 
618
          return new Dimension(width, height);
617
619
        }
618
620
      return null;
619
621
    }
652
654
    {
653
655
      Dimension dims = components[index].getMinimumSize();
654
656
      if (dims != null)
655
 
        return dims.height;
 
657
        return dims.height;
656
658
      else
657
 
        return 0;
 
659
        return 0;
658
660
    }
659
661
  }
660
662
 
813
815
    {
814
816
      if (e.getPropertyName().equals(JSplitPane.DIVIDER_SIZE_PROPERTY))
815
817
        {
816
 
          int newSize = splitPane.getDividerSize();
817
 
          int[] tmpSizes = layoutManager.getSizes();
818
 
          dividerSize = tmpSizes[2];
819
 
      int newSpace = newSize - tmpSizes[2];
820
 
          tmpSizes[2] = newSize;
 
818
          int newSize = splitPane.getDividerSize();
 
819
          int[] tmpSizes = layoutManager.getSizes();
 
820
          dividerSize = tmpSizes[2];
 
821
          int newSpace = newSize - tmpSizes[2];
 
822
          tmpSizes[2] = newSize;
821
823
 
822
 
          tmpSizes[0] += newSpace / 2;
823
 
          tmpSizes[1] += newSpace / 2;
 
824
          tmpSizes[0] += newSpace / 2;
 
825
          tmpSizes[1] += newSpace / 2;
824
826
      
825
 
          layoutManager.setSizes(tmpSizes);
 
827
          layoutManager.setSizes(tmpSizes);
826
828
        }
827
829
      else if (e.getPropertyName().equals(JSplitPane.ORIENTATION_PROPERTY))
828
830
        {
829
 
          int max = layoutManager.getAvailableSize(splitPane.getSize(),
830
 
                                                   splitPane.getInsets());
831
 
          int dividerLoc = getDividerLocation(splitPane);
832
 
          double prop = ((double) dividerLoc) / max;
 
831
          int max = layoutManager.getAvailableSize(splitPane.getSize(),
 
832
                                                   splitPane.getInsets());
 
833
          int dividerLoc = getDividerLocation(splitPane);
 
834
          double prop = ((double) dividerLoc) / max;
833
835
 
834
 
          resetLayoutManager();
835
 
          if (prop <= 1 && prop >= 0)
836
 
            splitPane.setDividerLocation(prop);
 
836
          resetLayoutManager();
 
837
          if (prop <= 1 && prop >= 0)
 
838
            splitPane.setDividerLocation(prop);
837
839
        }
838
 
      layoutManager.layoutContainer(splitPane);
839
 
      splitPane.repaint();
840
840
      // Don't have to deal with continuous_layout - only
841
841
      // necessary in dragging modes (and it's checked
842
842
      // every time you drag there)
843
843
      // Don't have to deal with resize_weight (as there
844
844
      // will be no extra space associated with this
845
845
      // event - the changes to the weighting will
846
 
      // be taken into account the next time the 
 
846
      // be taken into account the next time the
847
847
      // sizes change.)
848
 
      // Don't have to deal with divider_location 
 
848
      // Don't have to deal with divider_location
849
849
      // The method in JSplitPane calls our setDividerLocation
850
850
      // so we'll know about those anyway.
851
851
      // Don't have to deal with last_divider_location
852
 
      // Although I'm not sure why, it doesn't seem to 
 
852
      // Although I'm not sure why, it doesn't seem to
853
853
      // have any effect on Sun's JSplitPane.
854
854
      // one_touch_expandable changes are dealt with
855
855
      // by our divider.
933
933
  /** The JSplitPane that this UI draws. */
934
934
  protected JSplitPane splitPane;
935
935
 
 
936
  private int dividerLocation;
 
937
 
936
938
  /**
937
939
   * Creates a new BasicSplitPaneUI object.
938
940
   */
962
964
  {
963
965
    if (c instanceof JSplitPane)
964
966
      {
965
 
        splitPane = (JSplitPane) c;
966
 
        installDefaults();
967
 
        installListeners();
968
 
        installKeyboardActions();
 
967
        splitPane = (JSplitPane) c;
 
968
        installDefaults();
 
969
        installListeners();
 
970
        installKeyboardActions();
969
971
      }
970
972
  }
971
973
 
992
994
                              "SplitPane.foreground");
993
995
    LookAndFeel.installBorder(splitPane, "SplitPane.border");
994
996
    divider = createDefaultDivider();
 
997
    divider.setBorder(UIManager.getBorder("SplitPaneDivider.border"));
995
998
    resetLayoutManager();
996
999
    nonContinuousLayoutDivider = createDefaultNonContinuousLayoutDivider();
997
1000
    splitPane.add(divider, JSplitPane.DIVIDER);
1012
1015
    divider = null;
1013
1016
    nonContinuousLayoutDivider = null;
1014
1017
 
1015
 
    splitPane.setBackground(null);
1016
 
    splitPane.setBorder(null);
 
1018
    if (splitPane.getBackground() instanceof UIResource)
 
1019
      splitPane.setBackground(null);
 
1020
    if (splitPane.getBorder() instanceof UIResource)
 
1021
      splitPane.setBorder(null);
1017
1022
  }
1018
1023
 
1019
1024
  /**
1044
1049
   * This method installs the keyboard actions for the JSplitPane.
1045
1050
   */
1046
1051
  protected void installKeyboardActions()
 
1052
    throws NotImplementedException
1047
1053
  {
1048
1054
    // FIXME: implement.
1049
1055
  }
1052
1058
   * This method reverses the work done in installKeyboardActions.
1053
1059
   */
1054
1060
  protected void uninstallKeyboardActions()
 
1061
    throws NotImplementedException
1055
1062
  {
1056
1063
    // FIXME: implement.
1057
1064
  }
1218
1225
  {
1219
1226
    if (nonContinuousLayoutDivider == null)
1220
1227
      {
1221
 
        nonContinuousLayoutDivider = new Canvas();
1222
 
        nonContinuousLayoutDivider.setBackground(Color.DARK_GRAY);
 
1228
        nonContinuousLayoutDivider = new Canvas();
 
1229
        Color c = UIManager.getColor("SplitPaneDivider.draggingColor");
 
1230
        nonContinuousLayoutDivider.setBackground(c);
1223
1231
      }
1224
1232
    return nonContinuousLayoutDivider;
1225
1233
  }
1298
1306
   */
1299
1307
  public void setDividerLocation(JSplitPane jc, int location)
1300
1308
  {
1301
 
    location = validLocation(location);
1302
 
    Container p = jc.getParent();
1303
 
    Dimension rightPrefSize = jc.getRightComponent().getPreferredSize();
1304
 
    Dimension size = jc.getSize();
1305
 
    // check if the size has been set for the splitpane
1306
 
    if (size.width == 0 && size.height == 0)
1307
 
      size = jc.getPreferredSize();
1308
 
    
1309
 
    if (getOrientation() == 0 && location > size.height)
1310
 
      {
1311
 
        location = size.height;
1312
 
        while (p != null)
1313
 
          {
1314
 
            p.setSize(p.getWidth(), p.getHeight() + rightPrefSize.height);
1315
 
            p = p.getParent();
1316
 
          }
1317
 
      }
1318
 
    else if (location > size.width)
1319
 
      {
1320
 
        location = size.width;
1321
 
        while (p != null)
1322
 
          {
1323
 
            p.setSize(p.getWidth() + rightPrefSize.width, p.getHeight());
1324
 
            p = p.getParent();
1325
 
          }
1326
 
      }
1327
 
    
1328
 
    setLastDragLocation(getDividerLocation(splitPane));
1329
 
    splitPane.setLastDividerLocation(getDividerLocation(splitPane));
1330
 
    int[] tmpSizes = layoutManager.getSizes();
1331
 
    tmpSizes[0] = location 
1332
 
                  - layoutManager.getInitialLocation(splitPane.getInsets());
1333
 
    tmpSizes[1] = layoutManager.getAvailableSize(splitPane.getSize(),
1334
 
                                                 splitPane.getInsets())
1335
 
                  - tmpSizes[0];
1336
 
    layoutManager.setSizes(tmpSizes);
 
1309
    dividerLocation = location;
1337
1310
    splitPane.revalidate();
1338
1311
    splitPane.repaint();
1339
1312
  }
1347
1320
   */
1348
1321
  public int getDividerLocation(JSplitPane jc)
1349
1322
  {
1350
 
    return layoutManager.sizes[0]
1351
 
           + layoutManager.getInitialLocation(splitPane.getInsets());
 
1323
    return dividerLocation;
1352
1324
  }
1353
1325
 
1354
1326
  /**
1361
1333
   */
1362
1334
  public int getMinimumDividerLocation(JSplitPane jc)
1363
1335
  {
1364
 
    int value = layoutManager.getInitialLocation(jc.getInsets())
1365
 
                - layoutManager.getAvailableSize(jc.getSize(), jc.getInsets())
1366
 
                + splitPane.getDividerSize();
1367
 
    if (layoutManager.components[1] != null)
1368
 
      value += layoutManager.minimumSizeOfComponent(1);
 
1336
    int value = layoutManager.getInitialLocation(jc.getInsets());
 
1337
    if (layoutManager.components[0] != null)
 
1338
      value += layoutManager.minimumSizeOfComponent(0);
1369
1339
    return value;
1370
1340
  }
1371
1341
 
1485
1455
   */
1486
1456
  protected void startDragging()
1487
1457
  {
 
1458
    Component left = splitPane.getLeftComponent();
 
1459
    Component right = splitPane.getRightComponent();
1488
1460
    dividerSize = divider.getDividerSize();
1489
1461
    setLastDragLocation(-1);
1490
1462
 
1491
 
    if (! splitPane.getLeftComponent().isLightweight()
1492
 
        || ! splitPane.getRightComponent().isLightweight())
 
1463
    if ((left != null && !left.isLightweight())
 
1464
        || (right != null && !right.isLightweight()))
1493
1465
      draggingHW = true;
1494
1466
 
1495
1467
    if (splitPane.isContinuousLayout())
1496
1468
      nonContinuousLayoutDivider.setVisible(false);
1497
1469
    else
1498
1470
      {
1499
 
        nonContinuousLayoutDivider.setVisible(true);
1500
 
        nonContinuousLayoutDivider.setBounds(divider.getBounds());
 
1471
        nonContinuousLayoutDivider.setVisible(true);
 
1472
        nonContinuousLayoutDivider.setBounds(divider.getBounds());
1501
1473
      }
1502
 
    splitPane.revalidate();
1503
 
    splitPane.repaint();
1504
1474
  }
1505
1475
 
1506
1476
  /**
1520
1490
      splitPane.setDividerLocation(location);
1521
1491
    else
1522
1492
      {
1523
 
        Point p = nonContinuousLayoutDivider.getLocation();
1524
 
        if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
1525
 
          p.x = location;
1526
 
        else
1527
 
          p.y = location;
1528
 
        nonContinuousLayoutDivider.setLocation(p);
 
1493
        Point p = nonContinuousLayoutDivider.getLocation();
 
1494
        if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
 
1495
          p.x = location;
 
1496
        else
 
1497
          p.y = location;
 
1498
        nonContinuousLayoutDivider.setLocation(p);
1529
1499
      }
1530
1500
    setLastDragLocation(location);
1531
1501
    splitPane.repaint();
1542
1512
      nonContinuousLayoutDivider.setVisible(false);
1543
1513
    draggingHW = false;
1544
1514
    location = validLocation(location);
1545
 
    dragDividerTo(location);
1546
1515
    splitPane.setDividerLocation(location);
1547
1516
    splitPane.setLastDividerLocation(beginDragDividerLocation);
1548
1517
    beginDragDividerLocation = -1;
1549
 
    splitPane.repaint();
1550
1518
  }
1551
1519
 
1552
1520
  /**