001: /*
002: * $Id: JGraphpadDialog.java,v 1.1.1.1 2005/08/04 11:21:58 gaudenz Exp $
003: * Copyright (c) 2001-2005, Gaudenz Alder
004: *
005: * All rights reserved.
006: *
007: * See LICENSE file for license details. If you are unable to locate
008: * this file please contact info (at) jgraph (dot) com.
009: */
010: package com.jgraph.pad.dialog;
011:
012: import java.awt.BorderLayout;
013: import java.awt.Color;
014: import java.awt.Component;
015: import java.awt.FlowLayout;
016:
017: import javax.swing.BorderFactory;
018: import javax.swing.ImageIcon;
019: import javax.swing.JButton;
020: import javax.swing.JComponent;
021: import javax.swing.JDialog;
022: import javax.swing.JPanel;
023:
024: /**
025: * Basic dialog class for JGraphpad consisting of the header with a title,
026: * subtitle and icon, the content, and the button panel with a set of buttons.
027: */
028: public class JGraphpadDialog extends JDialog {
029:
030: /**
031: * Holds the button panel.
032: */
033: protected JPanel buttonPanel;
034:
035: /**
036: * Constructs a new dialog using the specified title.
037: *
038: * @param title
039: * The title to use for the dialog and header.
040: */
041: public JGraphpadDialog(String title) {
042: this (title, null, null);
043:
044: }
045:
046: /**
047: * Constructs a new dialog using the specified title. The title is used in
048: * the dialog and also in the header. The header is only displayed if either
049: * an icon or subtitle is specified.
050: *
051: * @param title
052: * The title to use for the dialog and header.
053: * @param subtitle
054: * The subtitle to display in the header.
055: * @param icon
056: * The icon to display in the header.
057: */
058: public JGraphpadDialog(String title, String subtitle, ImageIcon icon) {
059: getContentPane().setLayout(new BorderLayout());
060: setTitle(title);
061:
062: // Adds the header panel
063: if (subtitle != null || icon != null) {
064: JGraphpadHeaderPanel header = new JGraphpadHeaderPanel(
065: icon, title, subtitle);
066: getContentPane().add(header, BorderLayout.NORTH);
067: }
068:
069: // Adds the button panel
070: buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
071: buttonPanel.setBorder(BorderFactory
072: .createCompoundBorder(BorderFactory.createMatteBorder(
073: 1, 0, 0, 0, Color.GRAY), BorderFactory
074: .createEmptyBorder(16, 8, 8, 8)));
075: getContentPane().add(buttonPanel, BorderLayout.SOUTH);
076: setContent(createContent());
077: }
078:
079: /**
080: * Hook for subclassers to create the content of the dialog. The value
081: * returned by this method is passed to {@link #setContent(Component)}
082: * within the constructor.
083: *
084: * @return Returns the content of the dialog.
085: */
086: protected JComponent createContent() {
087: return null;
088: }
089:
090: /**
091: * Adds the specified component to the component hierarchy of the dialog.
092: *
093: * @param content
094: * The component to add to the hierarchy.
095: */
096: public void setContent(Component content) {
097: if (content != null)
098: getContentPane().add(content, BorderLayout.CENTER);
099: }
100:
101: /**
102: * Adds the specified buttons to the button panel.
103: *
104: * @param buttons
105: * The buttons to be added to the button panel.
106: */
107: public void addButtons(JButton[] buttons) {
108: for (int i = 0; i < buttons.length; i++)
109: buttonPanel.add(buttons[i]);
110: buttonPanel.invalidate();
111: }
112:
113: }
|