Reorganize files from svn

This commit is contained in:
james
2024-05-20 00:17:44 +00:00
parent c949f4c9a0
commit 7c830b241a
497 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
/*
* AuthorListEntry.cs
* Copyright (c) 2007-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
package org.kbinani.apputil;
import java.awt.*;
#else
using System;
using bocoree.java.awt;
namespace Boare.Lib.AppUtil {
#endif
public class AuthorListEntry {
String m_name;
int m_style;
public AuthorListEntry( String name, int style ) {
m_name = name;
m_style = style;
}
#if JAVA
public AuthorListEntry( String name ){
this( name, Font.PLAIN );
#else
public AuthorListEntry( String name )
: this( name, Font.PLAIN ) {
#endif
}
public AuthorListEntry() {
m_name = "";
m_style = Font.PLAIN;
}
public String getName() {
return m_name;
}
public int getStyle() {
return m_style;
}
}
#if !JAVA
}
#endif

View File

@@ -0,0 +1,68 @@
#if !JAVA
/*
* BHScrollBar.Designer.cs
* Copyright (c) 2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace Boare.Lib.AppUtil {
partial class OBSOLUTE_BHScrollBar {
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
/// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
protected override void Dispose( bool disposing ) {
if ( disposing && (components != null) ) {
components.Dispose();
}
base.Dispose( disposing );
}
#region
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent() {
this.hScroll = new System.Windows.Forms.HScrollBar();
this.SuspendLayout();
//
// hScroll
//
this.hScroll.Dock = System.Windows.Forms.DockStyle.Fill;
this.hScroll.Location = new System.Drawing.Point( 0, 0 );
this.hScroll.Name = "hScroll";
this.hScroll.Size = new System.Drawing.Size( 333, 16 );
this.hScroll.TabIndex = 0;
this.hScroll.ValueChanged += new System.EventHandler( this.hScroll_ValueChanged );
//
// BHScrollBar
//
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 12F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add( this.hScroll );
this.Name = "BHScrollBar";
this.Size = new System.Drawing.Size( 333, 16 );
this.ResumeLayout( false );
}
#endregion
private System.Windows.Forms.HScrollBar hScroll;
}
}
#endif

View File

@@ -0,0 +1,88 @@
#if !JAVA
/*
* BHScrollBar.cs
* Copyright (c) 2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.Windows.Forms;
namespace Boare.Lib.AppUtil {
/// <summary>
/// Valueの値が正しくMinimumからMaximumの間を動くスクロールバー
/// </summary>
public partial class OBSOLUTE_BHScrollBar : UserControl {
int m_max = 100;
int m_min = 0;
public event EventHandler ValueChanged;
public OBSOLUTE_BHScrollBar() {
InitializeComponent();
}
public int Value {
get {
return hScroll.Value;
}
set {
hScroll.Value = value;
}
}
public int LargeChange {
get {
return hScroll.LargeChange;
}
set {
hScroll.LargeChange = value;
hScroll.Maximum = m_max + value;
}
}
public int SmallChange {
get {
return hScroll.SmallChange;
}
set {
hScroll.SmallChange = value;
}
}
public int Maximum {
get {
return m_max;
}
set {
m_max = value;
hScroll.Maximum = m_max + hScroll.LargeChange;
}
}
public int Minimum {
get {
return m_min;
}
set {
m_min = value;
}
}
private void hScroll_ValueChanged( object sender, EventArgs e ) {
if ( ValueChanged != null ) {
ValueChanged( this, e );
}
}
}
}
#endif

View File

@@ -0,0 +1,532 @@
#if !JAVA
/*
* BSplitContainer.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace Boare.Lib.AppUtil {
[Serializable]
public partial class BSplitContainer : ContainerControl {
private Orientation m_orientation = Orientation.Horizontal;
private int m_splitter_distance = 50;
private int m_panel1_min = 25;
private int m_panel2_min = 25;
private int m_splitter_width = 4;
private bool m_splitter_moving = false;
private int m_splitter_distance_draft = 50;
private BSplitterPanel m_panel1;
private BSplitterPanel m_panel2;
private System.ComponentModel.IContainer components = null;
private bool m_splitter_fixed = false;
private Pen m_panel1_border = null;
private Pen m_panel2_border = null;
private System.Windows.Forms.FixedPanel m_fixed_panel;
private PictureBox m_lbl_splitter;
private int m_panel2_distance = 1;
private double m_distance_rate = 0.5;
public event SplitterEventHandler SplitterMoved;
[Browsable(false)]
public event ControlEventHandler ControlAdded;
public BSplitContainer() {
InitializeComponent();
if ( m_orientation == Orientation.Horizontal ) {
m_lbl_splitter.Cursor = Cursors.VSplit;
} else {
m_lbl_splitter.Cursor = Cursors.HSplit;
}
if ( m_orientation == Orientation.Horizontal ) {
m_panel2_distance = this.Width - m_splitter_distance;
} else {
m_panel2_distance = this.Height - m_splitter_distance;
}
m_distance_rate = m_splitter_distance / (double)(m_splitter_distance + m_panel2_distance);
}
public System.Windows.Forms.FixedPanel FixedPanel {
get {
return m_fixed_panel;
}
set {
System.Windows.Forms.FixedPanel old = m_fixed_panel;
m_fixed_panel = value;
if ( m_fixed_panel != FixedPanel.None && m_fixed_panel != old ) {
if ( m_fixed_panel == FixedPanel.Panel1 ) {
m_panel2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
if ( m_orientation == Orientation.Vertical ) {
m_panel1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
} else {
m_panel1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
}
} else {
m_panel1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
if ( m_orientation == Orientation.Vertical ) {
m_panel2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
} else {
m_panel2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
}
}
}
}
}
public bool IsSplitterFixed {
get {
return m_splitter_fixed;
}
set {
m_splitter_fixed = value;
if ( m_splitter_fixed ) {
m_lbl_splitter.Cursor = Cursors.Default;
} else {
if ( m_orientation == Orientation.Horizontal ) {
m_lbl_splitter.Cursor = Cursors.VSplit;
} else {
m_lbl_splitter.Cursor = Cursors.HSplit;
}
}
}
}
public bool isSplitterFixed() {
return this.IsSplitterFixed;
}
public void setSplitterFixed( bool value ) {
this.IsSplitterFixed = value;
}
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
/// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
protected override void Dispose( bool disposing ) {
if ( disposing && (components != null) ) {
components.Dispose();
}
base.Dispose( disposing );
}
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent() {
this.m_lbl_splitter = new System.Windows.Forms.PictureBox();
this.m_panel2 = new Boare.Lib.AppUtil.BSplitterPanel();
this.m_panel1 = new Boare.Lib.AppUtil.BSplitterPanel();
((System.ComponentModel.ISupportInitialize)(this.m_lbl_splitter)).BeginInit();
this.SuspendLayout();
//
// m_lbl_splitter
//
this.m_lbl_splitter.BackColor = System.Drawing.Color.Transparent;
this.m_lbl_splitter.Location = new System.Drawing.Point( 0, 0 );
this.m_lbl_splitter.Name = "m_lbl_splitter";
this.m_lbl_splitter.Size = new System.Drawing.Size( 100, 50 );
this.m_lbl_splitter.TabIndex = 0;
this.m_lbl_splitter.TabStop = false;
this.m_lbl_splitter.MouseMove += new System.Windows.Forms.MouseEventHandler( this.m_lbl_splitter_MouseMove );
this.m_lbl_splitter.MouseDown += new System.Windows.Forms.MouseEventHandler( this.m_lbl_splitter_MouseDown );
this.m_lbl_splitter.MouseUp += new System.Windows.Forms.MouseEventHandler( this.m_lbl_splitter_MouseUp );
//
// m_panel2
//
this.m_panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.m_panel2.BorderColor = System.Drawing.Color.Black;
this.m_panel2.Location = new System.Drawing.Point( 0, 103 );
this.m_panel2.Margin = new System.Windows.Forms.Padding( 0 );
this.m_panel2.Name = "m_panel2";
this.m_panel2.Size = new System.Drawing.Size( 441, 245 );
this.m_panel2.TabIndex = 1;
this.m_panel2.BorderStyleChanged += new System.EventHandler( this.m_panel2_BorderStyleChanged );
this.m_panel2.SizeChanged += new System.EventHandler( this.m_panel2_SizeChanged );
//
// m_panel1
//
this.m_panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.m_panel1.BorderColor = System.Drawing.Color.Black;
this.m_panel1.Location = new System.Drawing.Point( 0, 0 );
this.m_panel1.Margin = new System.Windows.Forms.Padding( 0, 0, 0, 4 );
this.m_panel1.Name = "m_panel1";
this.m_panel1.Size = new System.Drawing.Size( 441, 99 );
this.m_panel1.TabIndex = 0;
this.m_panel1.BorderStyleChanged += new System.EventHandler( this.m_panel1_BorderStyleChanged );
this.m_panel1.SizeChanged += new System.EventHandler( this.m_panel1_SizeChanged );
//
// SplitContainerEx
//
this.Controls.Add( this.m_panel2 );
this.Controls.Add( this.m_panel1 );
this.Controls.Add( this.m_lbl_splitter );
this.Size = new System.Drawing.Size( 441, 348 );
this.Paint += new System.Windows.Forms.PaintEventHandler( this.SplitContainerEx_Paint );
((System.ComponentModel.ISupportInitialize)(this.m_lbl_splitter)).EndInit();
this.ResumeLayout( false );
}
private void SplitContainerEx_Paint( object sender, PaintEventArgs e ) {
bool panel1_visible = true;
if ( Orientation == Orientation.Horizontal ) {
if ( m_panel1.Width == 0 ) {
panel1_visible = false;
}
} else {
if ( m_panel1.Height == 0 ) {
panel1_visible = false;
}
}
if ( m_panel1.BorderStyle == BorderStyle.FixedSingle && panel1_visible ) {
if ( m_panel1_border == null ) {
m_panel1_border = new Pen( m_panel1.BorderColor );
} else {
if ( !m_panel1.BorderColor.Equals( m_panel1_border.Color ) ) {
m_panel1_border = new Pen( m_panel1.BorderColor );
}
}
e.Graphics.DrawRectangle( m_panel1_border,
new Rectangle( m_panel1.Left - 1, m_panel1.Top - 1, m_panel1.Width + 1, m_panel1.Height + 1) );
}
bool panel2_visible = true;
if ( Orientation == Orientation.Horizontal ) {
if ( m_panel2.Width == 0 ) {
panel2_visible = false;
}
} else {
if ( m_panel2.Height == 0 ) {
panel2_visible = false;
}
}
if ( m_panel2.BorderStyle == BorderStyle.FixedSingle && panel2_visible ) {
if ( m_panel2_border == null ) {
m_panel2_border = new Pen( m_panel2.BorderColor );
} else {
if ( !m_panel2.BorderColor.Equals( m_panel2_border.Color ) ) {
m_panel2_border = new Pen( m_panel2.BorderColor );
}
}
e.Graphics.DrawRectangle( m_panel2_border,
new Rectangle( m_panel2.Left - 1, m_panel2.Top - 1, m_panel2.Width + 1, m_panel2.Height + 1 ) );
}
}
private void m_panel2_BorderStyleChanged( object sender, EventArgs e ) {
UpdateLayout( m_splitter_distance, m_splitter_width, m_panel1_min, m_panel2_min, false );
}
private void m_panel1_BorderStyleChanged( object sender, EventArgs e ) {
UpdateLayout( m_splitter_distance, m_splitter_width, m_panel1_min, m_panel2_min, false );
}
private void m_panel2_SizeChanged( object sender, EventArgs e ) {
m_panel2.Invalidate( true );
}
private void m_panel1_SizeChanged( object sender, EventArgs e ) {
m_panel1.Invalidate( true );
}
public int Panel1MinSize {
get {
return m_panel1_min;
}
set {
int min_splitter_distance = value;
if ( m_splitter_distance < min_splitter_distance && min_splitter_distance > 0 ) {
m_splitter_distance = min_splitter_distance;
}
UpdateLayout( m_splitter_distance, m_splitter_width, value, m_panel2_min, false );
}
}
public int Panel2MinSize {
get {
return m_panel2_min;
}
set {
int max_splitter_distance = (m_orientation == Orientation.Horizontal) ?
this.Width - m_splitter_width - value :
this.Height - m_splitter_width - value;
if ( m_splitter_distance > max_splitter_distance && max_splitter_distance > 0 ) {
m_splitter_distance = max_splitter_distance;
}
UpdateLayout( m_splitter_distance, m_splitter_width, m_panel1_min, value, false );
}
}
public int SplitterWidth {
get {
return m_splitter_width;
}
set {
if ( value < 1 ) {
value = 1;
}
UpdateLayout( m_splitter_distance, value, m_panel1_min, m_panel2_min, false );
}
}
public int getDividerSize() {
return this.SplitterWidth;
}
public void setDividerSize( int value ) {
this.SplitterWidth = value;
}
private bool UpdateLayout( int splitter_distance, int splitter_width, int panel1_min, int panel2_min, bool check_only ) {
Point mouse = this.PointToClient( Control.MousePosition );
int pad1 = (m_panel1.BorderStyle == BorderStyle.FixedSingle) ? 1 : 0;
int pad2 = (m_panel2.BorderStyle == BorderStyle.FixedSingle) ? 1 : 0;
if ( m_orientation == Orientation.Horizontal ) {
int p1 = splitter_distance;
if ( p1 < 0 ) {
p1 = 0;
} else if ( this.Width < p1 + splitter_width ) {
p1 = this.Width - splitter_width;
}
int p2 = this.Width - p1 - splitter_width;
if ( check_only ) {
if ( p1 < panel1_min || p2 < panel2_min ) {
return false;
}
} else {
if ( p1 < panel1_min ) {
p1 = panel1_min;
}
p2 = this.Width - p1 - splitter_width;
if ( p2 < panel2_min ) {
p2 = panel2_min;
//return false;
}
}
if ( !check_only ) {
m_panel1.Left = pad1;
m_panel1.Top = pad1;
m_panel1.Width = (p1 - 2 * pad1 >= 0) ? (p1 - 2 * pad1) : 0;
m_panel1.Height = (this.Height - 2 * pad1 >= 0) ? (this.Height - 2 * pad1) : 0;
m_panel2.Left = p1 + splitter_width + pad2;
m_panel2.Top = pad2;
m_panel2.Width = (p2 - 2 * pad2 >= 0) ? (p2 - 2 * pad2) : 0;
m_panel2.Height = (this.Height - 2 * pad2 >= 0) ? (this.Height - 2 * pad2) : 0;
m_splitter_distance = p1;
m_panel2_distance = this.Width - m_splitter_distance;
m_distance_rate = m_splitter_distance / (double)(m_splitter_distance + m_panel2_distance);
if ( SplitterMoved != null ) {
SplitterMoved( this, new SplitterEventArgs( mouse.X, mouse.Y, p1, 0 ) );
}
m_splitter_width = splitter_width;
m_panel1_min = panel1_min;
m_panel2_min = panel2_min;
m_lbl_splitter.Left = p1;
m_lbl_splitter.Top = 0;
m_lbl_splitter.Width = splitter_width;
m_lbl_splitter.Height = this.Height;
}
return true;
} else {
int p1 = splitter_distance;
if ( p1 < 0 ) {
p1 = 0;
} else if ( this.Height < p1 + splitter_width ) {
p1 = this.Height - splitter_width;
}
int p2 = this.Height - p1 - splitter_width;
if ( check_only ) {
if ( p1 < panel1_min || p2 < panel2_min ) {
return false;
}
} else {
if ( p1 < panel1_min ) {
p1 = panel1_min;
}
p2 = this.Height - p1 - splitter_width;
if ( p2 < panel2_min ) {
p2 = panel2_min;
//return false;
}
}
if ( !check_only ) {
m_panel1.Left = pad1;
m_panel1.Top = pad1;
m_panel1.Width = (this.Width - 2 * pad1 >= 0) ? (this.Width - 2 * pad1) : 0;
m_panel1.Height = (p1 - 2 * pad1 >= 0) ? (p1 - 2 * pad1) : 0;
m_panel2.Left = pad2;
m_panel2.Top = p1 + splitter_width + pad2;
m_panel2.Width = (this.Width - 2 * pad2 >= 0) ? (this.Width - 2 * pad2) : 0;
m_panel2.Height = (p2 - 2 * pad2 >= 0) ? (p2 - 2 * pad2) : 0;
m_splitter_distance = p1;
m_panel2_distance = this.Height - m_splitter_distance;
m_distance_rate = m_splitter_distance / (double)(m_splitter_distance + m_panel2_distance);
if ( SplitterMoved != null ) {
SplitterMoved( this, new SplitterEventArgs( mouse.X, mouse.Y, 0, p1 ) );
}
m_splitter_width = splitter_width;
m_panel1_min = panel1_min;
m_panel2_min = panel2_min;
m_lbl_splitter.Left = 0;
m_lbl_splitter.Top = p1;
m_lbl_splitter.Width = this.Width;
m_lbl_splitter.Height = splitter_width;
}
return true;
}
}
public int SplitterDistance {
get {
return m_splitter_distance;
}
set {
UpdateLayout( value, m_splitter_width, m_panel1_min, m_panel2_min, false );
if ( m_orientation == Orientation.Horizontal ) {
m_panel2_distance = this.Width - m_splitter_distance;
} else {
m_panel2_distance = this.Height - m_splitter_distance;
}
}
}
public int getDividerLocation() {
return this.SplitterDistance;
}
public void setDividerLocation( int value ) {
this.SplitterDistance = value;
}
public Orientation Orientation {
get {
return m_orientation;
}
set {
if ( m_orientation != value ) {
m_orientation = value;
UpdateLayout( m_splitter_distance, m_splitter_width, m_panel1_min, m_panel2_min, false );
if ( m_orientation == Orientation.Horizontal ) {
m_lbl_splitter.Cursor = Cursors.VSplit;
} else {
m_lbl_splitter.Cursor = Cursors.HSplit;
}
}
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public BSplitterPanel Panel1 {
get {
return m_panel1;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public BSplitterPanel Panel2 {
get {
return m_panel2;
}
}
protected override void OnSizeChanged( EventArgs e ) {
#if DEBUG
//Console.WriteLine( "BSplitContainer+OnSizeChanged" );
//Console.WriteLine( " FixedPanel=" + FixedPanel );
//Console.WriteLine( " m_splitter_distance=" + m_splitter_distance );
//Console.WriteLine( " Width=" + Width );
//Console.WriteLine( " Height=" + Height );
//Console.WriteLine( " m_panel2_distance=" + m_panel2_distance );
#endif
base.OnSizeChanged( e );
if ( Width <= 0 || Height <= 0 ) {
return;
}
if ( m_fixed_panel == FixedPanel.Panel2 ) {
if ( m_orientation == Orientation.Horizontal ) {
m_splitter_distance = this.Width - m_panel2_distance;
} else {
m_splitter_distance = this.Height - m_panel2_distance;
}
} else if ( m_fixed_panel == FixedPanel.None ) {
#if DEBUG
//Console.WriteLine( " m_distance_rate=" + m_distance_rate );
#endif
if ( m_orientation == Orientation.Horizontal ) {
m_splitter_distance = (int)(this.Width * m_distance_rate);
} else {
m_splitter_distance = (int)(this.Height * m_distance_rate);
}
}
UpdateLayout( m_splitter_distance, m_splitter_width, m_panel1_min, m_panel2_min, false );
}
private void m_lbl_splitter_MouseDown( object sender, MouseEventArgs e ) {
if ( !m_splitter_fixed ) {
m_splitter_moving = true;
m_splitter_distance_draft = m_splitter_distance;
this.Cursor = (m_orientation == Orientation.Horizontal) ? Cursors.VSplit : Cursors.HSplit;
m_lbl_splitter.BackColor = SystemColors.ControlDark;
m_lbl_splitter.BringToFront();
}
}
private void m_lbl_splitter_MouseUp( object sender, MouseEventArgs e ) {
if ( m_splitter_moving ) {
m_splitter_moving = false;
UpdateLayout( m_splitter_distance_draft, m_splitter_width, m_panel1_min, m_panel2_min, false );
this.Cursor = Cursors.Default;
m_lbl_splitter.BackColor = SystemColors.Control;
}
}
private void m_lbl_splitter_MouseMove( object sender, MouseEventArgs e ) {
base.OnMouseMove( e );
if ( m_splitter_fixed ) {
return;
}
Point mouse_local = this.PointToClient( Control.MousePosition );
if ( m_splitter_moving ) {
int new_distance = m_splitter_distance;
if ( m_orientation == Orientation.Horizontal ) {
new_distance = mouse_local.X;
} else {
new_distance = mouse_local.Y;
}
if ( UpdateLayout( new_distance, m_splitter_width, m_panel1_min, m_panel2_min, true ) ) {
m_splitter_distance_draft = new_distance;
if ( m_orientation == Orientation.Horizontal ) {
m_lbl_splitter.Left = m_splitter_distance_draft;
} else {
m_lbl_splitter.Top = m_splitter_distance_draft;
}
}
}
}
}
}
#endif

View File

@@ -0,0 +1,98 @@
#if !JAVA
/*
* BSplitterPanel.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
namespace Boare.Lib.AppUtil {
public class BSplitterPanel : Panel {
private BorderStyle m_border_style = BorderStyle.None;
private Color m_border_color = Color.Black;
public event EventHandler BorderStyleChanged;
public BSplitterPanel()
: base() {
base.AutoScroll = false;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public Color BorderColor {
get {
return m_border_color;
}
set {
m_border_color = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public new BorderStyle BorderStyle {
get {
return m_border_style;
}
set {
BorderStyle old = m_border_style;
m_border_style = value;
if ( m_border_style == BorderStyle.Fixed3D ) {
base.BorderStyle = BorderStyle.Fixed3D;
} else if ( m_border_style == BorderStyle.FixedSingle ) {
base.BorderStyle = BorderStyle.None;
base.Padding = new Padding( 1 );
} else {
base.Padding = new Padding( 0 );
base.BorderStyle = BorderStyle.None;
}
if ( old != m_border_style && BorderStyleChanged != null ) {
BorderStyleChanged( this, new EventArgs() );
}
}
}
[Browsable(false)]
public new int Width {
get {
return base.Width;
}
internal set {
base.Width = value;
}
}
[Browsable(false)]
public new int Height {
get {
return base.Height;
}
internal set {
base.Height = value;
}
}
[Browsable(false)]
public new Rectangle Bounds {
get {
return base.Bounds;
}
internal set {
base.Bounds = value;
}
}
}
}
#endif

View File

@@ -0,0 +1,291 @@
#if !JAVA
/*
* BTrackBar.cs
* Copyright (c) 2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
//#define BENCH
using System;
using System.Windows.Forms;
using System.Reflection;
namespace Boare.Lib.AppUtil {
/// <summary>
/// Valueの型を変えられるTrackBar
/// </summary>
public class BTrackBar<T> : UserControl where T : struct, IComparable<T> {
const int _MAX = 10000;
private T m_value;
private T m_min;
private T m_max;
private T m_tick_frequency;
private MethodInfo m_parser = null;
private ValueType m_value_type = ValueType.int_;
private TrackBarEx m_track_bar;
private Type m_type = typeof( int );
private enum ValueType {
sbyte_,
byte_,
shoft_,
ushort_,
int_,
uint_,
long_,
ulong_,
}
public event EventHandler ValueChanged;
private static void test() {
System.Windows.Forms.TrackBar tb = new System.Windows.Forms.TrackBar();
BTrackBar<int> tb2 = new BTrackBar<int>();
}
public BTrackBar() {
InitializeComponent();
T value_type = new T();
if ( value_type is byte ) {
m_value_type = BTrackBar<T>.ValueType.byte_;
} else if ( value_type is sbyte ) {
m_value_type = BTrackBar<T>.ValueType.sbyte_;
} else if ( value_type is short ) {
m_value_type = BTrackBar<T>.ValueType.shoft_;
} else if ( value_type is ushort ) {
m_value_type = BTrackBar<T>.ValueType.ushort_;
} else if ( value_type is int ) {
m_value_type = BTrackBar<T>.ValueType.int_;
} else if ( value_type is uint ) {
m_value_type = BTrackBar<T>.ValueType.uint_;
} else if ( value_type is long ) {
m_value_type = BTrackBar<T>.ValueType.long_;
} else if ( value_type is ulong ) {
m_value_type = BTrackBar<T>.ValueType.ulong_;
} else {
throw new NotSupportedException( "generic type T must be byte, sbyte, short, ushort, int, uint, long or ulong" );
}
m_type = value_type.GetType();
m_parser = typeof( T ).GetMethod( "Parse", new Type[] { typeof( string ) } );
if ( m_parser == null ) {
throw new ApplicationException( "this error never occurs; m_type=" + m_value_type );
}
#if BENCH
// Benchmark1: string parser
int _COUNT = 100000;
MethodInfo parser_double = typeof( double ).GetMethod( "Parse", new Type[] { typeof( string ) } );
Console.WriteLine( "parsed \"123.456\" = " + ((double)parser_double.Invoke( typeof( double ), new object[] { "123.456" } )) );
DateTime start = DateTime.Now;
for ( int i = 0; i < _COUNT; i++ ) {
double v = (double)parser_double.Invoke( typeof( double ), new object[] { "123.456" } );
}
Console.WriteLine( "Benchmark1; " + DateTime.Now.Subtract( start ).TotalMilliseconds / (double)_COUNT + "ms" );
// Benchmark2: BinaryFormatter
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream ms = new System.IO.MemoryStream( 64 );
const double cdbbl = 123.456;
bf.Serialize( ms, cdbbl );
_COUNT = 10000;
ms.Seek( 0, System.IO.SeekOrigin.Begin );
Console.WriteLine( "deserilized = " + ((double)bf.Deserialize( ms )) );
start = DateTime.Now;
for ( int i = 0; i < _COUNT; i++ ) {
ms.Seek( 0, System.IO.SeekOrigin.Begin );
double v = (double)bf.Deserialize( ms );
}
Console.WriteLine( "Benchmark2; " + DateTime.Now.Subtract( start ).TotalMilliseconds / (double)_COUNT + "ms" );
// Benchmark3: Convert class
object obj = cdbbl;
Console.WriteLine( "Converted = " + Convert.ToDouble( obj ) );
_COUNT = 100000;
start = DateTime.Now;
for ( int i = 0; i < _COUNT; i++ ) {
double v = Convert.ToDouble( obj );
}
Console.WriteLine( "Benchmark3; " + DateTime.Now.Subtract( start ).TotalMilliseconds / (double)_COUNT + "ms" );
#endif
}
public T Maximum {
get {
return m_max;
}
set {
if ( value.CompareTo( m_min ) < 0 ) {
throw new ArgumentOutOfRangeException( "Maximum" );
}
m_max = value;
if ( m_max.CompareTo( m_value ) < 0 ) {
Value = m_max;
}
}
}
public T Minimum {
get {
return m_min;
}
set {
if ( value.CompareTo( m_max ) > 0 ) {
throw new ArgumentOutOfRangeException( "Minimum" );
}
m_min = value;
if ( m_min.CompareTo( m_value ) > 0 ) {
Value = m_min;
}
}
}
public TickStyle TickStyle {
get {
return m_track_bar.TickStyle;
}
set {
m_track_bar.TickStyle = value;
}
}
public T TickFrequency {
get {
return m_tick_frequency;
}
set {
m_tick_frequency = value;
double max = asDouble( m_max );
double min = asDouble( m_min );
double stride = asDouble( m_tick_frequency );
double rate = (max - min) / stride;
Console.WriteLine( "BTrackBar+set__TickFrequency" );
Console.WriteLine( " rate=" + rate );
int freq = (int)(_MAX / rate);
Console.WriteLine( " freq=" + freq );
Console.WriteLine( " m_track_bar.Maximum=" + m_track_bar.Maximum );
m_track_bar.TickFrequency = freq;
}
}
public T Value {
get {
return m_value;
}
set {
if ( value.CompareTo( m_max ) > 0 ) {
throw new ArgumentOutOfRangeException( "Value" );
}
if ( value.CompareTo( m_min ) < 0 ) {
throw new ArgumentOutOfRangeException( "Value" );
}
T old = m_value;
m_value = value;
if ( old.CompareTo( m_value ) != 0 && ValueChanged != null ) {
ValueChanged( this, new EventArgs() );
}
}
}
private double asDouble( T value ) {
object o = value;
return Convert.ToDouble( o );
}
private T add( T value1, T value2 ) {
object o1 = value1;
object o2 = value2;
switch ( m_value_type ) {
case BTrackBar<T>.ValueType.sbyte_:
sbyte sb1 = Convert.ToSByte( o1 );
sbyte sb2 = Convert.ToSByte( o2 );
object sb_r = (sb1 + sb2);
return (T)sb_r;
case BTrackBar<T>.ValueType.byte_:
byte b1 = Convert.ToByte( o1 );
byte b2 = Convert.ToByte( o2 );
object b_r = (b1 + b2);
return (T)b_r;
case BTrackBar<T>.ValueType.shoft_:
short s1 = Convert.ToInt16( o1 );
short s2 = Convert.ToInt16( o2 );
object s_r = (s1 + s2);
return (T)s_r;
case BTrackBar<T>.ValueType.ushort_:
ushort us1 = Convert.ToUInt16( o1 );
ushort us2 = Convert.ToUInt16( o2 );
object us_r = (us1 + us2);
return (T)us_r;
case BTrackBar<T>.ValueType.int_:
int i1 = Convert.ToInt32( o1 );
int i2 = Convert.ToInt32( o2 );
object i_r = (i1 + i2);
return (T)i_r;
case BTrackBar<T>.ValueType.uint_:
uint ui1 = Convert.ToUInt32( o1 );
uint ui2 = Convert.ToUInt32( o2 );
object ui_r = ui1 + ui2;
return (T)ui_r;
case BTrackBar<T>.ValueType.long_:
long l1 = Convert.ToInt64( o1 );
long l2 = Convert.ToInt64( o2 );
object l_r = l1 + l2;
return (T)l_r;
case BTrackBar<T>.ValueType.ulong_:
ulong ul1 = Convert.ToUInt64( o1 );
ulong ul2 = Convert.ToUInt64( o2 );
object ul_r = ul1 + ul2;
return (T)ul_r;
}
return new T();
}
private void InitializeComponent() {
this.m_track_bar = new TrackBarEx();
((System.ComponentModel.ISupportInitialize)(this.m_track_bar)).BeginInit();
this.SuspendLayout();
//
// trackBar
//
this.m_track_bar.Dock = System.Windows.Forms.DockStyle.Fill;
this.m_track_bar.Location = new System.Drawing.Point( 0, 0 );
this.m_track_bar.Name = "trackBar";
this.m_track_bar.Size = new System.Drawing.Size( 286, 55 );
this.m_track_bar.TabIndex = 0;
this.m_track_bar.Maximum = _MAX;
this.m_track_bar.Minimum = 0;
this.m_track_bar.TickFrequency = 1;
this.m_track_bar.SmallChange = 1;
this.m_track_bar.m_wheel_direction = false;
//
// BTrackBar
//
this.Controls.Add( this.m_track_bar );
this.Name = "BTrackBar";
this.Size = new System.Drawing.Size( 286, 55 );
((System.ComponentModel.ISupportInitialize)(this.m_track_bar)).EndInit();
this.ResumeLayout( false );
this.PerformLayout();
}
}
internal class TrackBarEx : TrackBar {
public bool m_wheel_direction = true;
protected override void OnMouseWheel( MouseEventArgs e ) {
if ( m_wheel_direction ) {
base.OnMouseWheel( new MouseEventArgs( e.Button, e.Clicks, e.X, e.Y, e.Delta ) );
} else {
base.OnMouseWheel( new MouseEventArgs( e.Button, e.Clicks, e.X, e.Y, -e.Delta ) );
}
}
}
}
#endif

View File

@@ -0,0 +1,67 @@
/*
* BHScrollBar.Designer.cs
* Copyright (c) 2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace Boare.Lib.AppUtil {
partial class OBSOLUTE_BVScrollBar {
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
/// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
protected override void Dispose( bool disposing ) {
if ( disposing && (components != null) ) {
components.Dispose();
}
base.Dispose( disposing );
}
#region
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent() {
this.vScroll = new System.Windows.Forms.VScrollBar();
this.SuspendLayout();
//
// hScroll
//
this.vScroll.Dock = System.Windows.Forms.DockStyle.Fill;
this.vScroll.Location = new System.Drawing.Point( 0, 0 );
this.vScroll.Name = "hScroll";
this.vScroll.Size = new System.Drawing.Size( 16, 205 );
this.vScroll.TabIndex = 0;
this.vScroll.ValueChanged += new System.EventHandler( this.vScroll_ValueChanged );
//
// BHScrollBar
//
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 12F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add( this.vScroll );
this.Name = "BHScrollBar";
this.Size = new System.Drawing.Size( 16, 205 );
this.ResumeLayout( false );
}
#endregion
private System.Windows.Forms.VScrollBar vScroll;
}
}

View File

@@ -0,0 +1,88 @@
#if !JAVA
/*
* BVScrollBar.cs
* Copyright (c) 2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.Windows.Forms;
namespace Boare.Lib.AppUtil {
/// <summary>
/// Valueの値が正しくMinimumからMaximumの間を動くスクロールバー
/// </summary>
public partial class OBSOLUTE_BVScrollBar : UserControl {
int m_max = 100;
int m_min = 0;
public event EventHandler ValueChanged;
public OBSOLUTE_BVScrollBar() {
InitializeComponent();
}
public int Value {
get {
return vScroll.Value;
}
set {
vScroll.Value = value;
}
}
public int LargeChange {
get {
return vScroll.LargeChange;
}
set {
vScroll.LargeChange = value;
vScroll.Maximum = m_max + value;
}
}
public int SmallChange {
get {
return vScroll.SmallChange;
}
set {
vScroll.SmallChange = value;
}
}
public int Maximum {
get {
return m_max;
}
set {
m_max = value;
vScroll.Maximum = m_max + vScroll.LargeChange;
}
}
public int Minimum {
get {
return m_min;
}
set {
m_min = value;
}
}
private void vScroll_ValueChanged( object sender, EventArgs e ) {
if ( ValueChanged != null ) {
ValueChanged( this, e );
}
}
}
}
#endif

View File

@@ -0,0 +1,161 @@
#if !JAVA
/*
* BitmapEx.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace Boare.Lib.AppUtil {
public unsafe class BitmapEx : IDisposable {
private Bitmap m_base;
private bool m_locked = false;
private BitmapData m_bd;
private int m_stride;
private int m_byte_per_pixel;
public int Width {
get {
return m_base.Width;
}
}
public int Height {
get {
return m_base.Height;
}
}
public void Dispose() {
EndLock();
m_base.Dispose();
}
public void EndLock() {
if ( m_locked ) {
m_base.UnlockBits( m_bd );
m_locked = false;
}
}
public Bitmap GetBitmap() {
return (Bitmap)m_base.Clone();
}
public Color GetPixel( int x, int y ) {
if ( !m_locked ) {
BeginLock();
}
int location = y * m_stride + m_byte_per_pixel * x;
byte* dat = (byte*)m_bd.Scan0;
byte b = dat[location];
byte g = dat[location + 1];
byte r = dat[location + 2];
byte a = 255;
if ( m_base.PixelFormat == PixelFormat.Format32bppArgb ) {
a = dat[location + 3];
}
return Color.FromArgb( a, r, g, b );
}
public void SetPixel( int x, int y, Color color ) {
if ( !m_locked ) {
BeginLock();
}
int location = y * m_stride + m_byte_per_pixel * x;
byte* dat = (byte*)m_bd.Scan0;
dat[location] = (byte)color.B;
dat[location + 1] = (byte)color.G;
dat[location + 2] = (byte)color.R;
if ( m_base.PixelFormat == PixelFormat.Format32bppArgb ) {
dat[location + 3] = (byte)color.A;
}
}
public void BeginLock(){
if ( !m_locked ) {
m_bd = m_base.LockBits( new Rectangle( 0, 0, m_base.Width, m_base.Height ),
ImageLockMode.ReadWrite,
m_base.PixelFormat );
m_stride = m_bd.Stride;
switch ( m_base.PixelFormat ) {
case PixelFormat.Format24bppRgb:
m_byte_per_pixel = 3;
break;
case PixelFormat.Format32bppArgb:
m_byte_per_pixel = 4;
break;
default:
throw new Exception( "unsuported pixel format" );
}
m_locked = true;
}
}
~BitmapEx() {
m_base.Dispose();
}
public BitmapEx( Image original ) {
m_base = new Bitmap( original );
}
public BitmapEx( string filename ) {
m_base = new Bitmap( filename );
}
public BitmapEx( Stream stream ) {
m_base = new Bitmap( stream );
}
public BitmapEx( Image original, Size newSize ) {
m_base = new Bitmap( original, newSize );
}
public BitmapEx( int width, int height ) {
m_base = new Bitmap( width, height );
}
public BitmapEx( Stream stream, bool useIcm ) {
m_base = new Bitmap( stream, useIcm );
}
public BitmapEx( string filename, bool useIcm ) {
m_base = new Bitmap( filename, useIcm );
}
public BitmapEx( Type type, string resource ) {
m_base = new Bitmap( type, resource );
}
public BitmapEx( Image original, int width, int height ) {
m_base = new Bitmap( original, width, height );
}
public BitmapEx( int width, int height, Graphics g ) {
m_base = new Bitmap( width, height, g );
}
public BitmapEx( int width, int height, PixelFormat format ) {
m_base = new Bitmap( width, height, format );
}
public BitmapEx( int width, int height, int stride, PixelFormat format, IntPtr scan0 ) {
m_base = new Bitmap( width, height, stride, format, scan0 );
}
}
}
#endif

View File

@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0C58B068-272F-4390-A14F-3D72AFCF3DFB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Boare.Lib.AppUtil</RootNamespace>
<AssemblyName>Boare.Lib.AppUtil</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>bin\x86\Debug\Boare.Lib.AppUtil.XML</DocumentationFile>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>bin\x86\Release\Boare.Lib.AppUtil.XML</DocumentationFile>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AuthorListEntry.cs" />
<Compile Include="BHScrollBar.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="BHScrollBar.Designer.cs">
<DependentUpon>BHScrollBar.cs</DependentUpon>
</Compile>
<Compile Include="BitmapEx.cs" />
<Compile Include="ColorBar.cs" />
<Compile Include="CubicSpline.cs" />
<Compile Include="CursorUtil.cs" />
<Compile Include="DockPanelContainer.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="InputBox.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ISO639.cs" />
<Compile Include="MessageBodyEntry.cs" />
<Compile Include="Messaging.cs" />
<Compile Include="MessageBody.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="BSplitContainer.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="BSplitterPanel.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="BTrackBar.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Util.cs" />
<Compile Include="VersionInfo.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="VersionInfo.Designer.cs">
<DependentUpon>VersionInfo.cs</DependentUpon>
</Compile>
<Compile Include="BVScrollBar.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="BVScrollBar.Designer.cs">
<DependentUpon>BVScrollBar.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\bocoree\bocoree.csproj">
<Project>{C8AAE632-9C6C-4372-8175-811528A66742}</Project>
<Name>bocoree</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,277 @@
#if !JAVA
/*
* CubicSpline.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
namespace Boare.Lib.AppUtil {
public class CubicSpline : ICloneable, IDisposable {
int m_num_key;
public double[] m_key, m_sp3_a, m_sp3_b, m_sp3_c, m_sp3_d;
double m_default;
public void Dispose() {
m_key = null;
m_sp3_a = null;
m_sp3_b = null;
m_sp3_c = null;
m_sp3_d = null;
GC.Collect();
m_num_key = 0;
}
public object Clone() {
CubicSpline ret = new CubicSpline( m_key, m_sp3_d );
ret.DefaultValue = m_default;
return ret;
}
public double DefaultValue {
get {
return m_default;
}
set {
m_default = value;
}
}
public double GetValue( double x ) {
int status;
double a, b, c, d, xx;
int i, index;
status = 0;
if ( this.m_num_key == -1 ) {
status = -2;
return 0.0;
}
if ( x < this.m_key[0] || this.m_key[this.m_num_key] < x ) {
status = -1;
return 0.0;
}//end if
index = -1;
for ( i = 0; i < this.m_num_key; i++ ) {// do i = 0, sp3%noOfKey - 1
if ( this.m_key[i] <= x && x <= this.m_key[i + 1] ) {// if(sp3%key(i) <= x .and. x <= sp3%key(i + 1))then
index = i;
break;// exit
}//end if
}//end do
xx = x - this.m_key[index];// xx = x - sp3%key(index)
a = this.m_sp3_a[index];// a = sp3%a(index)
b = this.m_sp3_b[index];// b = sp3%b(index)
c = this.m_sp3_c[index];// c = sp3%c(index)
d = this.m_sp3_d[index];// d = sp3%d(index)
return ((a * xx + b) * xx + c) * xx + d;// ans = ((a * xx + b) * xx + c) * xx + d
}//end subroutine spline3_val
/// <summary>配列の形で与えられるデータ点から3次のスプライン補間で用いる各区域のxの多項式の係数を計算します</summary>
/// <param name="x">データ点のx座標を格納した配列</param>
/// <param name="y">データ点のy座標を格納した配列</param>
public CubicSpline( double[] x, double[] y ) {
//integer, intent(in) :: n
//real(8), intent(in) :: x(0:n), y(0:n)
//integer, intent(out) :: status
int n = x.Length - 1;
int status;
m_num_key = -1;
m_default = 0.0;
double[] h, v, a, b, c, u, tmp, xx, yy;//real(8), allocatable :: h(:), v(:), a(:), b(:), c(:), u(:), tmp(:), xx(:), yy(:)
double buff1, buff2;//real(8) buff1, buff2
int i, iostatus, nn, j;//integer i, iostatus, nn, j
status = 0;
nn = n;
xx = new double[n + 1];
yy = new double[n + 1];//allocate(xx(0:n), yy(0:n))
xx = x;
yy = y;//yy(0:n) = y(0:n)
//nullify(sp3%a)
//nullify(sp3%b)
//nullify(sp3%c)
//nullify(sp3%d)
//nullify(sp3%key)
while ( true ) {//do
iostatus = 0;
for ( i = 1; i <= nn - 1; i++ ) {// do i = 1, nn - 1
if ( xx[i + 1] - x[i] == 0.0 ) {// if(xx(i + 1) - xx(i) == 0.0d0)then
for ( j = i; j <= nn - 2; j++ ) {// do j = i, nn - 2
xx[j] = xx[j + 1];// xx(j) = xx(j + 1)
yy[j] = yy[j + 1];// yy(j) = yy(j + 1)
}// end do
iostatus = -1;
// create the copy of xx
//if(allocated(tmp))then
//deallocate(tmp)
//end if
tmp = new double[nn];// allocate(tmp(0:nn - 1))
for ( int k = 0; k < nn; k++ ) {
tmp[k] = xx[k];
}// tmp(0:nn - 1) = xx(0:nn - 1)
// deallocate(xx)
xx = new double[nn];// allocate(xx(0:nn - 1))
for ( int k = 0; k < nn; k++ ) {
xx[k] = tmp[k];
}// xx(0:nn - 1) = tmp(0:nn - 1)
// create the copy of yy
for ( int k = 0; k < nn; k++ ) {
tmp[k] = yy[k];
}// tmp(0:nn - 1) = yy(0:nn - 1)
//deallocate(yy)
yy = new double[nn];// allocate(yy(0:nn - 1))
for ( int k = 0; k < nn; k++ ) {
yy[k] = tmp[k];
}// yy(0:nn - 1) = tmp(0:nn - 1)
break;// exit
}//end if
}//end do
if ( iostatus == 0 ) {// if(iostatus == 0)then
break;// exit
} else {// else
nn = nn - 1;// nn = nn - 1
}// end if
}// end do
//allocate(h(0:nn - 1), v(1:nn - 1), a(1:nn - 1), b(1:nn - 1), c(1:nn - 1), u(1:nn - 1))
h = new double[nn];
v = new double[nn - 1];
a = new double[nn - 1];
b = new double[nn - 1];
c = new double[nn - 1];
u = new double[nn - 1];
// executed in debug mode ******************************************************************************************************
//if(spline_debug_flag == 1)then ! **
//open(unit = 26, file = 'spline_debug.txt') ! **
//end if ! **
// *****************************************************************************************************************************
// calculate h_j
for ( i = 0; i < nn; i++ ) {// do i = 0, nn - 1
h[i] = xx[i + 1] - xx[i];// h(i) = xx(i + 1) - xx(i)
if ( h[i] <= 0.0 ) {// if(h(i) <= 0.0d0)then
this.m_key = new double[1];
this.m_sp3_a = new double[1];
this.m_sp3_b = new double[1];
this.m_sp3_c = new double[1];
this.m_sp3_d = new double[1];
return;
}
}
// calculate v_j
for ( i = 1; i < nn; i++ ) {// do i = 1, nn - 1
buff1 = yy[i + 1] - yy[i];// buff1 = yy(i + 1) - yy(i)
buff2 = yy[i] - y[i - 1];// buff2 = yy(i) - yy(i - 1)
if ( buff1 == 0.0 ) {// if(buff1 == 0.0d0)then
if ( buff2 == 0.0 ) {// if(buff2 == 0.0d0)then
v[i - 1] = 0;// v(i) = 0.0d0
} else {// else
v[i - 1] = 6.0 * (-(yy[i] - yy[i - 1]) / h[i - 1]);// v(i) = 6.0d0 * (- (yy(i) - yy(i - 1)) / h(i - 1))
}// end if
} else {// else
if ( buff2 == 0.0 ) {// if(buff2 == 0.0d0)then
v[i - 1] = 6.0 * ((yy[i + 1] - yy[i]) / h[i]);// v(i) = 6.0d0 * ((yy(i + 1) - yy(i)) / h(i))
} else {// else
v[i - 1] = 6.0 * ((yy[i + 1] - yy[i]) / h[i] - (yy[i] - yy[i - 1]) / h[i - 1]);// v(i) = 6.0d0 * ((yy(i + 1) - yy(i)) / h(i) - (yy(i) - yy(i - 1)) / h(i - 1))
}// end if
}// end if
}//end do
for ( i = 1; i < nn; i++ ) {// do i = 1, nn - 1
a[i - 1] = 2.0 * (h[i - 1] + h[i]);// a(i) = 2.0d0 * (h(i - 1) + h(i))
b[i - 1] = h[i - 1];// b(i) = h(i - 1)
c[i - 1] = h[i];// c(i) = h(i)
}// end do
LUDecTDM( nn - 1, a, b, c, v, out u );// call LUDecTDM(nn - 1, a, b, c, v, u)
m_num_key = nn;// sp3%noOfKey = nn
this.m_sp3_a = new double[nn];// allocate(sp3%a(0:nn - 1))
this.m_sp3_b = new double[nn];// allocate(sp3%b(0:nn - 1))
this.m_sp3_c = new double[nn];// allocate(sp3%c(0:nn - 1))
this.m_sp3_d = new double[nn];// allocate(sp3%d(0:nn - 1))
this.m_key = new double[nn + 1];// allocate(sp3%key(0:nn))
this.m_sp3_a[0] = u[0] / (6.0 * h[0]);// sp3%a(0) = u(1) / (6.0d0 * h(0))
this.m_sp3_b[0] = 0.0;// sp3%b(0) = 0.0d0
this.m_sp3_c[0] = (yy[1] - yy[0]) / h[0] - h[0] * u[0] / 6.0;// sp3%c(0) = (yy(1) - yy(0)) / h(0) - h(0) * u(1) / 6.0d0
this.m_sp3_a[nn - 1] = -u[nn - 2] / (6.0 * h[nn - 1]);// sp3%a(nn - 1) = -u(nn - 1) / (6.0d0 * h(nn - 1))
this.m_sp3_b[nn - 1] = u[nn - 2] * 0.5;// sp3%b(nn - 1) = u(nn - 1) * 0.5d0
this.m_sp3_c[nn - 1] = (yy[nn] - yy[nn - 1]) / h[nn - 1] - h[nn - 1] * u[nn - 2] / 3.0;// sp3%c(nn - 1) = (yy(nn) - yy(nn - 1)) / h(nn - 1) - h(nn - 1) * u(nn - 1) / 3.0d0
for ( i = 1; i <= nn - 2; i++ ) {// do i = 1, nn - 2
this.m_sp3_a[i] = (u[i] - u[i - 1]) / (6.0 * h[i]);// sp3%a(i) = (u(i + 1) - u(i)) / (6.0d0 * h(i))
this.m_sp3_b[i] = u[i - 1] * 0.5;// sp3%b(i) = u(i) * 0.5d0
this.m_sp3_c[i] = (yy[i + 1] - yy[i]) / h[i] - h[i] * (2.0 * u[i - 1] + u[i]) / 6.0;// sp3%c(i) = (yy(i + 1) - yy(i)) / h(i) - h(i) * (2.0d0 * u(i) + u(i + 1)) / 6.0d0
}//end do
this.m_key = xx;
// sp3%key(0:nn) = xx(0:nn)
for ( int k = 0; k < nn; k++ ) {
this.m_sp3_d[k] = yy[k];
}// sp3%d(0:nn - 1) = yy(0:nn - 1)
}
/// <summary>
/// This subroutine solves system of linear equation(only for
/// tridiagonal matrix system) by LU decompression method.
/// Meanings of variables are defined below.
/// ( a1 c1 0 ) ( x1 ) ( y1 )
/// ( b2 a2 c2 ) ( x2 ) ( y2 )
/// ( b3 a3 c3 ) ( x3 ) ( y3 )
/// ( ... ) ( ...) = ( ...)
/// ( bN-1 aN-1 cN-1 ) (xN-1) (yN-1)
/// ( 0 bN aN ) ( xN ) ( yN )
/// </summary>
/// <param name="N"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <param name="y"></param>
/// <param name="x"></param>
private static void LUDecTDM( int N, double[] a, double[] b, double[] c, double[] y, out double[] x ) {
double[] d = new double[N];
double[] z = new double[N];
double[] l = new double[N];
int i;
x = new double[N];
d[0] = a[0];// d(1) = a(1)
for ( i = 1; i < N; i++ ) {// do i = 2, N
l[i] = b[i] / d[i - 1];// l(i) = b(i) / d(i - 1)
d[i] = a[i] - l[i] * c[i - 1];// d(i) = a(i) - l(i) * c(i - 1)
}// end do
z[0] = y[0];// z(1) = y(1)
for ( i = 1; i < N; i++ ) {// do i = 2, N
z[i] = y[i] - l[i] * z[i - 1];// z(i) = y(i) - l(i) * z(i - 1)
}// end do
x[N - 1] = z[N - 1] / d[N - 1];// x(N) = z(N) / d(N)
for ( i = N - 2; i >= 0; i-- ) {// do i = N - 1, 1, -1
x[i] = (z[i] - c[i] * x[i + 1]) / d[i];// x(i) = (z(i) - c(i) * x(i + 1)) / d(i)
}// end do
}
}
}
#endif

View File

@@ -0,0 +1,212 @@
#if !JAVA
#define RGB24
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Reflection;
using bocoree;
namespace Boare.Lib.AppUtil {
public static class CursorUtil {
public static void SaveAsIcon( Bitmap item, Stream stream, Color transp ) {
SaveCor( item, new Point( 0, 0 ), stream, 1, transp );
}
public static void SaveAsCursor( Bitmap item, Point hotspot, Stream stream, Color transp ) {
SaveCor( item, hotspot, stream, 2, transp );
}
private static void SaveCor( Bitmap item, Point hotspot, Stream stream, ushort type, Color transp ) {
IconFileHeader ifh = new IconFileHeader();
ifh.icoReserved = 0x0;
ifh.icoResourceCount = 1;
ifh.icoResourceType = type;
ifh.Write( stream );
IconInfoHeader iif = new IconInfoHeader();
BITMAPINFOHEADER bih = new BITMAPINFOHEADER();
iif.Width = (byte)item.Width;
iif.Height = (byte)item.Height;
iif.ColorCount = 0;
iif.Reserved1 = 0;
iif.Reserved2 = (ushort)hotspot.X;
iif.Reserved3 = (ushort)hotspot.Y;
#if RGB24
int linesize = ((item.Width * 24 + 31) / 32) * 4;
#else
int linesize = ((item.Width * 32 + 31) / 32) * 4;
#endif
int linesize_mask = ((item.Width * 1 + 31) / 32) * 4;
int size = linesize * item.Height + linesize_mask * item.Height + 40;
#if DEBUG
Console.WriteLine( "linesize=" + linesize );
#endif
iif.icoDIBSize = (uint)size;
iif.icoDIBOffset = 0x16;
iif.Write( stream );
bih.biSize = 40;
bih.biWidth = item.Width;
#if RGB24
bih.biHeight = item.Height * 2;
#else
bih.biHeight = item.Height * 2;
#endif
bih.biPlanes = 1;
#if RGB24
bih.biBitCount = 24;
#else
bih.biBitCount = 32;
#endif
bih.biCompression = 0;
bih.biSizeImage = (uint)(linesize * item.Height);
bih.biXPelsPerMeter = 0;// (int)(item.HorizontalResolution / 2.54e-2);
bih.biYPelsPerMeter = 0;// (int)(item.VerticalResolution / 2.54e-2);
bih.biClrUsed = 0;
bih.biClrImportant = 0;
bih.Write( stream );
for ( int y = item.Height - 1; y >= 0; y-- ) {
int count = 0;
for ( int x = 0; x < item.Width; x++ ) {
Color c = item.GetPixel( x, y );
stream.WriteByte( (byte)c.B );
stream.WriteByte( (byte)c.G );
stream.WriteByte( (byte)c.R );
#if DEBUG
if ( c.R != transp.R || c.G != transp.G || c.B != transp.B ) {
Console.WriteLine( "color=" + c );
}
#endif
#if RGB24
count += 3;
#else
stream.WriteByte( (byte)c.A );
count += 4;
#endif
}
for ( int i = count; i < linesize; i++ ) {
stream.WriteByte( 0x0 );
}
}
for ( int y = item.Height - 1; y >= 0; y-- ) {
int count = 0;
byte v = 0x0;
int tcount = 0;
for ( int x = 0; x < item.Width; x++ ) {
Color c = item.GetPixel( x, y );
byte tr = 0x0;
if ( c.R == transp.R && c.G == transp.G && c.B == transp.B ){
tr = 0x1;
}
v = (byte)((byte)(v << 1) | (byte)(tr & 0x1));
tcount++;
if ( tcount == 8 ) {
stream.WriteByte( v );
count++;
tcount = 0;
v = 0x0;
}
}
if ( 0 < tcount ) {
v = (byte)(v << (9 - tcount));
stream.WriteByte( v );
count++;
}
for ( int i = count; i < linesize_mask; i++ ) {
stream.WriteByte( 0x0 );
}
}
}
}
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
public struct IconFileHeader {
public ushort icoReserved;
public ushort icoResourceType;
public ushort icoResourceCount;
public void Write( Stream stream ) {
byte[] buf;
buf = BitConverter.GetBytes( icoReserved );
stream.Write( buf, 0, 2 );
buf = BitConverter.GetBytes( icoResourceType );
stream.Write( buf, 0, 2 );
buf = BitConverter.GetBytes( icoResourceCount );
stream.Write( buf, 0, 2 );
}
public static IconFileHeader Read( Stream fs ) {
IconFileHeader ifh = new IconFileHeader();
byte[] buf = new byte[2];
fs.Read( buf, 0, 2 );
ifh.icoReserved = BitConverter.ToUInt16( buf, 0 );
fs.Read( buf, 0, 2 );
ifh.icoResourceType = BitConverter.ToUInt16( buf, 0 );
fs.Read( buf, 0, 2 );
ifh.icoResourceCount = BitConverter.ToUInt16( buf, 0 );
return ifh;
}
}
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
public struct IconInfoHeader {
public byte Width;
public byte Height;
public byte ColorCount;
public byte Reserved1;
public ushort Reserved2;
public ushort Reserved3;
public uint icoDIBSize;
public uint icoDIBOffset;
public override string ToString() {
return "{Width=" + Width + ", Height=" + Height + ", ColorCount=" + ColorCount + ", Reserved1=" + Reserved1 + ", Reserved2=" + Reserved2 + ", Reserved3=" + Reserved3 + ", icoDIBSize=" + icoDIBSize + ", icoDIBOffset=" + icoDIBOffset + "}";
}
public void Write( Stream stream ) {
byte[] buf;
stream.WriteByte( Width );
stream.WriteByte( Height );
stream.WriteByte( ColorCount );
stream.WriteByte( Reserved1 );
buf = BitConverter.GetBytes( Reserved2 );
stream.Write( buf, 0, 2 );
buf = BitConverter.GetBytes( Reserved3 );
stream.Write( buf, 0, 2 );
buf = BitConverter.GetBytes( icoDIBSize );
stream.Write( buf, 0, 4 );
buf = BitConverter.GetBytes( icoDIBOffset );
stream.Write( buf, 0, 4 );
}
public static IconInfoHeader Read( Stream stream ) {
IconInfoHeader iih = new IconInfoHeader();
iih.Width = (byte)stream.ReadByte();
iih.Height = (byte)stream.ReadByte();
iih.ColorCount = (byte)stream.ReadByte();
iih.Reserved1 = (byte)stream.ReadByte();
byte[] buf = new byte[4];
stream.Read( buf, 0, 4 );
iih.Reserved2 = BitConverter.ToUInt16( buf, 0 );
iih.Reserved3 = BitConverter.ToUInt16( buf, 2 );
stream.Read( buf, 0, 4 );
iih.icoDIBSize = BitConverter.ToUInt32( buf, 0 );
stream.Read( buf, 0, 4 );
iih.icoDIBOffset = BitConverter.ToUInt32( buf, 0 );
return iih;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
#if !JAVA
using System;
using System.Windows.Forms;
namespace Boare.Lib.AppUtil {
public class DockPanelContainer : Panel {
}
}
#endif

View File

@@ -0,0 +1,31 @@
#if !JAVA
/*
* ISO639.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System.Globalization;
namespace Boare.Lib.AppUtil {
internal class iso639 {
public static bool CheckValidity( string code_string ) {
try {
CultureInfo c = CultureInfo.CreateSpecificCulture( code_string );
} catch {
return false;
}
return true;
}
}
}
#endif

114
Boare.Lib.AppUtil/InputBox.Designer.cs generated Normal file
View File

@@ -0,0 +1,114 @@
/*
* InputBox.Designer.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace Boare.Lib.AppUtil {
partial class InputBox {
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
/// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
protected override void Dispose( bool disposing ) {
if ( disposing && (components != null) ) {
components.Dispose();
}
base.Dispose( disposing );
}
#region Windows
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent() {
this.txtInput = new System.Windows.Forms.TextBox();
this.btnOk = new System.Windows.Forms.Button();
this.lblMessage = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtInput
//
this.txtInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtInput.Location = new System.Drawing.Point( 12, 24 );
this.txtInput.Name = "txtInput";
this.txtInput.Size = new System.Drawing.Size( 309, 19 );
this.txtInput.TabIndex = 0;
//
// btnOk
//
this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnOk.Location = new System.Drawing.Point( 246, 49 );
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size( 75, 23 );
this.btnOk.TabIndex = 1;
this.btnOk.Text = "OK";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler( this.btnOk_Click );
//
// lblMessage
//
this.lblMessage.AutoSize = true;
this.lblMessage.Location = new System.Drawing.Point( 12, 9 );
this.lblMessage.Name = "lblMessage";
this.lblMessage.Size = new System.Drawing.Size( 0, 12 );
this.lblMessage.TabIndex = 2;
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point( -100, 49 );
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size( 75, 23 );
this.btnCancel.TabIndex = 3;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
//
// InputBox
//
this.AcceptButton = this.btnOk;
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 12F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size( 333, 82 );
this.Controls.Add( this.btnCancel );
this.Controls.Add( this.lblMessage );
this.Controls.Add( this.btnOk );
this.Controls.Add( this.txtInput );
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "InputBox";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "InputBox";
this.ResumeLayout( false );
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtInput;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Label lblMessage;
private System.Windows.Forms.Button btnCancel;
}
}

View File

@@ -0,0 +1,291 @@
/*
* InputBox.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
package org.kbinani.apputil;
import java.awt.*;
import javax.swing.*;
import org.kbinani.*;
import org.kbinani.windows.forms.*;
#else
using System;
using System.Windows.Forms;
using bocoree.windows.forms;
namespace Boare.Lib.AppUtil {
using BEventArgs = System.EventArgs;
#endif
#if JAVA
public class InputBox extends BForm{
#else
public class InputBox : BForm {
#endif
private BLabel lblMessage;
private BButton btnCancel;
private BTextBox txtInput;
private BButton btnOk;
#if JAVA
public boolean closed = false;
private BDialogResult m_result = BDialogResult.CANCEL;
#else
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;
#endif
public InputBox( String message ) {
#if JAVA
initializeComponent();
#else
InitializeComponent();
#endif
lblMessage.setText( message );
}
#if JAVA
public class ShowDialogRunner implements Runnable{
public void run(){
show();
while( !closed ){
try{
Thread.sleep( 100 );
}catch( Exception ex ){
break;
}
}
hide();
}
}
public BDialogResult showDialog(){
Thread t = new Thread( new ShowDialogRunner() );
t.run();
return m_result;
}
#endif
public String getResult(){
return txtInput.getText();
}
public void setResult( String value ){
txtInput.setText( value );
}
public void btnOk_Click( Object sender, BEventArgs e ) {
#if JAVA
closed = true;
m_result = BDialogResult.OK;
#else
DialogResult = DialogResult.OK;
#endif
}
#if JAVA
private void initializeComponent(){
txtInput = new BTextBox();
btnOk = new BButton();
lblMessage = new BLabel();
btnCancel = new BButton();
//
// txtInput
//
//
// btnOk
//
this.btnOk.setText( "OK" );
this.btnOk.clickEvent.add( new BEventHandler( this, "btnOk_Click" ) );
//
// lblMessage
//
//
// btnCancel
//
this.btnCancel.setText( "Cancel" );
this.btnCancel.setVisible( false );
//
// InputBox
//
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout( gridbag );
// 1段目
JPanel jp1_1 = new JPanel();
gridbag.setConstraints( jp1_1, c );
add( jp1_1 );
c.gridwidth = 2;
c.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints( lblMessage, c );
add( lblMessage );
JPanel jp1_2 = new JPanel();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.NONE;
gridbag.setConstraints( jp1_2, c );
add( jp1_2 );
// 2段目
JPanel jp2_1 = new JPanel();
c.gridwidth = 1;
gridbag.setConstraints( jp2_1, c );
add( jp2_1 );
c.gridwidth = 2;
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1.0;
gridbag.setConstraints( txtInput, c );
add( txtInput );
JPanel jp2_2 = new JPanel();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.NONE;
c.weightx = 0.0;
gridbag.setConstraints( jp2_2, c );
add( jp2_2 );
// 3段目
JPanel jp3 = new JPanel();
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints( jp3, c );
add( jp3 );
// 4段目
JPanel jp4_1 = new JPanel();
c.gridwidth = 2;
gridbag.setConstraints( jp4_1, c );
add( jp4_1 );
c.gridwidth = 1;
c.anchor = GridBagConstraints.EAST;
gridbag.setConstraints( btnOk, c );
add( btnOk );
JPanel jp4_2 = new JPanel();
c.gridwidth = GridBagConstraints.REMAINDER;
c.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints( jp4_2, c );
add( jp4_2 );
// 5段目
JPanel jp5 = new JPanel();
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridheight = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
gridbag.setConstraints( jp5, c );
add( jp5 );
this.formClosedEvent.add( new BEventHandler( this, "InputBox_FormClosed" ) );
this.setTitle( "InputBox" );
this.setSize( 339, 110 );
}
public void InputBox_FormClosed( Object sender, BEventArgs e ){
closed = true;
}
#else
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
/// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
protected override void Dispose( bool disposing ) {
if ( disposing && (components != null) ) {
components.Dispose();
}
base.Dispose( disposing );
}
#region Windows
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent() {
this.txtInput = new BTextBox();
this.btnOk = new BButton();
this.lblMessage = new BLabel();
this.btnCancel = new BButton();
this.SuspendLayout();
//
// txtInput
//
this.txtInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtInput.Location = new System.Drawing.Point( 12, 24 );
this.txtInput.Name = "txtInput";
this.txtInput.Size = new System.Drawing.Size( 309, 19 );
this.txtInput.TabIndex = 0;
//
// btnOk
//
this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnOk.Location = new System.Drawing.Point( 246, 49 );
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size( 75, 23 );
this.btnOk.TabIndex = 1;
this.btnOk.Text = "OK";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler( this.btnOk_Click );
//
// lblMessage
//
this.lblMessage.AutoSize = true;
this.lblMessage.Location = new System.Drawing.Point( 12, 9 );
this.lblMessage.Name = "lblMessage";
this.lblMessage.Size = new System.Drawing.Size( 0, 12 );
this.lblMessage.TabIndex = 2;
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point( -100, 49 );
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size( 75, 23 );
this.btnCancel.TabIndex = 3;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
//
// InputBox
//
this.AcceptButton = this.btnOk;
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 12F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size( 333, 82 );
this.Controls.Add( this.btnCancel );
this.Controls.Add( this.lblMessage );
this.Controls.Add( this.btnOk );
this.Controls.Add( this.txtInput );
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "InputBox";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "InputBox";
this.ResumeLayout( false );
this.PerformLayout();
}
#endregion
#endif
}
#if !JAVA
}
#endif

View File

@@ -0,0 +1,21 @@
/*
* MathEx.cs
* Copyright (c) 2008 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace Boare.Lib.AppUtil {
}

View File

@@ -0,0 +1,245 @@
/*
* MessageBody.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
package org.kbinani.apputil;
import java.util.*;
import java.io.*;
import java.awt.image.*;
import org.kbinani.*;
#else
using System;
using bocoree;
using bocoree.java.util;
using bocoree.java.io;
namespace Boare.Lib.AppUtil {
using boolean = System.Boolean;
#endif
public class MessageBody {
public String lang;
public String poHeader = "";
public TreeMap<String, MessageBodyEntry> list = new TreeMap<String, MessageBodyEntry>();
public MessageBody( String lang_ ) {
lang = lang_;
}
public MessageBody( String lang, String[] ids, String[] messages ) {
this.lang = lang;
list = new TreeMap<String, MessageBodyEntry>();
for( int i = 0; i < ids.Length; i++ ) {
list.put( ids[i], new MessageBodyEntry( messages[i], new String[] { } ) );
}
}
public MessageBody( String lang_, String file ) {
lang = lang_;
poHeader = "";
BufferedReader sr = null;
try {
sr = new BufferedReader( new FileReader( file ) );
String line2 = "";
while ( (line2 = sr.readLine()) != null ) {
ByRef<String> msgid = new ByRef<String>( "" );
String first_line = line2;
ByRef<String[]> location = new ByRef<String[]>();
String last_line = readTillMessageEnd( sr, first_line, "msgid", msgid, location );
ByRef<String> msgstr = new ByRef<String>( "" );
ByRef<String[]> location_dumy = new ByRef<String[]>();
last_line = readTillMessageEnd( sr, last_line, "msgstr", msgstr, location_dumy );
if ( PortUtil.getStringLength( msgid.value ) > 0 ) {
list.put( msgid.value, new MessageBodyEntry( msgstr.value, location.value ) );
} else {
poHeader = msgstr.value;
String[] spl = PortUtil.splitString( poHeader, new char[] { (char)0x0d, (char)0x0a }, true );
poHeader = "";
int count = 0;
for ( int i = 0; i < spl.Length; i++ ) {
String line = spl[i];
String[] spl2 = PortUtil.splitString( line, new char[] { ':' }, 2 );
if ( spl2.Length == 2 ) {
String name = spl2[0].Trim();
String ct = "Content-Type";
String cte = "Content-Transfer-Encoding";
if ( name.ToLower().Equals( ct.ToLower() ) ) {
poHeader += (count == 0 ? "" : "\n") + "Content-Type: text/plain; charset=UTF-8";
} else if ( name.ToLower().Equals( cte.ToLower() ) ) {
poHeader += (count == 0 ? "" : "\n") + "Content-Transfer-Encoding: 8bit";
} else {
poHeader += (count == 0 ? "" : "\n") + line;
}
} else {
poHeader += (count == 0 ? "" : "\n") + line;
}
count++;
}
}
}
} catch ( Exception ex ) {
} finally {
if ( sr != null ) {
try {
sr.close();
} catch ( Exception ex2 ) {
}
}
}
}
public String getMessage( String id ) {
if ( list.containsKey( id ) ) {
String ret = list.get( id ).message;
if ( ret.Equals( "" ) ) {
return id;
} else {
return list.get( id ).message;
}
}
return id;
}
public MessageBodyEntry getMessageDetail( String id ) {
if ( list.containsKey( id ) ) {
String ret = list.get( id ).message;
if ( ret.Equals( "" ) ) {
return new MessageBodyEntry( id, new String[] { } );
} else {
return list.get( id );
}
}
return new MessageBodyEntry( id, new String[] { } );
}
public void write( String file ) {
BufferedWriter sw = null;
try {
sw = new BufferedWriter( new FileWriter( file ) );
if ( !poHeader.Equals( "" ) ) {
sw.write( "msgid \"\"" );
sw.newLine();
sw.write( "msgstr \"\"" );
sw.newLine();
String[] spl = PortUtil.splitString( poHeader, new char[] { (char)0x0d, (char)0x0a }, true );
for ( int i = 0; i < spl.Length; i++ ){
String line = spl[i];
sw.write( "\"" + line + "\\" + "n\"" );
sw.newLine();
}
sw.newLine();
} else {
sw.write( "msgid \"\"" );
sw.newLine();
sw.write( "msgstr \"\"" );
sw.newLine();
sw.write( "\"Content-Type: text/plain; charset=UTF-8\\" + "n\"" );
sw.newLine();
sw.write( "\"Content-Transfer-Encoding: 8bit\\" + "n\"" );
sw.newLine();
sw.newLine();
}
for ( Iterator itr = list.keySet().iterator(); itr.hasNext(); ){
String key = (String)itr.next();
String skey = key.Replace( "\n", "\\n\"\n\"" );
MessageBodyEntry mbe = list.get( key );
String s = mbe.message;
Vector<String> location = mbe.location;
int count = location.size();
for ( int i = 0; i < count; i++ ) {
sw.write( "#: " + location.get( i ) );
sw.newLine();
}
sw.write( "msgid \"" + skey + "\"" );
sw.newLine();
s = s.Replace( "\n", "\\n\"\n\"" );
sw.write( "msgstr \"" + s + "\"" );
sw.newLine();
sw.newLine();
}
} catch ( Exception ex ) {
} finally {
if ( sw != null ) {
try {
sw.close();
} catch ( Exception ex2 ) {
}
}
}
}
private static void separateEntryAndMessage( String source, ByRef<String> entry, ByRef<String> message ) {
String line = source.Trim();
entry.value = "";
message.value = "";
if ( PortUtil.getStringLength( line ) <= 0 ) {
return;
}
int index_space = line.IndexOf( ' ' );
int index_dquoter = line.IndexOf( '"' );
int index = Math.Min( index_dquoter, index_space );
entry.value = line.Substring( 0, index );
message.value = line.Substring( index_dquoter + 1 );
message.value = message.value.Substring( 0, PortUtil.getStringLength( message.value ) - 1 );
}
private static String readTillMessageEnd( BufferedReader sr, String first_line, String entry, ByRef<String> msg, ByRef<String[]> locations )
#if JAVA
throws IOException
#endif
{
msg.value = "";
String line = first_line;
Vector<String> location = new Vector<String>();
boolean entry_found = false;
if ( line.StartsWith( entry ) ) {
// 1行目がすでに"entry"の行だった場合
ByRef<String> dum = new ByRef<String>( "" );
ByRef<String> dum2 = new ByRef<String>( "" );
separateEntryAndMessage( line, dum, dum2 );
msg.value += dum2.value;
} else {
while ( (line = sr.readLine()) != null ) {
if ( line.StartsWith( "#:" ) ) {
line = line.Substring( 2 ).Trim();
location.add( line );
} else if ( line.StartsWith( entry ) ) {
ByRef<String> dum = new ByRef<String>( "" );
ByRef<String> dum2 = new ByRef<String>( "" );
separateEntryAndMessage( line, dum, dum2 );
msg.value += dum2.value;
break;
}
}
}
locations.value = location.toArray( new String[] { } );
String ret = "";
while ( (line = sr.readLine()) != null ) {
if ( !line.StartsWith( "\"" ) ) {
msg.value = msg.value.Replace( "\\\"", "\"" );
msg.value = msg.value.Replace( "\\n", "\n" );
return line;
}
int index = line.LastIndexOf( "\"" );
msg.value += line.Substring( 1, index - 1 );
}
msg.value = msg.value.Replace( "\\\"", "\"" );
msg.value = msg.value.Replace( "\\n", "\n" );
return line;
}
}
#if !JAVA
}
#endif

View File

@@ -0,0 +1,39 @@
/*
* MessageBody.cs
* Copyright (c) 2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
package org.kbinani.apputil;
import java.util.*;
#else
using System;
using bocoree.java.util;
namespace Boare.Lib.AppUtil {
#endif
public class MessageBodyEntry {
public String message;
public Vector<String> location = new Vector<String>();
public MessageBodyEntry( String message_, String[] location_ ) {
message = message_;
for ( int i = 0; i < location_.Length; i++ ) {
location.add( location_[i] );
}
}
}
#if !JAVA
}
#endif

View File

@@ -0,0 +1,131 @@
/*
* Messaging.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
package org.kbinani.apputil;
import org.kbinani.*;
import java.util.*;
#else
using System;
using bocoree;
using bocoree.java.util;
namespace Boare.Lib.AppUtil {
#endif
public class Messaging {
private static String s_lang = "";
private static Vector<MessageBody> s_messages = new Vector<MessageBody>();
public static String[] getKeys( String lang ) {
for( Iterator itr = s_messages.iterator(); itr.hasNext(); ){
MessageBody dict = (MessageBody)itr.next();
if ( lang.Equals( dict.lang ) ) {
Vector<String> list = new Vector<String>();
for ( Iterator itr2 = dict.list.keySet().iterator(); itr2.hasNext(); ) {
String key = (String)itr2.next();
list.add( key );
}
return list.toArray( new String[] { } );
}
}
return null;
}
public static String[] getRegisteredLanguage() {
Vector<String> res = new Vector<String>();
for ( Iterator itr = s_messages.iterator(); itr.hasNext(); ) {
MessageBody dict = (MessageBody)itr.next();
res.add( dict.lang );
}
return res.toArray( new String[] { } );
}
public static String getLanguage() {
if ( !s_lang.Equals( "" ) ) {
return s_lang;
} else {
s_lang = "en";
return s_lang;
}
}
public static void setLanguage( String value ) {
if ( !value.Equals( "" ) ) {
s_lang = value;
} else {
s_lang = "en";
}
}
/// <summary>
/// 現在の実行ディレクトリにある言語設定ファイルを全て読込み、メッセージリストに追加します
/// </summary>
public static void loadMessages() {
loadMessages( PortUtil.getApplicationStartupPath() );
}
/// <summary>
/// 指定されたディレクトリにある言語設定ファイルを全て読込み、メッセージリストに追加します
/// </summary>
/// <param name="directory"></param>
public static void loadMessages( String directory ) {
s_messages.clear();
#if DEBUG
Console.WriteLine( "Messaging+LoadMessages()" );
#endif
String[] files = PortUtil.listFiles( directory, ".po" );
for ( int i = 0; i < files.Length; i++ ){
String fname = PortUtil.combinePath( directory, files[i] );
#if DEBUG
Console.WriteLine( " fname=" + fname );
#endif
appendFromFile( fname );
}
}
public static void appendFromFile( String file ) {
s_messages.add( new MessageBody( PortUtil.getFileNameWithoutExtension( file ), file ) );
}
public static MessageBodyEntry getMessageDetail( String id ) {
if ( s_lang.Equals( "" ) ) {
s_lang = "en";
}
for ( Iterator itr = s_messages.iterator(); itr.hasNext(); ){
MessageBody mb = (MessageBody)itr.next();
if ( mb.lang.Equals( s_lang ) ) {
return mb.getMessageDetail( id );
}
}
return new MessageBodyEntry( id, new String[] { } );
}
public static String getMessage( String id ) {
if ( s_lang.Equals( "" ) ) {
s_lang = "en";
}
for ( Iterator itr = s_messages.iterator(); itr.hasNext(); ){
MessageBody mb = (MessageBody)itr.next();
if ( mb.lang.Equals( s_lang ) ) {
return mb.getMessage( id );
}
}
return id;
}
}
#if !JAVA
}
#endif

391
Boare.Lib.AppUtil/Misc.cs Normal file
View File

@@ -0,0 +1,391 @@
/*
* Misc.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace Boare.Lib.AppUtil {
public static partial class Util {
public static void ApplyContextMenuFontRecurse( ContextMenuStrip item, Font font ) {
item.Font = font;
foreach ( ToolStripItem tsi in item.Items ) {
ApplyToolStripFontRecurse( tsi, font );
}
}
public static void ApplyToolStripFontRecurse( ToolStripItem item, Font font ) {
item.Font = font;
if ( item is ToolStripMenuItem ) {
ToolStripMenuItem tsmi = (ToolStripMenuItem)item;
foreach ( ToolStripItem tsi in tsmi.DropDownItems ) {
ApplyToolStripFontRecurse( tsi, font );
}
} else if ( item is ToolStripDropDownItem ) {
ToolStripDropDownItem tsdd = (ToolStripDropDownItem)item;
foreach ( ToolStripItem tsi in tsdd.DropDownItems ) {
ApplyToolStripFontRecurse( tsi, font );
}
}
}
/// <summary>
/// 指定したフォントを描画するとき、描画指定したy座標と、描かれる文字の中心線のズレを調べます
/// </summary>
/// <param name="font"></param>
/// <returns></returns>
public static int GetStringDrawOffset( Font font ) {
int ret = 0;
string pangram = "cozy lummox gives smart squid who asks for job pen. 01234567890 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS.";
SizeF size = new SizeF();
using ( Bitmap b = new Bitmap( 1, 1 ) ) {
using ( Graphics g = Graphics.FromImage( b ) ) {
size = g.MeasureString( pangram, font );
}
}
if ( size.Height <= 0 ) {
return 0;
}
using ( Bitmap b = new Bitmap( (int)size.Width * 3, (int)size.Height * 3 ) ) {
using ( Graphics g = Graphics.FromImage( b ) ) {
g.Clear( Color.White );
g.DrawString( pangram, font, Brushes.Black, new PointF( (int)size.Width, (int)size.Height ) );
}
using ( BitmapEx b2 = new BitmapEx( b ) ) {
// 上端に最初に現れる色つきピクセルを探す
int firsty = 0;
bool found = false;
for ( int y = 0; y < b2.Height; y++ ) {
for ( int x = 0; x < b2.Width; x++ ) {
Color c = b2.GetPixel( x, y );
if ( c.R != 255 || c.G != 255 || c.B != 255 ) {
found = true;
firsty = y;
break;
}
}
if ( found ) {
break;
}
}
// 下端
int endy = b2.Height - 1;
found = false;
for ( int y = b2.Height - 1; y >= 0; y-- ) {
for ( int x = 0; x < b2.Width; x++ ) {
Color c = b2.GetPixel( x, y );
if ( c.R != 255 || c.G != 255 || c.B != 255 ) {
found = true;
endy = y;
break;
}
}
if ( found ) {
break;
}
}
int center = (firsty + endy) / 2;
ret = center - (int)size.Height;
}
}
return ret;
}
/// <summary>
/// 指定した言語コードの表す言語が、右から左へ記述する言語かどうかを調べます
/// </summary>
/// <param name="language_code"></param>
/// <returns></returns>
public static bool IsRightToLeftLanguage( string language_code ) {
language_code = language_code.ToLower();
switch ( language_code ) {
case "ar":
case "he":
case "iw":
case "fa":
case "ur":
return true;
default:
return false;
}
}
/// <summary>
/// 指定したディレクトリに作成可能な、一時ファイル名を取得します
/// </summary>
/// <param name="directory">ディレクトリ</param>
/// <returns></returns>
public static string GetTempFileNameIn( string directory ) {
for ( uint i = uint.MinValue; i <= uint.MaxValue; i++ ) {
string file = Path.Combine( directory, "temp" + i );
if ( !File.Exists( file ) ) {
return file;
}
}
return "";
}
/// <summary>
/// 指定したディレクトリに作成可能な、一時ファイル名を取得します
/// </summary>
/// <param name="directory">ディレクトリ</param>
/// <param name="extention">拡張子ex. ".txt"</param>
/// <returns></returns>
public static string GetTempFileNameIn( string directory, string extention ){
for ( uint i = uint.MinValue; i <= uint.MaxValue; i++ ) {
string file = Path.Combine( directory, "temp" + i + extention );
if ( !File.Exists( file ) ) {
return file;
}
}
return "";
}
/// <summary>
/// 指定した画像ファイルから新しいBitmapオブジェクトを作成します
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public static Bitmap BitmapFromStream( string file ) {
if ( !File.Exists( file ) ) {
return null;
}
FileStream fs = new FileStream( file, FileMode.Open );
Bitmap ret = new Bitmap( fs );
fs.Close();
return ret;
}
/// <summary>
/// 指定した画像ファイルから新しいImageオブジェクトを作成します
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public static Image ImageFromStream( string file ) {
if ( !File.Exists( file ) ) {
return null;
}
FileStream fs = new FileStream( file, FileMode.Open );
Image ret = Image.FromStream( fs );
fs.Close();
return ret;
}
/// <summary>
/// ImageFormatからデフォルトの拡張子を取得します
/// </summary>
/// <param name="format"></param>
/// <returns></returns>
public static string GetExtensionFromImageFormat( ImageFormat format ) {
switch ( format.ToString().ToLower() ) {
case "bmp":
return ".bmp";
case "emf":
return ".emf";
case "gif":
return ".gif";
case "jpeg":
return ".jpg";
case "png":
return ".png";
case "tiff":
return ".tiff";
case "wmf":
return ".wmf";
default:
return "";
}
}
/// <summary>
/// System.Drawimg.Imaging.ImageFormatで使用可能なフォーマットの一覧を取得します
/// </summary>
/// <returns></returns>
public static ImageFormat[] GetImageFormats() {
#if DEBUG
Console.WriteLine( "GetImageFormats()" );
#endif
PropertyInfo[] properties = typeof( System.Drawing.Imaging.ImageFormat ).GetProperties();
List<ImageFormat> ret = new List<ImageFormat>();
foreach ( PropertyInfo pi in properties ) {
if ( pi.PropertyType.Equals( typeof( System.Drawing.Imaging.ImageFormat ) ) ) {
ImageFormat ifmt = (System.Drawing.Imaging.ImageFormat)pi.GetValue( null, null );
#if DEBUG
Console.WriteLine( ifmt.ToString() );
#endif
ret.Add( ifmt );
}
}
return ret.ToArray();
}
public static void RgbToHsv( int r, int g, int b, out double h, out double s, out double v ) {
RgbToHsv( r / 255.0, g / 255.0, b / 255.0, out h, out s, out v );
}
public static void RgbToHsv( double r, double g, double b, out double h, out double s, out double v ) {
double tmph, imax, imin;
const double sqrt3 = 1.7320508075688772935274463415059;
imax = Math.Max( r, Math.Max( g, b ) );
imin = Math.Min( r, Math.Min( g, b ) );
if ( imax == 0.0 ) {
h = 0;
s = 0;
v = 0;
return;
} else if ( imax == imin ) {
tmph = 0;
} else {
if ( r == imax ) {
tmph = 60.0 * (g - b) / (imax - imin);
} else if ( g == imax ) {
tmph = 60.0 * (b - r) / (imax - imin) + 120.0;
} else {
tmph = 60.0 * (r - g) / (imax - imin) + 240.0;
}
}
while ( tmph < 0.0 ) {
tmph = tmph + 360.0;
}
while ( tmph >= 360.0 ) {
tmph = tmph - 360.0;
}
h = tmph / 360.0;
s = (imax - imin) / imax;
v = imax;
}
public static Color HsvToColor( double h, double s, double v ) {
double dr, dg, db;
HsvToRgb( h, s, v, out dr, out dg, out db );
return Color.FromArgb( (int)(dr * 255), (int)(dg * 255), (int)(db * 255) );
}
public static void HsvToRgb( double h, double s, double v, out byte r, out byte g, out byte b ) {
double dr, dg, db;
HsvToRgb( h, s, v, out dr, out dg, out db );
r = (byte)(dr * 255);
g = (byte)(dg * 255);
b = (byte)(db * 255);
}
public static void HsvToRgb( double h, double s, double v, out double r, out double g, out double b ) {
double f, p, q, t, hh;
int hi;
r = g = b = 0.0;
if ( s == 0 ) {
r = v;
g = v;
b = v;
} else {
hh = h * 360.0;
hi = (int)(hh / 60.0) % 6;
f = hh / 60.0 - (double)(hi);
p = v * (1.0 - s);
q = v * (1.0 - f * s);
t = v * (1.0 - (1.0 - f) * s);
switch ( hi ) {
case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
case 5:
r = v;
g = p;
b = q;
break;
}
}
}
/// <summary>
/// 指定された文字列を指定されたフォントで描画したときのサイズを計測します。
/// </summary>
/// <param name="text"></param>
/// <param name="font"></param>
/// <returns></returns>
public static Size MeasureString( string text, Font font ) {
using ( Bitmap dumy = new Bitmap( 1, 1 ) )
using ( Graphics g = Graphics.FromImage( dumy ) ) {
SizeF tmp = g.MeasureString( text, font );
return new Size( (int)tmp.Width, (int)tmp.Height );
}
}
/// <summary>
/// 指定したコントロールと、その子コントロールのフォントを再帰的に変更します
/// </summary>
/// <param name="c"></param>
/// <param name="font"></param>
public static void ApplyFontRecurse( Control c, Font font ) {
c.Font = font;
for ( int i = 0; i < c.Controls.Count; i++ ) {
ApplyFontRecurse( c.Controls[i], font );
}
}
/// <summary>
///
/// </summary>
/// <param name="start1"></param>
/// <param name="end1"></param>
/// <param name="start2"></param>
/// <param name="end2"></param>
/// <returns></returns>
public static bool IsOverwrapped( double start1, double end1, double start2, double end2 ) {
if ( start2 <= start1 && start1 < end2 ) {
return true;
} else if ( start2 < end1 && end1 < end2 ) {
return true;
} else {
if ( start1 <= start2 && start2 < end1 ) {
return true;
} else if ( start1 < end2 && end2 < end1 ) {
return true;
} else {
return false;
}
}
}
}
}

View File

@@ -0,0 +1,29 @@
/*
* AssemblyInfo.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Cadencii is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle( "Boare.Lib.AppUtil" )]
[assembly: AssemblyDescription( "" )]
[assembly: AssemblyConfiguration( "" )]
[assembly: AssemblyCompany( "Boare" )]
[assembly: AssemblyProduct( "Boare.Lib.AppUtil" )]
[assembly: AssemblyCopyright( "Copyright © 2008-2009" )]
[assembly: AssemblyTrademark( "" )]
[assembly: AssemblyCulture( "" )]
[assembly: ComVisible( false )]
[assembly: Guid( "1d456f8c-100a-4f4b-b53f-d09a32ce6bfc" )]
[assembly: AssemblyVersion( "1.0.0.0" )]
[assembly: AssemblyFileVersion( "1.0.1" )]

516
Boare.Lib.AppUtil/Util.cs Normal file
View File

@@ -0,0 +1,516 @@
/*
* Misc.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
package org.kbinani.apputil;
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
#else
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using bocoree;
namespace Boare.Lib.AppUtil {
using java = bocoree.java;
using boolean = System.Boolean;
#endif
#if JAVA
public class Util{
#else
public static partial class Util {
#endif
#if JAVA
public static void applyContextMenuFontRecurse( MenuElement item, Font font ){
applyToolStripFontRecurse( item, font );
}
#else
public static void applyContextMenuFontRecurse( ContextMenuStrip item, bocoree.java.awt.Font font ) {
item.Font = font.font;
foreach ( ToolStripItem tsi in item.Items ) {
applyToolStripFontRecurse( tsi, font );
}
}
#endif
#if JAVA
public static void applyToolStripFontRecurse( MenuElement item, Font font ){
if( item instanceof Component ){
((Component)item).setFont( font );
}
for( MenuElement element : item.getSubElements() ){
applyToolStripFontRecurse( element, font );
}
}
#else
public static void applyToolStripFontRecurse( ToolStripItem item, bocoree.java.awt.Font font ) {
item.Font = font.font;
if ( item is ToolStripMenuItem ) {
ToolStripMenuItem tsmi = (ToolStripMenuItem)item;
foreach ( ToolStripItem tsi in tsmi.DropDownItems ) {
applyToolStripFontRecurse( tsi, font );
}
} else if ( item is ToolStripDropDownItem ) {
ToolStripDropDownItem tsdd = (ToolStripDropDownItem)item;
foreach ( ToolStripItem tsi in tsdd.DropDownItems ) {
applyToolStripFontRecurse( tsi, font );
}
}
}
#endif
/// <summary>
/// 指定したフォントを描画するとき、描画指定したy座標と、描かれる文字の中心線のズレを調べます
/// </summary>
/// <param name="font"></param>
/// <returns></returns>
public static int getStringDrawOffset( java.awt.Font font ) {
int ret = 0;
String pangram = "cozy lummox gives smart squid who asks for job pen. 01234567890 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS.";
java.awt.Dimension size = measureString( pangram, font );
if ( size.height <= 0 ) {
return 0;
}
java.awt.image.BufferedImage b = null;
java.awt.Graphics2D g = null;
#if JAVA
java.awt.image.BufferedImage b2 = null;
#else
BitmapEx b2 = null;
#endif
try {
int w = size.width * 3;
int h = size.height * 3;
b = new java.awt.image.BufferedImage( w, h, java.awt.image.BufferedImage.TYPE_INT_BGR );
g = b.createGraphics();
g.setColor( java.awt.Color.white );
g.fillRect( 0, 0, w, h );
g.setFont( font );
g.setColor( java.awt.Color.black );
g.drawString( pangram, size.width, size.height );
#if JAVA
Graphics2D g2 = b.createGraphics();
g2.drawImage( b, 0, 0, null );
#else
b2 = new BitmapEx( b.m_image );
#endif
// 上端に最初に現れる色つきピクセルを探す
int firsty = 0;
boolean found = false;
for ( int y = 0; y < h; y++ ) {
for ( int x = 0; x < w; x++ ) {
#if JAVA
int ic = b2.getRGB( x, y );
Color c = new Color( ic );
#else
java.awt.Color c = new bocoree.java.awt.Color( b2.GetPixel( x, y ) );
#endif
if ( c.getRed() != 255 || c.getGreen() != 255 || c.getBlue() != 255 ) {
found = true;
firsty = y;
break;
}
}
if ( found ) {
break;
}
}
// 下端
int endy = h - 1;
found = false;
for ( int y = h - 1; y >= 0; y-- ) {
for ( int x = 0; x < w; x++ ) {
#if JAVA
int ic = b2.getRGB( x, y );
Color c = new Color( ic );
#else
java.awt.Color c = new bocoree.java.awt.Color( b2.GetPixel( x, y ) );
#endif
if ( c.getRed() != 255 || c.getGreen() != 255 || c.getBlue() != 255 ) {
found = true;
endy = y;
break;
}
}
if ( found ) {
break;
}
}
int center = (firsty + endy) / 2;
ret = center - (int)size.height;
} catch ( Exception ex ) {
} finally {
#if JAVA
#else
if ( b != null && b.m_image != null ) {
b.m_image.Dispose();
}
if ( g != null ) {
g.nativeGraphics.Dispose();
}
if ( b2 != null && b2 != null ) {
b2.Dispose();
}
#endif
}
return ret;
}
/// <summary>
/// 指定した言語コードの表す言語が、右から左へ記述する言語かどうかを調べます
/// </summary>
/// <param name="language_code"></param>
/// <returns></returns>
public static boolean isRightToLeftLanguage( String language_code ) {
language_code = language_code.ToLower();
if ( language_code.Equals( "ar" ) ||
language_code.Equals( "he" ) ||
language_code.Equals( "iw" ) ||
language_code.Equals( "fa" ) ||
language_code.Equals( "ur" ) ) {
return true;
} else {
return false;
}
}
#if !JAVA
/// <summary>
/// 指定したディレクトリに作成可能な、一時ファイル名を取得します
/// </summary>
/// <param name="directory">ディレクトリ</param>
/// <returns></returns>
public static string GetTempFileNameIn( string directory ) {
for ( uint i = uint.MinValue; i <= uint.MaxValue; i++ ) {
string file = Path.Combine( directory, "temp" + i );
if ( !File.Exists( file ) ) {
return file;
}
}
return "";
}
#endif
#if !JAVA
/// <summary>
/// 指定したディレクトリに作成可能な、一時ファイル名を取得します
/// </summary>
/// <param name="directory">ディレクトリ</param>
/// <param name="extention">拡張子ex. ".txt"</param>
/// <returns></returns>
public static string GetTempFileNameIn( string directory, string extention ){
for ( uint i = uint.MinValue; i <= uint.MaxValue; i++ ) {
string file = Path.Combine( directory, "temp" + i + extention );
if ( !File.Exists( file ) ) {
return file;
}
}
return "";
}
#endif
#if !JAVA
/// <summary>
/// 指定した画像ファイルから新しいBitmapオブジェクトを作成します
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public static Bitmap BitmapFromStream( string file ) {
if ( !File.Exists( file ) ) {
return null;
}
FileStream fs = new FileStream( file, FileMode.Open );
Bitmap ret = new Bitmap( fs );
fs.Close();
return ret;
}
#endif
#if !JAVA
/// <summary>
/// 指定した画像ファイルから新しいImageオブジェクトを作成します
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public static Image ImageFromStream( string file ) {
if ( !File.Exists( file ) ) {
return null;
}
FileStream fs = new FileStream( file, FileMode.Open );
Image ret = Image.FromStream( fs );
fs.Close();
return ret;
}
#endif
#if !JAVA
/// <summary>
/// ImageFormatからデフォルトの拡張子を取得します
/// </summary>
/// <param name="format"></param>
/// <returns></returns>
public static string GetExtensionFromImageFormat( ImageFormat format ) {
switch ( format.ToString().ToLower() ) {
case "bmp":
return ".bmp";
case "emf":
return ".emf";
case "gif":
return ".gif";
case "jpeg":
return ".jpg";
case "png":
return ".png";
case "tiff":
return ".tiff";
case "wmf":
return ".wmf";
default:
return "";
}
}
#endif
#if !JAVA
/// <summary>
/// System.Drawimg.Imaging.ImageFormatで使用可能なフォーマットの一覧を取得します
/// </summary>
/// <returns></returns>
public static ImageFormat[] GetImageFormats() {
#if DEBUG
Console.WriteLine( "GetImageFormats()" );
#endif
PropertyInfo[] properties = typeof( System.Drawing.Imaging.ImageFormat ).GetProperties();
List<ImageFormat> ret = new List<ImageFormat>();
foreach ( PropertyInfo pi in properties ) {
if ( pi.PropertyType.Equals( typeof( System.Drawing.Imaging.ImageFormat ) ) ) {
ImageFormat ifmt = (System.Drawing.Imaging.ImageFormat)pi.GetValue( null, null );
#if DEBUG
Console.WriteLine( ifmt.ToString() );
#endif
ret.Add( ifmt );
}
}
return ret.ToArray();
}
#endif
#if !JAVA
public static void RgbToHsv( int r, int g, int b, out double h, out double s, out double v ) {
RgbToHsv( r / 255.0, g / 255.0, b / 255.0, out h, out s, out v );
}
public static void RgbToHsv( double r, double g, double b, out double h, out double s, out double v ) {
double tmph, imax, imin;
const double sqrt3 = 1.7320508075688772935274463415059;
imax = Math.Max( r, Math.Max( g, b ) );
imin = Math.Min( r, Math.Min( g, b ) );
if ( imax == 0.0 ) {
h = 0;
s = 0;
v = 0;
return;
} else if ( imax == imin ) {
tmph = 0;
} else {
if ( r == imax ) {
tmph = 60.0 * (g - b) / (imax - imin);
} else if ( g == imax ) {
tmph = 60.0 * (b - r) / (imax - imin) + 120.0;
} else {
tmph = 60.0 * (r - g) / (imax - imin) + 240.0;
}
}
while ( tmph < 0.0 ) {
tmph = tmph + 360.0;
}
while ( tmph >= 360.0 ) {
tmph = tmph - 360.0;
}
h = tmph / 360.0;
s = (imax - imin) / imax;
v = imax;
}
public static Color HsvToColor( double h, double s, double v ) {
double dr, dg, db;
HsvToRgb( h, s, v, out dr, out dg, out db );
return Color.FromArgb( (int)(dr * 255), (int)(dg * 255), (int)(db * 255) );
}
public static void HsvToRgb( double h, double s, double v, out byte r, out byte g, out byte b ) {
double dr, dg, db;
HsvToRgb( h, s, v, out dr, out dg, out db );
r = (byte)(dr * 255);
g = (byte)(dg * 255);
b = (byte)(db * 255);
}
public static void HsvToRgb( double h, double s, double v, out double r, out double g, out double b ) {
double f, p, q, t, hh;
int hi;
r = g = b = 0.0;
if ( s == 0 ) {
r = v;
g = v;
b = v;
} else {
hh = h * 360.0;
hi = (int)(hh / 60.0) % 6;
f = hh / 60.0 - (double)(hi);
p = v * (1.0 - s);
q = v * (1.0 - f * s);
t = v * (1.0 - (1.0 - f) * s);
switch ( hi ) {
case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
case 5:
r = v;
g = p;
b = q;
break;
}
}
}
#endif
/// <summary>
/// 指定された文字列を指定されたフォントで描画したときのサイズを計測します。
/// </summary>
/// <param name="text"></param>
/// <param name="font"></param>
/// <returns></returns>
#if JAVA
public static Dimension measureString( String text, Font font ){
BufferedImage dumy = new BufferedImage( 1, 1, BufferedImage.TYPE_INT_BGR );
Graphics2D g = dumy.createGraphics();
g.setFont( font );
FontMetrics fm = g.getFontMetrics();
Dimension ret = new Dimension( fm.stringWidth( text ), fm.getHeight() );
g = null;
dumy = null;
return ret;
}
#else
public static java.awt.Dimension measureString( string text, java.awt.Font font ) {
Size s = measureString( text, font.font );
return new bocoree.java.awt.Dimension( s.Width, s.Height );
}
public static Size measureString( string text, Font font ) {
using ( Bitmap dumy = new Bitmap( 1, 1 ) )
using ( Graphics g = Graphics.FromImage( dumy ) ) {
SizeF tmp = g.MeasureString( text, font );
return new Size( (int)tmp.Width, (int)tmp.Height );
}
}
#endif
/// <summary>
/// 指定したコントロールと、その子コントロールのフォントを再帰的に変更します
/// </summary>
/// <param name="c"></param>
/// <param name="font"></param>
#if JAVA
public static void applyFontRecurse( Component c, Font font ){
#else
public static void applyFontRecurse( Control c, java.awt.Font font ) {
#endif
#if JAVA
c.setFont( font );
if( c instanceof Container ){
Container container = (Container)c;
int count = container.getComponentCount();
for( int i = 0; i < count; i++ ){
Component component = container.getComponent( i );
applyFontRecurse( component, font );
}
}
#else
applyFontRecurse( c, font.font );
#endif
}
#if !JAVA
public static void applyFontRecurse( Control c, System.Drawing.Font font ) {
c.Font = font;
for ( int i = 0; i < c.Controls.Count; i++ ) {
applyFontRecurse( c.Controls[i], font );
}
}
#endif
#if !JAVA
/// <summary>
///
/// </summary>
/// <param name="start1"></param>
/// <param name="end1"></param>
/// <param name="start2"></param>
/// <param name="end2"></param>
/// <returns></returns>
public static bool IsOverwrapped( double start1, double end1, double start2, double end2 ) {
if ( start2 <= start1 && start1 < end2 ) {
return true;
} else if ( start2 < end1 && end1 < end2 ) {
return true;
} else {
if ( start1 <= start2 && start2 < end1 ) {
return true;
} else if ( start1 < end2 && end2 < end1 ) {
return true;
} else {
return false;
}
}
}
#endif
}
#if !JAVA
}
#endif

136
Boare.Lib.AppUtil/VersionInfo.Designer.cs generated Normal file
View File

@@ -0,0 +1,136 @@
/*
* VersionInfo.Designer.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.Drawing;
namespace Boare.Lib.AppUtil {
partial class VersionInfo {
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
/// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
protected override void Dispose( bool disposing ) {
if( disposing && (components != null) ) {
components.Dispose();
}
base.Dispose( disposing );
}
#region Windows
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.btnFlip = new System.Windows.Forms.Button();
this.btnOK = new System.Windows.Forms.Button();
this.timer = new System.Windows.Forms.Timer( this.components );
this.btnSaveAuthorList = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnFlip
//
this.btnFlip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnFlip.Location = new System.Drawing.Point( 13, 391 );
this.btnFlip.Name = "btnFlip";
this.btnFlip.Size = new System.Drawing.Size( 75, 21 );
this.btnFlip.TabIndex = 2;
this.btnFlip.Text = "クレジット";
this.btnFlip.UseVisualStyleBackColor = true;
this.btnFlip.Click += new System.EventHandler( this.btnFlip_Click );
//
// btnOK
//
this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Location = new System.Drawing.Point( 211, 391 );
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size( 75, 21 );
this.btnOK.TabIndex = 1;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler( this.btnOK_Click );
//
// timer
//
this.timer.Interval = 30;
this.timer.Tick += new System.EventHandler( this.timer_Tick );
//
// btnSaveAuthorList
//
this.btnSaveAuthorList.Location = new System.Drawing.Point( 123, 391 );
this.btnSaveAuthorList.Name = "btnSaveAuthorList";
this.btnSaveAuthorList.Size = new System.Drawing.Size( 43, 21 );
this.btnSaveAuthorList.TabIndex = 3;
this.btnSaveAuthorList.Text = "button1";
this.btnSaveAuthorList.UseVisualStyleBackColor = true;
this.btnSaveAuthorList.Visible = false;
//
// VersionInfoEx
//
this.AcceptButton = this.btnOK;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size( 300, 426 );
this.Controls.Add( this.btnSaveAuthorList );
this.Controls.Add( this.btnOK );
this.Controls.Add( this.btnFlip );
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.KeyPreview = true;
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size( 306, 451 );
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size( 306, 451 );
this.Name = "VersionInfoEx";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "VersionInfoEx";
this.Paint += new System.Windows.Forms.PaintEventHandler( this.VersionInfoEx_Paint );
this.KeyDown += new System.Windows.Forms.KeyEventHandler( this.VersionInfoEx_KeyDown );
this.FontChanged += new System.EventHandler( this.VersionInfoEx_FontChanged );
this.ResumeLayout( false );
}
#endregion
public void ApplyLanguage() {
string about = string.Format( _( "About {0}" ), m_app_name );
string credit = _( "Credit" );
bocoree.java.awt.Dimension size1 = Util.measureString( about, new bocoree.java.awt.Font( btnFlip.Font ) );
bocoree.java.awt.Dimension size2 = Util.measureString( credit, new bocoree.java.awt.Font( btnFlip.Font ) );
m_button_width_about = Math.Max( 75, (int)(size1.width * 1.3) );
m_button_width_credit = Math.Max( 75, (int)(size2.width * 1.3) );
if( m_credit_mode ) {
btnFlip.Width = m_button_width_about;
btnFlip.Text = about;
} else {
btnFlip.Width = m_button_width_credit;
btnFlip.Text = credit;
}
this.Text = about;
}
private System.Windows.Forms.Button btnFlip;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.Button btnSaveAuthorList;
}
}

View File

@@ -0,0 +1,278 @@
#if !JAVA
/*
* VersionInfo.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
//using System.Drawing;
//using System.Drawing.Drawing2D;
//using System.Windows.Forms;
using bocoree;
using bocoree.java.awt;
using bocoree.java.awt.image;
namespace Boare.Lib.AppUtil {
using java = bocoree.java;
using javax = bocoree.javax;
using Graphics = bocoree.java.awt.Graphics2D;
public partial class VersionInfo : System.Windows.Forms.Form {
DateTime m_scroll_started;
private AuthorListEntry[] m_credit;
const float m_speed = 35f;
string m_version;
bool m_credit_mode = false;
float m_last_t = 0f;
float m_last_speed = 0f;
float m_shift = 0f;
int m_button_width_about = 75;
int m_button_width_credit = 75;
BufferedImage m_scroll;
const int m_height = 380;
readonly Color m_background = Color.white;
private string m_app_name = "";
private Color m_app_name_color = Color.black;
private Color m_version_color = new Color( 105, 105, 105 );
private bool m_shadow_enablde = true;
public VersionInfo( string app_name, string version ) {
m_version = version;
m_app_name = app_name;
InitializeComponent();
ApplyLanguage();
this.SetStyle( System.Windows.Forms.ControlStyles.DoubleBuffer, true );
this.SetStyle( System.Windows.Forms.ControlStyles.UserPaint, true );
this.SetStyle( System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true );
m_credit = new AuthorListEntry[] { };
btnSaveAuthorList.Visible = false;
#if DEBUG
GenerateAuthorList();
btnSaveAuthorList.Visible = true;
btnSaveAuthorList.Click += new EventHandler( btnSaveAuthorList_Click );
#endif
}
public bool SaveAuthorListVisible {
set {
btnSaveAuthorList.Visible = value;
}
}
public static string _( string s ) {
return Messaging.getMessage( s );
}
/// <summary>
/// バージョン番号表示の文字色を取得または設定します
/// </summary>
public Color VersionColor {
get {
return m_version_color;
}
set {
m_version_color = value;
}
}
/// <summary>
/// アプリケーション名表示の文字色を取得または設定します
/// </summary>
public Color AppNameColor {
get {
return m_app_name_color;
}
set {
m_app_name_color = value;
}
}
public BufferedImage Credit {
set {
m_scroll = value;
}
}
public string AppName {
get {
return m_app_name;
}
set {
m_app_name = value;
}
}
public AuthorListEntry[] AuthorList {
set {
m_credit = value;
GenerateAuthorList();
}
}
private void GenerateAuthorList() {
const float shadow_shift = 2f;
const string font_name = "Arial";
const int font_size = 10;
Font font = new Font( font_name, java.awt.Font.PLAIN, font_size );
Dimension size = Boare.Lib.AppUtil.Util.measureString( "Qjqp", font );
float width = this.Width;
float height = size.height;
System.Drawing.StringFormat sf = new System.Drawing.StringFormat();
m_scroll = new BufferedImage( (int)width, (int)(40f + m_credit.Length * height * 1.1f), BufferedImage.TYPE_INT_BGR );
Graphics2D g = m_scroll.createGraphics();
g.setColor( Color.white );
g.fillRect( 0, 0, m_scroll.getWidth(), m_scroll.getHeight() );
sf.Alignment = System.Drawing.StringAlignment.Center;
Font f = new Font( font_name, java.awt.Font.BOLD, (int)(font_size * 1.1f) );
g.setFont( f );
if ( m_shadow_enablde ) {
g.setColor( new Color( 0, 0, 0, 40 ) );
g.nativeGraphics.DrawString(
m_app_name,
f.font,
g.brush,
new System.Drawing.RectangleF( shadow_shift, shadow_shift, width, height ),
sf );
}
g.setColor( Color.black );
g.nativeGraphics.DrawString(
m_app_name,
f.font,
g.brush,
new System.Drawing.RectangleF( 0f, 0f, width, height ),
sf );
for ( int i = 0; i < m_credit.Length; i++ ) {
Font f2 = new Font( font_name, m_credit[i].getStyle(), font_size );
g.setFont( f2 );
if ( m_shadow_enablde ) {
g.setColor( new Color( 0, 0, 0, 40 ) );
g.nativeGraphics.DrawString(
m_credit[i].getName(),
f2.font,
g.brush,
new System.Drawing.RectangleF( 0f + shadow_shift, 40f + i * height * 1.1f + shadow_shift, width, height ),
sf );
}
g.setColor( Color.black );
g.nativeGraphics.DrawString(
m_credit[i].getName(),
f2.font,
g.brush,
new System.Drawing.RectangleF( 0f, 40f + i * height * 1.1f, width, height ),
sf );
}
}
void btnSaveAuthorList_Click( object sender, EventArgs e ) {
#if DEBUG
using ( System.Windows.Forms.SaveFileDialog dlg = new System.Windows.Forms.SaveFileDialog() ){
if( dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK ){
javax.imageio.ImageIO.write( m_scroll, "png", new java.io.File( dlg.FileName ) );
}
}
#endif
}
private void btnOK_Click( object sender, EventArgs e ) {
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
private void btnFlip_Click( object sender, EventArgs e ) {
m_credit_mode = !m_credit_mode;
if ( m_credit_mode ) {
btnFlip.Width = m_button_width_about;
btnFlip.Text = string.Format( _( "About {0}" ), m_app_name );
m_scroll_started = DateTime.Now;
m_last_speed = 0f;
m_last_t = 0f;
m_shift = 0f;
timer.Enabled = true;
} else {
timer.Enabled = false;
btnFlip.Width = m_button_width_credit;
btnFlip.Text = _( "Credit" );
}
this.Invalidate();
}
private void timer_Tick( object sender, EventArgs e ) {
this.Invalidate();
}
private void VersionInfoEx_Paint( object sender, System.Windows.Forms.PaintEventArgs e ) {
try {
paint( new Graphics2D( e.Graphics ) );
} catch ( Exception ex ) {
#if DEBUG
Console.WriteLine( "VersionInfoEx_Paint" );
Console.WriteLine( ex.StackTrace );
#endif
}
}
public void paint( Graphics g1 ) {
Graphics2D g = (Graphics2D)g1;
g.clipRect( 0, 0, this.Width, m_height );
g.clearRect( 0, 0, this.Width, this.Height );
if ( m_credit_mode ) {
float times = (float)(((DateTime.Now).Subtract( m_scroll_started )).TotalSeconds) - 3f;
float speed = (float)((2.0 - bocoree.math.erfcc( times * 0.8 )) / 2.0) * m_speed;
float dt = times - m_last_t;
m_shift += (speed + m_last_speed) * dt / 2f;
m_last_t = times;
m_last_speed = speed;
float dx = (this.Width - m_scroll.getWidth( null )) * 0.5f;
if ( m_scroll != null ) {
g.drawImage( m_scroll, (int)dx, (int)(90f - m_shift), null );
if ( 90f - m_shift + m_scroll.getHeight( null ) < 0 ) {
m_shift = -m_height * 1.5f;
}
}
int grad_height = 60;
Rectangle top = new Rectangle( 0, 0, this.Width, grad_height );
/*using ( LinearGradientBrush lgb = new LinearGradientBrush( top, Color.White, Color.Transparent, LinearGradientMode.Vertical ) ) {
g.FillRectangle( lgb, top );
}*/
Rectangle bottom = new Rectangle( 0, m_height - grad_height, this.Width, grad_height );
g.clipRect( 0, m_height - grad_height + 1, this.Width, grad_height - 1 );
/*using ( LinearGradientBrush lgb = new LinearGradientBrush( bottom, Color.Transparent, Color.White, LinearGradientMode.Vertical ) ) {
g.FillRectangle( lgb, bottom );
}*/
g.setClip( null );
} else {
g.setFont( new Font( "Century Gorhic", java.awt.Font.BOLD, 24 ) );
g.setColor( m_app_name_color );
g.drawString( m_app_name, 20, 110 );
g.setFont( new Font( "Arial", 0, 10 ) );
g.drawString( "version " + m_version, 25, 150 );
}
}
private void VersionInfoEx_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e ) {
if ( (e.KeyCode & System.Windows.Forms.Keys.Escape) == System.Windows.Forms.Keys.Escape ) {
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.Close();
}
}
private void VersionInfoEx_FontChanged( object sender, EventArgs e ) {
for ( int i = 0; i < this.Controls.Count; i++ ) {
Util.applyFontRecurse( this.Controls[i], new java.awt.Font( this.Font ) );
}
}
}
}
#endif

View File

@@ -0,0 +1,202 @@
/*
* XmlSerializeWithDescription.cs
* Copyright (c) 2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Reflection;
using System.IO;
namespace Boare.Lib.AppUtil {
/// <summary>
/// フィールド、またはプロパティの概要を格納するattribute
/// </summary>
[AttributeUsage( AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false )]
public class XmlItemDescription : Attribute {
private string m_value = "";
private string m_attribute_name = "description";
public XmlItemDescription( string Value ) {
m_value = Value;
}
public XmlItemDescription( string AttributeName, string Value ) {
m_value = Value;
m_attribute_name = AttributeName;
}
public string AttributeName {
get {
return m_attribute_name;
}
}
public string Value {
get {
return m_value;
}
}
}
/// <summary>
/// フィールドおよびプロパティを、XmlItemDescription属性の文字列を付加しながらXmlシリアライズする
/// </summary>
public class XmlSerializeWithDescription {
private XmlTextWriter m_writer;
private Type m_type;
public XmlSerializeWithDescription() {
}
public void Serialize( Stream stream, object obj ) {
m_writer = new XmlTextWriter( stream, null );
m_writer.Formatting = Formatting.Indented;
m_writer.Indentation = 4;
m_writer.IndentChar = ' ';
m_writer.WriteStartDocument();
m_writer.WriteStartElement( obj.GetType().Name );
PrintItemRecurse( obj );
m_writer.WriteEndElement();
m_writer.WriteEndDocument();
m_writer.Flush();
}
private void PrintItemRecurse( object obj ) {
Type t = obj.GetType();
if ( !TryWriteValueType( obj ) ){
if ( t.IsGenericType ) {
List<int> f = new List<int>();
Type list_type = f.GetType().GetGenericTypeDefinition();
if ( t.GetGenericTypeDefinition().Equals( list_type ) ) {
Type[] gen = t.GetGenericArguments();
if ( gen.Length == 1 ) {
PropertyInfo count_property = t.GetProperty( "Count", typeof( int ) );
int count = (int)count_property.GetValue( obj, new object[] { } );
Type returntype = gen[0];
MethodInfo indexer = t.GetMethod( "get_Item", new Type[] { typeof( int ) } );
string name = "";
if ( returntype.Equals( typeof( Boolean ) ) ) {
name = "boolean";
} else if ( returntype.Equals( typeof( DateTime ) ) ) {
name = "dateTime";
} else if ( returntype.Equals( typeof( Decimal ) ) ) {
name = "decimal";
} else if ( returntype.Equals( typeof( Double ) ) ) {
name = "double";
} else if ( returntype.Equals( typeof( Int32 ) ) ) {
name = "int";
} else if ( returntype.Equals( typeof( Int64 ) ) ) {
name = "long";
} else if ( returntype.Equals( typeof( Single ) ) ) {
name = "float";
} else if ( returntype.Equals( typeof( String ) ) ) {
name = "string";
} else if ( returntype.IsEnum ) {
name = returntype.Name;
}
if ( indexer != null && name != "" ) {
for ( int i = 0; i < count; i++ ) {
object value = indexer.Invoke( obj, new object[] { i } );
m_writer.WriteStartElement( name );
TryWriteValueType( value );
m_writer.WriteEndElement();
}
}
}
}
} else {
foreach ( FieldInfo fi in t.GetFields() ) {
if ( fi.IsPrivate || fi.IsStatic ) {
continue;
}
object[] attr = fi.GetCustomAttributes( typeof( XmlItemDescription ), false );
XmlItemDescription xid = null;
if ( attr.Length > 0 ) {
xid = (XmlItemDescription)attr[0];
}
WriteContents( fi.Name, fi.GetValue( obj ), xid );
}
foreach ( PropertyInfo pi in t.GetProperties() ) {
if ( !pi.CanRead | !pi.CanWrite ) {
continue;
}
if ( !pi.GetSetMethod().IsPublic | !pi.GetGetMethod().IsPublic ) {
continue;
}
if ( pi.GetSetMethod().IsStatic | pi.GetGetMethod().IsStatic ) {
continue;
}
object[] attr = pi.GetCustomAttributes( typeof( XmlItemDescription ), false );
XmlItemDescription xid = null;
if ( attr.Length > 0 ) {
xid = (XmlItemDescription)attr[0];
}
WriteContents( pi.Name, pi.GetValue( obj, new object[] { } ), xid );
}
}
}
}
private bool TryWriteValueType( object obj ) {
Type t = obj.GetType();
if ( t.Equals( typeof( Boolean ) ) ) {
m_writer.WriteValue( (Boolean)obj );
return true;
} else if ( t.Equals( typeof( DateTime ) ) ) {
m_writer.WriteValue( (DateTime)obj );
return true;
} else if ( t.Equals( typeof( Decimal ) ) ) {
m_writer.WriteValue( (Decimal)obj );
return true;
} else if ( t.Equals( typeof( Double ) ) ) {
m_writer.WriteValue( (Double)obj );
return true;
} else if ( t.Equals( typeof( Int32 ) ) ) {
m_writer.WriteValue( (Int32)obj );
return true;
} else if ( t.Equals( typeof( Int64 ) ) ) {
m_writer.WriteValue( (Int64)obj );
return true;
} else if ( t.Equals( typeof( Single ) ) ) {
m_writer.WriteValue( (Single)obj );
return true;
} else if ( t.Equals( typeof( String ) ) ) {
m_writer.WriteString( (String)obj );
return true;
} else if ( t.IsEnum ) {
string val = Enum.GetName( t, obj );
m_writer.WriteString( val );
return true;
} else {
return false;
}
}
private void WriteContents( string name, object next_obj, XmlItemDescription xid ) {
m_writer.WriteStartElement( name );
if ( xid != null ) {
m_writer.WriteAttributeString( xid.AttributeName, xid.Value );
}
PrintItemRecurse( next_obj );
m_writer.WriteEndElement();
}
private void test() {
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer( typeof( int ) );
}
}
}

View File

@@ -0,0 +1,209 @@
/*
* XmlStaticMemberSerializer.cs
* Copyright (c) 2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml.Serialization;
using Microsoft.CSharp;
namespace Boare.Lib.AppUtil {
/// <summary>
/// クラスのstaticメンバーのxmlシリアライズ/デシリアライズを行うclass
/// </summary>
public class XmlStaticMemberSerializer {
/// <summary>
/// ターゲットとなるクラスから,シリアライズするメンバーを抽出する時に使用
/// </summary>
private class MemberEntry {
/// <summary>
/// プロパティ/フィールドの名前
/// </summary>
public string Name;
/// <summary>
/// プロパティ/フィールドの型
/// </summary>
public Type Type;
/// <summary>
/// プロパティ/フィールドのデフォルト値
/// </summary>
public object Default;
public MemberEntry( string name, Type type, object default_ ) {
Name = name;
Type = type;
Default = default_;
}
}
/// <summary>
/// シリアライズする対象の型staticメンバーだけなのでインスタンスではなく型を保持
/// </summary>
private Type m_item;
/// <summary>
/// シリアライズ/デシリアライズするための内部型
/// </summary>
private Type m_config_type = null;
/// <summary>
/// m_config_typeで初期化されたシリアライザ
/// </summary>
private XmlSerializer m_xs = null;
private XmlStaticMemberSerializer() {
}
/// <summary>
/// 指定された型をシリアライズするための初期化を行います
/// </summary>
/// <param name="item"></param>
public XmlStaticMemberSerializer( Type item ) {
m_item = item;
}
/// <summary>
/// シリアライズを行い,ストリームに書き込みます
/// </summary>
/// <param name="stream"></param>
public void Serialize( Stream stream ) {
if ( m_config_type == null ) {
GenerateConfigType();
}
ConstructorInfo ci = m_config_type.GetConstructor( new Type[]{} );
object config = ci.Invoke( new object[]{} );
foreach ( FieldInfo target in m_config_type.GetFields() ) {
foreach ( PropertyInfo pi in m_item.GetProperties( BindingFlags.Public | BindingFlags.Static ) ) {
if ( target.Name == pi.Name && target.FieldType.Equals( pi.PropertyType ) && pi.CanRead && pi.CanWrite ) {
target.SetValue( config, pi.GetValue( m_item, new object[] { } ) );
break;
}
}
foreach ( FieldInfo fi in m_item.GetFields( BindingFlags.Public | BindingFlags.Static ) ) {
if ( target.Name == fi.Name && target.FieldType.Equals( fi.FieldType ) ) {
target.SetValue( config, fi.GetValue( m_item ) );
break;
}
}
}
m_xs.Serialize( stream, config );
}
/// <summary>
/// 指定したストリームを使って,デシリアライズを行います
/// </summary>
/// <param name="stream"></param>
public void Deserialize( Stream stream ) {
if ( m_config_type == null ) {
GenerateConfigType();
}
object config = m_xs.Deserialize( stream );
if ( config == null ) {
throw new ApplicationException( "failed serializing internal config object" );
}
foreach ( FieldInfo target in m_config_type.GetFields() ) {
foreach ( PropertyInfo pi in m_item.GetProperties( BindingFlags.Public | BindingFlags.Static ) ) {
if ( target.Name == pi.Name && target.FieldType.Equals( pi.PropertyType ) && pi.CanRead && pi.CanWrite ) {
pi.SetValue( m_item, target.GetValue( config ), new object[] { } );
break;
}
}
foreach ( FieldInfo fi in m_item.GetFields( BindingFlags.Public | BindingFlags.Static ) ) {
if ( target.Name == fi.Name && target.FieldType.Equals( fi.FieldType ) ) {
fi.SetValue( m_item, target.GetValue( config ) );
break;
}
}
}
}
/// <summary>
/// シリアライズ用の内部型をコンパイルしm_xsが使用できるようにします
/// </summary>
private void GenerateConfigType() {
List<MemberEntry> config_names = CollectScriptConfigEntries( m_item );
string code = GenerateClassCodeForXmlSerialization( config_names, m_item );
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters parameters = new CompilerParameters();
parameters.ReferencedAssemblies.Add( "System.Windows.Forms.dll" );
parameters.ReferencedAssemblies.Add( "System.dll" );
parameters.ReferencedAssemblies.Add( "System.Drawing.dll" );
parameters.ReferencedAssemblies.Add( "System.Xml.dll" );
parameters.GenerateInMemory = true;
parameters.GenerateExecutable = false;
parameters.IncludeDebugInformation = true;
CompilerResults results = provider.CompileAssemblyFromSource( parameters, code );
Assembly asm = results.CompiledAssembly;
if ( asm.GetTypes().Length <= 0 ) {
m_config_type = null;
m_xs = null;
throw new ApplicationException( "failed generating internal xml serizlizer" );
} else {
m_config_type = (asm.GetTypes())[0];
m_xs = new XmlSerializer( m_config_type );
}
}
/// <summary>
/// 設定ファイルから読込むための型情報を蒐集
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
private static List<MemberEntry> CollectScriptConfigEntries( Type item ) {
List<MemberEntry> config_names = new List<MemberEntry>();
foreach ( PropertyInfo pi in item.GetProperties( BindingFlags.Static | BindingFlags.Public ) ) {
object[] attrs = pi.GetCustomAttributes( true );
foreach ( object obj in attrs ) {
if ( obj.GetType().Equals( typeof( System.Xml.Serialization.XmlIgnoreAttribute ) ) ) {
continue;
}
}
if ( pi.CanRead && pi.CanWrite ) {
config_names.Add( new MemberEntry( pi.Name, pi.PropertyType, pi.GetValue( item, new object[] { } ) ) );
}
}
foreach ( FieldInfo fi in item.GetFields( BindingFlags.Static | BindingFlags.Public ) ) {
object[] attrs = fi.GetCustomAttributes( true );
foreach ( object obj in attrs ) {
if ( obj.GetType().Equals( typeof( System.Xml.Serialization.XmlIgnoreAttribute ) ) ) {
continue;
}
}
config_names.Add( new MemberEntry( fi.Name, fi.FieldType, fi.GetValue( item ) ) );
}
return config_names;
}
/// <summary>
/// 指定した型から、Reflectionを使ってxmlシリアライズ用のクラスをコンパイルするためのC#コードを作成します
/// </summary>
/// <param name="implemented"></param>
/// <returns></returns>
private static string GenerateClassCodeForXmlSerialization( List<MemberEntry> config_names, Type item ) {
// XmlSerialization用の型を作成
string code = "";
code += "using System;\n";
code += "namespace Boare.Lib.AppUtil{\n";
code += " public class StaticMembersOf" + item.Name + "{\n";
foreach ( MemberEntry entry in config_names ) {
code += " public " + entry.Type.ToString() + " " + entry.Name + ";\n";
}
code += " }\n";
code += "}\n";
return code;
}
}
}

View File

@@ -0,0 +1,11 @@
OPT=
CP=cp
RM=rm
Boare.Lib.AppUtil.dll: *.cs bocoree.dll
gmcs $(OPT) -recurse:*.cs -unsafe+ -target:library -out:Boare.Lib.AppUtil.dll \
-r:bocoree.dll,System.Drawing,System.Windows.Forms
clean:
$(RM) Boare.Lib.AppUtil.dll
$(RM) bocoree.dll