Class: JLDrill::DisplayProblemContext

Inherits:
Context::Context show all
Includes:
Behaviour::SearchDictionary
Defined in:
lib/jldrill/contexts/DisplayProblemContext.rb

Defined Under Namespace

Classes: ProblemView

Instance Attribute Summary

Attributes inherited from Context::Context

#mainView, #parent, #viewBridge

Instance Method Summary collapse

Methods included from Behaviour::SearchDictionary

#dictionaryLoaded?, #findKanjiInDictionary, #kanjiInfo, #kanjiLoaded?, #search

Methods inherited from Context::Context

#addView, #isEntered?, #onExit, #peekAtView, #setupViews

Constructor Details

#initialize(viewBridge) ⇒ DisplayProblemContext

Returns a new instance of DisplayProblemContext.



11
12
13
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 11

def initialize(viewBridge)
	super(viewBridge)
end

Instance Method Details

#createViewsObject



83
84
85
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 83

def createViews
    @mainView = @viewBridge.ProblemView.new(self)
end

#destroyViewsObject



87
88
89
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 87

def destroyViews
    @mainView = nil
end

#differs?(problem) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
127
128
129
130
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 124

def differs?(problem)
    exists = true
    if @parent.reference.loaded? && !problem.nil?
        exists = @parent.reference.include?(problem.item.to_o)
		    end
		    return !exists
end

#edictLoadUpdated(reference) ⇒ Object



147
148
149
150
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 147

def edictLoadUpdated(reference)
          quiz = @parent.quiz
          @mainView.updateProblem(quiz.currentProblem)
end

#enter(parent) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 91

def enter(parent)
    super(parent)
          if !@parent.nil?
              if !@parent.quiz.nil?
                  @parent.quiz.publisher.subscribe(self, "load")
                  @parent.quiz.publisher.subscribe(self, "newProblem")
                  @parent.quiz.publisher.subscribe(self, "problemModified")
              end
              if !@parent.reference.nil?
                  @parent.reference.publisher.subscribe(self, "edictLoad")
              end
              @parent.longEventPublisher.subscribe(self, "startLongEvent")
              @parent.longEventPublisher.subscribe(self, "stopLongEvent")
              newProblemUpdated(@parent.quiz.currentProblem)
          end
end

#exitObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 108

def exit
          if !@parent.nil?
              if !@parent.quiz.nil?
                  @parent.quiz.publisher.unsubscribe(self, "load")
                  @parent.quiz.publisher.unsubscribe(self, "newProblem")
                  @parent.quiz.publisher.unsubscribe(self, "problemModified")
              end
              if !@parent.reference.nil?
                  @parent.reference.publisher.unsubscribe(self, "edictLoad")
              end
              @parent.longEventPublisher.unsubscribe(self, "startLongEvent")
              @parent.longEventPublisher.unsubscribe(self, "stopLongEvent")
          end
    super
end

#expandWithSavePath(filename) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 164

def expandWithSavePath(filename)
    if !@parent.quiz.nil?
        return @parent.quiz.useSavePath(filename)
    else
        return filename
    end
end

#loadUpdated(quiz) ⇒ Object



132
133
134
135
136
137
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 132

def loadUpdated(quiz)
    # There isn't likely a new problem at this point, but this
    # will clear the panes and update the status for the new
    # quiz
    newProblemUpdated(quiz.currentProblem)
end

#newProblemUpdated(problem) ⇒ Object



139
140
141
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 139

def newProblemUpdated(problem)
          @mainView.newProblem(problem)
end

#problemModifiedUpdated(problem) ⇒ Object



143
144
145
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 143

def problemModifiedUpdated(problem)
          @mainView.updateProblem(problem)
end

#showAnswerObject



160
161
162
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 160

def showAnswer
    @mainView.showAnswer
end

#startLongEventUpdated(source) ⇒ Object



152
153
154
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 152

def startLongEventUpdated(source)
    @mainView.showBusy(true)
end

#stopLongEventUpdated(source) ⇒ Object



156
157
158
# File 'lib/jldrill/contexts/DisplayProblemContext.rb', line 156

def stopLongEventUpdated(source)
    @mainView.showBusy(false)
end