]]>SWT中的Sytem Tray相关处理http://www.aygfsteel.com/carob/archive/2006/03/19/36076.htmlcarobcarobSun, 19 Mar 2006 08:36:00 GMThttp://www.aygfsteel.com/carob/archive/2006/03/19/36076.htmlhttp://www.aygfsteel.com/carob/comments/36076.htmlhttp://www.aygfsteel.com/carob/archive/2006/03/19/36076.html#Feedback0http://www.aygfsteel.com/carob/comments/commentRss/36076.htmlhttp://www.aygfsteel.com/carob/services/trackbacks/36076.html SWT已经提供了对部分q_Q比如windowQ上的系l托盘的支持。但支持得还不够好,我最q需要在一个聊天工具实现Balloon效果(_附于系l托盘上的一个消息气泡效果,在IM软g中普遍被支持)Q查一下SWT API,到目前ؓ上ƈ没有提供支持。但一个好消息是在月底交要出来?.2M6中,对部分API做调_增加对Balloon的支持?br />
Milestone Plan 3.2 M6 March 31, 2006
Implement custom draw for table and tree Implement native drag source effects for cursor Implement ImageTransfer support Implement Balloon tooltips Implement Accessibility on Mac OS X
//http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet225.java /** *//******************************************************************************* * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.swt.snippets; /**//* * Tooltip example snippet: create a balloon tooltip for a tray item * * For a list of all SWT example snippets see * http://www.eclipse.org/swt/snippets/ * * @since 3.0 */ import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; publicclass Snippet225 { publicstaticvoid main(String[] args) { Display display =new Display(); Shell shell =new Shell(display); Image image =null; final ToolTip tip =new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION); tip.setMessage("Here is message for the user. When the message is too long it wraps. I should say something cool but nothing comes to my mind."); Tray tray = display.getSystemTray(); if (tray !=null) { TrayItem item =new TrayItem(tray, SWT.NONE); image =new Image(display, Snippet225.class.getResourceAsStream("eclipse.png")); item.setImage(image); tip.setText("Notification from a tray item"); item.setToolTip(tip); }else{ tip.setText("Notification from anywhere"); tip.setLocation(400, 400); } Button button =new Button (shell, SWT.PUSH); button.setText("Press for balloon tip"); button.addListener(SWT.Selection, new Listener() { publicvoid handleEvent(Event event) { tip.setVisible(true); } }); button.pack(); shell.setBounds(50, 50, 300, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image !=null) image.dispose(); display.dispose(); } }
]]>如何获取call stack(调用?信息——之?/title>http://www.aygfsteel.com/carob/archive/2005/03/13/2027.htmlcarobcarobSun, 13 Mar 2005 10:25:00 GMThttp://www.aygfsteel.com/carob/archive/2005/03/13/2027.htmlhttp://www.aygfsteel.com/carob/comments/2027.htmlhttp://www.aygfsteel.com/carob/archive/2005/03/13/2027.html#Feedback1http://www.aygfsteel.com/carob/comments/commentRss/2027.htmlhttp://www.aygfsteel.com/carob/services/trackbacks/2027.htmlgetSourceMethodname和方?STRONG>getSourceClassNameQ?我们已经走在正确的道路上了,l箋q查getSourceMethodname()………?BR>
public String getSourceClassName() { if (needToInferCaller) { inferCaller(); } return sourceClassName; }
l箋
// Private method to infer the caller's class and method names privatevoid inferCaller() { needToInferCaller =false; // Get the stack trace. StackTraceElement stack[] = (new Throwable()).getStackTrace(); // First, search back to a method in the Logger class. int ix =0; while (ix < stack.length) { StackTraceElement frame = stack[ix]; String cname = frame.getClassName(); if (cname.equals("java.util.logging.Logger")) { break; } ix++; } ……………?BR>……………?/SPAN>
直至q儿Q我们终于可以松一口气了,因ؓ我们已经扑ֈ了其中的关键
StackTraceElement stack[] = (new Throwable()).getStackTrace();
/**//** * LogRecord objects are used to pass logging requests between * the logging framework and individual log Handlers. * <p> * When a LogRecord is passed into the logging framework it * logically belongs to the framework and should no longer be * used or updated by the client application. * <p> * Note that if the client application has not specified an * explicit source method name and source class name, then the * LogRecord class will infer them automatically when they are * first accessed (due to a call on getSourceMethodName or * getSourceClassName) by analyzing the call stack.
q个LoggingInvocationHandler实现了InvocationHandler接中。方法的代理调用在invoke(…?中,可以如我dlogging()功能一P加入其它的Q何想要的功能Q然后再q行 real target的方法调用?BR> 如果logging(Method method)中的逻辑抽出来,攑ֈ外部文g(XML)中进行配|读取。再Ҏ法名采用正则表达式。是不是更ؓ通用了呢Q?/P>
]]>通过Java Reflection 获取指定static变量的?/title>http://www.aygfsteel.com/carob/archive/2005/03/04/1675.htmlcarobcarobFri, 04 Mar 2005 01:28:00 GMThttp://www.aygfsteel.com/carob/archive/2005/03/04/1675.htmlhttp://www.aygfsteel.com/carob/comments/1675.htmlhttp://www.aygfsteel.com/carob/archive/2005/03/04/1675.html#Feedback0http://www.aygfsteel.com/carob/comments/commentRss/1675.htmlhttp://www.aygfsteel.com/carob/services/trackbacks/1675.htmlelegant
/**//* * Created on 2005-3-3 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package reflection; /**//** * @author ruby * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ publicclass SQLUtil { publicstatic final String SELECT_SQL="from Ruby"; }
/**//* * Created on 2005-3-3 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package reflection; import java.lang.reflect.Field; /**//** * @author ruby * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */ publicclass Manager { publicstatic String getValue(String sqlName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Field f = SQLUtil.class.getField(sqlName); return f.get(null).toString(); } publicstaticvoid main(String[] args) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { System.out.println(getValue("SELECT_SQL")); } }