// This is a part of the Microsoft Visual J++ library. // Copyright (C) 1996 Microsoft Corporation // All rights reserved. import java.util.Hashtable; import java.awt.LayoutManager; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.FontMetrics; import java.awt.Insets; import java.awt.Label; public class DialogLayout implements LayoutManager { protected Hashtable m_map; protected int m_width; protected int m_height; protected int cwidth; protected int cheight; // DialogLayout methods public DialogLayout(Container parent, int width, int height) { cwidth = getCharWidth(parent); cheight = getCharHeight(parent); Construct(parent, width, height); m_map=new Hashtable(); } public DialogLayout(Container parent, Dimension d) { Construct(parent, d.width, d.height); } public void setShape(Component comp, int x, int y, int width, int height) { m_map.put(comp, new Rectangle(x, y, width, height)); } public void setShape(Component comp, Rectangle rect) { m_map.put(comp, new Rectangle(rect.x, rect.y, rect.width, rect.height)); } public Rectangle getShape(Component comp) { Rectangle rect = (Rectangle)m_map.get(comp); return new Rectangle(rect.x, rect.y, rect.width, rect.height); } public Dimension getDialogSize() { return new Dimension(m_width, m_height); } // LayoutManager Methods public void addLayoutComponent(String name, Component comp) { } public void removeLayoutComponent(Component comp) { } public Dimension preferredLayoutSize(Container parent) { return new Dimension(m_width, m_height); } public Dimension minimumLayoutSize(Container parent) { return new Dimension(m_width, m_height); } public void layoutContainer(Container parent) { int count = parent.countComponents(); Rectangle rect = new Rectangle(); int charHeight = getCharHeight(parent); int charWidth = getCharWidth(parent); Insets insets = parent.insets(); FontMetrics m = parent.getFontMetrics(parent.getFont()); for (int i = 0; i < count; i++) { Component c = parent.getComponent(i); Rectangle r = (Rectangle)m_map.get(c); if (r != null) { rect.x = r.x; rect.y = r.y; rect.height = r.height; rect.width = r.width; mapRectangle(rect, charWidth, charHeight); if (c instanceof Label) { // Adjusts for space at left of Java labels. //Self adjusted segment //rect.x -= 12; //rect.width += 12; } rect.x += insets.left; rect.y += insets.top; c.reshape(rect.x, rect.y, rect.width, rect.height); } } } // Implementation Helpers protected void Construct(Container parent, int width, int height) { Rectangle rect = new Rectangle(0, 0, width, height); mapRectangle(rect, getCharWidth(parent), getCharHeight(parent)); m_width = rect.width; m_height = rect.height; } protected int getCharWidth(Container parent) { FontMetrics m = parent.getFontMetrics(parent.getFont()); String s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int width = m.stringWidth(s) / s.length(); if (width <= 0) width = 1; return width; } protected int getCharHeight(Container parent) { FontMetrics m = parent.getFontMetrics(parent.getFont()); int height = m.getHeight(); return height; } public int translateX(int x) { return (x * cwidth) / 4; } public int translateY(int y) { return (y * cheight) / 8; } protected void mapRectangle(Rectangle rect, int charWidth, int charHeight) { rect.x = (rect.x * charWidth) / 4; rect.y = (rect.y * charHeight) / 8; rect.width = (rect.width * charWidth) / 4; rect.height = (rect.height * charHeight) / 8; } }