public void clear() {
   for (java.util.Enumeration<Editor> e = pageList.elements(); e.hasMoreElements(); )
     e.nextElement().clear();
   pageList.clear();
   tabbedPanel.removeAll();
   showFirstPage();
   updatePageCounterField(pageList.size());
   changed = false;
 }
  private void applyChanges() {
    boolean changedFieldSet = false; // Watch if we need to rebuild entry editors

    // First remove the mappings for fields that have been deleted.
    // If these were re-added, they will be added below, so it doesn't
    // cause any harm to remove them here.
    for (Iterator<String> i = removedFields.iterator(); i.hasNext(); ) {
      String fieldName = i.next();
      metaData.remove(Globals.SELECTOR_META_PREFIX + fieldName);
      changedFieldSet = true;
    }

    // Cycle through all fields that we have created listmodels for:
    loop:
    for (Iterator<String> i = wordListModels.keySet().iterator(); i.hasNext(); ) {
      // For each field name, store the values:
      String fieldName = i.next();
      if ((fieldName == null) || FIELD_FIRST_LINE.equals(fieldName)) continue loop;
      DefaultListModel lm = wordListModels.get(fieldName);
      int start = 0;
      // Avoid storing the <new word> marker if it is there:
      if (lm.size() > 0)
        while ((start < lm.size()) && (lm.get(start)).equals(WORD_FIRSTLINE_TEXT)) start++;
      Vector<String> data = metaData.getData(Globals.SELECTOR_META_PREFIX + fieldName);
      boolean newField = false;
      if (data == null) {
        newField = true;
        data = new Vector<String>();
        changedFieldSet = true;

      } else data.clear();
      for (int wrd = start; wrd < lm.size(); wrd++) {
        String word = (String) lm.get(wrd);
        data.add(word);
      }
      if (newField) metaData.putData(Globals.SELECTOR_META_PREFIX + fieldName, data);
    }

    // System.out.println("TODO: remove metadata for removed selector field.");
    panel.markNonUndoableBaseChanged();

    // Update all selectors in the current BasePanel.
    if (changedFieldSet) {
      panel.rebuildAllEntryEditors();
    } else {
      panel.updateAllContentSelectors();
    }
    panel.addContentSelectorValuesToAutoCompleters();
  }
  public void doLayout() {
    selections.clear();
    if (points == null) {
      points = new Vector<ExprPoint>();
    }
    points.clear();

    for (Pair<Integer, Double> p : watsonProbes) {
      ExprPoint ep = new ExprPoint(p.getFirst(), p.getLast(), '+');
      points.add(ep);
    }

    for (Pair<Integer, Double> p : crickProbes) {
      ExprPoint ep = new ExprPoint(p.getFirst(), p.getLast(), '-');
      points.add(ep);
    }
  }
 protected void setDrawables(Vector drawables) {
   if (drawables != null) this.drawables = drawables;
   else drawables.clear();
   if (manager != null) manager.setTierData(drawables);
 }
Exemple #5
0
 // remove all sequences
 public void clearSequences() {
   sequences.clear();
 }
Exemple #6
0
  private void parsePostScript() {
    try {
      BufferedReader PSIn = new BufferedReader(new FileReader("data/out/" + name + ".ps"));

      // parse header
      while (PSIn.ready()) {
        String S = PSIn.readLine().trim();
        if (S.contains("EndSetup")) {
          break;
        } else {
          if (S.startsWith("/magfont")) {
            fontInfo.add(S);
          } else if (S.startsWith("/lily-output-units")) {
            outputUnits = Float.parseFloat(S.split(" ")[1]);
            for (String T : fontInfo) {
              addFont(
                  T.split(" ")[0].substring(1),
                  T.split(" ")[2].substring(1),
                  (float) outputUnits * Float.parseFloat(T.split(" ")[3]));
            }
          } else if (S.startsWith("/output-scale")) {
            outputScale = Float.parseFloat(S.split(" ")[1]);
          } else if (S.startsWith("/staff-height")) {
            staffLineHeight = Float.parseFloat(S.split(" ")[1]) / 4;
          }
        }
      }
      scale = outputUnits * outputScale;

      for (int layer = 0; layer < staves; ++layer) {
        Vector<Vector<Double>> staff = new Vector<Vector<Double>>();
        for (int page = 0; page < pages; ++page) {
          staff.add(new Vector<Double>());
        }
        staffLines.add(staff);
      }
      Vector<Double> cStaffs = new Vector<Double>();

      String prevLine = "";
      int currPage = 1;

      // parse the rest of the file
      while (PSIn.ready()) {
        String S = PSIn.readLine().trim();
        if (S.contains("noteheads") || S.contains("rests")) {
          // extract coordinate, glyph, and font information
          String T[] = S.split(" ");
          NotePanel N = new NotePanel();
          N.setCoordinates(Double.parseDouble(T[0]), -Double.parseDouble(T[1]))
              .setGlyph(T[4].substring(1))
              .setGonville(fonts.get(T[3]));
          if (S.contains("rests")) {
            T = S.substring(S.lastIndexOf("rests")).split("[. ]");
            N.setRest(Integer.parseInt(T[1]));
          }

          T = prevLine.substring(prevLine.lastIndexOf(this.name + ".ly")).split(":");
          N.setLine(Integer.parseInt(T[1]), Integer.parseInt(T[2])).setPage(currPage);

          if (N.lyLine < staffLine || staffLine == 0) {
            notes[0].add(N);
          } else {
            notes[1].add(N);
          }
        } else if (S.contains("accidentals")) {
          // String T[] = S.split(" ");
          // lastNote.setAccidentals(Double.parseDouble(T[0]), -Double.parseDouble(T[1]),
          // T[4].substring(1), T[3]);
        } else if (S.startsWith("%%Page:")) {
          currPage = Integer.parseInt(S.split(" ")[1]);
        }

        if (S.contains("draw_line")) {
          cStaffs.add(-Double.parseDouble(S.split(" ")[1]));
          if (cStaffs.size() >= 5 * staves) {
            // found a full staff
            Collections.sort(cStaffs);
            staffLines.get(0).get(currPage - 1).add(cStaffs.get(4) + staffLineHeight);
            if (staves > 1) {
              staffLines.get(1).get(currPage - 1).add(cStaffs.get(5) - staffLineHeight);
            }
            cStaffs.clear();
          }
        } else if (!S.contains("draw_round_box")) {
          cStaffs.clear();
        }

        if (S.contains(this.name + ".ly")) {
          prevLine = S;
        }
      }

      // sort the notes we found from the PS by where they occurred in the .ly
      for (int i = 0; i < staves; ++i) {
        Collections.sort(notes[i]);
      }

      // find tied notes
      for (int i = 0; i < staves; ++i) {
        int cTie = 0;
        int cNote = 0;

        while (cTie < ties.size() && cNote < notes[i].size() - 1) {
          ArrayList<Integer> tie = ties.get(cTie);
          NotePanel prevNote = notes[i].get(cNote);
          NotePanel nextNote = notes[i].get(cNote + 1);
          if (pairComp(tie.get(0), tie.get(1), prevNote.lyLine, prevNote.lyNumber) != -1
              && pairComp(tie.get(0), tie.get(1), nextNote.lyLine, nextNote.lyNumber) != 1) {
            // tie is located between these notes
            nextNote.setTie(true);
            ++cNote;
            ++cTie;
          } else if (pairComp(tie.get(0), tie.get(1), prevNote.lyLine, prevNote.lyNumber) != -1) {
            ++cNote;
          } else {
            ++cTie;
          }
        }
      }

      PSIn.close();
    } catch (Exception e) {
      System.err.println("Parsing the score from Lilypond's output has failed. Error: ");
      e.printStackTrace();
    }
  }
  // RUN METHOD
  public void run() {

    for (int x = 0; x <= 3; x++) {
      selected[x] = false;
      questions[x] = "";
    }

    // Create new lists for the clients and threads
    if (clientSocketList == null || !clientSocketList.isEmpty()) {
      clientSocketList = new Vector<ClientConnection>();
    }

    if (clientThreadList == null || !clientThreadList.isEmpty()) {
      clientThreadList = new Vector<Thread>();
    }

    // Now we're ready to go
    isRunning = true;
    stopPressed = false;

    // Server initialization
    parent.updateStatusBox("SERVER ONLINE");
    parent.setStatus(new Color(32, 160, 32), "ONLINE");
    parent.setButtonEnabled(parent.STOP_BUTTON, true);

    Socket clientSocket = null;

    // SERVER CONNECTION LOOP AND CLIENT THREAD GENERATION
    while (!stopPressed) {
      try {
        // Create a new socket and wait for a client connection
        parent.updateStatusBox("Listening for clients on port: " + String.valueOf(port));
        serverSocket = new ServerSocket(port);
        clientSocket = serverSocket.accept();

        // Once a connection is established, we pass it off to clientConnected, which creates a new
        // thread
        //      to manage this client
        clientConnected(clientSocket);

      } catch (IOException e) {
        // No need to implement anything here -- cleanup is taken care of outside the loop
        // TODO: Move cleanup to a FINALLY block
        parent.updateStatusBox(e.getMessage());
      } finally {

        try {
          if (serverSocket != null) {
            serverSocket.close();
          }
        } catch (IOException e) {
          parent.updateStatusBox(e.getMessage());
        }
      }
    }

    // We're responsible adults...once we leave the server connection loop, we need to clean up
    // (close all
    //      connections) before we can officially stop the server.
    parent.updateStatusBox("Stopping server...");

    // Instead of locking clientSocketList inside of a huge synchronized block, just make a copy of
    // it
    //      This is a good idea because as clients disconnect, they will be asking to remove
    // themselves from
    //      the clientSocketList, and we don't want them to wait
    Vector<ClientConnection> snapshot = new Vector<ClientConnection>();
    snapshot.addAll(clientSocketList);
    Iterator<ClientConnection> clientIterator = snapshot.iterator();
    ClientConnection clientConnection;

    // This loop iterates through all of the currently connected clients and disconnects them
    while (clientIterator.hasNext()) {
      clientConnection = clientIterator.next();
      parent.updateStatusBox("Stopping client from ServerRunnable Loop");
      disconnectClient(clientConnection);
    }
    snapshot.clear();

    // Once we've cleaned up, we let the user know that the server is down and re-enable the Start
    // Server button
    parent.updateStatusBox("\nSERVER SHUTDOWN COMPLETE");
    parent.setStatus(Color.RED, "OFFLINE");
    isRunning = false;
    parent.setButtonEnabled(parent.GO_BUTTON, true);
  }