001: /*
002: * MCS Media Computer Software Copyright (c) 2006 by MCS
003: * -------------------------------------- Created on 18.09.2006 by w.klaas
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
006: * use this file except in compliance with the License. You may obtain a copy of
007: * the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014: * License for the specific language governing permissions and limitations under
015: * the License.
016: */
017: /**
018: *
019: */package de.mcs.jmeasurement.gui;
020:
021: import java.awt.BorderLayout;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024:
025: import javax.swing.JButton;
026: import javax.swing.JDialog;
027: import javax.swing.JEditorPane;
028: import javax.swing.JFrame;
029: import javax.swing.JPanel;
030: import javax.swing.JScrollPane;
031: import javax.swing.text.html.HTMLEditorKit;
032:
033: import de.mcs.jmeasurement.MeasureData;
034: import de.mcs.jmeasurement.MeasurePoint;
035:
036: /**
037: * This is a dialog to show i single measure point as HTML.
038: *
039: * @author w.klaas
040: *
041: */
042: public class PointDataDialog extends JDialog {
043: /**
044: *
045: */
046: private static final long serialVersionUID = 1L;
047:
048: /** the point to show. */
049: private MeasurePoint point;
050:
051: /** content pane. */
052: private JPanel contentPane;
053:
054: /** the main text control, showing html. */
055: private JEditorPane text;
056:
057: /**
058: * constructing a dialog showing the measure data of a point.
059: *
060: * @param aPoint
061: * the point to show.
062: */
063: public PointDataDialog(final MeasurePoint aPoint) {
064: super ();
065: this .point = aPoint;
066: initialize();
067: setMeasurePoint(aPoint);
068: }
069:
070: /**
071: * This method initializes this.
072: *
073: */
074: private void initialize() {
075: this .setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
076: this .setContentPane(getJContentPane());
077: this .setTitle(Messages
078: .getString("ReportViewer.POINTDIALOG.TITLE")); //$NON-NLS-1$
079: }
080:
081: /**
082: * This method initializes jContentPane.
083: *
084: * @return javax.swing.JPanel
085: */
086: private JPanel getJContentPane() {
087: if (contentPane == null) {
088: contentPane = new JPanel();
089: contentPane.setLayout(new BorderLayout());
090: text = new JEditorPane();
091: text.setEditable(false);
092: JScrollPane scrollPane = new JScrollPane(text);
093: contentPane.add(scrollPane, BorderLayout.CENTER);
094: JPanel bottom = new JPanel();
095: bottom.setLayout(new BorderLayout());
096: contentPane.add(bottom, BorderLayout.SOUTH);
097: JButton btexit = new JButton("Exit");
098: bottom.add(btexit, BorderLayout.CENTER);
099: btexit.addActionListener(new ActionListener() {
100:
101: public void actionPerformed(final ActionEvent e) {
102: setVisible(false);
103: }
104:
105: });
106: }
107: return contentPane;
108: }
109:
110: /**
111: * setitng the actual measure point. Filling the html component with the
112: * html representation of the point data.
113: *
114: * @param aPoint
115: * the point to show.
116: */
117: public final void setMeasurePoint(final MeasurePoint aPoint) {
118: this .point = aPoint;
119: this
120: .setTitle(Messages
121: .getString("ReportViewer.POINTDIALOG.TITLE") + " " + point.getName()); //$NON-NLS-1$
122: StringBuffer buf = new StringBuffer();
123: buf.append("<html><h1 align=\"center\"><u>MeasurePoint ");
124: buf.append(point.getName());
125: buf.append("</u></h1>\r\n");
126: buf.append("<table border=\"1\" width=\"100%\">");
127: MeasureData[] datas = point.getData();
128: for (int i = 0; i < datas.length; i++) {
129: MeasureData data = datas[i];
130: buf.append("<tr><td align=\"right\" width=\"10%\">");
131: buf.append(data.getName());
132: buf.append("</td><td>");
133: buf.append(data.getAsString());
134: buf.append("</td></tr>\r\n");
135: }
136: buf.append("</table>");
137: buf.append("</html>");
138: text.setEditorKit(new HTMLEditorKit());
139: text.setText(buf.toString());
140: text.setCaretPosition(0);
141:
142: }
143: }
|