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

javajs.swing.JSplitPane Maven / Gradle / Ivy

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

import javajs.awt.Container;
import javajs.util.SB;

public class JSplitPane extends JComponent {

	public static final int HORIZONTAL_SPLIT = 1;
	boolean isH = true;
	private int split = 1;
	private Container right;
	private Container left;

	public JSplitPane(int split) {
		super("JSpP");
		this.split = split;
		isH = (split == HORIZONTAL_SPLIT);
	}
	
	public void setRightComponent(JComponent r) {
		right = new JComponentImp(null);
		right.add(r); 
	}

	public void setLeftComponent(JComponent l) {
		left = new JComponentImp(null);
		left.add(l);
	}

	@Override
	public int getSubcomponentWidth() {
		int w = this.width;
		if (w == 0) {
			int wleft = left.getSubcomponentWidth();
			int wright = right.getSubcomponentWidth();
			if (wleft > 0 && wright > 0) {
				if (isH)
					w = wleft + wright;
				else
					w = Math.max(wleft, wright);
			}
		}
		return w;
	}
	
	@Override
	public int getSubcomponentHeight() {
		int h = this.height;
		if (h == 0) {
			int hleft = left.getSubcomponentHeight();
			int hright = right.getSubcomponentHeight();
			if (hleft > 0 && hright > 0) {
				if (isH)
					h = Math.max(hleft, hright);
				else
					h = hleft + hright;
			}
		}
		return h;
	}
	
	@Override
	public String toHTML() {
		if (left == null || right == null)
			return "";
		boolean isH = (split == HORIZONTAL_SPLIT);
		if (width == 0)
		  width = getSubcomponentWidth();
		if (height == 0)
		  height = getSubcomponentHeight();
		SB sb = new SB();
		sb.append("
"); if (isH) sb.append("
"); else sb.append("
"); sb.append(left.getComponents()[0].toHTML()); if (isH) sb.append("
"); else sb.append("
"); sb.append(right.getComponents()[0].toHTML()); sb.append("
\n"); return sb.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy