欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

actionlisteditor.java

PIY(Program It Yourself)是一个基于Java的应用程序开发环境
JAVA
第 1 页 / 共 3 页
字号:

			for (int i=0; i<a.size(); i++) {
				if (a.get(i) instanceof IfAction) {
					height = Math.max(height,spaceHeight + 2*Math.max( getRequiredHeight(((IfAction)a.get(i)).getTrueList()),
																		getRequiredHeight(((IfAction)a.get(i)).getFalseList())));
				}
			}
			return height;
		}

		public Dimension getMaximumSize() {
			return new Dimension(getRequiredWidth(list),getRequiredHeight(list));
		}
	
		public Dimension getMinimumSize() {
			return new Dimension(getRequiredWidth(list),getRequiredHeight(list));
		}
	
		public Dimension getPreferredSize() {
			return new Dimension(getRequiredWidth(list),getRequiredHeight(list));

		}

		//------------ ActionListener Method -------------
		public void actionPerformed(ActionEvent e) {
			switch (editType) {
				case SELECT:
					selectAction((ActionIcon)e.getSource());
					break;
				case ADD: //Add an action from the toolbar to the list
					selected = (ActionIcon)e.getSource();
					if (selected.getPIYAction() instanceof NullAction) {
						
						int pos = selected.getActionList().removeAction(selected.getPIYAction());
						try{					
							//Add the selected action to the action list
							PIYAction toSelect = (PIYAction)toolbarSelection.getDescribedClass().newInstance();
							selected.getActionList().add(pos, toSelect);

							for (int i=0; i<actionPanel.length; i++)
								actionPanel[i].clearSelection(); //deselect the icon on the toolbar

							removeAll();//clear all of the old action icons
							restructureList(list);//ensure the integrity of the list structure
							selected = setupList(list, new Point(0,0), new Dimension(getRequiredWidth(list), getRequiredHeight(list)), toSelect);

							//perform a "selection" of the newly added action - display its properties	
							selectAction(selected);
	
							scroller.validate();
						} catch (Exception ex) {
							System.out.println("Unable to insert action in list");
							ex.printStackTrace();
						}

						repaint();
					}
					break;
			}
		}
	} 

	/**
	* The panel which displays the properties and property support of the currently selected action.
	* @author David Vivash
	* @version 1.0, 27/03/01
	*/
	private class PropertiesPanel extends JPanel {
		private PIYAction action = null;
		
		public PropertiesPanel() {
			setLayout(new BorderLayout());
		}
		
		/**
		* Each time an action is selected in the action list viewer, this method should be called
		* to update the properties.
		* @param action the action that has been selected
		*/
		public void setup(PIYAction action) {
			this.action = action;
			
			//get rid of the old properties panels
			removeAll();

			if (action != null) {
	
				//Set up the top panel which displays the name of the PIYAction on a yellow background
				JPanel top = new JPanel();
				top.setBackground(Color.yellow);
				top.setBorder(new LineBorder(Color.black));
				top.setMinimumSize(new Dimension(64,64));

				if (viewer != null) {
					ActionDescriptor descriptor = viewer.getDescriptor(action.getClass());
	
					top.add(new JLabel(descriptor.getName() + " Properties"));
					JPanel propPane = new JPanel();
					JScrollPane propertyScroller = new JScrollPane(propPane);
					add(top, BorderLayout.NORTH);
					add(propertyScroller, BorderLayout.CENTER);
							
					//Get the class support panels for this action
					PropertyManager propMan = new PropertyManager(PIY.getInstance().getClassSupport());
					ClassSupport[] panels = propMan.getClassSupport(action, PIYAction.class, false, null);
		
					//if any of the properties are of type Object, we need to find out what type they really are
					for (int i=0; i<panels.length; i++) {
						if (panels[i].getProperty().getType() == Object.class) {
							Property objectProperty = panels[i].getProperty();					
							try{
								Method bindingMethod = action.getClass().getMethod("get"+objectProperty.getName()+"Binding",null); 
			
								Property boundTo = (Property)bindingMethod.invoke(action, null);
		
								for (int j=0; j<panels.length; j++)
									if (boundTo.getName().equals(panels[j].getProperty().getName()))
										((ObjectSupport)panels[i]).setPairSupport(panels[j]);
									
							} catch (Exception e) {
								System.err.println("Error retrieving the binding method of " + objectProperty.getName());
							}
						}
					}
		
					//Layout the class support panels
					GridBagLayout gridbag = new GridBagLayout();
					GridBagConstraints c = new GridBagConstraints();
			
					propPane.setLayout(gridbag);
					c.fill = GridBagConstraints.HORIZONTAL;
					c.ipadx = 4; c.ipady = 8;
					c.insets = new Insets(4,4,4,4);
		
					for (int i=0; i<panels.length; i++) {
			
						c.gridy = i; c.gridx = 0; c.weightx = 0;
						JLabel label = new JLabel(panels[i].getProperty().getName());
						gridbag.setConstraints(label, c);
						propPane.add(label);
						
						c.gridx = 1; c.weightx = 1.0;
						gridbag.setConstraints(panels[i], c);
						propPane.add(panels[i]);
					}
		
		
					//See if the action returns a value
					Class returnType = action.getReturnType();
					//the return place is stored in the action list
					if (returnType != null) {
						ClassSupport returnSupport = new FixedPropertySupport(new Property(this, "Return", FixedProperty.class));
		
						c.gridy = panels.length; c.gridx = 0; c.weightx = 0;
						JPanel strings = new JPanel();
						strings.setLayout(new BorderLayout());
						strings.add(new JLabel("Store"), BorderLayout.NORTH);
						strings.add(new JLabel("result"), BorderLayout.CENTER);
						strings.add(new JLabel("in"), BorderLayout.SOUTH);
						gridbag.setConstraints(strings, c);
						propPane.add(strings);
						
						c.gridx = 1; c.weightx = 1.0;
						gridbag.setConstraints(returnSupport, c);
						propPane.add(returnSupport);
					}
		
					//add a blank panel at the bottom to make sure the (real) properties are 
					//aligned to the top of the frame.
					c.gridy = returnType != null ? panels.length+1 : panels.length;
					c.weighty = 1.0;
					JPanel blank = new JPanel();
					gridbag.setConstraints(blank, c);
					propPane.add(blank);
				}

			}	
			
			validate();
			repaint();
		}

		/**
		* This is set up to support the return sent from the action.
		* @return the property fixed to the type of the getReturnType() of the action
		*/
		public FixedProperty getReturn() {
			Property val = list.getReturn(action);
			FixedProperty prop = new FixedProperty(null, action.getReturnType());
			if (val == null) val = new Property(null, "", action.getReturnType());
			prop.setProperty(val);
			prop.setDynamicOnly(true);
			setReturn(prop);
			return prop;
		}
		
		/**
		* Set where the action should send its return value to.
		* @param property the property fixed to the type that the action returns
		*/
		public void setReturn(FixedProperty property) {
			list.setReturn(action, property.getProperty());
		}
	}

	/**
	* Supports the selection and renaming of action lists.
	* @author David Vivash
	* @version 1.0, 27/03/01
	*/
	private class ActionListNamePanel extends JPanel implements ActionListener {

		private ActionList list = null;
		private JComboBox combo = new JComboBox();
		private static final String DELETE_LIST = "deleteList";

		private boolean editting = false;  //when this is true, it mean the action list combo box is being updated,
											//so when it fires the actionPerformed method, it shouldn't do anything 

		public ActionListNamePanel(ActionList list) {
			setup(list);
		}

		/**
		* Sets up the panel view for the specified action list.
		* @param list the list to initially display as being selected
		*/
		private void setup(ActionList list) {
			removeAll();
			combo = new JComboBox(ProjectHandler.getInstance().getProject().getActionListNamer().getNames());
			
			combo.insertItemAt("", 0);
			
			setLayout(new GridLayout(2,1));
			JPanel comboPanel = new JPanel();
			comboPanel.setLayout(new BorderLayout());
			comboPanel.add(combo, BorderLayout.CENTER);
			
			String sep = File.separator;
			String images = "piy" + sep + "images" + sep;

			FloatingButton delActionList = new FloatingButton(new ImageIcon(images + "delete.gif").getImage(), DELETE_LIST, false);
			delActionList.addActionListener(this);
			delActionList.setToolTipText("Delete Action List");
			delActionList.setPreferredSize(new Dimension(24,24));

			comboPanel.add(delActionList, BorderLayout.WEST);
			
			add(comboPanel);

			this.list = list;

			if (list != null) {
				Property listName = new Property(this, "Name", String.class);

				JPanel namePanel = new JPanel();
				namePanel.setLayout(new BorderLayout());
				namePanel.add(new JLabel(" Name   "), BorderLayout.WEST);
				ClassSupport panel = new StringSupport(listName);
				namePanel.add(panel, BorderLayout.CENTER);

				add(namePanel);
				combo.setSelectedItem(ProjectHandler.getInstance().getProject().getActionListNamer().getName(list));
			} else {
				combo.setSelectedIndex(0); //select the blank item at the top of the list
			}

			combo.addActionListener(this);

			validate();
			repaint();
		}

		/**
		* Creates a new actionlist which is automatically added to the project currently being editted.
		* Its name is also automatically added to the list of actionlist names in the combo box.
		* @return the ActionList object that was created
		*/
		public ActionList newList() {
			ActionList list = new ActionList();
			ProjectHandler.getInstance().getProject().getActionListNamer().add(list, "ActionList");
			setup(list);
			return list;
		}

		/**
		* Sets the name of the action list currently being editted.
		* @param name the new name for the action list.  The name will not be set unless it is 
		* unique in the project context.
		*/
		public void setName(String name) {
			editting = true;
			PIYNamer namer = ProjectHandler.getInstance().getProject().getActionListNamer();
			String oldName = namer.getName(list);
			namer.renameValue(oldName, name);
			String newName = namer.getName(list);
			combo.removeItem(oldName);
			combo.addItem(newName);
			combo.setSelectedItem(newName);
			editting = false;
		}

		/**
		* Gets the name of the action list currently being editted.
		* @returns the unique name for the action list.
		*/
		public String getName() {
			return ProjectHandler.getInstance().getProject().getName(list);
		}


		public Dimension getPreferredSize() { return new Dimension(100,48); }
		public Dimension getMinimumSize() { return new Dimension(100,48); }
		public Dimension getMaximumSize() { return new Dimension(100,48); }

		//------------- ActionListener Method ---------------
		public void actionPerformed(ActionEvent e) {
			if (!editting) {
				if (e.getActionCommand() == DELETE_LIST) {
					viewer.deleteList();			
					ProjectHandler.getInstance().projectChanged();
					list = null;
				} else {				
					String listName = (String)combo.getSelectedItem();
					if (listName.equals("")) list = null;
					else list = (ActionList)ProjectHandler.getInstance().getProject().getActionListNamer().getValue(listName);
				}
				
				viewer.setList(list);
				setup(list);
			} 
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -