Changeset 25709

Show
Ignore:
Timestamp:
12/02/08 22:47:53 (5 weeks ago)
Author:
tarchan
Message:

lang/java/IRCKit: チャットウインドウに文字列表示機能を追加

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/java/IRCKit/trunk/src/com/mac/tarchan/irc/client/IRCConsole.java

    r25708 r25709  
    2121import javax.swing.JTextField; 
    2222import javax.swing.JTextPane; 
    23 import javax.swing.text.AttributeSet; 
    2423import javax.swing.text.BadLocationException; 
     24import javax.swing.text.Style; 
     25import javax.swing.text.StyleContext; 
    2526import javax.swing.text.StyledDocument; 
    2627 
     
    3334{ 
    3435        /** 
    35          * @param args 
     36         * チャットコンソールを起動します。 
     37         *  
     38         * @param args 引数 
    3639         */ 
    3740        public static void main(String[] args) 
     
    3942                IRCConsole console = new IRCConsole(); 
    4043                console.createChatWindow(); 
    41 //              console.test(); 
     44                console.test(); 
    4245        } 
     46 
     47        /** 改行コード */ 
     48        protected final String LF = System.getProperty("line.separator"); 
     49 
     50        /** ドキュメント */ 
     51        protected StyledDocument doc; 
     52 
     53        /** 表示スタイル */ 
     54        protected Style style = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); 
    4355 
    4456        /** 
     
    5365                textPane.setEditable(false); 
    5466                textPane.setPreferredSize(new Dimension(320, 240)); 
    55                 final StyledDocument doc = textPane.getStyledDocument(); 
    56                 final String LF = System.getProperty("line.separator"); 
     67                doc = textPane.getStyledDocument(); 
    5768 
    5869                // スクロールパネル 
     
    6677                        public void actionPerformed(ActionEvent evt) 
    6778                        { 
    68                                 try 
    69                                 { 
    70                                         // 入力テキストを取得 
    71                                         String str = evt.getActionCommand(); 
     79                                // 入力テキストを取得 
     80                                String str = evt.getActionCommand(); 
    7281 
    73                                         // 入力フィールドをクリア 
    74                                         textField.setText(""); 
     82                                // 入力フィールドをクリア 
     83                                textField.setText(""); 
    7584 
    76                                         // 表示エリアに1行追加 
    77                                         AttributeSet style = null; 
    78                                         doc.insertString(doc.getLength(), str + LF, style); 
    79 //                                      textPane.setCaretPosition(doc.getLength()); 
    80                                 } 
    81                                 catch (BadLocationException e) 
    82                                 { 
    83                                         e.printStackTrace(); 
    84                                 } 
     85                                // 表示エリアに1行追加 
     86                                appendLine(str); 
    8587                        } 
    8688                }); 
     
    103105 
    104106        /** 
     107         * 指定された文字列を表示エリアに追加します。 
     108         *  
     109         * @param str 文字列 
     110         */ 
     111        public void appendLine(String str) 
     112        { 
     113                try 
     114                { 
     115                        // 表示エリアに1行追加 
     116                        doc.insertString(doc.getLength(), str + LF, style); 
     117//                      textPane.setCaretPosition(doc.getLength()); 
     118                } 
     119                catch (BadLocationException e) 
     120                { 
     121                        e.printStackTrace(); 
     122                } 
     123        } 
     124 
     125        /** 
    105126         * IRCKitの接続テスト 
    106127         */ 
    107128        public void test() 
    108129        { 
    109                 System.out.println("Welcome to IRCKit!"); 
     130                appendLine("Welcome to IRCKit!"); 
    110131                try 
    111132                { 
     
    122143                                { 
    123144                                        // TODO 受信したメッセージを表示 
     145                                        appendLine(msg.toString()); 
    124146                                } 
    125147                        });