Example usage for org.apache.commons.lang3 StringUtils replace

List of usage examples for org.apache.commons.lang3 StringUtils replace

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils replace.

Prototype

public static String replace(final String text, final String searchString, final String replacement) 

Source Link

Document

Replaces all occurrences of a String within another String.

A null reference passed to this method is a no-op.

 StringUtils.replace(null, *, *)        = null StringUtils.replace("", *, *)          = "" StringUtils.replace("any", null, *)    = "any" StringUtils.replace("any", *, null)    = "any" StringUtils.replace("any", "", *)      = "any" StringUtils.replace("aba", "a", null)  = "aba" StringUtils.replace("aba", "a", "")    = "b" StringUtils.replace("aba", "a", "z")   = "zbz" 

Usage

From source file:ch.cyberduck.ui.cocoa.BookmarkTableDataSource.java

/**
 * @return the names (not full paths) of the files that the receiver promises to create at dropDestination.
 * This method is invoked when the drop has been accepted by the destination and the destination,
 * in the case of another Cocoa application, invokes the NSDraggingInfo method
 * namesOfPromisedFilesDroppedAtDestination.
 * For long operations, you can cache dropDestination and defer the creation of the files until the
 * finishedDraggingImage method to avoid blocking the destination application.
 * @see NSTableView.DataSource//  ww w.  j ava 2 s .  c  om
 */
@Override
public NSArray namesOfPromisedFilesDroppedAtDestination(final NSURL dropDestination) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Query promised files dropped dat destination %s", dropDestination.path()));
    }
    final NSMutableArray promisedDragNames = NSMutableArray.array();
    if (null != dropDestination) {
        for (Host bookmark : pasteboard) {
            final Local file = LocalFactory.get(dropDestination.path(), String.format("%s.duck",
                    StringUtils.replace(BookmarkNameProvider.toString(bookmark), "/", ":")));
            try {
                HostWriterFactory.get().write(bookmark, file);
            } catch (AccessDeniedException e) {
                log.warn(e.getMessage());
            }
            // Adding the filename that is promised to be created at the dropDestination
            promisedDragNames.addObject(NSString.stringWithString(file.getName()));
        }
        pasteboard.clear();
    }
    return promisedDragNames;
}

From source file:com.adguard.filter.rules.UrlFilterRule.java

/**
 * Searches for domain name in rule text and transforms it to punycode if needed.
 *
 * @param ruleText Rule text//w w w.  jav a 2 s . c  om
 * @return String
 */
private static String toPunycode(String ruleText) {
    try {
        if (UrlUtils.isASCII(ruleText)) {
            return ruleText;
        }

        String[] startsWith = new String[] { "http://www.", "https://www.", "http://", "https://", "||" };
        String[] contains = new String[] { "/", "^" };
        int startIndex = -1;

        for (String start : startsWith) {
            if (ruleText.startsWith(start)) {
                startIndex = start.length();
                break;
            }
        }

        if (startIndex == -1) {
            return ruleText;
        }

        int symbolIndex = -1;
        for (String contain : contains) {
            int index = ruleText.indexOf(contain, startIndex);
            if (index >= 0) {
                symbolIndex = index;
                break;
            }
        }

        String domain = symbolIndex == -1 ? ruleText.substring(startIndex)
                : ruleText.substring(startIndex, symbolIndex);

        // In case of one domain
        ruleText = StringUtils.replace(ruleText, domain, UrlUtils.toPunycode(domain));
        return ruleText;
    } catch (Exception ex) {
        LoggerFactory.getLogger(UrlFilterRule.class)
                .warn("Error while getting ascii domain for rule " + ruleText, ex);
        return StringUtils.EMPTY;
    }
}

From source file:com.gargoylesoftware.htmlunit.WebTestCase.java

/**
 * Loads an expectation file for the specified browser search first for a browser specific resource
 * and falling back in a general resource.
 * @param resourcePrefix the start of the resource name
 * @param resourceSuffix the end of the resource name
 * @return the content of the file//www.  ja  v a 2 s .com
 * @throws Exception in case of error
 */
protected String loadExpectation(final String resourcePrefix, final String resourceSuffix) throws Exception {
    final URL url = getExpectationsResource(getClass(), getBrowserVersion(), resourcePrefix, resourceSuffix);
    assertNotNull(url);
    final File file = new File(url.toURI());

    String content = FileUtils.readFileToString(file, "UTF-8");
    content = StringUtils.replace(content, "\r\n", "\n");
    return content;
}

From source file:com.taobao.android.PatchFieldTool.java

/**
 * ?dexfield,???String//  w w w.j a v  a2 s .  c om
 *
 * @param dexFile
 * @param outDexFile
 * @param orgFieldValue
 * @param newFieldValue
 * @return
 */
public static boolean modifyFieldValue(File dexFile, File outDexFile, String orgFieldValue,
        String newFieldValue) throws IOException, RecognitionException {
    File smaliFolder = new File(outDexFile.getParentFile(), "smali");
    if (smaliFolder.exists()) {
        FileUtils.deleteDirectory(smaliFolder);
    }
    smaliFolder.mkdirs();
    boolean disassembled = SmaliUtils.disassembleDexFile(dexFile, smaliFolder);
    if (disassembled) {
        Collection<File> smaliFiles = FileUtils.listFiles(smaliFolder, new String[] { "smali" }, true);
        for (File smaliFile : smaliFiles) {
            List<String> lines = FileUtils.readLines(smaliFile);
            for (int index = 0; index < lines.size(); index++) {
                String line = lines.get(index);
                String newLine = StringUtils.replace(line, "\"" + orgFieldValue + "\"",
                        "\"" + newFieldValue + "\"");
                lines.set(index, newLine);
            }
            FileUtils.writeLines(smaliFile, lines);
        }

        //?dex
        boolean assembled = SmaliUtils.assembleSmaliFile(smaliFolder, outDexFile);
        if (assembled) {
            FileUtils.deleteDirectory(smaliFolder);
            return true;
        }
    }
    return false;
}

From source file:com.neophob.sematrix.output.gui.GeneratorGui.java

public void setup() {
    size(windowWidth, windowHeight);//from w  w  w.j a va 2s.  com
    LOG.log(Level.INFO, "Create GUI Window with size " + this.getWidth() + "/" + this.getHeight()); //$NON-NLS-1$ //$NON-NLS-2$

    frameRate(Collector.getInstance().getFps());
    smooth();
    background(0, 0, 0);
    int i = 0;

    cp5 = new ControlP5(this);
    cp5.setAutoDraw(false);

    //press alt and you can move gui elements arround. disable this *should* work but does not...
    cp5.setMoveable(false);

    //alt-h hide all controls - I don't want that!
    cp5.disableShortcuts();

    cp5.getTooltip().setDelay(200);
    P5EventListener listener = new P5EventListener(this);

    //selected visual
    Collector col = Collector.getInstance();
    int nrOfVisuals = col.getAllVisuals().size();

    selectedVisualList = cp5.addRadioButton(GuiElement.CURRENT_VISUAL.guiText(), getVisualCenter(col),
            p5GuiYOffset - 58);
    selectedVisualList.setItemsPerRow(nrOfVisuals);
    selectedVisualList.setNoneSelectedAllowed(false);
    for (i = 0; i < nrOfVisuals; i++) {
        String s = Messages.getString("GeneratorGui.GUI_SELECTED_VISUAL") + (1 + i); //$NON-NLS-1$
        Toggle t = cp5.addToggle(s, 0, 0, singleVisualXSize - 1, 13);
        t.setCaptionLabel(s);
        selectedVisualList.addItem(t, i);
        cp5.getTooltip().register(s, Messages.getString("GeneratorGui.GUI_SELECTED_VISUAL_TOOLTIP_PREFIX") //$NON-NLS-1$
                + (1 + i) + Messages.getString("GeneratorGui.GUI_SELECTED_VISUAL_TOOLTIP_POSTFIX")); //$NON-NLS-1$
    }
    selectedVisualList.moveTo(ALWAYS_VISIBLE_TAB);

    cp5.addTextlabel("gen1", Messages.getString("GeneratorGui.GUI_GENERATOR_LAYER_1"), GENERIC_X_OFS + 3, //$NON-NLS-1$//$NON-NLS-2$
            3 + p5GuiYOffset).moveTo(ALWAYS_VISIBLE_TAB).getValueLabel();
    cp5.addTextlabel("gen2", Messages.getString("GeneratorGui.GUI_GENERATOR_LAYER_2"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + 3 + 3 * Theme.DROPBOX_XOFS, 3 + p5GuiYOffset).moveTo(ALWAYS_VISIBLE_TAB)
            .getValueLabel();
    cp5.addTextlabel("fx1", Messages.getString("GeneratorGui.GUI_EFFECT_LAYER_1"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + 3 + 1 * Theme.DROPBOX_XOFS, 3 + p5GuiYOffset).moveTo(ALWAYS_VISIBLE_TAB)
            .getValueLabel();
    cp5.addTextlabel("fx2", Messages.getString("GeneratorGui.GUI_EFFECT_LAYER_2"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + 3 + 4 * Theme.DROPBOX_XOFS, 3 + p5GuiYOffset).moveTo(ALWAYS_VISIBLE_TAB)
            .getValueLabel();
    cp5.addTextlabel("mix2", Messages.getString("GeneratorGui.GUI_LAYER_MIXER"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + 3 + 2 * Theme.DROPBOX_XOFS, 3 + p5GuiYOffset).moveTo(ALWAYS_VISIBLE_TAB)
            .getValueLabel();

    cp5.getTooltip().register("gen1", Messages.getString("GeneratorGui.GUI_TOOLTIP_GENERATOR_1")); //$NON-NLS-1$ //$NON-NLS-2$
    cp5.getTooltip().register("gen2", Messages.getString("GeneratorGui.GUI_TOOLTIP_GENERATOR_2")); //$NON-NLS-1$ //$NON-NLS-2$
    cp5.getTooltip().register("fx1", Messages.getString("GeneratorGui.GUI_TOOLTIP_EFFECT_1")); //$NON-NLS-1$ //$NON-NLS-2$
    cp5.getTooltip().register("fx2", Messages.getString("GeneratorGui.GUI_TOOLTIP_EFFECT_2")); //$NON-NLS-1$ //$NON-NLS-2$
    cp5.getTooltip().register("mix2", Messages.getString("GeneratorGui.GUI_TOOLTIP_MIXER")); //$NON-NLS-1$ //$NON-NLS-2$

    //Generator 
    generatorListOne = cp5.addDropdownList(GuiElement.GENERATOR_ONE_DROPDOWN.guiText(), GENERIC_X_OFS,
            p5GuiYOffset, Theme.DROPBOXLIST_LENGTH, 140);
    generatorListTwo = cp5.addDropdownList(GuiElement.GENERATOR_TWO_DROPDOWN.guiText(),
            GENERIC_X_OFS + 3 * Theme.DROPBOX_XOFS, p5GuiYOffset, Theme.DROPBOXLIST_LENGTH, 140);
    Theme.themeDropdownList(generatorListOne);
    Theme.themeDropdownList(generatorListTwo);
    i = 0;
    for (GeneratorName gn : GeneratorName.values()) {
        generatorListOne.addItem(gn.guiText(), i);
        generatorListTwo.addItem(gn.guiText(), i);
        i++;
    }
    generatorListOne.setLabel(generatorListOne.getItem(1).getName());
    generatorListTwo.setLabel(generatorListTwo.getItem(1).getName());
    generatorListOne.moveTo(ALWAYS_VISIBLE_TAB);
    generatorListTwo.moveTo(ALWAYS_VISIBLE_TAB);

    //Effect 
    effectListOne = cp5.addDropdownList(GuiElement.EFFECT_ONE_DROPDOWN.guiText(),
            GENERIC_X_OFS + 1 * Theme.DROPBOX_XOFS, p5GuiYOffset, Theme.DROPBOXLIST_LENGTH, 140);
    effectListTwo = cp5.addDropdownList(GuiElement.EFFECT_TWO_DROPDOWN.guiText(),
            GENERIC_X_OFS + 4 * Theme.DROPBOX_XOFS, p5GuiYOffset, Theme.DROPBOXLIST_LENGTH, 140);
    Theme.themeDropdownList(effectListOne);
    Theme.themeDropdownList(effectListTwo);
    i = 0;
    for (EffectName gn : EffectName.values()) {
        effectListOne.addItem(gn.guiText(), i);
        effectListTwo.addItem(gn.guiText(), i);
        i++;
    }
    effectListOne.setLabel(effectListOne.getItem(0).getName());
    effectListTwo.setLabel(effectListTwo.getItem(0).getName());
    effectListOne.moveTo(ALWAYS_VISIBLE_TAB);
    effectListTwo.moveTo(ALWAYS_VISIBLE_TAB);

    //Mixer 
    mixerList = cp5.addDropdownList(GuiElement.MIXER_DROPDOWN.guiText(), GENERIC_X_OFS + 2 * Theme.DROPBOX_XOFS,
            p5GuiYOffset, Theme.DROPBOXLIST_LENGTH, 140);
    Theme.themeDropdownList(mixerList);

    i = 0;
    for (MixerName gn : MixerName.values()) {
        mixerList.addItem(gn.guiText(), i);
        i++;
    }
    mixerList.setLabel(mixerList.getItem(0).getName());
    mixerList.moveTo(ALWAYS_VISIBLE_TAB);

    //---------------------------------
    //TABS
    //---------------------------------

    final int yPosStartLabel = p5GuiYOffset + 50;
    final int yPosStartDrowdown = p5GuiYOffset + 36;

    cp5.getWindow().setPositionOfTabs(GENERIC_X_OFS, this.getHeight() - 20);

    //there a default tab which is present all the time. rename this tab
    Tab generatorTab = cp5.getTab("default"); //$NON-NLS-1$
    generatorTab.setLabel(Messages.getString("GeneratorGui.TAB_GENERATOR_EFFECT")); //$NON-NLS-1$
    Tab outputTab = cp5.addTab(Messages.getString("GeneratorGui.TAB_SINGLE_OUTPUT_MAPPING")); //$NON-NLS-1$
    Tab allOutputTab = null;

    //add all output mapping only if multiple output panels exist
    if (nrOfVisuals > 2) {
        allOutputTab = cp5.addTab(Messages.getString("GeneratorGui.TAB_ALL_OUTPUT_MAPPING")); //$NON-NLS-1$
        allOutputTab.setColorForeground(0xffff0000);
    }

    Tab randomTab = cp5.addTab(Messages.getString("GeneratorGui.TAB_RANDOMIZE")); //$NON-NLS-1$
    Tab presetTab = cp5.addTab(Messages.getString("GeneratorGui.TAB_PRESETS")); //$NON-NLS-1$
    infoTab = cp5.addTab(Messages.getString("GeneratorGui.TAB_INFO")); //$NON-NLS-1$

    generatorTab.setColorForeground(0xffff0000);
    outputTab.setColorForeground(0xffff0000);
    randomTab.setColorForeground(0xffff0000);
    presetTab.setColorForeground(0xffff0000);

    //-------------
    //EFFECT tab
    //-------------
    thresholdSlider = cp5.addSlider(GuiElement.THRESHOLD.guiText(), 0, 255, 255,
            GENERIC_X_OFS + 0 * Theme.DROPBOX_XOFS, yPosStartDrowdown + 60, 160, 14);
    thresholdSlider.setSliderMode(Slider.FIX);
    thresholdSlider.setGroup(generatorTab);
    thresholdSlider.setDecimalPrecision(0);

    fxRotoSlider = cp5.addSlider(GuiElement.FX_ROTOZOOMER.guiText(), -127, 127, 0,
            GENERIC_X_OFS + 2 * Theme.DROPBOX_XOFS, yPosStartDrowdown + 60, 160, 14);
    fxRotoSlider.setSliderMode(Slider.FIX);
    fxRotoSlider.setGroup(generatorTab);
    fxRotoSlider.setDecimalPrecision(0);
    fxRotoSlider.setCaptionLabel(Messages.getString("GeneratorGui.EFFECT_ROTOZOOM_SPEED")); //$NON-NLS-1$

    //-------------
    //Generator tab
    //-------------

    cp5.addTextlabel("genBlinken", Messages.getString("GeneratorGui.BLINKENLIGHT_LOAD"), GENERIC_X_OFS + 3, //$NON-NLS-1$//$NON-NLS-2$
            yPosStartLabel + 5).moveTo(generatorTab).getValueLabel();
    blinkenLightsList = cp5.addDropdownList(GuiElement.BLINKENLIGHTS_DROPDOWN.guiText(), GENERIC_X_OFS,
            yPosStartDrowdown + 16, Theme.DROPBOXLIST_LENGTH, 140);
    Theme.themeDropdownList(blinkenLightsList);
    i = 0;
    for (String s : FileUtils.findBlinkenFiles()) {
        blinkenLightsList.addItem(s, i);
        i++;
    }
    blinkenLightsList.setLabel(blinkenLightsList.getItem(1).getName());
    blinkenLightsList.setGroup(generatorTab);
    blinkenLightsList.setHeight(100);

    //images
    cp5.addTextlabel("genImg", Messages.getString("GeneratorGui.IMAGE_LOAD"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + 3 + 1 * Theme.DROPBOX_XOFS, yPosStartLabel + 5).moveTo(generatorTab)
            .getValueLabel();

    imageList = cp5.addDropdownList(GuiElement.IMAGE_DROPDOWN.guiText(), GENERIC_X_OFS + Theme.DROPBOX_XOFS,
            yPosStartDrowdown + 16, Theme.DROPBOXLIST_LENGTH, 140);
    Theme.themeDropdownList(imageList);
    i = 0;
    for (String s : FileUtils.findImagesFiles()) {
        imageList.addItem(s, i);
        i++;
    }
    imageList.setLabel(imageList.getItem(1).getName());
    imageList.setGroup(generatorTab);
    imageList.setHeight(100);

    cp5.addTextlabel("genTextdefOpt", Messages.getString("GeneratorGui.TEXTUREDDEFORM_OPTIONS"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + 3 + 2 * Theme.DROPBOX_XOFS, yPosStartLabel + 5).moveTo(generatorTab)
            .getValueLabel();

    //texturedeform options      
    textureDeformOptions = cp5.addDropdownList(GuiElement.TEXTUREDEFORM_OPTIONS.guiText(),
            GENERIC_X_OFS + 2 * Theme.DROPBOX_XOFS, yPosStartDrowdown + 16, Theme.DROPBOXLIST_LENGTH, 140);
    Theme.themeDropdownList(textureDeformOptions);

    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_ANAMORPHOSIS"), 1); //$NON-NLS-1$
    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_SPIRAL"), 2); //$NON-NLS-1$
    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_ROTATINGTUNNEL"), 3); //$NON-NLS-1$
    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_START"), 4); //$NON-NLS-1$
    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_TUNNEL"), 5); //$NON-NLS-1$
    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_FLOWER"), 6); //$NON-NLS-1$
    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_CLOUD"), 7); //$NON-NLS-1$
    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_PLANAR"), 8); //$NON-NLS-1$
    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_CIRCLE"), 9); //$NON-NLS-1$
    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_SPIRAL"), 10); //$NON-NLS-1$
    textureDeformOptions.addItem(Messages.getString("GeneratorGui.TEXTUREDEFORM_3D"), 11); //$NON-NLS-1$

    textureDeformOptions.setLabel(textureDeformOptions.getItem(1).getName());
    textureDeformOptions.setGroup(generatorTab);
    textureDeformOptions.setHeight(80);

    //colorscroll options
    cp5.addTextlabel("genColorScroll", Messages.getString("GeneratorGui.COLORSCROLL_OPTIONS"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + 3 + 3 * Theme.DROPBOX_XOFS, yPosStartLabel + 5).moveTo(generatorTab)
            .getValueLabel();

    colorScrollList = cp5.addDropdownList(GuiElement.COLORSCROLL_OPTIONS.guiText(),
            GENERIC_X_OFS + 3 * Theme.DROPBOX_XOFS, yPosStartDrowdown + 16, Theme.DROPBOXLIST_LENGTH, 140);
    Theme.themeDropdownList(colorScrollList);

    for (ScrollMode sm : ScrollMode.values()) {
        colorScrollList.addItem(sm.name().replace("_", " "), sm.getMode()); //$NON-NLS-1$ //$NON-NLS-2$
    }
    colorScrollList.setLabel(colorScrollList.getItem(0).getName());
    colorScrollList.setGroup(generatorTab);
    colorScrollList.setHeight(100);

    //add textfield
    textGenerator = cp5.addTextfield("textfield", "Textfield", "Textfield", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            GENERIC_X_OFS + 3 + 4 * Theme.DROPBOX_XOFS, yPosStartLabel - 14, Theme.DROPBOXLIST_LENGTH, 16);

    freezeUpdate = cp5.addButton(GuiElement.BUTTON_TOGGLE_FREEZE.guiText(), 0,
            GENERIC_X_OFS + 5 * Theme.DROPBOX_XOFS, yPosStartDrowdown, Theme.DROPBOXLIST_LENGTH, 15);
    freezeUpdate.setCaptionLabel(Messages.getString("GeneratorGui.GUI_TOGGLE_FREEZE")); //$NON-NLS-1$
    freezeUpdate.setGroup(generatorTab);
    cp5.getTooltip().register(GuiElement.BUTTON_TOGGLE_FREEZE.guiText(),
            Messages.getString("GeneratorGui.TOOLTIP_FREEZE")); //$NON-NLS-1$

    brightnessControll = cp5.addSlider(GuiElement.BRIGHTNESS.guiText(), 0, 255, 255,
            GENERIC_X_OFS + 4 * Theme.DROPBOX_XOFS, yPosStartDrowdown + 60, 160, 14);
    brightnessControll.setSliderMode(Slider.FIX);
    brightnessControll.setGroup(generatorTab);
    brightnessControll.setDecimalPrecision(0);
    brightnessControll.setNumberOfTickMarks(11);
    brightnessControll.setRange(0, 100);

    //-----------------
    //Single Output tab
    //-----------------            
    int nrOfOutputs = Collector.getInstance().getAllOutputMappings().size();
    selectedOutputs = cp5.addRadioButton(GuiElement.CURRENT_OUTPUT.guiText(), GENERIC_X_OFS, yPosStartDrowdown);
    selectedOutputs.setItemsPerRow(nrOfOutputs);
    selectedOutputs.setNoneSelectedAllowed(false);
    for (i = 0; i < nrOfOutputs; i++) {
        String s = Messages.getString("GeneratorGui.OUTPUT_NR") + (1 + i); //$NON-NLS-1$
        Toggle t = cp5.addToggle(s, 0, 0, singleVisualXSize, 13);
        t.setCaptionLabel(s);
        selectedOutputs.addItem(t, i);
        cp5.getTooltip().register(s, Messages.getString("GeneratorGui.TOOLTIP_OUTPUT_PREFIX") + (1 + i) //$NON-NLS-1$
                + Messages.getString("GeneratorGui.TOOLTIP_OUTPUT_POSTFIX")); //$NON-NLS-1$
    }
    selectedOutputs.moveTo(outputTab);

    //visual
    cp5.addTextlabel("singleOutputVisual", Messages.getString("GeneratorGui.OUTPUT_VISUAL"), 38, //$NON-NLS-1$//$NON-NLS-2$
            yPosStartDrowdown + 68).moveTo(outputTab).getValueLabel();
    dropdownOutputVisual = GeneratorGuiHelper.createVisualDropdown(cp5,
            GuiElement.OUTPUT_SELECTED_VISUAL_DROPDOWN.guiText(), yPosStartDrowdown + 20, nrOfVisuals);
    dropdownOutputVisual.moveTo(outputTab);

    //Fader         
    cp5.addTextlabel("singleOutputTransition", Messages.getString("GeneratorGui.OUTPUT_TRANSITION"), //$NON-NLS-1$//$NON-NLS-2$
            38 + Theme.DROPBOX_XOFS * 2, yPosStartDrowdown + 68).moveTo(outputTab).getValueLabel();
    dropdownOutputFader = GeneratorGuiHelper.createFaderDropdown(cp5,
            GuiElement.OUTPUT_FADER_DROPDOWN.guiText(), yPosStartDrowdown + 20);
    dropdownOutputFader.moveTo(outputTab);

    //--------------
    //All Output tab
    //--------------            

    if (allOutputTab != null) {
        cp5.addTextlabel("allOutputTabLabel", //$NON-NLS-1$
                Messages.getString("GeneratorGui.TEXT_CHANGE_ALL_OUTPUT_MAPPINGS"), 20, yPosStartDrowdown) //$NON-NLS-1$
                .moveTo(allOutputTab).getValueLabel();

        cp5.addTextlabel("allOutputVisual", Messages.getString("GeneratorGui.ALL_OUTPUT_VISUAL"), 38, //$NON-NLS-1$//$NON-NLS-2$
                yPosStartDrowdown + 68).moveTo(allOutputTab).getValueLabel();
        allOutputTabVis = GeneratorGuiHelper.createVisualDropdown(cp5,
                GuiElement.OUTPUT_ALL_SELECTED_VISUAL_DROPDOWN.guiText(), yPosStartDrowdown + 20, nrOfVisuals);
        allOutputTabVis.moveTo(allOutputTab);

        //Fader         
        cp5.addTextlabel("allOutputTransition", Messages.getString("GeneratorGui.ALL_OUTPUT_TRANSITION"), //$NON-NLS-1$//$NON-NLS-2$
                38 + Theme.DROPBOX_XOFS * 2, yPosStartDrowdown + 68).moveTo(allOutputTab).getValueLabel();
        allOutputTabFader = GeneratorGuiHelper.createFaderDropdown(cp5,
                GuiElement.OUTPUT_ALL_FADER_DROPDOWN.guiText(), yPosStartDrowdown + 20);
        allOutputTabFader.moveTo(allOutputTab);
    }

    //palette dropdown list   
    cp5.addTextlabel("colSet", Messages.getString("GeneratorGui.SELECT_COLORSET"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + 5 * Theme.DROPBOX_XOFS, p5GuiYOffset + 3).moveTo(ALWAYS_VISIBLE_TAB)
            .getValueLabel();

    colorSetList = cp5.addDropdownList(GuiElement.COLOR_SET_DROPDOWN.guiText(),
            GENERIC_X_OFS + 5 * Theme.DROPBOX_XOFS, p5GuiYOffset, Theme.DROPBOXLIST_LENGTH, 140);
    Theme.themeDropdownList(colorSetList);
    i = 0;
    for (ColorSet cs : Collector.getInstance().getColorSets()) {
        colorSetList.addItem(cs.getName(), i);
        i++;
    }
    colorSetList.setLabel(colorSetList.getItem(1).getName());
    colorSetList.setHeight(100);
    colorSetList.moveTo(ALWAYS_VISIBLE_TAB);
    cp5.getTooltip().register("colSet", Messages.getString("GeneratorGui.TOOLTIP_COLORSET")); //$NON-NLS-1$ //$NON-NLS-2$

    //----------
    //RANDOM Tab
    //----------            

    Textlabel t2 = cp5.addTextlabel("rndDesc", //$NON-NLS-1$
            Messages.getString("GeneratorGui.TEXT_RANDOM_MODE_SELECT_ELEMENTS"), //$NON-NLS-1$
            20, yPosStartDrowdown);
    t2.moveTo(randomTab).getValueLabel();

    randomCheckbox = cp5.addCheckBox(GuiElement.RANDOM_ELEMENT.guiText())
            .setPosition(35, 20 + yPosStartDrowdown).setSize(40, 20).setColorForeground(color(120))
            .setColorActive(color(255)).setColorLabel(color(255)).setItemsPerRow(5).setSpacingColumn(90);

    for (ShufflerOffset so : ShufflerOffset.values()) {
        randomCheckbox.addItem(so.guiText(), i);
    }
    randomCheckbox.activateAll();
    randomCheckbox.moveTo(randomTab);

    //Button
    randomSelection = cp5.addButton(GuiElement.BUTTON_RANDOM_CONFIGURATION.guiText(), 0,
            GENERIC_X_OFS + 5 * Theme.DROPBOX_XOFS, p5GuiYOffset + 30, 100, 15);
    randomSelection.setCaptionLabel(Messages.getString("GeneratorGui.RANDOMIZE")); //$NON-NLS-1$
    randomSelection.moveTo(randomTab);
    cp5.getTooltip().register(GuiElement.BUTTON_RANDOM_CONFIGURATION.guiText(),
            Messages.getString("GeneratorGui.TOOLTIP_RANDOMIZE")); //$NON-NLS-1$

    randomPresets = cp5.addButton(GuiElement.BUTTON_RANDOM_PRESET.guiText(), 0,
            GENERIC_X_OFS + 5 * Theme.DROPBOX_XOFS, p5GuiYOffset + 55, 100, 15);
    randomPresets.setCaptionLabel(Messages.getString("GeneratorGui.RANDOM_PRESET")); //$NON-NLS-1$
    randomPresets.moveTo(randomTab);
    cp5.getTooltip().register(GuiElement.BUTTON_RANDOM_PRESET.guiText(),
            Messages.getString("GeneratorGui.TOOLTIP_RANDOM_PRESET")); //$NON-NLS-1$

    toggleRandom = cp5.addToggle(GuiElement.BUTTON_TOGGLE_RANDOM_MODE.guiText(), true,
            GENERIC_X_OFS + 5 * Theme.DROPBOX_XOFS, p5GuiYOffset + 80, 100, 15);
    toggleRandom.setCaptionLabel(Messages.getString("GeneratorGui.RANDOM_MODE")); //$NON-NLS-1$
    toggleRandom.setState(false);
    toggleRandom.moveTo(randomTab);
    cp5.getTooltip().register(GuiElement.BUTTON_TOGGLE_RANDOM_MODE.guiText(),
            Messages.getString("GeneratorGui.TOOLTIP_RANDOM_MODE")); //$NON-NLS-1$

    //----------
    //PRESET Tab
    //----------

    presetButtons = cp5.addRadioButton(GuiElement.PRESET_BUTTONS.guiText()).setPosition(20, yPosStartDrowdown)
            .setSize(14, 14).setColorForeground(color(120)).setColorActive(color(255)).setColorLabel(color(255))
            .setItemsPerRow(16).setSpacingColumn(36).setNoneSelectedAllowed(false);

    for (i = 0; i < 96; i++) {
        String label = "" + (i + 1); //$NON-NLS-1$
        if (i < 9) {
            label = "0" + (i + 1); //$NON-NLS-1$
        }
        presetButtons.addItem(label, i);
    }
    presetButtons.activate(col.getSelectedPreset());
    presetButtons.moveTo(presetTab);

    loadPreset = cp5.addButton(GuiElement.LOAD_PRESET.guiText(), 0, GENERIC_X_OFS + 2 * Theme.DROPBOX_XOFS,
            yPosStartDrowdown + 106, 100, 15);
    loadPreset.setCaptionLabel(GuiElement.LOAD_PRESET.guiText());
    loadPreset.moveTo(presetTab);
    cp5.getTooltip().register(GuiElement.LOAD_PRESET.guiText(),
            Messages.getString("GeneratorGui.TOOLTIP_LOAD_PRESET")); //$NON-NLS-1$

    savePreset = cp5.addButton(GuiElement.SAVE_PRESET.guiText(), 0, GENERIC_X_OFS + 3 * Theme.DROPBOX_XOFS,
            yPosStartDrowdown + 106, 100, 15);
    savePreset.setCaptionLabel(GuiElement.SAVE_PRESET.guiText());
    savePreset.moveTo(presetTab);
    cp5.getTooltip().register(GuiElement.SAVE_PRESET.guiText(),
            Messages.getString("GeneratorGui.TOOLTIP_SAVE_PRESET")); //$NON-NLS-1$

    presetName = cp5.addTextfield("presetName", 20, yPosStartDrowdown + 106, Theme.DROPBOXLIST_LENGTH * 2, 16) //$NON-NLS-1$
            .moveTo(presetTab);
    presetInfo = cp5.addTextlabel("presetInfo", "", 160, yPosStartDrowdown + 126).moveTo(presetTab) //$NON-NLS-1$//$NON-NLS-2$
            .getValueLabel();

    updateCurrentPresetState();

    //-------------
    //Info tab
    //-------------

    int yposAdd = 20;
    int xposAdd = 200;

    //center it, we have 3 row which are 160 pixels wide
    int xOfs = (this.getWidth() - 3 * xposAdd) / 2;
    int nfoYPos = yPosStartDrowdown + 20;
    int nfoXPos = xOfs;

    cp5.addTextlabel("nfoFpsConf", Messages.getString("GeneratorGui.CONF_FPS") + col.getFps(), nfoXPos, nfoYPos) //$NON-NLS-1$//$NON-NLS-2$
            .moveTo(infoTab).getValueLabel();
    nfoYPos += yposAdd;
    currentFps = cp5.addTextlabel("nfoFpsCurrent", "", nfoXPos, nfoYPos).moveTo(infoTab).getValueLabel(); //$NON-NLS-1$ //$NON-NLS-2$
    nfoYPos += yposAdd;
    runtime = cp5.addTextlabel("nfoRuntime", "", nfoXPos, nfoYPos).moveTo(infoTab).getValueLabel(); //$NON-NLS-1$ //$NON-NLS-2$
    nfoYPos += yposAdd;
    cp5.addTextlabel("nfoSrvVersion", //$NON-NLS-1$
            Messages.getString("GeneratorGui.SERVER_VERSION") //$NON-NLS-1$
                    + Collector.getInstance().getPixConStat().getVersion(),
            nfoXPos, nfoYPos).moveTo(infoTab).getValueLabel();
    nfoYPos += yposAdd;

    nfoXPos += xposAdd;
    nfoYPos = yPosStartDrowdown + 20;
    Output output = col.getOutputDevice();
    if (output != null) {
        String gammaText = WordUtils
                .capitalizeFully(StringUtils.replace(output.getGammaType().toString(), "_", " "));
        cp5.addTextlabel("nfoGamma", Messages.getString("GeneratorGui.GAMMA_CORRECTION") + gammaText, nfoXPos, //$NON-NLS-1$//$NON-NLS-2$
                nfoYPos).moveTo(infoTab).getValueLabel();
        nfoYPos += yposAdd;
        cp5.addTextlabel("nfoBps", Messages.getString("GeneratorGui.OUTPUT_BPP") + output.getBpp(), nfoXPos, //$NON-NLS-1$//$NON-NLS-2$
                nfoYPos).moveTo(infoTab).getValueLabel();
        nfoYPos += yposAdd;
    }
    sentFrames = cp5.addTextlabel("nfoSentFrames", "", nfoXPos, nfoYPos).moveTo(infoTab).getValueLabel(); //$NON-NLS-1$ //$NON-NLS-2$
    nfoYPos += yposAdd;
    outputErrorCounter = cp5.addTextlabel("nfoErrorFrames", "", nfoXPos, nfoYPos).moveTo(infoTab) //$NON-NLS-1$//$NON-NLS-2$
            .getValueLabel();
    nfoYPos += yposAdd;
    outputState = cp5.addTextlabel("nfoOutputState", "", nfoXPos, nfoYPos).moveTo(infoTab).getValueLabel(); //$NON-NLS-1$ //$NON-NLS-2$
    nfoYPos += yposAdd;

    nfoXPos += xposAdd;
    nfoYPos = yPosStartDrowdown + 20;
    String oscPort = "" + Integer.parseInt(col.getPh().getProperty(ConfigConstant.NET_OSC_LISTENING_PORT, "")); //$NON-NLS-1$ //$NON-NLS-2$
    cp5.addTextlabel("nfoOscPort", Messages.getString("GeneratorGui.OSC_PORT") + oscPort, nfoXPos, nfoYPos) //$NON-NLS-1$//$NON-NLS-2$
            .moveTo(infoTab).getValueLabel();
    nfoYPos += yposAdd;
    String tcpPort = "" + Integer.parseInt(col.getPh().getProperty(ConfigConstant.NET_LISTENING_PORT, "")); //$NON-NLS-1$ //$NON-NLS-2$
    cp5.addTextlabel("nfoTcpPort", Messages.getString("GeneratorGui.TCP_PORT") + tcpPort, nfoXPos, nfoYPos) //$NON-NLS-1$//$NON-NLS-2$
            .moveTo(infoTab).getValueLabel();
    nfoYPos += yposAdd;
    oscStatistic = cp5
            .addTextlabel("nfoOscStatistic", Messages.getString("GeneratorGui.OSC_STATISTIC"), nfoXPos, nfoYPos)
            .moveTo(infoTab).getValueLabel();
    nfoYPos += yposAdd;

    //----------
    // LOGO
    //----------    

    try {
        logo = loadImage("gui" + File.separatorChar + "guilogo.jpg");
        LOG.log(Level.INFO, "GUI logo loaded");
    } catch (Exception e) {
        LOG.log(Level.INFO, "Failed to load gui logo!", e);
    }

    //----------
    // MISC
    //----------    

    int xSizeForEachWidget = (windowWidth - 2 * GENERIC_X_OFS) / NR_OF_WIDGETS;

    cp5.addTextlabel("frameDesc", Messages.getString("GeneratorGui.FRAME_PROGRESS"), GENERIC_X_OFS, //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_Y_OFS).moveTo(ALWAYS_VISIBLE_TAB).getValueLabel();
    cp5.addTextlabel("sndDesc", Messages.getString("GeneratorGui.SOUND_DESC"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + xSizeForEachWidget, GENERIC_Y_OFS).moveTo(ALWAYS_VISIBLE_TAB).getValueLabel();
    cp5.addTextlabel("sndVol", Messages.getString("GeneratorGui.INPUT_VOLUME"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + xSizeForEachWidget * 2, GENERIC_Y_OFS).moveTo(ALWAYS_VISIBLE_TAB).getValueLabel();
    cp5.addTextlabel("outputDevice", Messages.getString("GeneratorGui.OUTPUT_DEVICE"), //$NON-NLS-1$//$NON-NLS-2$
            GENERIC_X_OFS + xSizeForEachWidget * 3, GENERIC_Y_OFS).moveTo(ALWAYS_VISIBLE_TAB).getValueLabel();
    cp5.addTextlabel("outputDeviceName", col.getOutputDeviceName(), 15 + GENERIC_X_OFS + xSizeForEachWidget * 3, //$NON-NLS-1$
            2 + GENERIC_Y_OFS + 10).moveTo(ALWAYS_VISIBLE_TAB).getValueLabel();

    //register event listener
    cp5.addListener(listener);

    //select first visual
    selectedVisualList.activate(0);
    selectedOutputs.activate(0);

    initialized = true;
}

From source file:de.micromata.genome.gwiki.controls.GWikiEditPageActionBean.java

/**
 * Helper method to check keywords properties.
 * //from  w  w w  .j ava 2  s .  co m
 * @param ctx
 * @param value
 */
public static void checkKeywordProperties(GWikiContext ctx, String value) {
    try {
        List<String> keywords = CommaListParser.parseCommaList(value);
        for (String kw : keywords) {
            kw = StringUtils.replace(kw, ")", "){0,1}");
            Pattern.compile(kw);
        }
    } catch (Exception ex) {
        ctx.addValidationError("gwiki.edit.EditPage.message.invalidkeywordformat", ex.getMessage());
    }
}

From source file:eionet.gdem.utils.Utils.java

/**
 * Utility method for checking whether the resource exists. The resource can be web or file system resource that matches the URI
 * with "http", "https" or "file" schemes Returns false, if the resource does not exist
 *
 * @param strUri/*from  w  w w . j  av  a 2 s.  c om*/
 * @return
 */
public static boolean resourceExists(String strUri) {
    strUri = StringUtils.replace(strUri, "\\", "/");
    try {
        URI uri = new URI(strUri);
        String scheme = uri.getScheme();
        if (scheme.startsWith("http")) {
            return HttpUtils.urlExists(strUri);
        } else if (scheme.equals("file")) {
            File f = new File(uri.getPath());
            return f.exists();
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return false;
    }
    return false;
}

From source file:com.farmerbb.notepad.activity.MainActivity.java

@SuppressLint("SetJavaScriptEnabled")
@TargetApi(Build.VERSION_CODES.KITKAT)//from  w  ww.j a  v  a 2  s .c  o m
public void printNote(String contentToPrint) {
    SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", MODE_PRIVATE);

    // Create a WebView object specifically for printing
    boolean generateHtml = !(pref.getBoolean("markdown", false)
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
    WebView webView = generateHtml ? new WebView(this) : new MarkdownView(this);

    // Apply theme
    String theme = pref.getString("theme", "light-sans");
    int textSize = -1;

    String fontFamily = null;

    if (theme.contains("sans")) {
        fontFamily = "sans-serif";
    }

    if (theme.contains("serif")) {
        fontFamily = "serif";
    }

    if (theme.contains("monospace")) {
        fontFamily = "monospace";
    }

    switch (pref.getString("font_size", "normal")) {
    case "smallest":
        textSize = 12;
        break;
    case "small":
        textSize = 14;
        break;
    case "normal":
        textSize = 16;
        break;
    case "large":
        textSize = 18;
        break;
    case "largest":
        textSize = 20;
        break;
    }

    String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom_print)
            / getResources().getDisplayMetrics().density) + "px";
    String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right_print)
            / getResources().getDisplayMetrics().density) + "px";
    String fontSize = " " + Integer.toString(textSize) + "px";

    String css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:"
            + fontFamily + "; " + "font-size:" + fontSize + "; " + "}";

    webView.getSettings().setJavaScriptEnabled(false);
    webView.getSettings().setLoadsImagesAutomatically(false);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(final WebView view, String url) {
            createWebPrintJob(view);
        }
    });

    // Load content into WebView
    if (generateHtml) {
        webView.loadDataWithBaseURL(null,
                "<link rel='stylesheet' type='text/css' href='data:text/css;base64,"
                        + Base64.encodeToString(css.getBytes(), Base64.DEFAULT) + "' /><html><body><p>"
                        + StringUtils.replace(contentToPrint, "\n", "<br>") + "</p></body></html>",
                "text/HTML", "UTF-8", null);
    } else
        ((MarkdownView) webView).loadMarkdown(contentToPrint,
                "data:text/css;base64," + Base64.encodeToString(css.getBytes(), Base64.DEFAULT));
}

From source file:com.taobao.android.tpatch.utils.SmaliUtils.java

/**
 * ?davikclass??/*from   w  w w  .  ja  v  a  2 s.c  o  m*/
 * @param className
 * @return
 */
public static String getDalvikClassName(String className) {
    if (className.charAt(0) != 'L' || className.charAt(className.length() - 1) != ';') {
        throw new RuntimeException("Not a valid dalvik class name" + className);
    }
    return StringUtils.replace(className.substring(1, className.length() - 1), "/", ".");
}

From source file:me.ryanhamshire.griefprevention.permission.GPPermissionHandler.java

public static String getTargetPermission(String flagPermission) {
    flagPermission = StringUtils.replace(flagPermission, "griefprevention.flag.", "");
    boolean found = false;
    for (ClaimFlag flag : ClaimFlag.values()) {
        if (flagPermission.contains(flag.toString() + ".")) {
            found = true;//from ww  w. ja v a 2  s.  c o m
        }
        flagPermission = StringUtils.replace(flagPermission, flag.toString() + ".", "");
    }
    if (!found) {
        return null;
    }
    final int sourceIndex = flagPermission.indexOf(".source.");
    if (sourceIndex != -1) {
        flagPermission = StringUtils.replace(flagPermission,
                flagPermission.substring(sourceIndex, flagPermission.length()), "");
    }

    return flagPermission;
}