import java.awt.*; import java.util.*; import java.net.*; class CELLDISP{ public mform_c item; public int used; // Une cellule multi-colonne ou multi-ligne // occupe l'espace, voir USED_XXX public Dimension d; public CELLDISP(){ used = 0; item = null; d = null; } } class mform_layout implements LayoutManager { static int MAX_COL = 20; static int USED_TOP=1; // On est sur la première ligne d'un multi-ligne static int USED_LEFT=2; // On est sur la première colonne d'un multi-colonne static int USED_MULTICOL=4; // Ce champs occupe plusieurs colonnes static int USED_MULTILINE=8; // Ce champs occupe plusieurs lignes private int preferredWidth,preferredHeight; private int minWidth = 0, minHeight = 0; private boolean sizeUnknown = true; private boolean DEBUG = false; mform fl; public mform_layout(mform _fl) { fl = _fl; } /* Required by LayoutManager. */ public void addLayoutComponent(String name, Component comp) { System.err.println ("addLayoutComponent"); } /* Required by LayoutManager. */ public void removeLayoutComponent(Component comp) { System.err.println ("removeLayoutComponent"); } private Dimension FitStrategie_marge( int gauche, int droit, int haut, int bas, boolean use_cur_size){ // if (fl.parent == null) System.err.println ("fit start"); System.err.flush(); //System.err.println ("Fitstrategie " + mform.getabspath(fl) + " " + fl.was_modified()); //if (!fl.was_modified()) return; int nb = fl.nbc; gauche += fl.marge_gauche; droit += fl.marge_droite; haut += fl.marge_haut; bas += fl.marge_bas; FontMetrics met = fl.getGraphics().getFontMetrics(); CELLDISP tbcell[][] = new CELLDISP[100][20]; for (int i=0; i<100; i++){ for (int j=0; j<20; j++) tbcell[i][j] = new CELLDISP(); } int noline = 0; int nocol = 0; int has_fill = 0; for (int i=0; i 1) used |= USED_MULTICOL; if (item.v_cells > 1) used |= USED_MULTILINE; for (; nbcol>0; nbcol--,nocol++){ int nol = noline; used |= USED_TOP; for (int l=0; l 1 && (used & USED_LEFT) != 0){ int total = 0; for (int x=0; x 1 && (used & USED_TOP) != 0){ int total = 0; for (int x=0; x d.width || cheight > d.height){ b.stretch (cwidth,cheight); } } } } } } // On peut maitenant disposer les items int v_pos = haut; int h_pos = gauche; for (int i=0; i<=noline; i++){ h_pos = gauche; String disp = fl.dispstr; for (int c=0; cis_vline()) item->setspec(-1,-1,-1,total_height); } } h_pos += colwidth[c]; } v_pos += lineheight[i]; } //stretch_last(h_pos); // Peut-etre que dans windows il faut un chiffre different que 18. // if (menu_is_set){ // #if defined(UNIX_LINUX) // v_pos += GetCharHeight() + 18 ; // #else // if(!getframe_mode_resize()) // v_pos += GetCharHeight() + 5; // #endif // } Dimension ret = new Dimension (h_pos+droit, v_pos + bas); if (ret.width < fl.min_width) ret.width = fl.min_width; fl.modified = false; // if (fl.parent == null) System.err.println ("fit end"); return ret; } // Compute the layout of the dialog with existing item size // prefered size public Dimension setsizes (Container parent, boolean use_cur_size){ //System.err.println ("setsizes"); Insets insets = parent.insets(); int left = insets.left; if (fl.sidetitle != null) left += 20; Dimension ret = FitStrategie_marge(left,0,insets.top,0,use_cur_size); //Always add the container's insets! ret.width += insets.right; ret.height += insets.bottom; return ret; } /* Required by LayoutManager. */ public Dimension preferredLayoutSize(Container parent) { // if (fl.parent == null) System.err.println ("preferredLayoutSize"); if (sizeUnknown || fl.was_modified()){ Dimension ret = setsizes (parent,false); minWidth = preferredWidth = ret.width; minHeight = preferredHeight = ret.height; sizeUnknown = false; } // if (fl.parent == null) System.err.println ("fin preferredLayoutSize"); return new Dimension (preferredWidth, preferredHeight); } /* Required by LayoutManager. */ public Dimension minimumLayoutSize(Container parent) { //System.err.println ("minimumLayoutSize"); Dimension dim = new Dimension(0, 0); //Always add the container's insets! Insets insets = parent.insets(); dim.width = minWidth + insets.left + insets.right; dim.height = minHeight + insets.top + insets.bottom; sizeUnknown = false; return dim; } /* Required by LayoutManager. */ /* This is called when the panel is first displayed, * and every time its size changes. * Note: You CAN'T assume preferredLayoutSize() or minimumLayoutSize() * will be called -- in the case of applets, at leas, they probably * won't be. */ public void layoutContainer(Container parent) { //System.err.println ("layoutContainer"); Dimension pref = preferredLayoutSize(parent); Dimension cur = parent.size(); int diffx = cur.width - pref.width; int diffy = cur.height - pref.height; //System.err.println ("layoutContainer " + fl.id + " " + diffx + " " + diffy); if (diffx > 0 || diffy > 0){ fl.resizeitems(diffx,diffy); setsizes (parent,true); } } public String toString() { System.err.println ("toString"); String str = ""; return getClass().getName() + "[" + str + "]"; } } class mform_c{ public boolean is_hcontrib; // Contribue à la disposition horizontale public char h_align; // Alignement à l'intérieur de la cellule // l=left, c=center, r=right public char v_align; // Alignement à l'intérieur de la cellule // t=top, c=center, b=bottom public int h_cells; // Number of cells used horizontally (colspan) public int v_cells; // Number of cells used vertically (rowspan) public String s; // Input buffer is needed or label public String id; // Widget identifier public Component c; int weightx; // relative weight of the component for int weighty; // dialog resizing. 0 for fixed elements int x; // Position for T_LABEL int y; static final int T_UNKNOWN=0; static final int T_STRING=1; static final int T_BUTTON=2; static final int T_FORM=3; static final int T_CHECKBOX=4; static final int T_RADIO=5; static final int T_CHOICE=6; static final int T_HLINE=7; static final int T_VLINE=8; static final int T_SKIP=9; static final int T_NEWLINE=10; static final int T_COMBO=11; static final int T_LIST=12; static final int T_ICON=13; static final int T_FILL=14; static final int T_TEXT=15; static final int T_LABEL=16; static final int T_BOOK=17; static final int T_CLIST=18; public int type; public mform_c(String _id){ weightx = weighty = 0; h_align = ' '; v_align = 't'; is_hcontrib = true; v_cells = h_cells = 1; s = null; c = null; id = _id; type = T_UNKNOWN; } } class Checkbox_val extends Checkbox{ public int instance; public Checkbox_val (String str, CheckboxGroup g, boolean state, int instance){ super(str,g,state); this.instance = instance; } } class mform extends formbase{ mform_c tbc[]; public int nbc; public String dispstr; public int marge_haut; public int marge_bas; public int marge_gauche; public int marge_droite; public int min_width; String tbgid[]; String sidetitle; CheckboxGroup tbg[]; int nbgroup; public mform (formbase _parent, String _id){ super(_parent,_id); tbc = new mform_c[400]; marge_gauche = marge_droite = marge_haut = marge_bas = 0; min_width = 0; nbc = 0; dispstr = "llllllllllllllllllllllllllllllllllllllllllllllllll"; setLayout(new mform_layout(this)); nbgroup = 0; tbgid = new String[30]; tbg = new CheckboxGroup[30]; } public void reset(){ for (int i=0; i= 0. They are meaningless, except the // available space will be given to dialog items according to their // relative weight. A fixed item has 0,0 public void Setweightlast(int wx, int wy){ mform_c m = tbc[nbc-1]; m.weightx = wx; m.weighty = wy; } public void New_label(String str){ mform_c m = alloc_mf(); m.type = mform_c.T_LABEL; m.s = str; } public void New_richtext(String str){ mform_c m = alloc_mf(); m.type = mform_c.T_LABEL; m.s = str; } public Label New_wlabel(String str){ mform_c m = alloc_mf(); Label ret = new Label (str); m.c = ret; add(m.c); return ret; } public TextField New_string (String _id, int len, String initval){ mform_c m = alloc_mf(_id); m.s = initval; TextField ret = new TextField(m.s,len); m.c = ret; m.type = mform_c.T_STRING; add(m.c); return ret; } public TextField New_password (String _id, int len){ mform_c m = alloc_mf(_id); m.s = ""; TextField ret = new TextField(m.s,len); m.c = ret; m.type = mform_c.T_STRING; add(m.c); return ret; } public TextField New_string (int len, String initval){ return New_string ("",len,initval); } public TextArea New_text (String _id, int rows, int cols){ mform_c m = alloc_mf(_id); m.s = ""; TextArea ret = new TextArea("",rows,cols); m.c = ret; m.type = mform_c.T_TEXT; add(m.c); return ret; } public void Skip (int n){ mform_c m = alloc_mf(); m.type = mform_c.T_SKIP; m.h_cells = n; } public void Fill (){ mform_c m = alloc_mf(); m.type = mform_c.T_FILL; m.h_cells = 1; } public void New_hline (String s){ mform_c m = alloc_mf(); m.c = new hline (s); add (m.c); m.type = mform_c.T_HLINE; Dispolast ('l',1,'c',1); } public void New_hline (){ New_hline (null); } public void New_vline (){ mform_c m = alloc_mf(); m.type = mform_c.T_VLINE; } public Button New_button(String _id, boolean dodump, String str){ mform_c m = alloc_mf(_id); Button ret = new Button(str); m.c = ret; m.type = mform_c.T_BUTTON; add (ret); return ret; } public Button New_button(String _id, String str){ return New_button (_id,false,str); } public Button New_button(String str){ return New_button ("",false,str); } public Choice New_choice(String _id, String val){ mform_c m = alloc_mf (_id); Choice ret = new Choice(); m.c = ret; m.s = val; m.type = mform_c.T_CHOICE; add (ret); return ret; } public void New_choice_item(String _id, String val){ for (int i=0; i= 0 && n < nbc) ret = tbc[n]; return ret; } public void New_component (Component comp){ mform_c m = alloc_mf(); m.c = comp; add(comp); } // Display the current value of each field of the dialog public void dump(){ for (int i=0; i limity; i++, y -= charh){ g.drawString (sidetitle.substring(i,i+1),1,y); } } } private void distribute ( int start, int end, int nbfill, int diffx){ if (nbfill > 0){ int space = diffx/nbfill; int newx = 0; for (int i=start; i 0){ int start = 0; int nbfill = 0; for (int i=0; i 0){ tbexph[nbexph++] = item; totalh += item.weightx; } if (item.weighty > 0){ tbexpv[nbexpv++] = item; totalv += item.weighty; } } for (int i=0; i