0N/A/*
3835N/A * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions
0N/A * are met:
0N/A *
0N/A * - Redistributions of source code must retain the above copyright
0N/A * notice, this list of conditions and the following disclaimer.
0N/A *
0N/A * - Redistributions in binary form must reproduce the above copyright
0N/A * notice, this list of conditions and the following disclaimer in the
0N/A * documentation and/or other materials provided with the distribution.
0N/A *
2362N/A * - Neither the name of Oracle nor the names of its
0N/A * contributors may be used to endorse or promote products derived
0N/A * from this software without specific prior written permission.
0N/A *
0N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0N/A */
0N/A
4378N/A/*
4378N/A * This source code is provided to illustrate the usage of a given feature
4378N/A * or technique and has been deliberately simplified. Additional steps
4378N/A * required for a production-quality application, such as security checks,
4378N/A * input validation and proper error handling, might not be present in
4378N/A * this sample code.
4378N/A */
4378N/A
4378N/A
0N/A
3835N/Aimport java.awt.BorderLayout;
3835N/Aimport java.awt.Component;
3835N/Aimport java.awt.Container;
3835N/Aimport java.awt.Dimension;
3835N/Aimport java.awt.Insets;
3835N/Aimport java.awt.LayoutManager;
3835N/Aimport java.util.ArrayList;
3835N/Aimport java.util.Iterator;
3835N/Aimport java.util.List;
3835N/Aimport javax.swing.JComponent;
3835N/Aimport javax.swing.JInternalFrame;
3835N/Aimport javax.swing.JLabel;
3835N/Aimport javax.swing.JPanel;
3835N/Aimport javax.swing.JScrollPane;
3835N/Aimport javax.swing.JTextArea;
3835N/Aimport javax.swing.JTextField;
3835N/Aimport javax.swing.border.EmptyBorder;
0N/A
0N/A
0N/A/**
3835N/A * This is a subclass of JInternalFrame which displays documents.
3835N/A *
3835N/A * @author Steve Wilson
3835N/A */
3835N/A@SuppressWarnings("serial")
0N/Apublic class MetalworksDocumentFrame extends JInternalFrame {
0N/A
0N/A static int openFrameCount = 0;
0N/A static final int offset = 30;
0N/A
0N/A public MetalworksDocumentFrame() {
0N/A super("", true, true, true, true);
0N/A openFrameCount++;
0N/A setTitle("Untitled Message " + openFrameCount);
0N/A
0N/A JPanel top = new JPanel();
0N/A top.setBorder(new EmptyBorder(10, 10, 10, 10));
0N/A top.setLayout(new BorderLayout());
0N/A top.add(buildAddressPanel(), BorderLayout.NORTH);
0N/A
3835N/A JTextArea content = new JTextArea(15, 30);
3835N/A content.setBorder(new EmptyBorder(0, 5, 0, 5));
0N/A content.setLineWrap(true);
0N/A
0N/A
0N/A
0N/A JScrollPane textScroller = new JScrollPane(content,
3835N/A JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
3835N/A JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
3835N/A top.add(textScroller, BorderLayout.CENTER);
0N/A
0N/A
0N/A setContentPane(top);
0N/A pack();
3835N/A setLocation(offset * openFrameCount, offset * openFrameCount);
0N/A
0N/A }
0N/A
0N/A private JPanel buildAddressPanel() {
0N/A JPanel p = new JPanel();
3835N/A p.setLayout(new LabeledPairLayout());
0N/A
0N/A
0N/A JLabel toLabel = new JLabel("To: ", JLabel.RIGHT);
0N/A JTextField toField = new JTextField(25);
0N/A p.add(toLabel, "label");
0N/A p.add(toField, "field");
0N/A
0N/A
0N/A JLabel subLabel = new JLabel("Subj: ", JLabel.RIGHT);
0N/A JTextField subField = new JTextField(25);
0N/A p.add(subLabel, "label");
0N/A p.add(subField, "field");
0N/A
0N/A
0N/A JLabel ccLabel = new JLabel("cc: ", JLabel.RIGHT);
0N/A JTextField ccField = new JTextField(25);
0N/A p.add(ccLabel, "label");
0N/A p.add(ccField, "field");
0N/A
0N/A return p;
0N/A
0N/A }
0N/A
3835N/A
0N/A class LabeledPairLayout implements LayoutManager {
0N/A
3835N/A List<Component> labels = new ArrayList<Component>();
3835N/A List<Component> fields = new ArrayList<Component>();
3835N/A int yGap = 2;
3835N/A int xGap = 2;
0N/A
3835N/A public void addLayoutComponent(String s, Component c) {
3835N/A if (s.equals("label")) {
3835N/A labels.add(c);
3835N/A } else {
3835N/A fields.add(c);
3835N/A }
3835N/A }
0N/A
3835N/A public void layoutContainer(Container c) {
3835N/A Insets insets = c.getInsets();
0N/A
3835N/A int labelWidth = 0;
3835N/A for (Component comp : labels) {
3835N/A labelWidth = Math.max(labelWidth, comp.getPreferredSize().width);
3835N/A }
0N/A
3835N/A int yPos = insets.top;
0N/A
3835N/A Iterator<Component> fieldIter = fields.listIterator();
3835N/A Iterator<Component> labelIter = labels.listIterator();
3835N/A while (labelIter.hasNext() && fieldIter.hasNext()) {
3835N/A JComponent label = (JComponent) labelIter.next();
3835N/A JComponent field = (JComponent) fieldIter.next();
3835N/A int height = Math.max(label.getPreferredSize().height, field.
3835N/A getPreferredSize().height);
3835N/A label.setBounds(insets.left, yPos, labelWidth, height);
3835N/A field.setBounds(insets.left + labelWidth + xGap,
3835N/A yPos,
3835N/A c.getSize().width - (labelWidth + xGap + insets.left
3835N/A + insets.right),
3835N/A height);
3835N/A yPos += (height + yGap);
3835N/A }
0N/A
3835N/A }
0N/A
3835N/A public Dimension minimumLayoutSize(Container c) {
3835N/A Insets insets = c.getInsets();
0N/A
3835N/A int labelWidth = 0;
3835N/A for (Component comp : labels) {
3835N/A labelWidth = Math.max(labelWidth, comp.getPreferredSize().width);
3835N/A }
0N/A
3835N/A int yPos = insets.top;
0N/A
3835N/A Iterator<Component> labelIter = labels.listIterator();
3835N/A Iterator<Component> fieldIter = fields.listIterator();
3835N/A while (labelIter.hasNext() && fieldIter.hasNext()) {
3835N/A Component label = labelIter.next();
3835N/A Component field = fieldIter.next();
3835N/A int height = Math.max(label.getPreferredSize().height, field.
3835N/A getPreferredSize().height);
3835N/A yPos += (height + yGap);
3835N/A }
3835N/A return new Dimension(labelWidth * 3, yPos);
3835N/A }
0N/A
3835N/A public Dimension preferredLayoutSize(Container c) {
3835N/A Dimension d = minimumLayoutSize(c);
3835N/A d.width *= 2;
3835N/A return d;
3835N/A }
0N/A
3835N/A public void removeLayoutComponent(Component c) {
3835N/A }
3835N/A }
0N/A}