je veu sérialiser et swinger ce code , mais j'ai des problem avec le:
JComponent m = target.getComponent(i); // erreur: incompatble type?????,
Voici la source:
import java.awt.*;
import com.sun.java.swing.*;
/** A class that implements multi line FlowLayout */
public class FlowLayoutCust implements LayoutManager
{
static final int HORIZONTAL = 1;
static final int VERTICAL = 2;
int direction;
int hgap = 0;
int vgap = 0;
public FlowLayoutCust(int direction)
{
this(direction, 0, 0);
}
public FlowLayoutCust(int direction, int hgap, int vgab)
{
this.direction = direction;
this.hgap = hgap;
this.vgap = vgap;
}
public void addLayoutComponent(String name, Component comp) {}
public void removeLayoutComponent(Component comp) {}
public Dimension preferredLayoutSize(Container target)
{
Dimension dm = target.size();
Insets insets = target.insets();
int nmembers = target.countComponents();
if (direction == HORIZONTAL)
{
int sumWidth = 0;
int sumHeight = insets.top + insets.bottom + vgap*2;
int rowHeight = 0;
int maxWidth = dm.width - (insets.left + insets.right + hgap*2);
for (int i = 0 ; i < nmembers ; i++)
{
Component m = target.getComponent(i);
if (m.isVisible())
{
Dimension d = m.preferredSize();
sumWidth += d.width;
rowHeight = Math.max(rowHeight,
d.height);
if (sumWidth > maxWidth
&& i != 0)
{
sumHeight +=
rowHeight + vgap;
sumWidth =
d.width;
rowHeight =
d.height;
}
else
{
sumWidth +=
hgap;
}
}
}
sumHeight += rowHeight;
return new Dimension(dm.width, sumHeight);
}
else
{
int sumWidth = insets.left + insets.right + hgap*2;
int sumHeight = 0;
int colWidth = 0;
int maxHeight = dm.height - (insets.top + insets.bottom + vgap*2);
for (int i = 0 ; i < nmembers ; i++)
{
Component m = target.getComponent(i);
if (m.isVisible())
{
Dimension d = m.preferredSize();
sumHeight += d.height;
colWidth = Math.max(colWidth,
d.width);
if (sumHeight > maxHeight
&& i != 0)
{
sumWidth +=
colWidth + hgap;
sumHeight =
d.height;
colWidth =
d.width;
}
else
{
sumHeight +=
vgap;
}
}
}
sumWidth += colWidth;
return new Dimension(sumWidth, dm.height);
}
}
public Dimension minimumLayoutSize(Container target)
{
return preferredLayoutSize(target);
}
public void layoutContainer(Container target)
{
Dimension dm = target.size();
Insets insets = target.insets();
int nmembers = target.countComponents();
int posX = insets.left;
int posY = insets.top;
if (direction == HORIZONTAL)
{
int rowHeight = 0;
for (int i = 0 ; i < nmembers; i++)
{
Component m = target.getComponent(i);
if (m.isVisible())
{
Dimension d = m.preferredSize();
m.resize(d.width, d.height);
rowHeight = Math.max(rowHeight,
d.height);
if (posX + d.width > dm.width
&& i != 0)
{
posY +=
rowHeight + vgap;
posX =
insets.left + d.width;
rowHeight =
d.height;
m.move(insets.left, posY);
}
else
{
m.move(posX,
posY);
posX +=
d.width + hgap;
}
}
}
}
else
{
int colWidth = 0;
for (int i = 0 ; i < nmembers; i++)
{
Component m = target.getComponent(i);
if (m.isVisible())
{
Dimension d = m.preferredSize();
m.resize(d.width, d.height);
colWidth = Math.max(colWidth,
d.width);
if (posY + d.height >
dm.height && i != 0)
{
posX +=
colWidth + hgap;
posY =
insets.top + d.height;
colWidth =
d.width;
m.move(posX,
insets.top);
}
else
{
m.move(posX,
posY);
posY +=
d.height + vgap;
}
}
}
}
}
public String toString()
{
String str = "";
switch (direction)
{
case HORIZONTAL: str = ",direction=Horizontal"; break;
case VERTICAL: str = ",direction=Vertical"; break;
}
return getClass().getName() + str ;
}
}