Methods Summary |
---|
public void | addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)Adds the specified component to this card layout's internal
table of names. The object specified by constraints
must be a string. The card layout stores this string as a key-value
pair that can be used for random access to a particular card.
By calling the show method, an application can
display the component with the specified name.
synchronized (comp.getTreeLock()) {
if (constraints instanceof String) {
addLayoutComponent((String)constraints, comp);
} else {
throw new IllegalArgumentException("cannot add to layout: constraint must be a string");
}
}
|
public void | addLayoutComponent(java.lang.String name, java.awt.Component comp)
synchronized (comp.getTreeLock()) {
if (!vector.isEmpty()) {
comp.setVisible(false);
}
for (int i=0; i < vector.size(); i++) {
if (((Card)vector.get(i)).name.equals(name)) {
((Card)vector.get(i)).comp = comp;
return;
}
}
vector.add(new Card(name, comp));
}
|
void | checkLayout(java.awt.Container parent)Make sure that the Container really has a CardLayout installed.
Otherwise havoc can ensue!
if (parent.getLayout() != this) {
throw new IllegalArgumentException("wrong parent for CardLayout");
}
|
public void | first(java.awt.Container parent)Flips to the first card of the container.
synchronized (parent.getTreeLock()) {
checkLayout(parent);
int ncomponents = parent.getComponentCount();
for (int i = 0 ; i < ncomponents ; i++) {
Component comp = parent.getComponent(i);
if (comp.isVisible()) {
comp.setVisible(false);
break;
}
}
if (ncomponents > 0) {
currentCard = 0;
parent.getComponent(0).setVisible(true);
parent.validate();
}
}
|
public int | getHgap()Gets the horizontal gap between components.
return hgap;
|
public float | getLayoutAlignmentX(java.awt.Container parent)Returns the alignment along the x axis. This specifies how
the component would like to be aligned relative to other
components. The value should be a number between 0 and 1
where 0 represents alignment along the origin, 1 is aligned
the furthest away from the origin, 0.5 is centered, etc.
return 0.5f;
|
public float | getLayoutAlignmentY(java.awt.Container parent)Returns the alignment along the y axis. This specifies how
the component would like to be aligned relative to other
components. The value should be a number between 0 and 1
where 0 represents alignment along the origin, 1 is aligned
the furthest away from the origin, 0.5 is centered, etc.
return 0.5f;
|
public int | getVgap()Gets the vertical gap between components.
return vgap;
|
public void | invalidateLayout(java.awt.Container target)Invalidates the layout, indicating that if the layout manager
has cached information it should be discarded.
|
public void | last(java.awt.Container parent)Flips to the last card of the container.
synchronized (parent.getTreeLock()) {
checkLayout(parent);
int ncomponents = parent.getComponentCount();
for (int i = 0 ; i < ncomponents ; i++) {
Component comp = parent.getComponent(i);
if (comp.isVisible()) {
comp.setVisible(false);
break;
}
}
if (ncomponents > 0) {
currentCard = ncomponents - 1;
parent.getComponent(currentCard).setVisible(true);
parent.validate();
}
}
|
public void | layoutContainer(java.awt.Container parent)Lays out the specified container using this card layout.
Each component in the parent container is reshaped
to be the size of the container, minus space for surrounding
insets, horizontal gaps, and vertical gaps.
synchronized (parent.getTreeLock()) {
Insets insets = parent.getInsets();
int ncomponents = parent.getComponentCount();
Component comp = null;
boolean currentFound = false;
for (int i = 0 ; i < ncomponents ; i++) {
comp = parent.getComponent(i);
comp.setBounds(hgap + insets.left, vgap + insets.top,
parent.width - (hgap*2 + insets.left + insets.right),
parent.height - (vgap*2 + insets.top + insets.bottom));
if (comp.isVisible()) {
currentFound = true;
}
}
if (!currentFound && ncomponents > 0) {
parent.getComponent(0).setVisible(true);
}
}
|
public java.awt.Dimension | maximumLayoutSize(java.awt.Container target)Returns the maximum dimensions for this layout given the components
in the specified target container.
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
public java.awt.Dimension | minimumLayoutSize(java.awt.Container parent)Calculates the minimum size for the specified panel.
synchronized (parent.getTreeLock()) {
Insets insets = parent.getInsets();
int ncomponents = parent.getComponentCount();
int w = 0;
int h = 0;
for (int i = 0 ; i < ncomponents ; i++) {
Component comp = parent.getComponent(i);
Dimension d = comp.getMinimumSize();
if (d.width > w) {
w = d.width;
}
if (d.height > h) {
h = d.height;
}
}
return new Dimension(insets.left + insets.right + w + hgap*2,
insets.top + insets.bottom + h + vgap*2);
}
|
public void | next(java.awt.Container parent)Flips to the next card of the specified container. If the
currently visible card is the last one, this method flips to the
first card in the layout.
synchronized (parent.getTreeLock()) {
checkLayout(parent);
int ncomponents = parent.getComponentCount();
for (int i = 0 ; i < ncomponents ; i++) {
Component comp = parent.getComponent(i);
if (comp.isVisible()) {
comp.setVisible(false);
currentCard = (i + 1) % ncomponents;
comp = parent.getComponent(currentCard);
comp.setVisible(true);
parent.validate();
return;
}
}
showDefaultComponent(parent);
}
|
public java.awt.Dimension | preferredLayoutSize(java.awt.Container parent)Determines the preferred size of the container argument using
this card layout.
synchronized (parent.getTreeLock()) {
Insets insets = parent.getInsets();
int ncomponents = parent.getComponentCount();
int w = 0;
int h = 0;
for (int i = 0 ; i < ncomponents ; i++) {
Component comp = parent.getComponent(i);
Dimension d = comp.getPreferredSize();
if (d.width > w) {
w = d.width;
}
if (d.height > h) {
h = d.height;
}
}
return new Dimension(insets.left + insets.right + w + hgap*2,
insets.top + insets.bottom + h + vgap*2);
}
|
public void | previous(java.awt.Container parent)Flips to the previous card of the specified container. If the
currently visible card is the first one, this method flips to the
last card in the layout.
synchronized (parent.getTreeLock()) {
checkLayout(parent);
int ncomponents = parent.getComponentCount();
for (int i = 0 ; i < ncomponents ; i++) {
Component comp = parent.getComponent(i);
if (comp.isVisible()) {
comp.setVisible(false);
currentCard = ((i > 0) ? i-1 : ncomponents-1);
comp = parent.getComponent(currentCard);
comp.setVisible(true);
parent.validate();
return;
}
}
showDefaultComponent(parent);
}
|
private void | readObject(java.io.ObjectInputStream s)Reads serializable fields from stream.
ObjectInputStream.GetField f = s.readFields();
hgap = f.get("hgap", 0);
vgap = f.get("vgap", 0);
if (f.defaulted("vector")) {
// pre-1.4 stream
Hashtable tab = (Hashtable)f.get("tab", null);
vector = new Vector();
if (tab != null && !tab.isEmpty()) {
for (Enumeration e = tab.keys() ; e.hasMoreElements() ; ) {
String key = (String)e.nextElement();
Component comp = (Component)tab.get(key);
vector.add(new Card(key, comp));
if (comp.isVisible()) {
currentCard = vector.size() - 1;
}
}
}
} else {
vector = (Vector)f.get("vector", null);
currentCard = f.get("currentCard", 0);
}
|
public void | removeLayoutComponent(java.awt.Component comp)Removes the specified component from the layout.
If the card was visible on top, the next card underneath it is shown.
synchronized (comp.getTreeLock()) {
for (int i = 0; i < vector.size(); i++) {
if (((Card)vector.get(i)).comp == comp) {
// if we remove current component we should show next one
if (comp.isVisible() && (comp.getParent() != null)) {
next(comp.getParent());
}
vector.remove(i);
// correct currentCard if this is necessary
if (currentCard > i) {
currentCard--;
}
break;
}
}
}
|
public void | setHgap(int hgap)Sets the horizontal gap between components.
this.hgap = hgap;
|
public void | setVgap(int vgap)Sets the vertical gap between components.
this.vgap = vgap;
|
public void | show(java.awt.Container parent, java.lang.String name)Flips to the component that was added to this layout with the
specified name , using addLayoutComponent .
If no such component exists, then nothing happens.
synchronized (parent.getTreeLock()) {
checkLayout(parent);
Component next = null;
int ncomponents = vector.size();
for (int i = 0; i < ncomponents; i++) {
Card card = (Card)vector.get(i);
if (card.name.equals(name)) {
next = card.comp;
currentCard = i;
break;
}
}
if ((next != null) && !next.isVisible()) {
ncomponents = parent.getComponentCount();
for (int i = 0; i < ncomponents; i++) {
Component comp = parent.getComponent(i);
if (comp.isVisible()) {
comp.setVisible(false);
break;
}
}
next.setVisible(true);
parent.validate();
}
}
|
void | showDefaultComponent(java.awt.Container parent)
if (parent.getComponentCount() > 0) {
currentCard = 0;
parent.getComponent(0).setVisible(true);
parent.validate();
}
|
public java.lang.String | toString()Returns a string representation of the state of this card layout.
return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]";
|
private void | writeObject(java.io.ObjectOutputStream s)Writes serializable fields to stream.
Hashtable tab = new Hashtable();
int ncomponents = vector.size();
for (int i = 0; i < ncomponents; i++) {
Card card = (Card)vector.get(i);
tab.put(card.name, card.comp);
}
ObjectOutputStream.PutField f = s.putFields();
f.put("hgap", hgap);
f.put("vgap", vgap);
f.put("vector", vector);
f.put("currentCard", currentCard);
f.put("tab", tab);
s.writeFields();
|