View Javadoc

1   package fr.ove.openmath.jome.ctrlview.bidim;
2   
3   import java.awt.*;
4   import java.util.*;
5   import fr.ove.openmath.jome.ctrlview.bidim.Display;
6   import fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout;
7   import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
8   import fr.ove.openmath.jome.model.*;
9   
10  /***
11  * A layout manager that lays components horyzontally.
12  *
13  * @author © 1999 DIRAT Laurent
14  * @version 2.0 13/12/1999
15  */
16  public abstract class HorizontalLayout extends DisplayLayout {
17      /***
18      * Computes the size of the display according to its children size (if any),
19      * and its different attributes.
20      * @return the size of the display.
21      */
22      public Dimension computeAttributes() {
23          int ascent = 0;
24          int descent = 0;
25          Display tmp;
26          int width = 0;
27          int height = 0;
28          
29          updateLevel(displayToLay.getLevel());
30  
31          int count = displayToLay.getComponentCount();
32          for (int i = 0; i < count; i++) {
33              tmp = (Display) displayToLay.getComponent(i);
34              tmp.setSize(tmp.getPreferredSize());
35              
36              width += tmp.getWidth() + tmp.getShiftX();
37              
38              ascent = Math.max(tmp.getAscent() - tmp.getShiftY(),
39                                ascent);
40              
41              descent = Math.max(tmp.getDescent() + tmp.getShiftY(),
42                                 descent);
43          }
44  
45          displayToLay.setAscent(Math.max( 0, ascent ));
46          displayToLay.setDescent(Math.max( 0, descent));
47          height += displayToLay.getAscent() + displayToLay.getDescent();
48          displayToLay.setSize(width , height);
49          displayToLay.setComputeAttributes(false);
50  
51          return new Dimension(width, height);
52      }
53  
54  
55      // #################################################
56      // ### ImplÈmentation des diffÈrentes interfaces ###
57      // #################################################
58  
59      // ***************************************************
60      // *** ImplÈmentation de l'interface LayoutManager ***
61  
62  
63      /*
64       * Lays out the container in the specified panel.
65       * @param parent the component which needs to be laid out
66       */
67       public void layoutContainer(Container parent) {
68          int x, y;
69          Display display, previous;
70          
71          int count = parent.getComponentCount();
72          for (int i = 0; i < count; i++) {
73              display = (Display) parent.getComponent(i);
74              display.setSize(display.getPreferredSize());
75  
76              if (i == 0)
77                  x = display.getShiftX();
78              else {
79                  previous = (Display) parent.getComponent(i-1);
80                  x = previous.getX() + previous.getWidth() + display.getShiftX();
81              }
82  
83              y = ((Display) parent).getAscent() - display.getAscent() + display.getShiftY();
84  
85              display.setLocation(x, y);
86  
87              // On place maintenant les Èventuels display enfants du display courant
88              display.doLayout();
89          }
90      }
91  
92      // *** Fin de l'interface LayoutManager ***
93      // ****************************************
94  }