Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Introduction to the Context Menu API

Design

Interface

package org.lorainelab.igb.context.menu;
import java.util.Optional;
import org.lorainelab.igb.context.menu.model.AnnotationContextEvent;
import org.lorainelab.igb.context.menu.model.ContextMenuItem;

/**
 *
 * @author dcnorris
 */
public interface AnnotationContextMenuProvider {
    public Optional<ContextMenuItem> buildMenuItem(AnnotationContextEvent event);
    public MenuSection getMenuSection();
}

Data Model

AnnotationContextEvent

package org.lorainelab.igb.context.menu.model;
import com.affymetrix.genometry.symmetry.impl.SeqSymmetry;
import java.util.List;
/**
 *
 * @author dcnorris
 */
public class AnnotationContextEvent {
    private final List<SeqSymmetry> selectedItems;
    public AnnotationContextEvent(List<SeqSymmetry> selectedItems) {
        this.selectedItems = selectedItems;
    }
    public List<SeqSymmetry> getSelectedItems() {
        return selectedItems;
    }
}

ContextMenuItem

package org.lorainelab.igb.context.menu.model;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
/**
 *
 * @author dcnorris
 */
public class ContextMenuItem {
    private final String menuLabel;
    private MenuIcon menuIcon;
    private Function<Void, Void> action;
    private Set<ContextMenuItem> subMenuItems;
    private int weight = 0;
    public ContextMenuItem(String menuLabel, Set<ContextMenuItem> subMenuItems) {
        checkNotNull(menuLabel);
        checkNotNull(subMenuItems);
        checkState(!Strings.isNullOrEmpty(menuLabel));
        checkState(!subMenuItems.isEmpty());
        this.menuLabel = menuLabel;
        this.subMenuItems = ImmutableSet.copyOf(subMenuItems);
    }
    public ContextMenuItem(String menuLabel, Function<Void, Void> action) {
        checkNotNull(menuLabel);
        checkState(!Strings.isNullOrEmpty(menuLabel));
        checkNotNull(action);
        this.menuLabel = menuLabel;
        this.action = action;
        subMenuItems = ImmutableSet.of();
    }
    public String getMenuLabel() {
        return menuLabel;
    }
    public Function<Void, Void> getAction() {
        return action;
    }
    public Set<ContextMenuItem> getSubMenuItems() {
        return subMenuItems;
    }
    public void setWeight(int weight) {
        this.weight = weight;
    }
    public void setMenuIcon(MenuIcon menuIcon) {
        this.menuIcon = menuIcon;
    }
    public Optional<MenuIcon> getMenuIcon() {
        return Optional.ofNullable(menuIcon);
    }
}

MenuIcon

package org.lorainelab.igb.context.menu.model;
import com.google.common.io.BaseEncoding;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 *
 * @author dcnorris
 */
public class MenuIcon {
    private String encodedImage;
    private static final Logger logger = LoggerFactory.getLogger(MenuIcon.class);
    public MenuIcon(InputStream resourceAsStream) {
        try {
            encodedImage = BaseEncoding.base64().encode(IOUtils.toByteArray(resourceAsStream));
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
    public byte[] getEncodedImage() {
        return BaseEncoding.base64().decode(encodedImage);
    }
}
  • No labels