re: python和ruby的學習【緒】 wanglin 2008-04-29 11:42
一,python的基本理念和哲學:簡單,實用
python的作者心目中最重要的應該是簡單了,所以他設計出的python語言也盡量達成這個目的。他試圖使python寫出來的程序應該是很容易看懂的。
除此以外,可能他還是一個實用主義者,他覺得什么好用就加什么特性,比如oo好用python就oo但不追求極致的純oo;lamda也不排斥只要好用。還有很多特性,不過這個樣子語言就可能變得慢慢的臃腫。所以為了簡單作者山之在3kv中準備重寫核心并犧牲兼容性。
二,ruby的理念和哲學:完美,oo
松本行宏是個oo的粉絲,于是ruby純oo了。這個我有點擔心:當對象數量很多的時候ruby的性能怎么樣?
另外的,ruby語法上我感覺幾乎完美,強大到了極致。孟巖在他的魔幻語言和簡單語言中論述過這樣的優點缺點。我這里再次重復一下,ruby對使用它的人要求非常的高,必須從認識觀上從語言的強大中跳躍出來,從而“以魔幻致簡約”
其實兩種語言我都非常的喜歡。如果在工程中使用,我愿意使用python。但是如果碰到志同道合水平相近的朋友,用ruby無疑是很爽的事情。
re: 工作流、soa以及esb wanglin 2008-04-11 17:22
而為了真正達到服務之間的松耦合。有一個很重要的問題需要解決:業務流程誰發起?還有一個比較次要的問題:開始服務節點和工作流之間的關系互動關系。其他的流程稍微簡單一點。
初始我考慮使用定時器輪訓各個開始節點的服務。考慮到性能原因就放棄了。也許更可行的方案是ESB在應該有一個客戶端去配置監控各個服務節點,并主動向ESB提交服務,同時接受服務回饋。
不存在一種對現有模塊零要求的整合,這也許是最少侵入性的方案了。
re: linux控制臺分辨率 wanglin 2008-02-21 11:51
apt-get install xfce4
apt-get install gcc make build-essential
re: linux控制臺分辨率 wanglin 2008-02-21 10:16
apt-get install apt-spy
apt-spy -d testing -a Asia //在亞洲尋找最快的鏡像
re: linux控制臺分辨率 wanglin 2008-02-21 10:14
裝x
apt-get install x-window-system-core
apt-get install xfce4
re: 一個生成excel的工具類 wanglin 2008-01-28 09:02
有更好的方法
xlsWin = window.open('',''_blank, openPara);
xlsWin.document.write(inStr);
xlsWin.document.close();
xlsWin.document.execCommand('Saveas', true, fileName);
將response流instr放到一個document文件中保存。
翻譯的非常不錯
贊一個
同樣我多swing有興趣,不過因為工作的緣故多數在html/ext/rcp之間周旋,希望在swing上各位同愛多多貢獻。解我之痛。
re: 說說韓寒【轉】 wanglin 2007-11-16 08:58
我高中剛剛畢業那會,聽說的韓寒。拿時候國家出了本作文集給高考的學子們參考,有幸拜讀了韓寒的《書店》這本書,印象非常深刻。
大學之前關注了他很久。很是欣賞。
那時候最驚詫的就是他退學要自學成才什么的,其實我很是不以為然。覺得他雖然很有才華,可是這樣搞下去最終不過董永。....經過很多年.....又關注這個家伙,發現還是如同以前一樣讓我欣賞。
這很不容易。中國的青年作家里面,能讓我欣賞的也就他和余杰了。他們都是很干凈的人。小的時候也就罷了,經歷了這么多還能如此,不由讓人贊嘆。
re: 新的開始。。。。。。 wanglin 2007-09-20 16:19
dao的策略
evan認為一個業務對象應該對應一個dao,沒錯。的確應該這樣。但是業務對象和表是什么關系呢?不好確定,但是大部分是一對一的。。。。。。姑且這樣認為吧。
然后daohibernate和dao也是一對一的,因為前者是后者的實現策略。
今天還談了談遠程調用的懶加載問題。evan說他實現了遠程調用的懶加載,我應該看看怎么實現的。。
re: web客戶端技術展望 wanglin 2007-07-12 12:29
最近一直在忙于rcp的開發,在rcp的學習和使用過程中,發現了很多web開發的好。web開發的結構(html),顯示(css),行為(javascript)分離是非常優雅的,只是以前的開發習慣的慣性使我們不能正確的認識到這一點。
最近除了還是覺得javascript要規范以外,javascript的控件和cs開發的確是有不少的差距,ext已經開始在這方面為我們提供幫助,另外的ajax的粒度也是一個非常需要考慮的問題。
re: swt 日期控件 wanglin 2007-07-12 12:15
引用的工具類:判斷時間
public class StringUtil
{
public static boolean isNotNull(String str)
{
return !isNull(str);
}
public static boolean isNull(String str)
{
return str == null || str.trim().length() == 0;
}
public static boolean isStdDateTime(String dateStr)
{
String reg = "^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\\d):[0-5]?\\d$";
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(dateStr);
return matcher.find();
}
public static boolean isStdDate(String dateStr){
String reg = "^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$";
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(dateStr);
return matcher.find();
}
}
re: swt 日期控件 wanglin 2007-07-12 12:15
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Scrollable;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class CalendarDialog implements MouseListener
{
private SimpleDateFormat stdDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm");
private SimpleDateFormat stdDate = new SimpleDateFormat("yyyy-MM-dd");
private String[][] week =
{
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" },
{ "日", "一", "二", "三", "四", "五", "六" } };
private String[] hours =
{ "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21", "22", "23" };
private String[] mins =
{ "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36",
"37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54",
"55", "56", "57", "58", "59" };
private static Map widgetMap = new HashMap();
private Display display = null;
private Locale locale = Locale.CHINESE;
private Date nowDate = null; // current date
private Calendar now = null;
private Text selectedDate = null; // selected date
private boolean selectTime = false;
private Button hasTime;
private Text time;
private Shell shell = null;
private GridLayout gridLayout = null;
private GridData gridData = null;
private CLabel sunday = null;
private CLabel monday = null;
private CLabel tuesday = null;
private CLabel wednesday = null;
private CLabel thursday = null;
private CLabel friday = null;
private CLabel saturday = null;
private Button yearUp = null;
private Button yearNext = null;
private Button monthUp = null;
private Button monthNext = null;
private CLabel nowLabel = null;
private CLabel[] days = new CLabel[35];
private boolean hasChanged = false;
public CalendarDialog(Locale locale,boolean hasTime)
{
this.locale = locale;
this.selectTime = hasTime;
}
public CalendarDialog(Locale locale)
{
this(locale,false);
}
public CalendarDialog(boolean hasTime)
{
this(Locale.CHINESE,hasTime);
}
public CalendarDialog()
{
this(Locale.CHINESE,false);
}
private int getLastDayOfMonth(int year, int month)
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
return 31;
}
if (month == 4 || month == 6 || month == 9 || month == 11)
{
return 30;
}
if (month == 2)
{
if (isLeapYear(year))
{
return 29;
} else
{
return 28;
}
}
return 0;
}
public boolean isLeapYear(int year)
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
private void moveTo(int type, int value)
{
Calendar now = Calendar.getInstance(); // get current Calendar object
now.setTime(nowDate); // set current date
now.add(type, value); // add to spec time.
nowDate = new Date(now.getTimeInMillis()); // result
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");// format
// date
nowLabel.setText(formatter.format(nowDate)); // set to label
setDayForDisplay(now);
}
private void setDayForDisplay(Calendar now)
{
int currentDay = now.get(Calendar.DATE);
now.add(Calendar.DAY_OF_MONTH, -(now.get(Calendar.DATE) - 1)); //
int startIndex = now.get(Calendar.DAY_OF_WEEK) - 1; //
int year = now.get(Calendar.YEAR); //
int month = now.get(Calendar.MONTH) + 1; //
int hourInt = now.get(Calendar.HOUR_OF_DAY);
int minInt = now.get(Calendar.MINUTE);
int lastDay = this.getLastDayOfMonth(year, month); //
int endIndex = startIndex + lastDay - 1; //
int startday = 1;
for (int i = 0; i < 35; i++)
{
Color temp = days[i].getBackground();
if (temp.equals(display.getSystemColor(SWT.COLOR_BLUE)))
{
days[i].setBackground(display.getSystemColor(SWT.COLOR_WHITE));
}
}
for (int i = 0; i < 35; i++)
{
if (i >= startIndex && i <= endIndex)
{
days[i].setText("" + startday);
if (startday == currentDay)
{
days[i].setBackground(display.getSystemColor(SWT.COLOR_BLUE)); //
}
startday++;
} else
{
days[i].setText("");
}
}
if(StringUtil.isStdDateTime(selectedDate.getText())){
hasTime.setSelection(true);
time.setText(hours[hourInt] + ":" + mins[minInt]);
}else{
hasTime.setSelection(false);
int hi = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int mi = Calendar.getInstance().get(Calendar.MINUTE);
time.setText(hours[hi] + ":" + mins[mi]);
}
}
public void previousYear()
{
moveTo(Calendar.YEAR, -1);
}
public void nextYear()
{
moveTo(Calendar.YEAR, 1);
}
public void nextMonth()
{
moveTo(Calendar.MONTH, 1);
}
public void previousMonth()
{
moveTo(Calendar.MONTH, -1);
}
public void mouseDoubleClick(MouseEvent e)
{
}
public void mouseDown(MouseEvent e)
{
if (widgetMap.get(e.getSource()) != null)
{
return;
}
widgetMap.put(e.getSource(), e.getSource());
selectedDate = (Text) e.getSource();
open(getX(), getY());
hasChanged = true;
}
private int getX()
{
int x = 0;
x += selectedDate.getBounds().x;
Scrollable par;
par = selectedDate.getParent();
while (par instanceof Scrollable && par != null)
{
x += par.getBounds().x;
par = par.getParent();
}
return x;
}
private int getY()
{
int y = 50;
y += selectedDate.getBounds().y;
y += selectedDate.getBounds().height;
Scrollable par;
par = selectedDate.getParent();
while (par instanceof Scrollable && par != null)
{
y += par.getBounds().y;
par = par.getParent();
}
return y;
}
public void mouseUp(MouseEvent e)
{
}
public void dayMouseDown(MouseEvent e)
{
CLabel day = (CLabel) e.getSource();
if (!day.getText().equals("") && !day.getText().equals("×"))
{
if (selectedDate == null)
{
widgetMap.remove(selectedDate);
this.shell.close();
}
this.selectedDate.setText(nowLabel.getText() + "-" + day.getText());
}
if (hasTime.getSelection())
{
isValidaTime("");
if (!day.getText().equals("") && !day.getText().equals("×"))
{
if (selectedDate == null)
{
widgetMap.remove(selectedDate);
this.shell.close();
}
this.selectedDate.setText(nowLabel.getText() + "-" + day.getText() + " " + time.getText());
}
}
widgetMap.remove(selectedDate);
this.shell.close();
hasChanged = true;
}
public void open(int x, int y)
{
display = Display.getDefault();
display.setWarnings(true);
shell = new Shell(display, SWT.ON_TOP);
hasChanged = false;
gridLayout = new GridLayout();
gridLayout.numColumns = 7;
gridLayout.makeColumnsEqualWidth = true;
shell.setLayout(gridLayout);
shell.setBounds(x, y, 210, 220);
gridData = new GridData(GridData.FILL_HORIZONTAL);
yearUp = new Button(shell, SWT.PUSH | SWT.FLAT);
yearUp.setText("<");
yearUp.setLayoutData(gridData);
yearUp.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
previousYear();
}
});
gridData = new GridData(GridData.FILL_HORIZONTAL);
monthUp = new Button(shell, SWT.PUSH | SWT.FLAT);
monthUp.setText("<<");
monthUp.setLayoutData(gridData);
monthUp.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
previousMonth();
}
});
nowLabel = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
nowLabel.setLayoutData(gridData);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
nowLabel.setText(formatter.format(new Date()));
gridData = new GridData(GridData.FILL_HORIZONTAL);
monthNext = new Button(shell, SWT.PUSH | SWT.FLAT);
monthNext.setText(">>");
monthNext.setLayoutData(gridData);
monthNext.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
nextMonth();
}
});
gridData = new GridData(GridData.FILL_HORIZONTAL);
yearNext = new Button(shell, SWT.PUSH | SWT.FLAT);
yearNext.setText(">");
yearNext.setLayoutData(gridData);
yearNext.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
nextYear();
}
});
sunday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
sunday.setLayoutData(gridData);
sunday.setText(getWeekName(0));
monday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
monday.setLayoutData(gridData);
monday.setText(getWeekName(1));
tuesday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
tuesday.setLayoutData(gridData);
tuesday.setText(getWeekName(2));
wednesday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
wednesday.setLayoutData(gridData);
wednesday.setText(getWeekName(3));
thursday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
thursday.setLayoutData(gridData);
thursday.setText(getWeekName(4));
friday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
friday.setLayoutData(gridData);
friday.setText(getWeekName(5));
saturday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
saturday.setLayoutData(gridData);
saturday.setText(getWeekName(6));
for (int i = 0; i < 35; i++)
{
days[i] = new CLabel(shell, SWT.FLAT | SWT.CENTER);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
days[i].setLayoutData(gridData);
days[i].addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
dayMouseDown(e);
}
});
}
hasTime = new Button(shell, SWT.CHECK);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
gridData.horizontalAlignment = GridData.CENTER;
hasTime.setLayoutData(gridData);
hasTime.setSelection(selectTime);
Composite timeCom = new Composite(shell, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
gridData.horizontalSpan = 5;
timeCom.setLayoutData(gridData);
{
GridLayout timeLayout = new GridLayout();
timeLayout.numColumns = 5;
gridLayout.makeColumnsEqualWidth = true;
timeCom.setLayout(timeLayout);
Composite lCom = new Composite(timeCom, SWT.NONE);
timeLayout = new GridLayout();
timeLayout.numColumns = 1;
lCom.setLayout(timeLayout);
{
CLabel hourUp = new CLabel(lCom, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
hourUp.setLayoutData(gridData);
hourUp.setText("∧");
hourUp.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
nextHour();
}
});
CLabel hourDown = new CLabel(lCom, SWT.CENTER | SWT.EMBEDDED);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
hourDown.setLayoutData(gridData);
hourDown.setText("∨");
hourDown.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
preHour();
}
});
}
{
time = new Text(timeCom, SWT.SINGLE | SWT.CENTER | SWT.BORDER);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
time.setLayoutData(gridData);
}
Composite rCom = new Composite(timeCom, SWT.NONE);
timeLayout = new GridLayout();
timeLayout.numColumns = 1;
rCom.setLayout(timeLayout);
{
CLabel minUp = new CLabel(rCom, SWT.FLAT | SWT.CENTER);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
minUp.setLayoutData(gridData);
minUp.setText("∧");
minUp.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
nextMinute();
}
});
CLabel minDown = new CLabel(rCom, SWT.FLAT | SWT.CENTER);
GridData gridData = new GridData();
gridData.horizontalSpan = 3;
minDown.setLayoutData(gridData);
minDown.setText("∨");
minDown.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
preMinute();
}
});
}
}
CLabel cls = new CLabel(shell, SWT.FLAT | SWT.CENTER);
GridData gridData = new GridData();
cls.setLayoutData(gridData);
cls.setText("×");
cls.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
dayMouseDown(e);
}
});
now = getCalendar();
nowDate = new Date(now.getTimeInMillis());
setDayForDisplay(now);
shell.open();
Display display = shell.getDisplay();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
}
public boolean isChanged()
{
return hasChanged;
}
public String getDateText()
{
return selectedDate.toString();
}
private String getWeekName(int weekIndex)
{
if (locale.equals(Locale.CHINESE))
{
return week[1][weekIndex];
} else
{
return week[0][weekIndex];
}
}
private boolean isValidaTime(String time)
{
return true;
}
private void nextHour()
{
int textHour = getHourInText();
int textMinute = getMinuteInText();
if (textHour < 23)
{
time.setText(hours[textHour + 1] + ":" + mins[textMinute]);
} else
{
time.setText(hours[0]+ ":" + mins[textMinute]);
}
}
private void preHour()
{
int textHour = getHourInText();
int textMinute = getMinuteInText();
if (textHour > 0)
{
time.setText(hours[textHour - 1] + ":" + mins[textMinute]);
} else
{
time.setText(hours[23] + ":" + mins[textMinute]);
}
}
private void nextMinute()
{
int textHour = getHourInText();
int textMinute = getMinuteInText();
if (textMinute < 59)
{
time.setText(hours[textHour] + ":" + mins[textMinute + 1]);
} else
{
time.setText(hours[textHour] + ":" + mins[0]);
}
}
private void preMinute()
{
int textHour = getHourInText();
int textMinute = getMinuteInText();
if (textMinute > 0)
{
time.setText(hours[textHour] + ":" + mins[textMinute - 1]);
} else
{
time.setText(hours[textHour] + ":" + mins[59]);
}
}
private int getHourInText()
{
return new Integer(time.getText().split(":")[0]).intValue();
}
private int getMinuteInText()
{
return new Integer(time.getText().split(":")[1]).intValue();
}
private Calendar getCalendar()
{
Date d;
String timeStr = this.selectedDate.getText();
if (timeStr == null || timeStr.equals(""))
{
return Calendar.getInstance();
}
now = Calendar.getInstance();
if (StringUtil.isStdDateTime(timeStr))
{
try
{
d = this.stdDateTime.parse(timeStr);
now.setTime(d);
} catch (ParseException e)
{
e.printStackTrace();
}
}
if (StringUtil.isStdDate(timeStr))
{
try
{
d = this.stdDate.parse(timeStr);
now.setTime(d);
} catch (ParseException e)
{
e.printStackTrace();
}
}
return now;
}
}
re: SWT中的日期選擇控件 wanglin 2007-07-12 12:08
這個是我在你的基礎上改的
public class CalendarDialog implements MouseListener
{
private SimpleDateFormat stdDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm");
private SimpleDateFormat stdDate = new SimpleDateFormat("yyyy-MM-dd");
private String[][] week =
{
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" },
{ "日", "一", "二", "三", "四", "五", "六" } };
private String[] hours =
{ "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21", "22", "23" };
private String[] mins =
{ "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36",
"37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54",
"55", "56", "57", "58", "59" };
private static Map widgetMap = new HashMap();
private Display display = null;
private Locale locale = Locale.CHINESE;
private Date nowDate = null; // current date
private Calendar now = null;
private Text selectedDate = null; // selected date
private boolean selectTime = false;
private Button hasTime;
private Text time;
private Shell shell = null;
private GridLayout gridLayout = null;
private GridData gridData = null;
private CLabel sunday = null;
private CLabel monday = null;
private CLabel tuesday = null;
private CLabel wednesday = null;
private CLabel thursday = null;
private CLabel friday = null;
private CLabel saturday = null;
private Button yearUp = null;
private Button yearNext = null;
private Button monthUp = null;
private Button monthNext = null;
private CLabel nowLabel = null;
private CLabel[] days = new CLabel[35];
private boolean hasChanged = false;
public CalendarDialog(Locale locale,boolean hasTime)
{
this.locale = locale;
this.selectTime = hasTime;
}
public CalendarDialog(Locale locale)
{
this(locale,false);
}
public CalendarDialog(boolean hasTime)
{
this(Locale.CHINESE,hasTime);
}
public CalendarDialog()
{
this(Locale.CHINESE,false);
}
private int getLastDayOfMonth(int year, int month)
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
return 31;
}
if (month == 4 || month == 6 || month == 9 || month == 11)
{
return 30;
}
if (month == 2)
{
if (isLeapYear(year))
{
return 29;
} else
{
return 28;
}
}
return 0;
}
public boolean isLeapYear(int year)
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
private void moveTo(int type, int value)
{
Calendar now = Calendar.getInstance(); // get current Calendar object
now.setTime(nowDate); // set current date
now.add(type, value); // add to spec time.
nowDate = new Date(now.getTimeInMillis()); // result
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");// format
// date
nowLabel.setText(formatter.format(nowDate)); // set to label
setDayForDisplay(now);
}
private void setDayForDisplay(Calendar now)
{
int currentDay = now.get(Calendar.DATE);
now.add(Calendar.DAY_OF_MONTH, -(now.get(Calendar.DATE) - 1)); //
int startIndex = now.get(Calendar.DAY_OF_WEEK) - 1; //
int year = now.get(Calendar.YEAR); //
int month = now.get(Calendar.MONTH) + 1; //
int hourInt = now.get(Calendar.HOUR_OF_DAY);
int minInt = now.get(Calendar.MINUTE);
int lastDay = this.getLastDayOfMonth(year, month); //
int endIndex = startIndex + lastDay - 1; //
int startday = 1;
for (int i = 0; i < 35; i++)
{
Color temp = days[i].getBackground();
if (temp.equals(display.getSystemColor(SWT.COLOR_BLUE)))
{
days[i].setBackground(display.getSystemColor(SWT.COLOR_WHITE));
}
}
for (int i = 0; i < 35; i++)
{
if (i >= startIndex && i <= endIndex)
{
days[i].setText("" + startday);
if (startday == currentDay)
{
days[i].setBackground(display.getSystemColor(SWT.COLOR_BLUE)); //
}
startday++;
} else
{
days[i].setText("");
}
}
if(StringUtil.isStdDateTime(selectedDate.getText())){
hasTime.setSelection(true);
time.setText(hours[hourInt] + ":" + mins[minInt]);
}else{
hasTime.setSelection(false);
int hi = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int mi = Calendar.getInstance().get(Calendar.MINUTE);
time.setText(hours[hi] + ":" + mins[mi]);
}
}
public void previousYear()
{
moveTo(Calendar.YEAR, -1);
}
public void nextYear()
{
moveTo(Calendar.YEAR, 1);
}
public void nextMonth()
{
moveTo(Calendar.MONTH, 1);
}
public void previousMonth()
{
moveTo(Calendar.MONTH, -1);
}
public void mouseDoubleClick(MouseEvent e)
{
}
public void mouseDown(MouseEvent e)
{
if (widgetMap.get(e.getSource()) != null)
{
return;
}
widgetMap.put(e.getSource(), e.getSource());
selectedDate = (Text) e.getSource();
open(getX(), getY());
hasChanged = true;
}
private int getX()
{
int x = 0;
x += selectedDate.getBounds().x;
Scrollable par;
par = selectedDate.getParent();
while (par instanceof Scrollable && par != null)
{
x += par.getBounds().x;
par = par.getParent();
}
return x;
}
private int getY()
{
int y = 50;
y += selectedDate.getBounds().y;
y += selectedDate.getBounds().height;
Scrollable par;
par = selectedDate.getParent();
while (par instanceof Scrollable && par != null)
{
y += par.getBounds().y;
par = par.getParent();
}
return y;
}
public void mouseUp(MouseEvent e)
{
}
public void dayMouseDown(MouseEvent e)
{
CLabel day = (CLabel) e.getSource();
if (!day.getText().equals("") && !day.getText().equals("×"))
{
if (selectedDate == null)
{
widgetMap.remove(selectedDate);
this.shell.close();
}
this.selectedDate.setText(nowLabel.getText() + "-" + day.getText());
}
if (hasTime.getSelection())
{
isValidaTime("");
if (!day.getText().equals("") && !day.getText().equals("×"))
{
if (selectedDate == null)
{
widgetMap.remove(selectedDate);
this.shell.close();
}
this.selectedDate.setText(nowLabel.getText() + "-" + day.getText() + " " + time.getText());
}
}
widgetMap.remove(selectedDate);
this.shell.close();
hasChanged = true;
}
public void open(int x, int y)
{
display = Display.getDefault();
display.setWarnings(true);
shell = new Shell(display, SWT.ON_TOP);
hasChanged = false;
gridLayout = new GridLayout();
gridLayout.numColumns = 7;
gridLayout.makeColumnsEqualWidth = true;
shell.setLayout(gridLayout);
shell.setBounds(x, y, 210, 220);
gridData = new GridData(GridData.FILL_HORIZONTAL);
yearUp = new Button(shell, SWT.PUSH | SWT.FLAT);
yearUp.setText("<");
yearUp.setLayoutData(gridData);
yearUp.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
previousYear();
}
});
gridData = new GridData(GridData.FILL_HORIZONTAL);
monthUp = new Button(shell, SWT.PUSH | SWT.FLAT);
monthUp.setText("<<");
monthUp.setLayoutData(gridData);
monthUp.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
previousMonth();
}
});
nowLabel = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
nowLabel.setLayoutData(gridData);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
nowLabel.setText(formatter.format(new Date()));
gridData = new GridData(GridData.FILL_HORIZONTAL);
monthNext = new Button(shell, SWT.PUSH | SWT.FLAT);
monthNext.setText(">>");
monthNext.setLayoutData(gridData);
monthNext.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
nextMonth();
}
});
gridData = new GridData(GridData.FILL_HORIZONTAL);
yearNext = new Button(shell, SWT.PUSH | SWT.FLAT);
yearNext.setText(">");
yearNext.setLayoutData(gridData);
yearNext.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
nextYear();
}
});
sunday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
sunday.setLayoutData(gridData);
sunday.setText(getWeekName(0));
monday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
monday.setLayoutData(gridData);
monday.setText(getWeekName(1));
tuesday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
tuesday.setLayoutData(gridData);
tuesday.setText(getWeekName(2));
wednesday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
wednesday.setLayoutData(gridData);
wednesday.setText(getWeekName(3));
thursday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
thursday.setLayoutData(gridData);
thursday.setText(getWeekName(4));
friday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
friday.setLayoutData(gridData);
friday.setText(getWeekName(5));
saturday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
saturday.setLayoutData(gridData);
saturday.setText(getWeekName(6));
for (int i = 0; i < 35; i++)
{
days[i] = new CLabel(shell, SWT.FLAT | SWT.CENTER);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
days[i].setLayoutData(gridData);
days[i].addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
dayMouseDown(e);
}
});
}
hasTime = new Button(shell, SWT.CHECK);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
gridData.horizontalAlignment = GridData.CENTER;
hasTime.setLayoutData(gridData);
hasTime.setSelection(selectTime);
Composite timeCom = new Composite(shell, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
gridData.horizontalSpan = 5;
timeCom.setLayoutData(gridData);
{
GridLayout timeLayout = new GridLayout();
timeLayout.numColumns = 5;
gridLayout.makeColumnsEqualWidth = true;
timeCom.setLayout(timeLayout);
Composite lCom = new Composite(timeCom, SWT.NONE);
timeLayout = new GridLayout();
timeLayout.numColumns = 1;
lCom.setLayout(timeLayout);
{
CLabel hourUp = new CLabel(lCom, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
hourUp.setLayoutData(gridData);
hourUp.setText("∧");
hourUp.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
nextHour();
}
});
CLabel hourDown = new CLabel(lCom, SWT.CENTER | SWT.EMBEDDED);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
hourDown.setLayoutData(gridData);
hourDown.setText("∨");
hourDown.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
preHour();
}
});
}
{
time = new Text(timeCom, SWT.SINGLE | SWT.CENTER | SWT.BORDER);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
time.setLayoutData(gridData);
new ControlCheck().setTextTimeCheck1(time);
}
Composite rCom = new Composite(timeCom, SWT.NONE);
timeLayout = new GridLayout();
timeLayout.numColumns = 1;
rCom.setLayout(timeLayout);
{
CLabel minUp = new CLabel(rCom, SWT.FLAT | SWT.CENTER);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
minUp.setLayoutData(gridData);
minUp.setText("∧");
minUp.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
nextMinute();
}
});
CLabel minDown = new CLabel(rCom, SWT.FLAT | SWT.CENTER);
GridData gridData = new GridData();
gridData.horizontalSpan = 3;
minDown.setLayoutData(gridData);
minDown.setText("∨");
minDown.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
preMinute();
}
});
}
}
CLabel cls = new CLabel(shell, SWT.FLAT | SWT.CENTER);
GridData gridData = new GridData();
cls.setLayoutData(gridData);
cls.setText("×");
cls.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
dayMouseDown(e);
}
});
now = getCalendar();
nowDate = new Date(now.getTimeInMillis());
setDayForDisplay(now);
shell.open();
Display display = shell.getDisplay();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
}
public boolean isChanged()
{
return hasChanged;
}
public String getDateText()
{
return selectedDate.toString();
}
private String getWeekName(int weekIndex)
{
if (locale.equals(Locale.CHINESE))
{
return week[1][weekIndex];
} else
{
return week[0][weekIndex];
}
}
private boolean isValidaTime(String time)
{
return true;
}
private void nextHour()
{
int textHour = getHourInText();
int textMinute = getMinuteInText();
if (textHour < 23)
{
time.setText(hours[textHour + 1] + ":" + mins[textMinute]);
} else
{
time.setText(hours[0]+ ":" + mins[textMinute]);
}
}
private void preHour()
{
int textHour = getHourInText();
int textMinute = getMinuteInText();
if (textHour > 0)
{
time.setText(hours[textHour - 1] + ":" + mins[textMinute]);
} else
{
time.setText(hours[23] + ":" + mins[textMinute]);
}
}
private void nextMinute()
{
int textHour = getHourInText();
int textMinute = getMinuteInText();
if (textMinute < 59)
{
time.setText(hours[textHour] + ":" + mins[textMinute + 1]);
} else
{
time.setText(hours[textHour] + ":" + mins[0]);
}
}
private void preMinute()
{
int textHour = getHourInText();
int textMinute = getMinuteInText();
if (textMinute > 0)
{
time.setText(hours[textHour] + ":" + mins[textMinute - 1]);
} else
{
time.setText(hours[textHour] + ":" + mins[59]);
}
}
private int getHourInText()
{
return new Integer(time.getText().split(":")[0]).intValue();
}
private int getMinuteInText()
{
return new Integer(time.getText().split(":")[1]).intValue();
}
private Calendar getCalendar()
{
Date d;
String timeStr = this.selectedDate.getText();
if (timeStr == null || timeStr.equals(""))
{
return Calendar.getInstance();
}
now = Calendar.getInstance();
if (StringUtil.isStdDateTime(timeStr))
{
try
{
d = this.stdDateTime.parse(timeStr);
now.setTime(d);
} catch (ParseException e)
{
e.printStackTrace();
}
}
if (StringUtil.isStdDate(timeStr))
{
try
{
d = this.stdDate.parse(timeStr);
now.setTime(d);
} catch (ParseException e)
{
e.printStackTrace();
}
}
return now;
}
}
re: java異常設計總結 wanglin 2007-06-30 22:16
關于異常的再次總結
1,符合j2ee分層
即異常不跨層,跨層必須封裝
2,性能
如果在同一個方法內捕捉和處理掉異常,性能影響很小。但是如果要到堆棧里面,性能就影響比較大。
所以能處理就處理,不能處理就封裝再throw。如果不適合再次封裝(封裝層次太多也不好)那么就直接throw吧,這種情況要慎重
關于封裝的問題,看異常的分類
從語法上分error和exception,前者不提,后者又分runtimeexceptioin和exception。后者是可以處理的異常.
常常提uncheckexception和checkexception,前者是我們無法處理的,建議轉化成runtimeexception。后者我們處理。
我們處理異常的時候,要注意異常信息的丟失,使用異常鏈。
3,關于異常的new throw.....以及業務邏輯
我是贊成用異常控制邏輯的。
oo編程,僅僅靠返回值表達業務邏輯能力太有限了,如果返回字典符號也不自然。異常框架設計的好,性能的問題是不大的。
re: 看好JSF wanglin 2007-04-30 10:30
謝謝你提供的swing文檔,最近在學習swing。你的兩個文檔我都下了,如果有更多的資料,不要獨享哦:-)
我工作以來一直在從事web開發,這方面的困惑和思考比較多,說出來,偏頗的希望能得到指正,如果僥幸正確,希望能對大家有所啟發。
一起進步。
re: 看好JSF wanglin 2007-04-29 11:03
順便說一下,我認為html標簽才是web開發的組件的王道。jsf不可能比html開發view更快。
所以web開發不要聽到組件開發就興奮——那是在使這個世界更混亂——好好用html,解決html事件處理的問題(js的問題)
我不是在否認tag,誠然,比如邏輯tag、格式化tag還是非常好用的。所以我支持jstl的c和fmt
re: 看好JSF wanglin 2007-04-29 10:52
@azure
如果客戶端技術使用ajax的話,那jsf實現事件的機制是不是雞肋?它帶來了多少好處?(也許你說用java寫代碼比js容易一點,我承認;這個事件機制的分離——服務器jsf響應客戶端ajax處理響應返回,你覺得學習簡單么?
還不如這樣:js處理事件請求,js處理事件反饋。
jsf最大的優點是組件化、可視開發,可是帶來更多的視圖混雜(tag和html混雜在一起),在某種程度上,我很欣賞html的做法,(打個比方有個模塊a)a.html負責展示結構,a.js負責a.html上的所有事件,a.css負責a.html上面所有的展示和風格——這也是xul和xaml的做法,也是flex的做法,毫無疑問,這幾個最新技術的特征意味著將來的趨勢。
之所以web開發覺得不爽是因為js的不規范,js開發的低效率,恐懼的兼容性——它太腳本了,他至少應該像個語言才可以。
這也是j2ee web開發的困境:普通的web開發j2ee絕對沒有問題,可是碰到高交互性,就需要ajax支持才可以;可是js太不規范了。也就帶來開發的低效率。
于是要用一個規范一點的東西來代替ajax的事件響應,于是就用jsf組件。可是jsf組件最終是要在jre里面執行,這意味我們一個事件先發到服務器,然后處理,然后返回,常常的,還需要js幫助處理——他并沒有解決js的簡單問題卻帶來了更多的復雜性。
ps:我這里引用了xaml和flex,是為了說明視圖、處理分離是趨勢。我并不認為xaml和flex會代替web或者什么。。。。。聳人聽聞的吹牛。web有他無可救藥的優點(你只需要提供一個url就可以提供自己的服務,而url是無形的,不需要占用用戶的任何資源)而任何所謂的c/s或者類似的c/s都需要一個圖標(webstart可能好一點)
xaml,rcp適合在特別的群體里使用,受眾比較小,分眾的。
re: web客戶端技術展望 wanglin 2007-04-26 15:08
@大S
問題是要提供強大的展現能力和功能,這樣做只怕不可避免。
ajax為什么這么流行,因為他提高了用戶體驗。他是基于javascript的,但其實javascript也是一種“容器”,之不過他普遍了點。
flash也是一樣,是否你常常發現去一些網站要你先裝flash插件,但是flash還是很受歡迎的。這個插件也是一種容器。
很多qq用戶只怕裝完電腦第一件事情就是裝qq。
所以問題的關鍵是用戶感覺很爽就會裝。
java在服務器端技術已經很成熟很強大了,唯一的制約就在客戶端,客戶端的制約最大的地方就是jre。但是java發明了太多的復雜技術來回避這個簡單問題。而只需要在客戶端裝一個jre,開發就會很簡單,體驗就會很爽。
re: 看好JSF wanglin 2007-04-26 09:51
看好JSF。
但是,作為一個ui組件和事件驅動技術,我有點質疑他處理事件返回值和對html操縱的能力。因為他把事情都方到服務器端了,客戶端有這么強大的能力么?
re: idea 7 wanglin 2007-04-20 08:32
eric是banq現在比較推崇的DDD專家,就好像je那群人比較推崇mf一樣
除了委托加載,ms還有上下文加載。
后者資料甚少,sun官方也沒有提供詳細的介紹,而且雖然現在java技術中已經在使用他,但是還是有問題。。。。。。。。