001: package com.sun.portal.netlet.client.common;
002:
003: import com.sun.portal.netlet.client.common.ResourceProperties;
004:
005: import javax.swing.*;
006: import java.awt.*;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009: import java.awt.event.WindowAdapter;
010: import java.awt.event.WindowEvent;
011: import java.util.Enumeration;
012: import java.util.Hashtable;
013: import java.util.Vector;
014:
015: public class PortInfoDialog extends Frame implements ActionListener {
016:
017: Hashtable clientPorts = null;
018: int noEntries = 0;
019: Button b = null;
020: TextField t = null;
021: Panel p = null;
022: Panel mainPanel = null;
023:
024: public PortInfoDialog(Frame f, Hashtable clientPorts) {
025: // super(f);
026: setTitle(ResourceProperties.getString("portinfo.1"));
027: this .clientPorts = clientPorts;
028: init();
029: }
030:
031: public void init() {
032:
033: int numCols = 3;
034:
035: GridBagLayout gb = new GridBagLayout();
036: GridBagConstraints gc = new GridBagConstraints();
037:
038: setLayout(gb);
039: setBackground(new Color(192, 192, 192));
040: setResizable(false);
041:
042: mainPanel = new Panel();
043: mainPanel.setLayout(new GridLayout(0, numCols));
044:
045: GridBagLayout gbo = new GridBagLayout();
046: Panel outerPanel = new Panel(gbo);
047:
048: Panel headerPanel = new Panel();
049: headerPanel.setLayout(new GridLayout(0, numCols));
050:
051: // Add the headers
052: t = new TextField(ResourceProperties.getString("portinfo.2"),
053: 20);
054: t.setEditable(false);
055: t.setBackground(new Color(192, 192, 192));
056: headerPanel.add(t);
057:
058: t = new TextField(ResourceProperties.getString("portinfo.3"),
059: 20);
060: t.setEditable(false);
061: t.setBackground(new Color(192, 192, 192));
062: headerPanel.add(t);
063:
064: t = new TextField(ResourceProperties.getString("portinfo.4"),
065: 20);
066: t.setEditable(false);
067: t.setBackground(new Color(192, 192, 192));
068: headerPanel.add(t);
069:
070: ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
071: int height = 1;
072: sp.setSize(new Dimension(500, height * 30));
073:
074: gc.gridx = 0;
075: gc.gridy = 0;
076: sp.add(headerPanel);
077: gbo.setConstraints(sp, gc);
078: outerPanel.add(sp);
079:
080: sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
081: height = getNoEntries() < 4 ? getNoEntries() : 4;
082: System.out.println("Number of entries : " + noEntries);
083: sp.setSize(new Dimension(500, height * 30));
084:
085: // Add the entries
086: Enumeration ruleNames = clientPorts.keys();
087: while (ruleNames.hasMoreElements()) {
088: String ruleName = (String) ruleNames.nextElement();
089: Vector v = (Vector) clientPorts.get(ruleName);
090: Enumeration values = v.elements();
091: while (values.hasMoreElements()) {
092: String s = (String) values.nextElement();
093: if (s.indexOf(":") != -1) {
094: String targetPort = s.substring(0, s.indexOf(":"));
095: String clientPort = s.substring(s.indexOf(":") + 1);
096:
097: t = new TextField(ruleName, 20);
098: t.setBackground(Color.white);
099: t.setEditable(false);
100: mainPanel.add(t);
101:
102: t = new TextField(targetPort, 20);
103: t.setBackground(Color.white);
104: t.setEditable(false);
105: mainPanel.add(t);
106:
107: t = new TextField(clientPort, 20);
108: t.setBackground(Color.white);
109: t.setEditable(false);
110: mainPanel.add(t);
111: }
112: }
113: }
114:
115: gc.gridx = 0;
116: gc.gridy = 1;
117: sp.add(mainPanel);
118: gbo.setConstraints(sp, gc);
119: outerPanel.add(sp);
120: add(outerPanel);
121:
122: p = new Panel(new FlowLayout(FlowLayout.CENTER));
123: Button b = new Button(ResourceProperties
124: .getString("portinfo.5"));
125: b.setActionCommand("Close");
126: b.addActionListener(this );
127: p.add(b);
128:
129: gc.gridx = 0;
130: gc.gridy = 2;
131: gb.setConstraints(p, gc);
132: add(p);
133:
134: b.requestFocus();
135: pack();
136:
137: Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
138: Point pt = new Point();
139: pt.x = (d.width / 6);
140: pt.y = (d.height / 6);
141: setLocation(pt);
142:
143: addWindowListener(new WindowAdapter() {
144: public void windowClosing(WindowEvent we) {
145: setVisible(false);
146: dispose();
147: }
148: });
149: }
150:
151: public int getNoEntries() {
152: if (noEntries != 0) {
153: return noEntries;
154: }
155: Enumeration ruleNames = clientPorts.keys();
156: while (ruleNames.hasMoreElements()) {
157: String ruleName = (String) ruleNames.nextElement();
158: Vector v = (Vector) clientPorts.get(ruleName);
159: Enumeration values = v.elements();
160: while (values.hasMoreElements()) {
161: String s = (String) values.nextElement();
162: ++noEntries;
163: }
164: }
165: return noEntries;
166: }
167:
168: public void actionPerformed(ActionEvent ae) {
169: System.out.println("Source = " + ae.getSource());
170: if (ae.getSource() instanceof Button) {
171: if ("Close".equals(ae.getActionCommand())) {
172: hide();
173: dispose();
174: }
175: }
176: }
177: }
|