posts - 39,  comments - 263,  trackbacks - 0

          package publictool.cellEditor;

          import java.awt.Component;
          import java.awt.Frame;
          import java.awt.HeadlessException;
          import java.awt.event.ActionEvent;
          import java.awt.event.ActionListener;
          import java.awt.event.MouseEvent;
          import java.io.File;
          import java.io.FileInputStream;
          import java.io.InputStream;
          import java.util.EventObject;

          import javax.swing.AbstractCellEditor;
          import javax.swing.JButton;
          import javax.swing.JDialog;
          import javax.swing.JFileChooser;
          import javax.swing.JTable;
          import javax.swing.table.TableCellEditor;

          import rootwindow.ValueMap;

          import com.borland.jb.io.InputStreamToByteArray;

          public class ImageCellEditor extends AbstractCellEditor implements
            TableCellEditor, ActionListener {
           // 鼠標(biāo)點(diǎn)擊次數(shù)
           public int CLICKCOUNT = 2;

           JButton button;

           // button 命令的名稱
           protected static final String EDIT = "CELLEDITOR";

           // 對(duì)話框中確定的命令要是"OK"
           protected static final String DIALOG_OK = "OK";

           // 最終的返回一個(gè)object
           Object curobject;

           // 所有的彈出式窗口都必須是Dialog的子類
           // 而且必須有g(shù)etSelectInPut
           // CellEditorDialog dialog1;

           JDialog dialog1;

           ValueMap valuemap;

           Frame frame;

           JFileChooserx jfc;

           public ImageCellEditor(Frame frame, ValueMap valuemap) {
            // super(frame, valuemap);
            init();
           }

           public void init() {
            System.out.println("sss1");
            button = new JButton();
            button.setActionCommand(EDIT);
            button.addActionListener(this);
            button.setBorderPainted(false);
            /*
             * dialog1 = new CellEditorDialog(frame, "", true, valuemap, "select
             * bcode,bname from bcode", "bname", this, null);
             */

            jfc = new JFileChooserx();
            dialog1 = jfc.createDialog(frame);
            jfc.addActionListener(this);

           }

           public Object getCellEditorValue() {

            System.out.println("3");
            return curobject;

           }

           public Component getTableCellEditorComponent(JTable table, Object value,
             boolean isSelected, int row, int column) {
            System.out.println("4");
            // curobject =jfc .getSelectedFile();
          /*
            File file = jfc.getSelectedFile();
            InputStream is = null;
            InputStreamToByteArray imputs = null;
            byte[] b = new byte[102400];
            if (file != null) {
             try {
              System.out.println("5");
              is = new FileInputStream(file);
              is.read(b);

              imputs = new InputStreamToByteArray(b);
              // imputs = (InputStreamToByteArray)is;

             } catch (Exception e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
             }
              curobject = imputs;
             //curobject = null;
            }*/
            curobject = value;
            System.out.println("value = "+value);
            System.out.println("getTableCellEditorComponent"+curobject);
            return button;

           }

           // 默認(rèn)鼠標(biāo)雙擊才可以編輯
           public boolean isCellEditable(EventObject anEvent) {
            if (anEvent instanceof MouseEvent) {
             return ((MouseEvent) anEvent).getClickCount() >= CLICKCOUNT;
            }
            return true;
           }

           /**
            * Handles events from the editor button and from the dialog's OK button.
            */
           public void actionPerformed(ActionEvent e) {
            System.out.println("command=" + e.getActionCommand());
            if (EDIT.equals(e.getActionCommand())) {
             // The user has clicked the cell, so
             // bring up the dialog.

             dialog1.setVisible(true);

             // Make the renderer reappear.
             fireEditingStopped();
             System.out.println("1");
            } else if ("ApproveSelection".equals(e.getActionCommand())) { // User
             // pressed
             // dialog's
             // "OK"
             // button.
             File file = jfc.getSelectedFile();
             if (file != null) {
              InputStream is = null;
              InputStreamToByteArray imputs = null;
              byte[] b = new byte[102400];
              try {
               System.out.println("6");
               is = new FileInputStream(file);
               // InputStreamToByteArray imputs = new
               // InputStreamToByteArray(null);
               is.read(b);
               imputs = new InputStreamToByteArray(b);
               curobject = imputs;
               // imputs = (InputStreamToByteArray)is;
               // b = new byte[1024];
               // is.read(b);
              } catch (Exception e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
              }
             }
             dialog1.dispose();
             

            }
             else if ("CancelSelection".equals(e.getActionCommand())) {
            
             dialog1.dispose();
            
             }
           }

           class JFileChooserx extends JFileChooser implements ActionListener {
            JDialog dialog = null;

            public JFileChooserx() {
             super();
            }

            public JDialog createDialog(Component parent) throws HeadlessException {

             return dialog = super.createDialog(parent);
            }

            public void actionPerformed(ActionEvent e) {
             
             if ("CancelSelection".equals(e.getActionCommand())) {
              dialog.dispose();
             }
            }
           }
          }

          有幾個(gè)地方要注意JFileChooser的createDialog(Component parent)是protected的,我要覆蓋它
          jdbtable里存圖片是用InputStreamToByteArray 來(lái)存儲(chǔ)的,這里我還有個(gè)問(wèn)題如何把讀出來(lái)的圖片,存到數(shù)據(jù)庫(kù)中。
          我現(xiàn)在是讀取圖片--放在byte[]中--數(shù)據(jù)庫(kù),這樣一來(lái)我不知道byte要設(shè)置多大的長(zhǎng)度,在控制臺(tái)老報(bào)“Premature end of JPEG file”
          但是這不是一個(gè)異常。

          posted on 2005-10-23 23:34 nake 閱讀(970) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2005年10月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(18)

          我參與的團(tuán)隊(duì)

          隨筆檔案(39)

          收藏夾(1)

          搜索

          •  

          積分與排名

          • 積分 - 451387
          • 排名 - 119

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 乌什县| 深水埗区| 永安市| 筠连县| 新田县| 威海市| 邹城市| 通山县| 常山县| 桓台县| 五河县| 七台河市| 文安县| 察雅县| 宜都市| 奉贤区| 乌什县| 临海市| 景洪市| 高平市| 当涂县| 资源县| 棋牌| 辉县市| 德令哈市| 新丰县| 泽普县| 门源| 富裕县| 泸溪县| 新邵县| 岐山县| 双柏县| 高要市| 宜章县| 漯河市| 东台市| 二连浩特市| 内黄县| 米脂县| 微山县|