Package javax.swing.undo

Examples of javax.swing.undo.CompoundEdit


            meanDistance+= bounds.x - (previousBounds.x + previousBounds.width);
        }
        meanDistance/=selection.size()-1;

        // Trnaslate shapes
        CompoundEdit ce = new CompoundEdit();

        Shape shape, previousShape;
        for(int i=1; i<selection.size(); i++) {
            ElementSelection ss = ((ElementSelection)selection.get(i));
            shape = ss.getShape();
            previousShape= ((ElementSelection)selection.get(i-1)).getShape();
            int dx = previousShape.getBounds().x + previousShape.getBounds().width + meanDistance  - shape.getBounds().x;

            ss.translateShape(dx,0);
            if(ce!=null){
                ce.addEdit(ss.translateShapeEnd());
            }

        }
        ce.end();

        DiagramComponent dc = getElementContainer().getComponent();
        dc.fireUndoableEditUpdate(new UndoableEditEvent(dc, ce));
        dc.repaint();
    }
View Full Code Here


            meanDistance+= bounds.y - (previousBounds.y + previousBounds.height);
        }
        meanDistance/=selection.size()-1;

        // Translate shapes
        CompoundEdit ce = new CompoundEdit();
        Shape shape, previousShape;
        for(int i=1; i<selection.size(); i++) {
            ElementSelection ss = ((ElementSelection)selection.get(i));
            shape = ss.getShape();
            previousShape= ((ElementSelection)selection.get(i-1)).getShape();

            int dy = previousShape.getBounds().y + previousShape.getBounds().height + meanDistance  - shape.getBounds().y;

            ss.translateShape(0, dy);
            if(ce!=null){
                ce.addEdit(ss.translateShapeEnd());
            }

        }
        ce.end();

        DiagramComponent dc = getElementContainer().getComponent();
        dc.fireUndoableEditUpdate(new UndoableEditEvent(dc, ce));
        dc.repaint()
    }
View Full Code Here

        }

        // If some properties have changed, apply them to all shapes

        if (!changedProperties.isEmpty()){
            CompoundEdit shapesEdit = new CompoundEdit();

            for(int i=0;i<shapes.size(); i++){
                AbstractShape shape = (AbstractShape)shapes.get(i);

                // Merge the changes with all shape properties before
                ChangedProperties shapeProperties = new ChangedProperties();
                String[] shapePropertiesName = shape.getPropertyNames();

                for(int j=0; j < shapePropertiesName.length; j++){
                    String property = shapePropertiesName[j];

                    if (changedProperties.contains(property)){
                        shapeProperties.setPropertyValue(property, content.getPropertyValue(property));

                    } else {
                        shapeProperties.setPropertyValue(property, shape.getPropertyValue(property));
                    }
                }

                CompoundEdit ce = new CompoundEdit();
                if (shape.setProperties(shapeProperties, ce)) {
                    shapesEdit.addEdit(ce);  
                }  
                ce.end();
            }

            shapesEdit.end();
            if (shapesEdit.isSignificant()) {
                shapeComponent.fireUndoableEditUpdate(new UndoableEditEvent(shapeComponent, shapesEdit));
View Full Code Here

        public void actionPerformed(ActionEvent e) {
            // The first selected element is in charge of applying the collective action to the selection
            Shape s0 = getElementContainer().getSelection().getShape(0);
            if (s0 instanceof SelectionContextualActionProvider){
                CompoundEdit ce=new CompoundEdit();
                ((SelectionContextualActionProvider)getElementContainer().getSelection().getSelectedElements().get(0)).doCollectiveAction(getElementContainer().getSelection(), actionX, actionY, actionTarget, actionName, ce);
                ce.end();

                if (ce.isSignificant()) {
                    fireUndoableEditUpdate(new UndoableEditEvent(ShapesContainer.this, ce));
                }
            }
        }
View Full Code Here

    if(plot1==null){
      abort();
      return;
    }

    CompoundEdit ce=null;

    //  simple zoom, all the axes are taken into account
    HashMap plot1OldValues=plot1.getAxesProperties(null, -1);
    plot1.zoomWheel(x1, y1, PlotZoom.zoomWheelFactor, zoomIn);
    ce=plot1.new PlotCompoundEdit(plot1OldValues);
View Full Code Here

              collectivePlots.add(plot);     
          }
      }

      // do the zoom
      CompoundEdit ce=null;
      if(collectivePlots.isEmpty()){
        // a simple zoom, all the exes are taken into account
        HashMap plot1OldValues=plot1.getAxesProperties(null, -1);
        plot1.zoom(x1, x2, y1, y2, false);
        ce=plot1.new PlotCompoundEdit(plot1OldValues);
        plot1.repaintDiagram(plot1.getBounds());
      }
      else{
        // a collective zoom
        ce = new CompoundEdit();
        HashMap plot1OldValues=plot1.getAxesProperties(null, Plot.PX);
        if(plot1.secondaryX!=null){
          plot1.getAxesProperties(plot1OldValues, Plot.SX);
        }
        // X axes zoom only
        plot1.zoom(x1, x2, 0., 0., true);
        PlotCompoundEdit ce1=plot1.new PlotCompoundEdit(plot1OldValues);
        plot1.repaintDiagram(plot1.getBounds());
        ce.addEdit(ce1);
        // apply plot1 X axes properties to the other compliants plots
        Iterator it=collectivePlots.iterator();
        while(it.hasNext()){
          Plot plot=(Plot)it.next();
          HashMap oldValues=plot.getAxesProperties(null, Plot.PX);
          if(plot.secondaryX!=null){
            plot.getAxesProperties(oldValues, Plot.SX);
          }
          Iterator vit=oldValues.keySet().iterator();
          while(vit.hasNext()){
            String k=(String)vit.next();
            plot.setPropertyValue(k,plot1.getPropertyValue(k));
          }
          PlotCompoundEdit ce2=plot.new PlotCompoundEdit(oldValues);
          plot.repaintDiagram(plot.getBounds());
          ce.addEdit(ce2);
        }
        ce.end();
      }
      // store undoable event
      selection.getElementContainer().getComponent().fireUndoableEditUpdate(new UndoableEditEvent(selection.getElementContainer().getComponent(), ce));
      selection.getElementContainer().getComponent().repaint();
View Full Code Here

        collectivePlots.add(s);
      }
    }
   
    // Make the translation
    CompoundEdit ce=null;
    if(collectivePlots.isEmpty()){
      // a simple translation, all the exes are taken into account
      if (firstTranslation){
        HashMap plot1OldValues=plot1.getAxesProperties(null, -1);
        ce=plot1.new PlotCompoundEdit(plot1OldValues);
      }
      plot1.translate(x1, x2, y1, y2);
      plot1.repaintDiagram(plot1.getBounds());
     

    }
    else{
      // collective translation
      ce = new CompoundEdit();
     
      if (firstTranslation){
        HashMap plot1OldValues=plot1.getAxesProperties(null, -1);
        PlotCompoundEdit ce1=plot1.new PlotCompoundEdit(plot1OldValues);
        ce.addEdit(ce1);
      }
      plot1.translate(x1, x2, y1, y2);
      plot1.repaintDiagram(plot1.getBounds());
     
      // apply plot1 X axes properties to the other compliants plots
      Iterator it=collectivePlots.iterator();
      while(it.hasNext()){
        Plot plot=(Plot)it.next();

        if (firstTranslation){
          HashMap oldValues=plot.getAxesProperties(null,-1);
          PlotCompoundEdit ce2=plot.new PlotCompoundEdit(oldValues);
          ce.addEdit(ce2);
        }
        plot.translate(x1, x2, y1, y2);
            plot.repaintDiagram(plot.getBounds());
      }
      ce.end();
    }
   
    // store undoable event
    if (firstTranslation){
      selection.getElementContainer().getComponent().fireUndoableEditUpdate(new UndoableEditEvent(selection.getElementContainer().getComponent(), ce));
View Full Code Here

     */
    public boolean doAction(double x, double y, Object o, String action, CompoundEdit undoableEdit) {
      
        if (action.equals(resources.getString("SetSource"))) {
            // Save old params
            CompoundEdit ce = new CompoundEdit();
            HashMap oldValues = new HashMap();
            oldValues.put("TEXT_SOURCE", source);
            oldValues.put("TEXT", getText());
           
            setSource((DataSource) o);
           
            // Notify changes
            Iterator it = oldValues.keySet().iterator();
            while (it.hasNext()) {
                String n = (String) it.next();
                ce.addEdit(new PropertyChangeEdit(this, n, oldValues.get(n), getPropertyValue(n)));
            }
            ce.end();
            if (undoableEdit != null) {
                undoableEdit.addEdit(ce);
            }
            return true;
        }
        if (action.startsWith(resources.getString("Font"))) {
            // Save old params
            CompoundEdit ce = new CompoundEdit();
            HashMap oldValues = new HashMap();
            oldValues.put("FONT", currentFont);
            // Make changes
            fontName = action.substring(resources.getString("Font").length() + 1);
            updateFont();
            Rectangle bounds = getBounds();
            fitBounds();
            // Notify changes
            Iterator it = oldValues.keySet().iterator();
            while (it.hasNext()) {
                String n = (String) it.next();
                ce.addEdit(new PropertyChangeEdit(this, n, oldValues.get(n), getPropertyValue(n)));
            }
            ce.end();
            if (undoableEdit != null) {
                undoableEdit.addEdit(ce);
            }
            // Repaint
            bounds.add(getBounds());
            notifyChange(bounds);
            return true;
        }
        if (action.startsWith(resources.getString("Body"))) {
            // Save old params
            CompoundEdit ce = new CompoundEdit();
            HashMap oldValues = new HashMap();
            oldValues.put("FONT", currentFont);
            // Make changes
            fontSize = new Integer(action.substring(resources.getString("Body").length() + 1)).intValue();
            updateFont();
            Rectangle bounds = getBounds();
            fitBounds();
            // Notify changes
            Iterator it = oldValues.keySet().iterator();
            while (it.hasNext()) {
                String n = (String) it.next();
                ce.addEdit(new PropertyChangeEdit(this, n, oldValues.get(n), getPropertyValue(n)));
            }
            ce.end();
            if (undoableEdit != null) {
                undoableEdit.addEdit(ce);
            }
           
            // Repaint
            bounds.add(getBounds());
            notifyChange(bounds);
            return true;
        }
        if (action.equals(resources.getString("AdjustSize"))) {
            CompoundEdit ce = new CompoundEdit();
            HashMap oldValues = new HashMap();
            oldValues.put("WIDTH", getPropertyValue("WIDTH"));
            oldValues.put("HEIGHT", getPropertyValue("HEIGHT"));
            Rectangle bounds = getBounds();
            fitBounds();
            Iterator it = oldValues.keySet().iterator();
            while (it.hasNext()) {
                String n = (String) it.next();
                ce.addEdit(new PropertyChangeEdit(this, n, oldValues.get(n), getPropertyValue(n)));
            }
            ce.end();
            if (undoableEdit != null) {
                undoableEdit.addEdit(ce);
            }
           
            bounds.add(getBounds());
View Full Code Here

    public boolean doAction(double x, double y, Object o, String action, CompoundEdit undoableEdit) {
        boolean res;

        if (action.equals(resources.getString("setSource"))) {
            // Save old params
            CompoundEdit ce = new CompoundEdit();
            HashMap oldValues = new HashMap();
            oldValues.put("PROGRESS_SOURCE", progressSource);
            oldValues.put("FILL_COLOR", rectangle.getFillColor());

            addDataSource((DataSource)o);

            // Notify changes
            Iterator it = oldValues.keySet().iterator();
            while (it.hasNext()) {
                String n = (String) it.next();
                ce.addEdit(new PropertyChangeEdit(this, n, oldValues.get(n), getPropertyValue(n)));
            }
            ce.end();
            if (undoableEdit != null) {
                undoableEdit.addEdit(ce);
            }

            res =  true;
View Full Code Here

            shapes.add(this);
            doPropertiesAction(shapes);
           
        } else if (action.equals(resources.getString("rotation") + ";" + resources.getString("rightRotation"))) {
            // Save old params
            CompoundEdit ce = new CompoundEdit();
            HashMap oldValues = new HashMap();
            oldValues.put("TRANSFORM", getPropertyValue("TRANSFORM"));
            // Make changes
            if (transform == null) {
                transform = new AffineTransformData(this);
            }
            transform.rotEnabled = true;
            transform.rotValue = ((transform.rotValue * transform.angleUnitScale) + Math.PI / 2)
            / transform.angleUnitScale;
            setPropertyValue("TRANSFORM", transform);
            // Notify changes
            Iterator it = oldValues.keySet().iterator();
            while (it.hasNext()) {
                String n = (String) it.next();
                ce.addEdit(new PropertyChangeEdit(this, n, oldValues.get(n), getPropertyValue(n)));
            }
            ce.end();

            if (undoableEdit != null) {
                undoableEdit.addEdit(ce);
            }
        } else if (action.equals(resources.getString("rotation") + ";" + resources.getString("leftRotation"))) {
            // Save old params
            CompoundEdit ce = new CompoundEdit();
            HashMap oldValues = new HashMap();
            oldValues.put("TRANSFORM", getPropertyValue("TRANSFORM"));
            // Make changes
            if (transform == null) {
                transform = new AffineTransformData(this);
            }
            transform.rotEnabled = true;
            transform.rotValue = ((transform.rotValue * transform.angleUnitScale) - Math.PI / 2)
            / transform.angleUnitScale;
            setPropertyValue("TRANSFORM", transform);
            // Notify changes
            Iterator it = oldValues.keySet().iterator();
            while (it.hasNext()) {
                String n = (String) it.next();
                ce.addEdit(new PropertyChangeEdit(this, n, oldValues.get(n), getPropertyValue(n)));
            }
            ce.end();
           
            if (undoableEdit != null) {
                undoableEdit.addEdit(ce);
            }
           
View Full Code Here

TOP

Related Classes of javax.swing.undo.CompoundEdit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.