1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
|
/*
* FormCurvePointEdit.cs
* Copyright © 2008-2011 kbinani
*
* This file is part of org.kbinani.cadencii.
*
* org.kbinani.cadencii is free software; you can redistribute it and/or
* modify it under the terms of the GPLv3 License.
*
* org.kbinani.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.
*/
#if JAVA
package org.kbinani.cadencii;
//INCLUDE-SECTION IMPORT ../BuildJavaUI/src/org/kbinani/cadencii/FormCurvePointEdit.java
import java.util.*;
import java.awt.event.*;
import org.kbinani.*;
import org.kbinani.apputil.*;
import org.kbinani.vsq.*;
import org.kbinani.windows.forms.*;
#else
using System;
using org.kbinani.apputil;
using org.kbinani.vsq;
using org.kbinani;
using org.kbinani.windows.forms;
using org.kbinani.java.util;
namespace org.kbinani.cadencii
{
using BEventArgs = System.EventArgs;
using BKeyEventArgs = System.Windows.Forms.KeyEventArgs;
using boolean = System.Boolean;
using BEventHandler = System.EventHandler;
using BKeyEventHandler = System.Windows.Forms.KeyEventHandler;
#endif
#if JAVA
public class FormCurvePointEdit extends BDialog {
#else
public class FormCurvePointEdit : BDialog
{
#endif
private long m_editing_id = -1;
private CurveType m_curve;
private boolean m_changed = false;
private FormMain mMainWindow = null;
public FormCurvePointEdit( FormMain main_window, long editing_id, CurveType curve )
{
#if JAVA
super();
initialize();
#else
InitializeComponent();
#endif
mMainWindow = main_window;
registerEventHandlers();
setResources();
applyLanguage();
m_editing_id = editing_id;
m_curve = curve;
VsqBPPairSearchContext context = AppManager.getVsqFile().Track.get( AppManager.getSelected() ).getCurve( m_curve.getName() ).findElement( m_editing_id );
txtDataPointClock.setText( context.clock + "" );
txtDataPointValue.setText( context.point.value + "" );
txtDataPointValue.selectAll();
btnUndo.setEnabled( AppManager.editHistory.hasUndoHistory() );
btnRedo.setEnabled( AppManager.editHistory.hasRedoHistory() );
}
#region public methods
public void applyLanguage()
{
setTitle( _( "Edit Value" ) );
lblDataPointClock.setText( _( "Clock" ) );
lblDataPointValue.setText( _( "Value" ) );
btnApply.setText( _( "Apply" ) );
btnExit.setText( _( "Exit" ) );
}
#endregion
#region helper methods
private String _( String id )
{
return Messaging.getMessage( id );
}
private void applyValue( boolean mode_clock )
{
if ( !m_changed ) {
return;
}
int value = m_curve.getDefault();
try {
value = str.toi( txtDataPointValue.getText() );
} catch ( Exception ex ) {
Logger.write( typeof( FormCurvePointEdit ) + ".applyValue; ex=" + ex + "\n" );
return;
}
if ( value < m_curve.getMinimum() ) {
value = m_curve.getMinimum();
} else if ( m_curve.getMaximum() < value ) {
value = m_curve.getMaximum();
}
int clock = 0;
try {
clock = str.toi( txtDataPointClock.getText() );
} catch ( Exception ex ) {
Logger.write( typeof( FormCurvePointEdit ) + ".applyValue; ex=" + ex + "\n" );
return;
}
int selected = AppManager.getSelected();
VsqTrack vsq_track = AppManager.getVsqFile().Track.get( selected );
VsqBPList src = vsq_track.getCurve( m_curve.getName() );
VsqBPList list = (VsqBPList)src.clone();
VsqBPPairSearchContext context = list.findElement( m_editing_id );
list.move( context.clock, clock, value );
CadenciiCommand run = new CadenciiCommand( VsqCommand.generateCommandTrackCurveReplace( selected,
m_curve.getName(),
list ) );
EditedZone zone = new EditedZone();
Utility.compareList( zone, new VsqBPListComparisonContext( list, src ) );
Vector<EditedZoneUnit> zoneUnits = new Vector<EditedZoneUnit>();
for ( Iterator<EditedZoneUnit> itr = zone.iterator(); itr.hasNext(); ) {
zoneUnits.add( itr.next() );
}
AppManager.editHistory.register( AppManager.getVsqFile().executeCommand( run ) );
txtDataPointClock.setText( clock + "" );
txtDataPointValue.setText( value + "" );
if ( mMainWindow != null ) {
mMainWindow.setEdited( true );
mMainWindow.ensureVisible( clock );
mMainWindow.refreshScreen();
}
if ( mode_clock ) {
txtDataPointClock.selectAll();
} else {
txtDataPointValue.selectAll();
}
btnUndo.setEnabled( AppManager.editHistory.hasUndoHistory() );
btnRedo.setEnabled( AppManager.editHistory.hasRedoHistory() );
m_changed = false;
}
private void setResources()
{
}
private void registerEventHandlers()
{
btnForward.Click += new BEventHandler( commonButton_Click );
btnBackward.Click += new BEventHandler( commonButton_Click );
btnBackward2.Click += new BEventHandler( commonButton_Click );
btnForward2.Click += new BEventHandler( commonButton_Click );
btnApply.Click += new BEventHandler( btnApply_Click );
txtDataPointClock.TextChanged += new BEventHandler( commonTextBox_TextChanged );
txtDataPointClock.KeyUp += new BKeyEventHandler( commonTextBox_KeyUp );
txtDataPointValue.TextChanged += new BEventHandler( commonTextBox_TextChanged );
txtDataPointValue.KeyUp += new BKeyEventHandler( commonTextBox_KeyUp );
btnBackward3.Click += new BEventHandler( commonButton_Click );
btnForward3.Click += new BEventHandler( commonButton_Click );
btnUndo.Click += new BEventHandler( handleUndoRedo_Click );
btnRedo.Click += new BEventHandler( handleUndoRedo_Click );
btnExit.Click += new BEventHandler( btnExit_Click );
}
#endregion
#region event handlers
public void commonTextBox_KeyUp( Object sender, BKeyEventArgs e )
{
#if JAVA
if ( (e.KeyValue & KeyEvent.VK_ENTER) != KeyEvent.VK_ENTER ) {
#else
if ( (e.KeyCode & System.Windows.Forms.Keys.Enter) != System.Windows.Forms.Keys.Enter ) {
#endif
return;
}
applyValue( (sender == txtDataPointClock) );
}
public void commonButton_Click( Object sender, BEventArgs e )
{
VsqBPList list = AppManager.getVsqFile().Track.get( AppManager.getSelected() ).getCurve( m_curve.getName() );
VsqBPPairSearchContext search = list.findElement( m_editing_id );
int index = search.index;
if ( sender == btnForward ) {
index++;
} else if ( sender == btnBackward ) {
index--;
} else if ( sender == btnBackward2 ) {
index -= 5;
} else if ( sender == btnForward2 ) {
index += 5;
} else if ( sender == btnForward3 ) {
index += 10;
} else if ( sender == btnBackward3 ) {
index -= 10;
}
if ( index < 0 ) {
index = 0;
}
if ( list.size() <= index ) {
index = list.size() - 1;
}
VsqBPPair bp = list.getElementB( index );
m_editing_id = bp.id;
int clock = list.getKeyClock( index );
#if JAVA
txtDataPointClock.textChangedEvent.remove( new BEventHandler( this, "commonTextBox_TextChanged" ) );
txtDataPointValue.textChangedEvent.remove( new BEventHandler( this, "commonTextBox_TextChanged" ) );
#else
txtDataPointClock.TextChanged -= commonTextBox_TextChanged;
txtDataPointValue.TextChanged -= commonTextBox_TextChanged;
#endif
txtDataPointClock.setText( clock + "" );
txtDataPointValue.setText( bp.value + "" );
#if JAVA
txtDataPointClock.textChangedEvent.add( new BEventHandler( this, "commonTextBox_TextChanged" ) );
txtDataPointValue.textChangedEvent.add( new BEventHandler( this, "commonTextBox_TextChanged" ) );
#else
txtDataPointClock.TextChanged += commonTextBox_TextChanged;
txtDataPointValue.TextChanged += commonTextBox_TextChanged;
#endif
txtDataPointValue.requestFocus();
txtDataPointValue.selectAll();
AppManager.itemSelection.clearPoint();
AppManager.itemSelection.addPoint( m_curve, bp.id );
if ( mMainWindow != null ) {
mMainWindow.ensureVisible( clock );
mMainWindow.refreshScreen();
}
}
public void btnApply_Click( Object sender, BEventArgs e )
{
applyValue( true );
}
public void commonTextBox_TextChanged( Object sender, BEventArgs e )
{
m_changed = true;
}
public void handleUndoRedo_Click( Object sender, BEventArgs e )
{
if ( sender == btnUndo ) {
AppManager.undo();
} else if ( sender == btnRedo ) {
AppManager.redo();
} else {
return;
}
VsqFileEx vsq = AppManager.getVsqFile();
boolean exists = false;
if ( vsq != null ) {
exists = vsq.Track.get( AppManager.getSelected() ).getCurve( m_curve.getName() ).findElement( m_editing_id ).index >= 0;
}
#if DEBUG
sout.println( "FormCurvePointEdit#handleUndoRedo_Click; exists=" + exists );
#endif
txtDataPointClock.setEnabled( exists );
txtDataPointValue.setEnabled( exists );
btnApply.setEnabled( exists );
btnBackward.setEnabled( exists );
btnBackward2.setEnabled( exists );
btnBackward3.setEnabled( exists );
btnForward.setEnabled( exists );
btnForward2.setEnabled( exists );
btnForward3.setEnabled( exists );
if ( exists ) {
AppManager.itemSelection.clearPoint();
AppManager.itemSelection.addPoint( m_curve, m_editing_id );
}
if ( mMainWindow != null ) {
mMainWindow.updateDrawObjectList();
mMainWindow.refreshScreen();
}
btnUndo.setEnabled( AppManager.editHistory.hasUndoHistory() );
btnRedo.setEnabled( AppManager.editHistory.hasRedoHistory() );
}
public void btnExit_Click( Object sender, BEventArgs e )
{
setDialogResult( BDialogResult.CANCEL );
}
#endregion
#region UI implementation
#if JAVA
//INCLUDE-SECTION FIELD ../BuildJavaUI/src/org/kbinani/cadencii/FormCurvePointEdit.java
//INCLUDE-SECTION METHOD ../BuildJavaUI/src/org/kbinani/cadencii/FormCurvePointEdit.java
#else
/// <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 );
}
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.btnForward = new org.kbinani.windows.forms.BButton();
this.btnBackward = new org.kbinani.windows.forms.BButton();
this.lblDataPointValue = new org.kbinani.windows.forms.BLabel();
this.lblDataPointClock = new org.kbinani.windows.forms.BLabel();
this.btnExit = new org.kbinani.windows.forms.BButton();
this.btnBackward2 = new org.kbinani.windows.forms.BButton();
this.btnForward2 = new org.kbinani.windows.forms.BButton();
this.btnApply = new org.kbinani.windows.forms.BButton();
this.txtDataPointClock = new org.kbinani.cadencii.NumberTextBox();
this.txtDataPointValue = new org.kbinani.cadencii.NumberTextBox();
this.btnBackward3 = new org.kbinani.windows.forms.BButton();
this.btnForward3 = new org.kbinani.windows.forms.BButton();
this.btnUndo = new org.kbinani.windows.forms.BButton();
this.btnRedo = new org.kbinani.windows.forms.BButton();
this.SuspendLayout();
//
// btnForward
//
this.btnForward.Location = new System.Drawing.Point( 120, 12 );
this.btnForward.Name = "btnForward";
this.btnForward.Size = new System.Drawing.Size( 35, 30 );
this.btnForward.TabIndex = 6;
this.btnForward.Text = ">";
this.btnForward.UseVisualStyleBackColor = true;
//
// btnBackward
//
this.btnBackward.Location = new System.Drawing.Point( 84, 12 );
this.btnBackward.Name = "btnBackward";
this.btnBackward.Size = new System.Drawing.Size( 35, 30 );
this.btnBackward.TabIndex = 5;
this.btnBackward.Text = "<";
this.btnBackward.UseVisualStyleBackColor = true;
//
// lblDataPointValue
//
this.lblDataPointValue.AutoSize = true;
this.lblDataPointValue.Location = new System.Drawing.Point( 49, 55 );
this.lblDataPointValue.Name = "lblDataPointValue";
this.lblDataPointValue.Size = new System.Drawing.Size( 34, 12 );
this.lblDataPointValue.TabIndex = 16;
this.lblDataPointValue.Text = "Value";
//
// lblDataPointClock
//
this.lblDataPointClock.AutoSize = true;
this.lblDataPointClock.Location = new System.Drawing.Point( 49, 80 );
this.lblDataPointClock.Name = "lblDataPointClock";
this.lblDataPointClock.Size = new System.Drawing.Size( 34, 12 );
this.lblDataPointClock.TabIndex = 15;
this.lblDataPointClock.Text = "Clock";
//
// btnExit
//
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnExit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnExit.Location = new System.Drawing.Point( 152, 109 );
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size( 75, 23 );
this.btnExit.TabIndex = 3;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
//
// btnBackward2
//
this.btnBackward2.Location = new System.Drawing.Point( 48, 12 );
this.btnBackward2.Name = "btnBackward2";
this.btnBackward2.Size = new System.Drawing.Size( 35, 30 );
this.btnBackward2.TabIndex = 4;
this.btnBackward2.Text = "<5";
this.btnBackward2.UseVisualStyleBackColor = true;
//
// btnForward2
//
this.btnForward2.Location = new System.Drawing.Point( 156, 12 );
this.btnForward2.Name = "btnForward2";
this.btnForward2.Size = new System.Drawing.Size( 35, 30 );
this.btnForward2.TabIndex = 7;
this.btnForward2.Text = "5>";
this.btnForward2.UseVisualStyleBackColor = true;
//
// btnApply
//
this.btnApply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnApply.Location = new System.Drawing.Point( 71, 109 );
this.btnApply.Name = "btnApply";
this.btnApply.Size = new System.Drawing.Size( 75, 23 );
this.btnApply.TabIndex = 17;
this.btnApply.Text = "Apply";
this.btnApply.UseVisualStyleBackColor = true;
//
// txtDataPointClock
//
this.txtDataPointClock.Location = new System.Drawing.Point( 89, 77 );
this.txtDataPointClock.Name = "txtDataPointClock";
this.txtDataPointClock.Size = new System.Drawing.Size( 71, 19 );
this.txtDataPointClock.TabIndex = 2;
this.txtDataPointClock.Type = org.kbinani.cadencii.NumberTextBox.ValueType.Integer;
//
// txtDataPointValue
//
this.txtDataPointValue.Location = new System.Drawing.Point( 89, 52 );
this.txtDataPointValue.Name = "txtDataPointValue";
this.txtDataPointValue.Size = new System.Drawing.Size( 71, 19 );
this.txtDataPointValue.TabIndex = 1;
this.txtDataPointValue.Type = org.kbinani.cadencii.NumberTextBox.ValueType.Integer;
//
// btnBackward3
//
this.btnBackward3.Location = new System.Drawing.Point( 12, 12 );
this.btnBackward3.Name = "btnBackward3";
this.btnBackward3.Size = new System.Drawing.Size( 35, 30 );
this.btnBackward3.TabIndex = 18;
this.btnBackward3.Text = "<10";
this.btnBackward3.UseVisualStyleBackColor = true;
//
// btnForward3
//
this.btnForward3.Location = new System.Drawing.Point( 192, 12 );
this.btnForward3.Name = "btnForward3";
this.btnForward3.Size = new System.Drawing.Size( 35, 30 );
this.btnForward3.TabIndex = 19;
this.btnForward3.Text = "10>";
this.btnForward3.UseVisualStyleBackColor = true;
//
// btnUndo
//
this.btnUndo.Location = new System.Drawing.Point( 178, 50 );
this.btnUndo.Name = "btnUndo";
this.btnUndo.Size = new System.Drawing.Size( 49, 23 );
this.btnUndo.TabIndex = 20;
this.btnUndo.Text = "undo";
this.btnUndo.UseVisualStyleBackColor = true;
//
// btnRedo
//
this.btnRedo.Location = new System.Drawing.Point( 178, 75 );
this.btnRedo.Name = "btnRedo";
this.btnRedo.Size = new System.Drawing.Size( 49, 23 );
this.btnRedo.TabIndex = 21;
this.btnRedo.Text = "redo";
this.btnRedo.UseVisualStyleBackColor = true;
//
// FormCurvePointEdit
//
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 12F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnExit;
this.ClientSize = new System.Drawing.Size( 239, 144 );
this.Controls.Add( this.btnRedo );
this.Controls.Add( this.btnUndo );
this.Controls.Add( this.btnForward3 );
this.Controls.Add( this.btnBackward3 );
this.Controls.Add( this.btnApply );
this.Controls.Add( this.btnForward2 );
this.Controls.Add( this.btnBackward2 );
this.Controls.Add( this.btnExit );
this.Controls.Add( this.lblDataPointValue );
this.Controls.Add( this.btnForward );
this.Controls.Add( this.txtDataPointClock );
this.Controls.Add( this.btnBackward );
this.Controls.Add( this.lblDataPointClock );
this.Controls.Add( this.txtDataPointValue );
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FormCurvePointEdit";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "FormCurvePointEdit";
this.ResumeLayout( false );
this.PerformLayout();
}
private BButton btnForward;
private BButton btnBackward;
private BLabel lblDataPointValue;
private NumberTextBox txtDataPointClock;
private BLabel lblDataPointClock;
private NumberTextBox txtDataPointValue;
private BButton btnExit;
private BButton btnBackward2;
private BButton btnForward2;
private BButton btnApply;
private BButton btnBackward3;
private BButton btnForward3;
private BButton btnUndo;
private BButton btnRedo;
#endif
#endregion
}
#if !JAVA
}
#endif
|