Invalidating and updating in draw2d

Source: Internet
Author: User

This article comes from the building a database schema dimo-editor with GEF and draw2d plug-in developer guide, which describes some basic concepts in draw2d.

Layoutmanager)

    • The layout manager uses figure # setbounds () to change the position and size of the Child image.
    • Based on LayoutAlgorithmAnd the child image determine the preferredsize of the current image.
    • The layout process is to first determine the image size, and then calculate the new position and size of each sub-image.

Figure # invalidate ()

    • If the valid attribute is already false, return directly.
    • If the graph has layoutmanager, call layoutmanager's invalidate () method. In xylayout, the function is to reset preferredsize to null, and set minimumsize to null in flowlayout.
    • Set the valid attribute of the image to false.

Figure # revalidate ()

    • I think it actually represents "recursive invalidate. The function of this method is to first convert the graph into invalidate (), and then recursively convert the parent graph of the graph into invalidate () until the root graph ends, the root image is added to a list of updatemanager instances.
    • In many figure methods, such as setborder (), setcontstraint (), setlayoutmanager (), add (), and remove (), the revalidate () method is automatically called. Therefore, in most cases, we do not need to manually call this method.

Figure # validate ()

    • If the valid attribute is already true, return directly.
    • Set the valid attribute of the image to true.
    • If the graph has a layoutmanager, call the layout () method of layoutmanager.
    • Call the validate () method for each subgraph.

Figure # repaint ()

    • In the updatemanager of the image, mark the area of the image as "dirty" and this area will be repainted by updatemanager (regular.
    • The repaint () method is automatically called in the setvisible (), setopaque (), setforegroundcolor (), setbounds (), setbackgroundcolor (), and other methods of the image.

Figure # Paint ()

    • Although the name is similar, this method has little to do with repaint. In figure, this method calls paintfigure (), paintclientarea (), and paintborder () in sequence. When you implement your own figure, in most cases, only paintfigure () should be overwritten () instead of Painting () itself.

Figure # getpreferredsize ()

    • For a graph like a label, its preferredsize is determined by the space occupied by the text and icons it displays. If a graph contains a child image, its preferredsize should consider the arrangement of child images, therefore, it is up to layoutmanager.
    • The getpreferredsize () method of layoutmanager has two parameters: whint and hhint, which respectively represent the known length (width) degrees of the image. If one of the values is greater than zero, in the other direction, the Child graph will arrange the line breaks (columns) to ensure that the length (width) is not greater than the known value.

Basically, validate is the size adjustment, while repaint () is the color adjustment. When we drag a graph C as a subgraph to another Graph P (imagine p as a UML class rectangle, C as a class or a method rectangle ), because the add () method of P is called, all "ancestor" Images of P and P are set to invalid through revalidate. Updatemanager then performs validate () on these images in performupdate (). During the validate () process, each image recalculates its size through its own layoutmanager. In this way, the size of P is automatically changed with the number of sub-graphs.

The invalidate () method of fig4 is automatically called when the subgraph is changed in the left graph. As a result, the invalidate () method of all images between the root graph is triggered. In the right figure, updatemanager performs validate () on these invalid graphs, and runs from top to bottom (The Validate () method is almost considered to be a call to the layout () method ). Note that due to layout () of fig2, the size of fig5 may also change. If this happens, the invalidate () method of fig5 will also be called.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.