diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 49c899572aef..e13b8ad219d4 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,9 @@ 2000-12-03 Tom Tromey + * Makefile.in: Rebuilt. + * Makefile.am (awt_java_source_files): Added new file. + * java/awt/FlowLayout.java: New file. + * Makefile.in: Rebuilt. * Makefile.am (awt_java_source_files): Added new file. * java/awt/GridLayout.java: New file. diff --git a/libjava/Makefile.am b/libjava/Makefile.am index ff65cf0988f4..6c2681f8b996 100644 --- a/libjava/Makefile.am +++ b/libjava/Makefile.am @@ -585,6 +585,7 @@ java/awt/Event.java \ java/awt/EventDispatchThread.java \ java/awt/EventQueue.java \ java/awt/FileDialog.java \ +java/awt/FlowLayout.java \ java/awt/Font.java \ java/awt/FontMetrics.java \ java/awt/Frame.java \ diff --git a/libjava/Makefile.in b/libjava/Makefile.in index 6ee2fe5a8e06..46d894276fb9 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -356,6 +356,7 @@ java/awt/Event.java \ java/awt/EventDispatchThread.java \ java/awt/EventQueue.java \ java/awt/FileDialog.java \ +java/awt/FlowLayout.java \ java/awt/Font.java \ java/awt/FontMetrics.java \ java/awt/Frame.java \ @@ -713,7 +714,6 @@ java/util/EventListener.java \ java/util/EventObject.java \ java/util/GregorianCalendar.java \ java/util/HashMap.java \ -java/util/HashSet.java \ java/util/Hashtable.java \ java/util/Iterator.java \ java/util/LinkedList.java \ @@ -741,8 +741,6 @@ java/util/TimeZone.java \ java/util/Timer.java \ java/util/TimerTask.java \ java/util/TooManyListenersException.java \ -java/util/TreeMap.java \ -java/util/TreeSet.java \ java/util/Vector.java @@ -1327,10 +1325,10 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/java/awt/Dialog.P .deps/java/awt/Dimension.P \ .deps/java/awt/Event.P .deps/java/awt/EventDispatchThread.P \ .deps/java/awt/EventQueue.P .deps/java/awt/FileDialog.P \ -.deps/java/awt/Font.P .deps/java/awt/FontMetrics.P \ -.deps/java/awt/Frame.P .deps/java/awt/Graphics.P \ -.deps/java/awt/Graphics2D.P .deps/java/awt/GraphicsConfiguration.P \ -.deps/java/awt/GridLayout.P \ +.deps/java/awt/FlowLayout.P .deps/java/awt/Font.P \ +.deps/java/awt/FontMetrics.P .deps/java/awt/Frame.P \ +.deps/java/awt/Graphics.P .deps/java/awt/Graphics2D.P \ +.deps/java/awt/GraphicsConfiguration.P .deps/java/awt/GridLayout.P \ .deps/java/awt/IllegalComponentStateException.P .deps/java/awt/Image.P \ .deps/java/awt/Insets.P .deps/java/awt/ItemSelectable.P \ .deps/java/awt/Label.P .deps/java/awt/LayoutManager.P \ @@ -1687,11 +1685,11 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/java/util/EmptyStackException.P .deps/java/util/Enumeration.P \ .deps/java/util/EventListener.P .deps/java/util/EventObject.P \ .deps/java/util/GregorianCalendar.P .deps/java/util/HashMap.P \ -.deps/java/util/HashSet.P .deps/java/util/Hashtable.P \ -.deps/java/util/Iterator.P .deps/java/util/LinkedList.P \ -.deps/java/util/List.P .deps/java/util/ListIterator.P \ -.deps/java/util/ListResourceBundle.P .deps/java/util/Locale.P \ -.deps/java/util/Map.P .deps/java/util/MissingResourceException.P \ +.deps/java/util/Hashtable.P .deps/java/util/Iterator.P \ +.deps/java/util/LinkedList.P .deps/java/util/List.P \ +.deps/java/util/ListIterator.P .deps/java/util/ListResourceBundle.P \ +.deps/java/util/Locale.P .deps/java/util/Map.P \ +.deps/java/util/MissingResourceException.P \ .deps/java/util/NoSuchElementException.P .deps/java/util/Observable.P \ .deps/java/util/Observer.P .deps/java/util/Properties.P \ .deps/java/util/PropertyPermission.P \ @@ -1701,8 +1699,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/java/util/SortedSet.P .deps/java/util/Stack.P \ .deps/java/util/StringTokenizer.P .deps/java/util/TimeZone.P \ .deps/java/util/Timer.P .deps/java/util/TimerTask.P \ -.deps/java/util/TooManyListenersException.P .deps/java/util/TreeMap.P \ -.deps/java/util/TreeSet.P .deps/java/util/Vector.P \ +.deps/java/util/TooManyListenersException.P .deps/java/util/Vector.P \ .deps/java/util/jar/Attributes.P .deps/java/util/jar/JarEntry.P \ .deps/java/util/jar/JarException.P .deps/java/util/jar/JarFile.P \ .deps/java/util/jar/JarInputStream.P \ diff --git a/libjava/java/awt/FlowLayout.java b/libjava/java/awt/FlowLayout.java new file mode 100644 index 000000000000..c74d80229b75 --- /dev/null +++ b/libjava/java/awt/FlowLayout.java @@ -0,0 +1,250 @@ +// GridLayout.java - Grid-based layout engine + +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package java.awt; + +import java.io.Serializable; + +/** This class implements a flow-based layout. Components are laid + * out in order from left to right. When a component cannot be placed + * without horizontal clipping, a new row is started. This class + * supports horizontal and vertical gaps. These are used for spacing + * between components. + */ +public class FlowLayout implements LayoutManager, Serializable +{ + /** Constant that specifies left alignment. */ + public static final int LEFT = 0; + /** Constant that specifies center alignment. */ + public static final int CENTER = 1; + /** Constant that specifies right alignment. */ + public static final int RIGHT = 2; + + /** Add a new component to the layout. This particular implementation + * does nothing. + */ + public void addLayoutComponent (String name, Component comp) + { + // Nothing. + } + + /** Return the alignment. */ + public int getAlignment () + { + return align; + } + + /** Return the horizontal gap. */ + public int getHgap () + { + return hgap; + } + + /** Return the vertical gap. */ + public int getVgap () + { + return vgap; + } + + /** Create a new FlowLayout with center alignment. + * Both gaps are set to 0. + */ + public FlowLayout () + { + this (CENTER, 0, 0); + } + + /** Create a new FlowLayout with the alignment. + * columns. Both gaps are set to 0. + * @param align Alignment + */ + public FlowLayout (int align) + { + this (align, 0, 0); + } + + /** Create a new FlowLayout with the specified alignment and gaps. + * @param align Alignment + * @param hgap The horizontal gap + * @param vgap The vertical gap + * @exception IllegalArgumentException If either gap is negative + */ + public FlowLayout (int align, int hgap, int vgap) + { + if (hgap < 0) + throw new IllegalArgumentException ("horizontal gap must be nonnegative"); + if (vgap < 0) + throw new IllegalArgumentException ("vertical gap must be nonnegative"); + if (align != LEFT && align != RIGHT && align != CENTER) + throw new IllegalArgumentException ("invalid align: " + align); + this.align = align; + this.hgap = hgap; + this.vgap = vgap; + } + + /** Lay out the container's components based on current settings. + * @param parent The parent container + */ + public void layoutContainer (Container parent) + { + int num = parent.getComponentCount (); + // This is more efficient than calling getComponents(). + Component[] comps = parent.component; + + Dimension d = parent.getSize (); + Insets ins = parent.getInsets (); + + int y = ins.top + vgap; + int i = 0; + while (i < num) + { + // Find the components which go in the current row. + int new_w = ins.left + hgap + ins.right; + int new_h = 0; + int j; + for (j = i; j < num; ++j) + { + // FIXME: this is very inefficient. + Dimension c = comps[i].getPreferredSize (); + int next_w = new_w + hgap + c.width; + if (next_w > d.width) + { + // We must start a new row. + break; + } + new_w = next_w; + new_h = Math.max (new_h, c.height); + } + // We always need at least one item. + if (j == i) + ++j; + + // Set the location of each component for this row. + int x; + if (align == LEFT) + x = ins.left + hgap; + else if (align == CENTER) + x = (d.width - new_w) / 2; + else + x = d.width - new_w; + for (int k = i; i < j; ++k) + { + // FIXME: this is very inefficient. + Dimension c = comps[i].getPreferredSize (); + comps[i].setLocation (x, y); + x += c.width + vgap; + } + + // Advance to next row. + i = j; + y += new_h + vgap; + } + } + + /** Get the minimum layout size of the container. + * @param cont The parent container + */ + public Dimension minimumLayoutSize (Container cont) + { + return getSize (cont, true); + } + + /** Get the preferred layout size of the container. + * @param cont The parent container + */ + public Dimension preferredLayoutSize (Container cont) + { + return getSize (cont, false); + } + + /** Remove the indicated component from this layout manager. + * This particular implementation does nothing. + * @param comp The component to remove + */ + public void removeLayoutComponent (Component comp) + { + // Nothing. + } + + /** Set the alignment. + * @param align The alignment + */ + public void setAlignment (int align) + { + if (align != LEFT && align != RIGHT && align != CENTER) + throw new IllegalArgumentException ("invalid align: " + align); + this.align = align; + } + + /** Set the horizontal gap + * @param hgap The horizontal gap + */ + public void setHgap (int hgap) + { + if (hgap < 0) + throw new IllegalArgumentException ("horizontal gap must be nonnegative"); + this.hgap = hgap; + } + + /** Set the vertical gap. + * @param vgap The vertical gap + */ + public void setVgap (int vgap) + { + if (vgap < 0) + throw new IllegalArgumentException ("vertical gap must be nonnegative"); + this.vgap = vgap; + } + + /** Return String description of this object. */ + public String toString () + { + return ("[" + getClass ().getName () + ",hgap=" + hgap + ",vgap=" + vgap + + ",align=" + align + "]"); + } + + // This method is used to compute the various sizes. + private Dimension getSize (Container parent, boolean is_min) + { + int w, h, num = parent.getComponentCount (); + // This is more efficient than calling getComponents(). + Component[] comps = parent.component; + + w = 0; + h = 0; + for (int i = 0; i < num; ++i) + { + // FIXME: can we just directly read the fields in Component? + // Or will that not work with subclassing? + Dimension d; + + if (is_min) + d = comps[i].getMinimumSize (); + else + d = comps[i].getPreferredSize (); + + w += d.width; + h = Math.max (d.height, h); + } + + Insets ins = parent.getInsets (); + + w += (num + 1) * hgap + ins.left + ins.right; + h += 2 * vgap + ins.top + ins.bottom; + + return new Dimension (w, h); + } + + // Alignment. + private int align; + // The gaps. + private int hgap; + private int vgap; +}