// Path: src/org/sleeksnap/util/StreamUtils.java
// public class StreamUtils {
// 
// 	/**
// 	 * Read all of the data from an InputStream into a string
// 	 * @param inputStream
// 	 * 			The stream to read from
// 	 * @return
// 	 * 			The data, lines separated by \n
// 	 * @throws IOException
// 	 * 			If a problem occurred while reading
// 	 */
// 	public static String readContents(InputStream inputStream)
// 			throws IOException {
// 		StringBuilder contents = new StringBuilder();
// 		BufferedReader reader = new BufferedReader(new InputStreamReader(
// 				inputStream));
// 		try {
// 			String line;
// 			while ((line = reader.readLine()) != null) {
// 				contents.append(line).append("\n");
// 			}
// 		} finally {
// 			reader.close();
// 		}
// 		return contents.toString().trim();
// 	}
// 	
// 	public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
// 		int read;
// 		byte[] buf = new byte[1024];
// 		while((read = inputStream.read(buf, 0, buf.length)) != -1) {
// 			outputStream.write(buf, 0, read);
// 		}
// 	}
// }
// 
// Path: src/org/sleeksnap/util/active/ActiveWindow.java
// public class ActiveWindow {
// 	
// 	/**
// 	 * The window name
// 	 */
// 	private String name;
// 
// 	/**
// 	 * The window's bounds
// 	 */
// 	private Rectangle bounds;
// 
// 	public ActiveWindow(String name, Rectangle bounds) {
// 		this.name = name;
// 		this.bounds = bounds;
// 	}
// 
// 	/**
// 	 * Get the window's bounds as a rectangle
// 	 * @return
// 	 * 		A rectangle containing the window's bounds
// 	 */
// 	public Rectangle getBounds() {
// 		return bounds;
// 	}
// 
// 	/**
// 	 * Get the window name
// 	 * @return
// 	 * 		The window name
// 	 */
// 	public String getName() {
// 		return name;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return name + " [x=" + bounds.x + ",y=" + bounds.y + ",width="
// 				+ bounds.width + ",height=" + bounds.height + "]";
// 	}
// }
// 
// Path: src/org/sleeksnap/util/active/WindowUtil.java
// public interface WindowUtil {
// 
// 	/**
// 	 * Get the active window
// 	 * 
// 	 * @return The active desktop window
// 	 * @throws Exception
// 	 *             If we failed to get the window
// 	 */
// 	public ActiveWindow getActiveWindow() throws Exception;
// }


import java.awt.Rectangle;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.sleeksnap.util.StreamUtils;
import org.sleeksnap.util.active.ActiveWindow;
import org.sleeksnap.util.active.WindowUtil;
/**
 * Sleeksnap, the open source cross-platform screenshot uploader
 * Copyright (C) 2012 Nikki <nikki@nikkii.us>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.sleeksnap.util.active.linux;



/**
 * A WindowUtil that uses xprop/xwininfo to get the active window bounds. Note:
 * This does not include the title bar, which is why GnomeWindowUtil is
 * preferred... However, GnomeWindowUtil does not have the actual window title,
 * however it is currently not used.
 * 
 * @author Nikki
 * 
 */
public class XPropWindowUtil implements WindowUtil {

	/**
	 * The pattern to match width/height variables
	 */
	private static Pattern pattern = Pattern
			.compile("Width:\\s*(\\d+)\\s*Height:\\s*(\\d+)");

	/**
	 * The pattern to match the window location (Does not include title bar)
	 */
	private static Pattern locationPattern = Pattern
			.compile("Absolute upper-left X:\\s*(\\d+)\\s*Absolute upper-left Y:\\s*(\\d+)");

	/**
	 * The pattern to match the window name
	 */
	private static Pattern namePattern = Pattern
			.compile("xwininfo\\: Window id\\: .*? \"(.*?)\"");

	/**
	 * The pattern to match the window id from the xprop -root command
	 */
	private static Pattern windowid = Pattern
			.compile("_NET_ACTIVE_WINDOW\\(WINDOW\\): window id # (.*)");

	@Override
// Path: src/org/sleeksnap/util/StreamUtils.java
// public class StreamUtils {
// 
// 	/**
// 	 * Read all of the data from an InputStream into a string
// 	 * @param inputStream
// 	 * 			The stream to read from
// 	 * @return
// 	 * 			The data, lines separated by \n
// 	 * @throws IOException
// 	 * 			If a problem occurred while reading
// 	 */
// 	public static String readContents(InputStream inputStream)
// 			throws IOException {
// 		StringBuilder contents = new StringBuilder();
// 		BufferedReader reader = new BufferedReader(new InputStreamReader(
// 				inputStream));
// 		try {
// 			String line;
// 			while ((line = reader.readLine()) != null) {
// 				contents.append(line).append("\n");
// 			}
// 		} finally {
// 			reader.close();
// 		}
// 		return contents.toString().trim();
// 	}
// 	
// 	public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
// 		int read;
// 		byte[] buf = new byte[1024];
// 		while((read = inputStream.read(buf, 0, buf.length)) != -1) {
// 			outputStream.write(buf, 0, read);
// 		}
// 	}
// }
// 
// Path: src/org/sleeksnap/util/active/ActiveWindow.java
// public class ActiveWindow {
// 	
// 	/**
// 	 * The window name
// 	 */
// 	private String name;
// 
// 	/**
// 	 * The window's bounds
// 	 */
// 	private Rectangle bounds;
// 
// 	public ActiveWindow(String name, Rectangle bounds) {
// 		this.name = name;
// 		this.bounds = bounds;
// 	}
// 
// 	/**
// 	 * Get the window's bounds as a rectangle
// 	 * @return
// 	 * 		A rectangle containing the window's bounds
// 	 */
// 	public Rectangle getBounds() {
// 		return bounds;
// 	}
// 
// 	/**
// 	 * Get the window name
// 	 * @return
// 	 * 		The window name
// 	 */
// 	public String getName() {
// 		return name;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return name + " [x=" + bounds.x + ",y=" + bounds.y + ",width="
// 				+ bounds.width + ",height=" + bounds.height + "]";
// 	}
// }
// 
// Path: src/org/sleeksnap/util/active/WindowUtil.java
// public interface WindowUtil {
// 
// 	/**
// 	 * Get the active window
// 	 * 
// 	 * @return The active desktop window
// 	 * @throws Exception
// 	 *             If we failed to get the window
// 	 */
// 	public ActiveWindow getActiveWindow() throws Exception;
// }


// Path: src/org/sleeksnap/util/active/linux/XPropWindowUtil.java
import java.awt.Rectangle;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.sleeksnap.util.StreamUtils;
import org.sleeksnap.util.active.ActiveWindow;
import org.sleeksnap.util.active.WindowUtil;

/**
 * Sleeksnap, the open source cross-platform screenshot uploader
 * Copyright (C) 2012 Nikki <nikki@nikkii.us>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.sleeksnap.util.active.linux;



/**
 * A WindowUtil that uses xprop/xwininfo to get the active window bounds. Note:
 * This does not include the title bar, which is why GnomeWindowUtil is
 * preferred... However, GnomeWindowUtil does not have the actual window title,
 * however it is currently not used.
 * 
 * @author Nikki
 * 
 */
public class XPropWindowUtil implements WindowUtil {

	/**
	 * The pattern to match width/height variables
	 */
	private static Pattern pattern = Pattern
			.compile("Width:\\s*(\\d+)\\s*Height:\\s*(\\d+)");

	/**
	 * The pattern to match the window location (Does not include title bar)
	 */
	private static Pattern locationPattern = Pattern
			.compile("Absolute upper-left X:\\s*(\\d+)\\s*Absolute upper-left Y:\\s*(\\d+)");

	/**
	 * The pattern to match the window name
	 */
	private static Pattern namePattern = Pattern
			.compile("xwininfo\\: Window id\\: .*? \"(.*?)\"");

	/**
	 * The pattern to match the window id from the xprop -root command
	 */
	private static Pattern windowid = Pattern
			.compile("_NET_ACTIVE_WINDOW\\(WINDOW\\): window id # (.*)");

	@Override
	public ActiveWindow getActiveWindow() throws Exception {