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); }
/** * ------------------------------------------------------ Lays out the container's parts and it's * background shape. * * @overrides MiLayout.doLayout ------------------------------------------------------ */ protected void doLayout() { if (!autoLayoutEnabled) return; MiBounds contents = MiBounds.newBounds(); MiBounds oldContents = MiBounds.newBounds(); MiBounds containerBounds = MiBounds.newBounds(); MiBounds tmp = MiBounds.newBounds(); MiSize size = MiSize.newSize(); // ------------------------------------------------------- // Iterate through all parts of this container... set their // size to their preferredSize if this container does not // have a layout which has already done so. Also collect // the union of their bounds into 'contents'. // ------------------------------------------------------- for (int i = 0; i < getNumberOfParts(); ++i) { if (getPart(i).isVisible()) { // ------------------------------------------------------- // If contents have not already been laid out... // ------------------------------------------------------- if ((getLayout() == null) || (!getLayout().determinesPreferredAndMinimumSizes())) { getPart(i).getPreferredSize(size); getPart(i).setSize(size); } getPart(i).getBounds(tmp); contents.union(tmp); } } // ------------------------------------------------------- // Set 'oldContents' to this current bounds of all of this // container's parts. This will be used later to see it // we have changed the size of this container. 'contents' // will be modified by this layout routine as per the layout // constraints applied to this container. // ------------------------------------------------------- oldContents.copy(contents); // ------------------------------------------------------- // Get the inner bounds of this container into 'container'. // ------------------------------------------------------- MiBounds container = getInnerBounds(containerBounds); if (container.isReversed()) { getPreferredSize(size); replaceBounds(new MiBounds(size)); container = getInnerBounds(containerBounds); } // ------------------------------------------------------- // Set the bounds to the center of the inner bounds. // ------------------------------------------------------- contents.setCenterX(container.getCenterX()); contents.setCenterY(container.getCenterY()); // ------------------------------------------------------- // Expand the bounds to the size of the inner bounds, if // so specified by the elementSizing contraints. // ------------------------------------------------------- if (getElementHSizing() == Mi_EXPAND_TO_FILL) contents.setWidth(container.getWidth()); else if (getElementVSizing() == Mi_EXPAND_TO_FILL) contents.setHeight(container.getHeight()); // ------------------------------------------------------- // Translate the bounds in a horizontal direction if so // specified by the elementHJustification contraint. // ------------------------------------------------------- int elementHJustification = getElementHJustification(); if (elementHJustification == Mi_LEFT_JUSTIFIED) contents.translateXminTo(container.getXmin()); else if (elementHJustification == Mi_RIGHT_JUSTIFIED) contents.translateXmaxTo(container.getXmax()); else if (elementHJustification == Mi_CENTER_JUSTIFIED) contents.setCenterX(container.getCenterX()); else if (elementHJustification == Mi_JUSTIFIED) contents.setCenterX(container.getCenterX()); // ------------------------------------------------------- // Modify the bounds to stay within the inner bounds as // held in the 'container' variable. // ------------------------------------------------------- if (contents.getXmin() < container.getXmin()) contents.translateXminTo(container.getXmin()); if (contents.getXmax() > container.getXmax()) contents.translateXmaxTo(container.getXmax()); if (contents.getXmin() < container.getXmin()) contents.setXmin(container.getXmin()); // ------------------------------------------------------- // Translate the bounds in a vertical direction if so // specified by the elementVJustification contraint. // ------------------------------------------------------- int elementVJustification = getElementVJustification(); if (elementVJustification == Mi_BOTTOM_JUSTIFIED) contents.translateYminTo(container.getYmin()); else if (elementVJustification == Mi_TOP_JUSTIFIED) contents.translateYmaxTo(container.getYmax()); else if (elementVJustification == Mi_CENTER_JUSTIFIED) contents.setCenterY(container.getCenterY()); else if (elementVJustification == Mi_JUSTIFIED) contents.setCenterY(container.getCenterY()); // ------------------------------------------------------- // Modify the bounds to stay within the inner bounds as // held in the 'container' variable. // ------------------------------------------------------- if (container.getYmin() > contents.getYmin()) contents.translateYminTo(container.getYmin()); if (container.getYmax() < contents.getYmax()) contents.translateYmaxTo(container.getYmax()); if (container.getYmin() > contents.getYmin()) contents.setYmin(container.getYmin()); // ------------------------------------------------------- // If we have changed the bounds in some way... // ------------------------------------------------------- if (!oldContents.equals(contents)) { // ------------------------------------------------------- // Calculate how much we have to translate the parts... // ------------------------------------------------------- MiDistance tx = contents.getCenterX() - oldContents.getCenterX(); MiDistance ty = contents.getCenterY() - oldContents.getCenterY(); // ------------------------------------------------------- // If there are no expand-to-fill contraints... // ------------------------------------------------------- if ((getElementHSizing() != Mi_EXPAND_TO_FILL) && (getElementVSizing() != Mi_EXPAND_TO_FILL)) { // ------------------------------------------------------- // Just translate all of the parts and we are done... // ------------------------------------------------------- for (int i = 0; i < getNumberOfParts(); ++i) { getPart(i).translate(tx, ty); } } else { // ------------------------------------------------------- // There is an expand-to-fill contraint, we need to scale // the parts... calculate the scale factor for each dimension. // ------------------------------------------------------- MiPoint center = contents.getCenter(); MiScale scale = new MiScale( contents.getWidth() / oldContents.getWidth(), contents.getHeight() / oldContents.getHeight()); if (getElementHSizing() != Mi_EXPAND_TO_FILL) scale.x = 1; if (getElementVSizing() != Mi_EXPAND_TO_FILL) scale.y = 1; // ------------------------------------------------------- // Iterate through the parts, translating and scaling // ------------------------------------------------------- for (int i = 0; i < getNumberOfParts(); ++i) { getPart(i).translate(tx, ty); getPart(i).scale(center, scale); } } } // ------------------------------------------------------- // Release all the bounds we allocated above // ------------------------------------------------------- MiBounds.freeBounds(contents); MiBounds.freeBounds(oldContents); MiBounds.freeBounds(containerBounds); MiBounds.freeBounds(tmp); MiSize.freeSize(size); }