📄 simpleinternalframe.java
字号:
/*
* Copyright (c) 2003 JGoodies Karsten Lentzsch. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* o Neither the name of JGoodies Karsten Lentzsch nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Source code changes (c) 2005 beck et al. projects
*/
package org.flexdock.demos.maximizing;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Paint;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.AbstractBorder;
import com.jgoodies.looks.LookUtils;
/**
* A lightweight component derived from JPanel that features certain subcomponents
* that make it look similar to a frame or internal frame. It shows a titlebar above
* its content component. The title bar has an
* optional icon on the left, a title text and an optional toolbar on the right.
*/
public class SimpleInternalFrame extends JPanel {
private JLabel titleLabel;
private GradientPanel gradientPanel;
private JPanel headerPanel;
private boolean isSelected;
// Instance Creation ****************************************************
/**
* Constructs a <code>SimpleInternalFrame</code> with an empty title.
*
* @param title the initial title
*/
public SimpleInternalFrame() {
this(null, "", null, null);
}
/**
* Constructs a <code>SimpleInternalFrame</code> with the specified title.
*
* @param title the initial title
*/
public SimpleInternalFrame(String title) {
this(null, title, null, null);
}
/**
* Constructs a <code>SimpleInternalFrame</code> with the specified icon, and title.
*
* @param icon the initial icon
* @param title the initial title
*/
public SimpleInternalFrame(Icon icon, String title) {
this(icon, title, null, null);
}
/**
* Constructs a <code>SimpleInternalFrame</code> with the specified title, tool bar, and content panel.
*
* @param title the initial title
* @param bar the initial tool bar
* @param content the initial content pane
*/
public SimpleInternalFrame(String title, JToolBar bar, JComponent content) {
this(null, title, bar, content);
}
/**
* Constructs a <code>SimpleInternalFrame</code> with the specified icon, title, tool bar, and content
* panel.
*
* @param icon the initial icon
* @param title the initial title
* @param bar the initial tool bar
* @param content the initial content pane
*/
public SimpleInternalFrame(Icon icon, String title, JToolBar bar, JComponent content) {
super(new BorderLayout());
this.isSelected = false;
this.titleLabel = new JLabel(title, icon, SwingConstants.LEADING);
JPanel top = buildHeader(titleLabel, bar);
add(top, BorderLayout.NORTH);
if (content != null) {
setContent(content);
}
setBorder(new ShadowBorder());
setSelected(true);
updateHeader();
}
// Public API ***********************************************************
/**
* Returns the frame's icon.
*
* @return the frame's icon
*/
public Icon getFrameIcon() {
return titleLabel.getIcon();
}
/**
* Sets a new frame icon.
*
* @param newIcon the icon to be set
*/
public void setFrameIcon(Icon newIcon) {
Icon oldIcon = getFrameIcon();
titleLabel.setIcon(newIcon);
firePropertyChange("frameIcon", oldIcon, newIcon);
}
/**
* Returns the frame's title text.
*
* @return String the current title text
*/
public String getTitle() {
return titleLabel.getText();
}
/**
* Sets a new title text.
*
* @param newText the title text tp be set
*/
public void setTitle(String newText) {
String oldText = getTitle();
titleLabel.setText(newText);
firePropertyChange("title", oldText, newText);
}
/**
* Returns the current toolbar, null if none has been set before.
*
* @return the current toolbar - if any
*/
public JToolBar getToolBar() {
return headerPanel.getComponentCount() > 1 ? (JToolBar) headerPanel.getComponent(1) : null;
}
/**
* Sets a new tool bar in the header.
*
* @param newToolBar the tool bar to be set in the header
*/
public void setToolBar(JToolBar newToolBar) {
JToolBar oldToolBar = getToolBar();
if (oldToolBar == newToolBar) {
return;
}
if (oldToolBar != null) {
headerPanel.remove(oldToolBar);
}
if (newToolBar != null) {
newToolBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
headerPanel.add(newToolBar, BorderLayout.EAST);
}
updateHeader();
firePropertyChange("toolBar", oldToolBar, newToolBar);
}
/**
* Returns the content - null, if none has been set.
*
* @return the current content
*/
public Component getContent() {
return hasContent() ? getComponent(1) : null;
}
/**
* Sets a new panel content; replaces any existing content, if existing.
*
* @param newContent the panel's new content
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -