public static List<Integer> getBracketGroups(JTextPane tp) {
		int groupNumber = 0;
		List<Integer> groupsTmp = new ArrayList<Integer>();
		List<Integer[]> groupsPos = new ArrayList<Integer[]>();
		List<Integer> output = new ArrayList<Integer>();

		int caretPos = tp.getCaretPosition();

		try {

			for (int i = 0; i < tp.getText().length(); i++) {
				char tempChar = tp.getText().charAt(i);
				if (tempChar == "(".charAt(0)) { // if open
					groupsTmp.add(groupNumber);
					Integer[] tmpPos = new Integer[2];
					tmpPos[0] = Integer.valueOf(i);
					groupsPos.add(tmpPos);
					groupNumber++;
				}
				if (tempChar == ")".charAt(0)) { // if close
					int tmpGroupNumber = groupsTmp.get(groupsTmp.size() - 1);
					Integer[] tmpPos = groupsPos.get(tmpGroupNumber);
					tmpPos[1] = Integer.valueOf(i);
					groupsPos.set(tmpGroupNumber, tmpPos);
					groupsTmp.remove(groupsTmp.size() - 1);
				}
			}

			groupsTmp = null;
			groupNumber = 0;

			for (Integer[] tmpPos : groupsPos) {
				if (caretPos >= tmpPos[0] && caretPos <= tmpPos[1]) {
					output.clear();
					output.add(0, tmpPos[0]);
					output.add(1, tmpPos[1]);
				}
			}

			return output;
		} catch (NullPointerException e) {
			return null;
		} catch (ArrayIndexOutOfBoundsException e) {
			return null;
		}
	}