1 | /**
|
---|
2 | * Title: <p>
|
---|
3 | * Description: <p>
|
---|
4 | * Copyright: Copyright (c) <p>
|
---|
5 | * Company: <p>
|
---|
6 | * @author
|
---|
7 | * @version 1.0
|
---|
8 | */
|
---|
9 | package vishnu.testvis.visual;
|
---|
10 | import javax.swing.*;
|
---|
11 | import javax.swing.event.*;
|
---|
12 | import java.io.*;
|
---|
13 | import java.util.Date;
|
---|
14 |
|
---|
15 | import javax.swing.JPanel;
|
---|
16 | import java.awt.*;
|
---|
17 | import javax.swing.border.*;
|
---|
18 | import java.awt.event.*;
|
---|
19 |
|
---|
20 | public class PlainPanel extends JPanel
|
---|
21 | {
|
---|
22 | Vishnu displayFrame;
|
---|
23 | BorderLayout borderLayout1;
|
---|
24 | Border border1;
|
---|
25 | JScrollPane theScrollPane;
|
---|
26 | JEditorPane theEditorPane;
|
---|
27 |
|
---|
28 |
|
---|
29 | // This method returns an HTML table
|
---|
30 | public String makeHTMLTable()
|
---|
31 | {
|
---|
32 | String [] descriptions = displayFrame.dataManager.getDescriptions();
|
---|
33 | int [] docNums = displayFrame.dataManager.getDocs();
|
---|
34 | // Set up an output stream we can print the table to.
|
---|
35 | // This is easier than concatenating strings all the time.
|
---|
36 | int number;
|
---|
37 | if (docNums==null) number = 0;
|
---|
38 | else number = docNums.length;
|
---|
39 |
|
---|
40 | StringWriter sout = new StringWriter();
|
---|
41 | PrintWriter out = new PrintWriter(sout);
|
---|
42 |
|
---|
43 | // Print out the table
|
---|
44 | Dimension d = displayFrame.getSize();
|
---|
45 | int totalWidth = d.width-40;
|
---|
46 | int textWidth = totalWidth - 100;
|
---|
47 |
|
---|
48 | out.println("<TABLE BORDER= 2 WIDTH=" + totalWidth + "><TR>");
|
---|
49 |
|
---|
50 | out.println("<TH WIDTH= 100>Document Number</TH>");
|
---|
51 | out.println("<TH WIDTH = " + textWidth + ">Sample Text</TH></TR>");
|
---|
52 |
|
---|
53 | for(int i=0; i < docNums.length; i++)
|
---|
54 | {
|
---|
55 | out.print("<TR><TD><A HREF=\"");
|
---|
56 | out.print(docNums[i]);
|
---|
57 | out.print("\">");
|
---|
58 | out.print(docNums[i]);
|
---|
59 | out.print("</A></TD><TD>");
|
---|
60 | out.print(descriptions [i]);
|
---|
61 | out.println("</TD></TR>");
|
---|
62 | }
|
---|
63 | out.println("</TABLE>");
|
---|
64 | out.close();
|
---|
65 |
|
---|
66 | // Get the string of HTML from the StringWriter and return it.
|
---|
67 | return sout.toString();
|
---|
68 | }
|
---|
69 |
|
---|
70 | public PlainPanel()
|
---|
71 | {
|
---|
72 | try
|
---|
73 | {
|
---|
74 | jbInit();
|
---|
75 | }
|
---|
76 | catch(Exception e)
|
---|
77 | {
|
---|
78 | e.printStackTrace();
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | public PlainPanel(Vishnu d)
|
---|
84 | {
|
---|
85 | displayFrame = d;
|
---|
86 | try
|
---|
87 | {
|
---|
88 | jbInit();
|
---|
89 | }
|
---|
90 | catch(Exception e)
|
---|
91 | {
|
---|
92 | e.printStackTrace();
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | // The sychronized qualifier is placed here because when two plain
|
---|
98 | // panels are created in different threads almost simulataniously
|
---|
99 | // we seem to get interference happening
|
---|
100 | public synchronized void jbInit() throws Exception
|
---|
101 | {
|
---|
102 | borderLayout1 = new BorderLayout();
|
---|
103 | theEditorPane = new JEditorPane();
|
---|
104 |
|
---|
105 | border1 = BorderFactory.createEmptyBorder(10,10,10,10);
|
---|
106 | theEditorPane.setEditable(false); // we're browsing not editing
|
---|
107 | theEditorPane.setContentType("text/html"); // must specify HTML text
|
---|
108 | theEditorPane.setText("<TABLE BORDER= 2 WIDTH=640><TR>"+
|
---|
109 | "<TH WIDTH= 100>Document Number</TH>" +
|
---|
110 | "<TH WIDTH = 520>Sample Text</TH></TR>" +
|
---|
111 | "</TABLE>"); // specify the text to display
|
---|
112 | theEditorPane.setFont(new java.awt.Font("Monospaced", 0, 12));
|
---|
113 | // Set up the JEditorPane to handle clicks on hyperlinks
|
---|
114 | theEditorPane.addHyperlinkListener(new HyperlinkListener() {
|
---|
115 | public void hyperlinkUpdate(HyperlinkEvent e)
|
---|
116 | {
|
---|
117 | // Handle clicks; ignore mouseovers and other link-related events
|
---|
118 | if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
|
---|
119 | {
|
---|
120 | // Get the HREF of the link and display it.
|
---|
121 | String hpresult = e.getDescription();
|
---|
122 | int index = Integer.parseInt(hpresult);
|
---|
123 | if (index > 0)
|
---|
124 | displayFrame.dataManager.fetchDocNo(index);
|
---|
125 | }
|
---|
126 | }
|
---|
127 | });
|
---|
128 |
|
---|
129 | // Put the JEditorPane in a scrolling window and display it.
|
---|
130 |
|
---|
131 | this.setLayout(borderLayout1);
|
---|
132 | this.setFont(new java.awt.Font("Monospaced", 0, 12));
|
---|
133 | this.setBorder(border1);
|
---|
134 | theScrollPane = new JScrollPane();
|
---|
135 | //theScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
---|
136 | this.add(theScrollPane, BorderLayout.CENTER);
|
---|
137 | theScrollPane.getViewport().add(theEditorPane, null);
|
---|
138 | setSize(600, 400);
|
---|
139 | setVisible(true);
|
---|
140 | }
|
---|
141 |
|
---|
142 | public void update()
|
---|
143 | {
|
---|
144 | theEditorPane.setText(makeHTMLTable());
|
---|
145 | }
|
---|
146 |
|
---|
147 | public void paint(Graphics g)
|
---|
148 | {
|
---|
149 | update();
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | }
|
---|