Esempio n. 1
0
  //	public void updateComponentsOld(RemoteShape shape) {
  //		Component[] currentComponents = container.getComponents();
  //		Vector currentComponentVector = new Vector();
  //		for (int i = 0; i < currentComponents.length; i++)
  //			currentComponentVector.addElement(currentComponents[i]);
  //		int componentModelIndex = -1;
  //		//for (Enumeration shapeModels = slModel.elements();shapeModels.hasMoreElements();)
  //		List sortedElements = slModel.getSortedList();
  //		for (int index = sortedElements.size() - 1; index >= 0; index --)
  //        {
  //		     //System.out.println("paintShapes " + this);
  //			 //RemoteShape shapeModel = (RemoteShape) shapeModels.nextElement();
  //			 RemoteShape shapeModel = (RemoteShape) sortedElements.get(index);
  //			 if (shapeModel instanceof ComponentModel) {
  //				 componentModelIndex++;
  //				 ComponentModel componentModel = (ComponentModel) shapeModel;
  //				 Component component = componentModel.getComponent();
  //				 if (currentComponentVector.contains(component)) {
  //					 currentComponentVector.removeElement(component);
  //
  //				 } else {
  ////					 if (component.getParent() != null)
  ////						 System.out.println("Non null parent");
  //					 //container.add(component, componentModelIndex);
  //					 container.add(component, 0);
  ////					 if (component instanceof JTextField) {
  ////						 System.out.println ("Adding JtextField:" + ((JTextField) component).getText());
  ////					 }
  ////					 System.out.println("component x, y(" + component.getX() + "," + component.getY() + ")");
  ////					 System.out.println("component width, height(" + component.getBounds().getWidth() + "," +
  // component.getBounds().getHeight() + ")");
  //				 }
  //			 }
  //		}
  //		for (Enumeration elements = currentComponentVector.elements();
  //			 elements.hasMoreElements();) {
  //			Component component = (Component) elements.nextElement();
  ////			System.out.println("Remving component:" + component.getX() + "," + component.getY());
  //			container.remove(component);
  //			//container.remove((Component) elements.nextElement());
  //		}
  //		//container.validate();
  //
  //	}
  void resort(List sortedElements) {
    container.removeAll();
    // int componentModelIndex = -1;
    for (int index = sortedElements.size() - 1; index >= 0; index--) {

      RemoteShape shapeModel = (RemoteShape) sortedElements.get(index);
      if (shapeModel instanceof ComponentModel) {
        // componentModelIndex++;
        ComponentModel componentModel = (ComponentModel) shapeModel;
        Component component = componentModel.getComponent();
        container.add(component);
      }
    }
  }
Esempio n. 2
0
  public void updateComponents(RemoteShape shape) {
    Component[] currentComponents = container.getComponents();
    // Vector currentComponentVector = new Vector();
    List sortedElements = slModel.getSortedList();
    List sortedComponents = slModel.getSortedComponentList();
    //		for (int i = 0; i < currentComponents.length; i++)
    //			currentComponentVector.addElement(currentComponents[i]);
    // if (shape instanceof ComponentModel) {
    ComponentModel componentModel = (ComponentModel) shape;
    Component component = componentModel.getComponent();
    if (currentComponents.length < sortedComponents.size()) { // insert
      // if (!currentComponentVector.contains(component)) {
      int insertPos = sortedComponents.indexOf(shape);
      container.add(component, insertPos);
      // currentComponents = container.getComponents();
      return; // trying to make it more efficient
    } else { // remove -- this should be done in a better way
      container.remove(component);
    }

    // }

    //		Vector unvisitedComponentVector = new Vector(currentComponentVector);
    //		int componentModelIndex = -1;
    //		int componentIndex;
    //		//for (Enumeration shapeModels = slModel.elements();shapeModels.hasMoreElements();)
    //		boolean resort;
    //
    //		for (int index = sortedElements.size() - 1; index >= 0; index --)
    //        {
    //		     //System.out.println("paintShapes " + this);
    //			 //RemoteShape shapeModel = (RemoteShape) shapeModels.nextElement();
    //			 RemoteShape shapeModel = (RemoteShape) sortedElements.get(index);
    //			 if (shapeModel instanceof ComponentModel) {
    //				 componentModelIndex++;
    //				 ComponentModel componentModel = (ComponentModel) shapeModel;
    //				 Component component = componentModel.getComponent();
    //				 if (currentComponentVector.contains(component)) {
    ////					 componentIndex = currentComponentVector.indexOf(component);
    ////					 if (componentIndex != componentModelIndex) {
    ////						 resort (sortedElements);
    ////					 }
    //					 unvisitedComponentVector.removeElement(component);
    //
    //
    //				 } else {
    ////					 if (component.getParent() != null)
    ////						 System.out.println("Non null parent");
    //					 container.add(component, componentModelIndex); // this should not be executed
    //					 //container.add(component, 0);
    ////					 if (component instanceof JTextField) {
    ////						 System.out.println ("Adding JtextField:" + ((JTextField) component).getText());
    ////					 }
    ////					 System.out.println("component x, y(" + component.getX() + "," + component.getY() +
    // ")");
    ////					 System.out.println("component width, height(" + component.getBounds().getWidth() + ","
    // + component.getBounds().getHeight() + ")");
    //				 }
    //			 }
    //		}
    //		for (Enumeration elements = unvisitedComponentVector.elements();
    //			 elements.hasMoreElements();) {
    //			Component component = (Component) elements.nextElement();
    ////			System.out.println("Remving component:" + component.getX() + "," + component.getY());
    //			container.remove(component);
    //			//container.remove((Component) elements.nextElement());
    //		}
    //		//container.validate();

  }
Esempio n. 3
0
  //    public void updateOld(Listenable model, Object arg)
  //    {
  //    	try {
  //    		//System.out.println ("Listenable " + model + " arg " + arg);
  //		//System.out.println("update called");
  //    		RemoteShape shapeModel = null;
  //    		if (arg != null && arg instanceof Boolean && (Boolean) arg)
  //    			slModel.sort();
  //    		else if ((arg != null) && (arg instanceof SLPutCommand)) {
  //
  //		    //System.out.println("Update called on view " + this);
  //           //RemoteShape shapeModel = ((SLPutCommand) arg).getShapeModel();
  //           shapeModel = ((SLPutCommand) arg).getShapeModel();
  //           // System.out.println("Shape model:" + shapeModel);
  //            //shapeModel.addObserver(this);
  //            shapeModel.addListener(this);
  //			if (shapeModel instanceof ComponentModel) {
  //				ComponentModel componentModel = (ComponentModel) shapeModel;
  //			    Rectangle b = componentModel.getBounds();
  //				Component component = componentModel.getComponent();
  //				//System.out.println("comp model" + componentModel + "comp" + component);
  //				//System.out.println ("model bounds" + b + "comp bounds" + component.getBounds());
  //				component.setBounds(b.x, b.y, b.width, b.height);
  //			}
  //        }
  //    		// null means delete
  //		if (model instanceof SLModel &&  ((shapeModel == null ) || shapeModel instanceof
  // ComponentModel))
  //		     updateComponents(shapeModel);
  //		//System.out.println("calling repaint");
  //        container.repaint();
  //    	} catch (Exception e) {
  //    		System.out.println(e);
  //    		e.printStackTrace();
  //    	}
  //    }
  public void update(Listenable model, Object arg) {
    try {
      // System.out.println ("Listenable " + model + " arg " + arg);
      // System.out.println("update called");
      RemoteShape shapeModel = null;
      if (arg != null && arg instanceof Boolean && (Boolean) arg) slModel.sort();
      else if ((arg != null) && (arg instanceof SLPutCommand)) {

        // System.out.println("Update called on view " + this);
        // RemoteShape shapeModel = ((SLPutCommand)
        // arg).getShapeModel();
        shapeModel = ((SLPutCommand) arg).getShapeModel();
        // System.out.println("Shape model:" + shapeModel);
        // shapeModel.addObserver(this);
        shapeModel.addListener(this);
        if (shapeModel instanceof ComponentModel) {
          ComponentModel componentModel = (ComponentModel) shapeModel;
          Rectangle b = componentModel.getBounds();
          Component component = componentModel.getComponent();
          // System.out.println("comp model" + componentModel + "comp"
          // + component);
          // System.out.println ("model bounds" + b + "comp bounds" +
          // component.getBounds());
          component.setBounds(b.x, b.y, b.width, b.height);
          List sortedComponents = slModel.getSortedComponentList();
          int insertPos = sortedComponents.indexOf(shapeModel);
          if (insertPos >= 0 && insertPos <= container.getComponentCount())
            container.add(component, insertPos);
          else {
            Tracer.error(
                "Illegal position:"
                    + insertPos
                    + " Same object:"
                    + shapeModel
                    + " at coordinates("
                    + shapeModel.getX()
                    + ", "
                    + shapeModel.getY()
                    + ") probably displayed twice in graphics window and its stacking order will be ignored");
            container.add(component);
          }
          component.addMouseListener(shapeEventNotifier);
        }
      } else if ((arg instanceof SLRemoveCommand)) {
        shapeModel = ((SLRemoveCommand) arg).getOriginalShapeModel();
        if (shapeModel instanceof ComponentModel) {
          ComponentModel componentModel = (ComponentModel) shapeModel;
          container.remove(componentModel.getComponent());
        }
      }
      // null means delete
      //			if (model instanceof SLModel
      //					&& shapeModel instanceof ComponentModel)
      //				updateComponents(shapeModel);
      // System.out.println("calling repaint");
      if (!slModel.locked()) container.repaint();
    } catch (Exception e) {
      System.out.println(e);
      e.printStackTrace();
    }
  }