get toolbar working

This commit is contained in:
benfry
2011-01-26 03:28:12 +00:00
parent a6f0f1ef99
commit 26b98b8e6a
3 changed files with 24 additions and 3 deletions
+16 -1
View File
@@ -98,7 +98,7 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
int modeX1, modeY1;
int modeX2, modeY2;
ArrayList<Button> buttons;
protected ArrayList<Button> buttons;
public EditorToolbar(Editor editor, Base base) { //, JMenu menu) {
@@ -131,6 +131,14 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
}
/** Load images and add toolbar buttons */
abstract public void init();
/**
* Only call this from paintComponent, or when the comp is displayable,
* otherwise createImage() might fail.
*/
public Image[][] loadImages() {
// Image allButtons = Base.getThemeImage("buttons.gif", this);
// Image allButtons = Base.loadImage(file);
@@ -141,6 +149,9 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
for (int i = 0; i < count; i++) {
for (int state = 0; state < 3; state++) {
// Toolkit tk = Toolkit.getDefaultToolkit();
// Image image = tk.createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
// System.out.println("image is " + image + " " + BUTTON_WIDTH + " " + BUTTON_HEIGHT);
Image image = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
Graphics g = image.getGraphics();
g.drawImage(allButtons,
@@ -158,6 +169,10 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
@Override
public void paintComponent(Graphics screen) {
if (buttons.size() == 0) {
init();
}
// this data is shared by all EditorToolbar instances
// if (buttonImages == null) {
// loadButtons();
@@ -41,7 +41,10 @@ public class AndroidToolbar extends EditorToolbar {
public AndroidToolbar(Editor editor, Base base) {
super(editor, base);
}
public void init() {
Image[][] images = loadImages();
for (int i = 0; i < 6; i++) {
addButton(getTitle(i, false), getTitle(i, true), images[i], i == NEW);
@@ -54,7 +54,10 @@ public class JavaToolbar extends EditorToolbar {
public JavaToolbar(Editor editor, Base base) {
super(editor, base);
}
public void init() {
Image[][] images = loadImages();
for (int i = 0; i < 6; i++) {
addButton(getTitle(i, false), getTitle(i, true), images[i], i == NEW);