Ticket #2326 (closed feature: obsolete)

Opened 9 years ago

Last modified 8 years ago

APPEREANCE-BACKGROUND-SUB-HUD

Reported by: dido Owned by: stefan
Priority: major Milestone: X3
Component: ui_consistency Version: 2.0
Keywords: Cc:
Category: END_PROD Effort:
Importance: 75 Ticket_group:
Estimated Number of Hours: 0 Add Hours to Ticket: 0
Billable?: yes Total Hours: 0
Analysis_owners: dido Design_owners: stefan
Imp._owners: stefan Test_owners:
Analysis_reviewers: pap Changelog: Changelog
Design_reviewers: todor, meddle, pap Imp._reviewers: deyan, pap
Test_reviewers: Analysis_score: 3
Design_score: 3.5 Imp._score: 3
Test_score: 0

Description (last modified by stefan) (diff)

Overview
The goal is to create easy way to manipulate page/frame background properties via sub hud.

Task requirements

  • For type combo box (defines the type of the background "none", "solid", "gradient", "image")
  • Remove pattern option
  • This combo box controls the appearance of color chooser, gradient chooser and image chooser (defined on the state). Leave color chooser and gradient chooser as they are. In case of selecting image leave the control that appear the same, but instead of opening file chooser, let it open sub hud.
  • Add sub hud for the background inside appearance hud. Add the following items inside it:
  • Resource chooser - combo box that contain default selected item "none", second item "<browse...>" (open file chooser when selected), and list of available appropriate resources that are linked or embed inside the current book. (same as book properties resource chooser)
  • Image style combo box - combo box that controls the way the image paint itself. Values are the following:

o Stretch - the default one. Stretches the image in order to fit and fill the entire frame content.
o [OPTIONAL] "Center" - image placed with no scale in the center of the frame. NOTE: Cutting could occur. NOTE: there is no actual reason to remove offsets(see below) for this, so it actually may not be centered, better name needed here.
o Tile - tiles the image.

  • [OPTIONAL] Scale label - label that indicates the controls beneath him
  • [OPTIONAL] Scale text input - Allows the user to scale the image. Only active if the "Stretch" style is not selected, else it's disabled. The default value is 100(%).
  • [OPTIONAL] Rotation label - label that indicates the controls beneath him
    • [OPTIONAL] Rotation text field - controls the angle of rotation (min value -360 and max value 360)
    • [OPTIONAL] Rotation point controller - nine check boxes ordered in square.
    • [OPTIONAL] Offset label - label that indicates the controls beneath him
    • [OPTIONAL] Offset controller - two text fields that define the offset of the background, one for x and one for y with labels in front of them (same as the one for frame position ).

Change History

comment:1 Changed 9 years ago by dido

  • Type changed from bug to feature

comment:2 Changed 9 years ago by dido

  • Owner set to dido
  • Status changed from new to s1a_analysis_started

comment:3 Changed 9 years ago by dido

  • Description modified (diff)

comment:4 Changed 9 years ago by dido

  • Description modified (diff)

comment:5 Changed 9 years ago by dido

  • Description modified (diff)

comment:6 Changed 9 years ago by pap

  • Description modified (diff)

comment:7 Changed 9 years ago by pap

  • Status changed from s1a_analysis_started to s1b_analysis_finished
  • Done with analysis

comment:8 Changed 9 years ago by pap

  • Status changed from s1b_analysis_finished to s1c_analysis_ok
  • Analysis_reviewers set to pap
  • Analysis_score changed from 0 to 3
  • Accepted but
    • The tickets are no more in all capital letters
    • This should be about image/pattern bacground. The way it is called is misleading.
    • Too much optional things ... maybe some of the ideas should be written somewhere else because when this ticket is implemented they will almost be lost.

comment:9 Changed 9 years ago by deyan

  • Component changed from SOPHIE_END_PRODUCT to ui_consistency
  • Milestone set to X3

Batch update from file query.csv

comment:10 Changed 9 years ago by stefan

  • Design_owners set to stefan
  • Owner changed from dido to stefan
  • Status changed from s1c_analysis_ok to s2a_design_started
  • Changelog set to [wiki:Changelog]

comment:11 Changed 9 years ago by deyan

  • Description modified (diff)

Batch update from file active_tickets.csv

comment:12 Changed 9 years ago by stefan

  • Status changed from s2a_design_started to s2b_design_finished
  • Imp._owners set to stefan
  • Description modified (diff)

Working branch for this ticket is pap/image_hud.
All the obligatory requirements are fulfilled and following optional ones:

  • Scale label - label that indicates the controls beneath him
  • Scale text input - Allows the user to scale the image. Only active if the "Stretch" style is not selected, else it's disabled. The default value is 100(%).
  • Offset label - label that indicates the controls beneath him
  • Offset controller - two text fields that define the offset of the background, one for x and one for y with labels in front of them (same as the one for frame position ).

The list of the files that are changed and the changes itself in order to provide the required functionality for this task are as follows:

  • ImagePicketHud (org.sophie2.main.app.halos.huds.appearance) - This class is added to be used instead of the file dialog that used to be when choosing image file/resource type as background. Same time BackgroundImageField and BackgroundPatternField are removed, because their functionality is provided by ImagePicketHud (and few other functionalities).
    • ImagePickerHud.ImageHudTitleBar - the tittle bar for the hud.
    • ImagePickerHud.ImageChooser - an extension of ResourceChooser class that is used for importing image files. Important (needed) methods when extending ResourceChooser:
      @Override
      protected ResourceH getParentResource() {
      	BookView parent = AppViewUtil.getCurrentBookView(this);
      	if (parent != null && parent.model().get() != null) {
      		return parent.model().get();
      	}
      	return null;
      }
      @Override
      public ResourceH getSelectedResource() {
      	StyledElementH styler = AppearanceHud.getStyleHelper(this);
      	AppearanceHud hud = BaseVisualElement.findParentElement(this, AppearanceHud.class);
      			
      	if (styler == null || hud == null) {
      		return null;
      	}
      	
      	ResourceRefR4 imageRef = styler.getBackgroundImageRef();
      	if (imageRef == null || ResourceRefR4.NONE_REF.equals(imageRef)) {
      		return getEmptyItem();
      	}
      	
      	ResourceAccess selectedAccess = hud.access().get().open(imageRef, null);
      	return ResourceH.getHelper(selectedAccess, ImageResourceH.class);
      }
      
      • ImagePickerHud.ImageChooser.ImageChooserLogic - ON_IMAGE_SUBMIT handles the submits of new or chosen existing image from the ImageChooser.
    • ImagePickerHud.ImagePatternChooser - a ComboBox that is used for choosing between the kinds of the patterns (at the moment only TILED and STRETCHED are available).
    • ImagePickerHud.OffsetTitleBar - tittle for the offset control.
    • ImagePickerHud.ImageOffsetXField - a BoundTextField used to get desired offser of the X (horizontal) axis. (bounds of the vaules are [-1500, +1500] - they are desided in FrameH.MIN_POSIOTION and FrameH.MAX_POSIOTION). This field is only available if the PatternType is not STRECHED.
    • ImagePickerHud.ImageOffsetYField - a BoundTextField used to get desired offser of the Y (vertical) axis. (bounds of the vaules are [-1500, +1500] - they are desided in FrameH.MIN_POSIOTION and FrameH.MAX_POSIOTION). This field is only available if the PatternType is not STRECHED.
    • ImagePickerHud.ScaleTitleBar - title bar for the scaling control.
    • ImagePickerHud.ImageScaleField - a BoundTextFieldused to get desired scale of the image that is used as a background (default value 100%, available range 0-100%). This field is only available if the PatternType is not STRECHED.
    • ImagePickerHud.ImageBackgroundChooserLogic - defining of the operations for handling the pattern type change, offset change or scale change. They contain simple logic - using AutoAction to change the adequate key:
      • ON_IMAGE_PATTERN_SUBMIT - pattern submit.
      • ON_IMAGE_SIZE_SUBMIT - scale submit.
      • ON_IMAGE_X_LOCATION_SUBMIT - change horizontal offset.
      • ON_IMAGE_Y_LOCATION_SUBMIT - change vertical offset.
  • ImmPattern(org.sophie2.base.commons.util) - This class has minor changes in the logic that computes the background itself. changes are:
    public void fill(Graphics2D g2d, Shape shape) {
    	if (this.options.getType() == PatternType.TILED ) {
    		g2d.setPaint(getPaint());
    		g2d.fill(shape);
    	} else if (this.options.getType() == PatternType.STRETCHED ) {
    		Rectangle rec = shape.getBounds();
    		g2d.drawImage(this.pattern.toBufferedImage(), rec.x, rec.y, rec.width,
    		rec.height, null);
    	} else {
    		throw new IllegalStateException("Unknown pattern type");
    	}
    }
    
    private TexturePaint getPaint() {
    	if (this.paint == null ) {
    	Dimension dim = new Dimension((int) (this.pattern.getWidth() * getOptions().getSize()),
                             (int) (this.pattern.getHeight() * getOptions().getSize()));
    	getOptions().getSize());
    	this.paint = new TexturePaint(this.pattern.toBufferedImage(),
                             new Rectangle(getOptions().getOffset().toPoint(), dim));
            }		
    	return this.paint;
    }
    
    • ImmPatern.PatternOptions - only filed size/scale field is added to provide scalability of the image (as demonstrated in the code above).
  • BackgroundType (org.sophie2.base.model.book)- there is nothing added here, but PATTERN option is deleted.
  • PatternTypePersister - simple enum persister for PatternType.
  • PatternOptionsPersister - persister for PatternOptions. It uses PatternTypePersister.
  • PatternOptionsPersisterTest - test used for testing the implementation of the PatternOptionsPersister:
    /**
     * Persister for {@link PatternOptions} values.
     * @author stefan
     *
     */
    public class PatternOptionsPersister extends RefToStoragePersister<ImmPattern.PatternOptions> {
    
    	/**
    	 * Default constructor for the persister.
    	 * 
    	 * @throws NullPointerException
    	 */
    	public PatternOptionsPersister() throws NullPointerException {
    		super(PatternOptions.class);
    	}
    
    	@Override
    	public void persist(final ValueRef<PatternOptions> source, Storage target, PersistenceOptions options)
    			throws IOException, IncorrectFormatException {
    		
    		ValueRef<PatternType> patternTypeRef = new ValueRef<PatternType>() {
    			@Override
    			public PatternType getInitial() {
    				return source.get().getType();
    			}
    		};
    		
    		MasterPersister.persist(patternTypeRef, target.child("pattern-type"),
    				options, PersistenceUtil.getStorageR3Schema(PatternType.class));
    
    		ValueRef<Float> rotationAngleRef = new ValueRef<Float>() {
    			@Override
    			public Float getInitial() {
    				return source.get().getRotationAngle();
    			}
    		};
    		
    		MasterPersister.persist(rotationAngleRef, target.child("rotation-angle"),
    				options, PersistenceUtil.getStorageR3Schema(Float.class));
    		
    		ValueRef<ImmPoint> offsetRef = new ValueRef<ImmPoint>() {
    			@Override
    			public ImmPoint getInitial() {
    				return source.get().getOffset();
    			}
    		};
    		
    		MasterPersister.persist(offsetRef, target.child("offset"),
    				options, PersistenceUtil.getStorageR3Schema(ImmPoint.class));
    		
    		ValueRef<Float> sizeRef = new ValueRef<Float>() {
    			@Override
    			public Float getInitial() {
    				return source.get().getSize();
    			}
    		};
    		
    		MasterPersister.persist(sizeRef, target.child("size"),
    				options, PersistenceUtil.getStorageR3Schema(Float.class));
    
    		if (options.isLoadMode()) {
    			source.set(new PatternOptions(patternTypeRef.get(), rotationAngleRef.get(), offsetRef.get(), sizeRef.get()));
    		}
    	}
    }
    


Design related code:

comment:13 Changed 9 years ago by pap

  • Status changed from s2b_design_finished to s2c_design_ok
  • Design_score changed from 0 to 3.5
  • Design_reviewers set to todor, meddle, pap
  • You can use AppViewUtil.getCurrentBook in the getParrentResource method. It will save you the some code.
  • Make sure you use all the fields of PatternOptions in getHashCode(), equals() and getHash() methods.
  • It would be better if in the fill method of ImmPattern you use a switch/case statement instead of a series of ifs.
  • Please synhronize your branch with the trunk before implementation as there are important changes to ImmImmage that your code should should be compatible with.
  • In the ImmPattern.getPaint() method make use of ImmImage.exportToAwtImage() method and probably remove the ImmImage.getTexturePaint() method.
  • Probably ImmImage no longer needs to implement the ImmFilling interface as now we have only pattern filling.
  • In the PatternOptionsPersister first fix the JavaDoc. Also don't write ValueRefs this way. Instead of overriding the getInitial method use a if (options.isSaveMode()) {myRef.set(value);} construct as you can see in other persisters.
  • In ResourceChooserLogic.ON_BROWSE_RESOURCES don't log just the object(filter). You should write some meaningful text or not log.
  • Please make sure that you don't leave commented out code.
  • Please return the loglevel setup in FakeAuthorMain.
  • It is better to write "constant.equals(variable)" instead of "variable.equals(constant)" - PatternTypeEnumPersister.
  • UI related fixes that are needed
    • There's no title on the HUD.
    • The HUD is too big, maybe if the titles were Style and Image we could save space.
    • It remove the green tick.
    • Make the scale in the interval [0, 2].

comment:14 Changed 9 years ago by stefan

  • Status changed from s2c_design_ok to s3a_implementation_started

comment:15 Changed 9 years ago by stefan

  • Status changed from s3a_implementation_started to s3b_implementation_finished

implementation code:

comment:16 Changed 9 years ago by pap

  • Status changed from s3b_implementation_finished to s3c_implementation_ok
  • Imp._score changed from 0 to 3
  • Imp._reviewers set to deyan, pap
  • Commited in [8936].
  • PatternTypeEnumPersister is not needed - we have EnumPersister.
  • You didn't make ImmImage not implemenet ImmFilling
  • Malformed JavaDoc - newlines not placed accoring to our standards.
  • Leave some empty lines in order to make the code more readable - ImagePickerHud logics.
  • Why didn't you make a modify method for the patter type in the PatternOptions class.
  • You have inconsistent usage of "size" and "scale".
  • The persistence of the PatternOptions inside StyledElement was not backward compatible.
  • PatternType persistence was not backward compatible.
  • Now pattern images seem somewhat edgy and pixelized.

comment:17 Changed 8 years ago by meddle

  • Status changed from s3c_implementation_ok to closed
  • Resolution set to obsolete

Closing all the tickets before M Y1

Note: See TracTickets for help on using tickets.