EzDevInfo.com

formatter.js

Format html inputs to match a specified pattern formatter.js by firstopinion

Eclipse formatter to keep One-Liners

Can Eclipse Formatter be configured to keep:

public Long getId() { return this.id; }

And maybe to format small (one line) definitions as one-liners?


Source: (StackOverflow)

How to properly format currency on ios

I'm looking for a way to format a string into currency without using the TextField hack.

For example, i'd like to have the number "521242" converted into "5,212.42" Or if I have a number under 1$, I would like it to look like this: "52" -> "0.52"

Thanks


Source: (StackOverflow)

Advertisements

Making Eclipse's Java code formatter ignore comments

Is there a way to make Eclipse's built-in Java code formatter ignore comments? Whenever I run it, it turns this:

    /*
     * PSEUDOCODE
     * Read in user's string/paragraph
     * 
     * Three cases are possible
     * Case 1: foobar
     *         do case 1 things
     * Case 2: fred hacker
     *         do case 2 things
     * Case 3: cowboyneal
     *         do case 3 things
     *         
     * In all cases, do some other thing
     */

into this:

    /*
     * PSEUDOCODE Read in user's string/paragraph
     * 
     * Three cases are possible Case 1: foobar do case 1 things Case 2: fred
     * hacker do case 2 things Case 3: cowboyneal do case 3 things
     * 
     * In all cases, do some other thing
     */

I have already played around with the Windows > Preferences > Java > Code Style > Formatter settings but can't find one for keeping comment formatting. I'm using Eclipse 3.4.0.


Source: (StackOverflow)

Can the Eclipse Java formatter be used stand-alone

Is there a way to use the formatter that comes with eclipse, outside of eclipse? I would like to format some java files using my formatter.xml file that I have configured using eclipse. Does anyone have any code examples that would allow me to do this? I would also like to use this standalone, so the specific jars that are used would be nice.


Source: (StackOverflow)

How to stop Eclipse formatter from adding trailing whitespaces in Javadoc

I noticed an odd behavior of the Eclipse formatter (Strg+Alt+F) when running it on a piece of code like this:

/**
 * bar
 *
 * @return nothing
 */
Object foo() {
    return null;
}

It will add a trailing space character here:

/**
 * bar
 * <--- this line has a trailing space now!
 * @return nothing
 */
Object foo() {
    return null;
}

I know how to configure Eclipse to remove trailing whitespace, but it there a way to stop the formatter from adding it in the first place?


Source: (StackOverflow)

How to stop Eclipse formatter from placing all enums on one line

I have enums like:

public static enum Command
{
login,
register,
logout,
newMessage
}

When formatting the file, the output becomes:

public static enum Command 
{
login, register, logout, newMessage
}

Source: (StackOverflow)

How can I correctly format currency using jquery?

I do not need a mask, but I need something that will format currency(in all browsers) and not allow for any letters or special char's to be typed. Thanks for the help

Example:

Valid: $50.00
$1,000.53

Not Valid: $w45.00
$34.3r6


Source: (StackOverflow)

Understanding the $ in Java's format strings

 StringBuilder sb = new StringBuilder();
 // Send all output to the Appendable object sb
 Formatter formatter = new Formatter(sb, Locale.US);

 // Explicit argument indices may be used to re-order output.
 formatter.format("%4$2s %3$2s %2$2s %1$2s", "a", "b", "c", "d")
 // -> " d  c  b  a"

In this case, why is a 2 appended to $?


Source: (StackOverflow)

CSS formatter NOT based on CSS Tidy? [closed]

I can't find a css formatter (web based or Windows app) which formats the css where it puts the open brace on its own line aligned with its close brace, plus indents the attributes. The web based css formatters out here seem to be based on CSSTidy which doesn't do what I want.

I don't like this CSSTidy format:

.example {
font-size: 3em;
}

I want:

.example
{
    font-size: 3em;
}

Source: (StackOverflow)

android EditText ,keyboard textWatcher problem

I am working on a android app and I have an EditText where user can input numbers. I want to format the number using different currency formats (say ##,##,###) and I want to do it on the fly, ie when user enter each digit(not when enter is pressed). I googled around, and came across TextWatcher which I first found promising, but it turned out to be an absolute pain. I am debugging my code on a HTC Desire phone which only has a soft keyboard.

Now I want to get a callback when user press numbers (0 to 9) , del (backspace) key and enter key. From my testing I found these (atleast on my phone)

1) editText onKeyListener is called when user presses del or enter key. When user presses enter, onKey function is called twice for one enter (which I believe is for ACTION_UP and ACTION_DOWN). When user presses del, onKey is called once (only for ACTION_DOWN) which I dont know why. onKey is never called when user presses any digits(0 to 9) which too I cant understand.

2) TextWatchers 3 callback functions are called (beforeTextChanged, onTextChanged, afterTextChanged) whenever user presses any number (0 to 9) key . So I thought by using TextWatcher and onKeyListener together I can get all callbacks I need.

Now my questions are these..

1) First in my HTC soft keyboard there is a key (a keyboard symbol with a down arrow) and when I click on it keyboard is resigned without giving any callback. I still cant believe android letting user to edit a field and resign without letting program to process (save) the edit. Now my editText is showing one value and my object has another value (I am saving user edits on enter, and handling back press on keyboard by reseting editText value with the value in the object , but I have no answer to this keyboard down key).

2) Second, I want to format the number after user entered the new digit. Say I already have 123 on editText and user entered pressed 4, I want my editText to display 1,234. I get full number on onTextChanged() and afterTextChanged() and I can format the number and put it back to editText in any of these callback. Which one should I use? Which is the best practice?

3) Third one is the most crucial problem. When app start I put the current object value in the editText. Say I put 123 on onResume(), and when user enter a digit (say 4) I want it to be 1234. But on my onTextChanged callback what I am getting is 4123. When I press one more key (say 5) I am getting 45123. So for user inputs editText cursor are pointing to end of the text. But when value is set by hand, editText cursor dont seems to be updating. I believe I have to do something in textWatcher callbacks but I dont know what I should do.

I am posting my code below.

public class AppHome extends AppBaseActivity {
    private EditText ed = null;
    private NumberFormat amountFormatter = null;
    private boolean  isUserInput = true;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_home_screen);

        ed = (EditText)findViewById(R.id.main_amount_textfield);
        amountFormatter = new DecimalFormat("##,##,###");


        ed.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if(event.getAction() == KeyEvent.ACTION_DOWN) 
                    return true;
                String strippedAmount = ed.getText().toString().replace(",", "");
                if(keyCode == KeyEvent.KEYCODE_DEL){
                    //delete pressed, strip number of comas and then delete least significant digit.
                    strippedAmount = strippedAmount.substring(0, strippedAmount.length() - 1);
                    int amountNumeral = 0;
                    try{
                        amountNumeral = Integer.parseInt(strippedAmount);
                    } catch(NumberFormatException e){
                    }
                    myObject.amount = amountNumeral;
                    isUserInput = false;
                    setFormattedAmount(amountNumeral,ed.getId());
                }else if(keyCode == KeyEvent.KEYCODE_ENTER){
                    //enter pressed, save edits and resign keyboard
                    int amountNumeral = 0;
                    try{
                        amountNumeral = Integer.parseInt(strippedAmount);
                    } catch(NumberFormatException e){
                    }
                    myObject.amount = amountNumeral;
                    isUserInput = false;
                    setFormattedAmount(myObject.amount,ed.getId());
                    //save edits
                    save();
                    //resign keyboard..
                    InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    in.hideSoftInputFromWindow(AppHome.this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
                }
                return true;
            }
        });

        TextWatcher inputTextWatcher = new TextWatcher() {
            public void afterTextChanged(Editable s) { 
                if(isUserInput == false){
                    //textWatcher is recursive. When editText value is changed from code textWatcher callback gets called. So this variable acts as a flag which tells whether change is user generated or not..Possibly buggy code..:(
                    isUserInput = true;
                    return;
                }
                String strippedAmount = ed.getText().toString().replace(",", "");
                int amountNumeral = 0;
                try{
                    amountNumeral = Integer.parseInt(strippedAmount);
                } catch(NumberFormatException e){
                }
                isUserInput = false;
                setFormattedAmount(amountNumeral,ed.getId());
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after){
            }
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
        };

        ed.addTextChangedListener(inputTextWatcher);
    }//end of onCreate...

    public void setFormattedAmount(Integer amount, Integer inputBoxId){
        double amountValue = 0;
        String textString =null;
        TextView amountInputBox = (TextView) findViewById(inputBoxId);

        amountValue = Double.parseDouble(Integer.toString(amount));
        textString = amountFormatter.format(amountValue).toString();
        amountInputBox.setText(textString);
    }
}

I know it is a big question, but I am working on this same problem for 2 days. I am new to android and still cant believe that there is no easy way to process textEdit data on the fly (I done the same on iphone with ease). Thanks all

EDIT: after using input filter

InputFilter filter = new InputFilter() { 
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { 
            String strippedAmount = dest.toString() + source;
            strippedAmount = strippedAmount.replace(",", "");

        int amountNumeral = 0;
        try{
            amountNumeral = Integer.parseInt(strippedAmount);
        } catch(NumberFormatException e){
        }           
            return amountFormatter.format(amountNumeral).toString(); 
    } 
}; 

ed.setFilters(new InputFilter[]{filter}); 

When app starts I am putting 1,234 on the editText

myObject.amount = 1234;
ed.setText(amountFormatter.format(myObject.amount).toString());

Then when user clicks the editText, keyboard pops up, and say user enters digit 6

I am getting : 61234 I want : 12346


Source: (StackOverflow)

Change how eclipse formatter wraps long strings

I have set the eclipse java formatter to wrap lines that exceed 120 characters to conform to our team's coding standard. However, when I have a long string that is wrapped I want the plus sign (+) to appear as the last character on the first line e.g.

String s = "Very long line that should be " +
"wrapped across several rows"; 

The default behaviour is that the plus sign is placed on its own line e.g.

String s = "Very long line that should be "
+
"wrapped across several rows";

So is it possible to specify where the plus sign should appear in the eclipse java formatter?


Source: (StackOverflow)

Auto updating formatter in Eclipse

We rely on Eclipse formatter in our project to enforce formatting conventions for us. It works great and we really like it.

We keep the formatter file with our project in source control and ask everybody to import this formatter to Eclipse. The only serious problem is that whenever somebody modifies the formatter and commits the change, then every team member needs to manually "reimport" the formatter. And it's easy to forget about doing it, so we often end up with using different versions of formatter among the team.

Is there any way to make Eclipse automatically use new version of formatter when the formatter file is updated? (I mean, could we just say to Eclipse "here's the path to formatter file, always use the current version of this file as a formatter"?) It would be great!

Any ideas?


Source: (StackOverflow)

How can I get eclipse to wrap lines after a period instead of before

I've looked throughout Preferences -> Java -> Code Style -> Formatter and can't find any way to get eclipse to format my code like:

something.
    someMethod().
    anotherMethod().
    lastMethod();

Instead of:

something
    .someMethod()
    .anotherMethod()
    .lastMethod();

I know that's non-standard, but that's what I need.

Edit: This is not about getting lines to wrap. It's specifically about where the wrap happens in relation to the period. I want the period at the end of the line, before the newline and right now eclipse wants the period at the start of the next line.

Edit2: Even if I could find out where eclipse's source code it decides where to wrap the line, that might help. I think it might be in the JDT project, but I'm not 100% and there's a lot in there.


Source: (StackOverflow)

Recommendations for JSON editor on Windows? [closed]

Are there any JSON editor on Windows?

-I try Notepad++ but it supports JSON with third party plug-ins which needs to be call from Notepad++ menus each time you open a Json file. And some of them does not work properly.

-I try Gedit for Windows, but it does not supports JSON as default. I could not found support for Windows version.

-Most of JSON service I found based on online (from browser). I can not use them offline.

-All JSON extensions for browsers (Chrome and Firefox) can just read (format or validate) the JSON file. I could not find any JSON editor extension. I don't want to use extension because most of them (all extension that I try) does not works with local files. They just enabling themselves when I download the JSON file from internet.

Thanks in advance...


Source: (StackOverflow)

Android NumberPicker with Formatter does not format on first rendering

I have a number picker that has a formatter that formats the numbers as soon as I spin the numberpicker or put a value in myself. This works fine, but when the numberpicker is first shown and I initialize it with setValue(0) the 0 does not get formatted (it should display as "-" instead of 0). As soon as I spin the number picker, from that point on everything works.

How can I force the numberpicker to format instantly on first rendering (and also when I enter a number with the keyboard)?

Thanks for all advice!

public class PickerFormatter implements Formatter {

private String mSingle;
private String mMultiple;

public PickerFormatter(String single, String multiple) {
    mSingle = single;
    mMultiple = multiple;
}

@Override
public String format(int num) {
    if (num == 0) {
        return "-";
    }
    if (num == 1) {
        return num + " " + mSingle;
    }
    return num + " " + mMultiple;
}

}

this is my formatter and i just add it to the picker with the picker.setFormatter method, like so:

picker.setMaxValue(max);
    picker.setMinValue(min);
    picker.setFormatter(new PickerFormatter(single, multiple));
    picker.setWrapSelectorWheel(wrap);

that is all i do to the picker..


Source: (StackOverflow)