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
|
/*
* FormIconPalette.cs
* Copyright © 2010-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/FormIconPalette.java
import java.util.*;
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.io.*;
import javax.swing.*;
import javax.imageio.*;
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.java.awt;
using org.kbinani.java.util;
using org.kbinani.javax.swing;
using org.kbinani.vsq;
using org.kbinani.windows.forms;
namespace org.kbinani.cadencii
{
using BFormClosingEventArgs = System.Windows.Forms.FormClosingEventArgs;
using BMouseEventArgs = System.Windows.Forms.MouseEventArgs;
using BEventHandler = System.EventHandler;
using BFormClosingEventHandler = System.Windows.Forms.FormClosingEventHandler;
using BMouseEventHandler = System.Windows.Forms.MouseEventHandler;
using BEventArgs = System.EventArgs;
using boolean = System.Boolean;
#endif
#if JAVA
class DraggableBButton extends BButton
#else
class DraggableBButton : BButton
#endif
{
private IconDynamicsHandle mHandle = null;
#if JAVA
public DraggableBButton()
{
super();
int drag_action = DnDConstants.ACTION_COPY;
new DragSource().createDefaultDragGestureRecognizer(
this,
drag_action,
new DragGestureListener(){
//@Override
public void dragGestureRecognized( DragGestureEvent e ) {
// 1) cursor
Cursor dragCursor = DragSource.DefaultCopyDrop;
// 2) transfer data
// タグにはIconDynamicsHandleが格納されている
if( mHandle == null ){
return;
}
String icon_id = mHandle.IconID;
StringSelection transferable = new StringSelection( ClipboardModel.CLIP_PREFIX + ":" + icon_id );
// 3) start drag
e.startDrag( dragCursor, transferable );
}
} );
}
#endif
public IconDynamicsHandle getHandle()
{
return mHandle;
}
public void setHandle( IconDynamicsHandle value )
{
mHandle = value;
}
}
#if JAVA
public class FormIconPalette extends BForm
#else
public class FormIconPalette : BForm
#endif
{
private Vector<BButton> dynaffButtons = new Vector<BButton>();
private Vector<BButton> crescendButtons = new Vector<BButton>();
private Vector<BButton> decrescendButtons = new Vector<BButton>();
private int buttonWidth = 40;
private FormMain mMainWindow = null;
private boolean mPreviousAlwaysOnTop;
public FormIconPalette( FormMain main_window )
{
#if JAVA
super();
initialize();
#else
InitializeComponent();
#endif
mMainWindow = main_window;
applyLanguage();
Util.applyFontRecurse( this, AppManager.editorConfig.getBaseFont() );
init();
registerEventHandlers();
TreeMap<String, BKeys[]> dict = AppManager.editorConfig.getShortcutKeysDictionary( mMainWindow.getDefaultShortcutKeys() );
if ( dict.containsKey( "menuVisualIconPalette" ) ) {
BKeys[] keys = dict.get( "menuVisualIconPalette" );
KeyStroke shortcut = BKeysUtility.getKeyStrokeFromBKeys( keys );
menuWindowHide.setAccelerator( shortcut );
}
}
#region public methods
/// <summary>
/// AlwaysOnTopが強制的にfalseにされる直前の,AlwaysOnTop値を取得します.
/// </summary>
public boolean getPreviousAlwaysOnTop()
{
return mPreviousAlwaysOnTop;
}
/// <summary>
/// AlwaysOnTopが強制的にfalseにされる直前の,AlwaysOnTop値を設定しておきます.
/// </summary>
public void setPreviousAlwaysOnTop( boolean value )
{
mPreviousAlwaysOnTop = value;
}
public void applyLanguage()
{
setTitle( _( "Icon Palette" ) );
}
public void applyShortcut( KeyStroke shortcut )
{
menuWindowHide.setAccelerator( shortcut );
}
#endregion
#region helper methods
private static String _( String id )
{
return Messaging.getMessage( id );
}
private void registerEventHandlers()
{
this.Load += new BEventHandler( FormIconPalette_Load );
this.FormClosing += new BFormClosingEventHandler( FormIconPalette_FormClosing );
menuWindowHide.Click += new BEventHandler( menuWindowHide_Click );
}
private void init()
{
for ( Iterator<IconDynamicsHandle> itr = VocaloSysUtil.dynamicsConfigIterator( SynthesizerType.VOCALOID1 ); itr.hasNext(); ) {
IconDynamicsHandle handle = itr.next();
String icon_id = handle.IconID;
#if JAVA
DraggableBButton btn = new DraggableBButton();
#else
DraggableBButton btn = new DraggableBButton();
#endif
btn.setName( icon_id );
btn.setHandle( handle );
String buttonIconPath = handle.getButtonImageFullPath();
boolean setimg = fsys.isFileExists( buttonIconPath );
if ( setimg ) {
Image img = null;
#if JAVA
try{
img = ImageIO.read( new File( buttonIconPath ) );
}catch( Exception ex ){
Logger.write( FormIconPalette.class + "; ex=" + ex + "\n" );
serr.println( "FormIconPalette#init; ex=" + ex );
}
#else
img = new Image();
img.image = System.Drawing.Image.FromStream( new System.IO.FileStream( buttonIconPath, System.IO.FileMode.Open, System.IO.FileAccess.Read ) );
#endif
btn.setIcon( new ImageIcon( img ) );
} else {
Image img = null;
String str = "";
String caption = handle.IDS;
if ( caption.Equals( "cresc_1" ) ) {
img = Resources.get_cresc1();
} else if ( caption.Equals( "cresc_2" ) ) {
img = Resources.get_cresc2();
} else if ( caption.Equals( "cresc_3" ) ) {
img = Resources.get_cresc3();
} else if ( caption.Equals( "cresc_4" ) ) {
img = Resources.get_cresc4();
} else if ( caption.Equals( "cresc_5" ) ) {
img = Resources.get_cresc5();
} else if ( caption.Equals( "dim_1" ) ) {
img = Resources.get_dim1();
} else if ( caption.Equals( "dim_2" ) ) {
img = Resources.get_dim2();
} else if ( caption.Equals( "dim_3" ) ) {
img = Resources.get_dim3();
} else if ( caption.Equals( "dim_4" ) ) {
img = Resources.get_dim4();
} else if ( caption.Equals( "dim_5" ) ) {
img = Resources.get_dim5();
} else if ( caption.Equals( "Dynaff11" ) ) {
str = "fff";
} else if ( caption.Equals( "Dynaff12" ) ) {
str = "ff";
} else if ( caption.Equals( "Dynaff13" ) ) {
str = "f";
} else if ( caption.Equals( "Dynaff21" ) ) {
str = "mf";
} else if ( caption.Equals( "Dynaff22" ) ) {
str = "mp";
} else if ( caption.Equals( "Dynaff31" ) ) {
str = "p";
} else if ( caption.Equals( "Dynaff32" ) ) {
str = "pp";
} else if ( caption.Equals( "Dynaff33" ) ) {
str = "ppp";
}
if ( img != null ) {
btn.setIcon( new ImageIcon( img ) );
} else {
btn.setText( str );
}
}
btn.MouseDown += new BMouseEventHandler( handleCommonMouseDown );
btn.setPreferredSize( new Dimension( buttonWidth, buttonWidth ) );
int iw = 0;
int ih = 0;
if ( icon_id.StartsWith( IconDynamicsHandle.ICONID_HEAD_DYNAFF ) ) {
// dynaff
dynaffButtons.add( btn );
ih = 0;
iw = dynaffButtons.size() - 1;
} else if ( icon_id.StartsWith( IconDynamicsHandle.ICONID_HEAD_CRESCEND ) ) {
// crescend
crescendButtons.add( btn );
ih = 1;
iw = crescendButtons.size() - 1;
} else if ( icon_id.StartsWith( IconDynamicsHandle.ICONID_HEAD_DECRESCEND ) ) {
// decrescend
decrescendButtons.add( btn );
ih = 2;
iw = decrescendButtons.size() - 1;
} else {
continue;
}
#if JAVA
LayoutManager lm = jPanel.getLayout();
GridBagLayout gbl = null;
if( lm != null && lm instanceof GridBagLayout ){
gbl = (GridBagLayout)lm;
}else{
gbl = new GridBagLayout();
jPanel.setLayout( gbl );
}
GridBagConstraints g = new GridBagConstraints();
g.gridx = iw;
g.gridy = ih;
gbl.setConstraints( btn, g );
jPanel.add( btn );
#else
btn.Location = new System.Drawing.Point( iw * buttonWidth, ih * buttonWidth );
this.Controls.Add( btn );
btn.BringToFront();
#endif
}
// ウィンドウのサイズを固定化する
int height = 0;
int width = 0;
if ( dynaffButtons.size() > 0 ) {
height += buttonWidth;
}
width = Math.Max( width, buttonWidth * dynaffButtons.size() );
if ( crescendButtons.size() > 0 ) {
height += buttonWidth;
}
width = Math.Max( width, buttonWidth * crescendButtons.size() );
if ( decrescendButtons.size() > 0 ) {
height += buttonWidth;
}
width = Math.Max( width, buttonWidth * decrescendButtons.size() );
#if JAVA
pack();
Insets i = getInsets();
Dimension size = new Dimension( width + i.left + i.right, height + i.top + i.bottom );
setPreferredSize( size );
setSize( size );
setResizable( false );
#else
this.ClientSize = new System.Drawing.Size( width, height );
Dimension size = getSize();
#endif
setMaximumSize( size );
setMinimumSize( size );
}
#endregion
#region event handlers
public void FormIconPalette_Load( Object sender, BEventArgs e )
{
// コンストラクタから呼ぶと、スレッドが違うので(たぶん)うまく行かない
setAlwaysOnTop( true );
}
public void FormIconPalette_FormClosing( Object sender, BFormClosingEventArgs e )
{
setVisible( false );
#if !JAVA
e.Cancel = true;
#endif
}
public void menuWindowHide_Click( Object sender, EventArgs e )
{
setVisible( false );
}
public void handleCommonMouseDown( Object sender, BMouseEventArgs e )
{
if ( AppManager.getEditMode() != EditMode.NONE ) {
return;
}
DraggableBButton btn = (DraggableBButton)sender;
if ( mMainWindow != null ) {
mMainWindow.toFront();
}
IconDynamicsHandle handle = btn.getHandle();
VsqEvent item = new VsqEvent();
item.Clock = 0;
item.ID.Note = 60;
item.ID.type = VsqIDType.Aicon;
item.ID.IconDynamicsHandle = (IconDynamicsHandle)handle.clone();
int length = handle.getLength();
if ( length <= 0 ) {
length = 1;
}
item.ID.setLength( length );
AppManager.mAddingEvent = item;
#if JAVA
//TODO: fixme FormIconPalette#handleCommonMouseDown
#else
btn.DoDragDrop( handle, System.Windows.Forms.DragDropEffects.All );
#endif
}
#endregion
#region UI implementation
#if JAVA
//INCLUDE-SECTION FIELD ../BuildJavaUI/src/org/kbinani/cadencii/FormIconPalette.java
//INCLUDE-SECTION METHOD ../BuildJavaUI/src/org/kbinani/cadencii/FormIconPalette.java
#else
private void InitializeComponent()
{
this.menuBar = new org.kbinani.windows.forms.BMenuBar();
this.menuWindow = new org.kbinani.windows.forms.BMenuItem();
this.menuWindowHide = new org.kbinani.windows.forms.BMenuItem();
this.menuBar.SuspendLayout();
this.SuspendLayout();
//
// menuBar
//
this.menuBar.Items.AddRange( new System.Windows.Forms.ToolStripItem[] {
this.menuWindow} );
this.menuBar.Location = new System.Drawing.Point( 0, 0 );
this.menuBar.Name = "menuBar";
this.menuBar.Size = new System.Drawing.Size( 458, 24 );
this.menuBar.TabIndex = 0;
this.menuBar.Text = "bMenuBar1";
//
// menuWindow
//
this.menuWindow.DropDownItems.AddRange( new System.Windows.Forms.ToolStripItem[] {
this.menuWindowHide} );
this.menuWindow.Name = "menuWindow";
this.menuWindow.Size = new System.Drawing.Size( 55, 20 );
this.menuWindow.Text = "Window";
//
// menuWindowHide
//
this.menuWindowHide.Name = "menuWindowHide";
this.menuWindowHide.Size = new System.Drawing.Size( 93, 22 );
this.menuWindowHide.Text = "Hide";
//
// FormIconPalette
//
this.ClientSize = new System.Drawing.Size( 458, 342 );
this.Controls.Add( this.menuBar );
this.MainMenuStrip = this.menuBar;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FormIconPalette";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Icon Palette";
this.menuBar.ResumeLayout( false );
this.menuBar.PerformLayout();
this.ResumeLayout( false );
this.PerformLayout();
}
private BMenuBar menuBar;
private BMenuItem menuWindow;
private BMenuItem menuWindowHide;
#endif
#endregion
}
#if !JAVA
}
#endif
|