/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.myorg.MyViewer;
import java.io.Serializable;
import java.util.Collection;
import java.util.logging.Logger;
import org.myorg.myapi.APIObject;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import org.openide.util.Utilities;
/**
* Top component which displays something.
*/
final class MyViewerTopComponent extends TopComponent implements LookupListener {
private static MyViewerTopComponent instance;
/** path to the icon used by the component and its open action */
static final String ICON_PATH = "org/myorg/MyViewer/HaoSc32_1320_200525152611580.gif";
private static final String PREFERRED_ID = "MyViewerTopComponent";
private Lookup.Result result = null;
private MyViewerTopComponent() {
initComponents();
setName(NbBundle.getMessage(MyViewerTopComponent.class, "CTL_MyViewerTopComponent"));
setToolTipText(NbBundle.getMessage(MyViewerTopComponent.class, "HINT_MyViewerTopComponent"));
setIcon(Utilities.loadImage(ICON_PATH, true));
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(MyViewerTopComponent.class, "MyViewerTopComponent.jLabel1.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(MyViewerTopComponent.class, "MyViewerTopComponent.jLabel2.text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(110, 110, 110)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(104, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(67, 67, 67)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addContainerGap(179, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
// End of variables declaration//GEN-END:variables
/**
* Gets default instance. Do not use directly: reserved for *.settings files only,
* i.e. deserialization routines; otherwise you could get a non-deserialized instance.
* To obtain the singleton instance, use {@link #findInstance}.
*/
public static synchronized MyViewerTopComponent getDefault() {
if (instance == null) {
instance = new MyViewerTopComponent();
}
return instance;
}
/**
* Obtain the MyViewerTopComponent instance. Never call {@link #getDefault} directly!
*/
public static synchronized MyViewerTopComponent findInstance() {
TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
if (win == null) {
Logger.getLogger(MyViewerTopComponent.class.getName()).warning(
"Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
return getDefault();
}
if (win instanceof MyViewerTopComponent) {
return (MyViewerTopComponent) win;
}
Logger.getLogger(MyViewerTopComponent.class.getName()).warning(
"There seem to be multiple components with the '" + PREFERRED_ID +
"' ID. That is a potential source of errors and unexpected behavior.");
return getDefault();
}
@Override
public int getPersistenceType() {
return TopComponent.PERSISTENCE_ALWAYS;
}
/**
* componentOpened() is called whenever the component is made visible by the window system;
*/
@Override
public void componentOpened() {
Lookup.Template tpl = new Lookup.Template(APIObject.class);
result = Utilities.actionsGlobalContext().lookup(tpl);
result.addLookupListener(this);
}
@Override
public void componentClosed() {
result.removeLookupListener(this);
result = null;
}
/** replaces this in object stream */
@Override
public Object writeReplace() {
return new ResolvableHelper();
}
@Override
protected String preferredID() {
return PREFERRED_ID;
}
/**
* The resultChanged() method is your implementation of LookupListener.
* Whenever the selected APIObject changes, it will update the two JLabels you put on the form.
* @param arg0
*/
public void resultChanged(LookupEvent arg0) {
Lookup.Result r = (Lookup.Result) arg0.getSource();
Collection c = r.allInstances();
if (!c.isEmpty()) {
APIObject o = (APIObject) c.iterator().next();
jLabel1.setText(Integer.toString(o.getIndex()));
jLabel2.setText(o.getDate().toString());
} else {
jLabel1.setText("[no selection]");
jLabel2.setText("");
}
//throw new UnsupportedOperationException("Not supported yet.");
}
final static class ResolvableHelper implements Serializable {
private static final long serialVersionUID = 1L;
public Object readResolve() {
return MyViewerTopComponent.getDefault();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Using a TopComponent's Lookup (489个子文件)
messages.log.1 53KB
uigestures.1 46KB
1233565770187 384B
1233565775468 326B
messages.log.2 54KB
MyViewerTopComponent.class 6KB
MyEditor.class 4KB
APIObject.class 1008B
MyEditor$1.class 810B
MyViewerTopComponent$ResolvableHelper.class 710B
OpenEditorAction.class 670B
comment 0B
netbeans.conf 66B
data 153B
data 129B
MyEditor.form 5KB
MyViewerTopComponent.form 3KB
HaoSc32_1320_200525152611580.gif 1KB
HaoSc32_1320_200525152611580.gif 1KB
imported 0B
instance 0B
instance 0B
instance_1 0B
instance_2 0B
org-openide-util.jar 299KB
org-openide-awt.jar 137KB
org-jdesktop-layout.jar 57KB
org-openide-windows.jar 51KB
org-myorg-MyViewer.jar 13KB
org-myorg-myMyEditor.jar 9KB
org-myorg-myapi.jar 2KB
org-myorg-myapi.jar 703B
MyViewerTopComponent.java 7KB
MyEditor.java 5KB
APIObject.java 553B
OpenEditorAction.java 424B
.lastModified 0B
.lastModified 0B
messages.log 53KB
metrics 132KB
manifest.mf 234B
manifest.mf 228B
manifest.mf 170B
platform NetBeans Selection Management Tutorial for NetBeans Platform 6_0.mht 431KB
.nbattrs 3KB
.nbattrs 3KB
.nbattrs 1KB
org-myorg-MyViewer.nbm 7KB
org-myorg-myMyEditor.nbm 5KB
org-myorg-myapi.nbm 3KB
build.properties 29KB
customDefs.properties 10KB
projectui.properties 6KB
org-netbeans-modules-debugger-Settings.properties 6KB
RecentFilesHistory.properties 5KB
libraries-timestamps.properties 3KB
formdesignerpalette.properties 3KB
jsppalette.properties 1KB
indexing.properties 995B
autoupdate.properties 559B
welcome.properties 466B
genfiles.properties 455B
genfiles.properties 455B
genfiles.properties 455B
genfiles.properties 455B
Filters.properties 454B
URL_ThirdParty.properties 396B
Bundle.properties 386B
Bundle.properties 386B
URL_Standard.properties 354B
URL_Beta.properties 350B
Bundle.properties 286B
Bundle.properties 286B
URL_PluginPortal.properties 245B
project.properties 226B
ui.properties 194B
UPDATE.properties 149B
derby.properties 146B
common.properties 128B
uihandler.properties 124B
j2seproject.properties 111B
navigation.properties 111B
ui.properties 98B
platform-private.properties 87B
ant.properties 86B
dataconnectivity.properties 74B
explorer.properties 70B
api.properties 68B
java.properties 64B
project.properties 62B
project.properties 60B
project.properties 60B
project.properties 60B
mysql.properties 54B
org.netbeans.modules.java.project.share.properties 51B
appsrv81.properties 47B
common.properties 47B
platform.properties 47B
standard-update-provider.properties 44B
beta-update-provider.properties 44B
共 489 条
- 1
- 2
- 3
- 4
- 5
资源评论
- xuni12014-09-24还可以,对我有一定的启发
lycgxy
- 粉丝: 14
- 资源: 33
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功