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 static void paintShape(
      Graphics g, RemoteShape shapeModel, boolean fill, Component aComponent) {
    try {
      if (shapeModel.getWidth() == 0 && shapeModel.getHeight() == 0) return;
      Font graphicsFont = g.getFont();

      Color shapeColor = shapeModel.getColor();
      Color graphicsColor = g.getColor();
      Graphics2D g2d = (Graphics2D) g;
      Stroke graphicsStroke = g2d.getStroke();
      Paint graphicsPaint = g2d.getPaint();
      Font font = shapeModel.getFont();
      Integer myFontSize = shapeModel.getFontSize();
      if (myFontSize == null || myFontSize <= 0) {
        myFontSize = fontSize;
      }
      if (font != null) {
        g.setFont(font);
      } else if (myFontSize != null) {
        g.setFont(Common.toFontSize(g.getFont(), myFontSize));
        if (shapeModel instanceof ComponentModel) {
          ComponentModel componentModel = (ComponentModel) shapeModel;
          componentModel.setFont(Common.toFontSize(componentModel.getFont(), myFontSize));
        }
      }
      Stroke basicStroke = shapeModel.getStroke();
      if (basicStroke != null) g2d.setStroke(basicStroke);
      Paint gradientPaint = shapeModel.getPaint();
      if (gradientPaint != null) g2d.setPaint(gradientPaint);
      if (shapeColor != null) g.setColor(shapeColor);

      try {
        // Class shapeClass = shapeModel.getClass();
        // if (shapeClass == Class.forName("shapes.LineModel"))
        // if (shapeModel instanceof LineModel)
        if (shapeModel instanceof RemoteAWTShape) {
          paintAWTShape(g2d, (RemoteAWTShape) shapeModel);
        } else if (shapeModel instanceof RemoteLine) {
          // System.out.println(shapeModel.getBounds().x + " " + shapeModel.getBounds().y);
          // paintLine(g, (RemoteLine) shapeModel, fill);
          paintLine2D(g2d, (RemoteLine) shapeModel, fill);
        }
        // else if (shapeClass == Class.forName("shapes.OvalModel"))
        else if (shapeModel instanceof RemoteOval) {
          paintOval(g, (RemoteOval) shapeModel, fill);
        }
        // else if (shapeClass == Class.forName("shapes.RectangleModel"))
        else if (shapeModel instanceof RemoteRectangle) {
          // paintRectangle(g, (RemoteRectangle) shapeModel, fill);
          paintRectangle2D(g, (RemoteRectangle) shapeModel, fill);
        } else if (shapeModel instanceof RemoteArc) {
          // paintArc(g, (RemoteArc) shapeModel, fill);
          paintArc2D(g2d, (RemoteArc) shapeModel, fill);
        } else if (shapeModel instanceof RemoteCurve) {
          paintCurve2D(g2d, (RemoteCurve) shapeModel, fill);
        } else if (shapeModel instanceof shapes.StringModel) {
          paintString(g, (RemoteText) shapeModel, fill);
        } else if (shapeModel instanceof ImageModel) {
          paintImage((Graphics2D) g, (RemoteImage) shapeModel, fill, aComponent);
        }
        g.setColor(graphicsColor);
        g.setFont(graphicsFont);
        g2d.setPaint(graphicsPaint);
        g2d.setStroke(graphicsStroke);
      } catch (Exception e) {
        System.err.println("Should have stored shape id: " + e.toString());
        e.printStackTrace();
      }
      if (shapeColor != null) g.setColor(graphicsColor);
    } catch (Exception e) {
      e.printStackTrace();
      // System.out.println(e);
    }
  }
Esempio n. 3
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. 4
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();
    }
  }