Mercurial > hg > jslab
view src/samer/core_/util/heavy/JPanel.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line source
/* * JPanel.java * * Copyright (c) 2000, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.core.util.heavy; import samer.core.*; import samer.core.util.*; import java.awt.*; import java.awt.event.*; /** * This is a panel with an optional bevel border, * and a name label. It can also draw bevels * round its children */ public class JPanel extends Panel { private Border.Interface cborder=null; private Border.Interface border=null; /** Constructors can specify bevel type, inset and name */ public JPanel() { this(Border.createDefault()); } public JPanel(Border.Interface border) { setLayout(new FlowLayout(FlowLayout.LEFT,0,0)); addMouseListener(MouseRetarget.listener); this.border = border; } public Insets getInsets() { return border.getBorderInsets(this); } public void setBorder( Border.Interface b) { border=b; } public void setChildBorder( Border.Interface b) { cborder=b; } public void paint(Graphics g) { super.paint(g); if (border!=null) { Dimension d=getSize(); border.paintBorder(this,g,0,0,d.width,d.height); } if (cborder!=null) { Component [] c=getComponents(); Insets insets=cborder.getBorderInsets(this); int dx=insets.left, dy=insets.top; int dw=insets.left+insets.right; int dh=insets.top+insets.bottom; for (int i=c.length-1; i>=0; i--) { Rectangle r=c[i].getBounds(); if (!r.isEmpty()) { cborder.paintBorder( c[i], g, r.x-dx, r.y-dy, r.width+dw, r.height+dh ); } } } } }