Exemple #1
0
 /** Draw atom */
 void drawAtom(Graphics g, int iz) {
   int i = zOrder[iz];
   Atom atom = atoms[i];
   if (atom == null) return;
   double zMin = screenXYZ[zOrder[0]][2]; // fartherest from the viewer
   double zMax = screenXYZ[zOrder[np - 1]][2]; // closest to the viewer
   int greyScale = Atom.nBalls - 1;
   if (zMin != zMax) // zMin == zMax means the two-dimensional case
   greyScale = (int) (Atom.nBalls * (screenXYZ[i][2] - zMin) / (zMax - zMin) - 1e-6);
   // the atom closest to the viewer has a greyScale of Atom.nBalls - 1
   // the atom fartherest from the viewer has a greyScale of 0
   double radius = ballSize * atom.relRadius * real2Screen;
   atom.paint(g, screenXYZ[i][0], screenXYZ[i][1], greyScale, radius);
 }
Exemple #2
0
  static void reqGetSelectionOwner(Client c) throws IOException {
    int foo;
    int selection;
    IO io = c.client;
    selection = io.readInt();

    c.length -= 2;

    if (!Atom.valid(selection)) {
      c.errorValue = selection;
      c.errorReason = 5; // BadAtom
      return;
    }

    synchronized (io) {
      io.writeByte(1);
      Selection s = getSelection(selection);
      io.writePad(1);
      io.writeShort(c.seq);
      io.writeInt(0);
      if (s != null) {
        io.writeInt(s.wid);
      } else {
        io.writeInt(0);
      }
      io.writePad(20);
      io.flush();
    }
  }
Exemple #3
0
  static void reqConvertSelection(Client c) throws IOException {
    int foo;
    int selection, requestor, target, property, time;
    boolean paramsOkay = true;
    IO io = c.client;
    requestor = io.readInt();
    Window w = c.lookupWindow(requestor);
    if (w == null) {
      c.errorValue = requestor;
      c.errorReason = 3; // BadWindow;
    }
    selection = io.readInt();
    paramsOkay = Atom.valid(selection);
    target = io.readInt();
    paramsOkay &= Atom.valid(target);
    property = io.readInt();
    if (property != 0) {
      paramsOkay &= Atom.valid(property);
    }
    time = io.readInt();
    c.length -= 6;
    if (c.errorReason != 0) {
      return;
    }

    if (paramsOkay) {
      Selection s = getSelection(selection);
      if (s != null && s.client != null) {
        c.cevent.mkSelectionRequest(time, s.wid, requestor, selection, target, property);
        if (s.client.sendEvent(c.cevent, 1, Event.NoEventMask, Event.NoEventMask, null) != 0)
          return;
      }
      c.cevent.mkSelectionNotify(time, requestor, selection, target, 0);
      c.sendEvent(c.cevent, 1, Event.NoEventMask, Event.NoEventMask, null);

      return;
    } else {
      // System.out.println("error!!");
      c.errorValue = property;
      c.errorReason = 5; // BadAtom
      return;
    }
  }
  private void removeUnnecessaryData() {
    Set<AtomType> clear = Sets.newHashSet();
    List<Atom> atoms = Lists.newArrayList();
    List<AtomType> atomTypes = structure.getAtomTypes();

    for (Section section : structure.getSections()) {
      if (section.getSectionType().equals(SectionType.STRUCTUREDATA)) {
        atoms.addAll(section.getAtoms());
      }
    }
    for (AtomType atomType : atomTypes) {
      AtomType delete = atomType;
      for (Atom atom : atoms) {
        if (atomType.getName().contains(atom.getType())) {
          delete = null;
        }
      }
      if (delete != null) {
        clear.add(delete);
      }
    }
    clear.forEach(atomTypes::remove);
  }
Exemple #5
0
  static void reqSetSelectionOwner(Client c) throws IOException {
    int foo;
    int selection;
    IO io = c.client;
    foo = io.readInt();
    c.length -= 2;
    Window w = null;
    if (foo != 0) {
      w = c.lookupWindow(foo);
      if (w == null) {
        c.errorValue = foo;
        c.errorReason = 3; // BadWindow
        return;
      }
    }

    selection = io.readInt();
    foo = io.readInt();
    c.length -= 2;
    int time = 0;
    time = (int) System.currentTimeMillis();
    time = foo; // ??

    if (Atom.valid(selection)) {
      int i = 0;
      Selection s = getSelection(selection);
      if (s != null) {
        if (s.client != null && (w == null || (s.client != c))) {
          if (s.client != null) {
            c.cevent.mkSelectionClear(time, s.wid, s.selection);
            s.client.sendEvent(c.cevent, 1, Event.NoEventMask, Event.NoEventMask, null);
          }
        }
        s.window = w;
        s.wid = (w != null ? w.id : 0);
        s.lastTimeChanged = time;
        s.client = (w != null ? c : null);
      } else {
        // System.out.println("add");
        addSelection(selection, time, w, c);
      }
      return;
    } else {
      c.errorValue = selection;
      c.errorReason = 5;
      return;
    }
  }
Exemple #6
0
  static void reqRotateProperties(Client c) throws IOException {
    int foo, propty;
    IO io = c.client;

    foo = io.readInt();
    Window w = c.lookupWindow(foo);
    c.length -= 2;
    if (w == null) {
      c.errorValue = foo;
      c.errorReason = 3; // BadWindow;
      return;
    }
    int n = (short) io.readShort();
    int delta = (short) io.readShort();

    c.length--;

    if (n == 0) {
      return;
    }

    int[] atoms = new int[n];
    Property[] props = new Property[n];
    Property p;
    int i = 0;
    while (n != 0) {
      atoms[i] = io.readInt();
      c.length--;
      if (!Atom.valid(atoms[i])) {
        c.errorValue = atoms[i];
        c.errorReason = 5; // BadAtom
        return;
      }
      p = w.getProperty();
      while (p != null) {
        if (p.propertyName == atoms[i]) {
          props[i] = p;
          break;
        }
        p = p.next;
      }
      if (p == null) {
        c.errorReason = 8; // BadMatch
        return;
      }
      i++;
      n--;
    }
    for (int j = 0; j < atoms.length; j++) {
      for (int k = j + 1; k < atoms.length; k++) {
        if (atoms[j] == atoms[k]) {
          c.errorReason = 8; // BadMatch
          return;
        }
      }
    }
    if (((delta < 0 ? -1 * delta : delta) % atoms.length) != 0) {
      while (delta < 0) {
        delta += atoms.length;
      }
      for (i = 0; i < atoms.length; i++) {
        c.cevent.mkPropertyNotify(
            w.id,
            props[i].propertyName,
            (int) System.currentTimeMillis(),
            // Property.PropertyNewValue
            0);
        w.sendEvent(c.cevent, 1, null);
        props[i].propertyName = atoms[(i + delta) % atoms.length];
      }
    }
  }
Exemple #7
0
  public QTFastStartRAF(FileAccessor accessor, boolean enable) throws IOException {

    input = accessor;

    if (enable) {

      String name = accessor.getName();

      boolean log;
      String fail = null;

      synchronized (tested) {
        log = !tested.contains(name);

        if (log) {

          tested.add(name);
        }
      }

      try {
        Atom ah = null;
        Atom ftypAtom = null;

        boolean gotFtyp = false;
        boolean gotMdat = false;
        boolean justCopy = false;

        while (input.getFilePointer() < input.length()) {

          ah = new Atom(input);

          // System.out.println( "got " + ah.type +", size=" + ah.size );

          if (!isValidTopLevelAtom(ah)) {
            throw new IOException("Non top level QT atom found (" + ah.type + "). File invalid?");
          }

          if (gotFtyp && !gotMdat && ah.type.equalsIgnoreCase(ATOM_MOOV)) {
            justCopy = true;
            break;
          }

          // store ftyp atom to buffer
          if (ah.type.equalsIgnoreCase(ATOM_FTYP)) {
            ftypAtom = ah;
            ftypAtom.fillBuffer(input);
            gotFtyp = true;
          } else if (ah.type.equalsIgnoreCase(ATOM_MDAT)) {
            gotMdat = true;
            input.skipBytes((int) ah.size);
          } else {
            input.skipBytes((int) ah.size);
          }
        }

        if (justCopy) {

          transparent = true;

          return;
        }

        if (ftypAtom == null) {

          throw new IOException("No FTYP atom found");
        }

        if (ah == null || !ah.type.equalsIgnoreCase(ATOM_MOOV)) {

          throw new IOException("Last QT atom was not the MOOV atom.");
        }

        input.seek(ah.offset);

        Atom moovAtom = ah;

        moovAtom.fillBuffer(input);

        if (isCompressedMoovAtom(moovAtom)) {

          throw new IOException("Compressed MOOV qt atoms are not supported");
        }

        patchMoovAtom(moovAtom);

        body_start = ftypAtom.offset + ftypAtom.size;
        body_end = moovAtom.offset;

        header = new byte[ftypAtom.buffer.length + moovAtom.buffer.length];

        System.arraycopy(ftypAtom.buffer, 0, header, 0, ftypAtom.buffer.length);
        System.arraycopy(
            moovAtom.buffer, 0, header, ftypAtom.buffer.length, moovAtom.buffer.length);

        if (accessor.length() != header.length + (body_end - body_start)) {

          throw (new IOException("Inconsistent: file size has changed"));
        }

      } catch (Throwable e) {

        // e.printStackTrace();

        fail = Debug.getNestedExceptionMessage(e);

        transparent = true;

      } finally {

        input.seek(0);

        if (log) {

          String message;

          if (fail == null) {

            message = transparent ? "Not required" : "Required";

          } else {

            message = "Failed - " + fail;
          }

          Debug.outNoStack("MOOV relocation for " + accessor.getName() + ": " + message);
        }
      }
    } else {

      transparent = true;
    }
  }
  public void writeMeat() {

    try {
      for (int i = 0; i < aList.size(); i++) {

        w.write("{");
        w.newLine();
        Atom tempA = aList.get(i);

        w.write("\t" + "\"" + "vertexNum" + "\":" + tempA.getVertexNum() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "atomicNum" + "\":" + tempA.getAtomicNum() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "atomicWeight" + "\":" + tempA.getAtomicWeight() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "electroNeg" + "\":" + tempA.getElectroNeg() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "atomName" + "\":" + tempA.getAtomName() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "adjacentBonds" + "\": {");
        w.newLine();

        for (int z = 0; z < tempA.getAdjacentBonds().size(); z++) {
          w.write("\t\t" + "[");
          w.newLine();
          w.write(
              "\t\t\t"
                  + "\""
                  + "edgeNum"
                  + "\":"
                  + tempA.getAdjacentBonds().get(z).getEdgeNum()
                  + "\",");
          w.newLine();
          w.write(
              "\t\t\t"
                  + "\""
                  + "bondType"
                  + "\":"
                  + tempA.getAdjacentBonds().get(z).getBondType()
                  + "\",");
          w.newLine();
          w.write(
              "\t\t\t"
                  + "\""
                  + "exist"
                  + "\":"
                  + tempA.getAdjacentBonds().get(z).getExist()
                  + "\",");
          w.newLine();
          w.write("\t\t\t" + "\"" + "weight" + "\":" + tempA.getAdjacentBonds().get(z).getWeight());
          w.newLine();
          w.write("\t\t" + "]");
          w.newLine();
        }
        w.write("\t" + "}");
        w.newLine();
      }
      for (int p = 0; p < bList.size(); p++) {
        Bond tempB = bList.get(p);
        w.write("{");
        w.newLine();
        w.write("\t" + "\"" + "edgeNum" + "\":" + tempB.getEdgeNum() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "bondType" + "\":" + tempB.getBondType() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "exist" + "\":" + tempB.getExist() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "weight" + tempB.getWeight() + "\":");
        w.newLine();
        w.write("\t" + "\"" + "adjacentAtoms" + "\": {");
        w.newLine();
        w.write("\t\t" + "\"" + "vertexNum" + "\":" + "\",");
        w.newLine();
        w.write("\t\t" + "\"" + "atomicNum" + "\":" + "\",");
        w.newLine();
        w.write("\t\t" + "\"" + "atomicWeight" + "\":" + "\",");
        w.newLine();
        w.write("\t\t" + "\"" + "electroNeg" + "\":" + "\",");
        w.newLine();
        w.write("\t\t" + "\"" + "atomName" + "\":" + "\",");
        w.newLine();
      }
      w.write("\t" + "}");
      w.newLine();

    } catch (IOException e) {
      System.out.println("error writing meat of file");
    }
  }