Package gov.nasa.arc.mct.canvas.panel

Examples of gov.nasa.arc.mct.canvas.panel.Panel


     */
    public static List<Panel> getSelectedPanels(Collection<View> selectedManifestations) {
        List<Panel> selectedPanels = new ArrayList<Panel>(selectedManifestations.size());
       
        for (View manifestation : selectedManifestations) {
            Panel panel = (Panel) SwingUtilities.getAncestorOfClass(Panel.class, manifestation);
            if (panel != null) {
                selectedPanels.add(panel);
            }
        }
        return selectedPanels;
View Full Code Here


                    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();
View Full Code Here

   
    @Test
    public void testSinglePanel() {
        MockProvider provider = new MockProvider();
        int panelId = 0;
        Panel panel = Mockito.mock(Panel.class);
        MockManifestation manifestation = new MockManifestation();
        Mockito.when(panel.getPanelFocusSelectionProvider()).thenReturn(provider);
        Mockito.when(panel.getWrappedManifestation()).thenReturn(manifestation);
        renderedPanels.put(Integer.valueOf(panelId), panel);
        policy = new PanelFocusTraversalPolicy(renderedPanels);
        Assert.assertSame(policy.getDefaultComponent(provider), panel);
        Assert.assertSame(policy.getFirstComponent(provider), panel);
        Assert.assertSame(policy.getLastComponent(provider), panel);
View Full Code Here

       
        panelManifestation = new MockManifestation(mockComponent, new ViewInfo(CanvasManifestation.class, "", ViewType.OBJECT));
        MCTViewManifestationInfoImpl info = new MCTViewManifestationInfoImpl();
        panelManifestation.putClientProperty(CanvasManifestation.MANIFEST_INFO, info);
       
        Panel child = new Panel(panelManifestation,Mockito.mock(PanelFocusSelectionProvider.class) ) { 
            public Rectangle getBounds() {
                return new Rectangle(2,2,1,1);
            }
        };
       
View Full Code Here

                viewManifestationInfo.addInfoProperty(ControlAreaFormattingConstants.PANEL_ORDER, String.valueOf(nextPanelId));
                // use the viewComp here instead of the master component to retrieve the actual properties for the view
                View addManifestation = CanvasViewStrategy.CANVAS_OWNED.createViewFromManifestInfo(newViewInfo, comp, canvasManifestation.getManifestedComponent(), viewManifestationInfo);
               
                addManifestation.putClientProperty(CanvasManifestation.MANIFEST_INFO, viewManifestationInfo);
                Panel panel = containerManifestation.createPanel(addManifestation, nextPanelId, containerManifestation);
                viewManifestationInfo.setDimension(panel.getPreferredSize());

                addManifestation.setNamingContext(panel);
                assert addManifestation.getNamingContext() == panel;
               
                // Add new panel info to the canvas content property list
                ExtendedProperties viewTypeProperties = containerManifestation.getViewProperties();
                viewTypeProperties.addProperty(CANVAS_CONTENT_PROPERTY, viewManifestationInfo);               
                containerManifestation.renderedPanels.put(
                                nextPanelId, panel);
                containerManifestation.canvasPanel.add(panel, new Rectangle(dropPoint, panel.getPreferredSize()));
                panels.add(panel);
                containerManifestation.changeOrder(panel, PANEL_ZORDER.FRONT);
               
                panel.getSelectionProvider().addSelectionChangeListener(selectionListener);
            }
            if (!panels.isEmpty()) {
                containerManifestation.canvasPanel.revalidate();
                containerManifestation.fireFocusPersist();
            }
View Full Code Here

        positionXSpinner.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                List<Panel> selectedPanels = managedCanvas.getSelectedPanels();
                if (selectedPanels != null && selectedPanels.size() == 1) {
                    Panel selectedPanel = selectedPanels.get(0);
                    int newXLocation = ((Integer) positionXSpinner.getValue()).intValue()
                                    - CORRECTION_OFFSET;
                    if (selectedPanel.getLocation().x != newXLocation) {
                        CanvasFormattingController.notifyXPropertyChange(newXLocation, selectedPanel);
                        managedCanvas.fireFocusPersist();
                    }
                }
            }
        });

        positionYSpinner.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                List<Panel> selectedPanels = managedCanvas.getSelectedPanels();
                if (selectedPanels != null && selectedPanels.size() == 1) {
                    Panel selectedPanel = selectedPanels.get(0);
                    int newYLocation = ((Integer) positionYSpinner.getValue()).intValue()
                                    - CORRECTION_OFFSET;
                    if (selectedPanel.getLocation().y != newYLocation) {
                        CanvasFormattingController.notifyYPropertyChange(newYLocation, selectedPanel);
                        managedCanvas.fireFocusPersist();
                    }
                }
            }
View Full Code Here

            public ExtendedProperties getViewProperties() {
                return viewProps;
            };
        };

        Panel panel = new Panel(addManifestInfo(canvas1),
                        panelFocusSelectionProvider);
        int origX = panel.getBounds().x;
        CanvasFormattingController.notifyXPropertyChange(origX + 1000, panel);
        int newX = panel.getBounds().x;
        Assert.assertFalse(origX == newX);
        Assert.assertEquals(newX, origX + 1000);

        MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation());
        Assert.assertEquals(info.getStartPoint().x, newX);
    }
View Full Code Here

            public ExtendedProperties getViewProperties() {
                return viewProps;
            };
        };

        Panel panel = new Panel(addManifestInfo(canvas1),
                        panelFocusSelectionProvider);
        int origY = panel.getBounds().y;
        CanvasFormattingController.notifyYPropertyChange(origY + 1000, panel);
        int newY = panel.getBounds().y;
        Assert.assertFalse(origY == newY);
        Assert.assertEquals(newY, origY + 1000);

        MCTViewManifestationInfo info = CanvasManifestation.getManifestationInfo(panel.getWrappedManifestation());
        Assert.assertEquals(info.getStartPoint().y, newY);
    }
View Full Code Here

TOP

Related Classes of gov.nasa.arc.mct.canvas.panel.Panel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.