oldLocation = newLocation;
break;
case Cursor.NE_RESIZE_CURSOR:
if (highlightedPanels.size() == 1) {
Panel panel = highlightedPanels.iterator().next();
Rectangle panelOldBounds = panel.getBounds();
int oldNECornerX = panelOldBounds.x + panelOldBounds.width, oldNECornerY = panelOldBounds.y;
int diffWidth = newLocation.x - oldNECornerX, diffHeight = newLocation.y
- oldNECornerY;
int newWidth = panelOldBounds.width + diffWidth;
int newHeight = panelOldBounds.height - diffHeight;
if (newWidth > 0 && newHeight > 0)
panel.setBounds(panelOldBounds.x, panelOldBounds.y + diffHeight,
newWidth, newHeight);
}
break;
case Cursor.SE_RESIZE_CURSOR:
if (highlightedPanels.size() == 1) {
Panel panel = highlightedPanels.iterator().next();
Rectangle panelOldBounds = panel.getBounds();
int oldSECornerX = panelOldBounds.x + panelOldBounds.width, oldSECornerY = panelOldBounds.y
+ panelOldBounds.height;
int diffWidth = newLocation.x - oldSECornerX, diffHeight = newLocation.y
- oldSECornerY;
int newWidth = panelOldBounds.width + diffWidth;
int newHeight = panelOldBounds.height + diffHeight;
if (newWidth > 0 && newHeight > 0)
panel
.setBounds(panelOldBounds.x, panelOldBounds.y,
newWidth, newHeight);
}
break;
case Cursor.SW_RESIZE_CURSOR:
if (highlightedPanels.size() == 1) {
Panel panel = highlightedPanels.iterator().next();
Rectangle panelOldBounds = panel.getBounds();
int oldSWCornerX = panelOldBounds.x, oldSWCornerY = panelOldBounds.y
+ panelOldBounds.height;
int diffWidth = newLocation.x - oldSWCornerX, diffHeight = newLocation.y
- oldSWCornerY;
int newWidth = panelOldBounds.width - diffWidth;
int newHeight = panelOldBounds.height + diffHeight;
if (newWidth > 0 && newHeight > 0)
panel.setBounds(panelOldBounds.x + diffWidth, panelOldBounds.y,
newWidth, newHeight);
}
break;
case Cursor.NW_RESIZE_CURSOR:
if (highlightedPanels.size() == 1) {
Panel panel = highlightedPanels.iterator().next();
Rectangle panelOldBounds = panel.getBounds();
int oldSWCornerX = panelOldBounds.x, oldSWCornerY = panelOldBounds.y;
int diffWidth = newLocation.x - oldSWCornerX, diffHeight = newLocation.y
- oldSWCornerY;
int newWidth = panelOldBounds.width - diffWidth;
int newHeight = panelOldBounds.height - diffHeight;
if (newWidth > 0 && newHeight > 0)
panel.setBounds(panelOldBounds.x + diffWidth, panelOldBounds.y
+ diffHeight, newWidth, newHeight);
}
break;
case Cursor.E_RESIZE_CURSOR:
if (highlightedPanels.size() == 1) {
Panel panel = highlightedPanels.iterator().next();
Rectangle panelOldBounds = panel.getBounds();
int oldEEdgeX = panelOldBounds.x + panelOldBounds.width;
int diffWidth = newLocation.x - oldEEdgeX;
int newWidth = panelOldBounds.width + diffWidth;
if (newWidth > 0)
panel.setBounds(panelOldBounds.x, panelOldBounds.y, newWidth,
panelOldBounds.height);
}
break;
case Cursor.S_RESIZE_CURSOR:
if (highlightedPanels.size() == 1) {
Panel panel = highlightedPanels.iterator().next();
Rectangle panelOldBounds = panel.getBounds();
int oldSEdgeY = panelOldBounds.y + panelOldBounds.height;
int diffHeight = newLocation.y - oldSEdgeY;
int newHeight = panelOldBounds.height + diffHeight;
if (newHeight > 0)
panel.setBounds(panelOldBounds.x, panelOldBounds.y,
panelOldBounds.width, newHeight);
}
break;
case Cursor.W_RESIZE_CURSOR:
if (highlightedPanels.size() == 1) {
Panel panel = highlightedPanels.iterator().next();
Rectangle panelOldBounds = panel.getBounds();
int oldWEdgeX = panelOldBounds.x;
int diffWidth = newLocation.x - oldWEdgeX;
int newWidth = panelOldBounds.width - diffWidth;
if (newWidth > 0)
panel.setBounds(panelOldBounds.x + diffWidth, panelOldBounds.y,
newWidth, panelOldBounds.height);
}
break;
case Cursor.N_RESIZE_CURSOR:
if (highlightedPanels.size() == 1) {
Panel panel = highlightedPanels.iterator().next();
Rectangle panelOldBounds = panel.getBounds();
int oldNEdgeY = panelOldBounds.y;
int diffHeight = newLocation.y - oldNEdgeY;
int newHeight = panelOldBounds.height - diffHeight;
if (newHeight > 0)
panel.setBounds(panelOldBounds.x, panelOldBounds.y + diffHeight,
panelOldBounds.width, newHeight);
}
break;
default:
redispatchEvent(e);
return;
}
redispatchEvent(e);
hasPanelChanged = true;
}
private Point marshalNewLocation(Point mouseLocation, Point mouseLocationOnScreen) {
if (highlightedPanels.isEmpty()) {
return mouseLocation;
}
int smallestX;
int smallestY;
Iterator<Panel> it = highlightedPanels.iterator();
Panel panel = it.next();
Point bound = panel.getLocationOnScreen();
smallestX = bound.x;
smallestY = bound.y;
while (it.hasNext()) {
panel = it.next();
bound = panel.getLocationOnScreen();
if (bound.x < smallestX) {
smallestX = bound.x;
}
if (bound.y < smallestY) {
smallestY = bound.y;
}
}
Point smallestPoint = new Point(smallestX, smallestY);
Point returnLocation = new Point(mouseLocation.x, mouseLocation.y);
if (invalidHorizontalMovement(smallestPoint, mouseLocationOnScreen,
Augmentation.this.canvasManifestation,
mouseLocation.x < oldLocation.x)) {
returnLocation.x = oldLocation.x
+ Augmentation.this.canvasManifestation.getLocationOnScreen().x
- smallestX;
}
if (invalidVerticalMovement(smallestPoint, mouseLocationOnScreen,
Augmentation.this.canvasManifestation,
mouseLocation.y < oldLocation.y)) {
returnLocation.y = oldLocation.y
+ Augmentation.this.canvasManifestation.getLocationOnScreen().y
- smallestY;
}
return returnLocation;
}
private boolean invalidHorizontalMovement(Point checkPoint, Point mouseLocation,
Container parent, boolean leftMoving) {
Point parentLoc = parent.getLocationOnScreen();
if ((checkPoint.x <= parentLoc.x) && leftMoving) {
return true;
}
return false;
}
private boolean invalidVerticalMovement(Point checkPoint, Point mouseLocation,
Container parent, boolean upMoving) {
Point parentLoc = parent.getLocationOnScreen();
if ((checkPoint.y <= parentLoc.y) && upMoving) {
return true;
}
return false;
}
@Override
public void mouseMoved(MouseEvent e) {
Augmentation augmentation = (Augmentation) e.getSource();
if (highlightedPanels.isEmpty()) {
augmentation.setAugmentationCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
} else {
for (Panel panel : highlightedPanels) {
int currentCursorType = augmentation.getCursor().getType();
setCursorType(augmentation, panel, e.getPoint());
int newCursorType = augmentation.getCursor().getType();
oldLocation = e.getPoint();
if (currentCursorType != newCursorType) {
return;
}
}
}
redispatchEvent(e);
}
});
// if popup trigger is in title bar, then show popup otherwise redispatchEvent
//
addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
redispatchEvent(e);
}
@Override
public void mouseExited(MouseEvent e) {
redispatchEvent(e);
}
@Override
public void mousePressed(MouseEvent e) {
selectedPointIfNothingHappens = null;
// point is not in title area, pass the underlying event to the contents of the panel
Augmentation augmentation = (Augmentation) e.getSource();
Point p = e.getLocationOnScreen();
CanvasManifestation canvas = Augmentation.this.canvasManifestation;
Panel panel = canvas.findImmediatePanel(p);
// Detects if cursor is within the move or resize region. This region includes
// d pixels (see field declaration) beyond a panel's width and height.
if (panel == null && augmentation.getCursor().getType() != Cursor.DEFAULT_CURSOR) {
redispatchEvent(e);
return;
}
if (panel != null && !panel.pointOnBorder(p)) {
redispatchEvent(e);
return;
}
if (isPopupTrigger(e)) {
showPopupMenu(e);
return;
}
if (e.getClickCount() == 1) {
oldLocation = e.getPoint();
if (isDiscontinuousMultiSelection(e)) {
canvas.addSingleSelection(p);
} else if(canvas.getSelectedPanels().contains(panel)) {
canvas.addSingleSelection(p);
selectedPointIfNothingHappens = p;
} else {
canvas.setSingleSelection(p);
}
if(panel != null) {
panel.setTitleBounds();
setCursorType(augmentation, panel, e.getPoint());
}
augmentation.repaint();
} else if (isDoubleClick(e)) {
panel = augmentation.canvasManifestation.setSingleSelection(p);
if (panel != null) {
panel.getWrappedManifestation().getManifestedComponent().open();
}
}
redispatchEvent(e);
}
@Override
public void mouseReleased(MouseEvent e) {
if (isPopupTrigger(e)) {
showPopupMenu(e);
return;
}
for (Panel panel : highlightedPanels) {
Rectangle r = panel.getBounds();
r = panel.marshalBound(r);
panel.setBounds(r);
}
if(selectedPointIfNothingHappens != null) {
Augmentation.this.canvasManifestation.setSingleSelection(selectedPointIfNothingHappens);
hasPanelChanged = true;
}
if (hasPanelChanged) {
Augmentation.this.canvasManifestation.fireFocusPersist();
Augmentation.this.repaint();
Augmentation.this.canvasManifestation.computePreferredSize();
hasPanelChanged = false;
Augmentation.this.canvasManifestation.updateController(highlightedPanels);
}
redispatchEvent(e);
}
@Override
public void mouseClicked(MouseEvent e) {
redispatchEvent(e);
}
private boolean isDiscontinuousMultiSelection(MouseEvent e) {
return e.isControlDown() || e.isMetaDown();
}
private boolean isPopupTrigger(MouseEvent e) {
return e.isPopupTrigger();
}
private boolean isDoubleClick(MouseEvent e) {
return (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e));
}
private void showPopupMenu(MouseEvent e) {
Augmentation augmentation = (Augmentation) e.getSource();
Point p = e.getLocationOnScreen();
Panel panel = augmentation.canvasManifestation.findImmediatePanel(p);
if (panel != null && !panel.pointInTitle(p)) {
redispatchEvent(e);
return;
}
if (!augmentation.canvasManifestation.getSelectedPanels().contains(panel)) {
panel = augmentation.canvasManifestation.setSingleSelection(p);
}
// Don't show the popup if the canvas is in the inspector.
// This is because the actions don't use the right canvas.
// This causes bug MCT-2250.
// This should be re-enabled once the actions use the correct canvas.
View m = augmentation.canvasManifestation;
while (m != null && m.getInfo() != null) {
if (m.getInfo().getViewType() == ViewType.INSPECTOR || m.getInfo().getViewType() == ViewType.CENTER_OWNED_INSPECTOR) {
return;
}
m = (View) SwingUtilities.getAncestorOfClass(View.class, m);
}
if (panel == null) {
MenuManager menuManager = MenuManagerAccess.getMenuManager();
JPopupMenu popupMenu = menuManager.getViewPopupMenu(augmentation.canvasManifestation);
if (popupMenu != null)
popupMenu.show(augmentation.canvasManifestation, e.getX(), e.getY());
} else {
Point panelPoint = panel.getLocationOnScreen();
JPopupMenu popupMenu = panel.getWrappedManifestation()
.getManifestationPopupMenu();
if (popupMenu != null)
popupMenu.show(panel, p.x - panelPoint.x, p.y - panelPoint.y);
}
augmentation.repaint();