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

📄 infopanel.java

📁 具有不同语法高亮的编辑器实例
💻 JAVA
字号:
/*
 * 08/10/2005
 *
 * InfoPanel.java - The part of a property sheet with the name and description
 * of the currently selected property.
 * Copyright (C) 2005 Robert Futrell
 * email@address.com
 * www.website.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.fife.ui.propertysheet;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.AbstractBorder;
import javax.swing.border.Border;
import javax.swing.plaf.PanelUI;

/**
 * The panel in the southern part of the split pane that contains
 * information about the currently selected property.
 *
 * @author Robert Futrell
 * @version 1.0
 */
class InfoPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5410253825413107527L;
	private JLabel propertyNameLabel;
	private JLabel propertyInfoLabel;

	private static final Border BORDER = new PropertyLineBorder();


/*****************************************************************************/


	public InfoPanel() {
		setLayout(new BorderLayout());
		setBorder(BORDER);
		propertyNameLabel = new JLabel("Property Name");
		JPanel temp = new JPanel(new BorderLayout());
		temp.add(propertyNameLabel, BorderLayout.WEST);
		add(temp, BorderLayout.NORTH);
		propertyInfoLabel = new JLabel("Property information");
		propertyInfoLabel.setVerticalAlignment(SwingConstants.TOP);
		add(propertyInfoLabel);
		setPropertyInfo(null); // Initialize this panel's text.
		setBoldFont();
	}


/*****************************************************************************/


	public void setPropertyInfo(final SelectedPropertyEvent e) {
		if (e!=null && e.getPropertyName()!=null) {
			propertyNameLabel.setText(e.getPropertyName());
			String desc = e.getPropertyDescription();
			propertyInfoLabel.setText("<html>" +
						(desc==null ?
							"(" + e.getPropertyType() + ")" :
							desc) +
						"</html>");
		}
		else {
			propertyNameLabel.setText(null);
			// Add empty lines at the bottom to "trick" initial layout into
			// giving the info panel more height.
			propertyInfoLabel.setText("<html>Click on a property to " +
						"to see its description.<br><br><br></html>");
		}
	}


/*****************************************************************************/


	/**
	 * Sets the property name label's font to a bold label font, if possible.
	 */
	protected void setBoldFont() {
		Font boldFont = UIManager.getFont("Label.font").deriveFont(Font.BOLD);
		if (propertyNameLabel!=null)
			propertyNameLabel.setFont(boldFont);
	}


/*****************************************************************************/


	/**
	 * Overridden so we can set the "title" label's font to bold.
	 *
	 * @param ui The new UI.
	 */
	public void setUI(PanelUI ui) {
		super.setUI(ui);
		setBoldFont();	// Won't work the first time as nothing's been created.
	}


/*****************************************************************************/
/************************* INNER CLASSES *************************************/
/*****************************************************************************/


	/**
	 * A line border whose color changes depending on the LnF and who
	 * can toggle on or off its right edge.
	 */
	static class PropertyLineBorder extends AbstractBorder {

		/**
		 * 
		 */
		private static final long serialVersionUID = 4842120816033620140L;

		private Insets insets;

		public PropertyLineBorder() {
			super();
			insets = new Insets(11,11,11,11);
		}

		public Insets getBorderInsets(Component c) {
			return insets;
		}

		public void paintBorder(Component c, Graphics g, int x, int y,
							int width, int height) {
			x += 6;
			y += 6;
			width -= 12;
			height -= 12;
			g.setColor(PropertySheetUtilities.getBorderEdgeColor());
			g.drawLine(x,y, x+width,y);
			g.drawLine(x,y, x,y+height);
			g.drawLine(x,y+height, x+width,y+height);
			g.drawLine(x+width,y, x+width,y+height);
		}

	}


/*****************************************************************************/

}

⌨️ 快捷键说明

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