我的评论

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技术中已经在使用他,但是还是有问题。。。。。。。。

<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(1)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜