private void checkItemAttribute(CreResource cre) { List<StructEntry> list = cre.getList(); for (int i = 0; i < list.size(); i++) if (list.get(i) instanceof Item) { Item item = (Item) list.get(i); if (((ResourceRef) item.getAttribute("Item")) .getResourceName() .equalsIgnoreCase("None.ITM")) { table.addTableItem(new CreInvError(cre.getResourceEntry(), item, "Empty item ref")); continue; } StructEntry wear = item.getAttribute("Wear"); if (((DecNumber) wear).getValue() != 0) { table.addTableItem( new CreInvError( cre.getResourceEntry(), item, "Wear is: " + ((DecNumber) wear).getValue())); } for (int j = 4; j < 8 * ((Flag) item.getAttribute("Flags")).getSize(); j++) if (((Flag) item.getAttribute("Flags")).isFlagSet(j)) { table.addTableItem( new CreInvError( cre.getResourceEntry(), item, "Item flag is: " + item.getAttribute("Flags").toString())); break; } } }
private void checkContainedItem(ResourceEntry entry, StructEntry container) { List<StructEntry> cont_list = ((AbstractStruct) container).getList(); for (int i = 0; i < cont_list.size(); i++) if (cont_list.get(i) instanceof Item) { Item item = (Item) cont_list.get(i); ResourceRef itemRes = (ResourceRef) item.getAttribute("Item"); if (!ResourceFactory.getInstance().resourceExists(itemRes.getResourceName())) { errorTable.addTableItem( new AreaTableLine( entry, container, "Non existent item in container: " + itemRes.getResourceName())); } StructEntry wear = item.getAttribute("Wear"); if (((DecNumber) wear).getValue() != 0) { errorTable.addTableItem( new AreaTableLine(entry, container, "Wear is: " + ((DecNumber) wear).getValue())); } for (int j = 1; j < 8 * ((Flag) item.getAttribute("Flags")).getSize(); j++) if (((Flag) item.getAttribute("Flags")).isFlagSet(j)) { errorTable.addTableItem( new AreaTableLine( entry, container, "Item flag is: " + item.getAttribute("Flags").toString())); break; } } }
public void actionPerformed(ActionEvent event) { if (event.getSource() == bstart) { selectframe.setVisible(false); for (int i = 0; i < typeButtons.length; i++) if (typeButtons[i].isSelected()) { new Thread(this).start(); return; } } else if (event.getSource() == bcancel) selectframe.setVisible(false); else if (event.getSource() == bopen) { int row = errorTable.getSelectedRow(); if (row != -1) { ResourceEntry resourceEntry = (ResourceEntry) errorTable.getValueAt(row, 0); NearInfinity.getInstance().showResourceEntry(resourceEntry); } } else if (event.getSource() == bopennew) { 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)); } } }
public void valueChanged(ListSelectionEvent event) { if (table.getSelectedRow() == -1) textArea.setText(null); else { TableItem item = table.getTableItemAt(table.getSelectedRow()); textArea.setText(item.toString()); } textArea.setCaretPosition(0); }
public Component getDemoPanel() { TableModel model = new SampleTableModel(); _sortableTable = new SortableTable(model); _sortableTable.setAutoResizeMode(JideTable.AUTO_RESIZE_FILL); _sortableTable.setNestedTableHeader(true); _sortableTable.setFillsGrids(false); TableColumnGroup longText = new TableColumnGroup( "This is a very long column header title. You can resize the table header column and see how this long text automatically wraps according to the column width. " + "The current configuration specified {minimum two rows:f:red} and {maximum five rows:f:blue}. You could take a look at StyledLabelBuilderDemo to see what other annotations are available in the text.@r:3:2:5"); longText.add(_sortableTable.getColumnModel().getColumn(0)); longText.add(_sortableTable.getColumnModel().getColumn(1)); longText.add(_sortableTable.getColumnModel().getColumn(2)); longText.add(_sortableTable.getColumnModel().getColumn(3)); longText.add(_sortableTable.getColumnModel().getColumn(4)); longText.add(_sortableTable.getColumnModel().getColumn(5)); longText.add(_sortableTable.getColumnModel().getColumn(6)); if (_sortableTable.getTableHeader() instanceof NestedTableHeader) { NestedTableHeader header = (NestedTableHeader) _sortableTable.getTableHeader(); header.addColumnGroup(longText); } TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(_sortableTable); installer.addTableHeaderPopupMenuCustomizer(new TableColumnChooserPopupMenuCustomizer()); TableUtils.autoResizeAllColumns(_sortableTable); return new JScrollPane(_sortableTable); }
public void actionPerformed(ActionEvent e) { if (e.getSource() == save) { JFileChooser c = new JFileChooser(ResourceFactory.getRootDir()); c.setDialogTitle("Save result"); if (c.showSaveDialog(resultFrame) == JFileChooser.APPROVE_OPTION) { File output = c.getSelectedFile(); if (output.exists()) { String[] options = {"Overwrite", "Cancel"}; if (JOptionPane.showOptionDialog( resultFrame, output + "exists. Overwrite?", "Save result", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]) == 1) return; } try { PrintWriter w = new PrintWriter(new BufferedWriter(new FileWriter(output))); w.println("Searched for unused strings"); w.println("Number of hits: " + table.getRowCount()); w.println(""); for (int i = 0; i < table.getRowCount(); i++) { w.println( "StringRef: " + table.getTableItemAt(i).getObjectAt(1) + " /* " + table .getTableItemAt(i) .toString() .replaceAll("\r\n", System.getProperty("line.separator")) + " */"); } w.close(); JOptionPane.showMessageDialog( resultFrame, "Result saved to " + output, "Save complete", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog( resultFrame, "Error while saving " + output, "Error", JOptionPane.ERROR_MESSAGE); ex.printStackTrace(); } } } }
private void checkActorPosition(ResourceEntry entry, Actor actor, BmpResource searchMap) { String anim = actor.getAttribute("Animation").toString(); ResourceEntry creEntry; CreResource creature = null; if (actor.getAttribute("Character") instanceof ResourceRef && actor.getAttribute("Character").toString() != "None") { creEntry = ResourceFactory.getInstance() .getResourceEntry(((ResourceRef) actor.getAttribute("Character")).getResourceName()); creature = (CreResource) ResourceFactory.getResource(creEntry); } else if (actor.getAttribute("CRE file") != null) creature = (CreResource) actor.getAttribute("CRE file"); if (creature == null || ((IdsFlag) creature.getAttribute("Status")).isFlagSet(0) || ((IdsFlag) creature.getAttribute("Status")).isFlagSet(11)) return; if (!exclude.contains(anim.substring(0, anim.indexOf(" ")))) { int x = ((DecNumber) actor.getAttribute("Position: X")).getValue() / 16; int y = ((DecNumber) actor.getAttribute("Position: Y")).getValue() / 12; if (!Passable[searchMap.getPalette().getIndex(searchMap.getImage().getRGB(x, y) & 0xFFFFFF)]) errorTable.addTableItem( new AreaTableLine( entry, actor, "Impassable actor position (" + creature.getAttribute("Name").toString() + ")")); } }
private void checkAreaEntrance(ResourceEntry entry, ITEPoint tTriger, ResourceRef dAreaRef) { boolean isFound = false; TextString entName; AreResource dArea; entName = (TextString) tTriger.getAttribute("Entrance name"); dArea = (AreResource) ResourceFactory.getResource( ResourceFactory.getInstance().getResourceEntry(dAreaRef.getResourceName())); List<StructEntry> list = dArea.getList(); for (int i = 0; i < list.size(); i++) if (list.get(i) instanceof Entrance && entName .toString() .equalsIgnoreCase(((Entrance) list.get(i)).getAttribute("Name").toString())) isFound = true; if (!isFound) errorTable.addTableItem( new AreaTableLine( entry, tTriger, "No target entrance " + entName.toString() + " in area " + dAreaRef.getResourceName())); }
private void checkAreasConnectivity(ResourceEntry entry, Resource area) { ResourceRef darearef, rref; ITEPoint ttriger; checkNearestArea(entry, "Area north"); checkNearestArea(entry, "Area east"); checkNearestArea(entry, "Area south"); checkNearestArea(entry, "Area west"); List<StructEntry> list = ((AreResource) area).getList(); for (int i = 0; i < list.size(); i++) if (list.get(i) instanceof ITEPoint) { ttriger = (ITEPoint) list.get(i); if (((Bitmap) ttriger.getAttribute("Type")).getValue() == 2) { darearef = (ResourceRef) ttriger.getAttribute("Destination area"); if (!ResourceFactory.getInstance().resourceExists(darearef.getResourceName())) { rref = (ResourceRef) ttriger.getAttribute("Script"); if (!ResourceFactory.getInstance().resourceExists(rref.getResourceName())) errorTable.addTableItem( new AreaTableLine( entry, ttriger, "No target area " + darearef.getResourceName())); } else checkAreaEntrance(entry, ttriger, darearef); } } }
private void checkNearestArea(ResourceEntry entry, String direction) { ResourceRef rref; rref = (ResourceRef) ((AreResource) ResourceFactory.getResource(entry)).getAttribute(direction); if (rref != null && !rref.getResourceName().equalsIgnoreCase("None.ARE") && !ResourceFactory.getInstance().resourceExists(rref.getResourceName())) errorTable.addTableItem( new AreaTableLine(entry, rref, "No target area " + rref.getResourceName())); }
private void checkCreatureInventory(CreResource cre) { HexNumber slots_offset = (HexNumber) cre.getAttribute("Item slots offset"); items.clear(); slots.clear(); for (int i = 0; i < cre.getRowCount(); i++) { StructEntry entry = cre.getStructEntryAt(i); if (entry instanceof Item) items.add(entry); else if (entry.getOffset() >= slots_offset.getValue() + cre.getOffset() && entry instanceof DecNumber && !entry.getName().equals("Weapon slot selected") && !entry.getName().equals("Weapon ability selected")) slots.add(entry); } for (int i = 0; i < slots.size(); i++) { DecNumber slot = (DecNumber) slots.get(i); if (slot.getValue() >= 0 && slot.getValue() < items.size()) items.set(slot.getValue(), slots_offset); // Dummy object } for (int i = 0; i < items.size(); i++) { if (items.get(i) != slots_offset) { Item item = (Item) items.get(i); table.addTableItem(new CreInvError(cre.getResourceEntry(), item, "Item not in inventory")); } } }
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")); // } }
public void run() { WindowBlocker blocker = new WindowBlocker(NearInfinity.getInstance()); blocker.setBlocked(true); List<ResourceEntry> files = new ArrayList<ResourceEntry>(); for (final String fileType : FILETYPES) files.addAll(ResourceFactory.getInstance().getResources(fileType)); ProgressMonitor progress = new ProgressMonitor(NearInfinity.getInstance(), "Searching...", null, 0, files.size()); table = new SortableTable( new String[] {"String", "StrRef"}, new Class[] {Object.class, Integer.class}, new int[] {450, 20}); StringResource.getStringRef(0); strUsed = new boolean[StringResource.getMaxIndex() + 1]; for (int i = 0; i < files.size(); i++) { ResourceEntry entry = files.get(i); Resource resource = ResourceFactory.getResource(entry); if (resource instanceof DlgResource) checkDialog((DlgResource) resource); else if (resource instanceof BcsResource) checkScript((BcsResource) resource); else if (resource instanceof PlainTextResource) checkTextfile((PlainTextResource) resource); else if (resource != null) checkStruct((AbstractStruct) resource); progress.setProgress(i + 1); if (progress.isCanceled()) { JOptionPane.showMessageDialog( NearInfinity.getInstance(), "Operation canceled", "Info", JOptionPane.INFORMATION_MESSAGE); blocker.setBlocked(false); return; } } for (int i = 0; i < strUsed.length; i++) if (!strUsed[i]) table.addTableItem(new UnusedStringTableItem(new Integer(i))); if (table.getRowCount() == 0) JOptionPane.showMessageDialog( NearInfinity.getInstance(), "No unused strings found", "Info", JOptionPane.INFORMATION_MESSAGE); else { table.tableComplete(1); textArea = new JTextArea(10, 40); textArea.setEditable(false); textArea.setWrapStyleWord(true); textArea.setLineWrap(true); JScrollPane scrollText = new JScrollPane(textArea); resultFrame = new ChildFrame("Result", true); save = new JMenuItem("Save"); save.addActionListener(this); JMenu fileMenu = new JMenu("File"); fileMenu.add(save); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); resultFrame.setJMenuBar(menuBar); resultFrame.setIconImage(Icons.getIcon("Find16.gif").getImage()); JLabel count = new JLabel(table.getRowCount() + " unused string(s) found", JLabel.CENTER); count.setFont(count.getFont().deriveFont((float) count.getFont().getSize() + 2.0f)); 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); JPanel bottomPanel = new JPanel(new BorderLayout()); JPanel searchPanel = SearchMaster.createAsPanel(this, resultFrame); bottomPanel.add(scrollText, BorderLayout.CENTER); bottomPanel.add(searchPanel, BorderLayout.EAST); pane.add(bottomPanel, BorderLayout.SOUTH); table.setFont(BrowserMenuBar.getInstance().getScriptFont()); pane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); table.getSelectionModel().addListSelectionListener(this); resultFrame.pack(); Center.center(resultFrame, NearInfinity.getInstance().getBounds()); resultFrame.setVisible(true); } blocker.setBlocked(false); }
public void hitFound(int nr) { table.getSelectionModel().addSelectionInterval(nr, nr); table.scrollRectToVisible( table.getCellRect(table.getSelectionModel().getMinSelectionIndex(), 0, true)); }
public String getText(int nr) { if (nr < 0 || nr >= table.getRowCount()) return null; return table.getTableItemAt(nr).toString(); }
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); }