diff --git a/cave/com.raytheon.uf.viz.d2d.ui/src/com/raytheon/uf/viz/d2d/ui/map/actions/RotatePanelLayoutMenuAction.java b/cave/com.raytheon.uf.viz.d2d.ui/src/com/raytheon/uf/viz/d2d/ui/map/actions/RotatePanelLayoutMenuAction.java index 7ccdf23e6c..99f6e18a70 100644 --- a/cave/com.raytheon.uf.viz.d2d.ui/src/com/raytheon/uf/viz/d2d/ui/map/actions/RotatePanelLayoutMenuAction.java +++ b/cave/com.raytheon.uf.viz.d2d.ui/src/com/raytheon/uf/viz/d2d/ui/map/actions/RotatePanelLayoutMenuAction.java @@ -62,13 +62,13 @@ public class RotatePanelLayoutMenuAction extends AbstractRightClickAction { */ @Override public void run() { - RotatePanelsHandler handler = new RotatePanelsHandler(); - if (!(container instanceof IMultiPaneEditor)) { - return; - } - IMultiPaneEditor editor = (IMultiPaneEditor) container; - editor.setSelectedPane(IMultiPaneEditor.IMAGE_ACTION, null); - handler.rotate(getContainer(), paneWithFocus, 1); + RotatePanelsHandler.rotateToNextPane((IMultiPaneEditor) getContainer(), + paneWithFocus); + } + + @Override + public boolean isHidden() { + return container instanceof IMultiPaneEditor == false; } } diff --git a/cave/com.raytheon.uf.viz.d2d.ui/src/com/raytheon/uf/viz/d2d/ui/map/actions/RotatePanelsHandler.java b/cave/com.raytheon.uf.viz.d2d.ui/src/com/raytheon/uf/viz/d2d/ui/map/actions/RotatePanelsHandler.java index 80970da597..2275f0c3b0 100644 --- a/cave/com.raytheon.uf.viz.d2d.ui/src/com/raytheon/uf/viz/d2d/ui/map/actions/RotatePanelsHandler.java +++ b/cave/com.raytheon.uf.viz.d2d.ui/src/com/raytheon/uf/viz/d2d/ui/map/actions/RotatePanelsHandler.java @@ -27,216 +27,238 @@ import org.eclipse.core.commands.ExecutionException; import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IDisplayPaneContainer; import com.raytheon.uf.viz.core.drawables.ResourcePair; -import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.rsc.capabilities.BlendableCapability; import com.raytheon.uf.viz.d2d.core.legend.D2DLegendResource; import com.raytheon.viz.ui.EditorUtil; -import com.raytheon.viz.ui.HistoryList; import com.raytheon.viz.ui.editor.IMultiPaneEditor; import com.raytheon.viz.ui.tools.AbstractTool; +/** + * + * Contains logic for rotating panels + * + *
+ * + * SOFTWARE HISTORY + * + * Date Ticket# Engineer Description + * ------------ ---------- ----------- -------------------------- + * Jan 30, 2013 mschenke Initial creation + * + *+ * + * @author mschenke + * @version 1.0 + */ public class RotatePanelsHandler extends AbstractTool { - public Object execute(ExecutionEvent arg0) throws ExecutionException { + public Object execute(ExecutionEvent event) throws ExecutionException { IDisplayPaneContainer container = EditorUtil.getActiveVizContainer(); - if (container == null) { + if (container == null || container instanceof IMultiPaneEditor == false) { return null; } - // direction is usually +1 or -1 to specify which direction to rotate - String dirStr = arg0.getParameter("direction"); - // start index is the index to start rotating from, for example if you - // want to display pane 3 then you set startIndex to 2 and direction to - // +1, this is done so that if pane 3 has no data it will rotate past - // pane 3 and the next available pane with data. - String startStr = arg0.getParameter("startIndex"); - // hideIndex can be set to 0 or 1 to specify which half of a blended - // images should be hidden. - String hideIndexStr = arg0.getParameter("hideIndex"); - boolean toggle = false; - int dir = Integer.parseInt(dirStr); - if (startStr == null) { - // If there is no startIndex rotate from the currently displayed - // pane - if (container instanceof IMultiPaneEditor) { - // If it is going from multiple panes to a single pain, toggle - // the blended image - toggle = ((IMultiPaneEditor) container).displayedPaneCount() > 1; - } - if (rotateCurrent(container, dir)) { - // if it wraps around when we rotate, toggle the blended image. - toggle = true; + + // Get editor and panes + IMultiPaneEditor editor = (IMultiPaneEditor) container; + IDisplayPane[] panes = getEditorPanes(editor); + + // Get direction to rotate + String dirStr = event.getParameter("direction"); + int direction = Integer.parseInt(dirStr); + + // Get pane to start rotation on + IDisplayPane startPane = null; + String startStr = event.getParameter("startIndex"); + if (startStr != null) { + int startIdx = Integer.parseInt(startStr); + if (editor.displayedPaneCount() > 1) { + // more than one pane so we want to start on resulting pane + startPane = panes[getNextIndex(panes, startIdx, direction)]; + } else { + // Get pane specified by startIdx + startPane = panes[getNextIndex(panes, startIdx, 0)]; } } else { - int start = Integer.parseInt(startStr); - rotate(container, start, dir); - } - - Integer hideIndex = null; - if (hideIndexStr != null) { - hideIndex = Integer.parseInt(hideIndexStr); - } - if (toggle || hideIndex != null) { - for (IDisplayPane pane : container.getDisplayPanes()) { - for (ResourcePair rp : pane.getDescriptor().getResourceList()) { - if (rp.getResource() != null - && rp.getResource().hasCapability( - BlendableCapability.class)) { - BlendableCapability cap = rp.getResource() - .getCapability(BlendableCapability.class); - if (hideIndex != null) { - cap.toggle(hideIndex); - } else { - cap.toggle(); - } - } + // No startStr, get first visible pane + for (IDisplayPane pane : panes) { + if (pane.isVisible()) { + startPane = pane; + break; } } } - if (container instanceof IMultiPaneEditor) { - ((IMultiPaneEditor) container).setSelectedPane( - IMultiPaneEditor.IMAGE_ACTION, null); - } + if (startPane != null) { + Integer hideIndex = null; + String hideIndexStr = event.getParameter("hideIndex"); + if (hideIndexStr != null) { + hideIndex = Integer.parseInt(hideIndexStr); + } + rotateToNextPane(editor, startPane, direction, hideIndex); + } return null; } /** - * rotate starting from the activeDisplayPane in direction + * Rotates to next pane in container. If container has > 1 pane displayed, + * will rotate to pane passed in, otherwise to next in line * - * @param direction - * should be either 1, or -1 - * @return true if the data wrapped to the other side of the pane array. + * @param container + * @param pane */ - public boolean rotateCurrent(IDisplayPaneContainer container, int direction) { - if (container instanceof IMultiPaneEditor) { - IMultiPaneEditor mEditor = (IMultiPaneEditor) container; - int index = getIndex(container, mEditor.getActiveDisplayPane()); - return rotate(container, index, direction); - } - return false; + public static void rotateToNextPane(IMultiPaneEditor editor, + IDisplayPane pane) { + rotateToNextPane(editor, pane, 1, 0); } - public void rotate(IDisplayPaneContainer container, IDisplayPane pane, - int direction) { - if (container instanceof IMultiPaneEditor) { - rotate(container, getIndex(container, pane), direction); + /** + * Rotates to the next panel given the direction + * + * @param editor + * @param pane + * @param direction + */ + private static void rotateToNextPane(IMultiPaneEditor editor, + IDisplayPane pane, int direction, Integer hideIndex) { + boolean wrapped = false; + IDisplayPane paneToRotateTo = pane; + if (editor.displayedPaneCount() == 1) { + IDisplayPane[] panes = getEditorPanes(editor); + int paneIdx = -1; + for (int i = 0; i < panes.length; ++i) { + if (panes[i] == pane) { + paneIdx = i; + break; + } + } + + if (paneIdx >= 0) { + int idxToCheck = paneIdx; + boolean done = false; + do { + int tmpIdx = idxToCheck + direction; + idxToCheck = getNextIndex(panes, idxToCheck, direction); + if (idxToCheck != tmpIdx) { + wrapped = true; + } + IDisplayPane next = panes[idxToCheck]; + List