All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javajs.swing.Grid Maven / Gradle / Ivy

There is a newer version: 14.31.10
Show newest version
package javajs.swing;

import javajs.util.AU;
import javajs.util.SB;


public class Grid {

	private int nrows;
	private int ncols;

	private Cell[][] grid;
	private String renderer;
	

	Grid(int rows, int cols) {
		grid = new Cell[0][0];
	}

	public void add(JComponent btn, GridBagConstraints c) {
		if (c.gridx >= ncols) {
			ncols = c.gridx + 1;
			for (int i = 0; i < nrows; i++) {
				grid[i] = (Cell[]) AU.ensureLength(grid[i], ncols * 2);
			}
		}
		if (c.gridy >= nrows) {
			Cell[][] g = new Cell[c.gridy * 2 + 1][];
			for (int i = 0; i < nrows; i++)
				g[i] = grid[i];
			for (int i = g.length; --i >= nrows;)
				g[i] = new Cell[ncols * 2 + 1];
			grid = g;
			nrows = c.gridy + 1;
		}
		grid[c.gridy][c.gridx] = new Cell(btn, c);
	}

	public String toHTML(String id) {
		SB sb = new SB();
		id += "_grid";
		sb.append("\n");		
		for (int i = 0; i < nrows; i++) {
			String rowid = id + "_" + i;
			sb.append("\n");
			for (int j = 0; j < ncols; j++)
				if (grid[i][j] != null)
					sb.append(grid[i][j].toHTML(rowid + "_" + j));
			sb.append("");
		}
		sb.append("\n
\n"); return sb.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy