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

javajs.swing.JPanel Maven / Gradle / Ivy

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

import javajs.awt.BorderLayout;
import javajs.awt.LayoutManager;
import javajs.util.SB;

public class JPanel extends JComponent {

	//private LayoutManager layoutManager;

	private Grid grid;

	private int nElements;
	private JComponent last;
	
	
	/**
	 * @param manager  ignored. we just use the layout designations with a grid
	 */
	public JPanel(LayoutManager manager) {
		super("JP");
		//this.layoutManager = manager;
		grid = new Grid(10,10);
	}

	public void add(JComponent btn, Object c) {
		last = (++nElements == 1 ? btn : null);
		if (c instanceof String) {
			if (c.equals(BorderLayout.NORTH))
				c = new GridBagConstraints(0, 0, 3, 1, 0, 0, GridBagConstraints.CENTER,
						0, null, 0, 0);
			else if (c.equals(BorderLayout.SOUTH))
				c = new GridBagConstraints(0, 2, 3, 1, 0, 0, GridBagConstraints.CENTER,
						0, null, 0, 0);
			else if (c.equals(BorderLayout.EAST))
				c = new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.EAST,
						0, null, 0, 0);
			else if (c.equals(BorderLayout.WEST))
				c = new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST,
						0, null, 0, 0);
			else
				c = new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.CENTER,
						0, null, 0, 0);
		}
		grid.add(btn, (GridBagConstraints) c);
	}
	
	@Override
	public String toHTML() {
		if (last != null) {
			// only one element
			grid = new Grid(1, 1);
			grid.add(last, new GridBagConstraints(0, 0, 1, 1, 0, 0,
					GridBagConstraints.CENTER, 0, null, 0, 0));
			last = null;
		}
		SB sb = new SB();
		sb.append("\n
\n"); sb.append("\n"); sb.append(grid.toHTML(id)); sb.append(""); sb.append("\n
\n"); return sb.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy