LWUIT中的进度条实现(Progress Indicator & Threads In LWUIT by Shai Almog)

LWUIT doesn’t ship with a pre-existing progress indicator, mostly
because making something generic enough for all the common cases is
not as simple as it might seem in the beginning. Especially when
considering how easy it is to write your own progress
indicator…
This is a simple example of how to create a custom component in
LWUIT in this specific case a progress indicator that supports both
drawing itself (as a filled round rectangle and as a couple of
images overlayed one on top of the other. The progress indicator
component is fully themeable and customizable and will accept all
L&F settings seamlessly.
The screenshots show both an image based indicator (its ugliness is
just a testament to my bad drawing skills) and an indicator drawn
in graphics primitives (fill/drawRoundRect). These are the images
used to draw the image progress:
 LWUIT中的进度条实现(Progress <wbr>Indicator <wbr>& <wbr>Threads <wbr>In <wbr>LWUIT <wbr>by <wbr>Shai <wbr>Almog)Indicator Threads In LWUIT by Shai Almog)” TITLE=”LWUIT中的进度条实现(Progress Indicator Threads In LWUIT by Shai Almog)” />LWUIT中的进度条实现(Progress <wbr>Indicator <wbr>& <wbr>Threads <wbr>In <wbr>LWUIT <wbr>by <wbr>Shai <wbr>Almog)Indicator Threads In LWUIT by Shai Almog)” TITLE=”LWUIT中的进度条实现(Progress Indicator Threads In LWUIT by Shai Almog)” />

As part of this I also wanted to create something else familiar to
Swing developers, the SwingWorker. Generally I prefer the foxtrot
approach implemented in LWUIT as invokeAndBlock in Display, however
lots of people like the SwingWorker approach so I used it here as
part of the explanations.

First lets create the Progress indicator component:


public class Progress extends Component {
private byte percent;
private Image unfilled;
private Image filled;

public Progress() {
   setFocusable(false);
}

public Progress(Image unfilled, Image filled) {
   this();
   this.unfilled =
unfilled;
   this.filled = filled;
}

public String getUIID() {
   return “Progress”;
}

public byte getProgress() {
   return percent;
}

public void setProgress(byte percent) {
   this.percent = percent;
   repaint();
}

protected Dimension calcPreferredSize() {
   if(filled != null) {
      
return new Dimension(filled.getWidth(), filled.getHeight());
   } else {
      
// we don’t really need to be in the font height but this
provides
      
// a generally good indication for size expectations
      
return new Dimension(Display.getInstance().getDisplayWidth(),
          
Font.getDefaultFont().getHeight());
   }
}

public void paint(Graphics g) {
   int width =
(int)((((float)percent) / 100.0f) * getWidth());
   if(filled != null) {
      
if(filled.getWidth() != getWidth()) {
          
filled = filled.scaled(getWidth(), getHeight());
          
unfilled = unfilled.scaled(getWidth(), getHeight());
      
}
 
      
// draw based on two user supplied images
      
g.drawImage(unfilled, getX(), getY());
      
g.clipRect(getX(), getY(), width, getHeight());
      
g.drawImage(filled, getX(), getY());
   } else {
      
// draw based on simple graphics primitives
      
Style s = getStyle();
      
g.setColor(s.getBgColor());
      
int curve = getHeight() / 2 – 1;
      
g.fillRoundRect(getX(), getY(), getWidth() – 1, getHeight() – 1,
curve, curve);
      
g.setColor(s.getFgColor());
      
g.drawRoundRect(getX(), getY(), getWidth() – 1, getHeight() – 1,
curve, curve);
      
g.clipRect(getX(), getY(), width – 1, getHeight() – 1);
      
g.setColor(s.getBgSelectionColor());
      
g.fillRoundRect(getX(), getY(), getWidth() – 1, getHeight() – 1,
curve, curve);
   }
}
}

This code seems to me to be simple but obviously I’m not objective,
if something is not clear or you think it might not be clear to
others please let me know in the comments.

BackgroundTask is my equivalent to SwingWorker, its much simpler
than SwingWorker:


public abstract class BackgroundTask {

public final void start() {
  
if(Display.getInstance().isEdt()) {
      
taskStarted();
   } else {
      
Display.getInstance().callSeriallyAndWait(new Runnable() {
          
public void run() {
              
taskStarted();
          
}
      
});
   }
   new Thread(new Runnable()
{
      
public void run() {
          
if(Display.getInstance().isEdt()) {
              
taskFinished();
          
} else {
              
performTask();
              
Display.getInstance().callSerially(this);
          
}
      
}
   }).start();
}

public void taskStarted() {
}

public abstract void performTask();

public void taskFinished() {
}
}

And this is the code to display these two progress bars:

Form progressForm = new Form(“Progress”);
progressForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Progress p1 = new Progress();
progressForm.addComponent(new Label(“Drawn”));
progressForm.addComponent(p1);
Progress p2 = new Progress(Image.createImage(“/unfilled.png”),
Image.createImage(“/filled.png”));
p2.getStyle().setBgTransparency(0);
progressForm.addComponent(new Label(“Image Based”));
progressForm.addComponent(p2);
progressForm.show();

class ProgressCommand extends Command {
private Progress p;
public ProgressCommand(String name, Progress p) {
   super(name);
   this.p = p;
}
public void actionPerformed(ActionEvent ev) {
   new BackgroundTask() {
      
public void performTask() {
          
for(byte b = 0 ; b <= 100 ; b++) {
              
try {
                  
p.setProgress(b);
                  
Thread.sleep(100);
              
} catch (InterruptedException ex) {
                  
ex.printStackTrace();
              
}
          
}
      
}
   }.start();
}
}

progressForm.addCommand(new ProgressCommand(“Drawn”, p1));
progressForm.addCommand(new ProgressCommand(“Images”, p2));

转自:http://lwuit.blogspot.com/2008/05/progress-indicator-threads-in-lwuit.html

又一个人准备上船了

  新浪科技讯
北京时间3月4日凌晨消息,据《纽约邮报》报道,一名熟知内情的消息人士称,有人正试图出售价值最多3亿美元的Facebook私募发行股票。

  《纽约邮报》称,出售Facebook股票的可能是其联合创始人马克·扎克伯格(Mark
Zuckerberg)、达斯汀·莫斯科维茨(Dustin Moskovitz)或爱德华多·萨维林(Eduardo
Saverin)中的一人,但并未说明理由。除了这3人以外,其他许多投资者也持有大量的Facebook股票。

  《纽约邮报》没有提及扎克伯格的儿时好友亚当·安吉洛(Adam
D’Angelo),他可能是仅次于扎克伯格的最具影响力的Facebook联合创始人,但他很少公开露面。

  业界分析师指出,上述3人都有很好的理由出售Facebook股票。莫斯科维茨和萨维林现在都已不在Facebook供职,而扎克伯格可能希望出售部分股票来获得流动资金。

  此外,Facebook早期投资者皮特·泰尔(Peter Thiel)和Facebook创始总裁西恩·帕克(Sean
Parker)也可能出售该公司股票,而Facebook早期风投公司中的某一家也有此可能。举例来说,去年底Accel
Partners就出售了价值约为5亿美元的Facebook股票。(唐风)

“诺基亚近日宣布,将于2012年3月全面停止S60系统服务”——系谣传,不排除炒作嫌疑。

  “诺基亚近日宣布,将于2012年3月全面停止S60系统服务,内容包括停止开发和更新S60系统,停止开发支持S60系统的sis软件,停止
S60系统的手机发售。届时诺基亚所有中低端手机全面使用Symbian^3系统,高端手机使用Windows Phone
7系统!这意味着称霸智能手机领域近10年的S60系统将彻底退出历史的舞台。”

  所谓流言止于智者,小生一看这条新闻就觉得很假(哈哈)。果然,诺基亚官方下午在微博上作出了明确答复:“诺基亚从未发布过以下关于S60的信息。诺
基亚将继续支持Symbian平台,不断推出新产品,提升核心处理器能力和图形处理速度等硬件表现,以及不断更新的用户体验。”

  贴图为证:

“诺基亚近日宣布,将于2012年3月全面停止S60系统服务”——系谣传,不排除炒作嫌疑。