コード例 #1
0
  private ProgressMonitorInputStream getMonitorableStream(InputStream stream, String message) {

    final ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(this, message, stream);

    ProgressMonitor progress = pmis.getProgressMonitor();
    progress.setMillisToDecideToPopup(1);
    progress.setMillisToPopup(1);

    return pmis;
  }
コード例 #2
0
ファイル: BoggleGUI.java プロジェクト: nv23/Boggle
  /**
   * Read word list from file with name WORDLISTFILENAME, and pass a Set containing those words to
   * the computer player to intialize its lexicon.
   */
  private void initLexicon(InputStream stream) {

    ProgressMonitorInputStream pmis;
    ProgressMonitor progress = null;
    pmis = new ProgressMonitorInputStream(this, "reading words", stream);
    progress = pmis.getProgressMonitor();
    progress.setMillisToDecideToPopup(10);
    Scanner s = new Scanner(pmis);
    myLexicon.load(s);
    try {
      pmis.close();
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          null, "Error Closing Stream", "Error", JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #3
0
  private ProgressMonitorInputStream getMonitorableStream(File file, String message) {
    try {
      FileInputStream stream = new FileInputStream(file);
      if (stream == null) {
        System.out.println("null on " + file.getCanonicalPath());
      }
      final ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(this, message, stream);

      ProgressMonitor progress = pmis.getProgressMonitor();
      progress.setMillisToDecideToPopup(1);
      progress.setMillisToPopup(1);

      return pmis;
    } catch (IOException e) {
      showError("could not open " + file.getName());
      e.printStackTrace();
      return null;
    }
  }
コード例 #4
0
  public void run() {
    WindowBlocker blocker = new WindowBlocker(NearInfinity.getInstance());
    blocker.setBlocked(true);
    List<ResourceEntry> creFiles = ResourceFactory.getInstance().getResources("CRE");
    creFiles.addAll(ResourceFactory.getInstance().getResources("CHR"));
    ProgressMonitor progress =
        new ProgressMonitor(
            NearInfinity.getInstance(), "Checking inventories...", null, 0, creFiles.size());
    table =
        new SortableTable(
            new String[] {"File", "Name", "Item", "Message"},
            new Class[] {Object.class, Object.class, Object.class, Object.class},
            new int[] {100, 100, 200, 200});
    for (int i = 0; i < creFiles.size(); i++) {
      ResourceEntry entry = creFiles.get(i);
      try {
        if (typeButtons[0].isSelected())
          checkCreatureInventory((CreResource) ResourceFactory.getResource(entry));
        if (typeButtons[1].isSelected())
          checkItemAttribute((CreResource) ResourceFactory.getResource(entry));
      } catch (Exception e) {
        e.printStackTrace();
      }
      progress.setProgress(i + 1);
      if (progress.isCanceled()) {
        JOptionPane.showMessageDialog(
            NearInfinity.getInstance(),
            "Operation canceled",
            "Info",
            JOptionPane.INFORMATION_MESSAGE);
        blocker.setBlocked(false);
        return;
      }
    }

    if (table.getRowCount() == 0)
      JOptionPane.showMessageDialog(
          NearInfinity.getInstance(), "No hits found", "Info", JOptionPane.INFORMATION_MESSAGE);
    else {
      resultFrame = new ChildFrame("Result of CRE inventory check", true);
      resultFrame.setIconImage(Icons.getIcon("Refresh16.gif").getImage());
      bopen = new JButton("Open", Icons.getIcon("Open16.gif"));
      bopennew = new JButton("Open in new window", Icons.getIcon("Open16.gif"));
      JLabel count = new JLabel(table.getRowCount() + " hit(s) found", JLabel.CENTER);
      count.setFont(count.getFont().deriveFont((float) count.getFont().getSize() + 2.0f));
      bopen.setMnemonic('o');
      bopennew.setMnemonic('n');
      resultFrame.getRootPane().setDefaultButton(bopennew);
      JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
      panel.add(bopen);
      panel.add(bopennew);
      JScrollPane scrollTable = new JScrollPane(table);
      scrollTable.getViewport().setBackground(table.getBackground());
      JPanel pane = (JPanel) resultFrame.getContentPane();
      pane.setLayout(new BorderLayout(0, 3));
      pane.add(count, BorderLayout.NORTH);
      pane.add(scrollTable, BorderLayout.CENTER);
      pane.add(panel, BorderLayout.SOUTH);
      bopen.setEnabled(false);
      bopennew.setEnabled(false);
      table.setFont(BrowserMenuBar.getInstance().getScriptFont());
      table.getSelectionModel().addListSelectionListener(this);
      table.addMouseListener(
          new MouseAdapter() {
            public void mouseReleased(MouseEvent event) {
              if (event.getClickCount() == 2) {
                int row = table.getSelectedRow();
                if (row != -1) {
                  ResourceEntry resourceEntry = (ResourceEntry) table.getValueAt(row, 0);
                  Resource resource = ResourceFactory.getResource(resourceEntry);
                  new ViewFrame(resultFrame, resource);
                  ((AbstractStruct) resource)
                      .getViewer()
                      .selectEntry(((Item) table.getValueAt(row, 2)).getName());
                }
              }
            }
          });
      bopen.addActionListener(this);
      bopennew.addActionListener(this);
      pane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
      resultFrame.pack();
      Center.center(resultFrame, NearInfinity.getInstance().getBounds());
      resultFrame.setVisible(true);
    }
    blocker.setBlocked(false);
    //    for (int i = 0; i < table.getRowCount(); i++) {
    //      CreInvError error = (CreInvError)table.getTableItemAt(i);
    //      System.out.println(error.resourceEntry + " (" + error.resourceEntry.getSearchString() +
    // ") -> " + error.itemRef.getAttribute("Item"));
    //    }
  }
コード例 #5
0
  public void run() {
    WindowBlocker blocker = new WindowBlocker(NearInfinity.getInstance());
    blocker.setBlocked(true);
    BmpResource searchMap = null;
    List<ResourceEntry> files = ResourceFactory.getInstance().getResources("ARE");
    ProgressMonitor progress =
        new ProgressMonitor(NearInfinity.getInstance(), "Checking areas...", null, 0, files.size());
    errorTable =
        new SortableTable(
            new String[] {"Area", "Object", "Message"},
            new Class[] {Object.class, Object.class, Object.class},
            new int[] {100, 200, 200});
    long startTime = System.currentTimeMillis();

    exclude.clear();
    exclude.add("BIRD");
    exclude.add("EAGLE");
    exclude.add("SEAGULL");
    exclude.add("VULTURE");
    exclude.add("DOOM_GUARD");
    exclude.add("DOOM_GUARD_LARGER");
    exclude.add("BAT_INSIDE");
    exclude.add("BAT_OUTSIDE");

    //		exclude.add("CAT");
    //		exclude.add("MOOSE");
    //		exclude.add("RABBIT");
    exclude.add("SQUIRREL");
    exclude.add("RAT");
    //		exclude.add("STATIC_PEASANT_MAN_MATTE");
    //		exclude.add("STATIC_PEASANT_WOMAN_MATTE");

    for (int i = 0; i < files.size(); i++) {
      try {
        ResourceEntry entry = files.get(i);
        Resource area = ResourceFactory.getResource(entry);

        if (typeButtons[3].isSelected()) checkAreasConnectivity(entry, area);

        if (typeButtons[1].isSelected()) {
          String[] name = ((AreResource) area).getAttribute("WED resource").toString().split("\\.");
          ResourceEntry searchEntry =
              ResourceFactory.getInstance().getResourceEntry(name[0] + "SR.BMP");

          if (searchEntry == null) {
            searchMap = null;
            errorTable.addTableItem(
                new AreaTableLine(
                    entry,
                    ((AreResource) area).getAttribute("WED resource"),
                    "Area don't have search map"));
          } else {
            searchMap = (BmpResource) ResourceFactory.getResource(searchEntry);
          }
        }

        List<StructEntry> list = ((AreResource) area).getList();
        for (int j = 0; j < list.size(); j++) {
          if (list.get(j) instanceof Actor) {
            Actor actor = (Actor) list.get(j);
            StructEntry time = actor.getAttribute("Expiry time");
            if (typeButtons[0].isSelected() && ((DecNumber) time).getValue() != -1)
              errorTable.addTableItem(
                  new AreaTableLine(
                      entry, actor, "Actor expiry time is: " + ((DecNumber) time).getValue()));

            if (searchMap != null) checkActorPosition(entry, actor, searchMap);
          }

          if (typeButtons[2].isSelected() && list.get(j) instanceof Container) {
            ResourceRef keyRes = (ResourceRef) ((AbstractStruct) list.get(j)).getAttribute("Key");
            if (!keyRes.getResourceName().equalsIgnoreCase("None.ITM")
                && !ResourceFactory.getInstance().resourceExists(keyRes.getResourceName())) {
              errorTable.addTableItem(
                  new AreaTableLine(
                      entry,
                      list.get(j),
                      "Non existent key item for container: " + keyRes.getResourceName()));
            }
            checkContainedItem(entry, list.get(j));
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      progress.setProgress(i + 1);
      if (progress.isCanceled()) {
        JOptionPane.showMessageDialog(
            NearInfinity.getInstance(),
            "Operation canceled",
            "Info",
            JOptionPane.INFORMATION_MESSAGE);
        blocker.setBlocked(false);
        return;
      }
    }
    System.out.println("Check took " + (System.currentTimeMillis() - startTime) + "ms");
    if (errorTable.getRowCount() == 0)
      JOptionPane.showMessageDialog(
          NearInfinity.getInstance(), "No errors found", "Info", JOptionPane.INFORMATION_MESSAGE);
    else {
      errorTable.tableComplete();
      resultFrame = new ChildFrame("Result", true);
      resultFrame.setIconImage(Icons.getIcon("Find16.gif").getImage());
      bopen = new JButton("Open", Icons.getIcon("Open16.gif"));
      bopennew = new JButton("Open in new window", Icons.getIcon("Open16.gif"));
      bopen.setMnemonic('o');
      bopennew.setMnemonic('n');
      resultFrame.getRootPane().setDefaultButton(bopennew);
      JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
      panel.add(bopen);
      panel.add(bopennew);
      JLabel count = new JLabel(errorTable.getRowCount() + " errors found", JLabel.CENTER);
      count.setFont(count.getFont().deriveFont((float) count.getFont().getSize() + 2.0f));
      JScrollPane scrollTable = new JScrollPane(errorTable);
      scrollTable.getViewport().setBackground(errorTable.getBackground());
      JPanel pane = (JPanel) resultFrame.getContentPane();
      pane.setLayout(new BorderLayout(0, 3));
      pane.add(count, BorderLayout.NORTH);
      pane.add(scrollTable, BorderLayout.CENTER);
      pane.add(panel, BorderLayout.SOUTH);
      bopen.setEnabled(false);
      bopennew.setEnabled(false);
      errorTable.setFont(BrowserMenuBar.getInstance().getScriptFont());
      errorTable.addMouseListener(
          new MouseAdapter() {
            public void mouseReleased(MouseEvent event) {
              if (event.getClickCount() == 2) {
                int row = errorTable.getSelectedRow();
                if (row != -1) {
                  ResourceEntry resourceEntry = (ResourceEntry) errorTable.getValueAt(row, 0);
                  Resource resource = ResourceFactory.getResource(resourceEntry);
                  new ViewFrame(resultFrame, resource);
                  ((AbstractStruct) resource)
                      .getViewer()
                      .selectEntry((String) errorTable.getValueAt(row, 1));
                }
              }
            }
          });
      bopen.addActionListener(this);
      bopennew.addActionListener(this);
      pane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
      errorTable.getSelectionModel().addListSelectionListener(this);
      resultFrame.pack();
      Center.center(resultFrame, NearInfinity.getInstance().getBounds());
      resultFrame.setVisible(true);
    }
    blocker.setBlocked(false);
  }