?? jtpdefaultmenufactory.java
字號:
package com.sunking.tp.swing;
import java.awt.*;
import javax.swing.*;
import com.sunking.tp.framework.*;
import com.sunking.tp.tool.*;
import com.sunking.tp.util.*;
/**
*
* <p>Title: </p>
* <p>Description: 默認右鍵菜單生成器</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author <a href="mailto:sunkingxie@hotmail.com">SunKing</a>
* @version 1.0
*/
public class JTPDefaultMenuFactory implements JTPMenuFactory {
/**
*單件模式的唯一實例
*/
private static JTPMenuFactory staticInstance;
private JTPDefaultMenuFactory() {}
public static JTPMenuFactory getDefault() {
if (staticInstance == null) {
staticInstance = new JTPDefaultMenuFactory();
}
return staticInstance;
}
public JPopupMenu getPopup(JTPComponent c[]) {
if (c == null || c.length == 0) {
return null;
}
Desktop desk = getDesktop( (Component) c[0]);
JPopupMenu popup = new JPopupMenu();
createDefaultMenuItem(popup, desk);
createSelfMenuItem(popup, desk, c);
return popup;
}
/**
*建立該組件自己的菜單
*/
private void createSelfMenuItem(JPopupMenu popup, Desktop desktopPane, JTPComponent c[]) {
String className = null;
for (int index = 0; index < c.length; index++) {
if (index == 0) {
className = c[0].getClass().getName();
} else {
if (!c[index].getClass().getName().equals(className)) {
return;
}
}
}
if (c[0] instanceof JTPImage) {
AbstractAction changeImageAction = new ToolAction(
desktopPane, new ChangeImageTool(desktopPane, JTPUtil.getImage("image.gif")));
changeImageAction.putValue(Action.NAME, JTPUtil.getString("MENU_CHANGEIMAGE"));
changeImageAction.putValue(Action.MNEMONIC_KEY, new Integer('I'));
popup.addSeparator();
popup.add(changeImageAction);
} else {
AbstractAction changeTextAction = new ToolAction(
desktopPane,
new ChangeTextTool(desktopPane, JTPUtil.getImage("changetext.gif")));
changeTextAction.putValue(Action.NAME, JTPUtil.getString("MENU_CHANGETEXT"));
changeTextAction.putValue(Action.MNEMONIC_KEY, new Integer('T'));
popup.addSeparator();
popup.add(changeTextAction);
}
}
/**
*建立組件通用菜單
*/
private void createDefaultMenuItem(JPopupMenu popup, Desktop desktopPane) {
AbstractAction deleteAction = new ToolAction(
desktopPane,
new DeleteTool(desktopPane, JTPUtil.getImage("delete.gif")));
deleteAction.putValue(Action.NAME, JTPUtil.getString("MENU_DELETE"));
deleteAction.putValue(Action.MNEMONIC_KEY, new Integer('D'));
deleteAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("DEL"));
AbstractAction copyAction = new ToolAction(
desktopPane, new CopyTool(desktopPane, JTPUtil.getImage("copy.gif")));
copyAction.putValue(Action.NAME, JTPUtil.getString("MENU_COPY"));
copyAction.putValue(Action.MNEMONIC_KEY, new Integer('C'));
copyAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl C"));
AbstractAction pasteAction = new ToolAction(
desktopPane,
new PasteTool(desktopPane, JTPUtil.getImage("paste.gif")));
pasteAction.putValue(Action.NAME, JTPUtil.getString("MENU_PASTE"));
pasteAction.putValue(Action.MNEMONIC_KEY, new Integer('P'));
pasteAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl V"));
popup.add(copyAction);
popup.add(pasteAction);
popup.add(deleteAction);
}
Desktop getDesktop(Component c) {
if (c instanceof Desktop)
return (Desktop) c;
c = c.getParent();
if (c == null)
return null;
return getDesktop(c);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -