Back to index

wims  3.65+svn20090927
Public Member Functions | Protected Attributes
fr.ove.openmath.jome.ctrlview.bidim.IntegralLayout Class Reference

A layout manager that lays components to place them as an integral. More...

Inheritance diagram for fr.ove.openmath.jome.ctrlview.bidim.IntegralLayout:
Inheritance graph
[legend]
Collaboration diagram for fr.ove.openmath.jome.ctrlview.bidim.IntegralLayout:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void initDisplay (Display displayToLay)
 According to the operator, the layout manager has to add some components (e.g.
void updateLevel (int level)
 Updates the level of the display that is layed out.
void validateSelection ()
 Checks the validity of the selection.
void validateDeselection (Display display)
 Checks the validity of the deselection.
Dimension computeAttributes ()
 Computes the size of the display according to its children size (if any), and its different attributes.
void rebuildDisplay ()
 The display needs to be rebuilt.
void layoutContainer (Container parent)
boolean selectLeftDisplay ()
 Returns true if during the selection, the display which is located to the left of the display that the instance lays, must be selected too.
boolean selectRightDisplay ()
 Returns true if during the selection, the display which is located to the right of the display that the instance lays, must be selected too.
void selectDisplay ()
 Selects the display (and its children if any)
void deselectDisplay ()
 Deselects the display.
void addLayoutComponent (String name, Component comp)
 Adds the specified component with the specified name to the layout.
void addLayoutComponent (Component comp, Object constraints)
 Adds the specified component to the layout, using the specified constraint object.
void removeLayoutComponent (Component comp)
 Removes the specified component from the layout.
Dimension minimumLayoutSize (Container parent)
 Calculates the minimum size dimensions for the specified panel given the components in the specified parent container.
Dimension preferredLayoutSize (Container parent)
 Calculates the preferred size dimensions for the specified panel given the components in the specified parent container.
Dimension maximumLayoutSize (Container target)
 Returns the maximum size of this component.
float getLayoutAlignmentX (Container target)
 Returns the alignment along the x axis.
float getLayoutAlignmentY (Container target)
 Returns the alignment along the y axis.
void invalidateLayout (Container target)
 Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

Protected Attributes

Display displayToLay = null
 The display laid out by the instance.

Detailed Description

A layout manager that lays components to place them as an integral.


The different elements (when complete) are contained in the display in the following order :

Author:
© 1999 DIRAT Laurent
Version:
2.0 16/12/1999

Definition at line 52 of file IntegralLayout.java.


Member Function Documentation

void fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.addLayoutComponent ( String  name,
Component  comp 
) [inline, inherited]

Adds the specified component with the specified name to the layout.

Parameters:
namethe component name
compthe component to be added

Definition at line 189 of file DisplayLayout.java.

                                                                {
    }
void fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.addLayoutComponent ( Component  comp,
Object  constraints 
) [inline, inherited]

Adds the specified component to the layout, using the specified constraint object.

Parameters:
compthe component to be added
constraintswhere/how the component is added to the layout.

Definition at line 236 of file DisplayLayout.java.

                                                                       {
           if (!(constraints instanceof Display))
              throw new IllegalArgumentException("The component to add must be a Display instance !!!");
    }

Computes the size of the display according to its children size (if any), and its different attributes.

Returns:
the size of the display.

Reimplemented from fr.ove.openmath.jome.ctrlview.bidim.HorizontalLayout.

Definition at line 290 of file IntegralLayout.java.

                                         {
        int ascent = 0;
        int descent = 0;

        updateLevel(displayToLay.getLevel());

        int width = 0;
        int height = 0;
        
        SymbolDisplay symbol;
        Display expression, integrand;
        int gap = 4;
        
        int count = displayToLay.getComponentCount();
        if (count > 3) {
            symbol = (SymbolDisplay) displayToLay.getComponent(1);
            expression = (Display) displayToLay.getComponent(2);
            integrand = (Display) displayToLay.getComponent(3);
        }
        else {
            symbol = (SymbolDisplay) displayToLay.getComponent(0);
            expression = (Display) displayToLay.getComponent(1);
            integrand = (Display) displayToLay.getComponent(2);
        }
        
        symbol.setSize(symbol.getPreferredSize());
        expression.setSize(expression.getPreferredSize());
        integrand.setSize(integrand.getPreferredSize());
        
        int width1 = symbol.getWidth();
        width += expression.getWidth() + integrand.getWidth();
        
        ascent = Math.max(expression.getAscent(), symbol.getAscent());
        descent = Math.max(expression.getDescent(), symbol.getDescent());
        
        if (count > 3) {
            Display lower = (Display) displayToLay.getComponent(0);
            lower.setSize(lower.getPreferredSize());
            lower.setShiftY((int) Math.round(symbol.getDescent()*0.2f) + lower.getAscent());
            lower.setShiftX((int) Math.round(symbol.getWidth()*0.55f));
            
            //width1 += lower.getWidth();
            width1 = Math.max(symbol.getWidth(), lower.getShiftX() + lower.getWidth());
            
            descent = Math.max(lower.getShiftY() + lower.getDescent() + gap, descent);
            
            symbol.setShiftX(-lower.getWidth() - lower.getShiftX());
            
            if (count > 4) {
                Display upper = (Display) displayToLay.getComponent(4);
                upper.setSize(upper.getPreferredSize());
                
                width1 = Math.max(width1, symbol.getWidth() + upper.getWidth());
                
                int decalage = width1 - symbol.getWidth();
                upper.setShiftX(-(decalage + width/* - gap*/));
                upper.setShiftY((int) Math.round(-symbol.getAscent()*0.6f) - upper.getDescent());
            
                ascent = Math.max(-upper.getShiftY() + upper.getAscent() + gap, ascent);
            }
        }
        
        expression.setShiftX(width1 - symbol.getWidth() + gap);
                    
        displayToLay.setAscent(ascent);
        displayToLay.setDescent(descent);
        
        width += width1/* + expression.getWidth()*/ + 2*gap;
        
        height += ascent + descent;
        displayToLay.setSize(width , height);
        
        displayToLay.setComputeAttributes(false);
        return new Dimension(width, height);
    }

Here is the call graph for this function:

Deselects the display.

Parameters:
thedisplay to deselect.

Reimplemented in fr.ove.openmath.jome.ctrlview.bidim.OneFormulaLayout.

Definition at line 107 of file DisplayLayout.java.

                                  {
        displayToLay.deselect();

        SelectionEvent selEvt = new SelectionEvent(displayToLay);
        selEvt.setAction(SelectionEvent.REMOVE, displayToLay);
        displayToLay.fireSelectionEvent(selEvt);
        
        if (displayToLay.getParent() instanceof Display) {
            Display display = (Display) displayToLay.getParent();
            ((DisplayLayout) display.getLayout()).validateDeselection(displayToLay);
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

float fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.getLayoutAlignmentX ( Container  target) [inline, inherited]

Returns the alignment along the x axis.

This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

Definition at line 258 of file DisplayLayout.java.

                                                       {
        return 0.0f;
    }
float fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.getLayoutAlignmentY ( Container  target) [inline, inherited]

Returns the alignment along the y axis.

This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

Definition at line 269 of file DisplayLayout.java.

                                                       {
        return 0.0f;
    }

According to the operator, the layout manager has to add some components (e.g.

brackets, ...) or has to perform some "re-oganisation" before rendering.
As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST call super.initDisplay(displayToLay).

Parameters:
displayToLaythe display laid by the instance

Reimplemented from fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.

Definition at line 61 of file IntegralLayout.java.

                                                  {
        super.initDisplay(displayToLay);

        SymbolDisplay integral = new SymbolDisplay(this.displayToLay.getGraphicContext(), 
                                                new ImageSymbol("Integrale", this.displayToLay));
        // Le display de l'intégrale est le display d'un opérateur (on peut le considérer comme tel)
        integral.setIsSymbolOperatorDisplay(true);
        this.displayToLay.add(integral);
        integral.addControlListener((FormulaTreeStructure) this.displayToLay.getListener());
    }

Here is the call graph for this function:

void fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.invalidateLayout ( Container  target) [inline, inherited]

Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

Definition at line 277 of file DisplayLayout.java.

                                                   {
    }
void fr.ove.openmath.jome.ctrlview.bidim.HorizontalLayout.layoutContainer ( Container  parent) [inline, inherited]

Reimplemented in fr.ove.openmath.jome.ctrlview.bidim.RequestLayout.

Definition at line 95 of file HorizontalLayout.java.

                                                   {
        int x, y;
        Display display, previous;
        
        int count = parent.getComponentCount();
        for (int i = 0; i < count; i++) {
            display = (Display) parent.getComponent(i);
            display.setSize(display.getPreferredSize());

            if (i == 0)
                x = display.getShiftX();
            else {
                previous = (Display) parent.getComponent(i-1);
                x = previous.getX() + previous.getWidth() + display.getShiftX();
            }

            y = ((Display) parent).getAscent() - display.getAscent() + display.getShiftY();

            display.setLocation(x, y);

            // On place maintenant les éventuels display enfants du display courant
            display.doLayout();
        }
    }

Here is the call graph for this function:

Dimension fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.maximumLayoutSize ( Container  target) [inline, inherited]

Returns the maximum size of this component.

See also:
java.awt.Component::getMinimumSize()
java.awt.Component::getPreferredSize()
LayoutManager

Definition at line 247 of file DisplayLayout.java.

                                                         {
        return preferredLayoutSize(target);
    }

Here is the call graph for this function:

Dimension fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.minimumLayoutSize ( Container  parent) [inline, inherited]

Calculates the minimum size dimensions for the specified panel given the components in the specified parent container.

Parameters:
parentthe component to be laid out
See also:
preferredLayoutSize

Definition at line 205 of file DisplayLayout.java.

                                                         {
        return preferredLayoutSize(parent);
    }

Here is the call graph for this function:

Dimension fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.preferredLayoutSize ( Container  parent) [inline, inherited]

Calculates the preferred size dimensions for the specified panel given the components in the specified parent container.

Parameters:
parentthe component to be laid out
See also:
minimumLayoutSize

Definition at line 216 of file DisplayLayout.java.

                                                           {
        if (((Display) parent).getComputeAttributes())
            return computeAttributes();
        else
            return parent.getSize();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

The display needs to be rebuilt.

We do this.

Implements fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.

Definition at line 369 of file IntegralLayout.java.

                                 {
        // La taille des displays est probablement différente de ceux qui étaient
        // précédemment. On demande alors le recalcul des display ancêtres.
        displayToLay.computeAncestorsAttributes();
    }

Here is the call graph for this function:

Removes the specified component from the layout.

Parameters:
compthe component ot be removed

Definition at line 196 of file DisplayLayout.java.

                                                      {
    }

Selects the display (and its children if any)

Parameters:
thedisplay to select.

Reimplemented in fr.ove.openmath.jome.ctrlview.bidim.OneFormulaLayout.

Definition at line 85 of file DisplayLayout.java.

                                {
        displayToLay.select();
        
        SelectionEvent selEvt = new SelectionEvent(displayToLay);
        // On purge la liste des éléments sélectionnés.
        selEvt.setAction(SelectionEvent.PURGE, null);
        displayToLay.fireSelectionEvent(selEvt);
        selEvt.setAction(SelectionEvent.ADD, displayToLay);
        displayToLay.fireSelectionEvent(selEvt);
        
        Display display = displayToLay;
        if (displayToLay.getParent() instanceof Display) {
            display = (Display) displayToLay.getParent();
            ((DisplayLayout) display.getLayout()).validateSelection();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns true if during the selection, the display which is located to the left of the display that the instance lays, must be selected too.

false otherwise.

Reimplemented in fr.ove.openmath.jome.ctrlview.bidim.LeftAssocPrefixedUnaryOperatorLayout, and fr.ove.openmath.jome.ctrlview.bidim.StringLayout.

Definition at line 68 of file DisplayLayout.java.

                                       {
        return false;
    }

Here is the caller graph for this function:

Returns true if during the selection, the display which is located to the right of the display that the instance lays, must be selected too.

false otherwise.

Reimplemented in fr.ove.openmath.jome.ctrlview.bidim.StringLayout.

Definition at line 77 of file DisplayLayout.java.

                                        {
        return false;
    }

Here is the caller graph for this function:

Updates the level of the display that is layed out.


Parameters:
levelthe level put to the display

Reimplemented from fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.

Definition at line 76 of file IntegralLayout.java.

                                       {
        Display tmp;
        StringDisplay varIntDisplay;
        VariableOrNumber varInt;
        
        // Pour éviter de refaire le calcul plusieurs fois....
        if (displayToLay.getUpdateLevel()) {
            // On met à jour le niveau du display géré par le LM.
            displayToLay.setLevel(level);
            displayToLay.setUpdateLevel(false);
            
            int i = 0;
            int count = displayToLay.getComponentCount();
            // Si le nombre de composant est au moins 4, alors on a affaire à une intégrale où au moins une
            // borne est spécifiée (la borne inférieure)
            // On fait en sorte qu'elle soit en première position dans display,
            // sinon, à l'affichage, elle va être en partie masquée par le display de l'intégrale.
            if (count > 3) {
                // On regarde si le premier display est celui d'un opérateur (celui de l'intégrale en fait)
                // Si c'est le cas, il faut déplacer le display de la borne inf.
                if (((Display) displayToLay.getComponent(0)).isSymbolOperatorDisplay()) {
                    tmp = (Display) displayToLay.getComponent(3);
                    
                    // De part l'implémentation du add(tmp, tmp, 0), tmp va être enlevé de la liste
                    // des listeners qu'il écoute. Chose qu'on ne veut pas.
                    displayToLay.removeFromListListeners(false);
                    
                    displayToLay.add(tmp, tmp, 0);
                    
                    // On se remet dans la cas classique où la suppression de display entraînera sa suppression
                    // dans la liste des listeners qu'il écoute.
                    displayToLay.removeFromListListeners(true);
                    
                    displayToLay.adjustRank();
                }
                
                // On réduit la taille de la borne inf. de 1
                tmp = (Display) displayToLay.getComponent(0);
                ((DisplayLayout) tmp.getLayout()).updateLevel(level+1);
                tmp.setUpdateLevel(false);
                
                // On incrémente l'indice i, pour que dans la boucle qui suit, on parte bien du display
                // du tick
                i++;
                
                // Le display de la variable d'intégration est en 4-ième position
                tmp = (Display) displayToLay.getComponent(3);
                varIntDisplay = (StringDisplay) tmp.getComponent(0);
                
                if (count > 4) {
                    // C'est la borne supérieure. On réduit sa taille de 1
                    tmp = (Display) displayToLay.getComponent(4);
                    ((DisplayLayout) tmp.getLayout()).updateLevel(level+1);
                    tmp.setUpdateLevel(false);
                    
                    count--;
                }
            }
            else {
                // Le display de la variable d'intégration est en 3-ième position
                tmp = (Display) displayToLay.getComponent(2);
                varIntDisplay = (StringDisplay) tmp.getComponent(0);
            }
            
            // On récupère la fts de la variable d'intégration.
            // Si c'est un template, alors pas besoin de rajouter le d. Sinon, on le rajoute
            varInt = (VariableOrNumber) varIntDisplay.getListener();
            if (!varInt.isTemplate())
                varIntDisplay.setString("d" + varInt.getValue());
            
            // le symbole de l'intégrale, l'intégrande et la variable d'intégration (en fait le d"x")
            // ont le niveau du display qui les contient
            for (; i < count; i++) {
                tmp = (Display) displayToLay.getComponent(i);
                ((DisplayLayout) tmp.getLayout()).updateLevel(level);
                tmp.setUpdateLevel(false);
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Checks the validity of the deselection.

Parameters:
displaythe display to deselect.

Implements fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.

Definition at line 229 of file IntegralLayout.java.

                                                     {
        Display father = displayToLay;
        Display tmp;
        SelectionEvent selEvt = new SelectionEvent(father);
        
        if (father.isSelected()) {
            father.setNotSelected();
            // On enlève le display père de la liste des display sélectionnés.
            selEvt.setAction(SelectionEvent.REMOVE, father);
            father.fireSelectionEvent(selEvt);
            
            int count = father.getComponentCount();
            Display expression;
            
            if (count > 3)
                expression = (Display) father.getComponent(2);
            else
                expression = (Display) father.getComponent(1);
            
            if (display != expression) {
                // quand on désélectionne un élément de l'intégrale, autre que l'expression, l'expression
                // reste sélectionnée.
                selEvt.setAction(SelectionEvent.ADD, expression);
                father.fireSelectionEvent(selEvt);
            }
            
            if (count > 3) {
                ((Display) father.getComponent(0)).deselect();
                ((Display) father.getComponent(1)).setNotSelected();
                ((Display) father.getComponent(3)).deselect();
                if (count > 4) 
                    ((Display) father.getComponent(4)).deselect();
            }
            else {
                ((Display) father.getComponent(0)).setNotSelected();
                ((Display) father.getComponent(2)).deselect();
            }
            
            // Comme pour la sélection, on contrôle la validité de la désélection.
            if (father.getParent() instanceof Display) {
                father = (Display) father.getParent();
                FormulaTreeStructure fts = (FormulaTreeStructure) father.getListener();
                if (fts.getFather() != null)
                    ((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
            }
            // Hé oui, on contrôle la validité de la sélection... dans une désélection.
            // Toujours le même pb, est-ce que le nouvel état de la sélection (après
            // désélection donc) est syntaxiquement cohérent ?
            validateSelection();
            
            // On met à jour l'affichage.
            father.repaint();
        }        

    }

Here is the call graph for this function:

Checks the validity of the selection.

Parameters:
displaythe display to select.

Implements fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout.

Definition at line 160 of file IntegralLayout.java.

                                    {
        int count = displayToLay.getComponentCount();
        Display symbol, expression, varInt;
        
        if (count > 3) {
            symbol = (Display) displayToLay.getComponent(1);
            expression = (Display) displayToLay.getComponent(2);
            varInt = (Display) displayToLay.getComponent(3);
        }
        else {
            symbol = (Display) displayToLay.getComponent(0);
            expression = (Display) displayToLay.getComponent(1);
            varInt = (Display) displayToLay.getComponent(2);
        }
        
        if ((symbol.isSelected()) || (varInt.isSelected()))
            displayToLay.select();
        else if (count > 3) {
            Display lower = (Display) displayToLay.getComponent(0);
            Display upper;
            
            if (lower.gotSelectedElements()) {
                if (expression.gotSelectedElements())
                    displayToLay.select();
                else if (count > 4) {
                    upper = (Display) displayToLay.getComponent(4);
                    if (upper.gotSelectedElements())
                        displayToLay.select();
                }
            }
            else if (count > 4) {
                upper = (Display) displayToLay.getComponent(4);
                if (upper.gotSelectedElements()) {
                    if (expression.gotSelectedElements())
                        displayToLay.select();
                }
            }
        }
            
        // Quand on est ici, si display est sélectionné, alors c'est qu'on a validé un des tests
        // ci-dessus. On doit alors mettre à jour le gestionnaire de sélections, et y ajouter display
        if (displayToLay.isSelected()) {
            SelectionEvent selEvt = new SelectionEvent(displayToLay);
            // On purge la liste des éléments sélectionnés.
            selEvt.setAction(SelectionEvent.PURGE, null);
            displayToLay.fireSelectionEvent(selEvt);
            // On y ajoute notre intégrale.
            selEvt.setAction(SelectionEvent.ADD, displayToLay);
            displayToLay.fireSelectionEvent(selEvt);
        }

        // On a vérifié la validité de la sélection de l'intégrale. On doit maitenant
        // la contrôler au niveau supérieur, au niveau du père.
        Display display = displayToLay;
        if (display.getParent() instanceof Display) {
            display = (Display) display.getParent();
            FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
            if (fts.getFather() != null) // Si fts est la racine de la formule alors la sélection à déjà été validée
                ((DisplayLayout) display.getLayout()).validateSelection();
        }

        // On met à jour l'affichage.
        display.repaint();
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

The display laid out by the instance.

Definition at line 47 of file DisplayLayout.java.


The documentation for this class was generated from the following file: