@SuppressWarnings("unchecked") @Override public int loop() { synchronized (lock) { try { if (!ui.isVisible()) handler.stopMod(getName()); World world = minecraft.getWorld(); JTable list = ui.getList(); DefaultTableModel model = (DefaultTableModel) list.getModel(); TableRowSorter<TableModel> sorter = (TableRowSorter<TableModel>) list.getRowSorter(); if (world != null) { Player currentPlayer = minecraft.getPlayer(); int playerX = (int) java.lang.Math.round(currentPlayer.getX()); int playerY = (int) java.lang.Math.round(currentPlayer.getY()); int playerZ = (int) java.lang.Math.round(currentPlayer.getZ()); ArrayList<Block> blocks = new ArrayList<Block>(); for (int x = playerX - radius; x < playerX + radius; x++) for (int y = playerY - radius; y < playerY + radius; y++) for (int z = playerZ - radius; z < playerZ + radius; z++) if (world.getBlockIDAt(x, y, z) == blockID) blocks.add(new Block(x, y, z)); label: for (int row = 0; row < model.getRowCount(); row++) { int x = (Integer) model.getValueAt(row, 1); int y = (Integer) model.getValueAt(row, 2); int z = (Integer) model.getValueAt(row, 3); for (Block block : blocks) { if (x == block.getX() && y == block.getY() && z == block.getZ()) { model.setValueAt(getDistanceTo(x, y, z, currentPlayer), row, 0); continue label; } } model.removeRow(row); } label: for (Block block : blocks) { for (int row = 0; row < model.getRowCount(); row++) { int x = (Integer) model.getValueAt(row, 1); int y = (Integer) model.getValueAt(row, 2); int z = (Integer) model.getValueAt(row, 3); if (x == block.getX() && y == block.getY() && z == block.getZ()) continue label; } model.addRow( new Object[] { getDistanceTo(block.getX(), block.getY(), block.getZ(), minecraft.getPlayer()), block.getX(), block.getY(), block.getZ() }); } sorter.sort(); list.repaint(); } else { for (int i = model.getRowCount() - 1; i >= 0; i--) model.removeRow(i); } } catch (Exception exception) { } } return 500; }
/** * Gets the list of selected records. * * @return the list of selected records. */ public Variability[] getSelectedRecords() { ArrayList list = new ArrayList(); int check_column = getCheckColumn(); for (int i = 0; i < model.getRowCount(); i++) { if (((Boolean) getValueAt(i, check_column)).booleanValue()) { Variability record = (Variability) record_list.elementAt(index.get(i)); list.add(record); } } Variability[] records = new Variability[list.size()]; return (Variability[]) list.toArray(records); }
public Collection<Item> getSelection() { ArrayList<Item> result = new ArrayList<Item>(); int[] selectedRows = getSelectedRows(); if (selectedRows == null) return result; final List<Item> items = getItems(); if (!items.isEmpty()) { for (int selectedRow : selectedRows) { final int modelIndex = convertRowIndexToModel(selectedRow); if (modelIndex >= 0 && modelIndex < items.size()) { result.add(items.get(modelIndex)); } } } return result; }
// Add/Insert public int add(Script script) { // Find the correct spot to add it alphabetically int i, limit; for (i = 0, limit = scripts.size(); i < limit; i++) { Script scriptTemp = (Script) scripts.get(i); if (scriptTemp.getName().compareTo(script.getName()) >= 0) { break; } } scripts.add(i, script); // Update the table fireTableRowsInserted(i, i); return i; }
public void removeMessages(Message[] removedMessages) { try { // Translate the array of removed Message instances into a list of all the row indexes to be // removed from the model. // Assumes the list of removed messages is small. ArrayList<Integer> deadIndexes = new ArrayList<Integer>(); for (Message message : removedMessages) { int deadIndex = messages.indexOf(message); if (deadIndex != -1) { deadIndexes.add(deadIndex); } } // Actually remove the rows, notifying the listeners as we go (rather than bother trying to // coalesce). for (int i = deadIndexes.size() - 1; i >= 0; --i) { int deadIndex = deadIndexes.get(i); messages.remove(deadIndex); fireTableRowsDeleted(deadIndex, deadIndex); } } catch (Exception ex) { ex.printStackTrace(); } }
public SparseTableModel() { headers = new ArrayList<String>(); headers.add(""); lookup = new SparseTable(); }
public Ssys3() { store = new Storage(); tableSorter = new TableRowSorter<Storage>(store); jobs = new LinkedList<String>(); makeGUI(); frm.setSize(800, 600); frm.addWindowListener( new WindowListener() { public void windowActivated(WindowEvent evt) {} public void windowClosed(WindowEvent evt) { try { System.out.println("joining EDT's"); for (EDT edt : encryptDecryptThreads) { edt.weakStop(); try { edt.join(); System.out.println(" - joined"); } catch (InterruptedException e) { System.out.println(" - Not joined"); } } System.out.println("saving storage"); store.saveAll(tempLoc); } catch (IOException e) { e.printStackTrace(); System.err.println( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nFailed to save properly\n\n!!!!!!!!!!!!!!!!!!!!!!!!!"); System.exit(1); } clean(); System.exit(0); } public void windowClosing(WindowEvent evt) { windowClosed(evt); } public void windowDeactivated(WindowEvent evt) {} public void windowDeiconified(WindowEvent evt) {} public void windowIconified(WindowEvent evt) {} public void windowOpened(WindowEvent evt) {} }); ImageIcon ico = new ImageIcon(ICON_NAME); frm.setIconImage(ico.getImage()); frm.setLocationRelativeTo(null); frm.setVisible(true); // load config storeLocs = new ArrayList<File>(); String ossl = "openssl"; int numThreadTemp = 2; boolean priorityDecryptTemp = true; boolean allowExportTemp = false; boolean checkImportTemp = true; try { Scanner sca = new Scanner(CONF_FILE); while (sca.hasNextLine()) { String ln = sca.nextLine(); if (ln.startsWith(CONF_SSL)) { ossl = ln.substring(CONF_SSL.length()); } else if (ln.startsWith(CONF_THREAD)) { try { numThreadTemp = Integer.parseInt(ln.substring(CONF_THREAD.length())); } catch (Exception exc) { // do Nothing } } else if (ln.equals(CONF_STORE)) { while (sca.hasNextLine()) storeLocs.add(new File(sca.nextLine())); } else if (ln.startsWith(CONF_PRIORITY)) { try { priorityDecryptTemp = Boolean.parseBoolean(ln.substring(CONF_PRIORITY.length())); } catch (Exception exc) { // do Nothing } } else if (ln.startsWith(CONF_EXPORT)) { try { allowExportTemp = Boolean.parseBoolean(ln.substring(CONF_EXPORT.length())); } catch (Exception exc) { // do Nothing } } else if (ln.startsWith(CONF_CONFIRM)) { try { checkImportTemp = Boolean.parseBoolean(ln.substring(CONF_CONFIRM.length())); } catch (Exception exc) { // do Nothing } } } sca.close(); } catch (IOException e) { } String osslWorks = OpenSSLCommander.test(ossl); while (osslWorks == null) { ossl = JOptionPane.showInputDialog( frm, "Please input the command used to run open ssl\n We will run \"<command> version\" to confirm\n Previous command: " + ossl, "Find open ssl", JOptionPane.OK_CANCEL_OPTION); if (ossl == null) { System.err.println("Refused to provide openssl executable location"); System.exit(1); } osslWorks = OpenSSLCommander.test(ossl); if (osslWorks == null) JOptionPane.showMessageDialog( frm, "Command " + ossl + " unsuccessful", "Unsuccessful", JOptionPane.ERROR_MESSAGE); } if (storeLocs.size() < 1) JOptionPane.showMessageDialog( frm, "Please select an initial sotrage location\nIf one already exists, or there are more than one, please select it"); while (storeLocs.size() < 1) { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (jfc.showOpenDialog(frm) != JFileChooser.APPROVE_OPTION) { System.err.println("Refused to provide an initial store folder"); System.exit(1); } File sel = jfc.getSelectedFile(); if (sel.isDirectory()) storeLocs.add(sel); } numThreads = numThreadTemp; priorityExport = priorityDecryptTemp; allowExport = allowExportTemp; checkImports = checkImportTemp; try { PrintWriter pw = new PrintWriter(CONF_FILE); pw.println(CONF_SSL + ossl); pw.println(CONF_THREAD + numThreads); pw.println(CONF_PRIORITY + priorityExport); pw.println(CONF_EXPORT + allowExport); pw.println(CONF_CONFIRM + checkImports); pw.println(CONF_STORE); for (File fi : storeLocs) { pw.println(fi.getAbsolutePath()); } pw.close(); } catch (IOException e) { System.err.println("Failed to save config"); } File chk = null; for (File fi : storeLocs) { File lib = new File(fi, LIBRARY_NAME); if (lib.exists()) { chk = lib; // break; } } char[] pass = null; if (chk == null) { JOptionPane.showMessageDialog( frm, "First time run\n Create your password", "Create Password", JOptionPane.INFORMATION_MESSAGE); char[] p1 = askPassword(); char[] p2 = askPassword(); boolean same = p1.length == p2.length; for (int i = 0; i < Math.min(p1.length, p2.length); i++) { if (p1[i] != p2[i]) same = false; } if (same) { JOptionPane.showMessageDialog( frm, "Password created", "Create Password", JOptionPane.INFORMATION_MESSAGE); pass = p1; } else { JOptionPane.showMessageDialog( frm, "Passwords dont match", "Create Password", JOptionPane.ERROR_MESSAGE); System.exit(1); } } else { pass = askPassword(); } sec = OpenSSLCommander.getCommander(chk, pass, ossl); if (sec == null) { System.err.println("Wrong Password"); System.exit(1); } store.useSecurity(sec); store.useStorage(storeLocs); tempLoc = new File("temp"); if (!tempLoc.exists()) tempLoc.mkdirs(); // load stores try { store.loadAll(tempLoc); store.fireTableDataChanged(); } catch (IOException e) { System.err.println("Storage loading failure"); System.exit(1); } needsSave = false; encryptDecryptThreads = new EDT[numThreads]; for (int i = 0; i < encryptDecryptThreads.length; i++) { encryptDecryptThreads[i] = new EDT(i); encryptDecryptThreads[i].start(); } updateStatus(); txaSearch.grabFocus(); }
public void secureImport() { JFileChooser imp = new JFileChooser(); imp.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); imp.setMultiSelectionEnabled(true); int ret = imp.showOpenDialog(frm); if (ret != JFileChooser.APPROVE_OPTION) { return; } File[] fis = imp.getSelectedFiles(); ArrayList<String> impJobs = new ArrayList<String>(); boolean dirs = false; for (File fi : fis) { if (fi.isDirectory()) { dirs = true; File lib = new File(fi, LIBRARY_NAME); if (lib.exists()) { try { Scanner sca = new Scanner(lib); while (sca.hasNextLine()) { String nm = sca.nextLine(); String date = sca.nextLine(); String tags = sca.nextLine(); File addr = new File(fi, nm); if (addr.exists() && !addr.isDirectory()) impJobs.add(impJob(addr, date, tags)); } sca.close(); } catch (IOException exc) { // add nothing? } } else { for (File cont : fi.listFiles()) if (!cont.isDirectory()) impJobs.add(impJob(cont, null, null)); } } else { impJobs.add(impJob(fi, null, null)); } } if (impJobs.size() > 1 || dirs) { // dont bother user if selected single file String shw = "Importing:"; if (impJobs.size() > 30) shw = null; int pcount = 0; for (String jb : impJobs) { String[] prts = jb.split(",", 4); // import jobs have 4 parts, import, name, date, tags if (shw != null) shw = shw + "\n - " + new File(prts[1]).getName(); if (!prts[3].equalsIgnoreCase(Storage.NEW_TAG)) { pcount++; if (shw != null) shw = shw + " []"; } } if (shw == null) shw = "importing "; else shw = shw + "\n"; shw = shw + impJobs.size() + "(" + pcount + ") files"; if (JOptionPane.showConfirmDialog(frm, shw, "Confirm Import", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) return; } synchronized (jobs) { for (String j : impJobs) { if (priorityExport) jobs.addLast(j); else jobs.addFirst(j); } } updateStatus(); }
public ArrayList getSelectedMessages() { ArrayList list = new ArrayList(); for (int i = 0; i < table.getRowCount(); i++) { if (((Boolean) table.getValueAt(i, 0)) == true) { list.add(msgID[i]); } } return list; }