Example usage for java.nio.file Path subpath

List of usage examples for java.nio.file Path subpath

Introduction

In this page you can find the example usage for java.nio.file Path subpath.

Prototype

Path subpath(int beginIndex, int endIndex);

Source Link

Document

Returns a relative Path that is a subsequence of the name elements of this path.

Usage

From source file:org.nmrfx.processor.gui.MainApp.java

MenuBar makeMenuBar(String appName) {
    MenuToolkit tk = null;//from   w  w  w  .  j a  v a  2s  . c o  m
    if (isMac()) {
        tk = MenuToolkit.toolkit();
    }
    MenuBar menuBar = new MenuBar();

    // Application Menu
    // TBD: services menu
    Menu appMenu = new Menu(appName); // Name for appMenu can't be set at
    // Runtime
    MenuItem aboutItem = null;
    Stage aboutStage = makeAbout(appName);
    if (tk != null) {
        aboutItem = tk.createAboutMenuItem(appName, aboutStage);
    } else {
        aboutItem = new MenuItem("About...");
        aboutItem.setOnAction(e -> aboutStage.show());
    }
    MenuItem prefsItem = new MenuItem("Preferences...");
    MenuItem quitItem;
    prefsItem.setOnAction(e -> showPreferences(e));
    if (tk != null) {
        quitItem = tk.createQuitMenuItem(appName);
        appMenu.getItems().addAll(aboutItem, new SeparatorMenuItem(), prefsItem, new SeparatorMenuItem(),
                tk.createHideMenuItem(appName), tk.createHideOthersMenuItem(), tk.createUnhideAllMenuItem(),
                new SeparatorMenuItem(), quitItem);
        // createQuitMeneItem doesn't result in stop or quit being called
        //  therefore we can't check for waiting till a commit is done before leaving
        // so explicitly set action to quit
        quitItem.setOnAction(e -> quit());
    } else {
        quitItem = new MenuItem("Quit");
        quitItem.setOnAction(e -> quit());
    }
    // File Menu (items TBD)
    Menu fileMenu = new Menu("File");
    MenuItem openMenuItem = new MenuItem("Open and Draw...");
    openMenuItem.setOnAction(e -> FXMLController.getActiveController().openAction(e));
    MenuItem addMenuItem = new MenuItem("Open...");
    addMenuItem.setOnAction(e -> FXMLController.getActiveController().addNoDrawAction(e));
    MenuItem newMenuItem = new MenuItem("New Window...");
    newMenuItem.setOnAction(e -> newGraphics(e));
    Menu recentMenuItem = new Menu("Open and Draw Recent");

    List<Path> recentDatasets = PreferencesController.getRecentDatasets();
    for (Path path : recentDatasets) {
        int count = path.getNameCount();
        int first = count - 3;
        first = first >= 0 ? first : 0;
        Path subPath = path.subpath(first, count);

        MenuItem datasetMenuItem = new MenuItem(subPath.toString());
        datasetMenuItem
                .setOnAction(e -> FXMLController.getActiveController().openFile(path.toString(), false, false));
        recentMenuItem.getItems().add(datasetMenuItem);
    }
    MenuItem pdfMenuItem = new MenuItem("Export PDF...");
    pdfMenuItem.setOnAction(e -> FXMLController.getActiveController().exportPDFAction(e));
    MenuItem svgMenuItem = new MenuItem("Export SVG...");
    svgMenuItem.setOnAction(e -> FXMLController.getActiveController().exportSVGAction(e));
    MenuItem loadPeakListMenuItem = new MenuItem("Load PeakLists");
    loadPeakListMenuItem.setOnAction(e -> loadPeakLists());

    Menu projectMenu = new Menu("Projects");

    MenuItem projectOpenMenuItem = new MenuItem("Open...");
    projectOpenMenuItem.setOnAction(e -> loadProject());

    MenuItem projectSaveAsMenuItem = new MenuItem("Save As...");
    projectSaveAsMenuItem.setOnAction(e -> saveProjectAs());

    MenuItem projectSaveMenuItem = new MenuItem("Save");
    projectSaveMenuItem.setOnAction(e -> saveProject());
    Menu recentProjectMenuItem = new Menu("Open Recent");

    List<Path> recentProjects = PreferencesController.getRecentProjects();
    for (Path path : recentProjects) {
        int count = path.getNameCount();
        int first = count - 3;
        first = first >= 0 ? first : 0;
        Path subPath = path.subpath(first, count);

        MenuItem projectMenuItem = new MenuItem(subPath.toString());
        projectMenuItem.setOnAction(e -> loadProject(path));
        recentProjectMenuItem.getItems().add(projectMenuItem);
    }

    projectMenu.getItems().addAll(projectOpenMenuItem, recentProjectMenuItem, projectSaveMenuItem,
            projectSaveAsMenuItem);

    fileMenu.getItems().addAll(openMenuItem, addMenuItem, newMenuItem, recentMenuItem, new SeparatorMenuItem(),
            pdfMenuItem, svgMenuItem, loadPeakListMenuItem);

    Menu spectraMenu = new Menu("Spectra");
    MenuItem deleteItem = new MenuItem("Delete Spectrum");
    deleteItem.setOnAction(e -> FXMLController.getActiveController().removeChart());
    MenuItem syncMenuItem = new MenuItem("Sync Axes");
    syncMenuItem.setOnAction(e -> PolyChart.activeChart.syncSceneMates());

    Menu arrangeMenu = new Menu("Arrange");
    MenuItem horizItem = new MenuItem("Horizontal");
    horizItem.setOnAction(
            e -> FXMLController.getActiveController().arrange(FractionPane.ORIENTATION.HORIZONTAL));
    MenuItem vertItem = new MenuItem("Vertical");
    vertItem.setOnAction(e -> FXMLController.getActiveController().arrange(FractionPane.ORIENTATION.VERTICAL));
    MenuItem gridItem = new MenuItem("Grid");
    gridItem.setOnAction(e -> FXMLController.getActiveController().arrange(FractionPane.ORIENTATION.GRID));
    MenuItem overlayItem = new MenuItem("Overlay");
    overlayItem.setOnAction(e -> FXMLController.getActiveController().overlay());
    MenuItem minimizeItem = new MenuItem("Minimize Borders");
    minimizeItem.setOnAction(e -> FXMLController.getActiveController().setBorderState(true));
    MenuItem normalizeItem = new MenuItem("Normal Borders");
    normalizeItem.setOnAction(e -> FXMLController.getActiveController().setBorderState(false));

    arrangeMenu.getItems().addAll(horizItem, vertItem, gridItem, overlayItem, minimizeItem, normalizeItem);
    MenuItem alignMenuItem = new MenuItem("Align Spectra");
    alignMenuItem.setOnAction(e -> FXMLController.getActiveController().alignCenters());
    MenuItem analyzeMenuItem = new MenuItem("Analyzer...");
    analyzeMenuItem.setOnAction(e -> showAnalyzer(e));

    spectraMenu.getItems().addAll(deleteItem, arrangeMenu, syncMenuItem, alignMenuItem, analyzeMenuItem);

    // Format (items TBD)
    //        Menu formatMenu = new Menu("Format");
    //        formatMenu.getItems().addAll(new MenuItem("TBD"));
    // View Menu (items TBD)
    Menu viewMenu = new Menu("View");
    MenuItem dataMenuItem = new MenuItem("Show Datasets");
    dataMenuItem.setOnAction(e -> showDatasetsTable(e));

    MenuItem consoleMenuItem = new MenuItem("Show Console");
    consoleMenuItem.setOnAction(e -> showConsole(e));

    MenuItem attrMenuItem = new MenuItem("Show Attributes");
    attrMenuItem.setOnAction(e -> FXMLController.getActiveController().showSpecAttrAction(e));

    MenuItem procMenuItem = new MenuItem("Show Processor");
    procMenuItem.setOnAction(e -> FXMLController.getActiveController().showProcessorAction(e));

    MenuItem scannerMenuItem = new MenuItem("Show Scanner");
    scannerMenuItem.setOnAction(e -> FXMLController.getActiveController().showScannerAction(e));

    viewMenu.getItems().addAll(consoleMenuItem, dataMenuItem, attrMenuItem, procMenuItem, scannerMenuItem);

    Menu peakMenu = new Menu("Peaks");

    MenuItem peakAttrMenuItem = new MenuItem("Show Peak Tool");
    peakAttrMenuItem.setOnAction(e -> FXMLController.getActiveController().showPeakAttrAction(e));

    MenuItem peakNavigatorMenuItem = new MenuItem("Show Peak Navigator");
    peakNavigatorMenuItem.setOnAction(e -> FXMLController.getActiveController().showPeakNavigator());

    MenuItem linkPeakDimsMenuItem = new MenuItem("Link by Labels");
    linkPeakDimsMenuItem.setOnAction(e -> FXMLController.getActiveController().linkPeakDims());

    MenuItem peakSliderMenuItem = new MenuItem("Show Peak Slider");
    peakSliderMenuItem.setOnAction(e -> FXMLController.getActiveController().showPeakSlider());

    peakMenu.getItems().addAll(peakAttrMenuItem, peakNavigatorMenuItem, linkPeakDimsMenuItem,
            peakSliderMenuItem);

    // Window Menu
    // TBD standard window menu items
    // Help Menu (items TBD)
    Menu helpMenu = new Menu("Help");

    MenuItem webSiteMenuItem = new MenuItem("NMRFx Web Site");
    webSiteMenuItem.setOnAction(e -> showWebSiteAction(e));

    MenuItem docsMenuItem = new MenuItem("Online Documentation");
    docsMenuItem.setOnAction(e -> showDocAction(e));

    MenuItem versionMenuItem = new MenuItem("Check Version");
    versionMenuItem.setOnAction(e -> showVersionAction(e));

    MenuItem mailingListItem = new MenuItem("Mailing List Site");
    mailingListItem.setOnAction(e -> showMailingListAction(e));

    MenuItem refMenuItem = new MenuItem("NMRFx Publication");
    refMenuItem.setOnAction(e -> {
        MainApp.hostServices.showDocument("http://link.springer.com/article/10.1007/s10858-016-0049-6");
    });

    // home
    // mailing list
    //
    helpMenu.getItems().addAll(docsMenuItem, webSiteMenuItem, mailingListItem, versionMenuItem, refMenuItem);

    if (tk != null) {
        Menu windowMenu = new Menu("Window");
        windowMenu.getItems().addAll(tk.createMinimizeMenuItem(), tk.createZoomMenuItem(),
                tk.createCycleWindowsItem(), new SeparatorMenuItem(), tk.createBringAllToFrontItem());
        menuBar.getMenus().addAll(appMenu, fileMenu, projectMenu, spectraMenu, viewMenu, peakMenu, windowMenu,
                helpMenu);
        tk.autoAddWindowMenuItems(windowMenu);
        tk.setGlobalMenuBar(menuBar);
    } else {
        fileMenu.getItems().add(prefsItem);
        fileMenu.getItems().add(quitItem);
        menuBar.getMenus().addAll(fileMenu, projectMenu, spectraMenu, viewMenu, peakMenu, helpMenu);
        helpMenu.getItems().add(0, aboutItem);
    }
    return menuBar;
}

From source file:org.openhab.tools.analysis.checkstyle.ServiceComponentManifestCheck.java

@Override
protected void processFiltered(File file, FileText fileText) throws CheckstyleException {

    Path absolutePath = file.toPath();
    int osgiInfIndex = getIndex(absolutePath, OSGI_INF_DIRECTORY_NAME);
    String fileExtension = FilenameUtils.getExtension(file.getName());

    // The components are .xml files located in OSGI-INF folder
    if (fileExtension.equals(XML_EXTENSION) && osgiInfIndex > -1) {
        // All the defined components are collected to be processed later
        componentXmlFiles.add(file.getName());

        // Get the relative path
        Path relativePath = absolutePath.subpath(osgiInfIndex, absolutePath.getNameCount());
        componentXmlRelativePaths.add(relativePath);
    }/*w  w w .  ja v a2s .c o  m*/

    if (file.getName().equals(MANIFEST_FILE_NAME)) {
        verifyManifest(fileText);
    }

    if (file.getName().equals(BUILD_PROPERTIES_FILE_NAME)) {
        processBuildPropertiesFile(fileText);
    }
}

From source file:org.sleuthkit.autopsy.casemodule.SingleUserCaseConverter.java

/**
 * Fix up any paths in the database that refer to items that have moved.
 * Candidates include events.db, input images, reports, file paths, etc.
 *
 * @param icd the Import Case Data for the current case
 *
 * @throws Exception/*from   www .  ja  va 2  s  .  c  o  m*/
 * @throws SQLExceptionException
 */
private static void fixPaths(ImportCaseData icd) throws SQLException, Exception {
    /// Fix paths in reports, tsk_files_path, and tsk_image_names tables

    String input = icd.getImageInputFolder().toString();
    String output = icd.getImageOutputFolder().toString();

    Connection postgresqlConnection = getPostgreSQLConnection(icd);

    if (postgresqlConnection != null) {
        String hostName = NetworkUtils.getLocalHostName();

        // add hostname to reports
        Statement updateStatement = postgresqlConnection.createStatement();
        updateStatement.executeUpdate("UPDATE reports SET path=CONCAT('" + hostName
                + "/', path) WHERE path IS NOT NULL AND path != ''"); //NON-NLS

        // add hostname to tsk_files_path
        updateStatement = postgresqlConnection.createStatement();
        updateStatement.executeUpdate("UPDATE tsk_files_path SET path=CONCAT('" + hostName
                + "\\', path) WHERE path IS NOT NULL AND path != ''"); //NON-NLS

        String caseName = icd.getRawFolderName().toLowerCase();

        if (icd.getCopySourceImages()) {
            // update path for images
            Statement inputStatement = postgresqlConnection.createStatement();
            ResultSet inputResultSet = inputStatement.executeQuery("SELECT * FROM tsk_image_names"); //NON-NLS

            while (inputResultSet.next()) {
                Path oldPath = Paths.get(inputResultSet.getString(2));

                for (int x = 0; x < oldPath.getNameCount(); ++x) {
                    if (oldPath.getName(x).toString().toLowerCase().equals(caseName)) {
                        Path newPath = Paths.get(output,
                                oldPath.subpath(x + 1, oldPath.getNameCount()).toString());
                        updateStatement = postgresqlConnection.createStatement();
                        updateStatement.executeUpdate("UPDATE tsk_image_names SET name='" + newPath.toString()
                                + "' WHERE obj_id = " + inputResultSet.getInt(1)); //NON-NLS
                        break;
                    }
                }
            }
        }
        postgresqlConnection.close();
    } else {
        throw new Exception(NbBundle.getMessage(SingleUserCaseConverter.class,
                "SingleUserCaseConverter.CanNotOpenDatabase")); //NON-NLS
    }
}

From source file:org.xwiki.filter.xff.internal.input.PagesReader.java

@Override
public void route(Path path, InputStream inputStream) throws FilterException {
    String fileName = path.toString();
    if (fileName.equals(org.xwiki.xff.core.model.Page.PAGE_FILENAME)) {
        this.parsePage(inputStream);
        this.start();
        return;/*from  w  ww .j av a 2 s .  co m*/
    } else {
        this.start();
    }
    String hint = path.subpath(0, 1).toString();
    if (hint.equals(org.xwiki.xff.core.model.Property.PROPERTY_HINT)) {
        this.routeProperty(path, inputStream);
        return;
    }
    String childId = null;
    Path childPath = null;
    switch (hint) {
    case "attachments":
        childId = path.subpath(1, 2).toString();
        childPath = path.subpath(1, path.getNameCount());
        break;
    case "classes":
        childId = this.reference.toString();
        childPath = path.subpath(1, path.getNameCount());
        break;
    case "objects":
        childId = path.subpath(1, 3).toString();
        childPath = path.subpath(3, path.getNameCount());
        break;
    default:
        String message = String.format("PagesReader don't know how to route '%s'.", path.toString());
        throw new FilterException(message);
    }

    // Get a new reader only if the child change
    if (!childId.equals(this.lastReaderId)) {
        if (this.reader != null) {
            this.reader.close();
        }
        this.reader = this.getReader(hint);
        this.reader.open(childId, this.reference, this.filter, this.proxyFilter);
    }
    this.reader.route(childPath, inputStream);
    this.lastReaderId = childId;
}