⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialoglayout.java

📁 Java实现的点对点短消息发送协议(smpp)开发包源码
💻 JAVA
字号:

/*
 * Copyright (C) 1998 Noctor Consulting, Ltd. All rights reserved.
 * SMS JDK 2.0 Bureau application
 */

package bureau;
//package java.awt;

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 = new Hashtable();
	protected int m_width;
	protected int m_height;

	// DialogLayout methods

	public DialogLayout(Container parent, int width, int height)
	{
		Construct(parent, width, height);
	}

  public void resize(int width,int height)
  {
	m_width=width;
	m_height=height;
  }
  

	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.
					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;
                //if(parent!=null) setFont(parent.getFont());
	}

	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;
	}

	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;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -