Exemplo n.º 1
0
 /*
 public Container getContainer () {
 	return container;
 }
 */
 public void paintKeys(Graphics g) {
   for (Enumeration shapeKeys = slModel.keys(); shapeKeys.hasMoreElements(); ) {
     String key = (String) shapeKeys.nextElement();
     RemoteShape shapeModel = slModel.get(key);
     if ((mouseController == null) || mouseController.notBuffered(shapeModel))
       paintKey(g, key, shapeModel);
   }
 }
Exemplo n.º 2
0
 public synchronized void paintShapes(Graphics g) {
   try {
     // System.out.println("slModel " + slModel);
     List sortedShapes = new ArrayList(slModel.getSortedList());
     //        System.out.println("Painting:" + sortedShapes);
     // for (Enumeration shapeModels = slModel.elements();shapeModels.hasMoreElements();)
     for (int index = sortedShapes.size() - 1; index >= 0; index--) {
       // System.out.println("paintShapes " + this);
       // RemoteShape shapeModel = (RemoteShape) shapeModels.nextElement();
       if (index >= sortedShapes.size()) {
         Tracer.error("Index, " + index + ">=  size:" + sortedShapes.size() + " of sorted shapes");
       }
       RemoteShape shapeModel = (RemoteShape) sortedShapes.get(index);
       if ((mouseController == null) || mouseController.notBuffered(shapeModel)) {
         // System.out.println("paintShape " + this);
         /*
         if (shapeModel == selectedShape)
          paintSelection(g);
         else
         */
         paintShape(g, shapeModel, container);
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 3
0
  public void setSLModel(ShapesList theSLModel) {
    try {
      // System.out.println("slmodel " + theSLModel);
      slModel = theSLModel;
      // slModel.addObserver(this);
      for (Enumeration keys = slModel.keys(); keys.hasMoreElements(); ) {
        RemoteShape shapeModel = slModel.get((String) keys.nextElement());
        // (slModel.get(keys.nextElement())).addObserver(this);
        // shapeModel.addObserver(this);
        shapeModel.addListener(this);
      }

    } catch (Exception e) {
      e.printStackTrace();
      // System.out.println(e);
    }
    shapeEventNotifier = new ShapeEventNotifier(theSLModel, this);
    container.addMouseListener(shapeEventNotifier);
    container.addMouseMotionListener(shapeEventNotifier);
  }
Exemplo n.º 4
0
  public void paint(Object obj) {
    // System.out.println(Thread.currentThread());
    // System.out.println("graphics" + g);
    // System.out.println(slgController);
    // System.out.println("paint called");
    //    	System.out.println("Painted shapes");

    if (slModel.locked()) return;
    Graphics g = (Graphics) obj;
    this.paintShapes(g);
    if (paintKeys) this.paintKeys(g);
    if (paintLabels) this.paintLabels(g);
    if (mouseController != null) mouseController.paint(g);
    // paintSelection(g);
  }
Exemplo n.º 5
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();

  }
Exemplo n.º 6
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();
    }
  }