Annotation of FM2SQL/ResultWindow.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 ResultWindow 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:    * window title
        !            26:    */
        !            27:   String title = "";
        !            28:   boolean update = true;
        !            29:   int oldWidth = 0;
        !            30:   int oldHeight = 0;
        !            31:   static int counter = 0;
        !            32:   /**
        !            33:    * Constructs  the result Window with the JFrame argument as parent 
        !            34:    * @param parent frame of the JDialog  
        !            35:    */
        !            36:   public ResultWindow(JFrame frame)
        !            37:   {
        !            38:     super(frame);
        !            39:     fm = (JFrame) frame;
        !            40:     getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
        !            41:     getContentPane().add(table);
        !            42:     // getContentPane().setBackground(Color.white);
        !            43:     addComponentListener(new ComponentAdapter()
        !            44:     {
        !            45:       public void componentResized(ComponentEvent e)
        !            46:       {
        !            47: 
        !            48:         // System.out.println("Window resized " + getWidth() + " " + getHeight());
        !            49: 
        !            50:         setTitle(title);
        !            51:         //if(table.tableScroller.getPreferredSize().width<getWidth())
        !            52: 
        !            53:         //table.repaint();
        !            54:         if (oldWidth != getWidth() || oldHeight != getHeight())
        !            55:         {
        !            56:           table.sizeToFit(getWidth(), getHeight());
        !            57: 
        !            58:           Dimension dim = table.table.getPreferredSize();
        !            59: 
        !            60:           table.tableScroller.setPreferredSize(new Dimension(getWidth() - 15, getHeight() - 45));
        !            61:           Dimension d2 = table.tableScroller.getPreferredSize();
        !            62: 
        !            63:           oldWidth = getWidth();
        !            64:           oldHeight = getHeight();
        !            65:           //   System.out.println("fit" + getWidth() + " " + oldWidth);
        !            66:           //table.table.setPreferredScrollableViewportSize(dim);
        !            67: 
        !            68:           table.setPreferredSize(new Dimension(d2.width + 10, d2.height + 5));
        !            69:           table.table.revalidate();
        !            70:           table.tableScroller.revalidate();
        !            71:           table.revalidate();
        !            72:           int size = (table.tableScroller.getHorizontalScrollBar().isVisible()) ? 90 : 70;
        !            73:           if (getHeight() > table.table.getPreferredSize().height + size)
        !            74:             setSize(getWidth(), table.table.getHeight() + size+5);
        !            75:             //
        !            76:         }
        !            77: 
        !            78:         //  System.out.println("fit" + getWidth() + " " + oldWidth);
        !            79: 
        !            80:       }
        !            81:     });
        !            82:     table.setEnabled(false);
        !            83:     update = true;
        !            84:     pack();
        !            85:     oldWidth = getWidth();
        !            86:     setLocation(new Point(frame.getLocation().x, frame.getLocation().y + 50));
        !            87:     rootPane.setOpaque(false);
        !            88: 
        !            89:   }
        !            90:   /**
        !            91:    * Fills the table component of this window with new data
        !            92:    */
        !            93:   public void updateResult(Vector data, Vector columnNames)
        !            94:   {
        !            95:     update = true;
        !            96:     table.tableModel.setDataVector(data, columnNames);
        !            97:     Dimension d2 = table.tableScroller.getPreferredSize();
        !            98:     Dimension dim = table.table.getPreferredSize();
        !            99:     //System.out.println("here"+dim.width+" "+getWidth()+" "+d2.width+" "+table.table.getScrollableTracksViewportHeight());
        !           100:     if (dim.width > getWidth())
        !           101:     {
        !           102:       //table.vergroessern(getWidth(),getHeight());
        !           103:       oldWidth = dim.width * 3;
        !           104:       oldHeight = (dim.height >= table.screenSize.height) ? table.screenSize.height : dim.height + table.table.getTableHeader().getHeight() * 2; //32;
        !           105: 
        !           106:     } else
        !           107:     {
        !           108:       // table.sizeToFit(getWidth(),getHeight());
        !           109:       // table.sizeToFit(dim.width * 3, getHeight());
        !           110:       /*  // table.table.setSize(dim.width * 3,dim.height);
        !           111:          table.tableScroller.setPreferredSize(new Dimension((dim.width*3), dim.height+23));
        !           112:          d2 = table.tableScroller.getPreferredSize();
        !           113:           // table.table.setPreferredScrollableViewportSize(table.table.getSize());
        !           114:         dim = table.table.getPreferredSize();
        !           115:          table.setPreferredSize(new Dimension(d2.width+10,d2.height+3));
        !           116:          table.tableScroller.validate();
        !           117:          table.validate(); 
        !           118:        // setSize(dim.width, dim.height + 40);
        !           119:           oldWidth = d2.width+10;
        !           120:        oldHeight=d2.height+3; 
        !           121:          System.out.println("here"+dim.width+" "+getWidth()+" "+d2.width+" "+table.table.getPreferredScrollableViewportSize());
        !           122:         */
        !           123:       oldWidth = dim.width;
        !           124:       oldHeight = (dim.height >= table.screenSize.height) ? table.screenSize.height : dim.height + table.table.getTableHeader().getHeight() * 2;
        !           125:       setSize(dim.width, oldHeight);
        !           126:     }
        !           127: 
        !           128:     oldWidth = getWidth();
        !           129:     oldHeight = getHeight();
        !           130:     pack();
        !           131:     // table.repaint();
        !           132: 
        !           133:   }
        !           134:   /**
        !           135:    * exports the current results to HTML
        !           136:    * @param query that produced the result  
        !           137:    * @return StringBuffer containing the HTML code
        !           138:    */
        !           139:   public StringBuffer exportQueryToHTML(String query)
        !           140:   {
        !           141:     if (query == "")
        !           142:       query = title;
        !           143:     StringBuffer buff = new StringBuffer();
        !           144:     buff.append("<html>");
        !           145:     buff.append("<head>");
        !           146:     buff.append("<title>");
        !           147:     buff.append(query);
        !           148:     buff.append("</title>");
        !           149:     buff.append("</head>");
        !           150: 
        !           151:     buff.append("<body>");
        !           152:     buff.append("<center>");
        !           153:     buff.append("<h3>");
        !           154:     buff.append(query);
        !           155:     buff.append("</h3>");
        !           156:     buff.append(table.exportToHTML());
        !           157:     buff.append("</body>");
        !           158:     buff.append("</html>");
        !           159:     return TableComponent.convertUml(buff);
        !           160:   }
        !           161:   /**
        !           162:    * Actual write the result to a file( in HTML)
        !           163:    */
        !           164:   public String writeResult()
        !           165:   {
        !           166: 
        !           167:     String name = "";
        !           168:     try
        !           169:     {
        !           170:       NumberFormat nf = new DecimalFormat("0000");
        !           171:       name = "./html/query" + nf.format(counter++) + ".html";
        !           172:       FileWriter file = new FileWriter(new File(name));
        !           173:       file.write(exportQueryToHTML(title).toString());
        !           174:       file.close();
        !           175:     } catch (Exception e)
        !           176:     {
        !           177:       System.out.println("Error while writing html\n" + e);
        !           178:     }
        !           179:     return name;
        !           180:   }
        !           181: }

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