/** * ------------------------------------------------------ Deletes and copies the parts that are * selected in the given to this clipboard. * * @param editor the editor that contians the selected parts to cut * @see MiEditor#getSelectedParts * @see MiPart#isSelected ------------------------------------------------------ */ public void cutSelectionToClipBoard(MiEditor editor) { MiParts selectedParts = new MiParts(); editor.getSelectedParts(selectedParts); for (int i = 0; i < selectedParts.size(); ++i) { if (!selectedParts.get(i).isCopyable()) { selectedParts.removeElementAt(i); --i; } } for (int i = 0; i < selectedParts.size(); ++i) { MiPart part = selectedParts.elementAt(i); editor.deSelect(part); } MiNestedTransaction nestedTransaction = new MiNestedTransaction(Mi_CUT_DISPLAY_NAME); MiSystem.getTransactionManager().startTransaction(nestedTransaction); // MiDeletePartsCommand deleteCmd = new MiDeletePartsCommand(editor, selectedParts, true); MiParts pastableSelectedParts = MiUtility.makeCopyOfNetwork(selectedParts); MiDeletePartsCommand deleteCmd = MiSystem.getCommandBuilder().getDeletePartsCommand().create(editor, selectedParts, true); MiChangeContentsTransaction replaceCmd = new MiChangeContentsTransaction(this, pastableSelectedParts); MiSystem.getTransactionManager().appendTransaction(Mi_CUT_DISPLAY_NAME, replaceCmd, deleteCmd); deleteCmd.doit(editor, true); replaceCmd.doit(this, pastableSelectedParts, true); dispatchAction(Mi_CLIPBOARD_NOW_HAS_DATA_ACTION); MiSystem.getTransactionManager().commitTransaction(nestedTransaction); }
// Do not allow the one and only layer to be deleted. protected void updateLayerAttributesState() { int numberOfDeletableLayers = 0; for (int i = 0; i < editor.getNumberOfLayers(); ++i) { MiPart layer = editor.getLayer(i); MiLayerAttributes layerAttributes = (MiLayerAttributes) layer.getResource(MiLayerAttributes.Mi_LAYER_ATTRIBUTES_RESOURCE_NAME); if ((layerAttributes != null) && (layerAttributes.getEditability() != MiLayerAttributes.Mi_LAYER_NEVER_EDITABLE)) { ++numberOfDeletableLayers; } } boolean deletable = numberOfDeletableLayers > 1; for (int i = 0; i < editor.getNumberOfLayers(); ++i) { MiPart layer = editor.getLayer(i); MiLayerAttributes layerAttributes = (MiLayerAttributes) layer.getResource(MiLayerAttributes.Mi_LAYER_ATTRIBUTES_RESOURCE_NAME); if (layerAttributes != null) { layerAttributes.setDeletable(deletable); layerAttributes.updateCommandManagerState(); } } }
/** * ------------------------------------------------------ Sets whether the order of the MiParts in * the layers are kept such that MiConnections are at the begining of the list. This is useful * when and one does not want connections to be drawn in front of the nodes. * * @param flag true if connections to be drawn first * @see MiConnection#setTruncateLineAtEndPointPartBoundries * @see MiContainer#setKeepConnectionsBelowNodes * @see #getKeepConnectionsBelowNodes ------------------------------------------------------ */ public void setKeepConnectionsBelowNodes(boolean flag) { keepConnectionsBelowNodes = flag; for (int i = 0; i < editor.getNumberOfLayers(); ++i) { if (editor.getLayer(i) instanceof MiContainer) { ((MiContainer) editor.getLayer(i)).setKeepConnectionsBelowNodes(flag); } } }
public void setTargetEditor(MiEditor editor) { if (mouseLocationEditor != null) { mouseLocationEditor.removeEventHandler(mouseLocationMonitor); } mouseLocationEditor = editor; mouseLocationMonitor = new MiMouseLocationDisplayMonitor(getField(X_FIELD_INDEX), getField(Y_FIELD_INDEX)); mouseLocationEditor.appendEventHandler(mouseLocationMonitor); }
public void appendNewLayer() { MiContainer layer = new MiLayer(); layer.setKeepConnectionsBelowNodes(keepConnectionsBelowNodes); layer.setLayout(new MiSizeOnlyLayout()); // layer.setName("Layer " + editor.getNumberOfLayers()); editor.appendLayer(layer); }
public boolean processAction(MiiAction action) { MiPart layer = (MiPart) action.getActionSystemInfo(); if (action.hasActionType(Mi_EDITOR_LAYER_ADDED_ACTION)) { appendModelEntity(new MiLayerAttributes(layer)); updateLayerAttributesState(); } else if (action.hasActionType(Mi_EDITOR_LAYER_REMOVED_ACTION)) { MiLayerAttributes layerAttributes = (MiLayerAttributes) layer.getResource(MiLayerAttributes.Mi_LAYER_ATTRIBUTES_RESOURCE_NAME); if (layerAttributes != null) { removeModelEntity(layerAttributes); } updateLayerAttributesState(); } else if (action.hasActionType(Mi_EDITOR_LAYER_ORDER_CHANGED_ACTION)) { removeAllModelEntities(); for (int i = 0; i < editor.getNumberOfLayers(); ++i) { layer = editor.getLayer(i); MiLayerAttributes layerAttributes = (MiLayerAttributes) layer.getResource(MiLayerAttributes.Mi_LAYER_ATTRIBUTES_RESOURCE_NAME); if (layerAttributes == null) { layerAttributes = new MiLayerAttributes(layer); } appendModelEntity(layerAttributes); } updateLayerAttributesState(); } else if (action.hasActionType(Mi_EDITOR_CURRENT_LAYER_CHANGED_ACTION)) { MiPart currentLayer = editor.getCurrentLayer(); MiModelEntityList list = getModelEntities(); for (int i = 0; i < list.size(); ++i) { MiLayerAttributes atts = (MiLayerAttributes) list.elementAt(i); if (atts.getLayer() == currentLayer) atts.setCurrent(true); else if (atts.isCurrent()) atts.setCurrent(false); } updateLayerAttributesState(); } return (true); }
public MiLayerManager(MiEditor editor) { this.editor = editor; editor.setHasLayers(true); for (int i = 0; i < editor.getNumberOfLayers(); ++i) { MiPart layer = editor.getLayer(i); MiLayerAttributes layerAttributes = new MiLayerAttributes(layer); appendModelEntity(layerAttributes); } editor.appendActionHandler(this, Mi_EDITOR_LAYER_ADDED_ACTION); editor.appendActionHandler(this, Mi_EDITOR_LAYER_REMOVED_ACTION); editor.appendActionHandler(this, Mi_EDITOR_LAYER_ORDER_CHANGED_ACTION); editor.appendActionHandler(this, Mi_EDITOR_CURRENT_LAYER_CHANGED_ACTION); }
/** * ------------------------------------------------------ Copies the parts that are selected in * the given to this clipboard. * * @param editor the editor that contians the selected parts to copy * @see MiEditor#getSelectedParts * @see MiPart#isSelected ------------------------------------------------------ */ public void copySelectionToClipBoard(MiEditor editor) { MiParts selectedObjects = new MiParts(); editor.getSelectedParts(selectedObjects); for (int i = 0; i < selectedObjects.size(); ++i) { if (!selectedObjects.get(i).isCopyable()) { selectedObjects.removeElementAt(i); --i; } } selectedObjects = MiUtility.makeCopyOfNetwork(selectedObjects); MiChangeContentsTransaction cmd = new MiChangeContentsTransaction(this, selectedObjects); cmd.doit(this, selectedObjects, true); MiSystem.getTransactionManager().appendTransaction(cmd); dispatchAction(Mi_CLIPBOARD_NOW_HAS_DATA_ACTION); }
/** * ------------------------------------------------------ Pastes the graphics from this clipBoard * into the given editor translated by the given amount * * @param editor the target editor * @param translation the translation amount * ------------------------------------------------------ */ public void pasteFromClipBoard(MiEditor editor, MiVector translation) { MiParts parts = new MiParts(); for (int i = 0; i < getNumberOfParts(); ++i) { parts.addElement(getPart(i)); } HashMap mapOfConnToItsPoints = new HashMap(); // MiDebug.println("pasteFromClipBoard parts = " + parts); parts = MiUtility.makeCopyOfNetwork(parts); // MiDebug.println("2 pasteFromClipBoard parts = " + parts); // Save up where the connections lie now, before their nodes are // placed which tends to wack out the connection's orientation for (int i = 0; i < parts.size(); ++i) { MiPart obj = parts.elementAt(i); if (obj instanceof MiConnection) { ArrayList listOfPoints = new ArrayList(); for (int j = 0; j < obj.getNumberOfPoints(); ++j) { listOfPoints.add(obj.getPoint(j)); } mapOfConnToItsPoints.put(obj, listOfPoints); } } MiNestedTransaction nestedTransaction = new MiNestedTransaction(Mi_PASTE_DISPLAY_NAME); MiSystem.getTransactionManager().startTransaction(nestedTransaction); // Assume makeCopyOfNetwork list has nodes come first, followed by connections for (int i = 0; i < parts.size(); ++i) { MiPart obj = parts.elementAt(i); if (obj instanceof MiConnection) { obj.validateLayout(); MiiLayout layout = obj.getLayout(); obj.setLayout(null); ArrayList listOfPoints = (ArrayList) mapOfConnToItsPoints.get(obj); MiVector connTranslation = new MiVector(translation); MiConnection conn = (MiConnection) obj; int startPoint = 0; if (conn.getSource() != null) { startPoint = 1; connTranslation.x = conn.getPoint(0).x - ((MiPoint) listOfPoints.get(0)).x; connTranslation.y = conn.getPoint(0).y - ((MiPoint) listOfPoints.get(0)).y; } int endPoint = listOfPoints.size(); if (conn.getDestination() != null) { // If we are not going to truncate the number of points in the // connection to what it was, then the last point of of the // connection ends at a node, so we do not need or want to set // it, so decrease endPoint, which is the last point we are to modify if (conn.getNumberOfPoints() == listOfPoints.size()) { --endPoint; } int lastPoint = conn.getNumberOfPoints() - 1; connTranslation.x = conn.getPoint(lastPoint).x - ((MiPoint) listOfPoints.get(listOfPoints.size() - 1)).x; connTranslation.y = conn.getPoint(lastPoint).y - ((MiPoint) listOfPoints.get(listOfPoints.size() - 1)).y; } // Conns are now translatable so this has been done... // connTranslation = new MiVector(); conn.getGraphics().setNumberOfPoints(listOfPoints.size()); for (int j = startPoint; j < endPoint; ++j) { MiPoint pt = (MiPoint) listOfPoints.get(j); obj.setPoint(j, pt.x + connTranslation.x, pt.y + connTranslation.y); } obj.setLayout(layout); } // MiDebug.println("paste obj = " + obj); MiDataTransferOperation transfer = new MiDataTransferOperation(obj); MiPoint targetPosition = obj.getCenter(); targetPosition.translate(translation); transfer.setData(obj); transfer.setTarget(editor.getCurrentLayer()); transfer.setLookTargetPosition(targetPosition); transfer.setLookTargetBounds(obj.getBounds().translate(translation)); transfer.setDataFormat(MiDataTransferOperation.getCommonDataFormat(this, editor)); editor.doImport(transfer); editor.dispatchAction(Mi_DATA_IMPORT_ACTION, transfer); } // MiDeletePartsCommand createCmd = new MiDeletePartsCommand(editor, parts, false); // MiDebug.println("3 pasteFromClipBoard parts = " + parts); MiDeletePartsCommand createCmd = MiSystem.getCommandBuilder().getDeletePartsCommand().create(editor, parts, false); MiSystem.getTransactionManager() .appendTransaction(new MiNestedTransaction(Mi_PASTE_DISPLAY_NAME, createCmd)); MiSystem.getTransactionManager().commitTransaction(nestedTransaction); }
/** * ------------------------------------------------------ Pastes the parts in this clipboard to * the given editor. The location the (center of) parts are copied to is the cursor location (if * the cursor is within the editor) oor the center of the editor (if not). * * @param editor the editor to copy parts into. * @see MiEditor#getMousePosition ------------------------------------------------------ */ public void pasteFromClipBoard(MiEditor editor) { if (editor.getWorldBounds().intersects(editor.getMousePosition().getCenter())) pasteFromClipBoard(editor, editor.getMousePosition().getCenter()); else pasteFromClipBoard(editor, editor.getWorldBounds().getCenter()); }
public void deleteSelf() { if (mouseLocationEditor != null) mouseLocationEditor.removeEventHandler(mouseLocationMonitor); super.deleteSelf(); }
public MiLayerAttributes getLayerAttributes(int index) { MiPart layer = editor.getLayer(index); return ((MiLayerAttributes) layer.getResource(MiLayerAttributes.Mi_LAYER_ATTRIBUTES_RESOURCE_NAME)); }