13a14 > import CH.ifa.draw.contrib.AutoscrollHelper; 21d21 < import CH.ifa.draw.figures.TextTool; 36,38c36,37 < MouseListener, < MouseMotionListener, < KeyListener { --- > KeyListener, > java.awt.dnd.Autoscroll { 109,113d107 < * < */ < private transient UndoManager myUndoManager; < < /** 136a131,132 > setAutoscrolls(true); > counter++; 144d139 < setUndoManager(new UndoManager()); 151,152c146,147 < addMouseListener(this); < addMouseMotionListener(this); --- > addMouseListener(ml); > addMouseMotionListener(mml); 155a151,203 > MouseListener ml = new MouseListener() { > // listener methods we are not interested in > public void mouseClicked(MouseEvent e) {} > public void mouseEntered(MouseEvent e) {} > public void mouseExited(MouseEvent e) {} > /** > * Handles mouse down events. The event is delegated to the > * currently active tool. > * @return whether the event was handled. > */ > public void mousePressed(MouseEvent e) { > requestFocus(); // JDK1.1 > Point p = constrainPoint(new Point(e.getX(), e.getY())); > fLastClick = new Point(e.getX(), e.getY()); > tool().mouseDown(e, p.x, p.y); > checkDamage(); > } > /** > * Handles mouse up events. The event is delegated to the > * currently active tool. > * @return whether the event was handled. > */ > public void mouseReleased(MouseEvent e) { > Point p = constrainPoint(new Point(e.getX(), e.getY())); > tool().mouseUp(e, p.x, p.y); > checkDamage(); > } > }; > > MouseMotionListener mml = new MouseMotionListener() { > /** > * Handles mouse drag events. The event is delegated to the > * currently active tool. > * @return whether the event was handled. > */ > public void mouseDragged(MouseEvent e) { > // System.out.println("dragging " + myid); > Point p = constrainPoint(new Point(e.getX(), e.getY())); > tool().mouseDrag(e, p.x, p.y); > checkDamage(); > } > > /** > * Handles mouse move events. The event is delegated to the > * currently active tool. > * @return whether the event was handled. > */ > public void mouseMoved(MouseEvent e) { > // System.out.println("moved " + myid); > tool().mouseMove(e, e.getX(), e.getY()); > } > }; > 203,239d250 < * Automatically adjusts the size of view (optionally) and < * scroll the invalidated rectangle to be visible in viewport < * Params r - Rectangle to be scrolled < * bSizeChange - If true, view may be resized to accomodate "r". < */ < protected void scrollToVisible(Rectangle r, boolean bSizeChange) { < if (bSizeChange) { < // Flag for size change < boolean bChanged = false; < < // New width and height < int newWidth = r.x + r.width + SCROLL_INCR; < int newHeight = r.y + r.height + SCROLL_INCR; < < // Check the adjustments in size < if (newWidth > fViewSize.width) { < fViewSize.width = newWidth; < bChanged = true; < } < < if (newHeight > fViewSize.height) { < fViewSize.height = newHeight; < bChanged = true; < } < < // Auto size < if (bChanged) { < setSize(fViewSize); < } < } < < // Compute intersection of view size and to be scrolled rectangle < // in order to prevent scrolling beyond view size < scrollRectToVisible(r.intersection(new Rectangle(0, 0, fViewSize.width, fViewSize.height))); < } < < /** 244,252c255 < Figure f = drawing().add(figure); < < // If new figure is added, check for size and scrolling < if(f != null) { < Rectangle r = f.displayBox(); < scrollToVisible(r, true); < } < < return f; --- > return drawing().add(figure); 630,673d632 < * Handles mouse down events. The event is delegated to the < * currently active tool. < * @return whether the event was handled. < */ < public void mousePressed(MouseEvent e) { < requestFocus(); // JDK1.1 < Point p = constrainPoint(new Point(e.getX(), e.getY())); < fLastClick = new Point(e.getX(), e.getY()); < tool().mouseDown(e, p.x, p.y); < checkDamage(); < } < < /** < * Handles mouse drag events. The event is delegated to the < * currently active tool. < * @return whether the event was handled. < */ < public void mouseDragged(MouseEvent e) { < Point p = constrainPoint(new Point(e.getX(), e.getY())); < tool().mouseDrag(e, p.x, p.y); < checkDamage(); < } < < /** < * Handles mouse move events. The event is delegated to the < * currently active tool. < * @return whether the event was handled. < */ < public void mouseMoved(MouseEvent e) { < tool().mouseMove(e, e.getX(), e.getY()); < } < < /** < * Handles mouse up events. The event is delegated to the < * currently active tool. < * @return whether the event was handled. < */ < public void mouseReleased(MouseEvent e) { < Point p = constrainPoint(new Point(e.getX(), e.getY())); < tool().mouseUp(e, p.x, p.y); < checkDamage(); < } < < /** 682c641,643 < Command cmd = new DeleteCommand("Delete", this); --- > Command cmd = new DeleteCommand("Delete", editor()); > // cmd.viewSelectionChanged(this); > if(cmd.isExecutable()) { 684a646 > } 734,742d695 < * Determines whether to auto scroll damaged rectangle. < * Override if you do not want drag scroll mechanism. < * By default this method returns true. < */ < protected boolean doDragScroll() { < return true; < } < < /** 756,768c709,710 < if (fDamage == null) { < // repaint(); < } < else { < < // TextFigures have problems with scrolling: avoid scrolling them < // TextTool does not call checkDamage at the moment to avoid scrolling < // if (doDragScroll() && !(tool() instanceof TextTool)) { < if (doDragScroll() ) { < scrollToVisible(fDamage, false); < } < < repaint(1, fDamage.x, fDamage.y, fDamage.width, fDamage.height); --- > if (fDamage != null) { > repaint(fDamage.x, fDamage.y, fDamage.width, fDamage.height); 959,962c901,904 < // listener methods we are not interested in < public void mouseEntered(MouseEvent e) {} < public void mouseExited(MouseEvent e) {} < public void mouseClicked(MouseEvent e) {} --- > public boolean isInteractive() { > return true; > } > 982,983c924,925 < protected void setUndoManager(UndoManager newUndoManager) { < myUndoManager = newUndoManager; --- > public int getDefaultDNDActions() { > return java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE; 986,987c928,936 < public UndoManager getUndoManager() { < return myUndoManager; --- > > /***** Autoscroll support *****/ > private ASH ash = new ASH(10); > > public void autoscroll(java.awt.Point p) { > ash.autoscroll(p); > } > public Insets getAutoscrollInsets() { > return ash.getAutoscrollInsets(); 988a938,958 > class ASH extends AutoscrollHelper { > public ASH(int margin) { > super(margin); > } > public Dimension getSize() { > return StandardDrawingView.this.getSize(); > } > public Rectangle getVisibleRect() { > return StandardDrawingView.this.getVisibleRect(); > } > public void scrollRectToVisible(Rectangle aRect) { > StandardDrawingView.this.scrollRectToVisible(aRect); > } > } > > public String toString() { > return "DrawingView Nr: " + myCounter; > } > > static int counter; > int myCounter = counter;