Java Drawing DrawTop

Language

JP  US  UK

 

デバッグツール

 H. Jyounishi, Tokyo Japan
 

Frame (Index), No frame                 version:0.3(latest)  

要旨:デバッグボタンは標準出力、標準エラー出力を表示するダイアログを画面の下に表示する指示をする。
トレースボタンはデバッグ用の印刷を指示するダイアログを表示する。
このページで説明するクラス: ButtonOfDebug, DialogOfSystemOut, TextAreaOutputStream

1. ButtonOfDebugクラス 戻る=>page top

1.1 debugコマンドのメニュー、メニューアイテム
(a) debugコマンドのメニュー (b) Printメニューアイテム (c) Test Shapeメニューアイテム

図1. debugコマンド


1.2 API
public class ButtonOfDebug extends JMenuBar implements ActionListener
: ButtonOfDebugオブジェクトはDrawMenu.createDebugTestGroup で作成され、ToolBarパネルに加えらる。

フィールド 説明
menu JMenu menu
JMenuオブジェクトを設定する。
ButtonOfDebugはJMenuBarの拡張クラスで表示は図1(a)のdebugボタン。
menuオブジェクトはButtonOfDebugに加えられ(add)、図1(a)に示すようにdebugボタンの下に表示される。

メソッド 説明
コンストラクタ public ButtonOfDebug(String commandName, boolean setText, ImageIcon imageIcon, String tip)
ボタンにはIconとテキストを表示する。コンストラクタではボタンの設定だけを行い、 setMenuItemsメソッドでメニューアイテムの設定を行う。
引数:
commandName - コマンド名。
commandNameをアクションコマンド名にする。ボタンにはcommandNameを表示する。
setText - falseならばIconのみをボタンに表示する。trueならばテキスト(commandName)とIconの両方を表示する。
imageIcon - ボタンに表示するIcon画像。
tip - tool tipに表示する文字列
setStandardButtonStyle public void setStandardButtonStyle()
次のメソッドを呼んで設定する。

this.menu.setFont(MenuConstants.MenuFont);
Border raisedBorder = new BevelBorder(BevelBorder.RAISED);
this.menu.setBorder(raisedBorder);
this.menu.setIconTextGap(0);
this.menu.setOpaque(true);
Color backGround=new Color(0xDDE8F3);
this.menu.setBackground(backGround);
this.menu.setForeground(Color.black);

setSelected public void setSelected(boolean selected)
selectedをmenuに設定する。
isSelected public boolean isSelected()
JMenuのisSelectedメソッドの値を返す。
createDebugButton
(static)
public static ButtonOfDebug createDebugButton(int width)
引数:
width - ボタンの幅。
処理:
次の設定を行う。

ButtonOfDebug menuButton=new ButtonOfDebug("debug", true, null, commandName);
String[] menuItemNames={"System.out dialog","print menu list"};

actionPerformed public void actionPerformed(ActionEvent e)
登録したメニューアイテムに応じた処理を記述する。


2. DialogOfSystemOutクラス 戻る=>page top
2.1 表示


図2. SystemOutDialog
標準出力、標準エラー出力を表示する。


2.2 API
public class DialogOfSystemOut implements WindowListener
メソッド 説明
コンストラクター public DialogOfPageSetup()
次の設定を行う。

super(ObjectTable.getDrawMain(), "System.out");
this.setName("DialogOfSystemOut");
this.addWindowListener(this);

showDialog public void showDialog()
∙ もしすでにこのダイアログが開いていたら何もせずにリターン。

すでに開いているか否かはmenuUtilgetMenuComponentで知ることができる。

∙ JTextAreaオブジェクトとJScrollPaneオブジェクトを作成し、JTextArea をJScrollPaneに設定する。
TextAreaOutputStreamオブジェクトを作成し標準出力に設定する。

TextAreaOutputStream outputStream=new TextAreaOutputStream(textArea);
System.setOut(new PrintStream(outputStream));
System.setErr(new PrintStream(outputStream));

∙ ダイアログをsetVisible(true)で可視化。
∙ このオブジェクトをMenuComponentListに登録する。
closeDialog private void closeDialog()
このダイアログを不可視にし MenuComponentListから削除する。
標準出力をJTextAreaから元に戻す。

FileOutputStream fileOut=new FileOutputStream(FileDescriptor.out);
PrintStream out=new PrintStream(new BufferedOutputStream(fileOut), true);
System.setOut(out);
System.setErr(out);

windowClosing public void windowClosing(WindowEvent e)
closeDialogメソッドを呼ぶ。


4.TextAreaOutputStream 戻る=>page top
public class TextAreaOutputStream extends OutputStream
フィールド 説明
textArea JTextArea textArea
ダイアログに設定する文字表示領域のJTextAreaオブジェクト。

メソッド 説明
コンストラクタ public TextAreaOutputStream(JTextArea textArea)
DialogOfSystemOutから呼ばれたときにフィールド変数textAreaに引数を設定する。
write public void write(int i)
i(byte)をStringに変換し、textAreaに追加する。

this.textArea.append(Character.toString((char)i));

write public void write(char[] buf, int off, int len)
bufからStringを作成し、textAreaに追加する。

String s = new String(buf, off, len);
this.textArea.append(s);



Copyright (c) 2009-2013
All other trademarks are property of their respective owners.