📄 imagelabel.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: ImageLabel.java
package com.motorola.lwt;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
// Referenced classes of package com.motorola.lwt:
// InteractableComponent, Component
public class ImageLabel extends InteractableComponent
{
public static final int LABEL_BELOW = 32;
public static final int LABEL_ABOVE = 64;
public static final int LABEL_LEFT = 256;
public static final int LABEL_RIGHT = 512;
public static final int LABEL_CENTER = 128;
public static final int ALIGN_CENTER = 1;
public static final int ALIGN_NORTH = 2;
public static final int ALIGN_SOUTH = 4;
public static final int ALIGN_EAST = 8;
public static final int ALIGN_WEST = 16;
public static final int TRANSPARENT = -1;
public static int IMAGE_LABEL_ACTION_EVENT = 1;
Image normalImage;
Image pressedImage;
Image disabledImage;
int labelLocation;
int alignment;
int foreground;
int background;
int imageWidth;
int imageHeight;
public static final int HORIZONTAL_GAP = 3;
public static final int VERTICAL_GAP = 2;
public ImageLabel(Image image, Image image1, Image image2, String s)
{
super(s);
normalImage = null;
pressedImage = null;
disabledImage = null;
labelLocation = 128;
alignment = 1;
foreground = 0;
background = -1;
imageWidth = 0;
imageHeight = 0;
setNormalImage(image);
disabledImage = image1;
pressedImage = image2;
acceptsKeyFocus = true;
}
public ImageLabel(Image image, Image image1, String s)
{
this(image, image1, null, s);
acceptsKeyFocus = false;
interactable = false;
}
public int getPreferredWidth()
{
int i = imageWidth;
int j = labelWidth;
if(labelLocation <= 128)
return i <= j ? j : i;
else
return i + j + (i != 0 && j != 0 ? 3 : 0);
}
public int getPreferredHeight()
{
int i = imageHeight;
int j = labelHeight;
if(labelLocation >= 128)
return i <= j ? j : i;
else
return i + j + (imageWidth != 0 && labelWidth != 0 ? 2 : 0);
}
public void componentActuated()
{
dispatchComponentEvent(IMAGE_LABEL_ACTION_EVENT);
}
public synchronized void setNormalImage(Image image)
{
normalImage = image;
int i = image != null ? image.getWidth() : 0;
int j = image != null ? image.getHeight() : 0;
if(i != imageWidth)
{
imageWidth = i;
preferredWidthChanged();
}
if(j != imageHeight)
{
imageHeight = j;
preferredHeightChanged();
}
repaint();
}
public synchronized void setPressedImage(Image image)
{
pressedImage = image;
if(pressed)
repaint();
}
public synchronized void setDisabledImage(Image image)
{
disabledImage = image;
if(!enabled)
repaint();
}
public void setAlignment(int i)
throws IllegalArgumentException
{
if(i == 1 || i == 2 || i == 4 || i == 8 || i == 16)
{
if(alignment != i)
{
alignment = i;
repaint();
}
return;
} else
{
throw new IllegalArgumentException();
}
}
public void setLabelLocation(int i)
throws IllegalArgumentException
{
if(i == 128 || i == 256 || i == 512 || i == 64 || i == 32)
{
int j = labelLocation - i;
if(j != 0)
{
labelLocation = i;
if(labelWidth > 0 && (j & 0x1) != 0)
{
preferredWidthChanged();
preferredHeightChanged();
}
repaint();
}
return;
} else
{
throw new IllegalArgumentException();
}
}
public synchronized int getBackgroundColor()
{
return background;
}
public synchronized void setBackgroundColor(int i)
throws IllegalArgumentException
{
if(i < -1 || i > 0xffffff)
{
throw new IllegalArgumentException();
} else
{
background = i;
repaint();
return;
}
}
public synchronized int getForegroundColor()
{
return foreground;
}
public synchronized void setForegroundColor(int i)
throws IllegalArgumentException
{
if(i < 0 || i > 0xffffff)
{
throw new IllegalArgumentException();
} else
{
foreground = i;
repaint();
return;
}
}
public synchronized void paint(Graphics g)
{
int i = width;
int j = height;
int k = labelWidth;
Image image = null;
background = background >= 0 ? background : 0;
if(enabled && pressed)
{
image = pressedImage;
g.setColor(foreground);
if(k > 0)
g.fillRect(0, 0, i, j);
} else
if(enabled)
{
g.setColor(background);
} else
{
image = disabledImage;
g.setColor(-1);
}
if(image == null)
image = normalImage;
int l = getPreferredWidth();
int i1 = getPreferredHeight();
int j1 = imageWidth;
int k1 = imageHeight;
g.setFont(itsFont);
int l1 = 0;
int i2 = 0;
if(alignment == 2)
l1 = i - l >> 1;
else
if(alignment == 4)
{
l1 = i - l >> 1;
i2 = j - i1;
} else
if(alignment == 8)
{
l1 = i - l;
i2 = j - i1 >> 1;
} else
if(alignment == 16)
i2 = j - i1 >> 1;
else
if(alignment == 1)
{
l1 = i - l >> 1;
i2 = j - i1 >> 1;
}
int j2 = 0;
int k2 = 0;
int l2 = 0;
int i3 = 0;
g.translate(l1, i2);
byte byte0 = 20;
boolean flag = false;
byte byte1 = labelWidth <= 0 || j1 <= 0 ? ((byte) (0)) : 2;
switch(labelLocation)
{
case 256:
j2 = labelWidth + byte1;
k2 = i1 - k1 >> 1;
i3 = i1 - labelHeight >> 1;
break;
case 512:
k2 = i1 - k1 >> 1;
l2 = j1 + byte1;
i3 = i1 - labelHeight >> 1;
break;
case 64: // '@'
l2 = j2 = l >> 1;
k2 = labelHeight + byte1;
byte0 = 17;
break;
case 32: // ' '
j2 = l2 = l >> 1;
i3 = k1 + byte1;
byte0 = 17;
break;
case 128:
j2 = l2 = l >> 1;
k2 = i1 >> 1;
i3 = i1 - labelHeight >> 1;
byte0 = 17;
flag = true;
break;
}
if(image != null)
{
byte byte2 = flag ? 3 : byte0;
g.drawImage(image, j2, k2, byte2);
}
if(label != null)
{
if(enabled && pressed)
g.setColor(background);
else
if(enabled)
g.setColor(foreground);
else
g.setColor(0x808080);
g.drawString(label, l2, i3, byte0);
}
if(hasFocus())
g.drawRect(0, 0, width - 1, height - 1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -