Annotation of FM2SQL/MultiResultWindow.java, revision 1.1
1.1 ! rogo 1: import javax.swing.*;
! 2: import java.util.*;
! 3: import java.awt.event.*;
! 4: import java.awt.*;
! 5: import java.text.*;
! 6: import java.io.*;
! 7: /**
! 8: *
! 9: * ResultWindow - used to display the results of the query
! 10: *
! 11: * @author rogo
! 12: */
! 13:
! 14: public class MultiResultWindow extends JDialog
! 15: {
! 16: /**
! 17: * FM reference
! 18: */
! 19: JFrame fm;
! 20: /**
! 21: * TableComponent instance used to display the data
! 22: */
! 23: TableComponent table = new TableComponent();
! 24: /**
! 25: * Vector for mutltiple TableComponents
! 26: */
! 27:
! 28: Vector tables = new Vector();
! 29: JTabbedPane pane = new JTabbedPane();
! 30: /**
! 31: * window title
! 32: */
! 33: String title = "";
! 34: boolean update = true;
! 35: int oldWidth = 0;
! 36: int oldHeight = 0;
! 37: int oldTabCount = 0;
! 38: static int counter = 0;
! 39: /**
! 40: * Constructs the result Window with the JFrame argument as parent
! 41: * @param parent frame of the JDialog
! 42: */
! 43: public MultiResultWindow(JFrame frame)
! 44: {
! 45: super(frame);
! 46: fm = (JFrame) frame;
! 47: getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
! 48: // pane.addTab("no Name",table);
! 49: getContentPane().add(pane);
! 50: // getContentPane().setBackground(Color.white);
! 51: addComponentListener(new ComponentAdapter()
! 52: {
! 53: public void componentResized(ComponentEvent e)
! 54: {
! 55:
! 56: // System.out.println("Window resized " + getWidth() + " " + getHeight());
! 57:
! 58: setTitle("show Tables");
! 59: //if(table.tableScroller.getPreferredSize().width<getWidth())
! 60: //table.repaint();
! 61:
! 62: if (oldWidth != getWidth() || oldHeight != getHeight() || oldTabCount != pane.getTabRunCount())
! 63: {
! 64:
! 65: for (int i = 0; i < tables.size(); ++i)
! 66: {
! 67: table = (TableComponent) tables.get(i);
! 68: table.sizeToFit(getWidth(), getHeight());
! 69: // table.setEnabled(false);
! 70: Dimension dim = table.table.getPreferredSize();
! 71: oldTabCount = pane.getTabRunCount();
! 72: // System.out.println("correction " + (pane.getTabRunCount() * 19) + " " + pane.getBoundsAt(0));
! 73: int correction = getHeight() - (pane.getTabRunCount() * pane.getBoundsAt(0).height) - new JScrollBar().getPreferredSize().height;
! 74:
! 75: //table.tableScroller.setSize(new Dimension(getWidth() - 30,correction-15 ));
! 76: table.tableScroller.setPreferredSize(new Dimension(getWidth() - 30, correction));
! 77: Dimension d2 = table.tableScroller.getPreferredSize();
! 78: // System.out.println("runs faster" + pane.getTabRunCount() + " " + d2 + " " + getHeight() + " " + ((double) (d2.height) / ((double) getHeight()) * 100) + " pane height " + pane.getPreferredSize());
! 79: table.setPreferredSize(new Dimension(d2.width + 10, d2.height + 5));
! 80: table.table.revalidate();
! 81: //table.tableScroller.revalidate();
! 82: //table.revalidate();
! 83: }
! 84: pane.revalidate();
! 85: oldWidth = getWidth();
! 86: oldHeight = getHeight();
! 87:
! 88: }
! 89: //System.out.println("runs slower "+ pane.getTabRunCount());
! 90: validate();
! 91: repaint();
! 92: // System.out.println("fit" + getWidth() + " " + oldWidth);
! 93:
! 94: }
! 95: });
! 96: // table.setEnabled(false);
! 97: update = true;
! 98: pack();
! 99: oldWidth = getWidth();
! 100: setLocation(new Point(frame.getLocation().x, frame.getLocation().y + 50));
! 101: rootPane.setOpaque(true);
! 102:
! 103: }
! 104: /**
! 105: * Fills the table component of this window with new data
! 106: */
! 107: public void updateResult(Vector data, Vector columnNames)
! 108: {
! 109: update = true;
! 110: TableComponent table = new TableComponent();
! 111: tables.add(table);
! 112: pane.addTab(title, table);
! 113: table.tableModel.setDataVector(data, columnNames);
! 114: Dimension d2 = table.tableScroller.getPreferredSize();
! 115: Dimension dim = table.table.getPreferredSize();
! 116: // System.out.println("here"+dim.width+" "+getWidth()+" "+d2.width+" "+table.table.getScrollableTracksViewportHeight());
! 117: //pack();
! 118: // table.repaint();
! 119:
! 120: }
! 121: /**
! 122: * exports the current results to HTML
! 123: * @param query that produced the result
! 124: * @return StringBuffer containing the HTML code
! 125: */
! 126: public StringBuffer exportQueryToHTML(String query)
! 127: {
! 128: if (query == "")
! 129: query = title;
! 130: StringBuffer buff = new StringBuffer();
! 131: buff.append("<html>");
! 132: buff.append("<head>");
! 133: buff.append("<title>");
! 134: buff.append(query);
! 135: buff.append("</title>");
! 136: buff.append("</head>");
! 137:
! 138: buff.append("<body>");
! 139: buff.append("<center>");
! 140: buff.append("<h3>");
! 141: buff.append(query);
! 142: buff.append("</h3>");
! 143: buff.append(table.exportToHTML());
! 144: buff.append("</body>");
! 145: buff.append("</html>");
! 146: return TableComponent.convertUml(buff);
! 147: }
! 148: /**
! 149: * Actual write the result to a file( in HTML)
! 150: */
! 151: public String writeResult()
! 152: {
! 153:
! 154: String name = "";
! 155: try
! 156: {
! 157: NumberFormat nf = new DecimalFormat("0000");
! 158: name = "./html/query" + nf.format(counter++) + ".html";
! 159: FileWriter file = new FileWriter(new File(name));
! 160: file.write(exportQueryToHTML(title).toString());
! 161: file.close();
! 162: } catch (Exception e)
! 163: {
! 164: System.out.println("Error while writing html\n" + e);
! 165: }
! 166: return name;
! 167: }
! 168: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>