Example usage for org.apache.commons.lang.text StrSubstitutor replace

List of usage examples for org.apache.commons.lang.text StrSubstitutor replace

Introduction

In this page you can find the example usage for org.apache.commons.lang.text StrSubstitutor replace.

Prototype

public String replace(Object source) 

Source Link

Document

Replaces all the occurrences of variables in the given source object with their matching values from the resolver.

Usage

From source file:org.apache.maven.surefire.its.fixture.SurefireLauncher.java

public OutputValidator executeCurrentGoals() {

    String userLocalRepo = System.getProperty("user.localRepository");
    String testBuildDirectory = System.getProperty("testBuildDirectory");
    boolean useInterpolatedSettings = Boolean.getBoolean("useInterpolatedSettings");

    try {/*w  w w. j av a  2  s  .  c o m*/
        if (useInterpolatedSettings) {
            File interpolatedSettings = new File(testBuildDirectory, "interpolated-settings");

            if (!interpolatedSettings.exists()) {
                // hack "a la" invoker plugin to download dependencies from local repo
                // and not download from central

                Map<String, String> values = new HashMap<String, String>(1);
                values.put("localRepositoryUrl", toUrl(userLocalRepo));
                StrSubstitutor strSubstitutor = new StrSubstitutor(values);

                String fileContent = FileUtils.fileRead(new File(testBuildDirectory, "settings.xml"));

                String filtered = strSubstitutor.replace(fileContent);

                FileUtils.fileWrite(interpolatedSettings.getAbsolutePath(), filtered);

            }

            cliOptions.add("-s " + interpolatedSettings.getCanonicalPath());
        }
        verifier.setCliOptions(cliOptions);

        verifier.executeGoals(goals, envvars);
        return surefireVerifier;
    } catch (IOException e) {
        throw new SurefireVerifierException(e.getMessage(), e);
    } catch (VerificationException e) {
        throw new SurefireVerifierException(e.getMessage(), e);
    } finally {
        verifier.resetStreams();
    }
}

From source file:org.apache.usergrid.management.EmailFlowIT.java

private void testProperty(String propertyName, boolean containsSubstitution) {
    String propertyValue = setup.get(propertyName);
    assertTrue(propertyName + " was not found", isNotBlank(propertyValue));
    LOG.info(propertyName + "=" + propertyValue);

    if (containsSubstitution) {
        Map<String, String> valuesMap = new HashMap<String, String>();
        valuesMap.put("reset_url", "test-url");
        valuesMap.put("organization_name", "test-org");
        valuesMap.put("activation_url", "test-url");
        valuesMap.put("confirmation_url", "test-url");
        valuesMap.put("user_email", "test-email");
        valuesMap.put("pin", "test-pin");
        StrSubstitutor sub = new StrSubstitutor(valuesMap);
        String resolvedString = sub.replace(propertyValue);
        assertNotSame(propertyValue, resolvedString);
    }/*w w  w. j  a  v a  2  s. c om*/
}

From source file:org.apache.usergrid.rest.SwaggerServlet.java

public String loadTempate(String template) {
    String templateString = readClasspathFileAsString(template);
    Map<String, String> valuesMap = new HashMap<String, String>();
    String basePath = properties != null ? properties.getProperty("swagger.basepath", SWAGGER_BASE_PATH)
            : SWAGGER_BASE_PATH;/*from   w w  w .ja va2s . co m*/
    valuesMap.put("basePath", basePath);
    StrSubstitutor sub = new StrSubstitutor(valuesMap);
    return sub.replace(templateString);
}

From source file:org.codice.ddf.itests.common.AbstractIntegrationTest.java

/**
 * Variables to be replaced in a resource file should be in the format: $variableName$ The
 * variable to replace in the file should also also match the parameter names of the method
 * calling getFileContent./*from   w  w  w.  j  a va 2  s. c o  m*/
 *
 * @param filePath
 * @param params
 * @param classRelativeToResource
 * @return
 */
@SuppressWarnings({ "squid:S00112" /* A generic RuntimeException is perfectly reasonable in this case. */
})
public static String getFileContent(String filePath, ImmutableMap<String, String> params,
        Class classRelativeToResource) {

    StrSubstitutor strSubstitutor = new StrSubstitutor(params);

    strSubstitutor.setVariablePrefix(RESOURCE_VARIABLE_DELIMETER);
    strSubstitutor.setVariableSuffix(RESOURCE_VARIABLE_DELIMETER);
    String fileContent;

    try {
        fileContent = IOUtils.toString(classRelativeToResource.getClassLoader().getResourceAsStream(filePath),
                "UTF-8");
    } catch (IOException e) {
        throw new RuntimeException("Failed to read filepath: " + filePath);
    }

    return strSubstitutor.replace(fileContent);
}

From source file:org.craftercms.cstudio.publishing.processor.ShellProcessor.java

@Override
public void doProcess(PublishedChangeSet changeSet, Map<String, String> parameters, PublishingTarget target)
        throws PublishingException {
    checkConfiguration(parameters, target);
    LOGGER.debug("Starting Shell Processor");
    ProcessBuilder builder = new ProcessBuilder();
    builder.directory(getWorkingDir(workingDir, parameters.get(FileUploadServlet.PARAM_SITE)));
    LOGGER.debug("Working directory is " + workingDir);
    HashMap<String, String> argumentsMap = buildArgumentsMap(getFileList(parameters, changeSet));
    if (asSingleCommand) {
        StrSubstitutor substitutor = new StrSubstitutor(argumentsMap, "%{", "}");
        String execComand = substitutor.replace(command);
        LOGGER.debug("Command to be Executed is " + execComand);
        builder.command("/bin/bash", "-c", execComand);

    } else {//  w  w w  . ja  v a  2 s .co m
        Set<String> keys = argumentsMap.keySet();
        ArrayList<String> commandAsList = new ArrayList<String>();
        commandAsList.add(command.trim());
        for (String key : keys) {
            if (!key.equalsIgnoreCase(INCLUDE_FILTER_PARAM)) {
                commandAsList.add(argumentsMap.get(key));
            }
        }
        LOGGER.debug("Command to be Executed is " + StringUtils.join(commandAsList, " "));
        builder.command(commandAsList);
    }

    builder.environment().putAll(enviroment);
    builder.redirectErrorStream(true);
    try {
        Process process = builder.start();
        process.waitFor();
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String str;
        while ((str = reader.readLine()) != null) {
            LOGGER.info("PROCESS OUTPUT :" + str);
        }
        reader.close();
        LOGGER.info("Process Finish with Exit Code " + process.exitValue());
        LOGGER.debug("Process Output ");
    } catch (IOException ex) {
        LOGGER.error("Error ", ex);
    } catch (InterruptedException e) {
        LOGGER.error("Error ", e);
    } finally {
        LOGGER.debug("End of Shell Processor");
    }
}

From source file:org.craftercms.deployer.git.processor.ShellProcessor.java

@Override
public void doProcess(SiteConfiguration siteConfiguration, PublishedChangeSet changeSet)
        throws PublishingException {
    checkConfiguration(siteConfiguration);
    LOGGER.debug("Starting Shell Processor");
    ProcessBuilder builder = new ProcessBuilder();
    builder.directory(getWorkingDir(workingDir, siteConfiguration.getSiteId()));
    LOGGER.debug("Working directory is " + workingDir);
    HashMap<String, String> argumentsMap = buildArgumentsMap(getFileList(changeSet));
    if (asSingleCommand) {
        StrSubstitutor substitutor = new StrSubstitutor(argumentsMap, "%{", "}");
        String execComand = substitutor.replace(command);
        LOGGER.debug("Command to be Executed is " + execComand);
        builder.command("/bin/bash", "-c", execComand);

    } else {/*from  w w w. jav  a2  s  . c  om*/
        Set<String> keys = argumentsMap.keySet();
        ArrayList<String> commandAsList = new ArrayList<String>();
        commandAsList.add(command.trim());
        for (String key : keys) {
            if (!key.equalsIgnoreCase(INCLUDE_FILTER_PARAM)) {
                commandAsList.add(argumentsMap.get(key));
            }
        }
        LOGGER.debug("Command to be Executed is " + StringUtils.join(commandAsList, " "));
        builder.command(commandAsList);
    }

    builder.environment().putAll(enviroment);
    builder.redirectErrorStream(true);
    try {
        Process process = builder.start();
        process.waitFor();
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String str;
        while ((str = reader.readLine()) != null) {
            LOGGER.info("PROCESS OUTPUT :" + str);
        }
        reader.close();
        LOGGER.info("Process Finish with Exit Code " + process.exitValue());
        LOGGER.debug("Process Output ");
    } catch (IOException ex) {
        LOGGER.error("Error ", ex);
    } catch (InterruptedException e) {
        LOGGER.error("Error ", e);
    } finally {
        LOGGER.debug("End of Shell Processor");
    }
}

From source file:org.datavyu.controllers.component.MixerController.java

private void initView() {

    // Set default scale values
    minStart = 0;//www . ja  va2  s  . c  o m

    listenerList = new EventListenerList();

    // Set up the root panel
    tracksPanel = new JPanel();
    tracksPanel.setLayout(new MigLayout("ins 0", "[left|left|left|left]rel push[right|right]", ""));
    tracksPanel.setBackground(Color.WHITE);

    if (Platform.isMac()) {
        osxGestureListener.register(tracksPanel);
    }

    // Menu buttons
    lockToggle = new JToggleButton("Lock all");
    lockToggle.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            lockToggleHandler(e);
        }
    });
    lockToggle.setName("lockToggleButton");

    bookmarkButton = new JButton("Add Bookmark");
    bookmarkButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            addBookmarkHandler();
        }
    });
    bookmarkButton.setEnabled(false);
    bookmarkButton.setName("bookmarkButton");

    JButton snapRegion = new JButton("Snap Region");
    snapRegion.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            snapRegionHandler(e);
        }
    });
    snapRegion.setName("snapRegionButton");

    JButton clearRegion = new JButton("Clear Region");
    clearRegion.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            clearRegionHandler(e);
        }
    });
    clearRegion.setName("clearRegionButton");

    zoomSlide = new JSlider(JSlider.HORIZONTAL, 1, 1000, 1);
    zoomSlide.addChangeListener(new ChangeListener() {
        public void stateChanged(final ChangeEvent e) {

            if (!isUpdatingZoomSlide && zoomSlide.getValueIsAdjusting()) {

                try {
                    isUpdatingZoomSlide = true;
                    zoomSetting = (double) (zoomSlide.getValue() - zoomSlide.getMinimum())
                            / (zoomSlide.getMaximum() - zoomSlide.getMinimum() + 1);
                    viewportModel.setViewportZoom(zoomSetting,
                            needleController.getNeedleModel().getCurrentTime());
                } finally {
                    isUpdatingZoomSlide = false;
                }
            }
        }
    });
    zoomSlide.setName("zoomSlider");
    zoomSlide.setBackground(tracksPanel.getBackground());

    JButton zoomRegionButton = new JButton("", zoomIcon);
    zoomRegionButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            zoomToRegion(e);
        }
    });
    zoomRegionButton.setName("zoomRegionButton");

    tracksPanel.add(lockToggle);
    tracksPanel.add(bookmarkButton);
    tracksPanel.add(snapRegion);
    tracksPanel.add(clearRegion);
    tracksPanel.add(zoomRegionButton);
    tracksPanel.add(zoomSlide, "wrap");

    timescaleController = new TimescaleController(mixerModel);
    timescaleController.addTimescaleEventListener(this);
    needleController = new NeedleController(this, mixerModel);
    regionController = new RegionController(mixerModel);
    tracksEditorController = new TracksEditorController(this, mixerModel);

    needleController.setTimescaleTransitionHeight(
            timescaleController.getTimescaleModel().getZoomWindowToTrackTransitionHeight());
    needleController
            .setZoomIndicatorHeight(timescaleController.getTimescaleModel().getZoomWindowIndicatorHeight());

    // Set up the layered pane
    layeredPane = new JLayeredPane();
    layeredPane.setLayout(new MigLayout("fillx, ins 0"));

    final int layeredPaneHeight = 272;
    final int timescaleViewHeight = timescaleController.getTimescaleModel().getHeight();

    final int needleHeadHeight = (int) Math.ceil(NeedleConstants.NEEDLE_HEAD_HEIGHT);
    final int tracksScrollPaneY = needleHeadHeight + 1;
    final int timescaleViewY = layeredPaneHeight - MixerConstants.HSCROLL_HEIGHT - timescaleViewHeight;
    final int tracksScrollPaneHeight = timescaleViewY - tracksScrollPaneY;
    final int tracksScrollBarY = timescaleViewY + timescaleViewHeight;
    final int needleAndRegionMarkerHeight = (timescaleViewY + timescaleViewHeight
            - timescaleController.getTimescaleModel().getZoomWindowIndicatorHeight()
            - timescaleController.getTimescaleModel().getZoomWindowToTrackTransitionHeight() + 1);

    // Set up filler component responsible for horizontal resizing of the
    // layout.
    {

        // Null args; let layout manager handle sizes.
        Box.Filler filler = new Filler(null, null, null);
        filler.setName("Filler");
        filler.addComponentListener(new SizeHandler());

        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("wmin", Integer.toString(MixerConstants.MIXER_MIN_WIDTH));

        // TODO Could probably use this same component to handle vertical
        // resizing...
        String template = "id filler, h 0!, grow 100 0, wmin ${wmin}, cell 0 0 ";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        layeredPane.setLayer(filler, MixerConstants.FILLER_ZORDER);
        layeredPane.add(filler, sub.replace(template), MixerConstants.FILLER_ZORDER);
    }

    // Set up the timescale layout
    {
        JComponent timescaleView = timescaleController.getView();

        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("x", Integer.toString(TimescaleConstants.XPOS_ABS));
        constraints.put("y", Integer.toString(timescaleViewY));

        // Calculate padding from the right
        int rightPad = (int) (RegionConstants.RMARKER_WIDTH + MixerConstants.VSCROLL_WIDTH
                + MixerConstants.R_EDGE_PAD);
        constraints.put("x2", "(filler.w-" + rightPad + ")");
        constraints.put("y2", "(tscale.y+${height})");
        constraints.put("height", Integer.toString(timescaleViewHeight));

        String template = "id tscale, pos ${x} ${y} ${x2} ${y2}";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        // Must call setLayer first.
        layeredPane.setLayer(timescaleView, MixerConstants.TIMESCALE_ZORDER);
        layeredPane.add(timescaleView, sub.replace(template), MixerConstants.TIMESCALE_ZORDER);
    }

    // Set up the scroll pane's layout.
    {
        tracksScrollPane = new JScrollPane(tracksEditorController.getView());
        tracksScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        tracksScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        tracksScrollPane.setBorder(BorderFactory.createEmptyBorder());
        tracksScrollPane.setName("jScrollPane");

        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("x", "0");
        constraints.put("y", Integer.toString(tracksScrollPaneY));
        constraints.put("x2", "(filler.w-" + MixerConstants.R_EDGE_PAD + ")");
        constraints.put("height", Integer.toString(tracksScrollPaneHeight));

        String template = "pos ${x} ${y} ${x2} n, h ${height}!";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        layeredPane.setLayer(tracksScrollPane, MixerConstants.TRACKS_ZORDER);
        layeredPane.add(tracksScrollPane, sub.replace(template), MixerConstants.TRACKS_ZORDER);
    }

    // Create the region markers and set up the layout.
    {
        JComponent regionView = regionController.getView();

        Map<String, String> constraints = Maps.newHashMap();

        int x = (int) (TrackConstants.HEADER_WIDTH - RegionConstants.RMARKER_WIDTH);
        constraints.put("x", Integer.toString(x));
        constraints.put("y", "0");

        // Padding from the right
        int rightPad = MixerConstants.R_EDGE_PAD + MixerConstants.VSCROLL_WIDTH - 2;

        constraints.put("x2", "(filler.w-" + rightPad + ")");
        constraints.put("height", Integer.toString(needleAndRegionMarkerHeight));

        String template = "pos ${x} ${y} ${x2} n, h ${height}::";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        layeredPane.setLayer(regionView, MixerConstants.REGION_ZORDER);
        layeredPane.add(regionView, sub.replace(template), MixerConstants.REGION_ZORDER);
    }

    // Set up the timing needle's layout
    {
        JComponent needleView = needleController.getView();

        Map<String, String> constraints = Maps.newHashMap();

        int x = (int) (TrackConstants.HEADER_WIDTH - NeedleConstants.NEEDLE_HEAD_WIDTH
                + NeedleConstants.NEEDLE_WIDTH);
        constraints.put("x", Integer.toString(x));
        constraints.put("y", "0");

        // Padding from the right
        int rightPad = MixerConstants.R_EDGE_PAD + MixerConstants.VSCROLL_WIDTH - 1;

        constraints.put("x2", "(filler.w-" + rightPad + ")");
        constraints.put("height",
                Integer.toString(needleAndRegionMarkerHeight
                        + timescaleController.getTimescaleModel().getZoomWindowToTrackTransitionHeight()
                        + timescaleController.getTimescaleModel().getZoomWindowIndicatorHeight() - 1));

        String template = "pos ${x} ${y} ${x2} n, h ${height}::";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        layeredPane.setLayer(needleView, MixerConstants.NEEDLE_ZORDER);
        layeredPane.add(needleView, sub.replace(template), MixerConstants.NEEDLE_ZORDER);
    }

    // Set up the snap marker's layout
    {
        JComponent markerView = tracksEditorController.getMarkerView();

        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("x", Integer.toString(TimescaleConstants.XPOS_ABS));
        constraints.put("y", Integer.toString(needleHeadHeight + 1));

        // Padding from the right
        int rightPad = MixerConstants.R_EDGE_PAD + MixerConstants.VSCROLL_WIDTH - 1;

        constraints.put("x2", "(filler.w-" + rightPad + ")");
        constraints.put("height", Integer.toString(needleAndRegionMarkerHeight - needleHeadHeight - 1));

        String template = "pos ${x} ${y} ${x2} n, h ${height}::";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        layeredPane.setLayer(markerView, MixerConstants.MARKER_ZORDER);
        layeredPane.add(markerView, sub.replace(template), MixerConstants.MARKER_ZORDER);
    }

    // Set up the tracks horizontal scroll bar
    {
        tracksScrollBar = new JScrollBar(Adjustable.HORIZONTAL);
        tracksScrollBar.setValues(0, TRACKS_SCROLL_BAR_RANGE, 0, TRACKS_SCROLL_BAR_RANGE);
        tracksScrollBar.setUnitIncrement(TRACKS_SCROLL_BAR_RANGE / 20);
        tracksScrollBar.setBlockIncrement(TRACKS_SCROLL_BAR_RANGE / 2);
        tracksScrollBar.addAdjustmentListener(this);
        tracksScrollBar.setValueIsAdjusting(false);
        tracksScrollBar.setVisible(false);
        tracksScrollBar.setName("horizontalScrollBar");

        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("x", Integer.toString(TimescaleConstants.XPOS_ABS));
        constraints.put("y", Integer.toString(tracksScrollBarY));

        int rightPad = (int) (RegionConstants.RMARKER_WIDTH + MixerConstants.VSCROLL_WIDTH
                + MixerConstants.R_EDGE_PAD);
        constraints.put("x2", "(filler.w-" + rightPad + ")");
        constraints.put("height", Integer.toString(MixerConstants.HSCROLL_HEIGHT));

        String template = "pos ${x} ${y} ${x2} n, h ${height}::";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        layeredPane.setLayer(tracksScrollBar, MixerConstants.TRACKS_SB_ZORDER);
        layeredPane.add(tracksScrollBar, sub.replace(template), MixerConstants.TRACKS_SB_ZORDER);
    }

    {
        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("span", "6");
        constraints.put("width", Integer.toString(MixerConstants.MIXER_MIN_WIDTH));
        constraints.put("height", Integer.toString(layeredPaneHeight));

        String template = "growx, span ${span}, w ${width}::, h ${height}::, wrap";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        tracksPanel.add(layeredPane, sub.replace(template));
    }

    tracksPanel.validate();
}

From source file:org.datavyu.controllers.component.TrackController.java

/**
 * Creates a new TrackController./*from   w ww.  j  av a2 s .  c om*/
 *
 * @param trackPainter the track painter for this controller to manage.
 */
public TrackController(final MixerModel mixerModel, final TrackPainter trackPainter) {
    isMoveable = true;

    view = new JPanel();
    view.setLayout(new MigLayout("fillx, ins 0", "[]0[]"));
    view.setBorder(BorderFactory.createLineBorder(TrackConstants.BORDER_COLOR, 1));

    this.trackPainter = trackPainter;

    this.mixerModel = mixerModel;
    trackModel = new TrackModel();
    trackModel.setState(TrackState.NORMAL);
    trackModel.clearBookmarks();
    trackModel.setLocked(false);

    trackPainter.setMixerView(mixerModel);
    trackPainter.setTrackModel(trackModel);

    mixerModel.getViewportModel().addPropertyChangeListener(this);

    listenerList = new EventListenerList();

    final TrackPainterListener painterListener = new TrackPainterListener();
    trackPainter.addMouseListener(painterListener);
    trackPainter.addMouseMotionListener(painterListener);

    menu = new JPopupMenu();
    menu.setName("trackPopUpMenu");

    setBookmarkMenuItem = new JMenuItem("Set bookmark");
    setBookmarkMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            TrackController.this.setBookmarkAction();
        }
    });

    clearBookmarkMenuItem = new JMenuItem("Clear bookmarks");
    clearBookmarkMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            TrackController.this.clearBookmarkAction();
        }
    });
    menu.add(setBookmarkMenuItem);
    menu.add(clearBookmarkMenuItem);

    trackPainter.add(menu);

    // Create the Header panel and its components
    trackLabel = new JLabel("", SwingConstants.CENTER);
    trackLabel.setName("trackLabel");
    trackLabel.setHorizontalAlignment(SwingConstants.CENTER);
    trackLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    iconLabel = new JLabel("", SwingConstants.CENTER);
    iconLabel.setHorizontalAlignment(SwingConstants.CENTER);
    iconLabel.setHorizontalTextPosition(SwingConstants.CENTER);

    header = new JPanel(new MigLayout("ins 0, wrap 6"));
    header.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createMatteBorder(0, 0, 0, 1, TrackConstants.BORDER_COLOR),
            BorderFactory.createEmptyBorder(2, 2, 2, 2)));
    header.setBackground(Color.LIGHT_GRAY);

    // Normally I would use pushx instead of defining the width, but in this
    // case I defined the width because span combined with push makes the
    // first action icon cell push out as well. 136 was calculated from
    // 140 pixels minus 2 minus 2 (from the empty border defined above).
    header.add(trackLabel, "span 6, w 136!, center, growx");
    header.add(iconLabel, "span 6, w 136!, h 32!, center, growx");

    // Set up the button used for locking/unlocking track movement
    {
        lockUnlockButton = new JButton(TrackConstants.UNLOCK_ICON);
        lockUnlockButton.setName("lockUnlockButton");
        lockUnlockButton.setContentAreaFilled(false);
        lockUnlockButton.setBorderPainted(false);
        lockUnlockButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                handleLockUnlockButtonEvent(e);
            }
        });

        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("width", Integer.toString(TrackConstants.ACTION_BUTTON_WIDTH));
        constraints.put("height", Integer.toString(TrackConstants.ACTION_BUTTON_HEIGHT));

        String template = "cell 0 2, w ${width}!, h ${height}!";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        header.add(lockUnlockButton, sub.replace(template));
    }

    // Set up the button used for hiding/showing a track's data viewer
    {
        visibleButton = new JButton(TrackConstants.VIEWER_HIDE_ICON);
        visibleButton.setName("visibleButton");
        visibleButton.setContentAreaFilled(false);
        visibleButton.setBorderPainted(false);
        visibleButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                handleVisibleButtonEvent(e);
            }
        });

        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("width", Integer.toString(TrackConstants.ACTION_BUTTON_WIDTH));
        constraints.put("height", Integer.toString(TrackConstants.ACTION_BUTTON_HEIGHT));

        String template = "cell 1 2, w ${width}!, h ${height}!";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        header.add(visibleButton, sub.replace(template));
    }

    // Set up the button used for removing a track and its plugin
    {
        rubbishButton = new JButton(TrackConstants.DELETE_ICON);
        rubbishButton.setName("rubbishButton");
        rubbishButton.setContentAreaFilled(false);
        rubbishButton.setBorderPainted(false);
        rubbishButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                handleDeleteButtonEvent(e);
            }
        });

        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("width", Integer.toString(TrackConstants.ACTION_BUTTON_WIDTH));
        constraints.put("height", Integer.toString(TrackConstants.ACTION_BUTTON_HEIGHT));

        String template = "cell 5 2, w ${width}!, h ${height}!";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        header.add(rubbishButton, sub.replace(template));
    }

    // Add the header to our layout.
    {
        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("width", Integer.toString(TrackConstants.HEADER_WIDTH));
        constraints.put("height", Integer.toString(TrackConstants.CARRIAGE_HEIGHT));

        String template = "w ${width}!, h ${height}!";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        view.add(header, sub.replace(template));
    }

    // Add the track carriage to our layout.
    {
        Map<String, String> constraints = Maps.newHashMap();
        constraints.put("height", Integer.toString(TrackConstants.CARRIAGE_HEIGHT));

        String template = "pushx, growx, h ${height}!";
        StrSubstitutor sub = new StrSubstitutor(constraints);

        view.add(trackPainter, sub.replace(template));
    }

    view.validate();
}

From source file:org.datavyu.controllers.component.TrackController.java

public void bindTrackActions(final CustomActions actions) {
    Runnable edtTask = new Runnable() {
        @Override/*from   w  w w . j  a  v a2s.  c o  m*/
        public void run() {

            Map<String, String> constraints = Maps.newHashMap();
            constraints.put("width", Integer.toString(TrackConstants.ACTION_BUTTON_WIDTH));
            constraints.put("height", Integer.toString(TrackConstants.ACTION_BUTTON_HEIGHT));

            String template = "w ${width}!, h ${height}!";
            StrSubstitutor sub = new StrSubstitutor(constraints);
            String cons = sub.replace(template);

            if (actions.getActionButton1() != null) {
                header.add(actions.getActionButton1(), cons + ", cell 2 2");
            }

            if (actions.getActionButton2() != null) {
                header.add(actions.getActionButton2(), cons + ", cell 3 2");
            }

            if (actions.getActionButton3() != null) {
                header.add(actions.getActionButton3(), cons + ", cell 4 2");
            }

            header.validate();
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        edtTask.run();
    } else {
        SwingUtilities.invokeLater(edtTask);
    }
}

From source file:org.eclipse.skalli.core.permit.PermitConfig.java

public Permit asPermit(Map<String, String> properties) {
    if (properties == null || properties.isEmpty()) {
        return new Permit(level, action, path);
    }//from ww  w  . jav  a  2  s.  c  o  m
    StrSubstitutor subst = new StrSubstitutor(properties);
    return new Permit(level, action, subst.replace(path));
}