CharEraserButton.java

/*
 * Copyright © 2012 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners.
 * See LICENSE.TXT for license information.
 */

package com.nokia.example.paint.views.components;

import com.nokia.mid.ui.TextEditor;
import javax.microedition.lcdui.Graphics;

public class CharEraserButton
        extends Button {

    private TextEditor editor;

    public CharEraserButton(TextEditor texteditor) {
        super("/dialog_btn_pressed.png", "/dialog_btn.png");
        editor = texteditor;
    }

    public void onSelected() {
        int caretPosition = editor.getCaretPosition();
        editor.delete(caretPosition - 1, 1);
    }

    public void render(Graphics g) {
        super.render(g);
        g.setColor(0x000000);
        g.drawString("Clear", this.x + (width / 2), this.y + (height / 2) + 5, Graphics.BASELINE | Graphics.HCENTER);
    }
}