?? abstractcomponentadapter.java
字號:
}
}
return set;
}
public void paintComponentMascot(Graphics g) {
component.paint(g);
}
public Dimension getInitialSize() {
Dimension dim = INITIAL_SIZE.get(component.getClass());
if (dim == null) {
return component.getPreferredSize();
} else {
return dim;
}
}
protected void initSubMenu(JMenu menu, Action[] actions, Component current) {
for (Action action : actions) {
if (action == null) {
menu.addSeparator();
} else {
if (action instanceof AbstractContextAction) {
((AbstractContextAction) action).setComponent(current);
}
if (action instanceof ActionCategory) {
Action[] subactions = ((ActionCategory) action).getSubActions();
if (subactions == null) {
menu.add(action);
} else {
JMenu menuItem = new JMenu(action);
initSubMenu(menuItem, subactions, current);
menu.add(menuItem);
}
} else {
menu.add(action);
}
}
}
}
public JPopupMenu getContextPopupMenu(MouseEvent e) {
JPopupMenu popupMenu = new JPopupMenu();
if(setLnfAction == null){
setLnfAction = new SetLnfAction(designer);
}
JMenu lnfmenu=new JMenu(setLnfAction);
Action[]subactions = setLnfAction.getSubActions();
for(Action action : subactions){
lnfmenu.add(action);
}
popupMenu.add(lnfmenu);
if (changeVarNameAction == null) {
changeVarNameAction = new ChangeVarName(designer);
}
changeVarNameAction.setEnabled(!Util.isRootComponent(component));
changeVarNameAction.setComponent(component);
if(invokeEditorAction==null){
invokeEditorAction = new InvokeEditorAction(designer);
}
invokeEditorAction.setComponent(component);
invokeEditorAction.setEnabled(this.getDesignerEditor(e.getX(), e.getY())!=null);
invokeEditorAction.setMouseEvent(e);
popupMenu.add(changeVarNameAction);
popupMenu.add(invokeEditorAction);
Action[]actions = designer.getActions();
initContextMenu(actions, popupMenu);
return popupMenu;
}
private SetLnfAction setLnfAction;
private ChangeVarName changeVarNameAction;
private InvokeEditorAction invokeEditorAction;
private static String PROPERTY_CATEGORY = "category";
private static String DEFAULT_GROUP_NAME = "Properties";
public ArrayList<GroupModel> getBeanPropertyModel() {
if (groupModels == null) {
PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
HashMap<String, ArrayList<PropertyDescriptor>> maps = new HashMap<String, ArrayList<PropertyDescriptor>>();
ArrayList<String> groupNames = new ArrayList<String>();
for (PropertyDescriptor property : properties) {
String groupName = (String) property.getValue(PROPERTY_CATEGORY);
if (Util.isStringNull(groupName)) {
groupName = DEFAULT_GROUP_NAME;
}
ArrayList<PropertyDescriptor> groupProperties = maps.get(groupName);
if (groupProperties == null) {
groupProperties = new ArrayList<PropertyDescriptor>();
maps.put(groupName, groupProperties);
groupNames.add(groupName);
}
groupProperties.add(property);
}
ArrayList<PropertyGroupModel> groups = new ArrayList<PropertyGroupModel>();
for (String groupName : groupNames) {
ArrayList<PropertyDescriptor> groupProperties = maps.get(groupName);
PropertyDescriptor[] prop_array = groupProperties.toArray(new PropertyDescriptor[0]);
PropertyGroupModel groupModel = new PropertyGroupModel(groupName, component, designer, prop_array);
groups.add(groupModel);
}
Collections.sort(groups);
groupModels = new ArrayList<GroupModel>();
groupModels.addAll(groups);
}
return groupModels;
}
public ArrayList<GroupModel> getEventPropertyModel() {
if (eventGroups == null) {
EventSetDescriptor[] events = beanInfo.getEventSetDescriptors();
ArrayList<EventGroupModel> groups = new ArrayList<EventGroupModel>();
for (EventSetDescriptor event : events) {
groups.add(new EventGroupModel(designer, component, event));
}
Collections.sort(groups);
eventGroups=new ArrayList<GroupModel>();
eventGroups.addAll(groups);
}
return eventGroups;
}
private ArrayList<GroupModel> eventGroups;
private boolean hasDesignerEditor() {
String editor = (String) beanInfo.getBeanDescriptor()
.getValue("designer-editor");
return (editor != null) && (editor.trim().length() > 0);
}
private DesignerEditor createDesignerEditor() {
try {
String editor = (String) beanInfo.getBeanDescriptor()
.getValue("designer-editor");
return (DesignerEditor) Beans.instantiate(getClass().getClassLoader(),
editor);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
public DesignerEditor getDesignerEditor(int x, int y) {
if (isTextBound()) {
if (designerEditor == null) {
designerEditor = new TextEditor();
}
} else if (hasDesignerEditor()) {
if (designerEditor == null) {
designerEditor = createDesignerEditor();
}
}
return designerEditor;
}
private boolean isTextBound() {
if (textProperty != null) {
return true;
}
PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor property : properties) {
if (property.getName().equals("text")) {
textProperty = property;
return true;
}
}
return false;
}
public void validateBeanValue(Object value) throws ValidationException {
}
public void setBeanValue(Object value) {
if (textProperty != null) {
Method m = textProperty.getWriteMethod();
try {
if (m != null) {
m.invoke(component, value);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public Object getBeanValue() {
if (textProperty != null) {
Method m = textProperty.getReadMethod();
try {
return m.invoke(component);
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public Rectangle getEditorBounds(int x, int y) {
Rectangle bounds = component.getBounds();
bounds.x = 1;
bounds.y = 1;
bounds.width -= 1;
bounds.height -= 1;
return bounds;
}
public boolean componentClicked(MouseEvent e) {
Component parent=component;
while(!(parent instanceof JInternalFrame || parent == null))
parent=parent.getParent();
if(parent != null){
((JInternalFrame)parent).toFront();
return false;
}
return true;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -