Code Search for Developers
 
 
  

WootPage.java from PeerWriter at Krugle


Show WootPage.java syntax highlighted

package fr.loria.ecoo.wooki.woot.core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 
 * @author nabil
 */
public class WootPage implements Serializable {
	private List<WootRow> rows = new ArrayList<WootRow>();

	// private String directoryPath;
	private String pageName;// file name

	// private String id;

	private String title;

	// constructor
	public WootPage(boolean b) {
		if (b) {
			getRows().add(WootRow.RB);
			getRows().add(WootRow.RE);
		}
	}

	// methods
	public int indexOf(WootRow wr) {
		boolean b = this.contains(wr);
		return getRows().indexOf(wr) - 1;

	}

	public int indexOfVisibleNext(int from) {
		int n = rows.size();
		if ((from < 0) || (from >= n))
			return -1;
		for (int i = from + 1; i < n; ++i)
			if (rows.get(i).isVisible())
				return i;
		return -1;
	}

	public int indexOfVisible(int index) {
		if (index >= getRows().size() || index < 0)
			return -1;
		int count = 0, j = 0;
		for (WootRow r : rows) {
			if (r.isVisible()) {
				// count++;
				if (count == index)
					return j;
				count++;
			}
			j++;
		}
		return -1;
	}

	public int indexOfIdFrom(int from, WootId id) {
		for (int i = from + 1; i < rows.size(); ++i)
			if (rows.get(i).getWootId().equals(id))
				return i;
		return -1;
	}

	public int indexOfId(WootId id) {
		int i = 0;
		for (WootRow r : rows)
			if (r.getWootId().equals(id))
				return i;
			else
				++i;
		return -1;
	}

	public void insert(WootRow wr, int pos) {
		rows.add(pos + 1, wr);
	}

	public boolean contains(WootRow wr) {
		return rows.contains(wr);
	}

	public boolean containsById(WootId id) {
		return indexOfId(id) >= 0;
	}

	public WootRow elementAt(int i) {
		return rows.get(i);
	}

	public int size() {
		return rows.size() - 2;
	}

	public boolean isEmpty() {
		return size() == 0;
	}

	public boolean equals(Object o) {
		// assert o instanceof WootPage;
		return (o instanceof WootPage) && ((WootPage) o).pageName.equals(this.pageName) && ((WootPage) o).rows.equals(this.rows);
	}

	// public List subSeq(WootRow b, WootRow e) {
	// if ((!getRows().contains(b)) || (!getRows().contains(e))) {
	// return new ArrayList();
	// }
	// int ib = getRows().indexOf(b) + 1;
	// int ie = getRows().indexOf(e);
	// if (ib > ie)
	// return new ArrayList();
	// return getRows().subList(ib, ie);
	// }

	// public Vector getInterval(WootRow r, WootRow rp, WootRow rn) {
	// Vector res = new Vector();
	// if (!rp.getValue().equals(WootRow.RB.getValue())) {
	// res.add(ObjectCloner.deepCopy(rp));
	// }
	// for (int i = this.indexOf(rp); i < this.indexOf(rn); i++) {
	// WootRow wr = (WootRow) this.elementAt(i);
	// if (wr.getWootId().compareTo(r.getWootId()) < 0) {
	// res.add(ObjectCloner.deepCopy(wr));
	// }
	// }
	// if (!rn.getValue().equals(WootRow.RE.getValue())) {
	// res.add(ObjectCloner.deepCopy(rn));
	// }
	// return res;
	// }

	public String toString() {
		StringBuffer sb = new StringBuffer();
		Iterator i = getRows().iterator();
		while (i.hasNext()) {
			WootRow r = (WootRow) i.next();
			sb.append(r.getValue());
		}
		return sb.toString();
	}

	/*
	 * public WootRow getR(int pos) { if (pos == 0) { return WootRow.RB; }
	 * 
	 * int nb = 0; for (int i = 0; i < this.size(); i++) { WootRow res; if ((res =
	 * this.elementAt(i)).isVisible()) { nb++; } if (nb == pos) { return res; } }
	 * return WootRow.RE; }
	 */

	public String toHumanString() {
		StringBuffer sb = new StringBuffer();
		for (int i = 1; i < this.rows.size() - 1; i++) {
			WootRow r = (WootRow) this.rows.get(i);
			if (r.isVisible()) {
				sb.append(r.getValue());
				sb.append("\n");
			}
		}
		return sb.toString();
	}

	public String toStringInternal() {
		StringBuffer sbfull = new StringBuffer();
		for (WootRow r : rows)
			sbfull.append(r.toString());
		return sbfull.toString();
	}

	public String getPageName() {
		return pageName;
	}

	public void setPageName(String pageName) {
		this.pageName = pageName;
	}

	/*
	 * public String getId() { return id; }
	 * 
	 * public void setId(String id) { this.id = id; }
	 */
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public List<WootRow> getRows() {
		return rows;
	}

	public void setRows(List<WootRow> rows) {
		this.rows = rows;
	}

}




See more files for this project here

PeerWriter

PeerWriter is a collaborative text editor. Multiple peers can edit the same document while they see overall changes in real-time. PeerWriter is based on a decentralized infrastructure, using a non-locking concurrency protocol ensuring global consistency.

Project homepage: http://sourceforge.net/projects/peerwriter
Programming language(s): Java,XML
License: gpl2

  Pool.java
  WootId.java
  WootPage.java
  WootRow.java