📄 filebrowsingcanvas.java
字号:
//repaint();
break;
case -2: // DOWN
if(dirIndex>=dirList.size()-1)
return;
else if(visibleBottomIndex>dirIndex+1){
dirIndex++;
dirIndexIsImage=isImage( ((String)dirList.elementAt(dirIndex)) );
}
else {
dirIndex++;
visibleBottomIndex++;
visibleTopIndex++;
dirIndexIsImage=isImage( ((String)dirList.elementAt(dirIndex)) );
}
//repaint();
break;
case -3: //LEFT
break;
case -4: // RIGHT
break;
case -5: // FIRE
if(dirIndexIsImage) // if the marked item is an image load the image and show it
{
loadImage();
break;
}
if(dirIndex<lastDirIndex)
traverse();
break;
case -6: // Left Soft Button - View
if(dirIndexIsImage)
{
loadImage();
break;
}
if(dirIndex<lastDirIndex)
traverse();
break;
case -7: // Selected home dir
if(browserType==TYPE_SET_HOMEDIR)
{
PropertyClass.HOME_DIR=currentDir+(String)dirList.elementAt(dirIndex);
}
break;
case -11: // BACK
this.stopped=true;
FileConnectionDemoMidlet.display.setCurrent(next);
break;
}
}
public void updateDirList(Enumeration e, boolean isRoot)
{
// This is a callback method used by the FileAction to send us
// the directoryContent.
// if e is null somtheing went wrong and we don't do anything
if(e==null)
{
return;
}
// remove all elements in the dirList vector
dirList.removeAllElements();
// setting the indexes
lastDirIndex=0;
visibleTopIndex=0;
visibleBottomIndex=visibleBottomIndex_START;
dirIndex=0;
// If we are not in the root add the .. directory for going back in the filesystem
if(!isRoot)
{
dirList.addElement("..");
lastDirIndex++;
}
// Add all content to the dirList vector
while (e.hasMoreElements()) {
String s =(String)e.nextElement();
if(s.endsWith("/")) // If it is a directory
{
dirList.insertElementAt(s,lastDirIndex);
lastDirIndex++;
}
else if(browserType!=TYPE_SET_HOMEDIR) // If it is a file and the FilebrosingCanvs is not of type TYPE_SET_HOMEDIR we add the files to the dirList
dirList.addElement(s);
}
// set the last indexes
dirSize=dirList.size();
dirIndexIsImage=false;
//repaint();
}
// This method is called when the user press Left sofbutton or fire
// to display the content in the marked directory
private void traverse()
{
String choosenDir = (String)dirList.elementAt(dirIndex);
// If the marked directory is .. traverse back in the filesystem
if (choosenDir.equals(".."))
{
int i = currentDir.lastIndexOf('/', currentDir.length()-2);
if (i != -1) {
currentDir= currentDir.substring(0, i+1);
} else {
currentDir= "/";
}
// Start the thread to get the content of the .. directory
// the fileaction object will call the updateDirList method when it has retrieveed all the content.
new Thread(new Runnable() {
public void run() {
fileAction.getDirContent(currentDir);
}
}).start();
}
else if(dirIndex<lastDirIndex ) // Else traverse into the marked Directory
{
currentDir=currentDir+choosenDir;
// Start the thread to get the content of the choosenDir directory
// the fileaction object will call the updateDirList method when it has retrieveed all the content.
new Thread(new Runnable() {
public void run() {
fileAction.getDirContent(currentDir);
}
}).start();
}
}
// Repainting the canvas
public void run()
{
while(!stopped)
{
repaint();
try{
thread.sleep(10);
}
catch(Exception e){}
}
}
// used to check if a file is a image file.
private boolean isImage(String im)
{
int length = im.length()-4;
if(length<1)
return false;
String s = im.substring(length);
System.out.println(s);
if(s.equalsIgnoreCase(".jpg"))
return true;
if(s.equalsIgnoreCase(".gif"))
return true;
if(s.equalsIgnoreCase(".png"))
return true;
if(s.equalsIgnoreCase(".bmp"))
return true;
System.out.println("FALSE");
return false;
}
// Load a image from a file
private void loadImage()
{
final String choosenImage = "file://"+currentDir+(String)dirList.elementAt(dirIndex);
// start the fileAction to get the image, it will call the method ImageReceived when it is finsihed
new Thread(new Runnable() {
public void run() {
fileAction.getImage(choosenImage);
}
}).start();
}
// this method is used by the FileAction object to send the
// image when it done retrieving it from the filesystem
public void ImageReceived(Image im)
{
if(im==null)
return;
image = im;
showingImage=true;
}
public void fileSavedComplete(String msg){}
// Setting the proprtied we are using in the paint method
private void setProperties()
{
font_medium_Height= medium_Font.getHeight();
font_small_Height= small_Font.getHeight();
font_medium_Width= medium_Font.charWidth('w');
font_small_Width= small_Font.charWidth('w');
System.out.println("font_medium_Height:"+font_medium_Height);
System.out.println("font_small_Height:"+font_small_Height);
text_button_Width=font_medium_Width*4;
visibleTopIndex=0;
visibleBottomIndex_START=(HEIGHT - 4* font_medium_Height)/font_small_Height;
visibleBottomIndex=visibleBottomIndex_START;
currentDir="/";
}
// Loading the program images such as file and the folder images
private void loadProgramImages()
{
try{
folderImage = Image.createImage("/res/folder.PNG");
fileImage = Image.createImage("/res/file.PNG");
downArrowImage = Image.createImage("/res/downArrow.PNG");
upArrowImage = Image.createImage("/res/upArrow.PNG");
}
catch(Exception e){System.out.println("LoadProgramImages:"+e.toString());}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -