Changes between Version 11 and Version 12 of Ticket #2326


Ignore:
Timestamp:
03/17/10 15:28:32 (15 years ago)
Author:
stefan
Comment:

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:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #2326

    • Property Status changed from s2a_design_started to s2b_design_finished
    • Property Imp._owners changed from to stefan