public int processEvent(MiEvent event) { if ((event.type == Mi_WINDOW_EXIT_EVENT) || (event.type == Mi_MOUSE_EXIT_EVENT)) { setVisible(false); visible = false; } else if ((event.type != Mi_IDLE_EVENT) && (event.type != Mi_TIMER_TICK_EVENT)) { if (!cursorIsAttached) { event.editor.appendAttachment(cursor); cursorIsAttached = true; } boolean makeVisible = true; if (showOnlyDuringTheseEventStates != null) { for (int i = 0; i < showOnlyDuringTheseEventStates.size(); ++i) { makeVisible = false; MiEvent validEvent = (MiEvent) showOnlyDuringTheseEventStates.get(i); if (((validEvent.getModifiers() == event.getModifiers()) || (validEvent.getModifiers() == Mi_ANY_MODIFIERS_HELD_DOWN)) && (validEvent.getMouseButtonState() == event.getMouseButtonState())) { makeVisible = true; break; } } } if (hideDuringTheseEventStates != null) { for (int i = 0; i < hideDuringTheseEventStates.size(); ++i) { MiEvent validEvent = (MiEvent) hideDuringTheseEventStates.get(i); if (((validEvent.getModifiers() == event.getModifiers()) || (validEvent.getModifiers() == Mi_ANY_MODIFIERS_HELD_DOWN)) && (validEvent.getMouseButtonState() == event.getMouseButtonState())) { makeVisible = false; break; } } } if (makeVisible) { event.editor.getWorldBounds(editorWorld); if ((!event.worldPt.equals(cursorPt)) || (!editorWorld.equals(cursorWorldBounds))) { cursorPt.copy(event.worldPt); cursorWorldBounds.copy(editorWorld); setCursor(cursorPt, cursorWorldBounds); if (!visible) { setVisible(true); visible = true; } } } else { setVisible(false); visible = false; } } return (Mi_PROPOGATE_EVENT); }
public int processEvent(MiEvent event) { if ((isEnabled()) && (event.getType() != MiEvent.Mi_TIMER_TICK_EVENT) && (event.getType() != MiEvent.Mi_IDLE_EVENT)) { tmpPoint.copy(event.worldPt); MiPageManager pageManager = event.editor.getPageManager(); String unitsName = ""; if (pageManager != null) { pageManager.transformWorldPointToUnitsPoint(tmpPoint); unitsName = pageManager.getUnits().getAbbreviation(); } if (tmpPoint.x != lastX) { lastX = tmpPoint.x; xPos.setValue("X: " + Utility.toShortString(tmpPoint.x) + " " + unitsName); } if (tmpPoint.y != lastY) { lastY = tmpPoint.y; yPos.setValue("Y: " + Utility.toShortString(tmpPoint.y) + " " + unitsName); } } return (Mi_PROPOGATE_EVENT); }
/** * ------------------------------------------------------ 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); }
// Return true if associated line should be truncated at basePoint public boolean calcNewLineEndPoint( MiRenderer renderer, double angle, int style, MiDistance size, MiPoint basePoint) { boolean truncateAssocLine = false; double sinAngle = Math.sin(angle); double cosAngle = Math.cos(angle); MiDistance length = size; switch (style) { case Mi_NONE: truncateAssocLine = false; break; case Mi_TRIANGLE_VIA_LINE_END_STYLE: case Mi_FILLED_TRIANGLE_VIA_LINE_END_STYLE: length = size; truncateAssocLine = false; break; case Mi_CIRCLE_VIA_LINE_END_STYLE: case Mi_FILLED_CIRCLE_VIA_LINE_END_STYLE: case Mi_SQUARE_VIA_LINE_END_STYLE: case Mi_FILLED_SQUARE_VIA_LINE_END_STYLE: length = size / 2; truncateAssocLine = false; break; case Mi_STROKED_ARROW_LINE_END_STYLE: case Mi_FILLED_ARROW_LINE_END_STYLE: case Mi_3FEATHER_LINE_END_STYLE: // LONG_length = 2 * size; length = size; truncateAssocLine = false; break; case Mi_FILLED_TRIANGLE_LINE_END_STYLE: case Mi_TRIANGLE_LINE_END_STYLE: case Mi_2FEATHER_LINE_END_STYLE: // LONG_length = 2 * size; length = size; truncateAssocLine = true; break; case Mi_DIAMOND_LINE_END_STYLE: length = 2 * size; truncateAssocLine = true; break; case Mi_FILLED_DIAMOND_LINE_END_STYLE: length = 2 * size; truncateAssocLine = true; break; case Mi_FILLED_CIRCLE_LINE_END_STYLE: case Mi_FILLED_SQUARE_LINE_END_STYLE: length = size; truncateAssocLine = false; break; case Mi_CIRCLE_LINE_END_STYLE: case Mi_SQUARE_LINE_END_STYLE: length = size; truncateAssocLine = true; break; } basePoint.x = basePoint.x - length * cosAngle; basePoint.y = basePoint.y - length * sinAngle; return (truncateAssocLine); }