@Override public void buttonClicked(int buttonCode) { super.buttonClicked(buttonCode); if (isEdgePostProcessRequested()) { postProcessEdge2(newEdge); } }
/* * @see org.tigris.gef.base.SelectionButtons#paint(java.awt.Graphics) */ @Override public void paint(Graphics g) { final Mode topMode = Globals.curEditor().getModeManager().top(); if (!(topMode instanceof ModePlace)) { // If the user has selected ModePlace either by a diagram // tool or AddToDiagram then we don't want to show the // clarifiers. ((Clarifiable) getContent()).paintClarifiers(g); } super.paint(g); }
/* * @see org.tigris.gef.base.Selection#dragHandle(int, int, int, int, * org.tigris.gef.presentation.Handle) */ public void dragHandle(int mX, int mY, int anX, int anY, Handle hand) { // Don't allow drag outside of bounds of diagram mX = Math.max(mX, 0); mY = Math.max(mY, 0); if (hand.index < 10) { setPaintButtons(false); super.dragHandle(mX, mY, anX, anY, hand); return; } if (!isDraggableHandle(hand.index)) { return; } int cx = getContent().getX(), cy = getContent().getY(); int cw = getContent().getWidth(), ch = getContent().getHeight(); int bx = mX, by = mY; // Remember what handle was clicked for the case where the drag // is released over empty space button = hand.index; switch (hand.index) { case TOP: by = cy; bx = cx + cw / 2; break; case BOTTOM: by = cy + ch; bx = cx + cw / 2; break; case LEFT: by = cy + ch / 2; bx = cx; break; case RIGHT: by = cy + ch / 2; bx = cx + cw; break; case LOWER_LEFT: by = cy + ch; bx = cx; break; default: LOG.log(Level.WARNING, "invalid handle number"); break; } Object nodeType = getNewNodeType(hand.index); Object edgeType = getNewEdgeType(hand.index); boolean reverse = isReverseEdge(hand.index); if (edgeType != null && nodeType != null) { Editor ce = Globals.curEditor(); ModeCreateEdgeAndNode m = getNewModeCreateEdgeAndNode(ce, edgeType, isEdgePostProcessRequested(), this); m.setup((FigNode) getContent(), getContent().getOwner(), bx, by, reverse); ce.pushMode(m); } }
/** * Compute handle selection, if any, from cursor location. * * @param cursor cursor point represented by a 0-size rectangle * @param h handle in which to return selected Handle information (output parameter). A handle * index of -1 indicates that the cursor is not over any handle. * <p>If GEF had any API documentation you could see the following: * @see org.tigris.gef.base.SelectionResize#hitHandle(java.awt.Rectangle, * org.tigris.gef.presentation.Handle) */ public void hitHandle(Rectangle cursor, Handle h) { super.hitHandle(cursor, h); if (h.index != -1) { // super implementation found a hit return; } if (!isPaintButtons()) { return; } Icon[] icons = getIcons(); if (icons == null) { return; } Editor ce = Globals.curEditor(); SelectionManager sm = ce.getSelectionManager(); if (sm.size() != 1) { return; } ModeManager mm = ce.getModeManager(); if (mm.includes(ModeModify.class) && getPressedButton() == -1) { return; } int cx = getContent().getX(); int cy = getContent().getY(); int cw = getContent().getWidth(); int ch = getContent().getHeight(); /* * Crazy numbering scheme at work here. Here's how the handle numbers * are laid out. Values 0-7 are defined by GEF and go left to * right, top to bottom (ie not clockwise or counterclockwise). * Values 10-14 zigzag North, South, West, East, Southwest. * If you can correctly guess where 15 will go, you should buy * a lottery ticket immediately. * <pre> * 10 * 0-------1-------2 * | | * 12 3 4 13 * | | * 14 5-------6-------7 * 11 * </pre> */ if (icons[0] != null && hitAbove(cx + cw / 2, cy, icons[0].getIconWidth(), icons[0].getIconHeight(), cursor)) { h.index = TOP; } else if (icons[1] != null && hitBelow( cx + cw / 2, cy + ch, icons[1].getIconWidth(), icons[1].getIconHeight(), cursor)) { h.index = BOTTOM; } else if (icons[2] != null && hitLeft(cx, cy + ch / 2, icons[2].getIconWidth(), icons[2].getIconHeight(), cursor)) { h.index = LEFT; } else if (icons[3] != null && hitRight( cx + cw, cy + ch / 2, icons[3].getIconWidth(), icons[3].getIconHeight(), cursor)) { h.index = RIGHT; } else if (icons[4] != null && hitLeft(cx, cy + ch, icons[4].getIconWidth(), icons[4].getIconHeight(), cursor)) { h.index = LOWER_LEFT; } else { h.index = -1; } if (h.index == -1) { h.instructions = getInstructions(15); } else { h.instructions = getInstructions(h.index); } }