 
   setColor: (name, color) ->
     @colors[name] = color
+    return unless @isBound
     switch name
       when 'background'
         @containerEl.style.backgroundColor = @colors.background

  # If dirty is true then all saved shapes are completely redrawn,
  # otherwise the back buffer is simply copied to the screen as is.
  repaintLayer: (repaintLayerKey, dirty=(repaintLayerKey == 'main')) ->
    switch repaintLayerKey
      when 'background'
        @backgroundCtx.clearRect(

    # that all layers are repainted.
    @setZoom(@scale)

    @loadSnapshot(opts.snapshot) if opts.snapshot

    @isBound = false
    @bindToElement(containerEl)

  bindToElement: (containerEl) ->
    if @containerEl
      console.warn("Trying to bind Literally Canvas to a DOM element more than once is unsupported.")
      return

    @containerEl = containerEl
    @_unsubscribeEvents = bindEvents(this, @containerEl, @opts.keyboardShortcuts)
    @containerEl.style['background-color'] = @colors.background
    @containerEl.appendChild(@backgroundCanvas)
    @containerEl.appendChild(@canvas)

    @isBound = true

    repaintAll = =>
        @keepPanInImageBounds()
        @repaintAllLayers()

    util.matchElementSize(
      @containerEl, [@backgroundCanvas, @canvas], @backingScale, repaintAll)

    if @watermarkImage
      @watermarkImage.onload = => @repaintLayer('background')

    repaintAll()

  _teardown: ->
    @tool.willBecomeInactive(this)
    @tool = null
    @_unsubscribeEvents?()

  trigger: (name, data) ->
    @canvas.dispatchEvent(new CustomEvent(name, detail: data))
