/** Handles mouse down events and starts the corresponding tracker. */ public void mouseDown(MouseEvent e, int x, int y) { // on MS-Windows NT: AWT generates additional mouse down events // when the left button is down && right button is clicked. // To avoid dead locks we ignore such events if (fChild != null) { return; } view().freezeView(); Handle handle = view().findHandle(e.getX(), e.getY()); if (handle != null) { fChild = createHandleTracker(view(), handle); } else { Figure figure = drawing().findFigure(e.getX(), e.getY()); if (figure != null) { fChild = createDragTracker(figure); } else { if (!e.isShiftDown()) { view().clearSelection(); } fChild = createAreaTracker(); } } fChild.mouseDown(e, x, y); fChild.activate(); }
public ToolButton(PaletteListener listener, String iconName, String name, Tool tool) { super(listener); tool.addToolListener(this); setEnabled(tool.isUsable()); // use a Mediatracker to ensure that all the images are initially loaded Iconkit kit = Iconkit.instance(); if (kit == null) { throw new JHotDrawRuntimeException("Iconkit instance isn't set"); } Image im[] = new Image[3]; im[0] = kit.loadImageResource(iconName + "1.gif"); im[1] = kit.loadImageResource(iconName + "2.gif"); im[2] = kit.loadImageResource(iconName + "3.gif"); MediaTracker tracker = new MediaTracker(this); for (int i = 0; i < 3; i++) { tracker.addImage(im[i], i); } try { tracker.waitForAll(); } catch (Exception e) { // ignore exception } fIcon = new PaletteIcon(new Dimension(24, 24), im[0], im[1], im[2]); fTool = tool; fName = name; setIcon(new ImageIcon(im[0])); setPressedIcon(new ImageIcon(im[1])); setSelectedIcon(new ImageIcon(im[2])); setToolTipText(name); }
/** Handles mouse up events. The events are forwarded to the current tracker. */ public void mouseUp(MouseEvent e, int x, int y) { view().unfreezeView(); if (fChild != null) { // JDK1.1 doesn't guarantee mouseDown, mouseDrag, mouseUp fChild.mouseUp(e, x, y); fChild.deactivate(); fChild = null; } }
private void setTool(Tool t, String name) { if (fTool != null) { fTool.deactivate(); } fTool = t; if (fTool != null) { showStatus(name); fTool.activate(); } }
/** Handles mouse drag events. The events are forwarded to the current tracker. */ public void mouseDrag(MouseEvent e, int x, int y) { if (fChild != null) { // JDK1.1 doesn't guarantee mouseDown, mouseDrag, mouseUp fChild.mouseDrag(e, x, y); } }