/** * Recursively rebuild the tree nodes. * * @param root The full abstract path to the root saved layout directory. * @param local The current directory relative to root (null if none). * @param tnode The current parent tree node. */ private void rebuildTreeModel(Path root, Path local, DefaultMutableTreeNode tnode) { TreeSet<Path> subdirs = new TreeSet<Path>(); TreeSet<String> layouts = new TreeSet<String>(); { Path current = new Path(root, local); File files[] = current.toFile().listFiles(); if (files != null) { int wk; for (wk = 0; wk < files.length; wk++) { String name = files[wk].getName(); if (files[wk].isDirectory()) subdirs.add(new Path(local, name)); else if (files[wk].isFile()) layouts.add(name); } } } for (Path subdir : subdirs) { TreeData data = new TreeData(subdir); DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, true); tnode.add(child); rebuildTreeModel(root, subdir, child); } for (String lname : layouts) { TreeData data = new TreeData(new Path(local, lname), lname); DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, false); tnode.add(child); } }
private ArrayList<Path> holeLaufwerkeWindows() { ArrayList<Path> laufwerksRoot = new ArrayList<>(); Iterable<Path> rootDirectories = FileSystems.getDefault().getRootDirectories(); for (Path path : rootDirectories) { laufwerksRoot.add(path.getRoot()); } return laufwerksRoot; }
private int getNumberOfItems(Path quellOrdner) { int retValue = 0; try { DirectoryStream<Path> qstream = Files.newDirectoryStream(quellOrdner); for (Path qfile : qstream) { if (Files.isDirectory(qfile)) { getNumberOfItems(Paths.get(quellOrdner.toString() + "/" + qfile.getFileName())); } i++; } qstream.close(); } catch (IOException e) { e.printStackTrace(); } retValue = i; return retValue; }
public Path dateiAuswählen(Path neuesLaufwerk) { JFileChooser fc1 = new JFileChooser(); fc1.setDialogTitle("SyncOrdner auswählen"); fc1.setCurrentDirectory(neuesLaufwerk.toFile()); fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fc1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) return fc1.getSelectedFile().toPath(); else return null; }
/** * Update the layouts tree. * * @param current The name of the current layout or <CODE>null</CODE> if none. */ public void updateLayouts(Path current) throws PipelineException { DefaultMutableTreeNode root = null; { root = new DefaultMutableTreeNode(new TreeData(), true); { Path path = new Path(PackageInfo.getSettingsPath(), "layouts"); rebuildTreeModel(path, new Path("/"), root); } DefaultTreeModel model = (DefaultTreeModel) pTree.getModel(); model.setRoot(root); { Enumeration e = root.depthFirstEnumeration(); if (e != null) { while (e.hasMoreElements()) { DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) e.nextElement(); pTree.expandPath(new TreePath(tnode.getPath())); } } } } pTree.clearSelection(); if (current != null) { TreePath tpath = null; DefaultMutableTreeNode tnode = root; for (String comp : current.getComponents()) { DefaultMutableTreeNode next = null; Enumeration e = tnode.children(); if (e != null) { while (e.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.nextElement(); TreeData data = (TreeData) child.getUserObject(); if (data.toString().equals(comp)) { tpath = new TreePath(child.getPath()); next = child; break; } } } if (next == null) break; tnode = next; } if (tpath != null) { pTree.setSelectionPath(tpath); pTree.makeVisible(tpath); } } }
private void laden(Path saveName) throws IOException { Properties prop = new Properties(); FileInputStream in = new FileInputStream(saveName.toString()); prop.load(in); for (int i = 0; prop.containsKey(String.format("quellMenu%d", i)); i++) quellListModel.addElement( new ListItem( Paths.get(prop.getProperty(String.format("quellMenu%d", i))), Paths.get(prop.getProperty(String.format("quellMenu%d", i))))); for (int i = 0; prop.containsKey(String.format("zielMenu%d", i)); i++) zielListModel.addElement( new ListItem( Paths.get(prop.getProperty(String.format("zielMenu%d", i))), Paths.get(prop.getProperty(String.format("zielMenu%d", i))))); in.close(); }
private void speichern(Path saveName) { Properties prop = new Properties(); if (!quellListModel.isEmpty()) for (int i = 0; i < quellListModel.getSize(); i++) prop.setProperty( String.format("quellMenu%d", i), quellListModel.getElementAt(i).getValueMember().toString()); if (!zielListModel.isEmpty()) for (int i = 0; i < zielListModel.getSize(); i++) prop.setProperty( String.format("zielMenu%d", i), zielListModel.getElementAt(i).getValueMember().toString()); try { FileOutputStream out = new FileOutputStream(saveName.toString()); prop.store(out, null); out.close(); } catch (Exception e) { e.printStackTrace(); } }
public void cnpStart(Path quellOrdner, Path zielOrdner) { try { DirectoryStream<Path> qstream = Files.newDirectoryStream(quellOrdner); for (Path qfile : qstream) { Path target = Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()); if (abbruch) break; if (Files.isDirectory(qfile) && !Files.exists(target)) { Files.createDirectory(target); textArea.append("Verzeichnis: " + qfile + " wurde erstellt" + System.lineSeparator()); cnpStart( Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()), Paths.get(zielOrdner.toString() + "/" + qfile.getFileName())); } else if (Files.isDirectory(qfile) && Files.exists(target)) { textArea.append("Wechsle in Verzeichnis: " + qfile + System.lineSeparator()); cnpStart( Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()), Paths.get(zielOrdner.toString() + "/" + qfile.getFileName())); } // Wenn die Datei noch nicht existiert else if (!Files.exists(target)) { textArea.append( "Datei " + target.toString() + " wurde erstellt" + System.lineSeparator()); Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING); } // Wenn Datei im Zielverzeichnis schon existiert else if (Files.exists(target)) { if (cAUeSchr) { textArea.append( "Datei " + target.toString() + " wird absolut überschrieben" + System.lineSeparator()); Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING); } else if (cUeSchr) { if (checkAlter( Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()), Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()))) { textArea.append( target.toString() + " wird mit neuer Datei überschrieben" + System.lineSeparator()); Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING); } else { textArea.append( target.toString() + " alte Datei bleibt bestehen" + System.lineSeparator()); } } else textArea.append( target.toString() + " alte Datei bleibt bestehen" + System.lineSeparator()); } pbCounter++; progressBar.setValue(pbCounter); } qstream.close(); } catch (IOException e) { e.printStackTrace(); } }
private void addZListBoxEintrag(Path zielOrdner) { if (zielOrdner == null) return; zielListModel.addElement(new ListItem(zielOrdner, zielOrdner.toString())); zielJList.setSelectedIndex(zielListModel.getSize() - 1); }