23 |
24 |
25 |
--------------------------------------------------------------------------------
/dist/README.TXT:
--------------------------------------------------------------------------------
1 | ========================
2 | BUILD OUTPUT DESCRIPTION
3 | ========================
4 |
5 | When you build an Java application project that has a main class, the IDE
6 | automatically copies all of the JAR
7 | files on the projects classpath to your projects dist/lib folder. The IDE
8 | also adds each of the JAR files to the Class-Path element in the application
9 | JAR files manifest file (MANIFEST.MF).
10 |
11 | To run the project from the command line, go to the dist folder and
12 | type the following:
13 |
14 | java -jar "JavaHelper.jar"
15 |
16 | To distribute this project, zip up the dist folder (including the lib folder)
17 | and distribute the ZIP file.
18 |
19 | Notes:
20 |
21 | * If two JAR files on the project classpath have the same name, only the first
22 | JAR file is copied to the lib folder.
23 | * Only JAR files are copied to the lib folder.
24 | If the classpath contains other types of files or folders, these files (folders)
25 | are not copied.
26 | * If a library on the projects classpath also has a Class-Path element
27 | specified in the manifest,the content of the Class-Path element has to be on
28 | the projects runtime path.
29 | * To set a main class in a standard Java project, right-click the project node
30 | in the Projects window and choose Properties. Then click Run and enter the
31 | class name in the Main Class field. Alternatively, you can manually type the
32 | class name in the manifest Main-Class element.
33 |
--------------------------------------------------------------------------------
/dist/javadoc/com/kentcdodds/javahelper/model/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.kentcdodds.javahelper.model
8 |
9 |
10 |
11 |
12 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/src/com/kentcdodds/javahelper/extras/LimitLinesDocumentListener.java:
--------------------------------------------------------------------------------
1 | package com.kentcdodds.javahelper.extras;
2 |
3 | import javax.swing.event.DocumentListener;
4 | import javax.swing.*;
5 | import javax.swing.event.*;
6 | import javax.swing.text.*;
7 |
8 | /*
9 | * A class to control the maximum number of lines to be stored in a Document
10 | *
11 | * Excess lines can be removed from the start or end of the Document depending on your requirement.
12 | *
13 | * a) if you append text to the Document, then you would want to remove lines from the start. b) if you insert
14 | * text at the beginning of the Document, then you would want to remove lines from the end.
15 | */
16 | public class LimitLinesDocumentListener implements DocumentListener {
17 |
18 | private int maximumLines;
19 | private boolean isRemoveFromStart;
20 |
21 | /*
22 | * Specify the number of lines to be stored in the Document. Extra lines will be removed from the start of
23 | * the Document.
24 | */
25 | public LimitLinesDocumentListener(int maximumLines) {
26 | this(maximumLines, true);
27 | }
28 |
29 | /*
30 | * Specify the number of lines to be stored in the Document. Extra lines will be removed from the start or
31 | * end of the Document, depending on the boolean value specified.
32 | */
33 | public LimitLinesDocumentListener(int maximumLines, boolean isRemoveFromStart) {
34 | setLimitLines(maximumLines);
35 | this.isRemoveFromStart = isRemoveFromStart;
36 | }
37 |
38 | /*
39 | * Return the maximum number of lines to be stored in the Document
40 | */
41 | public int getLimitLines() {
42 | return maximumLines;
43 | }
44 |
45 | /*
46 | * Set the maximum number of lines to be stored in the Document
47 | */
48 | public void setLimitLines(int maximumLines) {
49 | if (maximumLines < 1) {
50 | String message = "Maximum lines must be greater than 0";
51 | throw new IllegalArgumentException(message);
52 | }
53 |
54 | this.maximumLines = maximumLines;
55 | }
56 |
57 | // Handle insertion of new text into the Document
58 | public void insertUpdate(final DocumentEvent e) {
59 | // Changes to the Document can not be done within the listener
60 | // so we need to add the processing to the end of the EDT
61 |
62 | SwingUtilities.invokeLater(new Runnable() {
63 |
64 | public void run() {
65 | removeLines(e);
66 | }
67 | });
68 | }
69 |
70 | public void removeUpdate(DocumentEvent e) {
71 | }
72 |
73 | public void changedUpdate(DocumentEvent e) {
74 | }
75 |
76 | /*
77 | * Remove lines from the Document when necessary
78 | */
79 | private void removeLines(DocumentEvent e) {
80 | // The root Element of the Document will tell us the total number
81 | // of line in the Document.
82 |
83 | Document document = e.getDocument();
84 | Element root = document.getDefaultRootElement();
85 |
86 | while (root.getElementCount() > maximumLines) {
87 | if (isRemoveFromStart) {
88 | removeFromStart(document, root);
89 | } else {
90 | removeFromEnd(document, root);
91 | }
92 | }
93 | }
94 |
95 | /*
96 | * Remove lines from the start of the Document
97 | */
98 | private void removeFromStart(Document document, Element root) {
99 | Element line = root.getElement(0);
100 | int end = line.getEndOffset();
101 |
102 | try {
103 | document.remove(0, end);
104 | } catch (BadLocationException ble) {
105 | System.out.println(ble);
106 | }
107 | }
108 |
109 | /*
110 | * Remove lines from the end of the Document
111 | */
112 | private void removeFromEnd(Document document, Element root) {
113 | // We use start minus 1 to make sure we remove the newline
114 | // character of the previous line
115 |
116 | Element line = root.getElement(root.getElementCount() - 1);
117 | int start = line.getStartOffset();
118 | int end = line.getEndOffset();
119 |
120 | try {
121 | document.remove(start - 1, end - start);
122 | } catch (BadLocationException ble) {
123 | System.out.println(ble);
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/src/com/kentcdodds/javahelper/helpers/StringFormatHelper.java:
--------------------------------------------------------------------------------
1 | package com.kentcdodds.javahelper.helpers;
2 |
3 | /**
4 | *
5 | * @author Kent
6 | */
7 | public class StringFormatHelper {
8 |
9 | /**
10 | * Exact code: String fixedNumber = cleanNumber(number).replace(".", ""); return
11 | * StringHelper.insertIntoString(fixedNumber, char0, "", "", char3, "", "", char6);
12 | *
13 | * @param number
14 | * @param char0
15 | * @param char3
16 | * @param char6
17 | * @return
18 | */
19 | public static String formatPhoneNumber(String number, String char0, String char3, String char6) {
20 | String fixedNumber = NumberHelper.cleanNumber(number).replace(".", "");
21 | return StringHelper.insertIntoString(fixedNumber, char0, "", "", char3, "", "", char6);
22 | }
23 |
24 | /**
25 | * Returns: formatPhoneNumber(number, "(", ") ", "-") which formats a number to look like this: (555)
26 | * 123-4567. Note: If you give too many numbers they'll just be added to the end of the number. Like this
27 | * (555) 123-456789101112
28 | *
29 | * @param number
30 | * @return formatted phone number
31 | */
32 | public static String formatPhoneNumber(String number) {
33 | return formatPhoneNumber(number, "(", ") ", "-");
34 | }
35 |
36 | /**
37 | * If the call was formatCreditCard("1234567812345678", "-") the result would be: 1234-5678-1234-5678. This
38 | * will continue if you give too long or too short of a number. If you give 12345, the result will be:
39 | * 1234-5. If you give 12345678123456789, it will return 1234-5678-1234-5678-9. NOTE: Also first calls
40 | * NumberHelper.cleanNumber(creditCard).replace(".", "");
41 | *
42 | * @param creditCard the number string to format like a credit card number
43 | * @param separator the item to put between every 4 numbers
44 | * @return formatted credit card
45 | */
46 | public static String formatCreditCard(String creditCard, String separator) {
47 | String fixedCreditCard = NumberHelper.cleanNumber(creditCard).replace(".", "");
48 | char[] numbers = fixedCreditCard.toCharArray();
49 | //1234567812345678
50 | StringBuilder sb = new StringBuilder();
51 | for (int i = 0; i < numbers.length; i++) {
52 | if (i % 4 == 0 && i > 0) {
53 | sb.append(separator);
54 | }
55 | sb.append(numbers[i]);
56 | }
57 | return sb.toString();
58 | }
59 |
60 | /**
61 | * This is posting something in a URL. It replaces anything in the string given with percentEncoded values
62 | *
63 | * @param originalString
64 | * @return
65 | */
66 | public static String percentEncodeString(String originalString) {
67 | //It is important that % is first, if you put it any later it will replace % with anything that's replace before.
68 | //Try it, you'll see what I mean.
69 | java.util.Map replaceMap = new java.util.TreeMap<>();
70 | //
71 | replaceMap.put('%', "%25");
72 | replaceMap.put('!', "%21");
73 | replaceMap.put('*', "%2A");
74 | replaceMap.put('\'', "%27"); //Escape character. This value is: '
75 | replaceMap.put('(', "%28");
76 | replaceMap.put(')', "%29");
77 | replaceMap.put(';', "%3B");
78 | replaceMap.put(':', "%3A");
79 | replaceMap.put('@', "%40");
80 | replaceMap.put('&', "%26");
81 | replaceMap.put('=', "%3D");
82 | replaceMap.put('+', "%2B");
83 | replaceMap.put('$', "%24");
84 | replaceMap.put(',', "%2C");
85 | replaceMap.put('/', "%2F");
86 | replaceMap.put('?', "%3F");
87 | replaceMap.put('#', "%23");
88 | replaceMap.put('[', "%5B");
89 | replaceMap.put(']', "%5D");
90 | replaceMap.put(' ', "%20");
91 | //
92 | char[] charArry = originalString.toCharArray();
93 | StringBuilder fixedString = new StringBuilder();
94 | for (int i = 0; i < charArry.length; i++) {
95 | Character c = charArry[i];
96 | String replacement = replaceMap.get(c);
97 | if (replacement != null) {
98 | fixedString.append(replacement);
99 | } else {
100 | fixedString.append(c);
101 | }
102 | }
103 | return fixedString.toString();
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | This project has been moved to BitBucket.org: https://bitbucket.org/kentcdodds/java-helper-library/overview
2 |
3 | The Java Helper Library is library of classes containing helpful methods I've found useful. I'm constantly developing on it because I'm constantly finding helpful things I use all the time when I code. I would love input from anyone who finds something that could be improved. Please let me know if you find this useful (it would really make my day). I'm super open to people contributing to this project. Please feel free to e-mail me at me@kentcdodds.com. Thanks.
4 |
5 | Notable helpful classes/methods:
6 | -IOHelper: This has Methods which make it easy to make sure a filename is filename safe (doesn't include illegal characters). There are methods to copy a resource to a file, file to a file, get the byte array of a file, get the file or resource into a String, zipping and unzipping files (in memory as well), and much more! It leverages the HelperFile to handle files in memory, so if you have files you don't want to actually save to disk, but would still like to treat as files, this can be a great help.
7 | -EmailHelper: sendEmail(service, username, password, email) is really helpful for sending e-mails with minimal code. The model package has helper classes like Email and HelperFile which allow you to send attachments even if the file itself is in memory. Support for Google, Yahoo, and Windows Live email sessions as well as the option of giving your own session with sendEmail(session, email).
8 | -StringHelper: Lots of helpful methods for manipulating strings. Have you wanted to shorten a string and add the "..." somewhere in the middle? What about wrapping a bunch of text by adding a newline after a given number of characters? Or, one of my favorites, have you wanted to split an array or list of words by a comma? It's so annoying, but this makes it really easy! Take a look. It's really helpful.
9 | -SwingHelper: Helpful methods dealing with Swing components. Center a window, resize an image, easily call a file opener/saver or a folder chooser for user interaction, work with JOptionPanes easily, and even get a window of an image (helpful for progress wheels).
10 | -NumberHelper: Ever needed to check whether input from a user is a valid number? This helper has a helpful method for that. It also helps with rounding, getting a percentage, and cleaning a number string of all non-numeric characters.
11 | -DateHelper: Difference between two dates (absolute and relative)
12 | -RandomHelper: This is mostly helpful for debugging purposes. It will generate anything from random names to random MAC addresses. Take a look. There's a lot available. If you think of anything more, let me know with an issue or contribute it yourself.
13 | -ReflectionHelper: This is good for looking into your program. You can see if an object has any fields which match a given string or print out the object and it's attributes in a logical way.
14 | -OtherHelper: Have two lists and need to remove the contents of one list from the contents of another list? Need to check whether a list or array has any null values? These methods have yet to be classified, so they're still in the OtherHelper class, but they have proven to be helpful for me.
15 | -PrinterHelper: This is helpful for debugging. Basically, the way it works is instead of Systm.out.println(), you use PrinterHelper.print() and it will only print if you've already specified PrinterHelper.setInstancePrint(true) before it's called. There's also a helpful option to open a log window where they will all be printed (this uses code from http://tips4java.wordpress.com/2008/11/08/message-console/)
16 | -StringFormatHelper: Helps you format strings like phone numbers, credit cards, and much more.
17 | -XMLHelper: Helpful methods for the XML Dom library. Create an XML document out of an xml string, transform a document into an xml string, and create an empty XML document.
18 |
19 | I'm hoping to develop this a great deal more. I welcome any (kind) input. Important: I'm not a developer with endless years of experience or anything so forgive me if some things are less than perfect. If you find something that falls short of that goal, please submit an issue and I'll look into improving it (or fork this repo and improve it yourself). Thanks!
20 |
21 | -Kent Dodds
--------------------------------------------------------------------------------
/dist/javadoc/allclasses-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | All Classes
8 |
9 |
10 |
11 |
12 |