File:  [Repository] / FM2SQL / Attic / MultiResultWindow.java
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Tue Mar 23 11:57:06 2004 UTC (20 years, 3 months ago) by rogo
Branches: MAIN
CVS tags: HEAD
GPL Disclaimer

    1: /*
    2:  * MultiResultWindow.java -- Display results from several tables in one Window
    3:  * FileMaker to SQL Converter 
    4:  * Copyright (C) 2003 Robert Gordesch (rogo@mpiwg-berlin.mpg.de) 
    5:  * This program is free software; you can redistribute it and/or modify it
    6:  * under the terms of the GNU General Public License as published by the Free
    7:  * Software Foundation; either version 2 of the License, or (at your option)
    8:  * any later version.  Please read license.txt for the full details. A copy of
    9:  * the GPL may be found at http://www.gnu.org/copyleft/lgpl.html  You should
   10:  * have received a copy of the GNU General Public License along with this
   11:  * program; if not, write to the Free Software Foundation, Inc., 59 Temple
   12:  * Place, Suite 330, Boston, MA 02111-1307 USA  Created on 15.09.2003 by
   13:  * rogo  
   14:  */
   15: 
   16: import javax.swing.*;
   17: import java.util.*;
   18: import java.awt.event.*;
   19: import java.awt.*;
   20: import java.text.*;
   21: import java.io.*;
   22: /**
   23:  * 
   24:  * ResultWindow - used to display the results of the query
   25:  * 
   26:  *  @author rogo
   27:  */
   28: 
   29: public class MultiResultWindow extends JDialog
   30: {
   31:   /**
   32:    * FM reference 
   33:    */
   34:   JFrame fm;
   35:   /**
   36:    * TableComponent instance used to display the data
   37:    */
   38:   TableComponent table = new TableComponent();
   39:   /**
   40:    * Vector for mutltiple TableComponents 
   41:    */
   42: 
   43:   Vector tables = new Vector();
   44:   JTabbedPane pane = new JTabbedPane();
   45:   /**
   46:    * window title
   47:    */
   48:   String title = "";
   49:   boolean update = true;
   50:   int oldWidth = 0;
   51:   int oldHeight = 0;
   52:   int oldTabCount = 0;
   53:   static int counter = 0;
   54:   /**
   55:    * Constructs  the result Window with the JFrame argument as parent 
   56:    * @param parent frame of the JDialog  
   57:    */
   58:   public MultiResultWindow(JFrame frame)
   59:   {
   60:     super(frame);
   61:     fm = (JFrame) frame;
   62:     getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
   63:     //  pane.addTab("no Name",table);
   64:     getContentPane().add(pane);
   65:     // getContentPane().setBackground(Color.white);
   66:     addComponentListener(new ComponentAdapter()
   67:     {
   68:       public void componentResized(ComponentEvent e)
   69:       {
   70: 
   71:         // System.out.println("Window resized " + getWidth() + " " + getHeight());
   72: 
   73:         setTitle("show Tables");
   74:         //if(table.tableScroller.getPreferredSize().width<getWidth())
   75:         //table.repaint();
   76: 
   77:         if (oldWidth != getWidth() || oldHeight != getHeight() || oldTabCount != pane.getTabRunCount())
   78:         {
   79: 
   80:           for (int i = 0; i < tables.size(); ++i)
   81:           {
   82:             table = (TableComponent) tables.get(i);
   83:             table.sizeToFit(getWidth(), getHeight());
   84:            // table.setEnabled(false);
   85:             Dimension dim = table.table.getPreferredSize();
   86:             oldTabCount = pane.getTabRunCount();
   87:           //  System.out.println("correction " + (pane.getTabRunCount() * 19) + " " + pane.getBoundsAt(0));
   88:             int correction = getHeight() - (pane.getTabRunCount() * pane.getBoundsAt(0).height) - new JScrollBar().getPreferredSize().height;
   89: 
   90:             //table.tableScroller.setSize(new Dimension(getWidth() - 30,correction-15 ));
   91:             table.tableScroller.setPreferredSize(new Dimension(getWidth() - 30, correction));
   92:             Dimension d2 = table.tableScroller.getPreferredSize();
   93:          //   System.out.println("runs faster" + pane.getTabRunCount() + " " + d2 + " " + getHeight() + " " + ((double) (d2.height) / ((double) getHeight()) * 100) + " pane height " + pane.getPreferredSize());
   94:             table.setPreferredSize(new Dimension(d2.width + 10, d2.height + 5));
   95:             table.table.revalidate();
   96:             //table.tableScroller.revalidate();
   97:             //table.revalidate();
   98:           }
   99: 					pane.revalidate();
  100: 			    oldWidth = getWidth();
  101: 				  oldHeight = getHeight();
  102:        
  103:         }
  104:         //System.out.println("runs slower "+ pane.getTabRunCount());
  105:         validate();
  106:         repaint();
  107:         //  System.out.println("fit" + getWidth() + " " + oldWidth);
  108: 
  109:       }
  110:     });
  111:    // table.setEnabled(false);
  112:     update = true;
  113:     pack();
  114:     oldWidth = getWidth();
  115:     setLocation(new Point(frame.getLocation().x, frame.getLocation().y + 50));
  116:     rootPane.setOpaque(true);
  117: 
  118:   }
  119:   /**
  120:    * Fills the table component of this window with new data
  121:    */
  122:   public void updateResult(Vector data, Vector columnNames)
  123:   {
  124:     update = true;
  125:     TableComponent table = new TableComponent();
  126:     tables.add(table);
  127:     pane.addTab(title, table);
  128:     table.tableModel.setDataVector(data, columnNames);
  129:     Dimension d2 = table.tableScroller.getPreferredSize();
  130:     Dimension dim = table.table.getPreferredSize();
  131:     //  System.out.println("here"+dim.width+" "+getWidth()+" "+d2.width+" "+table.table.getScrollableTracksViewportHeight());
  132:     //pack();
  133:     // table.repaint();
  134: 
  135:   }
  136:   /**
  137:    * exports the current results to HTML
  138:    * @param query that produced the result  
  139:    * @return StringBuffer containing the HTML code
  140:    */
  141:   public StringBuffer exportQueryToHTML(String query)
  142:   {
  143:     if (query == "")
  144:       query = title;
  145:     StringBuffer buff = new StringBuffer();
  146:     buff.append("<html>");
  147:     buff.append("<head>");
  148:     buff.append("<title>");
  149:     buff.append(query);
  150:     buff.append("</title>");
  151:     buff.append("</head>");
  152: 
  153:     buff.append("<body>");
  154:     buff.append("<center>");
  155:     buff.append("<h3>");
  156:     buff.append(query);
  157:     buff.append("</h3>");
  158:     buff.append(table.exportToHTML());
  159:     buff.append("</body>");
  160:     buff.append("</html>");
  161:     return TableComponent.convertUml(buff);
  162:   }
  163:   /**
  164:    * Actual write the result to a file( in HTML)
  165:    */
  166:   public String writeResult()
  167:   {
  168: 
  169:     String name = "";
  170:     try
  171:     {
  172:       NumberFormat nf = new DecimalFormat("0000");
  173:       name = "./html/query" + nf.format(counter++) + ".html";
  174:       FileWriter file = new FileWriter(new File(name));
  175:       file.write(exportQueryToHTML(title).toString());
  176:       file.close();
  177:     } catch (Exception e)
  178:     {
  179:       System.out.println("Error while writing html\n" + e);
  180:     }
  181:     return name;
  182:   }
  183: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>