Version 4 (modified by mitex, 16 years ago) (diff) |
---|
Analysis
Overview
- The goal of this task is to remove some code smells from controllers:
- Inconsistent naming in event and handlers.
- Inconsistent location of controllers - some related controllers are in sepaerate files, some are nested in the corresponding view, others - not, etc.
- Menu items have clicked method instead of firing an R3 event. For some items it is trivial to switch to R3 Logic.
- Not all menu items will be refactored.
- Code duplication due to copy-paste.
- No new functionality is going to be added.
Task requirements
- Rename all nested enums that contain event IDs to EventIds.
- In logic enums, names of all items should begin with "ON_", followed by the event ID, where possible.
- For example, the event CLICK can be handled by ON_CLICK.
- Check for inconsistent names - for example, FRAME_REMOVED is not a good name if the frame is removed during the handling of the event. FRAME_REMOVE is a better name.
- In main.app.commons logics should not be in separated subpackage. Instead, move each logic enum to the package with the corresponding views.
- For halo buttons, extract logics and group them by functionality.
- For example, create org.sophie2.main.app.halos.grouping.GroupHalosLogic which handles events from all halo buttons related to grouping.
- Refactor the align buttons: Reuse the code where possible.
- In menu items deprecate the method clicked.
- Create a new event CLICKED that should be fired when a menu item is clicked.
- For all menu items, that just fire R3 event, remove the clicked method and change the filter in the controllers - it should listen for MenuItem.EventIds.CLICKED.
Task result
- Source code
Implementation idea
- Use eclipse's "Open Type Hierarchy" to view all OperationDefs (all R3 controllers), all MenuItems, etc.
Related
How to demo
- The task has no visible result.
Design
- For the align buttons:
- Create two abstract methods in AlignElementsButton:
- float calculateAlignValue(List<ElementView> selected) - for a given list of element views calculates some align value, for example, the Y-axis of the top-most element.
- ImmPoint calculateNewLocation(ImmRect bounds, float alignValue) - calculates a new location for a single element, given the old bounds and the align value, returned from the above method.
- Replace the clicked method in all align buttons with the above methods.
- Create AlignElementsLogic with a single handler - ON_ALIGN, which listens for CLICKED from AlignElementsButton.
- Calculates the align value
- Creates an immutable list of new locations
- Creates an immutable list of references to elements. Only elements of type MemberElement are collected.
- Creates a new AutoAction that iterates over all references and changes MemberElement.KEY_LOCATION with the newly calculated location.
- Create two abstract methods in AlignElementsButton:
Implementation
(Describe and link the implementation results here (from the wiki or the repository).)
Testing
(Place the testing results here.)
Comments
(Write comments for this or later revisions here.)