File: FormWordDictionaryController.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-5
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 35,880 kB
  • sloc: cs: 160,836; java: 42,449; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (231 lines) | stat: -rw-r--r-- 8,295 bytes parent folder | download | duplicates (6)
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
/*
 * FormWordDictionaryController.cs
 * Copyright © 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;

import java.util.*;
import org.kbinani.*;
import org.kbinani.apputil.*;
import org.kbinani.vsq.*;

#else

namespace org
{
    namespace kbinani
    {
        namespace cadencii
        {
#if __cplusplus
#else
            using System;
            using System.Windows.Forms;
            using org.kbinani.apputil;
            using org.kbinani.vsq;
            using org.kbinani;
            using org.kbinani.java.util;
            using org.kbinani.windows.forms;
            using BEventArgs = System.EventArgs;
            using boolean = System.Boolean;
            using BEventHandler = System.EventHandler;
            using BFormClosingEventHandler = System.Windows.Forms.FormClosingEventHandler;
            using BFormClosingEventArgs = System.Windows.Forms.FormClosingEventArgs;
#endif

#endif

#if JAVA
            public class FormWordDictionaryController extends ControllerBase implements FormWordDictionaryUiListener
#else
            public class FormWordDictionaryController : ControllerBase, FormWordDictionaryUiListener
#endif
            {
                private FormWordDictionaryUiImpl ui;
                private static int mColumnWidth = 256;
                private static int mWidth = 327;
                private static int mHeight = 404;

                public FormWordDictionaryController()
                {
                    ui = new FormWordDictionaryUiImpl( this );
                    applyLanguage();
                    ui.setSize( mWidth, mHeight );
#if CSHARP
                    ui.listDictionariesSetColumnWidth( mColumnWidth );
#endif
                }


                #region FormWordDictionaryUiListenerの実装

                public void buttonCancelClick()
                {
                    ui.setDialogResult( false );
                }

                public void buttonDownClick()
                {
                    int index = ui.listDictionariesGetSelectedRow();
                    if ( 0 <= index && index + 1 < ui.listDictionariesGetItemCountRow() )
                    {
                        try
                        {
                            ui.listDictionariesClear();
                            String upper_name = ui.listDictionariesGetItemAt( index );
                            boolean upper_enabled = ui.listDictionariesIsRowChecked( index );
                            String lower_name = ui.listDictionariesGetItemAt( index + 1 );
                            boolean lower_enabled = ui.listDictionariesIsRowChecked( index + 1 );

                            ui.listDictionariesSetItemAt( index + 1, upper_name );
                            ui.listDictionariesSetRowChecked( index + 1, upper_enabled );
                            ui.listDictionariesSetItemAt( index, lower_name );
                            ui.listDictionariesSetRowChecked( index, lower_enabled );

                            ui.listDictionariesSetSelectedRow( index + 1 );
                        }
                        catch ( Exception ex )
                        {
                            serr.println( "FormWordDictionary#btnDown_Click; ex=" + ex );
                        }
                    }
                }

                public void buttonUpClick()
                {
                    int index = ui.listDictionariesGetSelectedRow();
                    if ( index >= 1 )
                    {
                        try
                        {
                            ui.listDictionariesClearSelection();
                            String upper_name = ui.listDictionariesGetItemAt( index - 1 );
                            boolean upper_enabled = ui.listDictionariesIsRowChecked( index - 1 );
                            String lower_name = ui.listDictionariesGetItemAt( index );
                            boolean lower_enabled = ui.listDictionariesIsRowChecked( index );

                            ui.listDictionariesSetItemAt( index - 1, lower_name );
                            ui.listDictionariesSetRowChecked( index - 1, lower_enabled );
                            ui.listDictionariesSetItemAt( index, upper_name );
                            ui.listDictionariesSetRowChecked( index, upper_enabled );

                            ui.listDictionariesSetSelectedRow( index - 1 );
                        }
                        catch ( Exception ex )
                        {
                            serr.println( "FormWordDictionary#btnUp_Click; ex=" + ex );
                        }
                    }
                }

                public void buttonOkClick()
                {
                    ui.setDialogResult( true );
                }

                public void formLoad()
                {
                    ui.listDictionariesClear();
                    for ( int i = 0; i < SymbolTable.getCount(); i++ )
                    {
                        String name = SymbolTable.getSymbolTable( i ).getName();
                        boolean enabled = SymbolTable.getSymbolTable( i ).isEnabled();
                        ui.listDictionariesAddRow( name, enabled );
                    }
                }

                public void formClosing()
                {
#if CSHARP
                    mColumnWidth = ui.listDictionariesGetColumnWidth();
#endif
                    mWidth = ui.getWidth();
                    mHeight = ui.getHeight();
                }

                #endregion


                #region public methods

                public void close()
                {
                    ui.close();
                }

                public UiBase getUi()
                {
                    return ui;
                }

                public int getWidth()
                {
                    return ui.getWidth();
                }

                public int getHeight()
                {
                    return ui.getHeight();
                }

                public void setLocation( int x, int y )
                {
                    ui.setLocation( x, y );
                }

                public void applyLanguage()
                {
                    ui.setTitle( _( "User Dictionary Configuration" ) );
                    ui.labelAvailableDictionariesSetText( _( "Available Dictionaries" ) );
                    ui.buttonOkSetText( _( "OK" ) );
                    ui.buttonCancelSetText( _( "Cancel" ) );
                    ui.buttonUpSetText( _( "Up" ) );
                    ui.buttonDownSetText( _( "Down" ) );
                }

                public Vector<ValuePair<String, Boolean>> getResult()
                {
                    Vector<ValuePair<String, Boolean>> ret = new Vector<ValuePair<String, Boolean>>();
                    int count = ui.listDictionariesGetItemCountRow();
#if DEBUG
                    sout.println( "FormWordDictionary#getResult; count=" + count );
#endif
                    for ( int i = 0; i < count; i++ )
                    {
                        String name = ui.listDictionariesGetItemAt( i );

                        ret.add( new ValuePair<String, Boolean>(
                            ui.listDictionariesGetItemAt( i ), ui.listDictionariesIsRowChecked( i ) ) );
                    }
                    return ret;
                }

                #endregion


                #region private methods

                private static String _( String id )
                {
                    return Messaging.getMessage( id );
                }

                #endregion
            }

#if !JAVA
        }
    }
}
#endif