// $Id: DatabaseAccess.java,v 1.3 1998/01/29 05:43:05 fuji Exp fuji $ //====================================================================== // データベース(POSTGRES95)アクセス用クラス //====================================================================== // Copyright(C) 1996, 1997, 1998 Hirofumi Fujiwara // // 本プログラムは、改造も含め、その商用利用は禁止します。 //====================================================================== import java.awt.*; import java.applet.*; import java.lang.*; import java.io.*; import java.util.*; import java.net.*; //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // データベース関連 及び ダイアログ //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ //================================================================================ // Database(pg95perl5) access common class //================================================================================ public class DatabaseAccess { DatabaseIF dbif; Frame parentFrame; public String problemid; // 問題識別子 public History history = new History(); // ヒストリ管理のための情報 boolean isviewdata = false; // View状態のデータ String viewuser; String versionstr; String midsatestr; //---------------------------------------- DatabaseAccess // 構築子 //-------------------------------------------------------- public DatabaseAccess( DatabaseIF db_if, Frame parent ) { dbif = db_if; parentFrame = parent; } } //================================================================================ // History //================================================================================ class History { StringBuffer historybuffer; long prevtime; // 開始時刻(ミリ秒) long curtime; // 現在時刻 long inttime; // 時間間隔 int curx; // x 位置 int cury; // y 位置 String statet, state0, state1; int historyidx = 0; int historysize = 0; // ヒストリィのサイズ String[] historyarray; // ヒストリィ配列 boolean flushed; // flush済 //------------------------------------------------ // 構築子 //------------------------------------------------ public History() { historybuffer = new StringBuffer(10000); statet = state0 = state1 = null; Date date = new Date(); curtime = prevtime = date.getTime(); inttime = 0; flushed = true; } public void clear() { historybuffer = new StringBuffer(10000); statet = state0 = state1 = null; Date date = new Date(); curtime = prevtime = date.getTime(); inttime = 0; flushed = true; } public void cont() { Date date = new Date(); prevtime = date.getTime(); flushed = true; } //------------------------------------------------ // ヒストリ文字列から、ヒストリ配列に入れる //------------------------------------------------ public void sethistory( String str, boolean arr ) { historybuffer = new StringBuffer( str.length()+10000 ); historybuffer.append( str ); flushed = true; if( ! arr ) return; StringTokenizer st = new StringTokenizer( str, "\n" ); historysize = st.countTokens(); if( historysize == 0 ) return; historyarray = new String[historysize]; for( int i=0; i= historysize ) return null; return historyarray[historyidx++]; } //------------------------------------------------ // 前のヒストリ //------------------------------------------------ public String gethistoryB() { if( historyidx <= 0 || historyidx > historysize ) return null; return historyarray[--historyidx]; } //------------------------------------------------ // 1ステップ分を記録する //------------------------------------------------ public void set( int x, int y, boolean fh, int fv, boolean th, int tv ) { set( null, x, y, fh, fv, th, tv ); } public void set( String t, int x, int y, boolean fh, int fv, boolean th, int tv ) { String fromstr = (fh ? "t" : "f") + fv; String tostr = (th ? "t" : "f") + tv; Date date = new Date(); curtime = date.getTime(); boolean tbx = (statet==null) || ! statet.equals( t ); if( (!flushed) && (!tbx) && curx==x && cury==y ) { // 同じ位置 state1 = tostr; inttime = (curtime - prevtime) / 1000; } else { boolean stx = (state0!=null) && ! state0.equals( state1 ); if( (!flushed) && (stx || tbx) ) { addstep(); } curx = x; cury = y; statet = t; state0 = fromstr; state1 = tostr; inttime = (curtime - prevtime) / 1000; prevtime = curtime; flushed = false; } } public String get() { if( ! flushed ) { addstep(); } flushed = true; return historybuffer.toString(); } //------------------------------------------------ // 1ステップ分を追加 //------------------------------------------------ private void addstep() { String str = ""; if( statet != null ) str += statet + " "; str += curx + " " + cury + " " + state0 + " " + state1 + " "+ inttime + "\n"; if( historybuffer.length()+str.length() +10 > historybuffer.capacity() ) { try { String s = historybuffer.toString(); int len = historybuffer.capacity() + 10000; historybuffer = new StringBuffer( len ); historybuffer.append( s ); } catch( StringIndexOutOfBoundsException e ) {} } historybuffer.append(str); } } //================================================================================ // ダイアログ集 //================================================================================ //================================================================================ // 複数行対応のラベル //================================================================================ class MultiLineLabel extends Canvas { public static final int LEFT = 0; // アラインメントのための定数 public static final int CENTER = 1; public static final int RIGHT = 2; protected String[] lines; // 表示文字列の各行 protected int num_lines; // 行数 protected int margin_width; // 左右のマージン protected int margin_height; // 上下のマージン protected int line_height; // フォント全体の高さ protected int line_ascent; // フォントアセント protected int[] line_widths; // 各行の幅 protected int max_width; // 最大行の幅 protected int alignment = LEFT; // テキストのアラインメント protected void newLabel( String label ) { StringTokenizer t = new StringTokenizer( label, "\n" ); num_lines = t.countTokens(); lines = new String[num_lines]; line_widths = new int[num_lines]; for( int i=0; i max_width ) { max_width = line_widths[i]; } } } public MultiLineLabel( String label, int margin_width, int margin_height, int alignment ) { newLabel( label ); this.margin_width = margin_width; this.margin_height = margin_height; this.alignment = alignment; } public MultiLineLabel( String label, int margin_width, int margin_height ) { this( label, margin_width, margin_height, LEFT ); } public MultiLineLabel( String label, int alignment ) { this( label, 10, 10, alignment ); } public MultiLineLabel( String label) { this( label, 10, 10, LEFT ); } public void setText( String label ) { newLabel(label); measure(); repaint(); } public void setFont( Font f ) { super.setFont( f ); measure(); repaint(); } public void setForeground( Color c ) { super.setForeground(c); repaint(); } public void setAlignment( int a ) { alignment = a; repaint(); } public void setMarginWidth( int mw ) { margin_width = mw; repaint(); } public void setMarginHeight( int mh ) { margin_height = mh; repaint(); } public int getAlignment() { return alignment; } public int getMarginWidth() { return margin_width; } public int getMarginHeight() { return margin_height; } public void addNotify() { super.addNotify(); measure(); } public Dimension preferredSize() { return new Dimension( max_width + 2*margin_width, num_lines*line_height + 2*margin_height ); } public Dimension minimumSize() { return new Dimension( max_width, num_lines*line_height ); } public void paint( Graphics g ) { int x, y; Dimension d = this.size(); y = line_ascent+(d.height-num_lines*line_height)/2; for( int i=0; i