コード例 #1
0
ファイル: SLGView.java プロジェクト: pdewan/Shapes
  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);
  }
コード例 #2
0
ファイル: SLGView.java プロジェクト: pdewan/Shapes
  //    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();
    }
  }