File:  [Repository] / FM2SQL / src / ResultWindow.java
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Fri Jan 21 11:27:03 2005 UTC (21 years, 3 months ago) by rogo
Branches: MAIN
CVS tags: HEAD
moved java src to src folder

    1: /*
    2:  * ResultWindow.java -- Class show results from an db query
    3:  * Filemake to SQL Converter 
    4:  * Copyright (C) 2004 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: import javax.swing.*;
   16: import java.util.*;
   17: import java.awt.event.*;
   18: import java.awt.*;
   19: import java.text.*;
   20: import java.io.*;
   21: /**
   22:  * 
   23:  * ResultWindow - used to display the results of the query
   24:  * 
   25:  *  @author rogo
   26:  */
   27: 
   28: public class ResultWindow extends JDialog
   29: {
   30:   /**
   31:    * FM reference 
   32:    */
   33:   JFrame fm;
   34:   /**
   35:    * TableComponent instance used to display the data
   36:    */
   37:   TableComponent table = new TableComponent();
   38:   /**
   39:    * window title
   40:    */
   41:   String title = "";
   42:   boolean update = true;
   43:   int oldWidth = 0;
   44:   int oldHeight = 0;
   45:   static int counter = 0;
   46:   /**
   47:    * Constructs  the result Window with the JFrame argument as parent 
   48:    * @param parent frame of the JDialog  
   49:    */
   50:   public ResultWindow(JFrame frame)
   51:   {
   52:     super(frame);
   53:     fm = (JFrame) frame;
   54:     getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
   55:     getContentPane().add(table);
   56:     // getContentPane().setBackground(Color.white);
   57:     addComponentListener(new ComponentAdapter()
   58:     {
   59:       public void componentResized(ComponentEvent e)
   60:       {
   61: 
   62:         // System.out.println("Window resized " + getWidth() + " " + getHeight());
   63: 
   64:         setTitle(title);
   65:         //if(table.tableScroller.getPreferredSize().width<getWidth())
   66: 
   67:         //table.repaint();
   68:         if (oldWidth != getWidth() || oldHeight != getHeight())
   69:         {
   70:           table.sizeToFit(getWidth(), getHeight());
   71: 
   72:           Dimension dim = table.table.getPreferredSize();
   73: 
   74:           table.tableScroller.setPreferredSize(new Dimension(getWidth() - 15, getHeight() - 45));
   75:           Dimension d2 = table.tableScroller.getPreferredSize();
   76: 
   77:           oldWidth = getWidth();
   78:           oldHeight = getHeight();
   79:           //   System.out.println("fit" + getWidth() + " " + oldWidth);
   80:           //table.table.setPreferredScrollableViewportSize(dim);
   81: 
   82:           table.setPreferredSize(new Dimension(d2.width + 10, d2.height + 5));
   83:           table.table.revalidate();
   84:           table.tableScroller.revalidate();
   85:           table.revalidate();
   86:           int size = (table.tableScroller.getHorizontalScrollBar().isVisible()) ? 90 : 70;
   87:           if (getHeight() > table.table.getPreferredSize().height + size)
   88:             setSize(getWidth(), table.table.getHeight() + size+5);
   89:             //
   90:         }
   91: 
   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(false);
  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:     table.tableModel.setDataVector(data, columnNames);
  111:     Dimension d2 = table.tableScroller.getPreferredSize();
  112:     Dimension dim = table.table.getPreferredSize();
  113:     //System.out.println("here"+dim.width+" "+getWidth()+" "+d2.width+" "+table.table.getScrollableTracksViewportHeight());
  114:     if (dim.width > getWidth())
  115:     {
  116:       //table.vergroessern(getWidth(),getHeight());
  117:       oldWidth = dim.width * 3;
  118:       oldHeight = (dim.height >= table.screenSize.height) ? table.screenSize.height : dim.height + table.table.getTableHeader().getHeight() * 2; //32;
  119: 
  120:     } else
  121:     {
  122:       // table.sizeToFit(getWidth(),getHeight());
  123:       // table.sizeToFit(dim.width * 3, getHeight());
  124:       /*  // table.table.setSize(dim.width * 3,dim.height);
  125:          table.tableScroller.setPreferredSize(new Dimension((dim.width*3), dim.height+23));
  126:          d2 = table.tableScroller.getPreferredSize();
  127:           // table.table.setPreferredScrollableViewportSize(table.table.getSize());
  128:         dim = table.table.getPreferredSize();
  129:          table.setPreferredSize(new Dimension(d2.width+10,d2.height+3));
  130:          table.tableScroller.validate();
  131:          table.validate(); 
  132:        // setSize(dim.width, dim.height + 40);
  133:           oldWidth = d2.width+10;
  134:        oldHeight=d2.height+3; 
  135:          System.out.println("here"+dim.width+" "+getWidth()+" "+d2.width+" "+table.table.getPreferredScrollableViewportSize());
  136:         */
  137:       oldWidth = dim.width;
  138:       oldHeight = (dim.height >= table.screenSize.height) ? table.screenSize.height : dim.height + table.table.getTableHeader().getHeight() * 2;
  139:       setSize(dim.width, oldHeight);
  140:     }
  141: 
  142:     oldWidth = getWidth();
  143:     oldHeight = getHeight();
  144:     pack();
  145:     // table.repaint();
  146: 
  147:   }
  148:   /**
  149:    * exports the current results to HTML
  150:    * @param query that produced the result  
  151:    * @return StringBuffer containing the HTML code
  152:    */
  153:   public StringBuffer exportQueryToHTML(String query)
  154:   {
  155:     if (query == "")
  156:       query = title;
  157:     StringBuffer buff = new StringBuffer();
  158:     buff.append("<html>");
  159:     buff.append("<head>");
  160:     buff.append("<title>");
  161:     buff.append(query);
  162:     buff.append("</title>");
  163:     buff.append("</head>");
  164: 
  165:     buff.append("<body>");
  166:     buff.append("<center>");
  167:     buff.append("<h3>");
  168:     buff.append(query);
  169:     buff.append("</h3>");
  170:     buff.append(table.exportToHTML());
  171:     buff.append("</body>");
  172:     buff.append("</html>");
  173:     return TableComponent.convertUml(buff);
  174:   }
  175:   /**
  176:    * Actual write the result to a file( in HTML)
  177:    */
  178:   public String writeResult()
  179:   {
  180: 
  181:     String name = "";
  182:     try
  183:     {
  184:       NumberFormat nf = new DecimalFormat("0000");
  185:       name = "./html/query" + nf.format(counter++) + ".html";
  186:       FileWriter file = new FileWriter(new File(name));
  187:       file.write(exportQueryToHTML(title).toString());
  188:       file.close();
  189:     } catch (Exception e)
  190:     {
  191:       System.out.println("Error while writing html\n" + e);
  192:     }
  193:     return name;
  194:   }
  195: }

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