Issue #1558 Fixed RotatePanelsHandler so it functions correctly when rotating from 4-1 panel
Change-Id: I39f6d119360b6c43b2ba4667321e4119d312f721 Former-commit-id:143180a32b
[formerlyd617eb3070
] [formerlyd0c9157e2a
] [formerlyd0c9157e2a
[formerlyed4a9023da
]] [formerly95d3706969
[formerlyd0c9157e2a
[formerlyed4a9023da
] [formerly95d3706969
[formerly b5f53d6b332c8f4b24462d0d42ff1d07cb31830b]]]] Former-commit-id:95d3706969
Former-commit-id: 5c047c6c09633c05353f469718b7b0d4d5372072 [formerly a95b0e6ddb561754bc961f3806861099650f8fc0] [formerlya1d92fa99f
[formerly0f9f51fb14
]] Former-commit-id:a1d92fa99f
Former-commit-id:86bf0ba125
This commit is contained in:
parent
9cce8c6224
commit
68a33e0f15
2 changed files with 203 additions and 181 deletions
|
@ -62,13 +62,13 @@ public class RotatePanelLayoutMenuAction extends AbstractRightClickAction {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
RotatePanelsHandler handler = new RotatePanelsHandler();
|
RotatePanelsHandler.rotateToNextPane((IMultiPaneEditor) getContainer(),
|
||||||
if (!(container instanceof IMultiPaneEditor)) {
|
paneWithFocus);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
IMultiPaneEditor editor = (IMultiPaneEditor) container;
|
|
||||||
editor.setSelectedPane(IMultiPaneEditor.IMAGE_ACTION, null);
|
@Override
|
||||||
handler.rotate(getContainer(), paneWithFocus, 1);
|
public boolean isHidden() {
|
||||||
|
return container instanceof IMultiPaneEditor == false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,216 +27,238 @@ import org.eclipse.core.commands.ExecutionException;
|
||||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||||
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
|
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
|
||||||
import com.raytheon.uf.viz.core.drawables.ResourcePair;
|
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.core.rsc.capabilities.BlendableCapability;
|
||||||
import com.raytheon.uf.viz.d2d.core.legend.D2DLegendResource;
|
import com.raytheon.uf.viz.d2d.core.legend.D2DLegendResource;
|
||||||
import com.raytheon.viz.ui.EditorUtil;
|
import com.raytheon.viz.ui.EditorUtil;
|
||||||
import com.raytheon.viz.ui.HistoryList;
|
|
||||||
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
|
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
|
||||||
import com.raytheon.viz.ui.tools.AbstractTool;
|
import com.raytheon.viz.ui.tools.AbstractTool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Contains logic for rotating panels
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Jan 30, 2013 mschenke Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author mschenke
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
public class RotatePanelsHandler extends AbstractTool {
|
public class RotatePanelsHandler extends AbstractTool {
|
||||||
|
|
||||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||||
IDisplayPaneContainer container = EditorUtil.getActiveVizContainer();
|
IDisplayPaneContainer container = EditorUtil.getActiveVizContainer();
|
||||||
if (container == null) {
|
if (container == null || container instanceof IMultiPaneEditor == false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// direction is usually +1 or -1 to specify which direction to rotate
|
|
||||||
String dirStr = arg0.getParameter("direction");
|
// Get editor and panes
|
||||||
// start index is the index to start rotating from, for example if you
|
IMultiPaneEditor editor = (IMultiPaneEditor) container;
|
||||||
// want to display pane 3 then you set startIndex to 2 and direction to
|
IDisplayPane[] panes = getEditorPanes(editor);
|
||||||
// +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.
|
// Get direction to rotate
|
||||||
String startStr = arg0.getParameter("startIndex");
|
String dirStr = event.getParameter("direction");
|
||||||
// hideIndex can be set to 0 or 1 to specify which half of a blended
|
int direction = Integer.parseInt(dirStr);
|
||||||
// images should be hidden.
|
|
||||||
String hideIndexStr = arg0.getParameter("hideIndex");
|
// Get pane to start rotation on
|
||||||
boolean toggle = false;
|
IDisplayPane startPane = null;
|
||||||
int dir = Integer.parseInt(dirStr);
|
String startStr = event.getParameter("startIndex");
|
||||||
if (startStr == null) {
|
if (startStr != null) {
|
||||||
// If there is no startIndex rotate from the currently displayed
|
int startIdx = Integer.parseInt(startStr);
|
||||||
// pane
|
if (editor.displayedPaneCount() > 1) {
|
||||||
if (container instanceof IMultiPaneEditor) {
|
// more than one pane so we want to start on resulting pane
|
||||||
// If it is going from multiple panes to a single pain, toggle
|
startPane = panes[getNextIndex(panes, startIdx, direction)];
|
||||||
// the blended image
|
} else {
|
||||||
toggle = ((IMultiPaneEditor) container).displayedPaneCount() > 1;
|
// Get pane specified by startIdx
|
||||||
}
|
startPane = panes[getNextIndex(panes, startIdx, 0)];
|
||||||
if (rotateCurrent(container, dir)) {
|
|
||||||
// if it wraps around when we rotate, toggle the blended image.
|
|
||||||
toggle = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int start = Integer.parseInt(startStr);
|
// No startStr, get first visible pane
|
||||||
rotate(container, start, dir);
|
for (IDisplayPane pane : panes) {
|
||||||
|
if (pane.isVisible()) {
|
||||||
|
startPane = pane;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (startPane != null) {
|
||||||
Integer hideIndex = null;
|
Integer hideIndex = null;
|
||||||
|
String hideIndexStr = event.getParameter("hideIndex");
|
||||||
if (hideIndexStr != null) {
|
if (hideIndexStr != null) {
|
||||||
hideIndex = Integer.parseInt(hideIndexStr);
|
hideIndex = Integer.parseInt(hideIndexStr);
|
||||||
}
|
}
|
||||||
if (toggle || hideIndex != null) {
|
|
||||||
for (IDisplayPane pane : container.getDisplayPanes()) {
|
rotateToNextPane(editor, startPane, direction, hideIndex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates to next pane in container. If container has > 1 pane displayed,
|
||||||
|
* will rotate to pane passed in, otherwise to next in line
|
||||||
|
*
|
||||||
|
* @param container
|
||||||
|
* @param pane
|
||||||
|
*/
|
||||||
|
public static void rotateToNextPane(IMultiPaneEditor editor,
|
||||||
|
IDisplayPane pane) {
|
||||||
|
rotateToNextPane(editor, pane, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<D2DLegendResource> rscs = next.getDescriptor()
|
||||||
|
.getResourceList()
|
||||||
|
.getResourcesByTypeAsType(D2DLegendResource.class);
|
||||||
|
for (D2DLegendResource rsc : rscs) {
|
||||||
|
if (rsc.hasProducts()) {
|
||||||
|
paneToRotateTo = next;
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (idxToCheck != paneIdx && !done);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rotateToPane(editor, paneToRotateTo, hideIndex, wrapped);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets container so pane passed in is the only visible pane
|
||||||
|
*
|
||||||
|
* @param container
|
||||||
|
* @param pane
|
||||||
|
*/
|
||||||
|
private static void rotateToPane(IMultiPaneEditor editor,
|
||||||
|
IDisplayPane pane, Integer hideIndex, boolean wrapped) {
|
||||||
|
IDisplayPane[] panes = getEditorPanes(editor);
|
||||||
|
boolean found = false;
|
||||||
|
for (IDisplayPane editorPane : panes) {
|
||||||
|
if (editorPane == pane) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
for (IDisplayPane editorPane : panes) {
|
||||||
|
if (editorPane != pane) {
|
||||||
|
editor.hidePane(editorPane);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editor.showPane(pane);
|
||||||
|
editor.setSelectedPane(IMultiPaneEditor.VISIBLE_PANE, pane);
|
||||||
|
editor.setSelectedPane(IMultiPaneEditor.IMAGE_ACTION, null);
|
||||||
|
|
||||||
|
if (hideIndex == null) {
|
||||||
|
// Search pane for current resource index
|
||||||
|
hideIndex = 0;
|
||||||
for (ResourcePair rp : pane.getDescriptor().getResourceList()) {
|
for (ResourcePair rp : pane.getDescriptor().getResourceList()) {
|
||||||
if (rp.getResource() != null
|
if (rp.getResource() != null
|
||||||
&& rp.getResource().hasCapability(
|
&& rp.getResource().hasCapability(
|
||||||
BlendableCapability.class)) {
|
BlendableCapability.class)) {
|
||||||
BlendableCapability cap = rp.getResource()
|
hideIndex = rp.getResource()
|
||||||
.getCapability(BlendableCapability.class);
|
.getCapability(BlendableCapability.class)
|
||||||
if (hideIndex != null) {
|
.getResourceIndex();
|
||||||
cap.toggle(hideIndex);
|
}
|
||||||
|
}
|
||||||
|
if (wrapped) {
|
||||||
|
// If we wrapped, switch index
|
||||||
|
if (hideIndex == 0) {
|
||||||
|
hideIndex = 1;
|
||||||
} else {
|
} else {
|
||||||
cap.toggle();
|
hideIndex = 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (container instanceof IMultiPaneEditor) {
|
// Toggle displayed resource
|
||||||
((IMultiPaneEditor) container).setSelectedPane(
|
for (IDisplayPane p : panes) {
|
||||||
IMultiPaneEditor.IMAGE_ACTION, null);
|
for (ResourcePair rp : p.getDescriptor().getResourceList()) {
|
||||||
|
if (rp.getResource() != null
|
||||||
|
&& rp.getResource().hasCapability(
|
||||||
|
BlendableCapability.class)) {
|
||||||
|
rp.getResource()
|
||||||
|
.getCapability(BlendableCapability.class)
|
||||||
|
.toggle(hideIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* rotate starting from the activeDisplayPane in direction
|
|
||||||
*
|
|
||||||
* @param direction
|
|
||||||
* should be either 1, or -1
|
|
||||||
* @return true if the data wrapped to the other side of the pane array.
|
|
||||||
*/
|
|
||||||
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 void rotate(IDisplayPaneContainer container, IDisplayPane pane,
|
|
||||||
int direction) {
|
|
||||||
if (container instanceof IMultiPaneEditor) {
|
|
||||||
rotate(container, getIndex(container, pane), direction);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rotate starting from a specific index in direction
|
* Gets the editor panes. Will reorder panes to special A1 ordering of
|
||||||
|
* UL,UR,LR,LL if number of panes is 4
|
||||||
*
|
*
|
||||||
* @param index
|
* @param editor
|
||||||
* the index to start rotating from
|
* @return
|
||||||
* @param direction
|
|
||||||
* should be either 1, or -1
|
|
||||||
* @return true if the data wrapped to the other side of the pane array.
|
|
||||||
*/
|
*/
|
||||||
private boolean rotate(IDisplayPaneContainer container, int index,
|
private static IDisplayPane[] getEditorPanes(IMultiPaneEditor editor) {
|
||||||
int direction) {
|
IDisplayPane[] panes = editor.getDisplayPanes();
|
||||||
boolean wrapped = false;
|
|
||||||
IMultiPaneEditor mEditor = (IMultiPaneEditor) container;
|
|
||||||
IDisplayPane[] panes = mEditor.getDisplayPanes();
|
|
||||||
if (panes.length == 4) {
|
if (panes.length == 4) {
|
||||||
// Pretend the panels are in the order 0, 1, 3, 2 because
|
IDisplayPane[] tmp = new IDisplayPane[panes.length];
|
||||||
// AWIPS I rotates the panes in a weird order = ul, ur, lr, ll
|
tmp[0] = panes[0];
|
||||||
IDisplayPane[] reorderedPanes = new IDisplayPane[4];
|
tmp[1] = panes[1];
|
||||||
reorderedPanes[0] = panes[0];
|
tmp[2] = panes[3];
|
||||||
reorderedPanes[1] = panes[1];
|
tmp[3] = panes[2];
|
||||||
reorderedPanes[2] = panes[3];
|
panes = tmp;
|
||||||
reorderedPanes[3] = panes[2];
|
}
|
||||||
panes = reorderedPanes;
|
return panes;
|
||||||
}
|
}
|
||||||
|
|
||||||
IDisplayPane paneToShow = null;
|
/**
|
||||||
|
* Gets the next index in line for rotation given panes, curIdx, and
|
||||||
if (panes != null && index < panes.length && panes.length != 1) {
|
* direction
|
||||||
boolean from4To1 = mEditor.displayedPaneCount() > 1;
|
*
|
||||||
boolean hasProducts = false;
|
* @param panes
|
||||||
if (panes[index] != null) {
|
* @param curIdx
|
||||||
List<D2DLegendResource> rscs = panes[index].getDescriptor()
|
* @param direction
|
||||||
.getResourceList()
|
* @return
|
||||||
.getResourcesByTypeAsType(D2DLegendResource.class);
|
*/
|
||||||
for (D2DLegendResource rsc : rscs) {
|
private static int getNextIndex(IDisplayPane[] panes, int curIdx,
|
||||||
hasProducts = rsc.hasProducts();
|
int direction) {
|
||||||
if (hasProducts) {
|
int idxToCheck = curIdx + direction;
|
||||||
break;
|
if (idxToCheck < 0) {
|
||||||
}
|
idxToCheck = panes.length - 1;
|
||||||
}
|
} else if (idxToCheck >= panes.length) {
|
||||||
}
|
idxToCheck = 0;
|
||||||
|
}
|
||||||
if (from4To1 && hasProducts) {
|
return idxToCheck;
|
||||||
paneToShow = panes[index];
|
|
||||||
} else {
|
|
||||||
IDisplayPane displayedPane = null;
|
|
||||||
boolean done = false;
|
|
||||||
for (int i = index + direction; !done; i = i + direction) {
|
|
||||||
if (i < 0) {
|
|
||||||
i += panes.length;
|
|
||||||
wrapped = true;
|
|
||||||
} else if (i >= panes.length) {
|
|
||||||
wrapped = true;
|
|
||||||
i -= panes.length;
|
|
||||||
}
|
|
||||||
IDisplayPane pane = panes[i];
|
|
||||||
if (i == index) {
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pane != panes[index] && pane != null) {
|
|
||||||
List<D2DLegendResource> rscs = pane
|
|
||||||
.getDescriptor()
|
|
||||||
.getResourceList()
|
|
||||||
.getResourcesByTypeAsType(
|
|
||||||
D2DLegendResource.class);
|
|
||||||
for (D2DLegendResource rsc : rscs) {
|
|
||||||
if (rsc.hasProducts()) {
|
|
||||||
displayedPane = pane;
|
|
||||||
done = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
paneToShow = displayedPane != null ? displayedPane
|
|
||||||
: panes[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IDisplayPane displayPane : panes) {
|
|
||||||
if (displayPane != paneToShow) {
|
|
||||||
mEditor.hidePane(displayPane);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mEditor.showPane(paneToShow);
|
|
||||||
mEditor.setSelectedPane(IMultiPaneEditor.VISIBLE_PANE, paneToShow);
|
|
||||||
|
|
||||||
container.refresh();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
HistoryList.getInstance().refreshLatestBundle();
|
|
||||||
} catch (VizException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return wrapped;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getIndex(IDisplayPaneContainer container, IDisplayPane pane) {
|
|
||||||
IMultiPaneEditor mEditor = (IMultiPaneEditor) container;
|
|
||||||
IDisplayPane[] panes = mEditor.getDisplayPanes();
|
|
||||||
int currentIndex = -1;
|
|
||||||
for (int i = 0; i < panes.length; i++) {
|
|
||||||
if (panes[i] == pane) {
|
|
||||||
currentIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Pretend the panels are in the order 0, 1, 3, 2 because
|
|
||||||
// AWIPS I rotates the panes in a wierd order = ul, ur, lr, ll
|
|
||||||
if (panes.length == 4 && currentIndex == 3) {
|
|
||||||
currentIndex = 2;
|
|
||||||
} else if (panes.length == 4 && currentIndex == 2) {
|
|
||||||
currentIndex = 3;
|
|
||||||
}
|
|
||||||
return currentIndex;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue