#
MultiPageEditorPart 的addPage方法
public int addPage(Control control)
{
int i = getPageCount();
addPage(i, control);
return i;
}
public void addPage(int i, IEditorPart ieditorpart, IEditorInput ieditorinput)
throws PartInitException
{
IEditorSite ieditorsite = createSite(ieditorpart);
ieditorpart.init(ieditorsite, ieditorinput);
Composite composite = new Composite(getContainer(), getOrientation(ieditorpart));
composite.setLayout(new FillLayout());
ieditorpart.createPartControl(composite);
ieditorpart.addPropertyListener(new IPropertyListener() {
public void propertyChanged(Object obj, int j)
{
handlePropertyChange(j);
}
}
);
CTabItem ctabitem = createItem(i, composite);
ctabitem.setData(ieditorpart);
nestedEditors.add(ieditorpart);
}
那么有辦法把一個EditorPart 加入Composite再放到Page里面呢?
public void addHtmlPage(IEditorPart ieditorpart, IEditorInput ieditorinput) throws PartInitException {
final SashForm sashForm = new SashForm(getContainer(), SWT.NONE);
final Composite pageContainer = new Composite(sashForm, SWT.NONE);
sashForm.setSashWidth(1);
final Composite resultContainer = new Composite(sashForm, SWT.NONE);
resultContainer.setLayout(new FillLayout());
sashForm.setWeights(new int[] {1, 1 });
createAnalyzePage(resultContainer);
IEditorSite ieditorsite = createSite(ieditorpart);
ieditorpart.init(ieditorsite, ieditorinput);
pageContainer.setLayout(new FillLayout());
ieditorpart.createPartControl(pageContainer);
ieditorpart.addPropertyListener(new IPropertyListener() {
public void propertyChanged(Object obj, int j) {
handlePropertyChange(j);
}
});
int index = addPage(sashForm);
setPageText(index, "html");
}
視乎這樣就可以了,但是問題出現了.缺少了父類 nestedEditors.add(ieditorpart);對editor生命周期的管理.導致屬性編輯器出問題.怎么解決呢?
private CTabFolder container;
private ArrayList nestedEditors;
MultiPageEditorPart 聲明的都是私有的屬性,按照面向對象的設計是不能被繼承者訪問的.
那怎么辦呢?這時候就該使用錘子了."Reflect"
CTabFolder container = (CTabFolder) getParentFileValue(MultiPageEditorPart.class,(MultiPageEditorPart)this, "container");
CTabItem ctabitem = new CTabItem(container, 0, i);
ctabitem.setControl(composite);
ctabitem.setData(ieditorpart);
ArrayList nestedEditors = (ArrayList) getParentFileValue(MultiPageEditorPart.class,(MultiPageEditorPart)this, "nestedEditors");
nestedEditors.add(ieditorpart);
public static Object getParentFileValue(Class parentClassType,Object object, String filedName) {
Field fild = null;
Object fildValue = null;
try {
fild = parentClassType.getDeclaredField(filedName);
fild.setAccessible(true);// 設置安全檢查,訪問私有成員變量必須
fildValue = fild.get(object);
} catch (NoSuchFieldException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
return fildValue;
}
呵呵,問題解決了.
日本程序員: 非常仔細。我認為很主要的一個原因是日本公司的需求非常細致。細致到在網頁上,連一個像素都不能偏差的地步。另外,日本人的執行力非常強,對老板的承諾比
命還重要。一個項目可以做到連續3個月天天加班,每天只睡4個小時。然而,高執行力背后的代價是低創造力。在日新月異的互聯網今天,很少聽說日本工程師發
明了哪些重要的技術。善于做領導想做的事.
印度程序員: 流程做得好,文檔寫得好。但是他們寫代碼的能力,我個人的觀點是一般般。我想這里面有兩層原因。一是有相當一部分在美國工作的印度程序員是半路出家。轉行
做程序員是為了生存而已。二是印度程序員在算法,數據機構等基本功方面的水平明顯低于中國程序員的。這就導致他們寫的很多代碼邏輯性不強和性能不優(以我
的標準來看)。不過這兩個問題在一定程度上被大量的文檔和高性能的硬件設備彌補和掩蓋了。善于說領導想聽的話.
美國程序員: 美國程序員千奇百怪,好像很難只用幾個詞來定義他們。喜歡技術,甚至崇尚技術。這點在硅谷尤為突出。這就導致每個技術領域中都有一些人會廢寢忘食地鉆研。其實這和打游戲一樣,如果你著了迷,自然會忘了吃,忘了喝,拼命地玩。我所認識的美國程序員還有一個特點,才藝能力都不錯。這會讓老板有時候很頭疼,因為程序員不那么“聽話”。他們不是給老板交差,而是要實現自己的想法,自己的設計,自己的完美。說白了,就是美國程序員有時候想法多了點。
中國的程序員: 比較注重理論知識。反過來,實踐能力就相對差些。我們的程序員執行能力并不差,但在解決問題的能力上明顯不足。往往需要把任務分解得很細以后才能完成,獨立解決問題的能力不夠。另外在表達能力上也相對差些。比較浮躁和急功近利。真正能夠沉下心來鉆研技術,熱愛技術的是鳳毛麟角。我在面試的時候,常常發現工程師知識面還挺廣,但深度幾乎沒有。這樣的人很難在技術領域有所作為。
在技術管理上,很多國內的公司把工程師簡單地作為資源,過于強調流程管理和資源管理。我的觀點是:工程師不是高級藍領,不能以管理生產線的方式來進行管理。優良的環境只有靠大家一起來創造。
對于程序員來講,也不要過分的去區分彼此的不同,天道酬勤,一份耕耘一份收獲.不論是做開發,還是做管理工作.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.graphics.codec.PNGEncoder;
import mx.graphics.codec.JPEGEncoder;
import mx.utils.Base64Encoder;
private var encoder:Base64Encoder;
private var encodeTarget:ByteArray;
private function loadImage():void
{
indentityImg.load(imageSrc.text);
}
private function encodeImage():void
{
var bmp:Bitmap = indentityImg.content as Bitmap;
var bmpData:BitmapData = bmp.bitmapData;
switch("jpg"){
case "bmp":
encodeTarget = bmpData.getPixels(bmpData.rect);
break;
case "jpg":
var jpg:JPEGEncoder = new JPEGEncoder(100);
encodeTarget = jpg.encode(bmpData);
break;
case "png":
var png:PNGEncoder = new PNGEncoder();
encodeTarget = png.encode(bmpData);
break;
}
encodeTarget.position = 0;
encoder = new Base64Encoder();
encoder.insertNewLines = false;
encoder.reset();
encoder.encodeBytes(encodeTarget,0,encodeTarget.length);
resultTxt.text = encoder.flush();
}
]]>
</mx:Script>
<mx:Image id="indentityImg" x="10" y="64" width="187" height="112" source="image2.jpg"/>
<mx:Button x="458" y="5" label="fetch" click="loadImage()"/>
<mx:Button x="260" y="169" label="encode" click="encodeImage()"/>
<mx:TextArea x="10" y="210" width="317" height="158" id="resultTxt" wordWrap="true" editable="false"/>
<mx:Label x="10" y="184" text="result" width="115"/>
<mx:TextInput id="imageSrc" x="10" y="5" width="425" editable="true">
<mx:text>http://avatar.profile.csdn.net/7/B/4/1_remote_roamer.jpg</mx:text>
</mx:TextInput>
</mx:Application>
System.loadLibary()
The parameter to System.loadLibrary() should be the name of the libary, without path, extension or "lib":
1: System.loadLibrary("payment");
Depending on your platform, this will load libpayment.so or payment.dll.
Although it is not an error to call System.loadLibrary() multiple times, loading the libraries is often done in a static code block:
1: class Test {
2: static {
3: System.loadLibrary("payment");
4: }
5: }
java.library.path
Java searches several directories for this libary file. The directories
to search are specified in the property java.library.path. On Linux,
this is a copy of the environment variable LD_LIBRARY_PATH. On Windows, it is a copy of the PATH variable.
Although changing the java.library.path has influence on how Java loads
its libraries, it has no effect on Windows. When your library depends
on other DLLs, these are loaded without taking java.library.path into
account. If the library you load needs another library, which can not
be found, you get an UnsatisfiedLinkError with the message "".
To solve this, you can load the dependant libraries yourself using
multiple calls to System.loadLibrary(), loading all libaries one by
one.
就是說假如你要加載的Dll依賴其它dll那你就要自己手工加載在Windows平臺。
util.js工具包包含了一些實用函數來幫助你用javascript操作從服務器返回的數據數據,以便來更新web頁面。 也可以在DWR以外使用它,因為它不依賴于DWR的其他部分。下面介紹這個工具的主要函數。
7.13.1 $()函數
$()
函數實現的功能相當于 document.getElementById方法。 因為在Ajax程序中,經常需要寫很多這樣的語句,所以使用 $()
會更簡潔。它通過指定的id來查找當前HTML文檔中的元素,如果傳遞給它多個參數,它會返回找到的元素的數組。所有非String類型的參數會被原封不
動的返回。這個函數的靈感來至于prototype庫,但是它可以在更多的瀏覽器上運行。
$() 函數的使用方法為:
var searchexp = $("searchbox").value
<!—對應HTML表單的ID-->
<input id="searchbox"/>
7.12.2 addOptions與 removeAllOptions函數
在DWR項目應用中,經常需要根據所選項來填充選擇列表。這現這種功能可能通過調用addOptions與 removeAllOptions函數來填充或移除列表。例如,如果希望在更新了select以后,它仍然保持更新前的選擇項,實現方法如下:
var sel = dwr.util.getValue(id);
dwr.util.removeAllOptions(id);
Array array = new Array[ 'Africa', 'America', 'Asia', 'Australasia', 'Europe' ];
dwr.util.addOptions("id ",array);
dwr.util.setValue(id, sel);
如果想加入一個初始的"請選擇..." 選項,那么可以直接加入下面的語句:
dwr.util.addOptions(id, \["請選擇 ..."]);
dwr.util.addOptions有5種模式,分別為:
? 數組模式:dwr.util.addOptions(selectid, array) 會創建多個option,每個option的文字和值都是數組元素中的值。
? 對象數組模式:(指定text): dwr.util.addOptions(selectid, data, prop) 用數組中的每個元素創造一個option,option的值和文字都是在prop中指定的對象的屬性。例如:
dwr.util.addOptions( "demo",
[{ name:'Africa', id:'AF' },
{ name:'America', id:'AM' },
{ name:'Asia', id:'AS' },
{ name:'Australasia', id:'AU' },
{ name:'Europe', id:'EU' } ],'id','name');
?
對象數組模式: (指定text和value值): dwr.util.addOptions(selectid, array,
valueprop, textprop)
用數組中的每個元素創造一個option,option的值是對象的valueprop屬性,option的文字是對象的textprop屬性。
這種情況下,你需要指定要顯示 beans 的 property 以及 對應的 bean 值,例如:
public class Person {
private String name;
private Integer id;
public void set(){……}
public String get(){……}
}
dwr.util.addOptions("demo",array,'id','name');
其中id指向及bean的id屬性,在optiong中對應value,name指向bean的name屬性,對應下拉框中顯示的哪個值。
?
對象模式: dwr.util.addOptions(selectid, map,
reverse)用每個屬性創建一個option。對象的屬性名用來作為option的值,對象的屬性值用來作為屬性的文字,如果reverse參數被設
置為true,那么對象的屬性值用來作為選項的值。
? 對象的Map模式:dwr.util.addOptions(selectid,
map, valueprop, textprop)
用map中的每一個對象創建一個option。用對象的valueprop屬性做為option的value,用對象的textprop屬性做為
option的文字。
? ol 或 ul 列表模式:dwr.util.addOptions(ulid, array) 用數組中的元素創建多個li元素,它們的innerHTML是數組元素中的值。這種模式可以用來創建ul和ol列表。
7.13.3 addRows與 removeAllRows函數
在
DWR應用中,通過addRows與
removeAllRows這兩個函數來操作table表格,這個函數的第一個參數都是table、tbody、thead、tfoot的id。一般來說
最好使用tbody,因為這樣可以保持header和footer行不變。它們的用法如下:
? dwr.util.removeAllRows()
dwr.util.removeAllRows(id);
通過table元素的id刪除table中所有行。
如果要刪除表格中的某一行,則可用如下方法:
function deleteRows(id)
{
var tbody=document.getElementById("tb1");// tbody 的id
var trow=document.getElementById(id);//要刪除的行號
if(confirm("確定刪除?"))
{
tbody.removeChild(trow);
}
}
? dwr.util.addRows()
dwr.util.addRows(id, array, cellfuncs, [options]);
這行語句向指定id的table元素添加行。它使用數組中的每一個元素在table中創建一行。然后用cellfuncs從傳遞過來的行數據中提取單元格數據。其中參數:
? id: table元素的id(最好是tbody元素的id)
? array:數組或對象,做為更新表格數據。
? cellfuncs: 函數數組,從傳遞過來的行數據中提取單元格數據。
?
options: 一個包含選項的對象,選項包括一個用來創建行的函數rowCreator(例如希望給tr加上css),
默認值是返回一個document.createElement("tr")。一個用來創建單元格的函數cellCreator(例如用th代替td)。
默認返回一個document.createElement("td")。下面就是一個向table元素添加行的應用例子,代碼如下:
var cellFuncs = [
function(data) { return data; },
function(data) { return data.toUpperCase(); },
function(data) {
return "<input type='button' value='提交' onclick='alert(\"測試\");'/>";
},
function(data) { return count++; }
];
var count = 1;
dwr.util.addRows( "t1", , cellFuncs, { escapeHtml:false });
<!—對應的HTML內容-->
<table border="1" width="110%" id="table17" name="table17" height="27">
<tbody id="t1" name="t1">
</tbody>
</table>
7.13.4 getText函數
getText(id)和getValue(id)相似。用它可以得到select列表項目的顯示的文本,而不是當前選項的值。
7.13.5 getValue函數
dwr.util.getValue(id)
可以從HTML元素中取出其中的值,這個函數能操作大多數HTML元素,其中包括select(去處當前選項的值而不是文字)、input元素(包括
textarea)、div和span。下面就是一個getValue函數的應用例子,實現代碼如下:
<html>
<head>
<title></title>
<script type="text/javascript" src="dwr/util.js"></script>
<script type="text/javascript" src="dwr/engine.js"></script>
<script>
function getValue()
{
var cnId = dwr.util.getValue("myId");
var cnValue = dwr.util.getValue("myValue");
alert(dwr.util.getValue("myId"));
}
</script>
</head>
<body>
<input type="text" value="" id="myId" />,
<input type="text" value="" id="myValue" />
<input type="button" value="setValue" onclick="getValue();" />
</body>
</html>
7.13.6 getValues函數
getValues()
得到的是包含name/value對的javascript對象。name是HTML元素的ID,value會被更改為這些ID對象元素的內容。
getValues()可以傳入一個HTML元素(一個DOM對象或者id字符串)象。這個函數不會返回對象,它只更改傳遞給它的值。下面就是一個
getValues函數的應用例子,實現代碼如下:
var person = { id:1, name:'tfnew21', address:'北京', salary:10000 };
dwr.util.getValues(person);
alert(person.name); //訪問person對象的屬于,運行后會在窗口中顯示’tfnew21’字符串
dwr.util.getValues({textarea:null,select:null,text:null,password:null,button:null})
alert(textarea.value);// 執行后textarea.value的值為"test"
//HTML中的代碼
<input type="textarea" id="textarea" value="test" />
<input type="text" id="text" value="tfnew21" />
<input type="password" id="password" value="12345" />
<select id="select">
<option value="1" select>
香蕉
</option>
</select>
7.13.7 onReturn函數
定
義在輸入框中按回車的響應,防止執行submit。當使用Ajax時,往往需要的觸發一些Javscript。
不幸的是不同的瀏覽器處理這個事件的方式不一樣。所以dwr.util.onReturn修復了這個差異。如果需要在一個表單元素中按回車時觸發一些
Javscript,實現代碼如下:
<input type="text" onkeypress="dwr.util.onReturn(event,submitFunction)"/>
<input type="button" onclick="submitFunction()"/>
這個函數的工作原理與onSubmit()事件相似,只能存在于<FORM >元素中。
7.13.8 selectRange函數
selectRange用于選擇一個輸入框中的一定范圍的文字。 調用方法如下:
dwr.util.selectRange(ele, start, end)//ele輸入ID,start開始位置,end結尾位置
例如:<input type="text" id="sel-test" value="0123456">
dwr.util.selectRange("sel-test", 2, 5);
7.13.9 setValue函數
dwr.util.setValue(id,
value)根據第一個參數中指定的id找到相應元素,并根據第二個參數改變其中的值。
這個函數能操作大多數HTML元素,包括select、input元素(包括textarea)、div和span。例如:下面就是一個getValue
函數的應用例子,實現代碼如下:
<html>
<head>
<title></title>
<script type="text/javascript" src="dwr/util.js"></script>
<script type="text/javascript" src="dwr/engine.js"></script>
<script>
function setValue()
{
var cnId = dwr.util.getValue("myId");
var cnValue = dwr.util.getValue("myValue");
dwr.util.setValue(cnId, cnValue);
alert(dwr.util.getValue("myId"));
}
</script>
</head>
<body>
dwr.util.setValue(
<input type="text" value="" id="myId" />,
<input type="text" value="" id="myValue" />
)
<input type="button" value="setValue" onclick="setValue();" />
</body>
</html>
7.13.10 setValues函數
setValues()
和setValue()非常相似,但它傳入的參數是一個擁有多個屬性的javascript
object,屬性名稱是html頁面元素的id,屬性value為html頁面元素的value。下面就是一個setValues函數的應用例子,實現
代碼如下:
<html>
<head>
<title></title>
<script type="text/javascript" src="dwr/util.js"></script>
<script type="text/javascript" src="dwr/engine.js"></script>
<script>
function setValue()
{
var cnId = {myAreaText:"tfnew21",myDiv:"ddr"};
dwr.util.setValues(cnId);
}
</script>
</head>
<body>
<input type="button" value="setValue" onclick="setValue();" />
<br />
id=myAreaText
<textarea id="myAreaText" value=""></textarea>
<br />
id=myDiv
<div id="myDiv"></div>
</body>
</html>
7.13.11 toDescriptiveString函數
toDescriptiveString函數是帶debug信息的toString,第一個為將要debug的對象,第二個參數為處理等級。等級如下:
0:單行調試
1:不分析子元素的多行調試
2: 最多分析到第二層子元素的多行調試
調用方法如下:
<input type="text" id="text">
dwr.util.toDescriptiveString("text",0);
7.13.12 useLoadingMessage函數
useLoadingMessage函數作用是當發出ajax請求后,頁面顯示的提示等待信息,調用方法如下:
function searchUser(){
var loadinfo = "loading....."
try{
regUser.queryAllUser(userList);
dwr.util.useLoadingMessage(loadinfo);
}catch(e){
}
}
以上介紹了DWR的工用原理就實現方法,同時介紹了兩個工具包的常用函數的用法,有關DWR的在項目中的具體應用,將在后面的在線書店電子商務系統中詳細介紹,本節不在介紹。
String strResource = ((IResource)o).getLocation().makeAbsolute().toFile().getAbsolutePath();
這樣才能獲取到磁盤路徑
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class RobotUtil {
/**
* path 不支持漢字
* @param robot
* @param line
*/
public static void printString(Robot robot, String line) {
char[] keys = line.toUpperCase().toCharArray();
for (char c : keys) {
pressKey(robot, c);
}
}
public static void pressKey(Robot robot, char c) {
if (c == ':') {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else {
int k = (int) c;
robot.keyPress(k);
robot.keyRelease(k);
}
}
/**
* @param args
*/
public static void main(String[] args) {
try {
String path = "c:/temp/form/a.html";
Robot robot;
robot = new Robot();
robot.delay(1000);
printString(robot, path);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
Eclipse Plugin]ResourceBundle Editor(國際化資源文件編輯器
http://sourceforge.net/projects/eclipse-rbe
1.JNorm 能夠幫助你分析代碼中那些可以使用開源的項目代替。
http://www.jnorm.org/
2.NWire 分析類之間的繼承關系
http://www.nwiresoftware.com
3.FindBugs 找到bug
http://findbugs.sourceforge.net
public static void setProxy(String ip,int port) throws RegistryErrorException{
Regor reg = new Regor();
Key ie = reg.openKey(Regor.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
if(ie!=null){
reg.setValue(ie, "ProxyServer", ip+":"+port);
reg.saveDword(ie, "ProxyEnable", Integer.toHexString(1));
}
}
public static void disableProxy() throws RegistryErrorException{
Regor reg = new Regor();
Key ie = reg.openKey(Regor.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
if(ie!=null){
reg.saveDword(ie, "ProxyEnable", Integer.toHexString(0));
reg.setValue(ie, "ProxyServer", "");
}
}
|