private boolean findViewState(Collection<ViewState> states, String viewType, String viewValue) { for (ViewState state : states) { if (state.getViewStatePK().getViewType().equals(viewType) && state.getViewInfo().equals(viewValue)) { return true; } } return false; }
/** * Popup a dialog asking the user for the name of the saved ViewManager. If provided, add a new * TwoFacedObject to the list of saved ViewManagers and write the list to disk. * * @param vm The view manager to save */ protected void saveViewManagerState(ViewManager vm) { try { String name = ((vm instanceof MapViewManager) ? "Map View" : "View"); name = GuiUtils.getInput(null, "Name for saved view: ", name); if (name == null) { return; } ViewState viewState = vm.doMakeViewState(); viewState.setName(name); getVMState().add(viewState); writeVMState(); } catch (Exception exc) { logException("Saving view state", exc); } }
/** * Instantiates (if needed) and returns the list of {@link TwoFacedObject}s that is the set of * saved viewpoints * * @return List that holds the viewpoints */ public List getVMState() { if (viewpoints == null) { List tmp = new ArrayList(); XmlResourceCollection rc = getResourceManager().getXmlResources(getResourceManager().RSC_VIEWPOINTS); for (int i = 0; i < rc.size(); i++) { String contents = rc.read(i); if (contents == null) { continue; } try { List resources = (List) getIdv().getEncoderForRead().toObject(contents); tmp.addAll(resources); boolean local = rc.isWritable(i); for (Object o : resources) { if (o instanceof ViewState) { ((ViewState) o).setIsLocal(local); } } } catch (Exception exc) { logException("Creating VM list", exc); } } viewpoints = tmp; } return viewpoints; }
public EventGotoPage(final AbstractViewController ctrl, final int viewIndex) { this.viewState = ViewState.get(ctrl); this.ctrl = ctrl; this.model = viewState.model; this.centerPage = true; this.viewIndex = viewIndex; this.offsetX = 0; this.offsetY = 0; }
@Override public ViewState process() { if (model == null) { return null; } final int pageCount = model.getPageCount(); if (viewIndex < 0 && viewIndex >= pageCount) { if (LCTX.isDebugEnabled()) { LCTX.d("Bad page index: " + viewIndex + ", page count: " + pageCount); } return viewState; } final Page page = model.getPageObject(viewIndex); if (page == null) { if (LCTX.isDebugEnabled()) { LCTX.d("No page found for index: " + viewIndex); } return viewState; } model.setCurrentPageIndex(page.index); final IView view = ctrl.getView(); final int scrollX = view.getScrollX(); final int scrollY = view.getScrollY(); final PointF p = calculateScroll(page, scrollX, scrollY); final int left = Math.round(p.x); final int top = Math.round(p.y); if (isScrollRequired(left, top, scrollX, scrollY)) { view.forceFinishScroll(); view.scrollTo(left, top); viewState.update(); return viewState; } viewState.release(); return EventPool.newEventScrollTo(ctrl, viewIndex).process(); }
private ComponentSpec createComponentSpec( String id, String userId, String name, String type, String owner, List<Tag> tags, Map<String, String> views) { ComponentSpec cs = new ComponentSpec(); cs.setComponentId(id); cs.setCreatorUserId(userId); cs.setComponentName(name); cs.setComponentType(type); cs.setOwner(owner); cs.setReferencedComponents(new ArrayList<ComponentSpec>()); List<ViewState> viewStates = new ArrayList<ViewState>(); for (Entry<String, String> e : views.entrySet()) { ViewState vs = new ViewState(); ViewStatePK viewStatePK = new ViewStatePK(); viewStatePK.setComponentId(cs.getComponentId()); viewStatePK.setViewType(e.getKey()); vs.setViewStatePK(viewStatePK); vs.setViewInfo(e.getValue()); viewStates.add(vs); } cs.setViewStateCollection(viewStates); cs.setTagAssociationCollection(new ArrayList<TagAssociation>()); for (Tag aTag : tags) { TagAssociation association = new TagAssociation(); TagAssociationPK tagPK = new TagAssociationPK(); tagPK.setComponentId(cs.getComponentId()); tagPK.setTagId(aTag.getTagId()); association.setTagAssociationPK(tagPK); association.setTagProperty(aTag.getTagProperty()); cs.getTagAssociationCollection().add(association); } return cs; }
public EventGotoPage( final AbstractViewController ctrl, final int viewIndex, final float offsetX, final float offsetY) { this.viewState = ViewState.get(ctrl); this.ctrl = ctrl; this.model = viewState.model; this.centerPage = false; this.viewIndex = viewIndex; this.offsetX = offsetX; this.offsetY = offsetY; }
@Override public int compare(final PageTreeNode node1, final PageTreeNode node2) { final int cp = viewState.currentIndex; final int viewIndex1 = node1.page.index.viewIndex; final int viewIndex2 = node2.page.index.viewIndex; final boolean v1 = viewState.isNodeVisible(node1, viewState.getBounds(node1.page)); final boolean v2 = viewState.isNodeVisible(node2, viewState.getBounds(node2.page)); final RectF s1 = node1.pageSliceBounds; final RectF s2 = node2.pageSliceBounds; int res = 0; if (viewIndex1 == cp && viewIndex2 == cp) { res = CompareUtils.compare(s1.top, s2.top); if (res == 0) { res = CompareUtils.compare(s1.left, s2.left); } } else if (v1 && !v2) { res = -1; } else if (!v1 && v2) { res = 1; } else { final float d1 = viewIndex1 + s1.centerY() - (cp + 0.5f); final float d2 = viewIndex2 + s2.centerY() - (cp + 0.5f); final int dist1 = Math.abs((int) (d1 * node1.childrenZoomThreshold)); final int dist2 = Math.abs((int) (d2 * node2.childrenZoomThreshold)); res = CompareUtils.compare(dist1, dist2); if (res == 0) { res = -CompareUtils.compare(viewIndex1, viewIndex2); } } return res; }