Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of manual move-function via the java-server-api #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.LinkedList;
import java.util.List;

import org.tepi.imageviewer.client.Directions;
import org.tepi.imageviewer.client.ImageViewerServerRpc;
import org.tepi.imageviewer.client.ImageViewerState;

Expand Down Expand Up @@ -62,8 +63,17 @@ public void centerImageSelected(int newCenterImageIndex) {
}
}
}
/**
* rpc call to reset the move direction
*/
@Override
public void moveFinished() {
ImageViewer.this.getState().direction = Directions.NODIRECTION;
}
};



/**
* Default constructor of ImageViewer.
*
Expand All @@ -90,6 +100,15 @@ protected ImageViewerState getState() {
return (ImageViewerState) super.getState();
}

/**
* Trigger a movement of the current image to the left/right. Will trigger the animation, if the animation is enabled.
*
* @param direction The direction the images will scroll.
*/
public void move(Directions direction) {
this.getState().direction = direction;
}

/**
* Returns (an unmodifiable) copy of the list of images currently set to
* this ImageViewer.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.tepi.imageviewer.client;

/**
* possible move directions
*/
public enum Directions {

LEFT, RIGHT, NODIRECTION
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ public void onStateChanged(StateChangeEvent stateChangeEvent) {
if (getWidget().animationRunning) {
return;
}

/*
* If the direction changed then move the images and signal the server the movement finished.
* Skip the rest to prevent the re-rendering of all images.
*/
if (stateChangeEvent.hasPropertyChanged("direction") && !Directions.NODIRECTION.equals(getState().direction)) {
getWidget().move(getState().direction);
this.moveFinished();
return;
}

getWidget().mouseOverEffects = getState().mouseOverEffects;
getWidget().amountOfImages = getState().imageCount;
getWidget().centerImageIndex = getState().centerImageIndex;
Expand Down Expand Up @@ -73,4 +84,11 @@ public void layout() {
public void centerImageSelected(int imageIndex) {
rpc.centerImageSelected(imageIndex);
}

/**
* makes and rpc call to signal that the movement is finished
*/
private void moveFinished() {
rpc.moveFinished();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
public interface ImageViewerServerRpc extends ServerRpc {

public void centerImageSelected(int newCenterImageIndex);

public void moveFinished();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public class ImageViewerState extends TabIndexState {
public boolean mouseOverEffects;
/** Amount of images added to the viewer */
public int imageCount;
/** Move Direction */
public Directions direction = Directions.NODIRECTION;
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,20 @@ void fixSideImageCount() {
}
}

/**
* Moves the current image one step left or right. Animates the movement if animations are enabled.
*
* @param direction -
*/
public void move(Directions direction) {
if (direction.equals(Directions.LEFT)) {
moveImages(true);
}
else {
moveImages(false);
}
}

/**
* Moves the image set one step left or right. Animates the movement if
* animations are enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@

import org.tepi.imageviewer.ImageViewer;
import org.tepi.imageviewer.ImageViewer.ImageSelectionListener;
import org.tepi.imageviewer.client.Directions;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.server.Resource;
import com.vaadin.server.ThemeResource;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
Expand Down Expand Up @@ -192,6 +195,18 @@ private Layout createControls() {
selectedImage.setWidth("50px");
hl.addComponent(selectedImage);
hl.setComponentAlignment(selectedImage, Alignment.BOTTOM_CENTER);

Button moveLeft = new Button(VaadinIcons.ARROW_LEFT);
moveLeft.setDescription("Move image left");
moveLeft.addClickListener(event -> this.imageViewer.move(Directions.LEFT));
hl.addComponent(moveLeft);
hl.setComponentAlignment(moveLeft, Alignment.BOTTOM_CENTER);

Button moveRight = new Button(VaadinIcons.ARROW_RIGHT);
moveRight.setDescription("Move image right");
moveRight.addClickListener(event -> this.imageViewer.move(Directions.RIGHT));
hl.addComponent(moveRight);
hl.setComponentAlignment(moveRight, Alignment.BOTTOM_CENTER);

return hl;
}
Expand Down