Пример #1
0
 private void computeSize(boolean immediate) {
   hidePopup();
   Bounds bounds;
   CircuitState circState = circuitState;
   if (circState == null) {
     bounds = Bounds.create(0, 0, 50, 50);
   } else {
     bounds = circState.getCircuit().getAppearance().getAbsoluteBounds();
   }
   int width = bounds.getX() + bounds.getWidth() + BOUNDS_BUFFER;
   int height = bounds.getY() + bounds.getHeight() + BOUNDS_BUFFER;
   Size dim;
   if (canvasPane == null) {
     dim = new Size(width, height);
   } else {
     dim = canvasPane.supportPreferredSize(width, height);
   }
   if (!immediate) {
     Bounds old = oldPreferredSize;
     if (old != null
         && Math.abs(old.getWidth() - dim.width) < THRESH_SIZE_UPDATE
         && Math.abs(old.getHeight() - dim.height) < THRESH_SIZE_UPDATE) {
       return;
     }
   }
   oldPreferredSize = Bounds.create(0, 0, dim.width, dim.height);
   setPreferredSize(dim);
   revalidate();
 }
Пример #2
0
 public void setData(InstanceData value) {
   CircuitState circState = context.getCircuitState();
   if (circState == null || comp == null) {
     throw new UnsupportedOperationException("setData on InstancePainter");
   } else {
     circState.setData(comp, value);
   }
 }
Пример #3
0
 public InstanceData getData() {
   CircuitState circState = context.getCircuitState();
   if (circState == null || comp == null) {
     throw new UnsupportedOperationException("setData on InstancePainter");
   } else {
     return (InstanceData) circState.getData(comp);
   }
 }
Пример #4
0
 public Value getPortValue(int portIndex) {
   InstanceComponent c = comp;
   CircuitState s = context.getCircuitState();
   if (c != null && s != null) {
     return s.getValue(c.getEnd(portIndex).getLocation());
   } else {
     return Value.UNKNOWN;
   }
 }
Пример #5
0
  @Override
  public void doAction(Action canvasAction) {
    Circuit circuit = circuitState.getCircuit();
    if (!proj.getLogisimFile().contains(circuit)) {
      return;
    }

    if (canvasAction instanceof ModelReorderAction) {
      int max = getMaxIndex(getModel());
      ModelReorderAction reorder = (ModelReorderAction) canvasAction;
      List<ReorderRequest> rs = reorder.getReorderRequests();
      List<ReorderRequest> mod = new ArrayList<ReorderRequest>(rs.size());
      boolean changed = false;
      boolean movedToMax = false;
      for (ReorderRequest r : rs) {
        CanvasObject o = r.getObject();
        if (o instanceof AppearanceElement) {
          changed = true;
        } else {
          if (r.getToIndex() > max) {
            int from = r.getFromIndex();
            changed = true;
            movedToMax = true;
            if (from == max && !movedToMax) {
              // this change is ineffective - don't add it
            } else {
              mod.add(new ReorderRequest(o, from, max));
            }
          } else {
            if (r.getToIndex() == max) movedToMax = true;
            mod.add(r);
          }
        }
      }
      if (changed) {
        if (mod.isEmpty()) {
          return;
        }
        canvasAction = new ModelReorderAction(getModel(), mod);
      }
    }

    if (canvasAction instanceof ModelAddAction) {
      ModelAddAction addAction = (ModelAddAction) canvasAction;
      int cur = addAction.getDestinationIndex();
      int max = getMaxIndex(getModel());
      if (cur > max) {
        canvasAction = new ModelAddAction(getModel(), addAction.getObjects(), max + 1);
      }
    }

    proj.doAction(new CanvasActionAdapter(circuit, canvasAction));
  }
Пример #6
0
	private void doLoad() {
		JFileChooser chooser = proj.createChooser();
		File oldSelected = factory.getCurrentImage(instance);
		if (oldSelected != null) chooser.setSelectedFile(oldSelected);
		chooser.setDialogTitle(_("ramLoadDialogTitle"));
		int choice = chooser.showOpenDialog(frame);
		if (choice == JFileChooser.APPROVE_OPTION) {
			File f = chooser.getSelectedFile();
			try {
				factory.loadImage(circState.getInstanceState(instance), f);
			} catch (IOException e) {
				JOptionPane.showMessageDialog(frame, e.getMessage(),
						_("ramLoadErrorTitle"), JOptionPane.ERROR_MESSAGE);
			}
		}
	}
Пример #7
0
 public void propagate(CircuitState state) {
   int A = state.getValue(getEndLocation(0)).toIntValue();
   int B = state.getValue(getEndLocation(1)).toIntValue();
   int op = state.getValue(getEndLocation(2)).toIntValue();
   int ans = 0;
   int overflow = 0;
   int zero = 0;
   switch (op) {
     case 0x0:
       // and
       ans = A & B;
       break;
     case 0x1:
       // or
       ans = A | B;
       break;
     case 0x2:
       // add
       ans = A + B;
       if ((A >= 0 && B >= 0 && ans < 0) || (A < 0 && B < 0 && ans >= 0)) {
         overflow = 1;
       }
       break;
     case 0x6:
       // sub
       ans = A - B;
       if ((A >= 0 && B < 0 && ans < 0) || (A < 0 && B >= 0 && ans >= 0)) {
         overflow = 1;
       }
       break;
     case 0x7:
       // slt
       ans = (A < B) ? 0x1 : 0x0;
       break;
     case 0xC:
       // nor
       ans = ~(A | B);
       break;
     case 0x8:
       // sll
       ans = B << A;
       break;
     case 0x9:
       // srl
       ans = B >>> A;
       break;
     case 0xA:
       // sra
       ans = B >> A;
       break;
   }
   if (ans == 0) {
     zero = 1;
   }
   Value out = Value.createKnown(BITWIDTH_32, ans);
   Value outZero = Value.createKnown(BITWIDTH_1, zero);
   Value outOverflow = Value.createKnown(BITWIDTH_1, overflow);
   state.setValue(getEndLocation(3), outZero, this, 4);
   state.setValue(getEndLocation(4), out, this, 5);
   state.setValue(getEndLocation(5), outOverflow, this, 4);
 }
Пример #8
0
 Circuit getCircuit() {
   return circuitState.getCircuit();
 }
Пример #9
0
 public void setCircuit(Project proj, CircuitState circuitState) {
   this.proj = proj;
   this.circuitState = circuitState;
   Circuit circuit = circuitState.getCircuit();
   setModel(circuit.getAppearance(), this);
 }