📄 dsextendjpopupmenu.java
字号:
package drawsmart.itsv.swing;
import javax.swing.JPopupMenu;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JMenuItem;
import drawsmart.itsv.framework.*;
import javax.swing.JOptionPane;
import drawsmart.itsv.framework.JDSDesktopface;
import java.awt.Font;
import javax.swing.ImageIcon;
import drawsmart.itsv.tool.GetResource;
import javax.swing.*;
import java.awt.*;
import drawsmart.itsv.framework.JDSSelectActionface;
import drawsmart.itsv.framework.JDSSetupDataModelface;
/**
* <p>Title: 组件的右键菜单</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class DSExtendJPopupMenu extends JPopupMenu
implements ActionListener {
private JMenuItem textname,copyItem,delItem,setupItem;
private JDSComponentface jDSComponentface;
private JDSDesktopface jDSDesktopface;
private Font myFont=new Font("宋体",12,12);
private JDSSelectActionface jDSSelectActionface;
private JDSSetupDataModelface jDSSetupDataModelface;
public DSExtendJPopupMenu(JDSSelectActionface jDSSelectActionface,JDSSetupDataModelface jDSSetupDataModelface)
{
this(null,null,jDSSelectActionface,jDSSetupDataModelface);
}
public DSExtendJPopupMenu(JDSComponentface jDSComponentface,JDSDesktopface jDSDesktopface,JDSSelectActionface jDSSelectActionface,JDSSetupDataModelface jDSSetupDataModelface) {
this.jDSComponentface=jDSComponentface;
this.jDSDesktopface=jDSDesktopface;
this.jDSSelectActionface=jDSSelectActionface;
this.jDSSetupDataModelface=jDSSetupDataModelface;
textname=new JMenuItem("设置名字");
textname.setFont(myFont);
//ImageIcon nameicon=new ImageIcon(getClass().getResource("/images/savedrw.gif"));
ImageIcon nameicon=GetResource.getImage("changetext.gif");
textname.setIcon(nameicon);
copyItem=new JMenuItem("复制到这里");
copyItem.setFont(myFont);
//ImageIcon copyicon=new ImageIcon(getClass().getResource("/images/savedrw.gif"));
ImageIcon copyicon=GetResource.getImage("copy.gif");
copyItem.setIcon(copyicon);
delItem=new JMenuItem("删除该组件");
delItem.setFont(myFont);
//ImageIcon delicon=new ImageIcon(getClass().getResource("/images/savedrw.gif"));
ImageIcon delicon=GetResource.getImage("delete.gif");
delItem.setIcon(delicon);
setupItem=new JMenuItem("配置该环节");
setupItem.setFont(myFont);
//ImageIcon setupicon=new ImageIcon(getClass().getResource("/images/savedrw.gif"));
ImageIcon setupicon=GetResource.getImage("changetext.gif");
setupItem.setIcon(setupicon);
//添加组件和事件
add(copyItem);
copyItem.addActionListener(this);
add(delItem);
delItem.addActionListener(this);
//设置分割符
this.addSeparator();
add(textname);
textname.addActionListener(this);
add(setupItem);
setupItem.addActionListener(this);
copyItem.setAccelerator(KeyStroke.getKeyStroke('C',Event.CTRL_MASK ));
//delItem.setAccelerator(KeyStroke.getKeyStroke('D'));
}
public void setFace(JDSComponentface jDSComponentface,JDSDesktopface jDSDesktopface)
{
this.jDSComponentface=jDSComponentface;
this.jDSDesktopface=jDSDesktopface;
}
/**
* Invoked when an action occurs.
*
* @param e ActionEvent
* @todo Implement this java.awt.event.ActionListener method
*/
public void actionPerformed(ActionEvent e) {
if(e.getSource()==textname)
{
String str1=jDSComponentface.getTextInfo();
str1=JOptionPane.showInputDialog(null,"输入该组件的名字",str1);
if(str1==null) return;
jDSComponentface.setTextInfo(str1);
jDSDesktopface.repaint();
}
else if(e.getSource()==copyItem)
{
JDSComponentface jDSComponentfaceClone=(JDSComponentface)jDSComponentface.cloneComponent();
jDSComponentfaceClone.setPlaceComponent(30,30);
jDSDesktopface.addJDSComponent(jDSComponentfaceClone);
jDSDesktopface.repaint();
}
else if(e.getSource()==delItem)
{
//获得所选的组件
JDSComponentface[] jDSComponentfaceAll = jDSDesktopface.
getSelectComponentface();
if (jDSComponentfaceAll == null || jDSComponentfaceAll.length <= 0)return;
jDSSelectActionface.delSelectComponent(jDSComponentfaceAll,jDSDesktopface);
}
else if(e.getSource()==setupItem)
{
DSSetupDataPanel dSSetupDataPanel=new DSSetupDataPanel(jDSSetupDataModelface,jDSComponentface.getComponentID());
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = dSSetupDataPanel.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
dSSetupDataPanel.setLocation( (screenSize.width -
frameSize.width) / 2,
(screenSize.height -
frameSize.height) / 2);
dSSetupDataPanel.setVisible(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -