~ubuntu-branches/ubuntu/lucid/gbrainy/lucid

« back to all changes in this revision

Viewing changes to src/Core/Main/Verbal/AnalogiesPairOfWordsCompare.cs

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2010-01-12 11:21:24 UTC
  • mfrom: (13.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100112112124-o4ztomxa0xfh2ulj
Tags: 1.30-1ubuntu1
* debian/control:
  - Revert build-depends to lucid versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Jordi Mas i Hernàndez <jmas@softcatala.org>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; either version 2 of the
 
7
 * License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public
 
15
 * License along with this program; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
using System;
 
21
using System.IO;
 
22
using System.Collections.Generic;
 
23
 
 
24
using Cairo;
 
25
using Mono.Unix;
 
26
 
 
27
using gbrainy.Core.Libraries;
 
28
 
 
29
namespace gbrainy.Core.Main.Verbal
 
30
{
 
31
        public class AnalogiesPairOfWordsCompare : Analogies
 
32
        {
 
33
                static protected Dictionary <int, Analogy> analogies;
 
34
                static protected ArrayListIndicesRandom analogies_indices;
 
35
                static protected int analogies_index = 0;
 
36
 
 
37
                string samples, sample;
 
38
 
 
39
                public AnalogiesPairOfWordsCompare ()
 
40
                {
 
41
                        if (analogies == null)
 
42
                                analogies = AnalogiesFactory. Get (Analogy.Type.PairOfWordsCompare);
 
43
                }
 
44
 
 
45
                public override string Name {
 
46
                        get { return Catalog.GetString ("Pair of words compare");}
 
47
                }
 
48
 
 
49
                public override ArrayListIndicesRandom Indices {
 
50
                        get { return analogies_indices; }
 
51
                        set { analogies_indices = value; }
 
52
                }
 
53
 
 
54
                public override int CurrentIndex {
 
55
                        get { return analogies_index; }
 
56
                        set { analogies_index = value; }
 
57
                }
 
58
 
 
59
                public override Dictionary <int, Analogy> List {
 
60
                        get { return analogies; }
 
61
                }
 
62
 
 
63
                public override string Question {
 
64
                        get {
 
65
                                if (current == null)
 
66
                                        return string.Empty;
 
67
 
 
68
                                if (current.answers == null)
 
69
                                        return current.question;
 
70
 
 
71
                                return String.Format (Catalog.GetString (
 
72
                                        "Given the pair of words below, which word has the closest relationship to '{0}'?"),
 
73
                                        sample);
 
74
                        }
 
75
                }
 
76
 
 
77
                public override void Initialize ()
 
78
                {
 
79
                        current = GetNext ();
 
80
 
 
81
                        if (current == null || current.answers == null)
 
82
                                return;
 
83
 
 
84
                        string [] items;
 
85
 
 
86
                        items = current.question.Split (AnalogiesFactory.Separator);
 
87
 
 
88
                        if (items.Length == 2)
 
89
                                sample = items [1].Trim ();
 
90
                        else
 
91
                                sample = string.Empty;
 
92
 
 
93
                        samples = items [0].Trim ();
 
94
                        right_answer = current.answers [current.right];
 
95
                }
 
96
        
 
97
                public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
 
98
                {
 
99
                        double y = DrawAreaY + 0.1;
 
100
 
 
101
                        base.Draw (gr, area_width, area_height, rtl);
 
102
 
 
103
                        if (current == null || current.answers == null)
 
104
                                return;
 
105
 
 
106
                        gr.SetPangoLargeFontSize ();
 
107
                        gr.DrawTextCentered (0.5, y + 0.25,
 
108
                                String.Format (Catalog.GetString ("Words: {0}"), samples));
 
109
                }
 
110
        }
 
111
}