Source code: net/jxta/ext/config/ui/UIConfigurator.java
1 /*
2 * Copyright (c) 2001 Sun Microsystems, Inc. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and thproe following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. The end-user documentation included with the redistribution,
18 * if any, must include the following acknowledgment:
19 * "This product includes software developed by the
20 * Sun Microsystems, Inc. for Project JXTA."
21 * Alternately, this acknowledgment may appear in the software itself,
22 * if and wherever such third-party acknowledgments normally appear.
23 *
24 * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA"
25 * must not be used to endorse or promote products derived from this
26 * software without prior written permission. For written
27 * permission, please contact Project JXTA at http://www.jxta.org.
28 *
29 * 5. Products derived from this software may not be called "JXTA",
30 * nor may "JXTA" appear in their name, without prior written
31 * permission of Sun.
32 *
33 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
34 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
37 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
40 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
43 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * SUCH DAMAGE.
45 * ====================================================================
46 *
47 * This software consists of voluntary contributions made by many
48 * individuals on behalf of Project JXTA. For more
49 * information on Project JXTA, please see
50 * <http://www.jxta.org/>.
51 *
52 * This license is based on the BSD license adopted by the Apache Foundation.
53 *
54 * $Id: UIConfigurator.java,v 1.1 2004/09/16 12:28:11 volkerj Exp $
55 */
56 package net.jxta.ext.config.ui;
57
58 import org.swixml.SwingEngine;
59
60 import javax.swing.*;
61
62 import java.awt.Component;
63 import java.awt.Container;
64 import java.awt.Dimension;
65 import java.awt.Insets;
66 import java.awt.event.ActionEvent;
67 import java.awt.event.ComponentEvent;
68 import java.awt.event.ComponentListener;
69 import java.awt.event.WindowAdapter;
70 import java.awt.event.WindowEvent;
71
72 /**
73 * Simple main application for ext:config:ui usage
74 *
75 * @author volker john [volkerj at jxta dot org]
76 * @version
77 * @created May 12, 2004
78 */
79 public class UIConfigurator extends WindowAdapter {
80
81 private static final String DESCRIPTOR = "net/jxta/ext/config/ui/resource/Configurator.xml";
82 private static UIConfigurator sxc;
83 private static SwingEngine swix;
84
85 /**
86 * Invoked when a window is in the process of being closed.
87 * The close operation can be overridden at this point.
88 */
89 public void windowClosing(WindowEvent e) {
90 super.windowClosing(e);
91 System.exit(0);
92 }
93
94 public static void main(String[] args) {
95 sxc = new UIConfigurator();
96 swix = new SwingEngine(sxc);
97 try {
98 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
99 JFrame cfg = (JFrame) swix.render(UIConfigurator.DESCRIPTOR);
100 init(cfg);
101 cfg.setVisible(true);
102 } catch (Exception ex) {
103 ex.printStackTrace();
104 }
105 }
106
107 /**
108 * @param cfg
109 */
110 private static void init(JFrame cfg) {
111 swix.setActionListener(cfg, new ConfiguratorListener(swix));
112 cfg.addWindowListener(sxc);
113 JTree tree = (JTree) swix.find("id_cfgtree");
114 tree.addTreeSelectionListener(new PeerTreeSelectionListener(swix));
115
116 JPanel tcpcard = (JPanel) swix.find("id_cfgtcpcard");
117
118 tcpcard.addComponentListener(
119 new ComponentListener() {
120
121 public void componentHidden(ComponentEvent e) {
122 }
123
124 public void componentMoved(ComponentEvent e) {
125 }
126
127 public void componentResized(ComponentEvent e) {
128
129 JPanel card = (JPanel) e.getSource();
130
131 JTable table = (JTable) swix.find("id_cfgtcptransporttable");
132 JPanel panel = (JPanel) swix.find("id_cfgtcptransport");
133 JScrollPane pane = (JScrollPane) swix.find("id_cfgtcpscrollpane");
134
135 Insets insets = pane.getInsets();
136
137 int height = card.getHeight() - panel.getHeight() - insets.top - insets.bottom;
138
139 int width = panel.getWidth() - insets.left - insets.right;
140 Dimension size = new Dimension(width, height);
141
142 pane.setPreferredSize(size);
143 pane.revalidate();
144 card.validate();
145
146 }
147
148 public void componentShown(ComponentEvent e) {
149 this.componentResized(e);
150 }
151
152 });
153
154 JPanel httpcard = (JPanel) swix.find("id_cfghttpcard");
155
156 httpcard.addComponentListener(
157 new ComponentListener() {
158
159 public void componentHidden(ComponentEvent e) {
160 }
161
162 public void componentMoved(ComponentEvent e) {
163 }
164
165 public void componentResized(ComponentEvent e) {
166
167 JPanel card = (JPanel) e.getSource();
168
169 JTable table = (JTable) swix.find("id_cfghttptransporttable");
170 JPanel panel = (JPanel) swix.find("id_cfghttptransport");
171 JScrollPane pane = (JScrollPane) swix.find("id_cfghttpscrollpane");
172
173 Insets insets = pane.getInsets();
174
175 int height = card.getHeight() - panel.getHeight() - insets.top - insets.bottom;
176
177 int width = panel.getWidth() - insets.left - insets.right;
178 Dimension size = new Dimension(width, height);
179
180 pane.setPreferredSize(size);
181 pane.revalidate();
182 card.validate();
183
184 }
185
186 public void componentShown(ComponentEvent e) {
187 this.componentResized(e);
188 }
189
190 });
191
192 }
193
194 }