21,21c14,14 < import CH.ifa.draw.figures.TextTool; --- > import CH.ifa.draw.contrib.AutoscrollHelper; 35a36,37 > KeyListener, > java.awt.dnd.Autoscroll { 36,38d35 < MouseListener, < MouseMotionListener, < KeyListener { 109,113d107 < * < */ < private transient UndoManager myUndoManager; < < /** 136a131,132 > setAutoscrolls(true); > counter++; 144,144d139 < setUndoManager(new UndoManager()); 150a146,147 > addMouseListener(ml); > addMouseMotionListener(mml); 151,152d145 < addMouseListener(this); < addMouseMotionListener(this); 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))); < } < < /** 243a255,255 > return drawing().add(figure); 244,252d254 < 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; 629a151,178 > 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(); > } > }; 630,640d150 < * 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(); < } 641,641c179,179 < --- > 641a180,191 > 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(); > } 642,651d179 < /** < * 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(); < } 652a193,202 > /** > * 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()); > } > }; 652,652c192,192 < --- > 653,660d192 < /** < * 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()); < } 661,661c203,203 < --- > 662,673d203 < /** < * 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(); < } < < /** 682a642,643 > // cmd.viewSelectionChanged(this); > if(cmd.isExecutable()) { 682,682c641,641 < Command cmd = new DeleteCommand("Delete", this); --- > Command cmd = new DeleteCommand("Delete", editor()); 684a646,646 > } 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; < } < < /** 755a709,709 > if (fDamage != null) { 756,767d708 < 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); < } < 768,768c710,710 < repaint(1, fDamage.x, fDamage.y, fDamage.width, fDamage.height); --- > repaint(fDamage.x, fDamage.y, fDamage.width, fDamage.height); 958a901,904 > public boolean isInteractive() { > return true; > } > 959,962d900 < // listener methods we are not interested in < public void mouseEntered(MouseEvent e) {} < public void mouseExited(MouseEvent e) {} < public void mouseClicked(MouseEvent e) {} 981a924,925 > public int getDefaultDNDActions() { > return java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE; 982,983d923 < protected void setUndoManager(UndoManager newUndoManager) { < myUndoManager = newUndoManager; 985a928,936 > > /***** Autoscroll support *****/ > private ASH ash = new ASH(10); > > public void autoscroll(java.awt.Point p) { > ash.autoscroll(p); > } > public Insets getAutoscrollInsets() { > return ash.getAutoscrollInsets(); 986,987d927 < public UndoManager getUndoManager() { < return myUndoManager; 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;